qsqldatabase.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/sql/kernel/qsqldatabase.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtSql module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qsqldatabase.h"-
35#include "qsqlquery.h"-
36-
37#ifdef Q_OS_WIN32-
38// Conflicting declarations of LPCBYTE in sqlfront.h and winscard.h-
39#define _WINSCARD_H_-
40#endif-
41-
42#ifdef QT_SQL_PSQL-
43#include "../drivers/psql/qsql_psql_p.h"-
44#endif-
45#ifdef QT_SQL_MYSQL-
46#include "../drivers/mysql/qsql_mysql_p.h"-
47#endif-
48#ifdef QT_SQL_ODBC-
49#include "../drivers/odbc/qsql_odbc_p.h"-
50#endif-
51#ifdef QT_SQL_OCI-
52#include "../drivers/oci/qsql_oci_p.h"-
53#endif-
54#ifdef QT_SQL_TDS-
55// conflicting RETCODE typedef between odbc and freetds-
56#define RETCODE DBRETCODE-
57#include "../drivers/tds/qsql_tds_p.h"-
58#undef RETCODE-
59#endif-
60#ifdef QT_SQL_DB2-
61#include "../drivers/db2/qsql_db2_p.h"-
62#endif-
63#ifdef QT_SQL_SQLITE-
64#include "../drivers/sqlite/qsql_sqlite_p.h"-
65#endif-
66#ifdef QT_SQL_SQLITE2-
67#include "../drivers/sqlite2/qsql_sqlite2_p.h"-
68#endif-
69#ifdef QT_SQL_IBASE-
70#undef SQL_FLOAT // avoid clash with ODBC-
71#undef SQL_DOUBLE-
72#undef SQL_TIMESTAMP-
73#undef SQL_TYPE_TIME-
74#undef SQL_TYPE_DATE-
75#undef SQL_DATE-
76#define SCHAR IBASE_SCHAR // avoid clash with ODBC (older versions of ibase.h with Firebird)-
77#include "../drivers/ibase/qsql_ibase_p.h"-
78#undef SCHAR-
79#endif-
80-
81#include "qdebug.h"-
82#include "qcoreapplication.h"-
83#include "qreadwritelock.h"-
84#include "qsqlresult.h"-
85#include "qsqldriver.h"-
86#include "qsqldriverplugin.h"-
87#include "qsqlindex.h"-
88#include "private/qfactoryloader_p.h"-
89#include "private/qsqlnulldriver_p.h"-
90#include "qmutex.h"-
91#include "qhash.h"-
92#include <stdlib.h>-
93-
94QT_BEGIN_NAMESPACE-
95-
96#ifndef QT_NO_LIBRARY-
97Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
executed 9 times by 9 tests: end of block
Executed by:
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
executed 9 times by 9 tests: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
executed 96 times by 9 tests: return &holder.value;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
guard.load() =...c::InitializedDescription
TRUEevaluated 9 times by 9 tests
Evaluated by:
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
FALSEnever evaluated
0-96
98 (QSqlDriverFactoryInterface_iid,-
99 QLatin1String("/sqldrivers")))-
100#endif-
101-
102#if !defined(Q_CC_MSVC) || _MSC_VER >= 1900-
103// ### Qt6: remove the #ifdef-
104const-
105#endif-
106char *QSqlDatabase::defaultConnection = const_cast<char *>("qt_sql_default_connection");-
107-
108typedef QHash<QString, QSqlDriverCreatorBase*> DriverDict;-
109-
110class QConnectionDict: public QHash<QString, QSqlDatabase>-
111{-
112public:-
113 inline bool contains_ts(const QString &key)-
114 {-
115 QReadLocker locker(&lock);-
116 return contains(key);
executed 2 times by 1 test: return contains(key);
Executed by:
  • tst_QSqlDatabase
2
117 }-
118 inline QStringList keys_ts() const-
119 {-
120 QReadLocker locker(&lock);-
121 return keys();
never executed: return keys();
0
122 }-
123-
124 mutable QReadWriteLock lock;-
125};-
126Q_GLOBAL_STATIC(QConnectionDict, dbDict)
executed 9 times by 9 tests: end of block
Executed by:
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
executed 9 times by 9 tests: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
executed 2324 times by 17 tests: return &holder.value;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
guard.load() =...c::InitializedDescription
TRUEevaluated 9 times by 9 tests
Evaluated by:
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
FALSEnever evaluated
0-2324
127-
128class QSqlDatabasePrivate-
129{-
130public:-
131 QSqlDatabasePrivate(QSqlDatabase *d, QSqlDriver *dr = 0):-
132 ref(1),-
133 q(d),-
134 driver(dr),-
135 port(-1)-
136 {-
137 precisionPolicy = QSql::LowPrecisionDouble;-
138 }
executed 44 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
44
139 QSqlDatabasePrivate(const QSqlDatabasePrivate &other);-
140 ~QSqlDatabasePrivate();-
141 void init(const QString& type);-
142 void copy(const QSqlDatabasePrivate *other);-
143 void disable();-
144-
145 QAtomicInt ref;-
146 QSqlDatabase *q;-
147 QSqlDriver* driver;-
148 QString dbname;-
149 QString uname;-
150 QString pword;-
151 QString hname;-
152 QString drvName;-
153 int port;-
154 QString connOptions;-
155 QString connName;-
156 QSql::NumericalPrecisionPolicy precisionPolicy;-
157-
158 static QSqlDatabasePrivate *shared_null();-
159 static QSqlDatabase database(const QString& name, bool open);-
160 static void addDatabase(const QSqlDatabase &db, const QString & name);-
161 static void removeDatabase(const QString& name);-
162 static void invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn = true);-
163 static DriverDict &driverDict();-
164 static void cleanConnections();-
165};-
166-
167QSqlDatabasePrivate::QSqlDatabasePrivate(const QSqlDatabasePrivate &other) : ref(1)-
168{-
169 q = other.q;-
170 dbname = other.dbname;-
171 uname = other.uname;-
172 pword = other.pword;-
173 hname = other.hname;-
174 drvName = other.drvName;-
175 port = other.port;-
176 connOptions = other.connOptions;-
177 driver = other.driver;-
178 precisionPolicy = other.precisionPolicy;-
179}
never executed: end of block
0
180-
181QSqlDatabasePrivate::~QSqlDatabasePrivate()-
182{-
183 if (driver != shared_null()->driver)
driver != shar...null()->driverDescription
TRUEevaluated 33 times by 11 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
FALSEevaluated 13 times by 12 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlQuery
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
13-33
184 delete driver;
executed 33 times by 11 tests: delete driver;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
33
185}
executed 46 times by 17 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
46
186-
187void QSqlDatabasePrivate::cleanConnections()-
188{-
189 QConnectionDict *dict = dbDict();-
190 Q_ASSERT(dict);-
191 QWriteLocker locker(&dict->lock);-
192-
193 QConnectionDict::iterator it = dict->begin();-
194 while (it != dict->end()) {
it != dict->end()Description
TRUEevaluated 7 times by 4 tests
Evaluated by:
  • tst_QSql
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
FALSEevaluated 22 times by 9 tests
Evaluated by:
  • tst_QSql
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
7-22
195 invalidateDb(it.value(), it.key(), false);-
196 ++it;-
197 }
executed 7 times by 4 tests: end of block
Executed by:
  • tst_QSql
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
7
198 dict->clear();-
199}
executed 22 times by 9 tests: end of block
Executed by:
  • tst_QSql
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
22
200-
201static bool qDriverDictInit = false;-
202static void cleanDriverDict()-
203{-
204 qDeleteAll(QSqlDatabasePrivate::driverDict());-
205 QSqlDatabasePrivate::driverDict().clear();-
206 QSqlDatabasePrivate::cleanConnections();-
207 qDriverDictInit = false;-
208}
executed 22 times by 9 tests: end of block
Executed by:
  • tst_QSql
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
22
209-
210DriverDict &QSqlDatabasePrivate::driverDict()-
211{-
212 static DriverDict dict;-
213 if (!qDriverDictInit) {
!qDriverDictInitDescription
TRUEevaluated 21 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEevaluated 87 times by 16 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
21-87
214 qDriverDictInit = true;-
215 qAddPostRoutine(cleanDriverDict);-
216 }
executed 21 times by 8 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
21
217 return dict;
executed 108 times by 17 tests: return dict;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
108
218}-
219-
220QSqlDatabasePrivate *QSqlDatabasePrivate::shared_null()-
221{-
222 static QSqlNullDriver dr;-
223 static QSqlDatabasePrivate n(NULL, &dr);-
224 return &n;
executed 8131 times by 18 tests: return &n;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsql - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqldriver - unknown status
  • tst_qsqlquery - unknown status
  • tst_qsqlquerymodel - unknown status
  • tst_qsqlrelationaltablemodel - unknown status
  • tst_qsqltablemodel - unknown status
  • tst_qsqlthread - unknown status
8131
225}-
226-
227void QSqlDatabasePrivate::invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn)-
228{-
229 if (db.d->ref.load() != 1 && doWarn) {
db.d->ref.load() != 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlDatabase
FALSEevaluated 36 times by 11 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
doWarnDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlDatabase
FALSEnever evaluated
0-36
230 qWarning("QSqlDatabasePrivate::removeDatabase: connection '%s' is still in use, "-
231 "all queries will cease to work.", name.toLocal8Bit().constData());-
232 db.d->disable();-
233 db.d->connName.clear();-
234 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSqlDatabase
1
235}
executed 37 times by 11 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
37
236-
237void QSqlDatabasePrivate::removeDatabase(const QString &name)-
238{-
239 QConnectionDict *dict = dbDict();-
240 Q_ASSERT(dict);-
241 QWriteLocker locker(&dict->lock);-
242-
243 if (!dict->contains(name))
!dict->contains(name)Description
TRUEnever evaluated
FALSEevaluated 30 times by 8 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
0-30
244 return;
never executed: return;
0
245-
246 invalidateDb(dict->take(name), name);-
247}
executed 30 times by 8 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
30
248-
249void QSqlDatabasePrivate::addDatabase(const QSqlDatabase &db, const QString &name)-
250{-
251 QConnectionDict *dict = dbDict();-
252 Q_ASSERT(dict);-
253 QWriteLocker locker(&dict->lock);-
254-
255 if (dict->contains(name)) {
dict->contains(name)Description
TRUEnever evaluated
FALSEevaluated 36 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
0-36
256 invalidateDb(dict->take(name), name);-
257 qWarning("QSqlDatabasePrivate::addDatabase: duplicate connection name '%s', old "-
258 "connection removed.", name.toLocal8Bit().data());-
259 }
never executed: end of block
0
260 dict->insert(name, db);-
261 db.d->connName = name;-
262}
executed 36 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
36
263-
264/*! \internal-
265*/-
266QSqlDatabase QSqlDatabasePrivate::database(const QString& name, bool open)-
267{-
268 const QConnectionDict *dict = dbDict();-
269 Q_ASSERT(dict);-
270-
271 dict->lock.lockForRead();-
272 QSqlDatabase db = dict->value(name);-
273 dict->lock.unlock();-
274 if (db.isValid() && !db.isOpen() && open) {
db.isValid()Description
TRUEevaluated 1972 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 262 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
!db.isOpen()Description
TRUEevaluated 24 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEevaluated 1948 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
openDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 19 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
5-1972
275 if (!db.open())
!db.open()Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QSqlQuery
0-5
276 qWarning() << "QSqlDatabasePrivate::database: unable to open database:" << db.lastError().text();
never executed: QMessageLogger(__FILE__, 276, __PRETTY_FUNCTION__).warning() << "QSqlDatabasePrivate::database: unable to open database:" << db.lastError().text();
0
277-
278 }
executed 5 times by 1 test: end of block
Executed by:
  • tst_QSqlQuery
5
279 return db;
executed 2234 times by 9 tests: return db;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2234
280}-
281-
282-
283/*! \internal-
284 Copies the connection data from \a other.-
285*/-
286void QSqlDatabasePrivate::copy(const QSqlDatabasePrivate *other)-
287{-
288 q = other->q;-
289 dbname = other->dbname;-
290 uname = other->uname;-
291 pword = other->pword;-
292 hname = other->hname;-
293 drvName = other->drvName;-
294 port = other->port;-
295 connOptions = other->connOptions;-
296 precisionPolicy = other->precisionPolicy;-
297}
executed 7 times by 3 tests: end of block
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlTableModel
  • tst_QSqlThread
7
298-
299void QSqlDatabasePrivate::disable()-
300{-
301 if (driver != shared_null()->driver) {
driver != shar...null()->driverDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlDatabase
FALSEnever evaluated
0-1
302 delete driver;-
303 driver = shared_null()->driver;-
304 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSqlDatabase
1
305}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSqlDatabase
1
306-
307/*!-
308 \class QSqlDriverCreatorBase-
309 \brief The QSqlDriverCreatorBase class is the base class for-
310 SQL driver factories.-
311-
312 \ingroup database-
313 \inmodule QtSql-
314-
315 Reimplement createObject() to return an instance of the specific-
316 QSqlDriver subclass that you want to provide.-
317-
318 See QSqlDatabase::registerSqlDriver() for details.-
319-
320 \sa QSqlDriverCreator-
321*/-
322-
323/*!-
324 \fn QSqlDriverCreatorBase::~QSqlDriverCreatorBase()-
325-
326 Destroys the SQL driver creator object.-
327*/-
328-
329/*!-
330 \fn QSqlDriver *QSqlDriverCreatorBase::createObject() const-
331-
332 Reimplement this function to returns a new instance of a-
333 QSqlDriver subclass.-
334*/-
335-
336/*!-
337 \class QSqlDriverCreator-
338 \brief The QSqlDriverCreator class is a template class that-
339 provides a SQL driver factory for a specific driver type.-
340-
341 \ingroup database-
342 \inmodule QtSql-
343-
344 QSqlDriverCreator<T> instantiates objects of type T, where T is a-
345 QSqlDriver subclass.-
346-
347 See QSqlDatabase::registerSqlDriver() for details.-
348*/-
349-
350/*!-
351 \fn QSqlDriver *QSqlDriverCreator::createObject() const-
352 \reimp-
353*/-
354-
355/*!-
356 \class QSqlDatabase-
357 \brief The QSqlDatabase class represents a connection to-
358 a database.-
359-
360 \ingroup database-
361-
362 \inmodule QtSql-
363-
364 The QSqlDatabase class provides an interface for accessing a-
365 database through a connection. An instance of QSqlDatabase-
366 represents the connection. The connection provides access to the-
367 database via one of the \l{SQL Database Drivers#Supported-
368 Databases} {supported database drivers}, which are derived from-
369 QSqlDriver. Alternatively, you can subclass your own database-
370 driver from QSqlDriver. See \l{How to Write Your Own Database-
371 Driver} for more information.-
372-
373 Create a connection (i.e., an instance of QSqlDatabase) by calling-
374 one of the static addDatabase() functions, where you specify-
375 \l{SQL Database Drivers#Supported Databases} {the driver or type-
376 of driver} to use (i.e., what kind of database will you access?)-
377 and a connection name. A connection is known by its own name,-
378 \e{not} by the name of the database it connects to. You can have-
379 multiple connections to one database. QSqlDatabase also supports-
380 the concept of a \e{default} connection, which is the unnamed-
381 connection. To create the default connection, don't pass the-
382 connection name argument when you call addDatabase().-
383 Subsequently, when you call any static member function that takes-
384 the connection name argument, if you don't pass the connection-
385 name argument, the default connection is assumed. The following-
386 snippet shows how to create and open a default connection to a-
387 PostgreSQL database:-
388-
389 \snippet sqldatabase/sqldatabase.cpp 0-
390-
391 Once the QSqlDatabase object has been created, set the connection-
392 parameters with setDatabaseName(), setUserName(), setPassword(),-
393 setHostName(), setPort(), and setConnectOptions(). Then call-
394 open() to activate the physical connection to the database. The-
395 connection is not usable until you open it.-
396-
397 The connection defined above will be the \e{default} connection,-
398 because we didn't give a connection name to \l{QSqlDatabase::}-
399 {addDatabase()}. Subsequently, you can get the default connection-
400 by calling database() without the connection name argument:-
401-
402 \snippet sqldatabase/sqldatabase.cpp 1-
403-
404 QSqlDatabase is a value class. Changes made to a database-
405 connection via one instance of QSqlDatabase will affect other-
406 instances of QSqlDatabase that represent the same connection. Use-
407 cloneDatabase() to create an independent database connection based-
408 on an existing one.-
409-
410 If you create multiple database connections, specify a unique-
411 connection name for each one, when you call addDatabase(). Use-
412 database() with a connection name to get that connection. Use-
413 removeDatabase() with a connection name to remove a connection.-
414 QSqlDatabase outputs a warning if you try to remove a connection-
415 referenced by other QSqlDatabase objects. Use contains() to see if-
416 a given connection name is in the list of connections.-
417-
418 Once a connection is established, you can call tables() to get the-
419 list of tables in the database, call primaryIndex() to get a-
420 table's primary index, and call record() to get meta-information-
421 about a table's fields (e.g., field names).-
422-
423 \note QSqlDatabase::exec() is deprecated. Use QSqlQuery::exec()-
424 instead.-
425-
426 If the driver supports transactions, use transaction() to start a-
427 transaction, and commit() or rollback() to complete it. Use-
428 \l{QSqlDriver::} {hasFeature()} to ask if the driver supports-
429 transactions. \note When using transactions, you must start the-
430 transaction before you create your query.-
431-
432 If an error occurs, lastError() will return information about it.-
433-
434 Get the names of the available SQL drivers with drivers(). Check-
435 for the presence of a particular driver with isDriverAvailable().-
436 If you have created your own custom driver, you must register it-
437 with registerSqlDriver().-
438-
439 \sa QSqlDriver, QSqlQuery, {Qt SQL}, {Threads and the SQL Module}-
440*/-
441-
442/*! \fn QSqlDatabase QSqlDatabase::addDatabase(const QString &type, const QString &connectionName)-
443 \threadsafe-
444-
445 Adds a database to the list of database connections using the-
446 driver \a type and the connection name \a connectionName. If-
447 there already exists a database connection called \a-
448 connectionName, that connection is removed.-
449-
450 The database connection is referred to by \a connectionName. The-
451 newly added database connection is returned.-
452-
453 If \a type is not available or could not be loaded, isValid() returns \c false.-
454-
455 If \a connectionName is not specified, the new connection becomes-
456 the default connection for the application, and subsequent calls-
457 to database() without the connection name argument will return the-
458 default connection. If a \a connectionName is provided here, use-
459 database(\a connectionName) to retrieve the connection.-
460-
461 \warning If you add a connection with the same name as an existing-
462 connection, the new connection replaces the old one. If you call-
463 this function more than once without specifying \a connectionName,-
464 the default connection will be the one replaced.-
465-
466 Before using the connection, it must be initialized. e.g., call-
467 some or all of setDatabaseName(), setUserName(), setPassword(),-
468 setHostName(), setPort(), and setConnectOptions(), and, finally,-
469 open().-
470-
471 \sa database(), removeDatabase(), {Threads and the SQL Module}-
472*/-
473QSqlDatabase QSqlDatabase::addDatabase(const QString &type, const QString &connectionName)-
474{-
475 QSqlDatabase db(type);-
476 QSqlDatabasePrivate::addDatabase(db, connectionName);-
477 return db;
executed 29 times by 8 tests: return db;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
29
478}-
479-
480/*!-
481 \threadsafe-
482-
483 Returns the database connection called \a connectionName. The-
484 database connection must have been previously added with-
485 addDatabase(). If \a open is true (the default) and the database-
486 connection is not already open it is opened now. If no \a-
487 connectionName is specified the default connection is used. If \a-
488 connectionName does not exist in the list of databases, an invalid-
489 connection is returned.-
490-
491 \sa isOpen(), {Threads and the SQL Module}-
492*/-
493-
494QSqlDatabase QSqlDatabase::database(const QString& connectionName, bool open)-
495{-
496 return QSqlDatabasePrivate::database(connectionName, open);
executed 2234 times by 9 tests: return QSqlDatabasePrivate::database(connectionName, open);
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2234
497}-
498-
499/*!-
500 \threadsafe-
501-
502 Removes the database connection \a connectionName from the list of-
503 database connections.-
504-
505 \warning There should be no open queries on the database-
506 connection when this function is called, otherwise a resource leak-
507 will occur.-
508-
509 Example:-
510-
511 \snippet code/src_sql_kernel_qsqldatabase.cpp 0-
512-
513 The correct way to do it:-
514-
515 \snippet code/src_sql_kernel_qsqldatabase.cpp 1-
516-
517 To remove the default connection, which may have been created with a-
518 call to addDatabase() not specifying a connection name, you can-
519 retrieve the default connection name by calling connectionName() on-
520 the database returned by database(). Note that if a default database-
521 hasn't been created an invalid database will be returned.-
522-
523 \sa database(), connectionName(), {Threads and the SQL Module}-
524*/-
525-
526void QSqlDatabase::removeDatabase(const QString& connectionName)-
527{-
528 QSqlDatabasePrivate::removeDatabase(connectionName);-
529}
executed 30 times by 8 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
30
530-
531/*!-
532 Returns a list of all the available database drivers.-
533-
534 \sa registerSqlDriver()-
535*/-
536-
537QStringList QSqlDatabase::drivers()-
538{-
539 QStringList list;-
540-
541#ifdef QT_SQL_PSQL-
542 list << QLatin1String("QPSQL7");-
543 list << QLatin1String("QPSQL");-
544#endif-
545#ifdef QT_SQL_MYSQL-
546 list << QLatin1String("QMYSQL3");-
547 list << QLatin1String("QMYSQL");-
548#endif-
549#ifdef QT_SQL_ODBC-
550 list << QLatin1String("QODBC3");-
551 list << QLatin1String("QODBC");-
552#endif-
553#ifdef QT_SQL_OCI-
554 list << QLatin1String("QOCI8");-
555 list << QLatin1String("QOCI");-
556#endif-
557#ifdef QT_SQL_TDS-
558 list << QLatin1String("QTDS7");-
559 list << QLatin1String("QTDS");-
560#endif-
561#ifdef QT_SQL_DB2-
562 list << QLatin1String("QDB2");-
563#endif-
564#ifdef QT_SQL_SQLITE-
565 list << QLatin1String("QSQLITE");-
566#endif-
567#ifdef QT_SQL_SQLITE2-
568 list << QLatin1String("QSQLITE2");-
569#endif-
570#ifdef QT_SQL_IBASE-
571 list << QLatin1String("QIBASE");-
572#endif-
573-
574#ifndef QT_NO_LIBRARY-
575 if (QFactoryLoader *fl = loader()) {
QFactoryLoader *fl = loader()Description
TRUEevaluated 26 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-26
576 typedef QMultiMap<int, QString> PluginKeyMap;-
577 typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;-
578-
579 const PluginKeyMap keyMap = fl->keyMap();-
580 const PluginKeyMapConstIterator cend = keyMap.constEnd();-
581 for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it)
it != cendDescription
TRUEevaluated 234 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEevaluated 26 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
26-234
582 if (!list.contains(it.value()))
!list.contains(it.value())Description
TRUEevaluated 234 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-234
583 list << it.value();
executed 234 times by 7 tests: list << it.value();
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
234
584 }
executed 26 times by 7 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
26
585#endif-
586-
587 DriverDict dict = QSqlDatabasePrivate::driverDict();-
588 for (DriverDict::const_iterator i = dict.constBegin(); i != dict.constEnd(); ++i) {
i != dict.constEnd()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSql
FALSEevaluated 26 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
1-26
589 if (!list.contains(i.key()))
!list.contains(i.key())Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSql
FALSEnever evaluated
0-1
590 list << i.key();
executed 1 time by 1 test: list << i.key();
Executed by:
  • tst_QSql
1
591 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSql
1
592-
593 return list;
executed 26 times by 7 tests: return list;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
26
594}-
595-
596/*!-
597 This function registers a new SQL driver called \a name, within-
598 the SQL framework. This is useful if you have a custom SQL driver-
599 and don't want to compile it as a plugin.-
600-
601 Example:-
602 \snippet code/src_sql_kernel_qsqldatabase.cpp 2-
603-
604 QSqlDatabase takes ownership of the \a creator pointer, so you-
605 mustn't delete it yourself.-
606-
607 \sa drivers()-
608*/-
609void QSqlDatabase::registerSqlDriver(const QString& name, QSqlDriverCreatorBase *creator)-
610{-
611 delete QSqlDatabasePrivate::driverDict().take(name);-
612 if (creator)
creatorDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSql
FALSEnever evaluated
0-1
613 QSqlDatabasePrivate::driverDict().insert(name, creator);
executed 1 time by 1 test: QSqlDatabasePrivate::driverDict().insert(name, creator);
Executed by:
  • tst_QSql
1
614}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSql
1
615-
616/*!-
617 \threadsafe-
618-
619 Returns \c true if the list of database connections contains \a-
620 connectionName; otherwise returns \c false.-
621-
622 \sa connectionNames(), database(), {Threads and the SQL Module}-
623*/-
624-
625bool QSqlDatabase::contains(const QString& connectionName)-
626{-
627 return dbDict()->contains_ts(connectionName);
executed 2 times by 1 test: return dbDict()->contains_ts(connectionName);
Executed by:
  • tst_QSqlDatabase
2
628}-
629-
630/*!-
631 \threadsafe-
632-
633 Returns a list containing the names of all connections.-
634-
635 \sa contains(), database(), {Threads and the SQL Module}-
636*/-
637QStringList QSqlDatabase::connectionNames()-
638{-
639 return dbDict()->keys_ts();
never executed: return dbDict()->keys_ts();
0
640}-
641-
642/*!-
643 \overload-
644-
645 Creates a QSqlDatabase connection that uses the driver referred-
646 to by \a type. If the \a type is not recognized, the database-
647 connection will have no functionality.-
648-
649 The currently available driver types are:-
650-
651 \table-
652 \header \li Driver Type \li Description-
653 \row \li QDB2 \li IBM DB2-
654 \row \li QIBASE \li Borland InterBase Driver-
655 \row \li QMYSQL \li MySQL Driver-
656 \row \li QOCI \li Oracle Call Interface Driver-
657 \row \li QODBC \li ODBC Driver (includes Microsoft SQL Server)-
658 \row \li QPSQL \li PostgreSQL Driver-
659 \row \li QSQLITE \li SQLite version 3 or above-
660 \row \li QSQLITE2 \li SQLite version 2-
661 \row \li QTDS \li Sybase Adaptive Server-
662 \endtable-
663-
664 Additional third party drivers, including your own custom-
665 drivers, can be loaded dynamically.-
666-
667 \sa {SQL Database Drivers}, registerSqlDriver(), drivers()-
668*/-
669-
670QSqlDatabase::QSqlDatabase(const QString &type)-
671{-
672 d = new QSqlDatabasePrivate(this);-
673 d->init(type);-
674}
executed 36 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
36
675-
676/*!-
677 \overload-
678-
679 Creates a database connection using the given \a driver.-
680*/-
681-
682QSqlDatabase::QSqlDatabase(QSqlDriver *driver)-
683{-
684 d = new QSqlDatabasePrivate(this, driver);-
685}
never executed: end of block
0
686-
687/*!-
688 Creates an empty, invalid QSqlDatabase object. Use addDatabase(),-
689 removeDatabase(), and database() to get valid QSqlDatabase-
690 objects.-
691*/-
692QSqlDatabase::QSqlDatabase()-
693{-
694 d = QSqlDatabasePrivate::shared_null();-
695 d->ref.ref();-
696}
executed 1287 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1287
697-
698/*!-
699 Creates a copy of \a other.-
700*/-
701QSqlDatabase::QSqlDatabase(const QSqlDatabase &other)-
702{-
703 d = other.d;-
704 d->ref.ref();-
705}
executed 19118 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
19118
706-
707/*!-
708 Assigns \a other to this object.-
709*/-
710QSqlDatabase &QSqlDatabase::operator=(const QSqlDatabase &other)-
711{-
712 qAtomicAssign(d, other.d);-
713 return *this;
executed 968 times by 9 tests: return *this;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
968
714}-
715-
716/*!-
717 \internal-
718-
719 Create the actual driver instance \a type.-
720*/-
721-
722void QSqlDatabasePrivate::init(const QString &type)-
723{-
724 drvName = type;-
725-
726 if (!driver) {
!driverDescription
TRUEevaluated 36 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-36
727#ifdef QT_SQL_PSQL-
728 if (type == QLatin1String("QPSQL") || type == QLatin1String("QPSQL7"))-
729 driver = new QPSQLDriver();-
730#endif-
731#ifdef QT_SQL_MYSQL-
732 if (type == QLatin1String("QMYSQL") || type == QLatin1String("QMYSQL3"))-
733 driver = new QMYSQLDriver();-
734#endif-
735#ifdef QT_SQL_ODBC-
736 if (type == QLatin1String("QODBC") || type == QLatin1String("QODBC3"))-
737 driver = new QODBCDriver();-
738#endif-
739#ifdef QT_SQL_OCI-
740 if (type == QLatin1String("QOCI") || type == QLatin1String("QOCI8"))-
741 driver = new QOCIDriver();-
742#endif-
743#ifdef QT_SQL_TDS-
744 if (type == QLatin1String("QTDS") || type == QLatin1String("QTDS7"))-
745 driver = new QTDSDriver();-
746#endif-
747#ifdef QT_SQL_DB2-
748 if (type == QLatin1String("QDB2"))-
749 driver = new QDB2Driver();-
750#endif-
751#ifdef QT_SQL_SQLITE-
752 if (type == QLatin1String("QSQLITE"))-
753 driver = new QSQLiteDriver();-
754#endif-
755#ifdef QT_SQL_SQLITE2-
756 if (type == QLatin1String("QSQLITE2"))-
757 driver = new QSQLite2Driver();-
758#endif-
759#ifdef QT_SQL_IBASE-
760 if (type == QLatin1String("QIBASE"))-
761 driver = new QIBaseDriver();-
762#endif-
763 }
executed 36 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
36
764-
765 if (!driver) {
!driverDescription
TRUEevaluated 36 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-36
766 DriverDict dict = QSqlDatabasePrivate::driverDict();-
767 for (DriverDict::const_iterator it = dict.constBegin();-
768 it != dict.constEnd() && !driver; ++it) {
it != dict.constEnd()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSql
FALSEevaluated 36 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
!driverDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSql
FALSEnever evaluated
0-36
769 if (type == it.key()) {
type == it.key()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSql
FALSEnever evaluated
0-1
770 driver = ((QSqlDriverCreatorBase*)(*it))->createObject();-
771 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSql
1
772 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSql
1
773 }
executed 36 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
36
774-
775#ifndef QT_NO_LIBRARY-
776 if (!driver && loader())
!driverDescription
TRUEevaluated 35 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSql
loader()Description
TRUEevaluated 35 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-35
777 driver = qLoadPlugin<QSqlDriver, QSqlDriverPlugin>(loader(), type);
executed 35 times by 9 tests: driver = qLoadPlugin<QSqlDriver, QSqlDriverPlugin>(loader(), type);
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
35
778#endif // QT_NO_LIBRARY-
779-
780 if (!driver) {
!driverDescription
TRUEevaluated 3 times by 3 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlQuery
FALSEevaluated 33 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
3-33
781 qWarning("QSqlDatabase: %s driver not loaded", type.toLatin1().data());-
782 qWarning("QSqlDatabase: available drivers: %s",-
783 QSqlDatabase::drivers().join(QLatin1Char(' ')).toLatin1().data());-
784 if (QCoreApplication::instance() == 0)
QCoreApplicati...nstance() == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSql
FALSEevaluated 2 times by 2 tests
Evaluated by:
  • tst_QSqlDatabase
  • tst_QSqlQuery
1-2
785 qWarning("QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins");
executed 1 time by 1 test: QMessageLogger(__FILE__, 785, __PRETTY_FUNCTION__).warning("QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins");
Executed by:
  • tst_QSql
1
786 driver = shared_null()->driver;-
787 }
executed 3 times by 3 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlQuery
3
788}
executed 36 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
36
789-
790/*!-
791 Destroys the object and frees any allocated resources.-
792-
793 \sa close()-
794*/-
795-
796QSqlDatabase::~QSqlDatabase()-
797{-
798 if (!d->ref.deref()) {
!d->ref.deref()Description
TRUEevaluated 37 times by 11 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
FALSEevaluated 20405 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
37-20405
799 close();-
800 delete d;-
801 }
executed 37 times by 11 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
37
802}
executed 20442 times by 12 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
20442
803-
804/*!-
805 Executes a SQL statement on the database and returns a QSqlQuery-
806 object. Use lastError() to retrieve error information. If \a-
807 query is empty, an empty, invalid query is returned and-
808 lastError() is not affected.-
809-
810 \sa QSqlQuery, lastError()-
811*/-
812-
813QSqlQuery QSqlDatabase::exec(const QString & query) const-
814{-
815 QSqlQuery r(d->driver->createResult());-
816 if (!query.isEmpty()) {
!query.isEmpty()Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEnever evaluated
0-16
817 r.exec(query);-
818 d->driver->setLastError(r.lastError());-
819 }
executed 16 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
16
820 return r;
executed 16 times by 1 test: return r;
Executed by:
  • tst_QSqlRelationalTableModel
16
821}-
822-
823/*!-
824 Opens the database connection using the current connection-
825 values. Returns \c true on success; otherwise returns \c false. Error-
826 information can be retrieved using lastError().-
827-
828 \sa lastError(), setDatabaseName(), setUserName(), setPassword(),-
829 setHostName(), setPort(), setConnectOptions()-
830*/-
831-
832bool QSqlDatabase::open()-
833{-
834 return d->driver->open(d->dbname, d->uname, d->pword, d->hname,
executed 48 times by 9 tests: return d->driver->open(d->dbname, d->uname, d->pword, d->hname, d->port, d->connOptions);
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
48
835 d->port, d->connOptions);
executed 48 times by 9 tests: return d->driver->open(d->dbname, d->uname, d->pword, d->hname, d->port, d->connOptions);
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
48
836}-
837-
838/*!-
839 \overload-
840-
841 Opens the database connection using the given \a user name and \a-
842 password. Returns \c true on success; otherwise returns \c false. Error-
843 information can be retrieved using the lastError() function.-
844-
845 This function does not store the password it is given. Instead,-
846 the password is passed directly to the driver for opening the-
847 connection and it is then discarded.-
848-
849 \sa lastError()-
850*/-
851-
852bool QSqlDatabase::open(const QString& user, const QString& password)-
853{-
854 setUserName(user);-
855 return d->driver->open(d->dbname, user, password, d->hname,
executed 1 time by 1 test: return d->driver->open(d->dbname, user, password, d->hname, d->port, d->connOptions);
Executed by:
  • tst_QSql
1
856 d->port, d->connOptions);
executed 1 time by 1 test: return d->driver->open(d->dbname, user, password, d->hname, d->port, d->connOptions);
Executed by:
  • tst_QSql
1
857}-
858-
859/*!-
860 Closes the database connection, freeing any resources acquired, and-
861 invalidating any existing QSqlQuery objects that are used with the-
862 database.-
863-
864 This will also affect copies of this QSqlDatabase object.-
865-
866 \sa removeDatabase()-
867*/-
868-
869void QSqlDatabase::close()-
870{-
871 d->driver->close();-
872}
executed 80 times by 11 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qitemmodel - unknown status
  • tst_qsqldatabase - unknown status
  • tst_qsqltablemodel - unknown status
80
873-
874/*!-
875 Returns \c true if the database connection is currently open;-
876 otherwise returns \c false.-
877*/-
878-
879bool QSqlDatabase::isOpen() const-
880{-
881 return d->driver->isOpen();
executed 2030 times by 9 tests: return d->driver->isOpen();
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2030
882}-
883-
884/*!-
885 Returns \c true if there was an error opening the database-
886 connection; otherwise returns \c false. Error information can be-
887 retrieved using the lastError() function.-
888*/-
889-
890bool QSqlDatabase::isOpenError() const-
891{-
892 return d->driver->isOpenError();
executed 10 times by 1 test: return d->driver->isOpenError();
Executed by:
  • tst_QSqlDatabase
10
893}-
894-
895/*!-
896 Begins a transaction on the database if the driver supports-
897 transactions. Returns \c{true} if the operation succeeded.-
898 Otherwise it returns \c{false}.-
899-
900 \sa QSqlDriver::hasFeature(), commit(), rollback()-
901*/-
902bool QSqlDatabase::transaction()-
903{-
904 if (!d->driver->hasFeature(QSqlDriver::Transactions))
!d->driver->ha...:Transactions)Description
TRUEnever evaluated
FALSEevaluated 5 times by 3 tests
Evaluated by:
  • tst_QSqlDatabase
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
0-5
905 return false;
never executed: return false;
0
906 return d->driver->beginTransaction();
executed 5 times by 3 tests: return d->driver->beginTransaction();
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
5
907}-
908-
909/*!-
910 Commits a transaction to the database if the driver supports-
911 transactions and a transaction() has been started. Returns \c{true}-
912 if the operation succeeded. Otherwise it returns \c{false}.-
913-
914 \note For some databases, the commit will fail and return \c{false}-
915 if there is an \l{QSqlQuery::isActive()} {active query} using the-
916 database for a \c{SELECT}. Make the query \l{QSqlQuery::isActive()}-
917 {inactive} before doing the commit.-
918-
919 Call lastError() to get information about errors.-
920-
921 \sa QSqlQuery::isActive(), QSqlDriver::hasFeature(), rollback()-
922*/-
923bool QSqlDatabase::commit()-
924{-
925 if (!d->driver->hasFeature(QSqlDriver::Transactions))
!d->driver->ha...:Transactions)Description
TRUEnever evaluated
FALSEevaluated 4 times by 3 tests
Evaluated by:
  • tst_QSqlDatabase
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
0-4
926 return false;
never executed: return false;
0
927 return d->driver->commitTransaction();
executed 4 times by 3 tests: return d->driver->commitTransaction();
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
4
928}-
929-
930/*!-
931 Rolls back a transaction on the database, if the driver supports-
932 transactions and a transaction() has been started. Returns \c{true}-
933 if the operation succeeded. Otherwise it returns \c{false}.-
934-
935 \note For some databases, the rollback will fail and return-
936 \c{false} if there is an \l{QSqlQuery::isActive()} {active query}-
937 using the database for a \c{SELECT}. Make the query-
938 \l{QSqlQuery::isActive()} {inactive} before doing the rollback.-
939-
940 Call lastError() to get information about errors.-
941-
942 \sa QSqlQuery::isActive(), QSqlDriver::hasFeature(), commit()-
943*/-
944bool QSqlDatabase::rollback()-
945{-
946 if (!d->driver->hasFeature(QSqlDriver::Transactions))
!d->driver->ha...:Transactions)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlDatabase
0-1
947 return false;
never executed: return false;
0
948 return d->driver->rollbackTransaction();
executed 1 time by 1 test: return d->driver->rollbackTransaction();
Executed by:
  • tst_QSqlDatabase
1
949}-
950-
951/*!-
952 Sets the connection's database name to \a name. To have effect,-
953 the database name must be set \e{before} the connection is-
954 \l{open()} {opened}. Alternatively, you can close() the-
955 connection, set the database name, and call open() again. \note-
956 The \e{database name} is not the \e{connection name}. The-
957 connection name must be passed to addDatabase() at connection-
958 object create time.-
959-
960 For the QOCI (Oracle) driver, the database name is the TNS-
961 Service Name.-
962-
963 For the QODBC driver, the \a name can either be a DSN, a DSN-
964 filename (in which case the file must have a \c .dsn extension),-
965 or a connection string.-
966-
967 For example, Microsoft Access users can use the following-
968 connection string to open an \c .mdb file directly, instead of-
969 having to create a DSN entry in the ODBC manager:-
970-
971 \snippet code/src_sql_kernel_qsqldatabase.cpp 3-
972-
973 There is no default value.-
974-
975 \sa databaseName(), setUserName(), setPassword(), setHostName(),-
976 setPort(), setConnectOptions(), open()-
977*/-
978-
979void QSqlDatabase::setDatabaseName(const QString& name)-
980{-
981 if (isValid())
isValid()Description
TRUEevaluated 25 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-25
982 d->dbname = name;
executed 25 times by 9 tests: d->dbname = name;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
25
983}
executed 25 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
25
984-
985/*!-
986 Sets the connection's user name to \a name. To have effect, the-
987 user name must be set \e{before} the connection is \l{open()}-
988 {opened}. Alternatively, you can close() the connection, set the-
989 user name, and call open() again.-
990-
991 There is no default value.-
992-
993 \sa userName(), setDatabaseName(), setPassword(), setHostName(),-
994 setPort(), setConnectOptions(), open()-
995*/-
996-
997void QSqlDatabase::setUserName(const QString& name)-
998{-
999 if (isValid())
isValid()Description
TRUEevaluated 23 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-23
1000 d->uname = name;
executed 23 times by 7 tests: d->uname = name;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
23
1001}
executed 23 times by 7 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
23
1002-
1003/*!-
1004 Sets the connection's password to \a password. To have effect, the-
1005 password must be set \e{before} the connection is \l{open()}-
1006 {opened}. Alternatively, you can close() the connection, set the-
1007 password, and call open() again.-
1008-
1009 There is no default value.-
1010-
1011 \warning This function stores the password in plain text within-
1012 Qt. Use the open() call that takes a password as parameter to-
1013 avoid this behavior.-
1014-
1015 \sa password(), setUserName(), setDatabaseName(), setHostName(),-
1016 setPort(), setConnectOptions(), open()-
1017*/-
1018-
1019void QSqlDatabase::setPassword(const QString& password)-
1020{-
1021 if (isValid())
isValid()Description
TRUEevaluated 22 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-22
1022 d->pword = password;
executed 22 times by 7 tests: d->pword = password;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
22
1023}
executed 22 times by 7 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
22
1024-
1025/*!-
1026 Sets the connection's host name to \a host. To have effect, the-
1027 host name must be set \e{before} the connection is \l{open()}-
1028 {opened}. Alternatively, you can close() the connection, set the-
1029 host name, and call open() again.-
1030-
1031 There is no default value.-
1032-
1033 \sa hostName(), setUserName(), setPassword(), setDatabaseName(),-
1034 setPort(), setConnectOptions(), open()-
1035*/-
1036-
1037void QSqlDatabase::setHostName(const QString& host)-
1038{-
1039 if (isValid())
isValid()Description
TRUEevaluated 23 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-23
1040 d->hname = host;
executed 23 times by 7 tests: d->hname = host;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
23
1041}
executed 23 times by 7 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
23
1042-
1043/*!-
1044 Sets the connection's port number to \a port. To have effect, the-
1045 port number must be set \e{before} the connection is \l{open()}-
1046 {opened}. Alternatively, you can close() the connection, set the-
1047 port number, and call open() again..-
1048-
1049 There is no default value.-
1050-
1051 \sa port(), setUserName(), setPassword(), setHostName(),-
1052 setDatabaseName(), setConnectOptions(), open()-
1053*/-
1054-
1055void QSqlDatabase::setPort(int port)-
1056{-
1057 if (isValid())
isValid()Description
TRUEevaluated 20 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-20
1058 d->port = port;
executed 20 times by 7 tests: d->port = port;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
20
1059}
executed 20 times by 7 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
20
1060-
1061/*!-
1062 Returns the connection's database name, which may be empty.-
1063 \note The database name is not the connection name.-
1064-
1065 \sa setDatabaseName()-
1066*/-
1067QString QSqlDatabase::databaseName() const-
1068{-
1069 return d->dbname;
executed 21 times by 5 tests: return d->dbname;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlQuery
  • tst_QSqlTableModel
  • tst_QSqlThread
21
1070}-
1071-
1072/*!-
1073 Returns the connection's user name; it may be empty.-
1074-
1075 \sa setUserName()-
1076*/-
1077QString QSqlDatabase::userName() const-
1078{-
1079 return d->uname;
executed 2 times by 1 test: return d->uname;
Executed by:
  • tst_QSql
2
1080}-
1081-
1082/*!-
1083 Returns the connection's password. If the password was not set-
1084 with setPassword(), and if the password was given in the open()-
1085 call, or if no password was used, an empty string is returned.-
1086*/-
1087QString QSqlDatabase::password() const-
1088{-
1089 return d->pword;
executed 2 times by 1 test: return d->pword;
Executed by:
  • tst_QSql
2
1090}-
1091-
1092/*!-
1093 Returns the connection's host name; it may be empty.-
1094-
1095 \sa setHostName()-
1096*/-
1097QString QSqlDatabase::hostName() const-
1098{-
1099 return d->hname;
executed 11568 times by 8 tests: return d->hname;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
11568
1100}-
1101-
1102/*!-
1103 Returns the connection's driver name.-
1104-
1105 \sa addDatabase(), driver()-
1106*/-
1107QString QSqlDatabase::driverName() const-
1108{-
1109 return d->drvName;
executed 35675 times by 8 tests: return d->drvName;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
35675
1110}-
1111-
1112/*!-
1113 Returns the connection's port number. The value is undefined if-
1114 the port number has not been set.-
1115-
1116 \sa setPort()-
1117*/-
1118int QSqlDatabase::port() const-
1119{-
1120 return d->port;
executed 11568 times by 8 tests: return d->port;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
11568
1121}-
1122-
1123/*!-
1124 Returns the database driver used to access the database-
1125 connection.-
1126-
1127 \sa addDatabase(), drivers()-
1128*/-
1129-
1130QSqlDriver* QSqlDatabase::driver() const-
1131{-
1132 return d->driver;
executed 4315 times by 8 tests: return d->driver;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
4315
1133}-
1134-
1135/*!-
1136 Returns information about the last error that occurred on the-
1137 database.-
1138-
1139 Failures that occur in conjunction with an individual query are-
1140 reported by QSqlQuery::lastError().-
1141-
1142 \sa QSqlError, QSqlQuery::lastError()-
1143*/-
1144-
1145QSqlError QSqlDatabase::lastError() const-
1146{-
1147 return d->driver->lastError();
executed 29 times by 6 tests: return d->driver->lastError();
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
  • tst_QSqlThread
29
1148}-
1149-
1150-
1151/*!-
1152 Returns a list of the database's tables, system tables and views,-
1153 as specified by the parameter \a type.-
1154-
1155 \sa primaryIndex(), record()-
1156*/-
1157-
1158QStringList QSqlDatabase::tables(QSql::TableType type) const-
1159{-
1160 return d->driver->tables(type);
executed 51 times by 8 tests: return d->driver->tables(type);
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
51
1161}-
1162-
1163/*!-
1164 Returns the primary index for table \a tablename. If no primary-
1165 index exists an empty QSqlIndex is returned.-
1166-
1167 \sa tables(), record()-
1168*/-
1169-
1170QSqlIndex QSqlDatabase::primaryIndex(const QString& tablename) const-
1171{-
1172 return d->driver->primaryIndex(tablename);
executed 187 times by 4 tests: return d->driver->primaryIndex(tablename);
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
187
1173}-
1174-
1175-
1176/*!-
1177 Returns a QSqlRecord populated with the names of all the fields in-
1178 the table (or view) called \a tablename. The order in which the-
1179 fields appear in the record is undefined. If no such table (or-
1180 view) exists, an empty record is returned.-
1181*/-
1182-
1183QSqlRecord QSqlDatabase::record(const QString& tablename) const-
1184{-
1185 return d->driver->record(tablename);
executed 328 times by 5 tests: return d->driver->record(tablename);
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
328
1186}-
1187-
1188-
1189/*!-
1190 Sets database-specific \a options. This must be done before the-
1191 connection is opened or it has no effect (or you can close() the-
1192 connection, call this function and open() the connection again).-
1193-
1194 The format of the \a options string is a semicolon separated list-
1195 of option names or option=value pairs. The options depend on the-
1196 database client used:-
1197-
1198 \table-
1199 \header \li ODBC \li MySQL \li PostgreSQL-
1200 \row-
1201-
1202 \li-
1203 \list-
1204 \li SQL_ATTR_ACCESS_MODE-
1205 \li SQL_ATTR_LOGIN_TIMEOUT-
1206 \li SQL_ATTR_CONNECTION_TIMEOUT-
1207 \li SQL_ATTR_CURRENT_CATALOG-
1208 \li SQL_ATTR_METADATA_ID-
1209 \li SQL_ATTR_PACKET_SIZE-
1210 \li SQL_ATTR_TRACEFILE-
1211 \li SQL_ATTR_TRACE-
1212 \li SQL_ATTR_CONNECTION_POOLING-
1213 \li SQL_ATTR_ODBC_VERSION-
1214 \endlist-
1215-
1216 \li-
1217 \list-
1218 \li CLIENT_COMPRESS-
1219 \li CLIENT_FOUND_ROWS-
1220 \li CLIENT_IGNORE_SPACE-
1221 \li CLIENT_ODBC-
1222 \li CLIENT_NO_SCHEMA-
1223 \li CLIENT_INTERACTIVE-
1224 \li UNIX_SOCKET-
1225 \li MYSQL_OPT_RECONNECT-
1226 \li MYSQL_OPT_CONNECT_TIMEOUT-
1227 \li MYSQL_OPT_READ_TIMEOUT-
1228 \li MYSQL_OPT_WRITE_TIMEOUT-
1229 \li SSL_KEY-
1230 \li SSL_CERT-
1231 \li SSL_CA-
1232 \li SSL_CAPATH-
1233 \li SSL_CIPHER-
1234 \endlist-
1235-
1236 \li-
1237 \list-
1238 \li connect_timeout-
1239 \li options-
1240 \li tty-
1241 \li requiressl-
1242 \li service-
1243 \endlist-
1244-
1245 \header \li DB2 \li OCI \li TDS-
1246 \row-
1247-
1248 \li-
1249 \list-
1250 \li SQL_ATTR_ACCESS_MODE-
1251 \li SQL_ATTR_LOGIN_TIMEOUT-
1252 \endlist-
1253-
1254 \li-
1255 \list-
1256 \li OCI_ATTR_PREFETCH_ROWS-
1257 \li OCI_ATTR_PREFETCH_MEMORY-
1258 \endlist-
1259-
1260 \li-
1261 \e none-
1262-
1263 \header \li SQLite \li Interbase-
1264 \row-
1265-
1266 \li-
1267 \list-
1268 \li QSQLITE_BUSY_TIMEOUT-
1269 \li QSQLITE_OPEN_READONLY-
1270 \li QSQLITE_OPEN_URI-
1271 \li QSQLITE_ENABLE_SHARED_CACHE-
1272 \endlist-
1273-
1274 \li-
1275 \list-
1276 \li ISC_DPB_LC_CTYPE-
1277 \li ISC_DPB_SQL_ROLE_NAME-
1278 \endlist-
1279-
1280 \endtable-
1281-
1282 Examples:-
1283 \snippet code/src_sql_kernel_qsqldatabase.cpp 4-
1284-
1285 Refer to the client library documentation for more information-
1286 about the different options.-
1287-
1288 \sa connectOptions()-
1289*/-
1290-
1291void QSqlDatabase::setConnectOptions(const QString &options)-
1292{-
1293 if (isValid())
isValid()Description
TRUEevaluated 21 times by 7 tests
Evaluated by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
FALSEnever evaluated
0-21
1294 d->connOptions = options;
executed 21 times by 7 tests: d->connOptions = options;
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
21
1295}
executed 21 times by 7 tests: end of block
Executed by:
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlThread
21
1296-
1297/*!-
1298 Returns the connection options string used for this connection.-
1299 The string may be empty.-
1300-
1301 \sa setConnectOptions()-
1302 */-
1303QString QSqlDatabase::connectOptions() const-
1304{-
1305 return d->connOptions;
never executed: return d->connOptions;
0
1306}-
1307-
1308/*!-
1309 Returns \c true if a driver called \a name is available; otherwise-
1310 returns \c false.-
1311-
1312 \sa drivers()-
1313*/-
1314-
1315bool QSqlDatabase::isDriverAvailable(const QString& name)-
1316{-
1317 return drivers().contains(name);
never executed: return drivers().contains(name);
0
1318}-
1319-
1320/*! \fn QSqlDatabase QSqlDatabase::addDatabase(QSqlDriver* driver, const QString& connectionName)-
1321-
1322 This overload is useful when you want to create a database-
1323 connection with a \l{QSqlDriver} {driver} you instantiated-
1324 yourself. It might be your own database driver, or you might just-
1325 need to instantiate one of the Qt drivers yourself. If you do-
1326 this, it is recommended that you include the driver code in your-
1327 application. For example, you can create a PostgreSQL connection-
1328 with your own QPSQL driver like this:-
1329-
1330 \snippet code/src_sql_kernel_qsqldatabase.cpp 5-
1331 \codeline-
1332 \snippet code/src_sql_kernel_qsqldatabase.cpp 6-
1333-
1334 The above code sets up a PostgreSQL connection and instantiates a-
1335 QPSQLDriver object. Next, addDatabase() is called to add the-
1336 connection to the known connections so that it can be used by the-
1337 Qt SQL classes. When a driver is instantiated with a connection-
1338 handle (or set of handles), Qt assumes that you have already-
1339 opened the database connection.-
1340-
1341 \note We assume that \c qtdir is the directory where Qt is-
1342 installed. This will pull in the code that is needed to use the-
1343 PostgreSQL client library and to instantiate a QPSQLDriver object,-
1344 assuming that you have the PostgreSQL headers somewhere in your-
1345 include search path.-
1346-
1347 Remember that you must link your application against the database-
1348 client library. Make sure the client library is in your linker's-
1349 search path, and add lines like these to your \c{.pro} file:-
1350-
1351 \snippet code/src_sql_kernel_qsqldatabase.cpp 7-
1352-
1353 The method described works for all the supplied drivers. The only-
1354 difference will be in the driver constructor arguments. Here is a-
1355 table of the drivers included with Qt, their source code files,-
1356 and their constructor arguments:-
1357-
1358 \table-
1359 \header \li Driver \li Class name \li Constructor arguments \li File to include-
1360 \row-
1361 \li QPSQL-
1362 \li QPSQLDriver-
1363 \li PGconn *connection-
1364 \li \c qsql_psql.cpp-
1365 \row-
1366 \li QMYSQL-
1367 \li QMYSQLDriver-
1368 \li MYSQL *connection-
1369 \li \c qsql_mysql.cpp-
1370 \row-
1371 \li QOCI-
1372 \li QOCIDriver-
1373 \li OCIEnv *environment, OCISvcCtx *serviceContext-
1374 \li \c qsql_oci.cpp-
1375 \row-
1376 \li QODBC-
1377 \li QODBCDriver-
1378 \li SQLHANDLE environment, SQLHANDLE connection-
1379 \li \c qsql_odbc.cpp-
1380 \row-
1381 \li QDB2-
1382 \li QDB2-
1383 \li SQLHANDLE environment, SQLHANDLE connection-
1384 \li \c qsql_db2.cpp-
1385 \row-
1386 \li QTDS-
1387 \li QTDSDriver-
1388 \li LOGINREC *loginRecord, DBPROCESS *dbProcess, const QString &hostName-
1389 \li \c qsql_tds.cpp-
1390 \row-
1391 \li QSQLITE-
1392 \li QSQLiteDriver-
1393 \li sqlite *connection-
1394 \li \c qsql_sqlite.cpp-
1395 \row-
1396 \li QIBASE-
1397 \li QIBaseDriver-
1398 \li isc_db_handle connection-
1399 \li \c qsql_ibase.cpp-
1400 \endtable-
1401-
1402 The host name (or service name) is needed when constructing the-
1403 QTDSDriver for creating new connections for internal queries. This-
1404 is to prevent blocking when several QSqlQuery objects are used-
1405 simultaneously.-
1406-
1407 \warning Adding a database connection with the same connection-
1408 name as an existing connection, causes the existing connection to-
1409 be replaced by the new one.-
1410-
1411 \warning The SQL framework takes ownership of the \a driver. It-
1412 must not be deleted. To remove the connection, use-
1413 removeDatabase().-
1414-
1415 \sa drivers()-
1416*/-
1417QSqlDatabase QSqlDatabase::addDatabase(QSqlDriver* driver, const QString& connectionName)-
1418{-
1419 QSqlDatabase db(driver);-
1420 QSqlDatabasePrivate::addDatabase(db, connectionName);-
1421 return db;
never executed: return db;
0
1422}-
1423-
1424/*!-
1425 Returns \c true if the QSqlDatabase has a valid driver.-
1426-
1427 Example:-
1428 \snippet code/src_sql_kernel_qsqldatabase.cpp 8-
1429*/-
1430bool QSqlDatabase::isValid() const-
1431{-
1432 return d->driver && d->driver != d->shared_null()->driver;
executed 6793 times by 9 tests: return d->driver && d->driver != d->shared_null()->driver;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
d->driverDescription
TRUEevaluated 6793 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEnever evaluated
d->driver != d...null()->driverDescription
TRUEevaluated 5445 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 1348 times by 6 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
0-6793
1433}-
1434-
1435/*!-
1436 Clones the database connection \a other and stores it as \a-
1437 connectionName. All the settings from the original database, e.g.-
1438 databaseName(), hostName(), etc., are copied across. Does nothing-
1439 if \a other is an invalid database. Returns the newly created-
1440 database connection.-
1441-
1442 \note The new connection has not been opened. Before using the new-
1443 connection, you must call open().-
1444*/-
1445QSqlDatabase QSqlDatabase::cloneDatabase(const QSqlDatabase &other, const QString &connectionName)-
1446{-
1447 if (!other.isValid())
!other.isValid()Description
TRUEnever evaluated
FALSEevaluated 7 times by 3 tests
Evaluated by:
  • tst_QSqlDatabase
  • tst_QSqlTableModel
  • tst_QSqlThread
0-7
1448 return QSqlDatabase();
never executed: return QSqlDatabase();
0
1449-
1450 QSqlDatabase db(other.driverName());-
1451 db.d->copy(other.d);-
1452 QSqlDatabasePrivate::addDatabase(db, connectionName);-
1453 return db;
executed 7 times by 3 tests: return db;
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlTableModel
  • tst_QSqlThread
7
1454}-
1455-
1456/*!-
1457 \since 4.4-
1458-
1459 Returns the connection name, which may be empty. \note The-
1460 connection name is not the \l{databaseName()} {database name}.-
1461-
1462 \sa addDatabase()-
1463*/-
1464QString QSqlDatabase::connectionName() const-
1465{-
1466 return d->connName;
executed 4 times by 1 test: return d->connName;
Executed by:
  • tst_QSqlDatabase
4
1467}-
1468-
1469/*!-
1470 \since 4.6-
1471-
1472 Sets the default numerical precision policy used by queries created-
1473 on this database connection to \a precisionPolicy.-
1474-
1475 Note: Drivers that don't support fetching numerical values with low-
1476 precision will ignore the precision policy. You can use-
1477 QSqlDriver::hasFeature() to find out whether a driver supports this-
1478 feature.-
1479-
1480 Note: Setting the default precision policy to \a precisionPolicy-
1481 doesn't affect any currently active queries.-
1482-
1483 \sa QSql::NumericalPrecisionPolicy, numericalPrecisionPolicy(),-
1484 QSqlQuery::setNumericalPrecisionPolicy(), QSqlQuery::numericalPrecisionPolicy()-
1485*/-
1486void QSqlDatabase::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy)-
1487{-
1488 if(driver())
driver()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlDatabase
FALSEnever evaluated
0-2
1489 driver()->setNumericalPrecisionPolicy(precisionPolicy);
executed 2 times by 1 test: driver()->setNumericalPrecisionPolicy(precisionPolicy);
Executed by:
  • tst_QSqlDatabase
2
1490 d->precisionPolicy = precisionPolicy;-
1491}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QSqlDatabase
2
1492-
1493/*!-
1494 \since 4.6-
1495-
1496 Returns the current default precision policy for the database connection.-
1497-
1498 \sa QSql::NumericalPrecisionPolicy, setNumericalPrecisionPolicy(),-
1499 QSqlQuery::numericalPrecisionPolicy(), QSqlQuery::setNumericalPrecisionPolicy()-
1500*/-
1501QSql::NumericalPrecisionPolicy QSqlDatabase::numericalPrecisionPolicy() const-
1502{-
1503 if(driver())
driver()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlDatabase
FALSEnever evaluated
0-1
1504 return driver()->numericalPrecisionPolicy();
executed 1 time by 1 test: return driver()->numericalPrecisionPolicy();
Executed by:
  • tst_QSqlDatabase
1
1505 else-
1506 return d->precisionPolicy;
never executed: return d->precisionPolicy;
0
1507}-
1508-
1509-
1510#ifndef QT_NO_DEBUG_STREAM-
1511QDebug operator<<(QDebug dbg, const QSqlDatabase &d)-
1512{-
1513 QDebugStateSaver saver(dbg);-
1514 dbg.nospace();-
1515 dbg.noquote();-
1516 if (!d.isValid()) {
!d.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1517 dbg << "QSqlDatabase(invalid)";-
1518 return dbg;
never executed: return dbg;
0
1519 }-
1520-
1521 dbg << "QSqlDatabase(driver=\"" << d.driverName() << "\", database=\""-
1522 << d.databaseName() << "\", host=\"" << d.hostName() << "\", port=" << d.port()-
1523 << ", user=\"" << d.userName() << "\", open=" << d.isOpen() << ')';-
1524 return dbg;
never executed: return dbg;
0
1525}-
1526#endif-
1527-
1528QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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