QSqlError Class
QSqlError 类提供 SQL 数据库错误信息。更多
Header: | #include <QSqlError> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Sql) target_link_libraries(mytarget PRIVATE Qt6::Sql) |
qmake: | QT += sql |
- 所有成员(包括继承成员)的列表
- QSqlError 属于数据库类。
公共类型
enum | ErrorType { NoError, ConnectionError, StatementError, TransactionError, UnknownError } |
公共函数
QSqlError(const QString &driverText = QString(), const QString &databaseText = QString(), QSqlError::ErrorType type = NoError, const QString &code = QString()) | |
QSqlError(const QSqlError &other) | |
QSqlError(QSqlError &&other) | |
~QSqlError() | |
QString | databaseText() const |
QString | driverText() const |
bool | isValid() const |
QString | nativeErrorCode() const |
void | swap(QSqlError &other) |
QString | text() const |
QSqlError::ErrorType | type() const |
bool | operator!=(const QSqlError &other) const |
QSqlError & | operator=(QSqlError &&other) |
QSqlError & | operator=(const QSqlError &other) |
bool | operator==(const QSqlError &other) const |
详细说明
QSqlError 对象可提供特定于数据库的错误数据,包括driverText() 和databaseText() 消息(或将二者串联为text() 消息),以及nativeErrorCode() 和type() 消息。
另请参阅 QSqlDatabase::lastError() 和QSqlQuery::lastError()。
成员类型文档
enum QSqlError::ErrorType
该枚举类型描述了发生错误的上下文,如连接错误、语句错误等。
常量 | 值 | 说明 |
---|---|---|
QSqlError::NoError | 0 | 未发生错误。 |
QSqlError::ConnectionError | 1 | 连接错误。 |
QSqlError::StatementError | 2 | SQL 语句语法错误。 |
QSqlError::TransactionError | 3 | 事务失败错误。 |
QSqlError::UnknownError | 4 | 未知错误 |
成员函数文档
QSqlError::QSqlError(const QString &driverText = QString(), const QString &databaseText = QString(), QSqlError::ErrorType type = NoError, const QString &code = QString())
构造一个包含驱动程序错误文本driverText 、特定于数据库的错误文本databaseText 、类型type 和错误代码code 的错误。
QSqlError::QSqlError(const QSqlError &other)
创建other 的副本。
[noexcept]
QSqlError::QSqlError(QSqlError &&other)
Move- 构造一个 QSqlError 实例,使其指向other 所指向的同一对象。
注意: 从移动对象other 将处于部分形成状态,其中唯一有效的操作是销毁和分配新值。
[noexcept]
QSqlError::~QSqlError()
销毁对象并释放已分配的资源。
QString QSqlError::databaseText() const
返回数据库报告的错误文本。其中可能包含特定于数据库的描述;也可能为空。
另请参阅 driverText() 和text()。
QString QSqlError::driverText() const
返回驱动程序报告的错误文本。其中可能包含特定于数据库的描述。也可能为空。
另请参阅 databaseText() 和text()。
bool QSqlError::isValid() const
如果设置了错误,则返回true
,否则返回 false。
示例
QSqlQueryModelmodel; model.setQuery("select * from myTable");if(model.lastError().isValid()) qDebug() << model.lastError();
另请参见 type().
QString QSqlError::nativeErrorCode() const
返回数据库特定的错误代码,如果无法确定,则返回空字符串。
注意: 某些驱动程序(如 DB2 或 ODBC)可能会返回多个错误代码。在这种情况下,;
将用作错误代码之间的分隔符。
[noexcept]
void QSqlError::swap(QSqlError &other)
将此错误与other 互换。该操作速度非常快,从未出现过故障。
QString QSqlError::text() const
这是一个方便函数,用于返回databaseText() 和driverText() 连接成的单个字符串。
另请参阅 driverText() 和databaseText()。
QSqlError::ErrorType QSqlError::type() const
返回错误类型,如果无法确定错误类型,则返回-1。
bool QSqlError::operator!=(const QSqlError &other) const
将other 错误的type() 和nativeErrorCode() 与此错误进行比较,如果不相等,则返回true
。
[noexcept]
QSqlError &QSqlError::operator=(QSqlError &&other)
移动--将other 赋值给此QSqlError 实例。
注意: 从移动对象other 将处于部分形成状态,其中唯一有效的操作是销毁和赋新值。
QSqlError &QSqlError::operator=(const QSqlError &other)
将other 错误的值赋值给该错误。
bool QSqlError::operator==(const QSqlError &other) const
将other 错误的type() 和nativeErrorCode() 与此错误进行比较,如果相同,则返回true
。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.