QSqlError Class▲
-
Header: QSqlError
-
qmake: QT += sql
-
Group: QSqlError is part of Database Classes
Detailed Description▲
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▲
See also QSqlDatabase::lastError(), 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.
Member Function Documentation▲
QSqlError::QSqlError(const QString &driverText = QString(), const QString &databaseText = QString(), QSqlError::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.
DB2: It is possible for DB2 to report more than one error code. When this happens, ; is used as separator between the error codes.
QSqlError::QSqlError(const QSqlError &other)▲
Creates a copy of other.
[since 5.10] QSqlError::QSqlError(QSqlError &&other)▲
Move-constructs a QSqlError instance, making it point at the same object that other was pointing to.
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.
This function was introduced in Qt 5.10.
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▲
See also setDatabaseText(), driverText(), 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▲
See also setDriverText(), databaseText(), 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() &
lt;&
lt; model.lastError();
See Also▲
See also type()
QString QSqlError::nativeErrorCode() const▲
Returns the database-specific error code, or an empty string if it cannot be determined.
[since 5.10] void QSqlError::swap(QSqlError &other)▲
Swaps error other with this error. This operation is very fast and never fails.
This function was introduced in Qt 5.10.
QString QSqlError::text() const▲
This is a convenience function that returns databaseText() and driverText() concatenated into a single string.
See Also▲
See also driverText(), databaseText()
QSqlError::ErrorType QSqlError::type() const▲
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.
[since 5.10] QSqlError &QSqlError::operator=(QSqlError &&other)▲
Move-assigns other to this QSqlError instance.
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.
This function was introduced in Qt 5.10.
bool QSqlError::operator==(const QSqlError &other) const▲
Compare the other error's values to this error and returns true, if it equal.
Obsolete Members for QSqlError▲
The following members of class QSqlError are deprecated. We strongly advise against using them in new code.
Obsolete Member Function Documentation▲
QSqlError::QSqlError(const QString &driverText, const QString &databaseText, QSqlError::ErrorType type, int number)▲
This function is deprecated. We strongly advise against using it in new code.
Constructs an error containing the driver error text driverText, the database-specific error text databaseText, the type type and the optional error number number.
int QSqlError::number() const▲
This function is deprecated. We strongly advise against using it in new code.
Returns the database-specific error number, or -1 if it cannot be determined.
Returns 0 if the error code is not an integer.
Some databases use alphanumeric error codes, which makes number() unreliable if such a database is used.
Use nativeErrorCode() instead
See Also▲
See also setNumber(), nativeErrorCode()
void QSqlError::setDatabaseText(const QString &databaseText)▲
This function is deprecated. We strongly advise against using it in new code.
Sets the database error text to the value of databaseText.
Use QSqlError(const QString &driverText, const QString &databaseText, ErrorType type, int number) instead
See Also▲
See also databaseText(), setDriverText(), text()
void QSqlError::setDriverText(const QString &driverText)▲
This function is deprecated. We strongly advise against using it in new code.
Sets the driver error text to the value of driverText.
Use QSqlError(const QString &driverText, const QString &databaseText, ErrorType type, int number) instead
See Also▲
See also driverText(), setDatabaseText(), text()
void QSqlError::setNumber(int number)▲
This function is deprecated. We strongly advise against using it in new code.
Sets the database-specific error number to number.
Use QSqlError(const QString &driverText, const QString &databaseText, ErrorType type, int number) instead
See Also▲
See also number()
void QSqlError::setType(QSqlError::ErrorType type)▲
This function is deprecated. We strongly advise against using it in new code.
Sets the error type to the value of type.
Use QSqlError(const QString &driverText, const QString &databaseText, ErrorType type, int number) instead
See Also▲
See also type()