Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.sql
Class QSqlDriver

    java.lang.Object
      com.trolltech.qt.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.core.QObject
                  com.trolltech.qt.sql.QSqlDriver

All Implemented Interfaces:
  QtJambiInterface

    public abstract class QSqlDriver

extends QObject

The `QSqlDriver` class is an abstract base class for accessing specific SQL databases.

This class should not be used directly. Use `QSqlDatabase` instead.

If you want to create your own SQL drivers, you can subclass this class and reimplement its pure virtual functions and those virtual functions that you need. See How to Write Your Own Database Driver for more information.

See Also:
  `QSqlDatabase`, `QSqlResult`

Nested Class Summary
`static class` | `QSqlDriver.DriverFeature` This enum contains a list of features a driver might support.
`static class` | `QSqlDriver.IdentifierType` This enum contains a list of SQL identifier types.
`static class` | `QSqlDriver.StatementType` This enum contains a list of SQL statement (or clause) types the driver can create.

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>`

Constructor Summary
`QSqlDriver()` Equivalent to `QSqlDriver`(0).
`QSqlDriver(QObject parent)` Constructs a new driver with the given `parent`.

Method Summary
`boolean` | `beginTransaction()` This function is called to begin a transaction.
`abstract void` | `close()` Derived classes must reimplement this pure virtual function in order to close the database connection.
`boolean` | `commitTransaction()` This function is called to commit a transaction.
`abstract QSqlResult` | `createResult()` Creates an empty SQL result on the database.
`java.lang.String` | `escapeIdentifier(java.lang.String identifier, QSqlDriver.IdentifierType type)` Returns the `identifier` escaped according to the database rules.
`java.lang.String` | `formatValue(QSqlField field)` Equivalent to `formatValue`(`field`, false).
`java.lang.String` | `formatValue(QSqlField field, boolean trimStrings)` Returns a string representation of the `field` value for the database.
`static QSqlDriver` | `fromNativePointer(QNativePointer nativePointer)` This function returns the QSqlDriver instance pointed to by nativePointer
`java.lang.Object` | `handle()` Returns the low-level database handle wrapped in a `QVariant` or an invalid variant if there is no handle.
`abstract boolean` | `hasFeature(QSqlDriver.DriverFeature f)` Returns true if the driver supports feature `f`; otherwise returns false.
`boolean` | `isOpen()` Returns true if the database connection is open; otherwise returns false.
`boolean` | `isOpenError()` Returns true if the there was an error opening the database connection; otherwise returns false.
`QSqlError` | `lastError()` Returns a `QSqlError` object which contains information about the last error that occurred on the database.
`boolean` | `open(java.lang.String db)` Equivalent to open(`db`, QString(), QString(), QString(), -1, QString()).
`boolean` | `open(java.lang.String db, java.lang.String user)` Equivalent to open(`db`, `user`, QString(), QString(), -1, QString()).
`boolean` | `open(java.lang.String db, java.lang.String user, java.lang.String password)` Equivalent to open(`db`, `user`, `password`, QString(), -1, QString()).
`boolean` | `open(java.lang.String db, java.lang.String user, java.lang.String password, java.lang.String host)` Equivalent to open(`db`, `user`, `password`, `host`, -1, QString()).
`boolean` | `open(java.lang.String db, java.lang.String user, java.lang.String password, java.lang.String host, int port)` Equivalent to open(`db`, `user`, `password`, `host`, `port`, QString()).
`abstract boolean` | `open(java.lang.String db, java.lang.String user, java.lang.String password, java.lang.String host, int port, java.lang.String connOpts)` Derived classes must reimplement this pure virtual function to open a database connection on database `db`, using user name `user`, password `password`, host `host`, port `port` and connection options `connOpts`.
`QSqlIndex` | `primaryIndex(java.lang.String tableName)` Returns the primary index for table `tableName`.
`QSqlRecord` | `record(java.lang.String tableName)` Returns a `QSqlRecord` populated with the names of the fields in table `tableName`.
`boolean` | `rollbackTransaction()` This function is called to rollback a transaction.
`protected void` | `setLastError(QSqlError e)` This function is used to set the value of the last error, `e`, that occurred on the database.
`protected void` | `setOpen(boolean o)` This function sets the open state of the database to `o`.
`protected void` | `setOpenError(boolean e)` This function sets the open error state of the database to `e`.
`java.lang.String` | `sqlStatement(QSqlDriver.StatementType type, java.lang.String tableName, QSqlRecord rec, boolean preparedStatement)` Returns a SQL statement of type `type` for the table `tableName` with the values from `rec`.
`java.util.List<java.lang.String>` | `tables(QSql.TableType tableType)` Returns a list of the names of the tables in the database.

Methods inherited from class com.trolltech.qt.core.QObject
`blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent`

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`disconnect, disconnect, signalSender`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Constructor Detail

### QSqlDriver

    public QSqlDriver()

  Equivalent to `QSqlDriver`(0).

### QSqlDriver

    public QSqlDriver(QObject parent)

  Constructs a new driver with the given `parent`.

Method Detail

### isOpenError

    public final boolean isOpenError()

  Returns true if the there was an error opening the database connection; otherwise returns false.

### lastError

    public final QSqlError lastError()

  Returns a `QSqlError` object which contains information about the last error that occurred on the database.

  See Also:
    `setLastError`

### beginTransaction

    public boolean beginTransaction()

  This function is called to begin a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns false.

  See Also:
    `commitTransaction`, `rollbackTransaction`

### close

    public abstract void close()

  Derived classes must reimplement this pure virtual function in order to close the database connection. Return true on success, false on failure.

  See Also:
    `open`, `setOpen`

### commitTransaction

    public boolean commitTransaction()

  This function is called to commit a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns false.

  See Also:
    `beginTransaction`, `rollbackTransaction`

### createResult

    public abstract QSqlResult createResult()

  Creates an empty SQL result on the database. Derived classes must reimplement this function and return a `QSqlResult` object appropriate for their database to the caller.

### escapeIdentifier

    public java.lang.String escapeIdentifier(java.lang.String identifier,
                                             QSqlDriver.IdentifierType type)

  Returns the `identifier` escaped according to the database rules. `identifier` can either be a table name or field name, dependent on `type`.

  The default implementation does nothing.

### formatValue

    public final java.lang.String formatValue(QSqlField field)

  Equivalent to `formatValue`(`field`, false).

### formatValue

    public java.lang.String formatValue(QSqlField field,
                                        boolean trimStrings)

  Returns a string representation of the `field` value for the database. This is used, for example, when constructing INSERT and UPDATE statements.

  The default implementation returns the value formatted as a string according to the following rules:

  - If `field` is character data, the value is returned enclosed in single quotation marks, which is appropriate for many SQL databases. Any embedded single-quote characters are escaped (replaced with two single-quote characters). If `trimStrings` is true (the default is false), all trailing whitespace is trimmed from the field.
  - If `field` is date/time data, the value is formatted in ISO format and enclosed in single quotation marks. If the date/time data is invalid, "NULL" is returned.
  - If `field` is bytearray data, and the driver can edit binary fields, the value is formatted as a hexadecimal string.
  - For any other field type, toString() is called on its value and the result of this is returned.

  See Also:
    `QVariant::toString`

### handle

    public java.lang.Object handle()

  Returns the low-level database handle wrapped in a `QVariant` or an invalid variant if there is no handle.

  Warning: Use this with uttermost care and only if you know what you're doing.

  Warning: The handle returned here can become a stale pointer if the connection is modified (for example, if you close the connection).

  Warning: The handle can be NULL if the connection is not open yet.

  The handle returned here is database-dependent, you should query the type name of the variant before accessing it.

  This example retrieves the handle for a connection to sqlite:

          QSqlDatabase db = ...;
          QVariant v = db.driver()->handle();
          if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*")) {
              // v.data() returns a pointer to the handle
              sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
              if (handle != 0) { // check that it is not NULL
                  ...
              }
          }

  This snippet returns the handle for PostgreSQL or MySQL:

          if (v.typeName() == "PGconn*") {
              PGconn *handle = *static_cast<PGconn **>(v.data());
              if (handle != 0) ...
          }

          if (v.typeName() == "MYSQL*") {
              MYSQL *handle = *static_cast<MYSQL **>(v.data());
              if (handle != 0) ...
          }

  See Also:
    `QSqlResult::handle`

### hasFeature

    public abstract boolean hasFeature(QSqlDriver.DriverFeature f)

  Returns true if the driver supports feature `f`; otherwise returns false.

  Note that some databases need to be `open` before this can be determined.

  See Also:
    `DriverFeature`

### isOpen

    public boolean isOpen()

  Returns true if the database connection is open; otherwise returns false.

### open

    public final boolean open(java.lang.String db,
                              java.lang.String user,
                              java.lang.String password,
                              java.lang.String host,
                              int port)

  Equivalent to open(`db`, `user`, `password`, `host`, `port`, QString()).

### open

    public final boolean open(java.lang.String db,
                              java.lang.String user,
                              java.lang.String password,
                              java.lang.String host)

  Equivalent to open(`db`, `user`, `password`, `host`, -1, QString()).

### open

    public final boolean open(java.lang.String db,
                              java.lang.String user,
                              java.lang.String password)

  Equivalent to open(`db`, `user`, `password`, QString(), -1, QString()).

### open

    public final boolean open(java.lang.String db,
                              java.lang.String user)

  Equivalent to open(`db`, `user`, QString(), QString(), -1, QString()).

### open

    public final boolean open(java.lang.String db)

  Equivalent to open(`db`, QString(), QString(), QString(), -1, QString()).

### open

    public abstract boolean open(java.lang.String db,
                                 java.lang.String user,
                                 java.lang.String password,
                                 java.lang.String host,
                                 int port,
                                 java.lang.String connOpts)

  Derived classes must reimplement this pure virtual function to open a database connection on database `db`, using user name `user`, password `password`, host `host`, port `port` and connection options `connOpts`.

  The function must return true on success and false on failure.

  See Also:
    `setOpen`

### primaryIndex

    public QSqlIndex primaryIndex(java.lang.String tableName)

  Returns the primary index for table `tableName`. Returns an empty `QSqlIndex` if the table doesn't have a primary index. The default implementation returns an empty index.

### record

    public QSqlRecord record(java.lang.String tableName)

  Returns a `QSqlRecord` populated with the names of the fields in table `tableName`. If no such table exists, an empty record is returned. The default implementation returns an empty record.

### rollbackTransaction

    public boolean rollbackTransaction()

  This function is called to rollback a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns false.

  See Also:
    `beginTransaction`, `commitTransaction`

### setLastError

    protected void setLastError(QSqlError e)

  This function is used to set the value of the last error, `e`, that occurred on the database.

  See Also:
    `lastError`

### setOpen

    protected void setOpen(boolean o)

  This function sets the open state of the database to `o`. Derived classes can use this function to report the status of `open`.

  See Also:
    `open`, `setOpenError`

### setOpenError

    protected void setOpenError(boolean e)

  This function sets the open error state of the database to `e`. Derived classes can use this function to report the status of `open`. Note that if `e` is true the open state of the database is set to closed (i.e., `isOpen` returns false).

  See Also:
    `isOpenError`, `open`, `setOpen`

### sqlStatement

    public java.lang.String sqlStatement(QSqlDriver.StatementType type,
                                         java.lang.String tableName,
                                         QSqlRecord rec,
                                         boolean preparedStatement)

  Returns a SQL statement of type `type` for the table `tableName` with the values from `rec`. If `preparedStatement` is true, the string will contain placeholders instead of values.

  This method can be used to manipulate tables without having to worry about database-dependent SQL dialects. For non-prepared statements, the values will be properly escaped.

### tables

    public java.util.List<java.lang.String> tables(QSql.TableType tableType)

  Returns a list of the names of the tables in the database. The default implementation returns an empty list.

  The `tableType` argument describes what types of tables should be returned. Due to binary compatibility, the string contains the value of the enum QSql::TableTypes as text. An empty string should be treated as QSql::Tables for backward compatibility.

### fromNativePointer

    public static QSqlDriver fromNativePointer(QNativePointer nativePointer)

  This function returns the QSqlDriver instance pointed to by nativePointer

  Parameters:
    `nativePointer` - the QNativePointer of which object should be returned.

Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD