PySide.QtSql.QSqlDriver class is an abstract base class for accessing specific SQL databases.
This class should not be used directly. Use PySide.QtSql.QSqlDatabase 代替。
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 了解更多信息。
| 参数: | parent – PySide.QtCore.QObject |
|---|
Constructs a new driver with the given parent .
This enum contains a list of SQL statement (or clause) types the driver can create.
| 常量 | 描述 |
|---|---|
| QSqlDriver.WhereStatement | An SQL WHERE statement (e.g., WHERE f = 5 ). |
| QSqlDriver.SelectStatement | An SQL SELECT statement (e.g., SELECT f FROM t ). |
| QSqlDriver.UpdateStatement | An SQL UPDATE statement (e.g., UPDATE TABLE t set f = 1 ). |
| QSqlDriver.InsertStatement | An SQL INSERT statement (e.g., INSERT INTO t (f) values (1) ). |
| QSqlDriver.DeleteStatement | An SQL DELETE statement (e.g., DELETE FROM t ). |
This enum contains a list of SQL identifier types.
| 常量 | 描述 |
|---|---|
| QSqlDriver.FieldName | A SQL field name |
| QSqlDriver.TableName | A SQL table name |
This enum contains a list of features a driver might support. Use PySide.QtSql.QSqlDriver.hasFeature() to query whether a feature is supported or not.
| 常量 | 描述 |
|---|---|
| QSqlDriver.Transactions | Whether the driver supports SQL transactions. |
| QSqlDriver.QuerySize | 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 | Whether the driver supports Binary Large Object fields. |
| QSqlDriver.Unicode | Whether the driver supports Unicode strings if the database server does. |
| QSqlDriver.PreparedQueries | Whether the driver supports prepared query execution. |
| QSqlDriver.NamedPlaceholders | Whether the driver supports the use of named placeholders. |
| QSqlDriver.PositionalPlaceholders | Whether the driver supports the use of positional placeholders. |
| QSqlDriver.LastInsertId | Whether the driver supports returning the Id of the last touched row. |
| QSqlDriver.BatchOperations | Whether the driver supports batched operations, see QSqlQuery.execBatch() |
| QSqlDriver.SimpleLocking | Whether the driver disallows a write lock on a table while other queries have a read lock on it. |
| QSqlDriver.LowPrecisionNumbers | Whether the driver allows fetching numerical values with low precision. |
| QSqlDriver.EventNotifications | Whether the driver supports database event notifications. |
| QSqlDriver.FinishQuery | Whether the driver can do any low-level resource cleanup when QSqlQuery.finish() 被调用。 |
| QSqlDriver.MultipleResultSets | Whether the driver can access multiple result sets returned from batched statements or stored procedures. |
More information about supported features can be found in the Qt SQL driver 文档编制。
| 返回类型: | PySide.QtCore.bool |
|---|
This function is called to begin a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns false.
Derived classes must reimplement this pure virtual function in order to close the database connection. Return true on success, false on failure.
| 返回类型: | PySide.QtCore.bool |
|---|
This function is called to commit a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns false.
| 返回类型: | PySide.QtSql.QSqlResult |
|---|
Creates an empty SQL result on the database. Derived classes must reimplement this function and return a PySide.QtSql.QSqlResult object appropriate for their database to the caller.
| 参数: |
|
|---|---|
| 返回类型: |
unicode |
返回 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.
| 参数: |
|
|---|---|
| 返回类型: |
unicode |
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:
另请参阅
QVariant.toString()
| 参数: | f – PySide.QtSql.QSqlDriver.DriverFeature |
|---|---|
| 返回类型: | PySide.QtCore.bool |
Returns true if the driver supports feature feature ;否则返回 false。
Note that some databases need to be PySide.QtSql.QSqlDriver.open() before this can be determined.
另请参阅
QSqlDriver.DriverFeature
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
Returns whether identifier is escaped according to the database rules. identifier can either be a table name or field name, dependent on type .
警告
Because of binary compatibility constraints, this function is not virtual. If you want to provide your own implementation in your PySide.QtSql.QSqlDriver subclass, reimplement the PySide.QtSql.QSqlDriver.isIdentifierEscapedImplementation() slot in your subclass instead. The isIdentifierEscapedFunction() will dynamically detect the slot and call it.
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
This slot returns whether identifier is escaped according to the database rules. identifier can either be a table name or field name, dependent on type .
Because of binary compatibility constraints, PySide.QtSql.QSqlDriver.isIdentifierEscaped() function (introduced in Qt 4.5) is not virtual. Instead, PySide.QtSql.QSqlDriver.isIdentifierEscaped() will dynamically detect and call this slot. The default implementation assumes the escape/delimiter character is a double quote. Reimplement this slot in your own PySide.QtSql.QSqlDriver if your database engine uses a different delimiter character.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the database connection is open; otherwise returns false.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the there was an error opening the database connection; otherwise returns false.
| 返回类型: | PySide.QtSql.QSqlError |
|---|
返回 PySide.QtSql.QSqlError object which contains information about the last error that occurred on the database.
| 参数: | name – unicode |
|---|
| 返回类型: | PySide.QtSql.QSql.NumericalPrecisionPolicy |
|---|
Returns the current default precision policy for the database connection.
另请参阅
QSql.NumericalPrecisionPolicy PySide.QtSql.QSqlDriver.setNumericalPrecisionPolicy() QSqlQuery.numericalPrecisionPolicy() QSqlQuery.setNumericalPrecisionPolicy()
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
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.
| 参数: | tableName – unicode |
|---|---|
| 返回类型: | PySide.QtSql.QSqlIndex |
Returns the primary index for table tableName . Returns an empty PySide.QtSql.QSqlIndex if the table doesn't have a primary index. The default implementation returns an empty index.
| 参数: | tableName – unicode |
|---|---|
| 返回类型: | PySide.QtSql.QSqlRecord |
返回 PySide.QtSql.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.
| 返回类型: | PySide.QtCore.bool |
|---|
This function is called to rollback a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns false.
| 参数: | e – PySide.QtSql.QSqlError |
|---|
This function is used to set the value of the last error, error , that occurred on the database.
| 参数: | precisionPolicy – PySide.QtSql.QSql.NumericalPrecisionPolicy |
|---|
| 参数: | o – PySide.QtCore.bool |
|---|
This function sets the open state of the database to open . Derived classes can use this function to report the status of PySide.QtSql.QSqlDriver.open() .
| 参数: | e – PySide.QtCore.bool |
|---|
This function sets the open error state of the database to error . Derived classes can use this function to report the status of PySide.QtSql.QSqlDriver.open() . Note that if error is true the open state of the database is set to closed (i.e., PySide.QtSql.QSqlDriver.isOpen() returns false).
| 参数: |
|
|---|---|
| 返回类型: |
unicode |
Returns a SQL statement of type type for the table tableName with the values from rec 。若 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.
| 参数: |
|
|---|---|
| 返回类型: |
unicode |
返回 identifier with the leading and trailing delimiters removed, identifier can either be a table name or field name, dependent on type 。若 identifier does not have leading and trailing delimiter characters, identifier is returned without modification.
警告
Because of binary compatibility constraints, this function is not virtual, If you want to provide your own implementation in your PySide.QtSql.QSqlDriver subclass, reimplement the PySide.QtSql.QSqlDriver.stripDelimitersImplementation() slot in your subclass instead. The PySide.QtSql.QSqlDriver.stripDelimiters() function will dynamically detect the slot and call it.
| 参数: |
|
|---|---|
| 返回类型: |
unicode |
This slot returns identifier with the leading and trailing delimiters removed, identifier can either be a tablename or field name, dependent on type 。若 identifier does not have leading and trailing delimiter characters, identifier is returned without modification.
Because of binary compatibility constraints, the PySide.QtSql.QSqlDriver.stripDelimiters() function (introduced in Qt 4.5) is not virtual. Instead, PySide.QtSql.QSqlDriver.stripDelimiters() will dynamically detect and call this slot. It generally unnecessary to reimplement this slot.
| 参数: | name – unicode |
|---|---|
| 返回类型: | PySide.QtCore.bool |
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 PySide.QtSql.QSqlDriver.close() all subscribed event notifications are automatically unsubscribed. Note that calling PySide.QtSql.QSqlDriver.open() on an already open database may implicitly cause PySide.QtSql.QSqlDriver.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 PySide.QtSql.QSqlDriver.notification() 信号被发射。
警告
Because of binary compatibility constraints, this function is not virtual. If you want to provide event notification support in your own PySide.QtSql.QSqlDriver subclass, reimplement the PySide.QtSql.QSqlDriver.subscribeToNotificationImplementation() slot in your subclass instead. The PySide.QtSql.QSqlDriver.subscribeToNotification() function will dynamically detect the slot and call it.
| 参数: | name – unicode |
|---|---|
| 返回类型: | PySide.QtCore.bool |
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 PySide.QtSql.QSqlDriver.close() all subscribed event notifications are automatically unsubscribed. Note that calling PySide.QtSql.QSqlDriver.open() on an already open database may implicitly cause PySide.QtSql.QSqlDriver.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 PySide.QtSql.QSqlDriver.notification() 信号被发射。
Reimplement this slot to provide your own PySide.QtSql.QSqlDriver subclass with event notification support; because of binary compatibility constraints, the PySide.QtSql.QSqlDriver.subscribeToNotification() function (introduced in Qt 4.4) is not virtual. Instead, PySide.QtSql.QSqlDriver.subscribeToNotification() will dynamically detect and call this slot. The default implementation does nothing and returns false.
| 返回类型: | 字符串列表 |
|---|
Returns a list of the names of the event notifications that are currently subscribed to.
警告
Because of binary compatibility constraints, this function is not virtual. If you want to provide event notification support in your own PySide.QtSql.QSqlDriver subclass, reimplement the PySide.QtSql.QSqlDriver.subscribedToNotificationsImplementation() slot in your subclass instead. The PySide.QtSql.QSqlDriver.subscribedToNotifications() function will dynamically detect the slot and call it.
| 返回类型: | 字符串列表 |
|---|
Returns a list of the names of the event notifications that are currently subscribed to.
Reimplement this slot to provide your own PySide.QtSql.QSqlDriver subclass with event notification support; because of binary compatibility constraints, the PySide.QtSql.QSqlDriver.subscribedToNotifications() function (introduced in Qt 4.4) is not virtual. Instead, PySide.QtSql.QSqlDriver.subscribedToNotifications() will dynamically detect and call this slot. The default implementation simply returns an empty PySide.QtCore.QStringList .
| 参数: | tableType – PySide.QtSql.QSql.TableType |
|---|---|
| 返回类型: | 字符串列表 |
| 参数: | name – unicode |
|---|---|
| 返回类型: | PySide.QtCore.bool |
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 PySide.QtSql.QSqlDriver.close() 函数被调用。
After calling this function the PySide.QtSql.QSqlDriver.notification() signal will no longer be emitted when an event notification identified by name is posted by the database.
警告
Because of binary compatibility constraints, this function is not virtual. If you want to provide event notification support in your own PySide.QtSql.QSqlDriver subclass, reimplement the PySide.QtSql.QSqlDriver.unsubscribeFromNotificationImplementation() slot in your subclass instead. The PySide.QtSql.QSqlDriver.unsubscribeFromNotification() function will dynamically detect the slot and call it.
| 参数: | name – unicode |
|---|---|
| 返回类型: | PySide.QtCore.bool |
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 PySide.QtSql.QSqlDriver.close() 函数被调用。
After calling this slot the PySide.QtSql.QSqlDriver.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 PySide.QtSql.QSqlDriver subclass with event notification support; because of binary compatibility constraints, the PySide.QtSql.QSqlDriver.unsubscribeFromNotification() function (introduced in Qt 4.4) is not virtual. Instead, PySide.QtSql.QSqlDriver.unsubscribeFromNotification() will dynamically detect and call this slot. The default implementation does nothing and returns false.