Qt 4.8
Public Types | Public Functions | Properties | List of all members
QSqlError Class Reference

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

#include <qsqlerror.h>

Public Types

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

Public Functions

QString databaseText () const
 Returns the text of the error as reported by the database. More...
 
QString driverText () const
 Returns the text of the error as reported by the driver. More...
 
bool isValid () const
 Returns true if an error is set, otherwise false. More...
 
int number () const
 Returns the database-specific error number, or -1 if it cannot be determined. More...
 
QSqlErroroperator= (const QSqlError &other)
 Assigns the other error's values to this error. More...
 
 QSqlError (const QString &driverText=QString(), const QString &databaseText=QString(), ErrorType type=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. More...
 
 QSqlError (const QSqlError &other)
 Creates a copy of other. More...
 
void setDatabaseText (const QString &databaseText)
 Sets the database error text to the value of databaseText. More...
 
void setDriverText (const QString &driverText)
 Sets the driver error text to the value of driverText. More...
 
void setNumber (int number)
 Sets the database-specific error number to number. More...
 
void setType (ErrorType type)
 Sets the error type to the value of type. More...
 
QString text () const
 This is a convenience function that returns databaseText() and driverText() concatenated into a single string. More...
 
ErrorType type () const
 Returns the error type, or -1 if the type cannot be determined. More...
 
 ~QSqlError ()
 Destroys the object and frees any allocated resources. More...
 

Properties

QString databaseError
 
QString driverError
 
int errorNumber
 
ErrorType errorType
 

Detailed Description

The QSqlError class provides SQL database error information.

Attention
Module: QtSql

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

Definition at line 53 of file qsqlerror.h.

Enumerations

◆ ErrorType

This enum type describes the context in which the error occurred, e.

g., a connection error, a statement error, etc.

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

\arg \e None
\arg \e Connection
\arg \e Statement
\arg \e Transaction
\arg \e Unknown
Enumerator
NoError 
ConnectionError 
StatementError 
TransactionError 
UnknownError 

Definition at line 56 of file qsqlerror.h.

56  {
57  NoError,
62 #ifdef QT3_SUPPORT
63  , None = NoError,
64  Connection = ConnectionError,
65  Statement = StatementError,
66  Transaction = TransactionError,
67  Unknown = UnknownError
68 #endif
69  };
#define None

Constructors and Destructors

◆ QSqlError() [1/2]

QSqlError::QSqlError ( const QString driverText = QString(),
const QString databaseText = QString(),
ErrorType  type = 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.

Definition at line 103 of file qsqlerror.cpp.

105  : driverError(driverText), databaseError(databaseText), errorType(type), errorNumber(number)
106 {
107 }
ErrorType type() const
Returns the error type, or -1 if the type cannot be determined.
Definition: qsqlerror.cpp:191
ErrorType errorType
Definition: qsqlerror.h:92
int errorNumber
Definition: qsqlerror.h:93
QString driverError
Definition: qsqlerror.h:90
QString databaseError
Definition: qsqlerror.h:91
int number() const
Returns the database-specific error number, or -1 if it cannot be determined.
Definition: qsqlerror.cpp:214

◆ QSqlError() [2/2]

QSqlError::QSqlError ( const QSqlError other)

Creates a copy of other.

Definition at line 112 of file qsqlerror.cpp.

114  errorType(other.errorType),
115  errorNumber(other.errorNumber)
116 {
117 }
ErrorType errorType
Definition: qsqlerror.h:92
int errorNumber
Definition: qsqlerror.h:93
QString driverError
Definition: qsqlerror.h:90
QString databaseError
Definition: qsqlerror.h:91

◆ ~QSqlError()

QSqlError::~QSqlError ( )

Destroys the object and frees any allocated resources.

Definition at line 136 of file qsqlerror.cpp.

137 {
138 }

Functions

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

Definition at line 169 of file qsqlerror.cpp.

Referenced by QSQLiteDriver::beginTransaction(), QSQLiteDriver::commitTransaction(), operator<<(), QSQLiteDriver::rollbackTransaction(), and setDatabaseText().

170 {
171  return databaseError;
172 }
QString databaseError
Definition: qsqlerror.h:91

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

Definition at line 146 of file qsqlerror.cpp.

Referenced by operator<<(), and setDriverText().

147 {
148  return driverError;
149 }
QString driverError
Definition: qsqlerror.h:90

◆ isValid()

bool QSqlError::isValid ( ) const

Returns true if an error is set, otherwise false.

Example:

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

Definition at line 254 of file qsqlerror.cpp.

Referenced by QSqlTableModel::select(), and QSqlQueryModel::setQuery().

255 {
256  return errorType != NoError;
257 }
ErrorType errorType
Definition: qsqlerror.h:92

◆ number()

int QSqlError::number ( ) const

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

See also
setNumber()

Definition at line 214 of file qsqlerror.cpp.

Referenced by operator<<(), and setNumber().

215 {
216  return errorNumber;
217 }
int errorNumber
Definition: qsqlerror.h:93

◆ operator=()

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

Assigns the other error's values to this error.

Definition at line 123 of file qsqlerror.cpp.

124 {
125  driverError = other.driverError;
127  errorType = other.errorType;
128  errorNumber = other.errorNumber;
129  return *this;
130 }
ErrorType errorType
Definition: qsqlerror.h:92
int errorNumber
Definition: qsqlerror.h:93
QString driverError
Definition: qsqlerror.h:90
QString databaseError
Definition: qsqlerror.h:91

◆ setDatabaseText()

void QSqlError::setDatabaseText ( const QString databaseText)

Sets the database error text to the value of databaseText.

See also
databaseText() setDriverText() text()

Definition at line 180 of file qsqlerror.cpp.

181 {
183 }
QString databaseText() const
Returns the text of the error as reported by the database.
Definition: qsqlerror.cpp:169
QString databaseError
Definition: qsqlerror.h:91

◆ setDriverText()

void QSqlError::setDriverText ( const QString driverText)

Sets the driver error text to the value of driverText.

See also
driverText() setDatabaseText() text()

Definition at line 157 of file qsqlerror.cpp.

158 {
160 }
QString driverText() const
Returns the text of the error as reported by the driver.
Definition: qsqlerror.cpp:146
QString driverError
Definition: qsqlerror.h:90

◆ setNumber()

void QSqlError::setNumber ( int  number)

Sets the database-specific error number to number.

See also
number()

Definition at line 225 of file qsqlerror.cpp.

226 {
228 }
int errorNumber
Definition: qsqlerror.h:93
int number() const
Returns the database-specific error number, or -1 if it cannot be determined.
Definition: qsqlerror.cpp:214

◆ setType()

void QSqlError::setType ( ErrorType  type)

Sets the error type to the value of type.

See also
type()

Definition at line 202 of file qsqlerror.cpp.

203 {
204  errorType = type;
205 }
ErrorType type() const
Returns the error type, or -1 if the type cannot be determined.
Definition: qsqlerror.cpp:191
ErrorType errorType
Definition: qsqlerror.h:92

◆ 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 237 of file qsqlerror.cpp.

Referenced by QSqlDatabasePrivate::database(), and qmlsqldatabase_executeSql().

238 {
239  QString result = databaseError;
241  result += QLatin1Char(' ');
242  result += driverError;
243  return result;
244 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString driverError
Definition: qsqlerror.h:90
QString databaseError
Definition: qsqlerror.h:91
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ type()

QSqlError::ErrorType QSqlError::type ( ) const

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

See also
setType()

Definition at line 191 of file qsqlerror.cpp.

Referenced by setType().

192 {
193  return errorType;
194 }
ErrorType errorType
Definition: qsqlerror.h:92

Properties

◆ databaseError

QString QSqlError::databaseError
private

Definition at line 91 of file qsqlerror.h.

Referenced by databaseText(), operator=(), setDatabaseText(), and text().

◆ driverError

QString QSqlError::driverError
private

Definition at line 90 of file qsqlerror.h.

Referenced by driverText(), operator=(), setDriverText(), and text().

◆ errorNumber

int QSqlError::errorNumber
private

Definition at line 93 of file qsqlerror.h.

Referenced by number(), operator=(), and setNumber().

◆ errorType

ErrorType QSqlError::errorType
private

Definition at line 92 of file qsqlerror.h.

Referenced by isValid(), operator=(), setType(), and type().


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