QSqlError Class
The QSqlError class provides SQL database error information. More…
| Header | #include <QSqlError> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Sql) |
| Module | Nt SQL C++ Classes |
List of all members, including inherited members
Public Types
| enum | ErrorType |
Public Functions
| QSqlError(const QString &driverText = QString(), const QString &databaseText = QString(), ErrorType type = NoError, const QString &nativeErrorCode = QString()) | |
| QString | driverText() const |
| QString | databaseText() const |
| ErrorType | type() const |
| QString | nativeErrorCode() const |
| QString | text() const |
| bool | isValid() const |
| void | swap(QSqlError &other) |
Detailed Description
A QSqlError tells what went wrong with a connection or a statement. It has a type(), the message of the driver (driverText()), the message of the database itself (databaseText()) and the error code of the database (nativeErrorCode()). text() joins the two messages.
QSqlQuery query;
if (!query.exec("SELECT nme FROM people"))
qWarning() << query.lastError().text();
See also QSqlDatabase::lastError() and QSqlQuery::lastError().
Differences from Qt
None.
Member Type Documentation
enum QSqlError::ErrorType
The kind of an error.
| Constant | Description |
|---|---|
QSqlError::NoError | No error happened. |
QSqlError::ConnectionError | The connection could not be opened, or was lost. |
QSqlError::StatementError | An SQL statement had a syntax error or could not be run. |
QSqlError::TransactionError | A transaction could not be started, committed or rolled back. |
QSqlError::UnknownError | Another error. |
Member Function Documentation
QSqlError::QSqlError(const QString &driverText = QString(), const QString &databaseText = QString(), ErrorType type = NoError, const QString &nativeErrorCode = QString())
Constructs an error with the message of the driver driverText, the message of the database databaseText, the type and the error code of the database nativeErrorCode.
QString QSqlError::databaseText() const
Returns the message of the database. It says why the operation failed.
See also driverText() and text().
QString QSqlError::driverText() const
Returns the message of the driver. It says which operation failed.
See also databaseText() and text().
bool QSqlError::isValid() const
Returns true if an error is set, that is if type() is not NoError; otherwise returns false.
QString QSqlError::nativeErrorCode() const
Returns the error code of the database, or an empty string if it gave none. For SQLite this is the extended result code as a number.
void QSqlError::swap(QSqlError &other)
Swaps this error with other.
QString QSqlError::text() const
Returns the message of the database and the message of the driver, joined by a space.
See also driverText() and databaseText().
ErrorType QSqlError::type() const
Returns the kind of the error, or NoError if there is none.