QSqlDriverclass is an abstract base class for accessing specific SQL databases. 更多 …
def
dbmsType
()
def
isOpenError
()
def
lastError
()
def
numericalPrecisionPolicy
()
def
setNumericalPrecisionPolicy
(precisionPolicy)
def
beginTransaction
()
def
cancelQuery
()
def
close
()
def
commitTransaction
()
def
createResult
()
def
escapeIdentifier
(identifier, type)
def
formatValue
(field[, trimStrings=false])
def
hasFeature
(f)
def
isIdentifierEscaped
(identifier, type)
def
isOpen
()
def
open
(db[, user=””[, password=””[, host=””[, port=-1[, connOpts=””]]]]])
def
primaryIndex
(tableName)
def
record
(tableName)
def
rollbackTransaction
()
def
setLastError
(e)
def
setOpen
(o)
def
setOpenError
(e)
def
sqlStatement
(type, tableName, rec, preparedStatement)
def
stripDelimiters
(identifier, type)
def
subscribeToNotification
(name)
def
subscribedToNotifications
()
def
tables
(tableType)
def
unsubscribeFromNotification
(name)
def
notification
(name)
def
notification
(name, source, payload)
This class should not be used directly. Use
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 了解更多信息。
另请参阅
QSqlDriver
(
[
parent=None
]
)
¶
- param parent
QObject
Constructs a new driver with the given
parent
.
PySide2.QtSql.QSqlDriver.
DriverFeature
¶
This enum contains a list of features a driver might support. Use
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
|
|
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
|
|
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
|
|
QSqlDriver.MultipleResultSets |
Whether the driver can access multiple result sets returned from batched statements or stored procedures. |
|
QSqlDriver.CancelQuery |
Whether the driver allows cancelling a running query. |
More information about supported features can be found in the Qt SQL driver 文档编制。
另请参阅
PySide2.QtSql.QSqlDriver.
StatementType
¶
This enum contains a list of SQL statement (or clause) types the driver can create.
|
常量 |
描述 |
|---|---|
|
QSqlDriver.WhereStatement |
An SQL
|
|
QSqlDriver.SelectStatement |
An SQL
|
|
QSqlDriver.UpdateStatement |
An SQL
|
|
QSqlDriver.InsertStatement |
An SQL
|
|
QSqlDriver.DeleteStatement |
An SQL
|
另请参阅
PySide2.QtSql.QSqlDriver.
IdentifierType
¶
This enum contains a list of SQL identifier types.
|
常量 |
描述 |
|---|---|
|
QSqlDriver.FieldName |
A SQL field name |
|
QSqlDriver.TableName |
A SQL table name |
PySide2.QtSql.QSqlDriver.
NotificationSource
¶
This enum contains a list of SQL notification sources.
|
常量 |
描述 |
|---|---|
|
QSqlDriver.UnknownSource |
The notification source is unknown |
|
QSqlDriver.SelfSource |
The notification source is this connection |
|
QSqlDriver.OtherSource |
The notification source is another connection |
PySide2.QtSql.QSqlDriver.
DbmsType
¶
This enum contains DBMS types.
|
常量 |
描述 |
|---|---|
|
QSqlDriver.UnknownDbms |
|
|
QSqlDriver.MSSqlServer |
|
|
QSqlDriver.MySqlServer |
|
|
QSqlDriver.PostgreSQL |
|
|
QSqlDriver.Oracle |
|
|
QSqlDriver.Sybase |
|
|
QSqlDriver.SQLite |
|
|
QSqlDriver.Interbase |
|
|
QSqlDriver.DB2 |
PySide2.QtSql.QSqlDriver.
beginTransaction
(
)
¶
bool
This function is called to begin a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns
false
.
PySide2.QtSql.QSqlDriver.
cancelQuery
(
)
¶
bool
Tries to cancel the running query, if the underlying driver has the capability to cancel queries. Returns
true
on success, otherwise false.
This function can be called from a different thread.
If you use this function as a slot, you need to use a
DirectConnection
from a different thread.
Reimplement this function to support canceling running queries in your own
QSqlDriver
subclass. It must be implemented in a thread-safe manner.
另请参阅
PySide2.QtSql.QSqlDriver.
close
(
)
¶
Derived classes must reimplement this pure virtual function in order to close the database connection. Return true on success, false on failure.
PySide2.QtSql.QSqlDriver.
commitTransaction
(
)
¶
bool
This function is called to commit a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns
false
.
PySide2.QtSql.QSqlDriver.
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.
PySide2.QtSql.QSqlDriver.
dbmsType
(
)
¶
Returns the current DBMS type for the database connection.
PySide2.QtSql.QSqlDriver.
escapeIdentifier
(
identifier
,
type
)
¶
identifier – unicode
type
–
IdentifierType
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.
PySide2.QtSql.QSqlDriver.
formatValue
(
field
[
,
trimStrings=false
]
)
¶
field
–
QSqlField
trimStrings
–
bool
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:
若
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.
若
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.
若
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.
另请参阅
toString()
PySide2.QtSql.QSqlDriver.
hasFeature
(
f
)
¶
f
–
DriverFeature
bool
返回
true
if the driver supports feature
feature
;否则返回
false
.
Note that some databases need to be
open()
before this can be determined.
另请参阅
DriverFeature
PySide2.QtSql.QSqlDriver.
isIdentifierEscaped
(
identifier
,
type
)
¶
identifier – unicode
type
–
IdentifierType
bool
Returns whether
identifier
is escaped according to the database rules.
identifier
can either be a table name or field name, dependent on
type
.
Reimplement this function if you want to provide your own implementation in your
QSqlDriver
子类,
PySide2.QtSql.QSqlDriver.
isOpen
(
)
¶
bool
返回
true
if the database connection is open; otherwise returns false.
PySide2.QtSql.QSqlDriver.
isOpenError
(
)
¶
bool
返回
true
if the there was an error opening the database connection; otherwise returns
false
.
PySide2.QtSql.QSqlDriver.
lastError
(
)
¶
返回
QSqlError
object which contains information about the last error that occurred on the database.
另请参阅
PySide2.QtSql.QSqlDriver.
notification
(
name
)
¶
name – unicode
注意
此函数被弃用。
PySide2.QtSql.QSqlDriver.
notification
(
name
,
source
,
payload
)
¶
name – unicode
source
–
NotificationSource
payload – object
PySide2.QtSql.QSqlDriver.
numericalPrecisionPolicy
(
)
¶
NumericalPrecisionPolicy
Returns the current default precision policy for the database connection.
另请参阅
NumericalPrecisionPolicy
setNumericalPrecisionPolicy()
numericalPrecisionPolicy()
setNumericalPrecisionPolicy()
PySide2.QtSql.QSqlDriver.
open
(
db
[
,
user=""
[
,
password=""
[
,
host=""
[
,
port=-1
[
,
connOpts=""
]
]
]
]
]
)
¶
db – unicode
user – unicode
password – unicode
host – unicode
port
–
int
connOpts – unicode
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.
另请参阅
PySide2.QtSql.QSqlDriver.
primaryIndex
(
tableName
)
¶
tableName – unicode
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.
PySide2.QtSql.QSqlDriver.
record
(
tableName
)
¶
tableName – unicode
返回
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.
PySide2.QtSql.QSqlDriver.
rollbackTransaction
(
)
¶
bool
This function is called to rollback a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns
false
.
PySide2.QtSql.QSqlDriver.
setLastError
(
e
)
¶
e
–
QSqlError
This function is used to set the value of the last error,
error
, that occurred on the database.
另请参阅
PySide2.QtSql.QSqlDriver.
setNumericalPrecisionPolicy
(
precisionPolicy
)
¶
precisionPolicy
–
NumericalPrecisionPolicy
Sets the default numerical precision policy used by queries created by this driver to
precisionPolicy
.
Note: Setting the default precision policy to
precisionPolicy
doesn’t affect any currently active queries.
另请参阅
NumericalPrecisionPolicy
numericalPrecisionPolicy()
setNumericalPrecisionPolicy()
numericalPrecisionPolicy()
PySide2.QtSql.QSqlDriver.
setOpen
(
o
)
¶
o
–
bool
This function sets the open state of the database to
open
. Derived classes can use this function to report the status of
open()
.
另请参阅
PySide2.QtSql.QSqlDriver.
setOpenError
(
e
)
¶
e
–
bool
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()
返回
false
).
另请参阅
PySide2.QtSql.QSqlDriver.
sqlStatement
(
type
,
tableName
,
rec
,
preparedStatement
)
¶
type
–
StatementType
tableName – unicode
rec
–
QSqlRecord
preparedStatement
–
bool
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.
The generated flag in each field of
rec
determines whether the field is included in the generated statement.
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.
In the WHERE statement, each non-null field of
rec
specifies a filter condition of equality to the field value, or if prepared, a placeholder. However, prepared or not, a null field specifies the condition IS NULL and never introduces a placeholder. The application must not attempt to bind data for the null field during execution. The field must be set to some non-null value if a placeholder is desired. Furthermore, since non-null fields specify equality conditions and SQL NULL is not equal to anything, even itself, it is generally not useful to bind a null to a placeholder.
PySide2.QtSql.QSqlDriver.
stripDelimiters
(
identifier
,
type
)
¶
identifier – unicode
type
–
IdentifierType
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.
Reimplement this function if you want to provide your own implementation in your
QSqlDriver
子类,
PySide2.QtSql.QSqlDriver.
subscribeToNotification
(
name
)
¶
name – unicode
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
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()
信号被发射。
Reimplement this function if you want to provide event notification support in your own
QSqlDriver
子类,
PySide2.QtSql.QSqlDriver.
subscribedToNotifications
(
)
¶
字符串列表
Returns a list of the names of the event notifications that are currently subscribed to.
Reimplement this function if you want to provide event notification support in your own
QSqlDriver
子类,
PySide2.QtSql.QSqlDriver.
tables
(
tableType
)
¶
tableType
–
TableType
字符串列表
Returns a list of the names of the tables in the database. The default implementation returns an empty list.
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
Tables
for backward compatibility.
PySide2.QtSql.QSqlDriver.
unsubscribeFromNotification
(
name
)
¶
name – unicode
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
close()
函数被调用。
After calling
this
function the
notification()
signal will no longer be emitted when an event notification identified by
name
is posted by the database.
Reimplement this function if you want to provide event notification support in your own
QSqlDriver
子类,