Line | Source Code | Coverage |
---|
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 "qsqldriver.h" | - |
43 | | - |
44 | #include "qdatetime.h" | - |
45 | #include "qsqlerror.h" | - |
46 | #include "qsqlfield.h" | - |
47 | #include "qsqlindex.h" | - |
48 | #include "private/qobject_p.h" | - |
49 | | - |
50 | QT_BEGIN_NAMESPACE | - |
51 | | - |
52 | static QString prepareIdentifier(const QString &identifier, | - |
53 | QSqlDriver::IdentifierType type, const QSqlDriver *driver) | - |
54 | { | - |
55 | Q_ASSERT( driver != NULL ); executed (the execution status of this line is deduced): qt_noop(); | - |
56 | QString ret = identifier; executed (the execution status of this line is deduced): QString ret = identifier; | - |
57 | if (!driver->isIdentifierEscaped(identifier, type)) { partially evaluated: !driver->isIdentifierEscaped(identifier, type) yes Evaluation Count:1199 | no Evaluation Count:0 |
| 0-1199 |
58 | ret = driver->escapeIdentifier(identifier, type); executed (the execution status of this line is deduced): ret = driver->escapeIdentifier(identifier, type); | - |
59 | } executed: } Execution Count:1199 | 1199 |
60 | return ret; executed: return ret; Execution Count:1199 | 1199 |
61 | } | - |
62 | | - |
63 | class QSqlDriverPrivate : public QObjectPrivate | - |
64 | { | - |
65 | public: | - |
66 | QSqlDriverPrivate(); | - |
67 | virtual ~QSqlDriverPrivate(); | - |
68 | | - |
69 | public: | - |
70 | // @CHECK: this member is never used. It was named q, which expanded to q_func(). | - |
71 | QSqlDriver *q_func(); | - |
72 | uint isOpen : 1; | - |
73 | uint isOpenError : 1; | - |
74 | QSqlError error; | - |
75 | QSql::NumericalPrecisionPolicy precisionPolicy; | - |
76 | }; | - |
77 | | - |
78 | inline QSqlDriverPrivate::QSqlDriverPrivate() | - |
79 | : QObjectPrivate(), isOpen(false), isOpenError(false), precisionPolicy(QSql::LowPrecisionDouble) | - |
80 | { | - |
81 | } executed: } Execution Count:53 | 53 |
82 | | - |
83 | QSqlDriverPrivate::~QSqlDriverPrivate() | - |
84 | { | - |
85 | } | - |
86 | | - |
87 | /*! | - |
88 | \class QSqlDriver | - |
89 | \brief The QSqlDriver class is an abstract base class for accessing | - |
90 | specific SQL databases. | - |
91 | | - |
92 | \ingroup database | - |
93 | \inmodule QtSql | - |
94 | | - |
95 | This class should not be used directly. Use QSqlDatabase instead. | - |
96 | | - |
97 | If you want to create your own SQL drivers, you can subclass this | - |
98 | class and reimplement its pure virtual functions and those | - |
99 | virtual functions that you need. See \l{How to Write Your Own | - |
100 | Database Driver} for more information. | - |
101 | | - |
102 | \sa QSqlDatabase, QSqlResult | - |
103 | */ | - |
104 | | - |
105 | /*! | - |
106 | Constructs a new driver with the given \a parent. | - |
107 | */ | - |
108 | | - |
109 | QSqlDriver::QSqlDriver(QObject *parent) | - |
110 | : QObject(*new QSqlDriverPrivate, parent) | - |
111 | { | - |
112 | } executed: } Execution Count:53 | 53 |
113 | | - |
114 | /*! | - |
115 | Destroys the object and frees any allocated resources. | - |
116 | */ | - |
117 | | - |
118 | QSqlDriver::~QSqlDriver() | - |
119 | { | - |
120 | } | - |
121 | | - |
122 | /*! | - |
123 | \since 4.4 | - |
124 | | - |
125 | \fn QSqlDriver::notification(const QString &name) | - |
126 | | - |
127 | This signal is emitted when the database posts an event notification | - |
128 | that the driver subscribes to. \a name identifies the event notification. | - |
129 | | - |
130 | \sa subscribeToNotification() | - |
131 | */ | - |
132 | | - |
133 | /*! | - |
134 | \since 5.0 | - |
135 | | - |
136 | \fn QSqlDriver::notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant & payload) | - |
137 | | - |
138 | This signal is emitted when the database posts an event notification | - |
139 | that the driver subscribes to. \a name identifies the event notification, \a source indicates the signal source, | - |
140 | \a payload holds the extra data optionally delivered with the notification. | - |
141 | | - |
142 | \sa subscribeToNotification() | - |
143 | */ | - |
144 | | - |
145 | /*! | - |
146 | \fn bool QSqlDriver::open(const QString &db, const QString &user, const QString& password, | - |
147 | const QString &host, int port, const QString &options) | - |
148 | | - |
149 | Derived classes must reimplement this pure virtual function to | - |
150 | open a database connection on database \a db, using user name \a | - |
151 | user, password \a password, host \a host, port \a port and | - |
152 | connection options \a options. | - |
153 | | - |
154 | The function must return true on success and false on failure. | - |
155 | | - |
156 | \sa setOpen() | - |
157 | */ | - |
158 | | - |
159 | /*! | - |
160 | \fn bool QSqlDriver::close() | - |
161 | | - |
162 | Derived classes must reimplement this pure virtual function in | - |
163 | order to close the database connection. Return true on success, | - |
164 | false on failure. | - |
165 | | - |
166 | \sa open(), setOpen() | - |
167 | */ | - |
168 | | - |
169 | /*! | - |
170 | \fn QSqlResult *QSqlDriver::createResult() const | - |
171 | | - |
172 | Creates an empty SQL result on the database. Derived classes must | - |
173 | reimplement this function and return a QSqlResult object | - |
174 | appropriate for their database to the caller. | - |
175 | */ | - |
176 | | - |
177 | /*! | - |
178 | Returns true if the database connection is open; otherwise returns | - |
179 | false. | - |
180 | */ | - |
181 | | - |
182 | bool QSqlDriver::isOpen() const | - |
183 | { | - |
184 | return d_func()->isOpen; executed: return d_func()->isOpen; Execution Count:8278 | 8278 |
185 | } | - |
186 | | - |
187 | /*! | - |
188 | Returns true if the there was an error opening the database | - |
189 | connection; otherwise returns false. | - |
190 | */ | - |
191 | | - |
192 | bool QSqlDriver::isOpenError() const | - |
193 | { | - |
194 | return d_func()->isOpenError; executed: return d_func()->isOpenError; Execution Count:5582 | 5582 |
195 | } | - |
196 | | - |
197 | /*! | - |
198 | \enum QSqlDriver::DriverFeature | - |
199 | | - |
200 | This enum contains a list of features a driver might support. Use | - |
201 | hasFeature() to query whether a feature is supported or not. | - |
202 | | - |
203 | \value Transactions Whether the driver supports SQL transactions. | - |
204 | \value QuerySize Whether the database is capable of reporting the size | - |
205 | of a query. Note that some databases do not support returning the size | - |
206 | (i.e. number of rows returned) of a query, in which case | - |
207 | QSqlQuery::size() will return -1. | - |
208 | \value BLOB Whether the driver supports Binary Large Object fields. | - |
209 | \value Unicode Whether the driver supports Unicode strings if the | - |
210 | database server does. | - |
211 | \value PreparedQueries Whether the driver supports prepared query execution. | - |
212 | \value NamedPlaceholders Whether the driver supports the use of named placeholders. | - |
213 | \value PositionalPlaceholders Whether the driver supports the use of positional placeholders. | - |
214 | \value LastInsertId Whether the driver supports returning the Id of the last touched row. | - |
215 | \value BatchOperations Whether the driver supports batched operations, see QSqlQuery::execBatch() | - |
216 | \value SimpleLocking Whether the driver disallows a write lock on a table while other queries have a read lock on it. | - |
217 | \value LowPrecisionNumbers Whether the driver allows fetching numerical values with low precision. | - |
218 | \value EventNotifications Whether the driver supports database event notifications. | - |
219 | \value FinishQuery Whether the driver can do any low-level resource cleanup when QSqlQuery::finish() is called. | - |
220 | \value MultipleResultSets Whether the driver can access multiple result sets returned from batched statements or stored procedures. | - |
221 | \value CancelQuery Whether the driver allows cancelling a running query. | - |
222 | | - |
223 | More information about supported features can be found in the | - |
224 | \l{sql-driver.html}{Qt SQL driver} documentation. | - |
225 | | - |
226 | \sa hasFeature() | - |
227 | */ | - |
228 | | - |
229 | /*! | - |
230 | \enum QSqlDriver::StatementType | - |
231 | | - |
232 | This enum contains a list of SQL statement (or clause) types the | - |
233 | driver can create. | - |
234 | | - |
235 | \value WhereStatement An SQL \c WHERE statement (e.g., \c{WHERE f = 5}). | - |
236 | \value SelectStatement An SQL \c SELECT statement (e.g., \c{SELECT f FROM t}). | - |
237 | \value UpdateStatement An SQL \c UPDATE statement (e.g., \c{UPDATE TABLE t set f = 1}). | - |
238 | \value InsertStatement An SQL \c INSERT statement (e.g., \c{INSERT INTO t (f) values (1)}). | - |
239 | \value DeleteStatement An SQL \c DELETE statement (e.g., \c{DELETE FROM t}). | - |
240 | | - |
241 | \sa sqlStatement() | - |
242 | */ | - |
243 | | - |
244 | /*! | - |
245 | \enum QSqlDriver::IdentifierType | - |
246 | | - |
247 | This enum contains a list of SQL identifier types. | - |
248 | | - |
249 | \value FieldName A SQL field name | - |
250 | \value TableName A SQL table name | - |
251 | */ | - |
252 | | - |
253 | /*! | - |
254 | \enum QSqlDriver::NotificationSource | - |
255 | | - |
256 | This enum contains a list of SQL notification sources. | - |
257 | | - |
258 | \value UnknownSource The notification source is unknown | - |
259 | \value SelfSource The notification source is this connection | - |
260 | \value OtherSource The notification source is another connection | - |
261 | */ | - |
262 | | - |
263 | /*! | - |
264 | \fn bool QSqlDriver::hasFeature(DriverFeature feature) const | - |
265 | | - |
266 | Returns true if the driver supports feature \a feature; otherwise | - |
267 | returns false. | - |
268 | | - |
269 | Note that some databases need to be open() before this can be | - |
270 | determined. | - |
271 | | - |
272 | \sa DriverFeature | - |
273 | */ | - |
274 | | - |
275 | /*! | - |
276 | This function sets the open state of the database to \a open. | - |
277 | Derived classes can use this function to report the status of | - |
278 | open(). | - |
279 | | - |
280 | \sa open(), setOpenError() | - |
281 | */ | - |
282 | | - |
283 | void QSqlDriver::setOpen(bool open) | - |
284 | { | - |
285 | d_func()->isOpen = open; executed (the execution status of this line is deduced): d_func()->isOpen = open; | - |
286 | } executed: } Execution Count:90 | 90 |
287 | | - |
288 | /*! | - |
289 | This function sets the open error state of the database to \a | - |
290 | error. Derived classes can use this function to report the status | - |
291 | of open(). Note that if \a error is true the open state of the | - |
292 | database is set to closed (i.e., isOpen() returns false). | - |
293 | | - |
294 | \sa open(), setOpen() | - |
295 | */ | - |
296 | | - |
297 | void QSqlDriver::setOpenError(bool error) | - |
298 | { | - |
299 | d_func()->isOpenError = error; executed (the execution status of this line is deduced): d_func()->isOpenError = error; | - |
300 | if (error) evaluated: error yes Evaluation Count:2 | yes Evaluation Count:90 |
| 2-90 |
301 | d_func()->isOpen = false; executed: d_func()->isOpen = false; Execution Count:2 | 2 |
302 | } executed: } Execution Count:92 | 92 |
303 | | - |
304 | /*! | - |
305 | This function is called to begin a transaction. If successful, | - |
306 | return true, otherwise return false. The default implementation | - |
307 | does nothing and returns false. | - |
308 | | - |
309 | \sa commitTransaction(), rollbackTransaction() | - |
310 | */ | - |
311 | | - |
312 | bool QSqlDriver::beginTransaction() | - |
313 | { | - |
314 | return false; never executed: return false; | 0 |
315 | } | - |
316 | | - |
317 | /*! | - |
318 | This function is called to commit a transaction. If successful, | - |
319 | return true, otherwise return false. The default implementation | - |
320 | does nothing and returns false. | - |
321 | | - |
322 | \sa beginTransaction(), rollbackTransaction() | - |
323 | */ | - |
324 | | - |
325 | bool QSqlDriver::commitTransaction() | - |
326 | { | - |
327 | return false; never executed: return false; | 0 |
328 | } | - |
329 | | - |
330 | /*! | - |
331 | This function is called to rollback a transaction. If successful, | - |
332 | return true, otherwise return false. The default implementation | - |
333 | does nothing and returns false. | - |
334 | | - |
335 | \sa beginTransaction(), commitTransaction() | - |
336 | */ | - |
337 | | - |
338 | bool QSqlDriver::rollbackTransaction() | - |
339 | { | - |
340 | return false; never executed: return false; | 0 |
341 | } | - |
342 | | - |
343 | /*! | - |
344 | This function is used to set the value of the last error, \a error, | - |
345 | that occurred on the database. | - |
346 | | - |
347 | \sa lastError() | - |
348 | */ | - |
349 | | - |
350 | void QSqlDriver::setLastError(const QSqlError &error) | - |
351 | { | - |
352 | d_func()->error = error; executed (the execution status of this line is deduced): d_func()->error = error; | - |
353 | } executed: } Execution Count:37 | 37 |
354 | | - |
355 | /*! | - |
356 | Returns a QSqlError object which contains information about the | - |
357 | last error that occurred on the database. | - |
358 | */ | - |
359 | | - |
360 | QSqlError QSqlDriver::lastError() const | - |
361 | { | - |
362 | return d_func()->error; executed: return d_func()->error; Execution Count:29 | 29 |
363 | } | - |
364 | | - |
365 | /*! | - |
366 | Returns a list of the names of the tables in the database. The | - |
367 | default implementation returns an empty list. | - |
368 | | - |
369 | The \a tableType argument describes what types of tables | - |
370 | should be returned. Due to binary compatibility, the string | - |
371 | contains the value of the enum QSql::TableTypes as text. | - |
372 | An empty string should be treated as QSql::Tables for | - |
373 | backward compatibility. | - |
374 | */ | - |
375 | | - |
376 | QStringList QSqlDriver::tables(QSql::TableType) const | - |
377 | { | - |
378 | return QStringList(); executed: return QStringList(); Execution Count:1 | 1 |
379 | } | - |
380 | | - |
381 | /*! | - |
382 | Returns the primary index for table \a tableName. Returns an empty | - |
383 | QSqlIndex if the table doesn't have a primary index. The default | - |
384 | implementation returns an empty index. | - |
385 | */ | - |
386 | | - |
387 | QSqlIndex QSqlDriver::primaryIndex(const QString&) const | - |
388 | { | - |
389 | return QSqlIndex(); never executed: return QSqlIndex(); | 0 |
390 | } | - |
391 | | - |
392 | | - |
393 | /*! | - |
394 | Returns a QSqlRecord populated with the names of the fields in | - |
395 | table \a tableName. If no such table exists, an empty record is | - |
396 | returned. The default implementation returns an empty record. | - |
397 | */ | - |
398 | | - |
399 | QSqlRecord QSqlDriver::record(const QString & /* tableName */) const | - |
400 | { | - |
401 | return QSqlRecord(); never executed: return QSqlRecord(); | 0 |
402 | } | - |
403 | | - |
404 | /*! | - |
405 | Returns the \a identifier escaped according to the database rules. | - |
406 | \a identifier can either be a table name or field name, dependent | - |
407 | on \a type. | - |
408 | | - |
409 | The default implementation does nothing. | - |
410 | \sa isIdentifierEscaped() | - |
411 | */ | - |
412 | QString QSqlDriver::escapeIdentifier(const QString &identifier, IdentifierType) const | - |
413 | { | - |
414 | return identifier; never executed: return identifier; | 0 |
415 | } | - |
416 | | - |
417 | /*! | - |
418 | Returns whether \a identifier is escaped according to the database rules. | - |
419 | \a identifier can either be a table name or field name, dependent | - |
420 | on \a type. | - |
421 | | - |
422 | Reimplement this function if you want to provide your own implementation in your | - |
423 | QSqlDriver subclass, | - |
424 | | - |
425 | \sa stripDelimiters(), escapeIdentifier() | - |
426 | */ | - |
427 | bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType type) const | - |
428 | { | - |
429 | Q_UNUSED(type); executed (the execution status of this line is deduced): (void)type;; | - |
430 | return identifier.size() > 2 executed: return identifier.size() > 2 && identifier.startsWith(QLatin1Char('"')) && identifier.endsWith(QLatin1Char('"')); Execution Count:2652 | 2652 |
431 | && identifier.startsWith(QLatin1Char('"')) //left delimited executed: return identifier.size() > 2 && identifier.startsWith(QLatin1Char('"')) && identifier.endsWith(QLatin1Char('"')); Execution Count:2652 | 2652 |
432 | && identifier.endsWith(QLatin1Char('"')); //right delimited executed: return identifier.size() > 2 && identifier.startsWith(QLatin1Char('"')) && identifier.endsWith(QLatin1Char('"')); Execution Count:2652 | 2652 |
433 | } | - |
434 | | - |
435 | /*! | - |
436 | Returns the \a identifier with the leading and trailing delimiters removed, | - |
437 | \a identifier can either be a table name or field name, | - |
438 | dependent on \a type. If \a identifier does not have leading | - |
439 | and trailing delimiter characters, \a identifier is returned without | - |
440 | modification. | - |
441 | | - |
442 | Reimplement this function if you want to provide your own implementation in your | - |
443 | QSqlDriver subclass, | - |
444 | | - |
445 | \since 4.5 | - |
446 | \sa isIdentifierEscaped() | - |
447 | */ | - |
448 | QString QSqlDriver::stripDelimiters(const QString &identifier, IdentifierType type) const | - |
449 | { | - |
450 | QString ret; executed (the execution status of this line is deduced): QString ret; | - |
451 | if (isIdentifierEscaped(identifier, type)) { partially evaluated: isIdentifierEscaped(identifier, type) yes Evaluation Count:99 | no Evaluation Count:0 |
| 0-99 |
452 | ret = identifier.mid(1); executed (the execution status of this line is deduced): ret = identifier.mid(1); | - |
453 | ret.chop(1); executed (the execution status of this line is deduced): ret.chop(1); | - |
454 | } else { executed: } Execution Count:99 | 99 |
455 | ret = identifier; never executed (the execution status of this line is deduced): ret = identifier; | - |
456 | } | 0 |
457 | return ret; executed: return ret; Execution Count:99 | 99 |
458 | } | - |
459 | | - |
460 | /*! | - |
461 | Returns a SQL statement of type \a type for the table \a tableName | - |
462 | with the values from \a rec. If \a preparedStatement is true, the | - |
463 | string will contain placeholders instead of values. | - |
464 | | - |
465 | This method can be used to manipulate tables without having to worry | - |
466 | about database-dependent SQL dialects. For non-prepared statements, | - |
467 | the values will be properly escaped. | - |
468 | */ | - |
469 | QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, | - |
470 | const QSqlRecord &rec, bool preparedStatement) const | - |
471 | { | - |
472 | int i; executed (the execution status of this line is deduced): int i; | - |
473 | QString s; executed (the execution status of this line is deduced): QString s; | - |
474 | s.reserve(128); executed (the execution status of this line is deduced): s.reserve(128); | - |
475 | switch (type) { | - |
476 | case SelectStatement: | - |
477 | for (i = 0; i < rec.count(); ++i) { evaluated: i < rec.count() yes Evaluation Count:721 | yes Evaluation Count:293 |
| 293-721 |
478 | if (rec.isGenerated(i)) partially evaluated: rec.isGenerated(i) yes Evaluation Count:721 | no Evaluation Count:0 |
| 0-721 |
479 | s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); executed: s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); Execution Count:721 | 721 |
480 | } executed: } Execution Count:721 | 721 |
481 | if (s.isEmpty()) partially evaluated: s.isEmpty() no Evaluation Count:0 | yes Evaluation Count:293 |
| 0-293 |
482 | return s; never executed: return s; | 0 |
483 | s.chop(2); executed (the execution status of this line is deduced): s.chop(2); | - |
484 | s.prepend(QLatin1String("SELECT ")).append(QLatin1String(" FROM ")).append(tableName); executed (the execution status of this line is deduced): s.prepend(QLatin1String("SELECT ")).append(QLatin1String(" FROM ")).append(tableName); | - |
485 | break; executed: break; Execution Count:293 | 293 |
486 | case WhereStatement: | - |
487 | if (preparedStatement) { evaluated: preparedStatement yes Evaluation Count:72 | yes Evaluation Count:63 |
| 63-72 |
488 | for (int i = 0; i < rec.count(); ++i) { evaluated: i < rec.count() yes Evaluation Count:160 | yes Evaluation Count:72 |
| 72-160 |
489 | s.append(prepareIdentifier(rec.fieldName(i), FieldName,this)); executed (the execution status of this line is deduced): s.append(prepareIdentifier(rec.fieldName(i), FieldName,this)); | - |
490 | if (rec.isNull(i)) evaluated: rec.isNull(i) yes Evaluation Count:8 | yes Evaluation Count:152 |
| 8-152 |
491 | s.append(QLatin1String(" IS NULL")); executed: s.append(QLatin1String(" IS NULL")); Execution Count:8 | 8 |
492 | else | - |
493 | s.append(QLatin1String(" = ?")); executed: s.append(QLatin1String(" = ?")); Execution Count:152 | 152 |
494 | s.append(QLatin1String(" AND ")); executed (the execution status of this line is deduced): s.append(QLatin1String(" AND ")); | - |
495 | } executed: } Execution Count:160 | 160 |
496 | } else { executed: } Execution Count:72 | 72 |
497 | for (i = 0; i < rec.count(); ++i) { evaluated: i < rec.count() yes Evaluation Count:126 | yes Evaluation Count:63 |
| 63-126 |
498 | s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)); executed (the execution status of this line is deduced): s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)); | - |
499 | QString val = formatValue(rec.field(i)); executed (the execution status of this line is deduced): QString val = formatValue(rec.field(i)); | - |
500 | if (val == QLatin1String("NULL")) evaluated: val == QLatin1String("NULL") yes Evaluation Count:9 | yes Evaluation Count:117 |
| 9-117 |
501 | s.append(QLatin1String(" IS NULL")); executed: s.append(QLatin1String(" IS NULL")); Execution Count:9 | 9 |
502 | else | - |
503 | s.append(QLatin1String(" = ")).append(val); executed: s.append(QLatin1String(" = ")).append(val); Execution Count:117 | 117 |
504 | s.append(QLatin1String(" AND ")); executed (the execution status of this line is deduced): s.append(QLatin1String(" AND ")); | - |
505 | } executed: } Execution Count:126 | 126 |
506 | } executed: } Execution Count:63 | 63 |
507 | if (!s.isEmpty()) { partially evaluated: !s.isEmpty() yes Evaluation Count:135 | no Evaluation Count:0 |
| 0-135 |
508 | s.prepend(QLatin1String("WHERE ")); executed (the execution status of this line is deduced): s.prepend(QLatin1String("WHERE ")); | - |
509 | s.chop(5); // remove tailing AND executed (the execution status of this line is deduced): s.chop(5); | - |
510 | } executed: } Execution Count:135 | 135 |
511 | break; executed: break; Execution Count:135 | 135 |
512 | case UpdateStatement: | - |
513 | s.append(QLatin1String("UPDATE ")).append(tableName).append( executed (the execution status of this line is deduced): s.append(QLatin1String("UPDATE ")).append(tableName).append( | - |
514 | QLatin1String(" SET ")); executed (the execution status of this line is deduced): QLatin1String(" SET ")); | - |
515 | for (i = 0; i < rec.count(); ++i) { evaluated: i < rec.count() yes Evaluation Count:153 | yes Evaluation Count:49 |
| 49-153 |
516 | if (!rec.isGenerated(i)) evaluated: !rec.isGenerated(i) yes Evaluation Count:89 | yes Evaluation Count:64 |
| 64-89 |
517 | continue; executed: continue; Execution Count:89 | 89 |
518 | s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1Char('=')); executed (the execution status of this line is deduced): s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1Char('=')); | - |
519 | if (preparedStatement) partially evaluated: preparedStatement yes Evaluation Count:64 | no Evaluation Count:0 |
| 0-64 |
520 | s.append(QLatin1Char('?')); executed: s.append(QLatin1Char('?')); Execution Count:64 | 64 |
521 | else | - |
522 | s.append(formatValue(rec.field(i))); never executed: s.append(formatValue(rec.field(i))); | 0 |
523 | s.append(QLatin1String(", ")); executed (the execution status of this line is deduced): s.append(QLatin1String(", ")); | - |
524 | } executed: } Execution Count:64 | 64 |
525 | if (s.endsWith(QLatin1String(", "))) partially evaluated: s.endsWith(QLatin1String(", ")) yes Evaluation Count:49 | no Evaluation Count:0 |
| 0-49 |
526 | s.chop(2); executed: s.chop(2); Execution Count:49 | 49 |
527 | else | - |
528 | s.clear(); never executed: s.clear(); | 0 |
529 | break; executed: break; Execution Count:49 | 49 |
530 | case DeleteStatement: | - |
531 | s.append(QLatin1String("DELETE FROM ")).append(tableName); executed (the execution status of this line is deduced): s.append(QLatin1String("DELETE FROM ")).append(tableName); | - |
532 | break; executed: break; Execution Count:22 | 22 |
533 | case InsertStatement: { | - |
534 | s.append(QLatin1String("INSERT INTO ")).append(tableName).append(QLatin1String(" (")); executed (the execution status of this line is deduced): s.append(QLatin1String("INSERT INTO ")).append(tableName).append(QLatin1String(" (")); | - |
535 | QString vals; executed (the execution status of this line is deduced): QString vals; | - |
536 | for (i = 0; i < rec.count(); ++i) { evaluated: i < rec.count() yes Evaluation Count:145 | yes Evaluation Count:53 |
| 53-145 |
537 | if (!rec.isGenerated(i)) evaluated: !rec.isGenerated(i) yes Evaluation Count:17 | yes Evaluation Count:128 |
| 17-128 |
538 | continue; executed: continue; Execution Count:17 | 17 |
539 | s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); executed (the execution status of this line is deduced): s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); | - |
540 | if (preparedStatement) partially evaluated: preparedStatement yes Evaluation Count:128 | no Evaluation Count:0 |
| 0-128 |
541 | vals.append(QLatin1Char('?')); executed: vals.append(QLatin1Char('?')); Execution Count:128 | 128 |
542 | else | - |
543 | vals.append(formatValue(rec.field(i))); never executed: vals.append(formatValue(rec.field(i))); | 0 |
544 | vals.append(QLatin1String(", ")); executed (the execution status of this line is deduced): vals.append(QLatin1String(", ")); | - |
545 | } executed: } Execution Count:128 | 128 |
546 | if (vals.isEmpty()) { evaluated: vals.isEmpty() yes Evaluation Count:1 | yes Evaluation Count:52 |
| 1-52 |
547 | s.clear(); executed (the execution status of this line is deduced): s.clear(); | - |
548 | } else { executed: } Execution Count:1 | 1 |
549 | vals.chop(2); // remove trailing comma executed (the execution status of this line is deduced): vals.chop(2); | - |
550 | s[s.length() - 2] = QLatin1Char(')'); executed (the execution status of this line is deduced): s[s.length() - 2] = QLatin1Char(')'); | - |
551 | s.append(QLatin1String("VALUES (")).append(vals).append(QLatin1Char(')')); executed (the execution status of this line is deduced): s.append(QLatin1String("VALUES (")).append(vals).append(QLatin1Char(')')); | - |
552 | } executed: } Execution Count:52 | 52 |
553 | break; } executed: break; Execution Count:53 | 53 |
554 | } | - |
555 | return s; executed: return s; Execution Count:552 | 552 |
556 | } | - |
557 | | - |
558 | /*! | - |
559 | Returns a string representation of the \a field value for the | - |
560 | database. This is used, for example, when constructing INSERT and | - |
561 | UPDATE statements. | - |
562 | | - |
563 | The default implementation returns the value formatted as a string | - |
564 | according to the following rules: | - |
565 | | - |
566 | \list | - |
567 | | - |
568 | \li If \a field is character data, the value is returned enclosed | - |
569 | in single quotation marks, which is appropriate for many SQL | - |
570 | databases. Any embedded single-quote characters are escaped | - |
571 | (replaced with two single-quote characters). If \a trimStrings is | - |
572 | true (the default is false), all trailing whitespace is trimmed | - |
573 | from the field. | - |
574 | | - |
575 | \li If \a field is date/time data, the value is formatted in ISO | - |
576 | format and enclosed in single quotation marks. If the date/time | - |
577 | data is invalid, "NULL" is returned. | - |
578 | | - |
579 | \li If \a field is \l{QByteArray}{bytearray} data, and the | - |
580 | driver can edit binary fields, the value is formatted as a | - |
581 | hexadecimal string. | - |
582 | | - |
583 | \li For any other field type, toString() is called on its value | - |
584 | and the result of this is returned. | - |
585 | | - |
586 | \endlist | - |
587 | | - |
588 | \sa QVariant::toString() | - |
589 | | - |
590 | */ | - |
591 | QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const | - |
592 | { | - |
593 | const QLatin1String nullTxt("NULL"); executed (the execution status of this line is deduced): const QLatin1String nullTxt("NULL"); | - |
594 | | - |
595 | QString r; executed (the execution status of this line is deduced): QString r; | - |
596 | if (field.isNull()) evaluated: field.isNull() yes Evaluation Count:9 | yes Evaluation Count:123 |
| 9-123 |
597 | r = nullTxt; executed: r = nullTxt; Execution Count:9 | 9 |
598 | else { | - |
599 | switch (field.type()) { | - |
600 | case QVariant::Int: | - |
601 | case QVariant::UInt: | - |
602 | if (field.value().type() == QVariant::Bool) partially evaluated: field.value().type() == QVariant::Bool no Evaluation Count:0 | yes Evaluation Count:81 |
| 0-81 |
603 | r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0"); never executed: r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0"); never evaluated: field.value().toBool() | 0 |
604 | else | - |
605 | r = field.value().toString(); executed: r = field.value().toString(); Execution Count:81 | 81 |
606 | break; executed: break; Execution Count:81 | 81 |
607 | #ifndef QT_NO_DATESTRING | - |
608 | case QVariant::Date: | - |
609 | if (field.value().toDate().isValid()) never evaluated: field.value().toDate().isValid() | 0 |
610 | r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate) never executed: r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate) + QLatin1Char('\''); | 0 |
611 | + QLatin1Char('\''); never executed: r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate) + QLatin1Char('\''); | 0 |
612 | else | - |
613 | r = nullTxt; never executed: r = nullTxt; | 0 |
614 | break; | 0 |
615 | case QVariant::Time: | - |
616 | if (field.value().toTime().isValid()) never evaluated: field.value().toTime().isValid() | 0 |
617 | r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) never executed: r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) + QLatin1Char('\''); | 0 |
618 | + QLatin1Char('\''); never executed: r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) + QLatin1Char('\''); | 0 |
619 | else | - |
620 | r = nullTxt; never executed: r = nullTxt; | 0 |
621 | break; | 0 |
622 | case QVariant::DateTime: | - |
623 | if (field.value().toDateTime().isValid()) never evaluated: field.value().toDateTime().isValid() | 0 |
624 | r = QLatin1Char('\'') + never executed: r = QLatin1Char('\'') + field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\''); | 0 |
625 | field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\''); never executed: r = QLatin1Char('\'') + field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\''); | 0 |
626 | else | - |
627 | r = nullTxt; never executed: r = nullTxt; | 0 |
628 | break; | 0 |
629 | #endif | - |
630 | case QVariant::String: | - |
631 | case QVariant::Char: | - |
632 | { | - |
633 | QString result = field.value().toString(); executed (the execution status of this line is deduced): QString result = field.value().toString(); | - |
634 | if (trimStrings) { evaluated: trimStrings yes Evaluation Count:6 | yes Evaluation Count:36 |
| 6-36 |
635 | int end = result.length(); executed (the execution status of this line is deduced): int end = result.length(); | - |
636 | while (end && result.at(end-1).isSpace()) /* skip white space from end */ evaluated: end yes Evaluation Count:13 | yes Evaluation Count:2 |
evaluated: result.at(end-1).isSpace() yes Evaluation Count:9 | yes Evaluation Count:4 |
| 2-13 |
637 | end--; executed: end--; Execution Count:9 | 9 |
638 | result.truncate(end); executed (the execution status of this line is deduced): result.truncate(end); | - |
639 | } executed: } Execution Count:6 | 6 |
640 | /* escape the "'" character */ | - |
641 | result.replace(QLatin1Char('\''), QLatin1String("''")); executed (the execution status of this line is deduced): result.replace(QLatin1Char('\''), QLatin1String("''")); | - |
642 | r = QLatin1Char('\'') + result + QLatin1Char('\''); executed (the execution status of this line is deduced): r = QLatin1Char('\'') + result + QLatin1Char('\''); | - |
643 | break; executed: break; Execution Count:42 | 42 |
644 | } | - |
645 | case QVariant::Bool: | - |
646 | r = QString::number(field.value().toBool()); never executed (the execution status of this line is deduced): r = QString::number(field.value().toBool()); | - |
647 | break; | 0 |
648 | case QVariant::ByteArray : { | - |
649 | if (hasFeature(BLOB)) { never evaluated: hasFeature(BLOB) | 0 |
650 | QByteArray ba = field.value().toByteArray(); never executed (the execution status of this line is deduced): QByteArray ba = field.value().toByteArray(); | - |
651 | QString res; never executed (the execution status of this line is deduced): QString res; | - |
652 | static const char hexchars[] = "0123456789abcdef"; | - |
653 | for (int i = 0; i < ba.size(); ++i) { never evaluated: i < ba.size() | 0 |
654 | uchar s = (uchar) ba[i]; never executed (the execution status of this line is deduced): uchar s = (uchar) ba[i]; | - |
655 | res += QLatin1Char(hexchars[s >> 4]); never executed (the execution status of this line is deduced): res += QLatin1Char(hexchars[s >> 4]); | - |
656 | res += QLatin1Char(hexchars[s & 0x0f]); never executed (the execution status of this line is deduced): res += QLatin1Char(hexchars[s & 0x0f]); | - |
657 | } | 0 |
658 | r = QLatin1Char('\'') + res + QLatin1Char('\''); never executed (the execution status of this line is deduced): r = QLatin1Char('\'') + res + QLatin1Char('\''); | - |
659 | break; | 0 |
660 | } | - |
661 | } | - |
662 | default: code before this statement never executed: default: | 0 |
663 | r = field.value().toString(); never executed (the execution status of this line is deduced): r = field.value().toString(); | - |
664 | break; | 0 |
665 | } | - |
666 | } executed: } Execution Count:123 | 123 |
667 | return r; executed: return r; Execution Count:132 | 132 |
668 | } | - |
669 | | - |
670 | /*! | - |
671 | Returns the low-level database handle wrapped in a QVariant or an | - |
672 | invalid variant if there is no handle. | - |
673 | | - |
674 | \warning Use this with uttermost care and only if you know what you're doing. | - |
675 | | - |
676 | \warning The handle returned here can become a stale pointer if the connection | - |
677 | is modified (for example, if you close the connection). | - |
678 | | - |
679 | \warning The handle can be NULL if the connection is not open yet. | - |
680 | | - |
681 | The handle returned here is database-dependent, you should query the type | - |
682 | name of the variant before accessing it. | - |
683 | | - |
684 | This example retrieves the handle for a connection to sqlite: | - |
685 | | - |
686 | \snippet code/src_sql_kernel_qsqldriver.cpp 0 | - |
687 | | - |
688 | This snippet returns the handle for PostgreSQL or MySQL: | - |
689 | | - |
690 | \snippet code/src_sql_kernel_qsqldriver.cpp 1 | - |
691 | | - |
692 | \sa QSqlResult::handle() | - |
693 | */ | - |
694 | QVariant QSqlDriver::handle() const | - |
695 | { | - |
696 | return QVariant(); never executed: return QVariant(); | 0 |
697 | } | - |
698 | | - |
699 | /*! | - |
700 | This function is called to subscribe to event notifications from the database. | - |
701 | \a name identifies the event notification. | - |
702 | | - |
703 | If successful, return true, otherwise return false. | - |
704 | | - |
705 | The database must be open when this function is called. When the database is closed | - |
706 | by calling close() all subscribed event notifications are automatically unsubscribed. | - |
707 | Note that calling open() on an already open database may implicitly cause close() to | - |
708 | be called, which will cause the driver to unsubscribe from all event notifications. | - |
709 | | - |
710 | When an event notification identified by \a name is posted by the database the | - |
711 | notification() signal is emitted. | - |
712 | | - |
713 | Reimplement this function if you want to provide event notification support in your | - |
714 | own QSqlDriver subclass, | - |
715 | | - |
716 | \since 4.4 | - |
717 | \sa unsubscribeFromNotification(), subscribedToNotifications(), QSqlDriver::hasFeature() | - |
718 | */ | - |
719 | bool QSqlDriver::subscribeToNotification(const QString &name) | - |
720 | { | - |
721 | Q_UNUSED(name); never executed (the execution status of this line is deduced): (void)name;; | - |
722 | return false; never executed: return false; | 0 |
723 | } | - |
724 | | - |
725 | /*! | - |
726 | This function is called to unsubscribe from event notifications from the database. | - |
727 | \a name identifies the event notification. | - |
728 | | - |
729 | If successful, return true, otherwise return false. | - |
730 | | - |
731 | The database must be open when this function is called. All subscribed event | - |
732 | notifications are automatically unsubscribed from when the close() function is called. | - |
733 | | - |
734 | After calling \e this function the notification() signal will no longer be emitted | - |
735 | when an event notification identified by \a name is posted by the database. | - |
736 | | - |
737 | Reimplement this function if you want to provide event notification support in your | - |
738 | own QSqlDriver subclass, | - |
739 | | - |
740 | \since 4.4 | - |
741 | \sa subscribeToNotification(), subscribedToNotifications() | - |
742 | */ | - |
743 | bool QSqlDriver::unsubscribeFromNotification(const QString &name) | - |
744 | { | - |
745 | Q_UNUSED(name); never executed (the execution status of this line is deduced): (void)name;; | - |
746 | return false; never executed: return false; | 0 |
747 | } | - |
748 | | - |
749 | /*! | - |
750 | Returns a list of the names of the event notifications that are currently subscribed to. | - |
751 | | - |
752 | Reimplement this function if you want to provide event notification support in your | - |
753 | own QSqlDriver subclass, | - |
754 | | - |
755 | \since 4.4 | - |
756 | \sa subscribeToNotification(), unsubscribeFromNotification() | - |
757 | */ | - |
758 | QStringList QSqlDriver::subscribedToNotifications() const | - |
759 | { | - |
760 | return QStringList(); never executed: return QStringList(); | 0 |
761 | } | - |
762 | | - |
763 | /*! | - |
764 | \since 4.6 | - |
765 | | - |
766 | Sets the default numerical precision policy used by queries created | - |
767 | by this driver to \a precisionPolicy. | - |
768 | | - |
769 | Note: Setting the default precision policy to \a precisionPolicy | - |
770 | doesn't affect any currently active queries. | - |
771 | | - |
772 | \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy(), | - |
773 | QSqlQuery::setNumericalPrecisionPolicy(), QSqlQuery::numericalPrecisionPolicy() | - |
774 | */ | - |
775 | void QSqlDriver::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy) | - |
776 | { | - |
777 | d_func()->precisionPolicy = precisionPolicy; executed (the execution status of this line is deduced): d_func()->precisionPolicy = precisionPolicy; | - |
778 | } executed: } Execution Count:2 | 2 |
779 | | - |
780 | /*! | - |
781 | \since 4.6 | - |
782 | | - |
783 | Returns the current default precision policy for the database connection. | - |
784 | | - |
785 | \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy(), | - |
786 | QSqlQuery::numericalPrecisionPolicy(), QSqlQuery::setNumericalPrecisionPolicy() | - |
787 | */ | - |
788 | QSql::NumericalPrecisionPolicy QSqlDriver::numericalPrecisionPolicy() const | - |
789 | { | - |
790 | return d_func()->precisionPolicy; executed: return d_func()->precisionPolicy; Execution Count:2187 | 2187 |
791 | } | - |
792 | | - |
793 | /*! | - |
794 | \since 5.0 | - |
795 | \internal | - |
796 | | - |
797 | Tries to cancel the running query, if the underlying driver has the | - |
798 | capability to cancel queries. Returns true on success, otherwise false. | - |
799 | | - |
800 | This function can be called from a different thread. | - |
801 | | - |
802 | If you use this function as a slot, you need to use a Qt::DirectConnection | - |
803 | from a different thread. | - |
804 | | - |
805 | Reimplement this function to support canceling running queries in | - |
806 | your own QSqlDriver subclass. It must be implemented in a thread-safe | - |
807 | manner. | - |
808 | | - |
809 | \sa QSqlDriver::hasFeature() | - |
810 | */ | - |
811 | bool QSqlDriver::cancelQuery() | - |
812 | { | - |
813 | return false; never executed: return false; | 0 |
814 | } | - |
815 | | - |
816 | QT_END_NAMESPACE | - |
817 | | - |
| | |