The QSqlError class provides SQL database error information. More...
| Header: | #include <QSqlError> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Sql)target_link_libraries(mytarget PRIVATE Qt6::Sql) |
| qmake: | QT += sql |
| 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 |
A QSqlError object can provide database-specific error data, including the driverText() and databaseText() messages (or both concatenated together as text()), and the nativeErrorCode() and type().
See also QSqlDatabase::lastError() and QSqlQuery::lastError().
This enum type describes the context in which the error occurred, e.g., a connection error, a statement error, etc.
| Constant | Value | Description |
|---|---|---|
QSqlError::NoError |
0 |
No error occurred. |
QSqlError::ConnectionError |
1 |
Connection error. |
QSqlError::StatementError |
2 |
SQL statement syntax error. |
QSqlError::TransactionError |
3 |
Transaction failed error. |
QSqlError::UnknownError |
4 |
Unknown error. |
Constructs an error containing the driver error text driverText, the database-specific error text databaseText, the type type and the error code code.
Creates a copy of other.
[noexcept] QSqlError::QSqlError(QSqlError &&other)Move-constructs a QSqlError instance, making it point at the same object that other was pointing to.
Note: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.
[noexcept] QSqlError::~QSqlError()Destroys the object and frees any allocated resources.
Returns the text of the error as reported by the database. This may contain database-specific descriptions; it may be empty.
See also driverText() and text().
Returns the text of the error as reported by the driver. This may contain database-specific descriptions. It may also be empty.
See also databaseText() and text().
Returns true if an error is set, otherwise false.
Example:
QSqlQueryModel model; model.setQuery("select * from myTable"); if (model.lastError().isValid()) qDebug() << model.lastError();
See also type().
Returns the database-specific error code, or an empty string if it cannot be determined.
Note: Some drivers (like DB2 or ODBC) may return more than one error code. When this happens, ; is used as separator between the error codes.
[noexcept] void QSqlError::swap(QSqlError &other)Swaps this error with other. This operation is very fast and never fails.
This is a convenience function that returns databaseText() and driverText() concatenated into a single string.
See also driverText() and databaseText().
Returns the error type, or -1 if the type cannot be determined.
Compare the other error's type() and nativeErrorCode() to this error and returns true
if it is not equal.
[noexcept] QSqlError &QSqlError::operator=(QSqlError &&other)Move-assigns other to this QSqlError instance.
Note: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.
Assigns the other error's values to this error.
Compare the other error's type() and nativeErrorCode() to this error and returns true,
if it equal.