PySide6.QtSql.QSqlError¶
- class QSqlError¶
QSqlError
类提供了 SQL 数据库错误信息。更多…概要¶
方法¶
def
__init__()
def
databaseText()
def
driverText()
def
isValid()
def
__ne__()
def
__eq__()
def
swap()
def
text()
def
type()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
一个
QSqlError
对象可以提供数据库特定的错误数据,包括driverText()
和databaseText()
消息(或两者连接在一起作为text()
),以及nativeErrorCode()
和type()
。另请参阅
- class ErrorType¶
此枚举类型描述了错误发生的上下文,例如,连接错误、语句错误等。
常量
描述
QSqlError.NoError
没有发生错误。
QSqlError.ConnectionError
连接错误。
QSqlError.StatementError
SQL语句语法错误。
QSqlError.TransactionError
事务失败错误。
QSqlError.UnknownError
未知错误。
创建
other
的副本。- __init__([driverText=""[, databaseText=""[, type=QSqlError.ErrorType.NoError[, errorCode=""]]]])
- Parameters:
driverText – str
databaseText – str
type –
ErrorType
errorCode – str
构造一个包含驱动程序错误文本
driverText
、数据库特定错误文本databaseText
、类型type
和错误代码code
的错误。- databaseText()¶
- Return type:
字符串
返回数据库报告的错误文本。这可能包含特定于数据库的描述;它可能为空。
另请参阅
- driverText()¶
- Return type:
字符串
返回驱动程序报告的错误文本。这可能包含特定于数据库的描述。它也可能是空的。
另请参阅
- isValid()¶
- Return type:
布尔
警告
本节包含从C++自动翻译到Python的代码片段,可能包含错误。
如果设置了错误,则返回
true
,否则返回false。示例:
model = QSqlQueryModel() model.setQuery("select * from myTable") if model.lastError().isValid(): print(model.lastError())
另请参阅
- nativeErrorCode()¶
- Return type:
字符串
返回数据库特定的错误代码,如果无法确定则返回空字符串。
注意
某些驱动程序(如DB2或ODBC)可能会返回多个错误代码。当这种情况发生时,
;
被用作错误代码之间的分隔符。将
other
错误的type()
和nativeErrorCode()
与此错误进行比较,如果不相等则返回true
。比较
other
错误的type()
和nativeErrorCode()
与此错误,如果相等则返回true
。将此错误与
other
错误交换。此操作非常快速且永远不会失败。- text()¶
- Return type:
字符串
这是一个便捷函数,返回
databaseText()
和driverText()
连接成一个字符串的结果。返回错误类型,如果无法确定类型则返回-1。