Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |
The QSqlDriver class is an abstract base class for accessing specific SQL databases. More...
#include <QSqlDriver>
Inherits 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.
This enum contains a list of features a driver might support. Use hasFeature() to query whether a feature is supported or not.
Constant | Value | Description |
---|---|---|
QSqlDriver::Transactions | 0 | Whether the driver supports SQL transactions. |
QSqlDriver::QuerySize | 1 | Whether the database is capable of reporting the size of a query. Note that some databases do not support returning the size (i.e. number of rows returned) of a query, in which case QSqlQuery::size() will return -1. |
QSqlDriver::BLOB | 2 | Whether the driver supports Binary Large Object fields. |
QSqlDriver::Unicode | 3 | Whether the driver supports Unicode strings if the database server does. |
QSqlDriver::PreparedQueries | 4 | Whether the driver supports prepared query execution. |
QSqlDriver::NamedPlaceholders | 5 | Whether the driver supports the use of named placeholders. |
QSqlDriver::PositionalPlaceholders | 6 | Whether the driver supports the use of positional placeholders. |
QSqlDriver::LastInsertId | 7 | Whether the driver supports returning the Id of the last touched row. |
QSqlDriver::BatchOperations | 8 | Whether the driver supports batched operations, see QSqlResult::execBatch() |
More information about supported features can be found in the Qt SQL driver documentation.
See also hasFeature().
This enum contains a list of SQL identifier types.
Constant | Value | Description |
---|---|---|
QSqlDriver::FieldName | 0 | A SQL field name |
QSqlDriver::TableName | 1 | A SQL table name |
This enum contains a list of SQL statement (or clause) types the driver can create.
Constant | Value | Description |
---|---|---|
QSqlDriver::WhereStatement | 0 | An SQL WHERE statement (e.g., WHERE f = 5). |
QSqlDriver::SelectStatement | 1 | An SQL SELECT statement (e.g., SELECT f FROM t). |
QSqlDriver::UpdateStatement | 2 | An SQL UPDATE statement (e.g., UPDATE TABLE t set f = 1). |
QSqlDriver::InsertStatement | 3 | An SQL INSERT statement (e.g., INSERT INTO t (f) values (1)). |
QSqlDriver::DeleteStatement | 4 | An SQL DELETE statement (e.g., DELETE FROM t). |
See also sqlStatement().
Constructs a new driver with the given parent.
Destroys the object and frees any allocated resources.
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().
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().
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().
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.
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.
This is an overloaded member function, provided for convenience.
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:
See also QVariant::toString().
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() && 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().
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.
Returns true if the database connection is open; otherwise returns false.
Returns true if the there was an error opening the database connection; otherwise returns false.
Returns a QSqlError object which contains information about the last error that occurred on the database.
See also setLastError().
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().
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.
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.
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().
This function is used to set the value of the last error, error, that occurred on the database.
See also lastError().
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().
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().
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-dependend SQL dialects. For non-prepared statements, the values will be properly escaped.
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.
Copyright © 2006 Trolltech | Trademarks | Qt 4.1.3 |