QSqlError Class Reference

[ QtSql module]

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

类型

方法


详细描述

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 error number () 和 type (). The functions all have setters so that you can create and return QSqlError objects from your own classes, for example from your own SQL drivers.


类型文档编制

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.__init__ ( self , QString  driverText  = QString(), QString  databaseText  = QString(), ErrorType   type  = QSqlError.NoError, int  number  = -1)

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

QSqlError.__init__ ( self , QSqlError   other )

Creates a copy of other .

QString QSqlError.databaseText ( self )

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

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

Returns true if an error is set, otherwise false.

范例:

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

另请参阅 type ().

int QSqlError.number ( self )

Returns the database-specific error number, or -1 if it cannot be determined.

另请参阅 setNumber ().

QSqlError.setDatabaseText ( self , QString  databaseText )

Sets the database error text to the value of databaseText .

另请参阅 databaseText (), setDriverText (),和 text ().

QSqlError.setDriverText ( self , QString  driverText )

Sets the driver error text to the value of driverText .

另请参阅 driverText (), setDatabaseText (),和 text ().

QSqlError.setNumber ( self , int  number )

Sets the database-specific error number to number .

另请参阅 number ().

QSqlError.setType ( self , ErrorType   type )

Sets the error type to the value of type .

另请参阅 type ().

QString QSqlError.text ( self )

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

另请参阅 driverText () 和 databaseText ().

ErrorType QSqlError.type ( self )

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

另请参阅 setType ().