1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the sql module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qsqlerror.h"
32
#ifndef QT_NO_DEBUG_STREAM
33
QDebug operator<<(QDebug dbg, const QSqlError &s)
35
dbg.nospace() << "QSqlError(" << s.number() << ", \"" << s.driverText() <<
36
"\", \"" << s.databaseText() << "\")";
43
\brief The QSqlError class provides SQL database error information.
48
A QSqlError object can provide database-specific error data,
49
including the driverText() and databaseText() messages (or both
50
concatenated together as text()), and the error number() and
51
type(). The functions all have setters so that you can create and
52
return QSqlError objects from your own classes, for example from
55
\sa QSqlDatabase::lastError(), QSqlQuery::lastError()
59
\enum QSqlError::ErrorType
61
This enum type describes the type of SQL error that occurred.
63
\value NoError No error occurred.
64
\value ConnectionError Connection error.
65
\value StatementError SQL statement syntax error.
66
\value TransactionError Transaction failed error.
67
\value UnknownError Unknown error.
72
\omitvalue Transaction
77
Constructs an error containing the driver error text \a
78
driverText, the database-specific error text \a databaseText, the
79
type \a type and the optional error number \a number.
82
QSqlError::QSqlError(const QString& driverText, const QString& databaseText, ErrorType type,
84
: driverError(driverText), databaseError(databaseText), errorType(type), errorNumber(number)
89
Creates a copy of \a other.
91
QSqlError::QSqlError(const QSqlError& other)
92
: driverError(other.driverError), databaseError(other.databaseError),
93
errorType(other.errorType),
94
errorNumber(other.errorNumber)
99
Assigns the \a other error's values to this error.
102
QSqlError& QSqlError::operator=(const QSqlError& other)
104
driverError = other.driverError;
105
databaseError = other.databaseError;
106
errorType = other.errorType;
107
errorNumber = other.errorNumber;
112
Destroys the object and frees any allocated resources.
115
QSqlError::~QSqlError()
120
Returns the text of the error as reported by the driver. This may
121
contain database-specific descriptions. It may also be empty.
123
\sa setDriverText() databaseText() text()
125
QString QSqlError::driverText() const
131
Sets the driver error text to the value of \a driverText.
133
\sa driverText() setDatabaseText() text()
136
void QSqlError::setDriverText(const QString& driverText)
138
driverError = driverText;
142
Returns the text of the error as reported by the database. This
143
may contain database-specific descriptions; it may be empty.
145
\sa setDatabaseText() driverText() text()
148
QString QSqlError::databaseText() const
150
return databaseError;
154
Sets the database error text to the value of \a databaseText.
156
\sa databaseText() setDriverText() text()
159
void QSqlError::setDatabaseText(const QString& databaseText)
161
databaseError = databaseText;
165
Returns the error type, or -1 if the type cannot be determined.
170
QSqlError::ErrorType QSqlError::type() const
176
Sets the error type to the value of \a type.
181
void QSqlError::setType(ErrorType type)
187
Returns the database-specific error number, or -1 if it cannot be
193
int QSqlError::number() const
199
Sets the database-specific error number to \a number.
204
void QSqlError::setNumber(int number)
206
errorNumber = number;
210
This is a convenience function that returns databaseText() and
211
driverText() concatenated into a single string.
213
\sa driverText() databaseText()
216
QString QSqlError::text() const
218
QString result = databaseError;
219
if (!databaseError.endsWith(QLatin1String("\n")))
220
result += QLatin1Char(' ');
221
result += driverError;