Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QSqlError Class Reference

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

#include <qsqlerror.h>

+ Collaboration diagram for QSqlError:

Public Types

enum  ErrorType {
  NoError , ConnectionError , StatementError , TransactionError ,
  UnknownError
}
 This enum type describes the context in which the error occurred, e.g., a connection error, a statement error, etc. More...
 

Public Member Functions

 QSqlError (const QString &driverText=QString(), const QString &databaseText=QString(), ErrorType type=NoError, const QString &errorCode=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 (const QSqlError &other)
 Creates a copy of other.
 
 QSqlError (QSqlError &&other) noexcept=default
 Move-constructs a QSqlError instance, making it point at the same object that other was pointing to.
 
QSqlErroroperator= (const QSqlError &other)
 Move-assigns other to this QSqlError instance.
 
 ~QSqlError ()
 Destroys the object and frees any allocated resources.
 
bool operator== (const QSqlError &other) const
 Compare the other error's type() and nativeErrorCode() to this error and returns true, if it equal.
 
bool operator!= (const QSqlError &other) const
 Compare the other error's type() and nativeErrorCode() to this error and returns true if it is not equal.
 
void swap (QSqlError &other) noexcept
 Swaps error other with this error.
 
QString driverText () const
 Returns the text of the error as reported by the driver.
 
QString databaseText () const
 Returns the text of the error as reported by the database.
 
ErrorType type () const
 Returns the error type, or -1 if the type cannot be determined.
 
QString nativeErrorCode () const
 Returns the database-specific error code, or an empty string if it cannot be determined.
 
QString text () const
 This is a convenience function that returns databaseText() and driverText() concatenated into a single string.
 
bool isValid () const
 Returns true if an error is set, otherwise false.
 

Detailed Description

The QSqlError class provides SQL database error information.

\inmodule QtSql

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(), QSqlQuery::lastError()

Definition at line 16 of file qsqlerror.h.

Member Enumeration Documentation

◆ ErrorType

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

\value NoError No error occurred. \value ConnectionError Connection error. \value StatementError SQL statement syntax error. \value TransactionError Transaction failed error. \value UnknownError Unknown error.

Enumerator
NoError 
ConnectionError 
StatementError 
TransactionError 
UnknownError 

Definition at line 19 of file qsqlerror.h.

Constructor & Destructor Documentation

◆ QSqlError() [1/3]

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

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

Definition at line 92 of file qsqlerror.cpp.

References d.

◆ QSqlError() [2/3]

QSqlError::QSqlError ( const QSqlError & other)
default

Creates a copy of other.

◆ QSqlError() [3/3]

QSqlError::QSqlError ( QSqlError && other)
defaultnoexcept

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.
Since
5.10

◆ ~QSqlError()

QSqlError::~QSqlError ( )
default

Destroys the object and frees any allocated resources.

Member Function Documentation

◆ databaseText()

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
driverText(), text()

Definition at line 166 of file qsqlerror.cpp.

References QSqlErrorPrivate::databaseError.

◆ driverText()

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
databaseText(), text()

Definition at line 154 of file qsqlerror.cpp.

References QSqlErrorPrivate::driverError.

◆ isValid()

bool QSqlError::isValid ( ) const

Returns true if an error is set, otherwise false.

Example:

model.setQuery("select * from myTable");
See also
type()

Definition at line 217 of file qsqlerror.cpp.

References QSqlErrorPrivate::errorType, and NoError.

Referenced by checkSqlQueryModel(), MyModel::fetchModel(), and QSqlQuery::isValid().

+ Here is the caller graph for this function:

◆ nativeErrorCode()

QString QSqlError::nativeErrorCode ( ) const

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.

Definition at line 188 of file qsqlerror.cpp.

References QSqlErrorPrivate::errorCode.

◆ operator!=()

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

Compare the other error's type() and nativeErrorCode() to this error and returns true if it is not equal.

Definition at line 134 of file qsqlerror.cpp.

References QSqlErrorPrivate::errorCode, QSqlErrorPrivate::errorType, and other().

+ Here is the call graph for this function:

◆ operator=()

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

Move-assigns other to this QSqlError instance.

Assigns the other error's values to this error.

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.
Since
5.10

◆ operator==()

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

Compare the other error's type() and nativeErrorCode() to this error and returns true, if it equal.

Definition at line 122 of file qsqlerror.cpp.

References QSqlErrorPrivate::errorCode, QSqlErrorPrivate::errorType, and other().

+ Here is the call graph for this function:

◆ swap()

QSqlError::swap ( QSqlError & other)
inlinenoexcept

Swaps error other with this error.

This operation is very fast and never fails.

Since
5.10

Definition at line 39 of file qsqlerror.h.

References d, and other().

+ Here is the call graph for this function:

◆ text()

QString QSqlError::text ( ) const

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

See also
driverText(), databaseText()

Definition at line 200 of file qsqlerror.cpp.

References QSqlErrorPrivate::databaseError, QSqlErrorPrivate::driverError, QString::endsWith(), and QString::isEmpty().

+ Here is the call graph for this function:

◆ type()

QSqlError::ErrorType QSqlError::type ( ) const

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

Definition at line 175 of file qsqlerror.cpp.

References QSqlErrorPrivate::errorType.

Referenced by QOCIResult::execBatch().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: