qsqlerror.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/sql/kernel/qsqlerror.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtSql module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qsqlerror.h"-
35#include "qdebug.h"-
36-
37QT_BEGIN_NAMESPACE-
38-
39#ifndef QT_NO_DEBUG_STREAM-
40QDebug operator<<(QDebug dbg, const QSqlError &s)-
41{-
42 QDebugStateSaver saver(dbg);-
43 dbg.nospace();-
44 dbg << "QSqlError(" << s.nativeErrorCode() << ", " << s.driverText()-
45 << ", " << s.databaseText() << ')';-
46 return dbg;
never executed: return dbg;
0
47}-
48#endif-
49-
50class QSqlErrorPrivate-
51{-
52public:-
53 QString driverError;-
54 QString databaseError;-
55 QSqlError::ErrorType errorType;-
56 QString errorCode;-
57};-
58-
59-
60/*!-
61 \class QSqlError-
62 \brief The QSqlError class provides SQL database error information.-
63-
64 \ingroup database-
65 \inmodule QtSql-
66-
67 A QSqlError object can provide database-specific error data,-
68 including the driverText() and databaseText() messages (or both-
69 concatenated together as text()), and the nativeErrorCode() and-
70 type().-
71-
72 \sa QSqlDatabase::lastError(), QSqlQuery::lastError()-
73*/-
74-
75/*!-
76 \enum QSqlError::ErrorType-
77-
78 This enum type describes the context in which the error occurred, e.g., a connection error, a statement error, etc.-
79-
80 \value NoError No error occurred.-
81 \value ConnectionError Connection error.-
82 \value StatementError SQL statement syntax error.-
83 \value TransactionError Transaction failed error.-
84 \value UnknownError Unknown error.-
85*/-
86-
87/*!-
88 \obsolete-
89-
90 Constructs an error containing the driver error text \a-
91 driverText, the database-specific error text \a databaseText, the-
92 type \a type and the optional error number \a number.-
93*/-
94-
95#if QT_DEPRECATED_SINCE(5, 3)-
96QSqlError::QSqlError(const QString& driverText, const QString& databaseText, ErrorType type,-
97 int number)-
98{-
99 d = new QSqlErrorPrivate;-
100-
101 d->driverError = driverText;-
102 d->databaseError = databaseText;-
103 d->errorType = type;-
104 if (number != -1)
number != -1Description
TRUEevaluated 2 times by 2 tests
Evaluated by:
  • tst_QSqlDatabase
  • tst_qsqlerror - unknown status
FALSEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QSqlDatabase
  • tst_qsqlerror - unknown status
2-3
105 d->errorCode = QString::number(number);
executed 2 times by 2 tests: d->errorCode = QString::number(number);
Executed by:
  • tst_QSqlDatabase
  • tst_qsqlerror - unknown status
2
106}
executed 5 times by 2 tests: end of block
Executed by:
  • tst_QSqlDatabase
  • tst_qsqlerror - unknown status
5
107#endif-
108-
109/*!-
110 Constructs an error containing the driver error text \a-
111 driverText, the database-specific error text \a databaseText, the-
112 type \a type and the error code \a code.-
113*/-
114-
115QSqlError::QSqlError(const QString &driverText, const QString &databaseText,-
116 ErrorType type, const QString &code)-
117{-
118 d = new QSqlErrorPrivate;-
119-
120 d->driverError = driverText;-
121 d->databaseError = databaseText;-
122 d->errorType = type;-
123 d->errorCode = code;-
124}
executed 309827 times by 11 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlerror - unknown status
  • tst_qsqlresult - unknown status
309827
125-
126-
127/*!-
128 Creates a copy of \a other.-
129*/-
130QSqlError::QSqlError(const QSqlError& other)-
131{-
132 d = new QSqlErrorPrivate;-
133-
134 *d = *other.d;-
135}
executed 247768 times by 10 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlerror - unknown status
247768
136-
137/*!-
138 Assigns the \a other error's values to this error.-
139*/-
140-
141QSqlError& QSqlError::operator=(const QSqlError& other)-
142{-
143 *d = *other.d;-
144 return *this;
executed 307318 times by 9 tests: return *this;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
307318
145}-
146-
147/*!-
148 Compare the \a other error's values to this error and returns \c true, if it equal.-
149*/-
150-
151bool QSqlError::operator==(const QSqlError& other) const-
152{-
153 return (d->errorType == other.d->errorType);
executed 1 time by 1 test: return (d->errorType == other.d->errorType);
Executed by:
  • tst_qsqlerror - unknown status
1
154}-
155-
156-
157/*!-
158 Compare the \a other error's values to this error and returns \c true if it is not equal.-
159*/-
160-
161bool QSqlError::operator!=(const QSqlError& other) const-
162{-
163 return (d->errorType != other.d->errorType);
executed 1 time by 1 test: return (d->errorType != other.d->errorType);
Executed by:
  • tst_qsqlerror - unknown status
1
164}-
165-
166-
167/*!-
168 Destroys the object and frees any allocated resources.-
169*/-
170-
171QSqlError::~QSqlError()-
172{-
173 delete d;-
174}
executed 557602 times by 20 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlerror - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqlresult - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
557602
175-
176/*!-
177 Returns the text of the error as reported by the driver. This may-
178 contain database-specific descriptions. It may also be empty.-
179-
180 \sa databaseText(), text()-
181*/-
182QString QSqlError::driverText() const-
183{-
184 return d->driverError;
executed 11607 times by 9 tests: return d->driverError;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlerror - unknown status
11607
185}-
186-
187/*!-
188 \fn void QSqlError::setDriverText(const QString &driverText)-
189 \obsolete-
190-
191 Sets the driver error text to the value of \a driverText.-
192-
193 Use QSqlError(const QString &driverText, const QString &databaseText,-
194 ErrorType type, int number) instead-
195-
196 \sa driverText(), setDatabaseText(), text()-
197*/-
198-
199#if QT_DEPRECATED_SINCE(5, 1)-
200void QSqlError::setDriverText(const QString& driverText)-
201{-
202 d->driverError = driverText;-
203}
never executed: end of block
0
204#endif-
205-
206/*!-
207 Returns the text of the error as reported by the database. This-
208 may contain database-specific descriptions; it may be empty.-
209-
210 \sa driverText(), text()-
211*/-
212-
213QString QSqlError::databaseText() const-
214{-
215 return d->databaseError;
executed 11575 times by 9 tests: return d->databaseError;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlerror - unknown status
11575
216}-
217-
218/*!-
219 \fn void QSqlError::setDatabaseText(const QString &databaseText)-
220 \obsolete-
221-
222 Sets the database error text to the value of \a databaseText.-
223-
224 Use QSqlError(const QString &driverText, const QString &databaseText,-
225 ErrorType type, int number) instead-
226-
227 \sa databaseText(), setDriverText(), text()-
228*/-
229-
230#if QT_DEPRECATED_SINCE(5, 1)-
231void QSqlError::setDatabaseText(const QString& databaseText)-
232{-
233 d->databaseError = databaseText;-
234}
never executed: end of block
0
235#endif-
236-
237/*!-
238 Returns the error type, or -1 if the type cannot be determined.-
239*/-
240-
241QSqlError::ErrorType QSqlError::type() const-
242{-
243 return d->errorType;
executed 22 times by 3 tests: return d->errorType;
Executed by:
  • tst_QSqlQuery
  • tst_QSqlTableModel
  • tst_qsqlerror - unknown status
22
244}-
245-
246/*!-
247 \fn void QSqlError::setType(ErrorType type)-
248 \obsolete-
249-
250 Sets the error type to the value of \a type.-
251-
252 Use QSqlError(const QString &driverText, const QString &databaseText,-
253 ErrorType type, int number) instead-
254-
255 \sa type()-
256*/-
257-
258#if QT_DEPRECATED_SINCE(5, 1)-
259void QSqlError::setType(ErrorType type)-
260{-
261 d->errorType = type;-
262}
executed 8 times by 1 test: end of block
Executed by:
  • tst_qsqlerror - unknown status
8
263#endif-
264-
265/*!-
266 \fn int QSqlError::number() const-
267 \obsolete-
268-
269 Returns the database-specific error number, or -1 if it cannot be-
270 determined.-
271-
272 Returns 0 if the error code is not an integer.-
273-
274 \warning Some databases use alphanumeric error codes, which makes-
275 number() unreliable if such a database is used.-
276-
277 Use nativeErrorCode() instead-
278-
279 \sa nativeErrorCode()-
280*/-
281-
282#if QT_DEPRECATED_SINCE(5, 3)-
283int QSqlError::number() const-
284{-
285 return d->errorCode.isEmpty() ? -1 : d->errorCode.toInt();
executed 12 times by 1 test: return d->errorCode.isEmpty() ? -1 : d->errorCode.toInt();
Executed by:
  • tst_qsqlerror - unknown status
d->errorCode.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qsqlerror - unknown status
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qsqlerror - unknown status
2-12
286}-
287#endif-
288-
289/*!-
290 \fn void QSqlError::setNumber(int number)-
291 \obsolete-
292-
293 Sets the database-specific error number to \a number.-
294-
295 Use QSqlError(const QString &driverText, const QString &databaseText,-
296 ErrorType type, int number) instead-
297-
298 \sa number()-
299*/-
300-
301#if QT_DEPRECATED_SINCE(5, 1)-
302void QSqlError::setNumber(int number)-
303{-
304 d->errorCode = QString::number(number);-
305}
executed 3 times by 1 test: end of block
Executed by:
  • tst_qsqlerror - unknown status
3
306#endif-
307-
308/*!-
309 Returns the database-specific error code, or an empty string if-
310 it cannot be determined.-
311*/-
312-
313QString QSqlError::nativeErrorCode() const-
314{-
315 return d->errorCode;
executed 11603 times by 9 tests: return d->errorCode;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlerror - unknown status
11603
316}-
317-
318/*!-
319 This is a convenience function that returns databaseText() and-
320 driverText() concatenated into a single string.-
321-
322 \sa driverText(), databaseText()-
323*/-
324-
325QString QSqlError::text() const-
326{-
327 QString result = d->databaseError;-
328 if (!d->databaseError.endsWith(QLatin1String("\n")))
!d->databaseEr...1String("\n"))Description
TRUEnever evaluated
FALSEnever evaluated
0
329 result += QLatin1Char(' ');
never executed: result += QLatin1Char(' ');
0
330 result += d->driverError;-
331 return result;
never executed: return result;
0
332}-
333-
334/*!-
335 Returns \c true if an error is set, otherwise false.-
336-
337 Example:-
338 \snippet code/src_sql_kernel_qsqlerror.cpp 0-
339-
340 \sa type()-
341*/-
342bool QSqlError::isValid() const-
343{-
344 return d->errorType != NoError;
executed 236170 times by 10 tests: return d->errorType != NoError;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlerror - unknown status
236170
345}-
346-
347QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9