Qt 4.8
qsqlerror.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSql module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qsqlerror.h"
43 #include "qdebug.h"
44 
46 
47 #ifndef QT_NO_DEBUG_STREAM
49 {
50  dbg.nospace() << "QSqlError(" << s.number() << ", " << s.driverText() <<
51  ", " << s.databaseText() << ')';
52  return dbg.space();
53 }
54 #endif
55 
103 QSqlError::QSqlError(const QString& driverText, const QString& databaseText, ErrorType type,
104  int number)
105  : driverError(driverText), databaseError(databaseText), errorType(type), errorNumber(number)
106 {
107 }
108 
114  errorType(other.errorType),
115  errorNumber(other.errorNumber)
116 {
117 }
118 
124 {
125  driverError = other.driverError;
127  errorType = other.errorType;
128  errorNumber = other.errorNumber;
129  return *this;
130 }
131 
137 {
138 }
139 
147 {
148  return driverError;
149 }
150 
158 {
160 }
161 
170 {
171  return databaseError;
172 }
173 
181 {
183 }
184 
192 {
193  return errorType;
194 }
195 
203 {
204  errorType = type;
205 }
206 
214 int QSqlError::number() const
215 {
216  return errorNumber;
217 }
218 
226 {
228 }
229 
238 {
239  QString result = databaseError;
241  result += QLatin1Char(' ');
242  result += driverError;
243  return result;
244 }
245 
254 bool QSqlError::isValid() const
255 {
256  return errorType != NoError;
257 }
258 
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
QString text() const
This is a convenience function that returns databaseText() and driverText() concatenated into a singl...
Definition: qsqlerror.cpp:237
ErrorType type() const
Returns the error type, or -1 if the type cannot be determined.
Definition: qsqlerror.cpp:191
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString driverText() const
Returns the text of the error as reported by the driver.
Definition: qsqlerror.cpp:146
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 dat...
Definition: qsqlerror.cpp:103
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
ErrorType errorType
Definition: qsqlerror.h:92
QSqlError & operator=(const QSqlError &other)
Assigns the other error&#39;s values to this error.
Definition: qsqlerror.cpp:123
The QString class provides a Unicode character string.
Definition: qstring.h:83
~QSqlError()
Destroys the object and frees any allocated resources.
Definition: qsqlerror.cpp:136
ErrorType
This enum type describes the context in which the error occurred, e.
Definition: qsqlerror.h:56
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void setType(ErrorType type)
Sets the error type to the value of type.
Definition: qsqlerror.cpp:202
void setDriverText(const QString &driverText)
Sets the driver error text to the value of driverText.
Definition: qsqlerror.cpp:157
QString databaseText() const
Returns the text of the error as reported by the database.
Definition: qsqlerror.cpp:169
void setNumber(int number)
Sets the database-specific error number to number.
Definition: qsqlerror.cpp:225
bool isValid() const
Returns true if an error is set, otherwise false.
Definition: qsqlerror.cpp:254
int errorNumber
Definition: qsqlerror.h:93
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
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
void setDatabaseText(const QString &databaseText)
Sets the database error text to the value of databaseText.
Definition: qsqlerror.cpp:180
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition: qurl.cpp:6757
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
int number() const
Returns the database-specific error number, or -1 if it cannot be determined.
Definition: qsqlerror.cpp:214