QSqlError Class

The QSqlError class provides SQL database error information. 更多...

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

公共類型

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

公共函數

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

詳細描述

A QSqlError object can provide database-specific error data, including the driverText () 和 databaseText () messages (or both concatenated together as text ()), and the nativeErrorCode () 和 type ().

另請參閱 QSqlDatabase::lastError () 和 QSqlQuery::lastError ().

成員類型文檔編製

enum QSqlError:: ErrorType

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

常量 描述
QSqlError::NoError 0 沒有齣現錯誤。
QSqlError::ConnectionError 1 Connection error.
QSqlError::StatementError 2 SQL statement syntax error.
QSqlError::TransactionError 3 Transaction failed error.
QSqlError::UnknownError 4 Unknown error.

成員函數文檔編製

QSqlError:: QSqlError ( QSqlError && other )

Move-constructs a QSqlError instance, making it point at the same object that other 所指嚮的。

注意: 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.

該函數在 Qt 5.10 引入。

QSqlError:: QSqlError (const QSqlError & other )

創建副本為 other .

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:: operator= ( QSqlError && other )

移動賦值 other 到此 QSqlError 實例。

注意: 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.

該函數在 Qt 5.10 引入。

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

賦值 other error's values to this error.

QSqlError:: ~QSqlError ()

銷毀對象並釋放任何分配資源。

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.

另請參閱 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.

另請參閱 setDriverText (), databaseText (),和 text ().

bool QSqlError:: isValid () const

返迴 true if an error is set, otherwise false.

範例:

QSqlQueryModel model;
model.setQuery("select * from myTable");
if (model.lastError().isValid())
    qDebug() << model.lastError();
					

另請參閱 type ().

QString QSqlError:: nativeErrorCode () const

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

void QSqlError:: swap ( QSqlError & other )

Swaps error other with this error. This operation is very fast and never fails.

該函數在 Qt 5.10 引入。

QString QSqlError:: text () const

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

另請參閱 driverText () 和 databaseText ().

QSqlError::ErrorType QSqlError:: type () const

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

另請參閱 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.

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

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