QSqlError

The QSqlError class provides SQL database error information. More

Inheritance diagram of PySide2.QtSql.QSqlError

Synopsis

Functions

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

class QSqlError(other)

QSqlError([driverText=”“[, databaseText=”“[, type=NoError[, errorCode=”“]]]])

QSqlError(driverText, databaseText, type, number)

Note

This constructor is deprecated.

Parameters
  • typeErrorType

  • driverText – unicode

  • databaseText – unicode

  • otherQSqlError

  • numberint

  • errorCode – unicode

PySide2.QtSql.QSqlError.ErrorType

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

Constant

Description

QSqlError.NoError

No error occurred.

QSqlError.ConnectionError

Connection error.

QSqlError.StatementError

SQL statement syntax error.

QSqlError.TransactionError

Transaction failed error.

QSqlError.UnknownError

Unknown error.

PySide2.QtSql.QSqlError.databaseText()
Return type

unicode

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

PySide2.QtSql.QSqlError.driverText()
Return type

unicode

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

PySide2.QtSql.QSqlError.isValid()
Return type

bool

Returns true if an error is set, otherwise false.

Example:

model = QSqlQueryModel()
model.setQuery("select * from myTable")
if model.lastError().isValid():
    print model.lastError()

See also

type()

PySide2.QtSql.QSqlError.nativeErrorCode()
Return type

unicode

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

PySide2.QtSql.QSqlError.number()
Return type

int

Note

This function is deprecated.

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

Returns 0 if the error code is not an integer.

Warning

Some databases use alphanumeric error codes, which makes unreliable if such a database is used.

Use nativeErrorCode() instead

PySide2.QtSql.QSqlError.__ne__(other)
Parameters

otherQSqlError

Return type

bool

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

PySide2.QtSql.QSqlError.__eq__(other)
Parameters

otherQSqlError

Return type

bool

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

PySide2.QtSql.QSqlError.setDatabaseText(databaseText)
Parameters

databaseText – unicode

Note

This function is deprecated.

Sets the database error text to the value of databaseText .

Use QSqlError (const QString & driverText , const QString & databaseText , ErrorType type, int number) instead

PySide2.QtSql.QSqlError.setDriverText(driverText)
Parameters

driverText – unicode

Note

This function is deprecated.

Sets the driver error text to the value of driverText .

Use QSqlError (const QString & driverText , const QString & databaseText , ErrorType type, int number) instead

PySide2.QtSql.QSqlError.setNumber(number)
Parameters

numberint

Note

This function is deprecated.

Sets the database-specific error number to number .

Use QSqlError (const QString & driverText , const QString & databaseText , ErrorType type, int number) instead

See also

number()

PySide2.QtSql.QSqlError.setType(type)
Parameters

typeErrorType

Note

This function is deprecated.

Sets the error type to the value of type .

Use QSqlError (const QString & driverText , const QString & databaseText , ErrorType type, int number) instead

See also

type()

PySide2.QtSql.QSqlError.swap(other)
Parameters

otherQSqlError

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

PySide2.QtSql.QSqlError.text()
Return type

unicode

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

PySide2.QtSql.QSqlError.type()
Return type

ErrorType

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

See also

setType()