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