Overview | Package | Class | Tree | Deprecated | Index | Help
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`, and `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.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Field Summary
`QSignalEmitter.Signal1` | `notification` This signal is emitted when the database posts an event notification that the driver subscribes to.

Constructor Summary
`QSqlDriver()` Constructs a new driver with the given `parent`.
`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)` Use the other `formatValue()` overload instead.
`java.lang.String` | `formatValue(QSqlField field, boolean trimStrings)` Use the other `formatValue()` overload instead.
`static QSqlDriver` | `fromNativePointer(QNativePointer nativePointer)` This method 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 `feature`; 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)` 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 `options`.
`boolean` | `open(java.lang.String db, java.lang.String user)` 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 `options`.
`boolean` | `open(java.lang.String db, java.lang.String user, java.lang.String password)` 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 `options`.
`boolean` | `open(java.lang.String db, java.lang.String user, java.lang.String password, java.lang.String host)` 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 `options`.
`boolean` | `open(java.lang.String db, java.lang.String user, java.lang.String password, java.lang.String host, int port)` 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 `options`.
`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 `options`.
`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, `error`, that occurred on the database.
`protected void` | `setOpen(boolean o)` This function sets the open state of the database to `open`.
`protected void` | `setOpenError(boolean e)` This function sets the open error state of the database to `error`.
`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` | `subscribedToNotifications()` Returns a list of the names of the event notifications that are currently subscribed to.
`protected java.util.List` | `subscribedToNotificationsImplementation()` Returns a list of the names of the event notifications that are currently subscribed to.
`boolean` | `subscribeToNotification(java.lang.String name)` This function is called to subscribe to event notifications from the database.
`protected boolean` | `subscribeToNotificationImplementation(java.lang.String name)` This slot is called to subscribe to event notifications from the database.
`java.util.List` | `tables(QSql.TableType tableType)` Returns a list of the names of the tables in the database.
`boolean` | `unsubscribeFromNotification(java.lang.String name)` This function is called to unsubscribe from event notifications from the database.
`protected boolean` | `unsubscribeFromNotificationImplementation(java.lang.String name)` This slot is called to unsubscribe from event notifications from the database.

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

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

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

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

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

Field Detail

### notification

    public final QSignalEmitter.Signal1 notification

  This signal is emitted when the database posts an event notification that the driver subscribes to. `name` identifies the event notification.

See also:
  `subscribeToNotification()`.

Constructor Detail

### QSqlDriver

    public QSqlDriver()

  Constructs a new driver with the given `parent`.

### 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()`.

### subscribeToNotification

    public final boolean subscribeToNotification(java.lang.String name)

  This function is called to subscribe to event notifications from the database. `name` identifies the event notification.

  If successful, return true, otherwise return false.

  The database must be open when this function is called. When the database is closed by calling `close()` all subscribed event notifications are automatically unsubscribed. Note that calling `open()` on an already open database may implicitly cause `close()` to be called, which will cause the driver to unsubscribe from all event notifications.

  When an event notification identified by `name` is posted by the database the `notification()` signal is emitted.

  Warning: Because of binary compatibility constraints, this function is not virtual. If you want to provide event notification support in your own `QSqlDriver` subclass, reimplement the `subscribeToNotificationImplementation()` slot in your subclass instead. The `subscribeToNotification()` function will dynamically detect the slot and call it.

See also:
  `unsubscribeFromNotification()`, `subscribedToNotifications()`, and `QSqlDriver::hasFeature()`.

### subscribeToNotificationImplementation

    protected final boolean subscribeToNotificationImplementation(java.lang.String name)

  This slot is called to subscribe to event notifications from the database. `name` identifies the event notification.

  If successful, return true, otherwise return false.

  The database must be open when this slot is called. When the database is closed by calling `close()` all subscribed event notifications are automatically unsubscribed. Note that calling `open()` on an already open database may implicitly cause `close()` to be called, which will cause the driver to unsubscribe from all event notifications.

  When an event notification identified by `name` is posted by the database the `notification()` signal is emitted.

  Reimplement this slot to provide your own `QSqlDriver` subclass with event notification support; because of binary compatibility constraints, the `subscribeToNotification()` function (introduced in Qt 4.4) is not virtual. Instead, `subscribeToNotification()` will dynamically detect and call this slot. The default implementation does nothing and returns false.

See also:
  `subscribeToNotification()`.

### subscribedToNotifications

    public final java.util.List subscribedToNotifications()

  Returns a list of the names of the event notifications that are currently subscribed to.

  Warning: Because of binary compatibility constraints, this function is not virtual. If you want to provide event notification support in your own `QSqlDriver` subclass, reimplement the `subscribedToNotificationsImplementation()` slot in your subclass instead. The `subscribedToNotifications()` function will dynamically detect the slot and call it.

See also:
  `subscribeToNotification()`, and `unsubscribeFromNotification()`.

### subscribedToNotificationsImplementation

    protected final java.util.List subscribedToNotificationsImplementation()

  Returns a list of the names of the event notifications that are currently subscribed to.

  Reimplement this slot to provide your own `QSqlDriver` subclass with event notification support; because of binary compatibility constraints, the `subscribedToNotifications()` function (introduced in Qt 4.4) is not virtual. Instead, `subscribedToNotifications()` will dynamically detect and call this slot. The default implementation simply returns an empty QStringList.

See also:
  `subscribedToNotifications()`.

### unsubscribeFromNotification

    public final boolean unsubscribeFromNotification(java.lang.String name)

  This function is called to unsubscribe from event notifications from the database. `name` identifies the event notification.

  If successful, return true, otherwise return false.

  The database must be open when this function is called. All subscribed event notifications are automatically unsubscribed from when the `close()` function is called.

  After calling this function the `notification()` signal will no longer be emitted when an event notification identified by `name` is posted by the database.

  Warning: Because of binary compatibility constraints, this function is not virtual. If you want to provide event notification support in your own `QSqlDriver` subclass, reimplement the `unsubscribeFromNotificationImplementation()` slot in your subclass instead. The `unsubscribeFromNotification()` function will dynamically detect the slot and call it.

See also:
  `subscribeToNotification()`, and `subscribedToNotifications()`.

### unsubscribeFromNotificationImplementation

    protected final boolean unsubscribeFromNotificationImplementation(java.lang.String name)

  This slot is called to unsubscribe from event notifications from the database. `name` identifies the event notification.

  If successful, return true, otherwise return false.

  The database must be open when this slot is called. All subscribed event notifications are automatically unsubscribed from when the `close()` function is called.

  After calling this slot the `notification()` signal will no longer be emitted when an event notification identified by `name` is posted by the database.

  Reimplement this slot to provide your own `QSqlDriver` subclass with event notification support; because of binary compatibility constraints, the `unsubscribeFromNotification()` function (introduced in Qt 4.4) is not virtual. Instead, `unsubscribeFromNotification()` will dynamically detect and call this slot. The default implementation does nothing and returns false.

See also:
  `unsubscribeFromNotification()`.

### 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()`, and `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()`, and `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()`, and `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)

  Use the other `formatValue()` overload instead.

### formatValue

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

  Use the other `formatValue()` overload instead.

### 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 = QSqlDatabase.addDatabase("QPSQL");
          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 = tatic_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 `feature`; 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)

  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 `options`.

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

See also:
  `setOpen()`.

### open

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

  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 `options`.

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

See also:
  `setOpen()`.

### open

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

  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 `options`.

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

See also:
  `setOpen()`.

### open

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

  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 `options`.

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

See also:
  `setOpen()`.

### open

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

  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 `options`.

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

See also:
  `setOpen()`.

### 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 `options`.

  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()`, and `commitTransaction()`.

### setLastError

    protected void setLastError(QSqlError e)

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

See also:
  `lastError()`.

### setOpen

    protected void setOpen(boolean o)

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

See also:
  `open()`, and `setOpenError()`.

### setOpenError

    protected void setOpenError(boolean e)

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

See also:
  `isOpenError()`, `open()`, and `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 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 method returns the QSqlDriver instance pointed to by `nativePointer`.

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