QSqlError Class

The QSqlError class provides SQL database error information. More...

Header: #include <QSqlError>
qmake: QT += sql

Public Types

enum ErrorType { NoError, ConnectionError, StatementError, TransactionError, UnknownError }

Public Functions

QSqlError(const QString & driverText = QString(), const QString & databaseText = QString(), ErrorType type = NoError, const QString & code = QString())
QSqlError(const QSqlError & other)
~QSqlError()
QString databaseText() const
QString driverText() const
bool isValid() const
QString nativeErrorCode() const
QString text() const
ErrorType type() const
bool operator!=(const QSqlError & other) const
QSqlError & operator=(const QSqlError & other)
bool operator==(const QSqlError & other) const

Detailed Description

The QSqlError class provides SQL database error information.

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().

Member Type Documentation

enum QSqlError::​ErrorType

This enum type describes the context in which the error occurred, e.g., a connection error, a statement error, etc.

ConstantValueDescription
QSqlError::NoError0No error occurred.
QSqlError::ConnectionError1Connection error.
QSqlError::StatementError2SQL statement syntax error.
QSqlError::TransactionError3Transaction failed error.
QSqlError::UnknownError4Unknown error.

Member Function Documentation

QSqlError::​QSqlError(const QString & driverText = QString(), const QString & databaseText = QString(), ErrorType type = NoError, const QString & code = QString())

Constructs an error containing the driver error text driverText, the database-specific error text databaseText, the type type and the error code code.

QSqlError::​QSqlError(const QSqlError & other)

Creates a copy of other.

QSqlError::​~QSqlError()

Destroys the object and frees any allocated resources.

QString QSqlError::​databaseText() const

Returns the text of the error as reported by the database. This may contain database-specific descriptions; it may be empty.

See also setDatabaseText(), driverText(), and text().

QString QSqlError::​driverText() const

Returns the text of the error as reported by the driver. This may contain database-specific descriptions. It may also be empty.

See also setDriverText(), databaseText(), and text().

bool QSqlError::​isValid() const

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().

QString QSqlError::​nativeErrorCode() const

Returns the database-specific error code, or an empty string if it cannot be determined.

QString QSqlError::​text() const

This is a convenience function that returns databaseText() and driverText() concatenated into a single string.

See also driverText() and databaseText().

ErrorType QSqlError::​type() const

Returns the error type, or -1 if the type cannot be determined.

See also setType().

bool QSqlError::​operator!=(const QSqlError & other) const

Compare the other error's values to this error and returns true if it is not equal.

QSqlError & QSqlError::​operator=(const QSqlError & other)

Assigns the other error's values to this error.

bool QSqlError::​operator==(const QSqlError & other) const

Compare the other error's values to this error and returns true, if it equal.

© 2015 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.