6.0.0-rc4Source

QSqlError Class

The QSqlError class provides SQL database error information. More…

Header#include <QSqlError>
CMaketarget_link_libraries(app PRIVATE Nt::Sql)
ModuleNt SQL C++ Classes

List of all members, including inherited members

Public Types

enumErrorType

Public Functions

QSqlError(const QString &driverText = QString(), const QString &databaseText = QString(), ErrorType type = NoError, const QString &nativeErrorCode = QString())
QStringdriverText() const
QStringdatabaseText() const
ErrorTypetype() const
QStringnativeErrorCode() const
QStringtext() const
boolisValid() const
voidswap(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.

ConstantDescription
QSqlError::NoErrorNo error happened.
QSqlError::ConnectionErrorThe connection could not be opened, or was lost.
QSqlError::StatementErrorAn SQL statement had a syntax error or could not be run.
QSqlError::TransactionErrorA transaction could not be started, committed or rolled back.
QSqlError::UnknownErrorAnother error.

Member Function Documentation

[explicit] 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.