kernel/qsqlerror.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 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 -
45QT_BEGIN_NAMESPACE -
46 -
47#ifndef QT_NO_DEBUG_STREAM -
48QDebug operator<<(QDebug dbg, const QSqlError &s) -
49{ -
50 dbg.nospace() << "QSqlError(" << s.number() << ", " << s.driverText() <<
never executed (the execution status of this line is deduced): dbg.nospace() << "QSqlError(" << s.number() << ", " << s.driverText() <<
-
51 ", " << s.databaseText() << ')';
never executed (the execution status of this line is deduced): ", " << s.databaseText() << ')';
-
52 return dbg.space();
never executed: return dbg.space();
0
53} -
54#endif -
55 -
56/*! -
57 \class QSqlError -
58 \brief The QSqlError class provides SQL database error information. -
59 -
60 \ingroup database -
61 \inmodule QtSql -
62 -
63 A QSqlError object can provide database-specific error data, -
64 including the driverText() and databaseText() messages (or both -
65 concatenated together as text()), and the error number() and -
66 type(). The functions all have setters so that you can create and -
67 return QSqlError objects from your own classes, for example from -
68 your own SQL drivers. -
69 -
70 \sa QSqlDatabase::lastError(), QSqlQuery::lastError() -
71*/ -
72 -
73/*! -
74 \enum QSqlError::ErrorType -
75 -
76 This enum type describes the context in which the error occurred, e.g., a connection error, a statement error, etc. -
77 -
78 \value NoError No error occurred. -
79 \value ConnectionError Connection error. -
80 \value StatementError SQL statement syntax error. -
81 \value TransactionError Transaction failed error. -
82 \value UnknownError Unknown error. -
83*/ -
84 -
85/*! -
86 Constructs an error containing the driver error text \a -
87 driverText, the database-specific error text \a databaseText, the -
88 type \a type and the optional error number \a number. -
89*/ -
90 -
91QSqlError::QSqlError(const QString& driverText, const QString& databaseText, ErrorType type, -
92 int number) -
93 : driverError(driverText), databaseError(databaseText), errorType(type), errorNumber(number) -
94{ -
95}
executed: }
Execution Count:309803
309803
96 -
97/*! -
98 Creates a copy of \a other. -
99*/ -
100QSqlError::QSqlError(const QSqlError& other) -
101 : driverError(other.driverError), databaseError(other.databaseError), -
102 errorType(other.errorType), -
103 errorNumber(other.errorNumber) -
104{ -
105}
executed: }
Execution Count:247731
247731
106 -
107/*! -
108 Assigns the \a other error's values to this error. -
109*/ -
110 -
111QSqlError& QSqlError::operator=(const QSqlError& other) -
112{ -
113 driverError = other.driverError;
executed (the execution status of this line is deduced): driverError = other.driverError;
-
114 databaseError = other.databaseError;
executed (the execution status of this line is deduced): databaseError = other.databaseError;
-
115 errorType = other.errorType;
executed (the execution status of this line is deduced): errorType = other.errorType;
-
116 errorNumber = other.errorNumber;
executed (the execution status of this line is deduced): errorNumber = other.errorNumber;
-
117 return *this;
executed: return *this;
Execution Count:307300
307300
118} -
119 -
120/*! -
121 Compare the \a other error's values to this error and returns true, if it equal. -
122*/ -
123 -
124bool QSqlError::operator==(const QSqlError& other) const -
125{ -
126 return (errorType == other.errorType);
executed: return (errorType == other.errorType);
Execution Count:1
1
127} -
128 -
129 -
130/*! -
131 Compare the \a other error's values to this error and returns true if it is not equal. -
132*/ -
133 -
134bool QSqlError::operator!=(const QSqlError& other) const -
135{ -
136 return (errorType != other.errorType);
executed: return (errorType != other.errorType);
Execution Count:1
1
137} -
138 -
139 -
140/*! -
141 Destroys the object and frees any allocated resources. -
142*/ -
143 -
144QSqlError::~QSqlError() -
145{ -
146} -
147 -
148/*! -
149 Returns the text of the error as reported by the driver. This may -
150 contain database-specific descriptions. It may also be empty. -
151 -
152 \sa setDriverText(), databaseText(), text() -
153*/ -
154QString QSqlError::driverText() const -
155{ -
156 return driverError;
executed: return driverError;
Execution Count:11582
11582
157} -
158 -
159/*! -
160 Sets the driver error text to the value of \a driverText. -
161 -
162 \sa driverText(), setDatabaseText(), text() -
163*/ -
164 -
165void QSqlError::setDriverText(const QString& driverText) -
166{ -
167 driverError = driverText;
never executed (the execution status of this line is deduced): driverError = driverText;
-
168}
never executed: }
0
169 -
170/*! -
171 Returns the text of the error as reported by the database. This -
172 may contain database-specific descriptions; it may be empty. -
173 -
174 \sa setDatabaseText(), driverText(), text() -
175*/ -
176 -
177QString QSqlError::databaseText() const -
178{ -
179 return databaseError;
executed: return databaseError;
Execution Count:11550
11550
180} -
181 -
182/*! -
183 Sets the database error text to the value of \a databaseText. -
184 -
185 \sa databaseText(), setDriverText(), text() -
186*/ -
187 -
188void QSqlError::setDatabaseText(const QString& databaseText) -
189{ -
190 databaseError = databaseText;
never executed (the execution status of this line is deduced): databaseError = databaseText;
-
191}
never executed: }
0
192 -
193/*! -
194 Returns the error type, or -1 if the type cannot be determined. -
195 -
196 \sa setType() -
197*/ -
198 -
199QSqlError::ErrorType QSqlError::type() const -
200{ -
201 return errorType;
executed: return errorType;
Execution Count:18
18
202} -
203 -
204/*! -
205 Sets the error type to the value of \a type. -
206 -
207 \sa type() -
208*/ -
209 -
210void QSqlError::setType(ErrorType type) -
211{ -
212 errorType = type;
executed (the execution status of this line is deduced): errorType = type;
-
213}
executed: }
Execution Count:8
8
214 -
215/*! -
216 Returns the database-specific error number, or -1 if it cannot be -
217 determined. -
218 -
219 \sa setNumber() -
220*/ -
221 -
222int QSqlError::number() const -
223{ -
224 return errorNumber;
executed: return errorNumber;
Execution Count:11581
11581
225} -
226 -
227/*! -
228 Sets the database-specific error number to \a number. -
229 -
230 \sa number() -
231*/ -
232 -
233void QSqlError::setNumber(int number) -
234{ -
235 errorNumber = number;
executed (the execution status of this line is deduced): errorNumber = number;
-
236}
executed: }
Execution Count:3
3
237 -
238/*! -
239 This is a convenience function that returns databaseText() and -
240 driverText() concatenated into a single string. -
241 -
242 \sa driverText(), databaseText() -
243*/ -
244 -
245QString QSqlError::text() const -
246{ -
247 QString result = databaseError;
never executed (the execution status of this line is deduced): QString result = databaseError;
-
248 if (!databaseError.endsWith(QLatin1String("\n")))
never evaluated: !databaseError.endsWith(QLatin1String("\n"))
0
249 result += QLatin1Char(' ');
never executed: result += QLatin1Char(' ');
0
250 result += driverError;
never executed (the execution status of this line is deduced): result += driverError;
-
251 return result;
never executed: return result;
0
252} -
253 -
254/*! -
255 Returns true if an error is set, otherwise false. -
256 -
257 Example: -
258 \snippet code/src_sql_kernel_qsqlerror.cpp 0 -
259 -
260 \sa type() -
261*/ -
262bool QSqlError::isValid() const -
263{ -
264 return errorType != NoError;
executed: return errorType != NoError;
Execution Count:236151
236151
265} -
266 -
267QT_END_NAMESPACE -
268 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial