|  | Home · All Classes · Modules

# QSqlError Class Reference
[QtSql module]

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

### Types

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

### Methods

- __init__ (self, QStringQString driverText = QString(), QStringQString databaseText = QString(), ErrorType type = QSqlError.NoError, int number = -1)
- __init__ (self, QSqlError)
- QStringQString databaseText (self)
- QStringQString driverText (self)
- bool isValid (self)
- int number (self)
- setDatabaseText (self, QStringQString)
- setDriverText (self, QStringQString)
- setNumber (self, int)
- setType (self, ErrorType)
- QStringQString text (self)
- ErrorType type (self)

## Detailed Description

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

See also QSqlDatabase.lastError() and QSqlQuery.lastError().

## Type Documentation

### QSqlError.ErrorType

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

Constant | Value | Description
--- | --- | ---
`QSqlError.NoError` | `0` | No error occurred.
`QSqlError.ConnectionError` | `1` | Connection error.
`QSqlError.StatementError` | `2` | SQL statement syntax error.
`QSqlError.TransactionError` | `3` | Transaction failed error.
`QSqlError.UnknownError` | `4` | Unknown error.

## Method Documentation

### QSqlError.__init__ (self, QStringQString driverText = QString(), QStringQString 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)

Creates a copy of other.

### QStringQString QSqlError.databaseText (self)

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

See also setDatabaseText(), driverText(), and text().

### QStringQString 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.

See also setDriverText(), databaseText(), and text().

### bool QSqlError.isValid (self)

Returns true if an error is set, otherwise false.

Example:

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

See also type().

### int QSqlError.number (self)

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

See also setNumber().

### QSqlError.setDatabaseText (self, QStringQString)

Sets the database error text to the value of databaseText.

See also databaseText(), setDriverText(), and text().

### QSqlError.setDriverText (self, QStringQString)

Sets the driver error text to the value of driverText.

See also driverText(), setDatabaseText(), and text().

### QSqlError.setNumber (self, int)

Sets the database-specific error number to number.

See also number().

### QSqlError.setType (self, ErrorType)

Sets the error type to the value of type.

See also type().

### QStringQString QSqlError.text (self)

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

See also driverText() and databaseText().

### ErrorType QSqlError.type (self)

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

See also setType().