author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qsqldatabase.h> |
|
45 |
#include <qsqlquery.h> |
|
46 |
#include <qsqldriver.h> |
|
47 |
#ifdef QT3_SUPPORT |
|
48 |
#include <q3sqlcursor.h> |
|
49 |
#include <q3sqlrecordinfo.h> |
|
50 |
#include <q3cstring.h> |
|
51 |
#endif |
|
52 |
#include <qsqlrecord.h> |
|
53 |
#include <qsqlfield.h> |
|
54 |
#include <qsqlindex.h> |
|
55 |
#include <qregexp.h> |
|
56 |
#include <qvariant.h> |
|
57 |
#include <qdatetime.h> |
|
58 |
#include <qdebug.h> |
|
59 |
||
60 |
#define NODATABASE_SKIP "No database drivers are available in this Qt configuration" |
|
61 |
||
62 |
#include "tst_databases.h" |
|
63 |
||
64 |
//TESTED_FILES= |
|
65 |
||
66 |
QT_FORWARD_DECLARE_CLASS(QSqlDatabase) |
|
67 |
struct FieldDef; |
|
68 |
||
69 |
class tst_QSqlDatabase : public QObject |
|
70 |
{ |
|
71 |
Q_OBJECT |
|
72 |
||
73 |
public: |
|
74 |
tst_QSqlDatabase(); |
|
75 |
virtual ~tst_QSqlDatabase(); |
|
76 |
||
77 |
public slots: |
|
78 |
void initTestCase(); |
|
79 |
void cleanupTestCase(); |
|
80 |
void init(); |
|
81 |
void cleanup(); |
|
82 |
private slots: |
|
83 |
void record_data() { generic_data(); } |
|
84 |
//void record(); |
|
85 |
void open_data() { generic_data(); } |
|
86 |
void open(); |
|
87 |
void tables_data() { generic_data(); } |
|
88 |
void tables(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
void oci_tables_data() { generic_data("QOCI"); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
void oci_tables(); |
0 | 91 |
void transaction_data() { generic_data(); } |
92 |
void transaction(); |
|
93 |
void eventNotification_data() { generic_data(); } |
|
94 |
void eventNotification(); |
|
95 |
void addDatabase(); |
|
96 |
||
97 |
//database specific tests |
|
98 |
void recordMySQL_data() { generic_data("QMYSQL"); } |
|
99 |
void recordMySQL(); |
|
100 |
void recordPSQL_data() { generic_data("QPSQL"); } |
|
101 |
void recordPSQL(); |
|
102 |
void recordOCI_data() { generic_data("QOCI"); } |
|
103 |
void recordOCI(); |
|
104 |
void recordTDS_data() { generic_data("QTDS"); } |
|
105 |
void recordTDS(); |
|
106 |
void recordDB2_data() { generic_data("QDB2"); } |
|
107 |
void recordDB2(); |
|
108 |
void recordSQLite_data() { generic_data("QSQLITE"); } |
|
109 |
void recordSQLite(); |
|
110 |
void recordAccess_data() { generic_data("QODBC"); } |
|
111 |
void recordAccess(); |
|
112 |
void recordSQLServer_data() { generic_data("QODBC"); } |
|
113 |
void recordSQLServer(); |
|
114 |
void recordIBase_data() {generic_data("QIBASE"); } |
|
115 |
void recordIBase(); |
|
116 |
||
117 |
void eventNotificationIBase_data() { generic_data("QIBASE"); } |
|
118 |
void eventNotificationIBase(); |
|
119 |
void eventNotificationPSQL_data() { generic_data("QPSQL"); } |
|
120 |
void eventNotificationPSQL(); |
|
121 |
||
122 |
//database specific 64 bit integer test |
|
123 |
void bigIntField_data() { generic_data(); } |
|
124 |
void bigIntField(); |
|
125 |
||
126 |
// general tests |
|
127 |
void getConnectionName_data() { generic_data(); } |
|
128 |
void getConnectionName(); // For task 129992 |
|
129 |
||
130 |
//problem specific tests |
|
131 |
void alterTable_data() { generic_data(); } |
|
132 |
void alterTable(); |
|
133 |
void recordNonSelect_data() { generic_data(); } |
|
134 |
void recordNonSelect(); |
|
135 |
void caseSensivity_data() { generic_data(); } |
|
136 |
void caseSensivity(); |
|
137 |
void noEscapedFieldNamesInRecord_data() { generic_data(); } |
|
138 |
void noEscapedFieldNamesInRecord(); |
|
139 |
void whitespaceInIdentifiers_data() { generic_data(); } |
|
140 |
void whitespaceInIdentifiers(); |
|
141 |
void formatValueTrimStrings_data() { generic_data(); } |
|
142 |
void formatValueTrimStrings(); |
|
143 |
void precisionPolicy_data() { generic_data(); } |
|
144 |
void precisionPolicy(); |
|
145 |
||
146 |
void db2_valueCacheUpdate_data() { generic_data("QDB2"); } |
|
147 |
void db2_valueCacheUpdate(); |
|
148 |
||
149 |
void psql_schemas_data() { generic_data("QPSQL"); } |
|
150 |
void psql_schemas(); |
|
151 |
void psql_escapedIdentifiers_data() { generic_data("QPSQL"); } |
|
152 |
void psql_escapedIdentifiers(); |
|
153 |
void psql_escapeBytea_data() { generic_data("QPSQL"); } |
|
154 |
void psql_escapeBytea(); |
|
155 |
void bug_249059_data() { generic_data("QPSQL"); } |
|
156 |
void bug_249059(); |
|
157 |
||
158 |
void mysqlOdbc_unsignedIntegers_data() { generic_data(); } |
|
159 |
void mysqlOdbc_unsignedIntegers(); |
|
160 |
void mysql_multiselect_data() { generic_data("QMYSQL"); } |
|
161 |
void mysql_multiselect(); // For task 144331 |
|
162 |
void mysql_savepointtest_data() { generic_data("QMYSQL"); } |
|
163 |
void mysql_savepointtest(); |
|
164 |
||
165 |
void accessOdbc_strings_data() { generic_data(); } |
|
166 |
void accessOdbc_strings(); |
|
167 |
||
168 |
void ibase_numericFields_data() { generic_data("QIBASE"); } |
|
169 |
void ibase_numericFields(); // For task 125053 |
|
170 |
void ibase_fetchBlobs_data() { generic_data("QIBASE"); } |
|
171 |
void ibase_fetchBlobs(); // For task 143471 |
|
172 |
void ibase_useCustomCharset_data() { generic_data("QIBASE"); } |
|
173 |
void ibase_useCustomCharset(); // For task 134608 |
|
174 |
void ibase_procWithoutReturnValues_data() { generic_data("QIBASE"); } // For task 165423 |
|
175 |
void ibase_procWithoutReturnValues(); |
|
176 |
void ibase_procWithReturnValues_data() { generic_data("QIBASE"); } // For task 177530 |
|
177 |
void ibase_procWithReturnValues(); |
|
178 |
||
179 |
void odbc_reopenDatabase_data() { generic_data("QODBC"); } |
|
180 |
void odbc_reopenDatabase(); |
|
181 |
void odbc_uniqueidentifier_data() { generic_data("QODBC"); } |
|
182 |
void odbc_uniqueidentifier(); // For task 141822 |
|
183 |
void odbc_uintfield_data() { generic_data("QODBC"); } |
|
184 |
void odbc_uintfield(); |
|
185 |
void odbc_bindBoolean_data() { generic_data("QODBC"); } |
|
186 |
void odbc_bindBoolean(); |
|
187 |
void odbc_testqGetString_data() { generic_data("QODBC"); } |
|
188 |
void odbc_testqGetString(); |
|
189 |
||
190 |
void oci_serverDetach_data() { generic_data("QOCI"); } |
|
191 |
void oci_serverDetach(); // For task 154518 |
|
192 |
void oci_xmltypeSupport_data() { generic_data("QOCI"); } |
|
193 |
void oci_xmltypeSupport(); |
|
194 |
void oci_fieldLength_data() { generic_data("QOCI"); } |
|
195 |
void oci_fieldLength(); |
|
196 |
void oci_synonymstest_data() { generic_data("QOCI"); } |
|
197 |
void oci_synonymstest(); |
|
198 |
||
199 |
void sqlite_bindAndFetchUInt_data() { generic_data("QSQLITE"); } |
|
200 |
void sqlite_bindAndFetchUInt(); |
|
201 |
||
202 |
void sqlStatementUseIsNull_189093_data() { generic_data(); } |
|
203 |
void sqlStatementUseIsNull_189093(); |
|
204 |
||
205 |
||
206 |
private: |
|
207 |
void createTestTables(QSqlDatabase db); |
|
208 |
void dropTestTables(QSqlDatabase db); |
|
209 |
void populateTestTables(QSqlDatabase db); |
|
210 |
void generic_data(const QString &engine=QString()); |
|
211 |
||
212 |
#ifdef QT3_SUPPORT |
|
213 |
void testRecordInfo(const FieldDef fieldDefs[], const Q3SqlRecordInfo& inf); |
|
214 |
#endif |
|
215 |
void testRecord(const FieldDef fieldDefs[], const QSqlRecord& inf, QSqlDatabase db); |
|
216 |
void commonFieldTest(const FieldDef fieldDefs[], QSqlDatabase, const int); |
|
217 |
void checkValues(const FieldDef fieldDefs[], QSqlDatabase db); |
|
218 |
void checkNullValues(const FieldDef fieldDefs[], QSqlDatabase db); |
|
219 |
||
220 |
tst_Databases dbs; |
|
221 |
}; |
|
222 |
||
223 |
// number of records to be inserted per testfunction |
|
224 |
static const int ITERATION_COUNT = 2; |
|
225 |
static int pkey = 1; |
|
226 |
||
227 |
//helper class for database specific tests |
|
228 |
struct FieldDef { |
|
229 |
FieldDef(QString tn = QString(), |
|
230 |
QVariant::Type t = QVariant::Invalid, |
|
231 |
QVariant v = QVariant(), |
|
232 |
bool nl = true): |
|
233 |
typeName(tn), type(t), val(v), nullable(nl) {} |
|
234 |
||
235 |
QString fieldName() const |
|
236 |
{ |
|
237 |
QString rt = typeName; |
|
238 |
rt.replace(QRegExp("\\s"), QString("_")); |
|
239 |
#ifdef QT3_SUPPORT |
|
240 |
int i = rt.find("("); |
|
241 |
#else |
|
242 |
int i = rt.indexOf("("); |
|
243 |
#endif |
|
244 |
if (i == -1) |
|
245 |
i = rt.length(); |
|
246 |
if (i > 20) |
|
247 |
i = 20; |
|
248 |
return "t_" + rt.left(i); |
|
249 |
} |
|
250 |
QString typeName; |
|
251 |
QVariant::Type type; |
|
252 |
QVariant val; |
|
253 |
bool nullable; |
|
254 |
}; |
|
255 |
||
256 |
// creates a table out of the FieldDefs and returns the number of fields |
|
257 |
// excluding the primary key field |
|
258 |
static int createFieldTable(const FieldDef fieldDefs[], QSqlDatabase db) |
|
259 |
{ |
|
260 |
tst_Databases::safeDropTable(db, qTableName("qtestfields")); |
|
261 |
QSqlQuery q(db); |
|
262 |
// construct a create table statement consisting of all fieldtypes |
|
263 |
QString qs = "create table " + qTableName("qtestfields"); |
|
264 |
QString autoName = tst_Databases::autoFieldName(db); |
|
265 |
if (tst_Databases::isMSAccess(db)) |
|
266 |
qs.append(" (id int not null"); |
|
267 |
else if (tst_Databases::isPostgreSQL(db)) |
|
268 |
qs.append(" (id serial not null"); |
|
269 |
else |
|
270 |
qs.append(QString("(id integer not null %1 primary key").arg(autoName)); |
|
271 |
||
272 |
int i = 0; |
|
273 |
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) { |
|
274 |
qs += QString(",\n %1 %2").arg(fieldDefs[ i ].fieldName()).arg(fieldDefs[ i ].typeName); |
|
275 |
if ((db.driverName().startsWith("QTDS") || tst_Databases::isSqlServer(db)) && fieldDefs[ i ].nullable) { |
|
276 |
qs += " null"; |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
if (tst_Databases::isMSAccess(db)) |
|
281 |
qs.append(",\n primary key (id)"); |
|
282 |
||
283 |
qs += ')'; |
|
284 |
if (!q.exec(qs)) { |
|
285 |
qDebug() << "Creation of Table failed:" << tst_Databases::printError(q.lastError(), db); |
|
286 |
qDebug() << "Query: " << qs; |
|
287 |
return -1; |
|
288 |
} |
|
289 |
return i; |
|
290 |
} |
|
291 |
||
292 |
tst_QSqlDatabase::tst_QSqlDatabase() |
|
293 |
{ |
|
294 |
} |
|
295 |
||
296 |
tst_QSqlDatabase::~tst_QSqlDatabase() |
|
297 |
{ |
|
298 |
} |
|
299 |
||
300 |
void tst_QSqlDatabase::createTestTables(QSqlDatabase db) |
|
301 |
{ |
|
302 |
if (!db.isValid()) |
|
303 |
return; |
|
304 |
QSqlQuery q(db); |
|
305 |
if (db.driverName().startsWith("QMYSQL")) |
|
306 |
// ### stupid workaround until we find a way to hardcode this |
|
307 |
// in the MySQL server startup script |
|
308 |
q.exec("set table_type=innodb"); |
|
309 |
else if (tst_Databases::isSqlServer(db)) { |
|
310 |
QVERIFY_SQL(q, exec("SET ANSI_DEFAULTS ON")); |
|
311 |
QVERIFY_SQL(q, exec("SET IMPLICIT_TRANSACTIONS OFF")); |
|
312 |
} else if(tst_Databases::isPostgreSQL(db)) |
|
313 |
QVERIFY_SQL( q, exec("set client_min_messages='warning'")); |
|
314 |
||
315 |
// please never ever change this table; otherwise fix all tests ;) |
|
316 |
if (tst_Databases::isMSAccess(db)) { |
|
317 |
QVERIFY_SQL(q, exec("create table " + qTableName("qtest") + |
|
318 |
" (id int not null, t_varchar varchar(40) not null, t_char char(40), " |
|
319 |
"t_numeric number, primary key (id, t_varchar))")); |
|
320 |
} else { |
|
321 |
QVERIFY_SQL(q, exec("create table " + qTableName("qtest") + |
|
322 |
" (id integer not null, t_varchar varchar(40) not null, " |
|
323 |
"t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar))")); |
|
324 |
} |
|
325 |
||
326 |
if (testWhiteSpaceNames(db.driverName())) { |
|
327 |
QString qry = "create table " |
|
328 |
+ db.driver()->escapeIdentifier(qTableName("qtest") + " test", QSqlDriver::TableName) |
|
329 |
+ '(' |
|
330 |
+ db.driver()->escapeIdentifier(QLatin1String("test test"), QSqlDriver::FieldName) |
|
331 |
+ " int not null primary key)"; |
|
332 |
QVERIFY_SQL(q, exec(qry)); |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
void tst_QSqlDatabase::dropTestTables(QSqlDatabase db) |
|
337 |
{ |
|
338 |
if (!db.isValid()) |
|
339 |
return; |
|
340 |
||
341 |
if(tst_Databases::isPostgreSQL(db)) { |
|
342 |
QSqlQuery q(db); |
|
343 |
QVERIFY_SQL( q, exec("set client_min_messages='warning'")); |
|
344 |
} |
|
345 |
||
346 |
// drop the view first, otherwise we'll get dependency problems |
|
347 |
tst_Databases::safeDropViews(db, QStringList() << qTableName("qtest_view") << qTableName("qtest_view2")); |
|
348 |
||
349 |
QStringList tableNames; |
|
350 |
tableNames << qTableName("qtest") |
|
351 |
<< qTableName("qtestfields") |
|
352 |
<< qTableName("qtestalter") |
|
353 |
<< qTableName("qtest_temp") |
|
354 |
<< qTableName("qtest_bigint") |
|
355 |
<< qTableName("qtest_xmltype") |
|
356 |
<< qTableName("latin1table") |
|
357 |
<< qTableName("qtest_sqlguid") |
|
358 |
<< qTableName("batable") |
|
359 |
<< qTableName("qtest_prec") |
|
360 |
<< qTableName("uint") |
|
361 |
<< qTableName("strings") |
|
362 |
<< qTableName("numericfields") |
|
363 |
<< qTableName("qtest_ibaseblobs") |
|
364 |
<< qTableName("qtestBindBool") |
|
365 |
<< qTableName("testqGetString") |
|
366 |
<< qTableName("qtest_sqlguid") |
|
367 |
<< qTableName("uint_table") |
|
368 |
<< qTableName("uint_test") |
|
369 |
<< qTableName("bug_249059"); |
|
370 |
||
371 |
QSqlQuery q(0, db); |
|
372 |
if (db.driverName().startsWith("QPSQL")) { |
|
373 |
q.exec("drop schema " + qTableName("qtestschema") + " cascade"); |
|
374 |
q.exec("drop schema " + qTableName("qtestScHeMa") + " cascade"); |
|
375 |
} |
|
376 |
||
377 |
if (testWhiteSpaceNames(db.driverName())) |
|
378 |
tableNames << db.driver()->escapeIdentifier(qTableName("qtest") + " test", QSqlDriver::TableName); |
|
379 |
||
380 |
tst_Databases::safeDropTables(db, tableNames); |
|
381 |
||
382 |
if (db.driverName().startsWith("QOCI")) { |
|
383 |
q.exec("drop user "+qTableName("CREATOR")+" cascade"); |
|
384 |
q.exec("drop user "+qTableName("APPUSER")+" cascade"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
q.exec("DROP TABLE system."+qTableName("mypassword")); |
0 | 386 |
|
387 |
} |
|
388 |
} |
|
389 |
||
390 |
void tst_QSqlDatabase::populateTestTables(QSqlDatabase db) |
|
391 |
{ |
|
392 |
if (!db.isValid()) |
|
393 |
return; |
|
394 |
QSqlQuery q(db); |
|
395 |
||
396 |
q.exec("delete from " + qTableName("qtest")); //non-fatal |
|
397 |
QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (0, 'VarChar0', 'Char0', 1.1)")); |
|
398 |
QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (1, 'VarChar1', 'Char1', 2.2)")); |
|
399 |
QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (2, 'VarChar2', 'Char2', 3.3)")); |
|
400 |
QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (3, 'VarChar3', 'Char3', 4.4)")); |
|
401 |
QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (4, 'VarChar4', NULL, NULL)")); |
|
402 |
} |
|
403 |
||
404 |
void tst_QSqlDatabase::initTestCase() |
|
405 |
{ |
|
406 |
dbs.open(); |
|
407 |
||
408 |
for (QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it) { |
|
409 |
QSqlDatabase db = QSqlDatabase::database((*it)); |
|
410 |
CHECK_DATABASE(db); |
|
411 |
dropTestTables(db); //in case of leftovers |
|
412 |
createTestTables(db); |
|
413 |
populateTestTables(db); |
|
414 |
} |
|
415 |
} |
|
416 |
||
417 |
void tst_QSqlDatabase::cleanupTestCase() |
|
418 |
{ |
|
419 |
for (QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it) { |
|
420 |
QSqlDatabase db = QSqlDatabase::database((*it)); |
|
421 |
CHECK_DATABASE(db); |
|
422 |
dropTestTables(db); |
|
423 |
} |
|
424 |
||
425 |
dbs.close(); |
|
426 |
} |
|
427 |
||
428 |
void tst_QSqlDatabase::init() |
|
429 |
{ |
|
430 |
} |
|
431 |
||
432 |
void tst_QSqlDatabase::cleanup() |
|
433 |
{ |
|
434 |
} |
|
435 |
||
436 |
void tst_QSqlDatabase::generic_data(const QString& engine) |
|
437 |
{ |
|
438 |
if ( dbs.fillTestTable(engine) == 0 ) { |
|
439 |
if(engine.isEmpty()) |
|
440 |
QSKIP( "No database drivers are available in this Qt configuration", SkipAll ); |
|
441 |
else |
|
442 |
QSKIP( (QString("No database drivers of type %1 are available in this Qt configuration").arg(engine)).toLocal8Bit(), SkipAll ); |
|
443 |
} |
|
444 |
} |
|
445 |
||
446 |
void tst_QSqlDatabase::addDatabase() |
|
447 |
{ |
|
448 |
QTest::ignoreMessage(QtWarningMsg, "QSqlDatabase: BLAH_FOO_NONEXISTENT_DRIVER driver not loaded"); |
|
449 |
QTest::ignoreMessage(QtWarningMsg, qPrintable("QSqlDatabase: available drivers: " + QSqlDatabase::drivers().join(QLatin1String(" ")))); |
|
450 |
{ |
|
451 |
QSqlDatabase db = QSqlDatabase::addDatabase("BLAH_FOO_NONEXISTENT_DRIVER", |
|
452 |
"INVALID_CONNECTION"); |
|
453 |
QVERIFY(!db.isValid()); |
|
454 |
} |
|
455 |
QVERIFY(QSqlDatabase::contains("INVALID_CONNECTION")); |
|
456 |
QSqlDatabase::removeDatabase("INVALID_CONNECTION"); |
|
457 |
QVERIFY(!QSqlDatabase::contains("INVALID_CONNECTION")); |
|
458 |
} |
|
459 |
||
460 |
void tst_QSqlDatabase::open() |
|
461 |
{ |
|
462 |
QFETCH(QString, dbName); |
|
463 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
464 |
CHECK_DATABASE(db); |
|
465 |
||
466 |
int i; |
|
467 |
for (i = 0; i < 10; ++i) { |
|
468 |
db.close(); |
|
469 |
QVERIFY(!db.isOpen()); |
|
470 |
QVERIFY_SQL(db, open()); |
|
471 |
QVERIFY(db.isOpen()); |
|
472 |
QVERIFY(!db.isOpenError()); |
|
473 |
} |
|
474 |
||
475 |
if (db.driverName().startsWith("QSQLITE") && db.databaseName() == ":memory:") { |
|
476 |
// tables in in-memory databases don't survive an open/close |
|
477 |
createTestTables(db); |
|
478 |
populateTestTables(db); |
|
479 |
} |
|
480 |
} |
|
481 |
||
482 |
void tst_QSqlDatabase::recordNonSelect() |
|
483 |
{ |
|
484 |
#ifdef QT3_SUPPORT |
|
485 |
QFETCH(QString, dbName); |
|
486 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
487 |
CHECK_DATABASE(db); |
|
488 |
||
489 |
QSqlQuery q(db); |
|
490 |
||
491 |
// nothing should happen on an empty query |
|
492 |
QSqlRecord rec = db.record(q); |
|
493 |
QVERIFY(rec.isEmpty()); |
|
494 |
Q3SqlRecordInfo rInf = db.recordInfo(q); |
|
495 |
QVERIFY(rInf.isEmpty()); |
|
496 |
||
497 |
QVERIFY_SQL(q, exec("create table " + qTableName("qtest_temp") + " (id int)")); |
|
498 |
||
499 |
// query without result set should return empty record |
|
500 |
rec = db.record(q); |
|
501 |
QVERIFY(rec.isEmpty()); |
|
502 |
rInf = db.recordInfo(q); |
|
503 |
QVERIFY(rInf.isEmpty()); |
|
504 |
#endif |
|
505 |
} |
|
506 |
||
507 |
void tst_QSqlDatabase::tables() |
|
508 |
{ |
|
509 |
QFETCH(QString, dbName); |
|
510 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
511 |
CHECK_DATABASE(db); |
|
512 |
||
513 |
bool views = true; |
|
514 |
bool tempTables = false; |
|
515 |
||
516 |
QSqlQuery q(db); |
|
517 |
if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) |
|
518 |
QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); |
|
519 |
||
520 |
||
521 |
if (!q.exec("CREATE VIEW " + qTableName("qtest_view") + " as select * from " + qTableName("qtest"))) { |
|
522 |
qDebug(QString("DBMS '%1' cannot handle VIEWs: %2").arg( |
|
523 |
tst_Databases::dbToString(db)).arg(QString(tst_Databases::printError(q.lastError()))).toLatin1()); |
|
524 |
views = false; |
|
525 |
} |
|
526 |
||
527 |
if (db.driverName().startsWith("QSQLITE3")) { |
|
528 |
QVERIFY_SQL(q, exec("CREATE TEMPORARY TABLE " + qTableName("temp_tab") + " (id int)")); |
|
529 |
tempTables = true; |
|
530 |
} |
|
531 |
||
532 |
QStringList tables = db.tables(QSql::Tables); |
|
533 |
QVERIFY(tables.contains(qTableName("qtest"), Qt::CaseInsensitive)); |
|
534 |
QVERIFY(!tables.contains("sql_features", Qt::CaseInsensitive)); //check for postgres 7.4 internal tables |
|
535 |
if (views) { |
|
536 |
QVERIFY(!tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)); |
|
537 |
} |
|
538 |
if (tempTables) |
|
539 |
QVERIFY(tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive)); |
|
540 |
||
541 |
tables = db.tables(QSql::Views); |
|
542 |
if (views) { |
|
543 |
if(!tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)) |
|
544 |
qDebug() << "failed to find" << qTableName("qtest_view") << "in" << tables; |
|
545 |
QVERIFY(tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)); |
|
546 |
} |
|
547 |
if (tempTables) |
|
548 |
QVERIFY(!tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive)); |
|
549 |
QVERIFY(!tables.contains(qTableName("qtest"), Qt::CaseInsensitive)); |
|
550 |
||
551 |
tables = db.tables(QSql::SystemTables); |
|
552 |
QVERIFY(!tables.contains(qTableName("qtest"), Qt::CaseInsensitive)); |
|
553 |
QVERIFY(!tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)); |
|
554 |
QVERIFY(!tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive)); |
|
555 |
||
556 |
tables = db.tables(QSql::AllTables); |
|
557 |
if (views) |
|
558 |
QVERIFY(tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)); |
|
559 |
if (tempTables) |
|
560 |
QVERIFY(tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive)); |
|
561 |
QVERIFY(tables.contains(qTableName("qtest"), Qt::CaseInsensitive)); |
|
562 |
||
563 |
if (db.driverName().startsWith("QPSQL")) { |
|
564 |
QVERIFY(tables.contains(qTableName("qtest") + " test")); |
|
565 |
} |
|
566 |
} |
|
567 |
||
568 |
void tst_QSqlDatabase::whitespaceInIdentifiers() |
|
569 |
{ |
|
570 |
QFETCH(QString, dbName); |
|
571 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
572 |
CHECK_DATABASE(db); |
|
573 |
||
574 |
if (testWhiteSpaceNames(db.driverName())) { |
|
575 |
QString tableName = qTableName("qtest") + " test"; |
|
576 |
QVERIFY(db.tables().contains(tableName, Qt::CaseInsensitive)); |
|
577 |
||
578 |
QSqlRecord rec = db.record(db.driver()->escapeIdentifier(tableName, QSqlDriver::TableName)); |
|
579 |
QCOMPARE(rec.count(), 1); |
|
580 |
QCOMPARE(rec.fieldName(0), QString("test test")); |
|
581 |
if(db.driverName().startsWith("QOCI")) |
|
582 |
QCOMPARE(rec.field(0).type(), QVariant::Double); |
|
583 |
else |
|
584 |
QCOMPARE(rec.field(0).type(), QVariant::Int); |
|
585 |
||
586 |
QSqlIndex idx = db.primaryIndex(db.driver()->escapeIdentifier(tableName, QSqlDriver::TableName)); |
|
587 |
QCOMPARE(idx.count(), 1); |
|
588 |
QCOMPARE(idx.fieldName(0), QString("test test")); |
|
589 |
if(db.driverName().startsWith("QOCI")) |
|
590 |
QCOMPARE(idx.field(0).type(), QVariant::Double); |
|
591 |
else |
|
592 |
QCOMPARE(idx.field(0).type(), QVariant::Int); |
|
593 |
} else { |
|
594 |
QSKIP("DBMS does not support whitespaces in identifiers", SkipSingle); |
|
595 |
} |
|
596 |
} |
|
597 |
||
598 |
void tst_QSqlDatabase::alterTable() |
|
599 |
{ |
|
600 |
QFETCH(QString, dbName); |
|
601 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
602 |
CHECK_DATABASE(db); |
|
603 |
||
604 |
QSqlQuery q(db); |
|
605 |
||
606 |
QVERIFY_SQL(q, exec("create table " + qTableName("qtestalter") + " (F1 char(20), F2 char(20), F3 char(20))")); |
|
607 |
QSqlRecord rec = db.record(qTableName("qtestalter")); |
|
608 |
QCOMPARE((int)rec.count(), 3); |
|
609 |
#ifdef QT3_SUPPORT |
|
610 |
Q3SqlRecordInfo rinf = db.recordInfo(qTableName("qtestalter")); |
|
611 |
QCOMPARE((int)rinf.count(), 3); |
|
612 |
#endif |
|
613 |
||
614 |
||
615 |
int i; |
|
616 |
for (i = 0; i < 3; ++i) { |
|
617 |
QCOMPARE(rec.field(i).name().toUpper(), QString("F%1").arg(i + 1)); |
|
618 |
#ifdef QT3_SUPPORT |
|
619 |
QCOMPARE(rinf[ i ].name().upper(), QString("F%1").arg(i + 1)); |
|
620 |
#endif |
|
621 |
} |
|
622 |
||
623 |
if (!q.exec("alter table " + qTableName("qtestalter") + " drop column F2")) { |
|
624 |
QSKIP("DBMS doesn't support dropping columns in ALTER TABLE statement", SkipSingle); |
|
625 |
} |
|
626 |
||
627 |
rec = db.record(qTableName("qtestalter")); |
|
628 |
#ifdef QT3_SUPPORT |
|
629 |
rinf = db.recordInfo(qTableName("qtestalter")); |
|
630 |
#endif |
|
631 |
||
632 |
QCOMPARE((int)rec.count(), 2); |
|
633 |
#ifdef QT3_SUPPORT |
|
634 |
QCOMPARE((int)rinf.count(), 2); |
|
635 |
#endif |
|
636 |
||
637 |
QCOMPARE(rec.field(0).name().toUpper(), QString("F1")); |
|
638 |
QCOMPARE(rec.field(1).name().toUpper(), QString("F3")); |
|
639 |
#ifdef QT3_SUPPORT |
|
640 |
QCOMPARE(rinf[ 0 ].name().upper(), QString("F1")); |
|
641 |
QCOMPARE(rinf[ 1 ].name().upper(), QString("F3")); |
|
642 |
#endif |
|
643 |
||
644 |
q.exec("select * from " + qTableName("qtestalter")); |
|
645 |
||
646 |
#ifdef QT3_SUPPORT |
|
647 |
rec = db.record(q); |
|
648 |
rinf = db.recordInfo(q); |
|
649 |
||
650 |
QCOMPARE((int)rec.count(), 2); |
|
651 |
QCOMPARE((int)rinf.count(), 2); |
|
652 |
||
653 |
QCOMPARE(rec.field(0).name().upper(), QString("F1")); |
|
654 |
QCOMPARE(rec.field(1).name().upper(), QString("F3")); |
|
655 |
QCOMPARE(rinf[ 0 ].name().upper(), QString("F1")); |
|
656 |
QCOMPARE(rinf[ 1 ].name().upper(), QString("F3")); |
|
657 |
#endif |
|
658 |
} |
|
659 |
||
660 |
#if 0 |
|
661 |
// this is the general test that should work on all databases. |
|
662 |
// unfortunately no DBMS supports SQL 92/ 99 so the general |
|
663 |
// test is more or less a joke. Please write a test for each |
|
664 |
// database plugin (see recordOCI and so on). Use this test |
|
665 |
// as a template. |
|
666 |
void tst_QSqlDatabase::record() |
|
667 |
{ |
|
668 |
QFETCH(QString, dbName); |
|
669 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
670 |
CHECK_DATABASE(db); |
|
671 |
||
672 |
static const FieldDef fieldDefs[] = { |
|
673 |
FieldDef("char(20)", QVariant::String, QString("blah1"), false), |
|
674 |
FieldDef("varchar(20)", QVariant::String, QString("blah2"), false), |
|
675 |
FieldDef() |
|
676 |
}; |
|
677 |
||
678 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
679 |
QVERIFY(fieldCount > 0); |
|
680 |
||
681 |
// doesn't work with oracle: checkNullValues(fieldDefs, db); |
|
682 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
683 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
684 |
checkValues(fieldDefs, db); |
|
685 |
} |
|
686 |
} |
|
687 |
#endif |
|
688 |
||
689 |
#ifdef QT3_SUPPORT |
|
690 |
void tst_QSqlDatabase::testRecordInfo(const FieldDef fieldDefs[], const Q3SqlRecordInfo& inf) |
|
691 |
{ |
|
692 |
int i = 0; |
|
693 |
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) { |
|
694 |
QCOMPARE(inf[i+1].name().upper(), fieldDefs[ i ].fieldName().upper()); |
|
695 |
if (inf[i+1].type() != fieldDefs[ i ].type) { |
|
696 |
QFAIL(QString(" Expected: '%1' Received: '%2' for field %3 in testRecordInfo").arg( |
|
697 |
QVariant::typeToName(fieldDefs[ i ].type)).arg( |
|
698 |
QVariant::typeToName(inf[i+1].type())).arg( |
|
699 |
fieldDefs[ i ].fieldName())); |
|
700 |
} |
|
701 |
} |
|
702 |
} |
|
703 |
#endif |
|
704 |
||
705 |
void tst_QSqlDatabase::testRecord(const FieldDef fieldDefs[], const QSqlRecord& inf, QSqlDatabase db) |
|
706 |
{ |
|
707 |
int i = 0; |
|
708 |
if (!tst_Databases::autoFieldName(db).isEmpty()) // Currently only MySQL is tested |
|
709 |
QVERIFY2(inf.field(i).isAutoValue(), qPrintable(inf.field(i).name() + " should be reporting as an autovalue")); |
|
710 |
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) { |
|
711 |
QCOMPARE(inf.field(i+1).name().toUpper(), fieldDefs[ i ].fieldName().toUpper()); |
|
712 |
if (inf.field(i+1).type() != fieldDefs[ i ].type) { |
|
713 |
QFAIL(qPrintable(QString(" Expected: '%1' Received: '%2' for field %3 in testRecord").arg( |
|
714 |
QVariant::typeToName(fieldDefs[ i ].type)).arg( |
|
715 |
QVariant::typeToName(inf.field(i+1).type())).arg( |
|
716 |
fieldDefs[ i ].fieldName()))); |
|
717 |
} |
|
718 |
QVERIFY(!inf.field(i+1).isAutoValue()); |
|
719 |
||
720 |
// qDebug(QString(" field: %1 type: %2 variant type: %3").arg(fieldDefs[ i ].fieldName()).arg(QVariant::typeToName(inf.field(i+1)->type())).arg(QVariant::typeToName(inf.field(i+1)->value().type()))); |
|
721 |
} |
|
722 |
} |
|
723 |
||
724 |
// non-dbms specific tests |
|
725 |
void tst_QSqlDatabase::commonFieldTest(const FieldDef fieldDefs[], QSqlDatabase db, const int fieldCount) |
|
726 |
{ |
|
727 |
CHECK_DATABASE(db); |
|
728 |
||
729 |
// check whether recordInfo returns the right types |
|
730 |
#ifdef QT3_SUPPORT |
|
731 |
Q3SqlRecordInfo inf = db.recordInfo(qTableName("qtestfields")); |
|
732 |
QCOMPARE((int)inf.count(), fieldCount+1); |
|
733 |
testRecordInfo(fieldDefs, inf); |
|
734 |
#endif |
|
735 |
||
736 |
QSqlRecord rec = db.record(qTableName("qtestfields")); |
|
737 |
QCOMPARE((int)rec.count(), fieldCount+1); |
|
738 |
testRecord(fieldDefs, rec, db); |
|
739 |
||
740 |
QSqlQuery q(db); |
|
741 |
QVERIFY_SQL(q, exec("select * from " + qTableName("qtestfields"))); |
|
742 |
||
743 |
#ifdef QT3_SUPPORT |
|
744 |
inf = db.recordInfo(q); |
|
745 |
QCOMPARE((int)inf.count(), fieldCount+1); |
|
746 |
testRecordInfo(fieldDefs, inf); |
|
747 |
||
748 |
rec = db.record(q); |
|
749 |
QCOMPARE((int)rec.count(), fieldCount+1); |
|
750 |
testRecord(fieldDefs, rec, db); |
|
751 |
#endif |
|
752 |
} |
|
753 |
||
754 |
// inserts testdata into the testtable, fetches and compares them |
|
755 |
void tst_QSqlDatabase::checkValues(const FieldDef fieldDefs[], QSqlDatabase db) |
|
756 |
{ |
|
757 |
Q_UNUSED(fieldDefs); |
|
758 |
#ifdef QT3_SUPPORT |
|
759 |
CHECK_DATABASE(db); |
|
760 |
||
761 |
Q3SqlCursor cur(qTableName("qtestfields"), true, db); |
|
762 |
QVERIFY_SQL(cur, select()); |
|
763 |
QSqlRecord* rec = cur.primeInsert(); |
|
764 |
Q_ASSERT(rec); |
|
765 |
rec->setValue("id", pkey++); |
|
766 |
int i = 0; |
|
767 |
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) { |
|
768 |
rec->setValue(fieldDefs[ i ].fieldName(), fieldDefs[ i ].val); |
|
769 |
// qDebug(QString("inserting %1 into %2").arg(fieldDefs[ i ].val.toString()).arg(fieldDefs[ i ].fieldName())); |
|
770 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
QVERIFY_SQL(cur, insert()); |
0 | 772 |
cur.setForwardOnly(true); |
773 |
QVERIFY_SQL(cur, select("id = " + QString::number(pkey - 1))); |
|
774 |
QVERIFY_SQL(cur, next()); |
|
775 |
||
776 |
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) { |
|
777 |
bool ok = false; |
|
778 |
QVariant val1 = cur.value(fieldDefs[ i ].fieldName()); |
|
779 |
QVariant val2 = fieldDefs[ i ].val; |
|
780 |
if (val1.type() == QVariant::String) |
|
781 |
//TDS Workaround |
|
782 |
val1 = val1.toString().stripWhiteSpace(); |
|
783 |
if (fieldDefs[ i ].fieldName() == "t_real") { |
|
784 |
// strip precision |
|
785 |
val1 = (float)val1.toDouble(); |
|
786 |
val2 = (float)val2.toDouble(); |
|
787 |
} |
|
788 |
if (val1.canCast(QVariant::Double) && val2.type() == QVariant::Double) { |
|
789 |
// we don't care about precision here, we just want to know whether |
|
790 |
// we can insert/fetch the right values |
|
791 |
ok = (val1.toDouble() - val2.toDouble() < 0.00001); |
|
792 |
} else if (val1.type() == val2.type()) { |
|
793 |
ok = (val1 == val2); |
|
794 |
} else { |
|
795 |
ok = (val1.toString() == val2.toString()); |
|
796 |
} |
|
797 |
if (!ok) { |
|
798 |
if (val2.type() == QVariant::DateTime || val2.type() == QVariant::Time) |
|
799 |
qDebug("Expected Time: " + val2.toTime().toString("hh:mm:ss.zzz")); |
|
800 |
if (val1.type() == QVariant::DateTime || val1.type() == QVariant::Time) |
|
801 |
qDebug("Received Time: " + val1.toTime().toString("hh:mm:ss.zzz")); |
|
802 |
QFAIL(QString(" Expected: '%1' Received: '%2' for field %3 (etype %4 rtype %5) in checkValues").arg( |
|
803 |
val2.type() == QVariant::ByteArray ? val2.toByteArray().toHex() : val2.toString()).arg( |
|
804 |
val1.type() == QVariant::ByteArray ? val1.toByteArray().toHex() : val1.toString()).arg( |
|
805 |
fieldDefs[ i ].fieldName()).arg( |
|
806 |
val2.typeName()).arg( |
|
807 |
val1.typeName()) |
|
808 |
); |
|
809 |
} |
|
810 |
} |
|
811 |
#endif |
|
812 |
} |
|
813 |
||
814 |
// inserts a NULL value for each nullable field in testdata, fetches and checks whether |
|
815 |
// we get back NULL |
|
816 |
void tst_QSqlDatabase::checkNullValues(const FieldDef fieldDefs[], QSqlDatabase db) |
|
817 |
{ |
|
818 |
Q_UNUSED(fieldDefs); |
|
819 |
#ifdef QT3_SUPPORT |
|
820 |
CHECK_DATABASE(db); |
|
821 |
||
822 |
Q3SqlCursor cur(qTableName("qtestfields"), true, db); |
|
823 |
QVERIFY_SQL(cur, select()); |
|
824 |
QSqlRecord* rec = cur.primeInsert(); |
|
825 |
Q_ASSERT(rec); |
|
826 |
rec->setValue("id", pkey++); |
|
827 |
int i = 0; |
|
828 |
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) { |
|
829 |
if (fieldDefs[ i ].fieldName(), fieldDefs[ i ].nullable) |
|
830 |
rec->setNull(fieldDefs[ i ].fieldName()); |
|
831 |
else |
|
832 |
rec->setValue(fieldDefs[ i ].fieldName(), fieldDefs[ i ].val); |
|
833 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
834 |
QVERIFY_SQL(cur, insert()); |
0 | 835 |
cur.setForwardOnly(true); |
836 |
QVERIFY_SQL(cur, select("id = " + QString::number(pkey - 1))); |
|
837 |
QVERIFY_SQL(cur, next()); |
|
838 |
||
839 |
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) { |
|
840 |
if (fieldDefs[ i ].nullable == false) |
|
841 |
continue; |
|
842 |
// multiple inheritance sucks so much |
|
843 |
QVERIFY2(((QSqlQuery)cur).isNull(i + 1), "Check whether '" + fieldDefs[ i ].fieldName() + "' is null in QSqlQuery"); |
|
844 |
QVERIFY2(((QSqlRecord)cur).isNull(fieldDefs[ i ].fieldName()), "Check whether '" + fieldDefs[ i ].fieldName() + "' is null in QSqlRecord"); |
|
845 |
if (!cur.value(fieldDefs[ i ].fieldName()).isNull()) |
|
846 |
qDebug(QString("QVariant is not null for NULL-Value in Field '%1'").arg(fieldDefs[ i ].fieldName())); |
|
847 |
} |
|
848 |
#endif |
|
849 |
} |
|
850 |
||
851 |
void tst_QSqlDatabase::recordTDS() |
|
852 |
{ |
|
853 |
QFETCH(QString, dbName); |
|
854 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
855 |
CHECK_DATABASE(db); |
|
856 |
||
857 |
static const FieldDef fieldDefs[] = { |
|
858 |
FieldDef("tinyint", QVariant::Int, 255), |
|
859 |
FieldDef("smallint", QVariant::Int, 32767), |
|
860 |
FieldDef("int", QVariant::Int, 2147483647), |
|
861 |
FieldDef("numeric(10,9)", QVariant::Double, 1.23456789), |
|
862 |
FieldDef("decimal(10,9)", QVariant::Double, 1.23456789), |
|
863 |
FieldDef("float(4)", QVariant::Double, 1.23456789), |
|
864 |
FieldDef("double precision", QVariant::Double, 1.23456789), |
|
865 |
FieldDef("real", QVariant::Double, 1.23456789), |
|
866 |
FieldDef("smallmoney", QVariant::Double, 100.42), |
|
867 |
FieldDef("money", QVariant::Double, 200.42), |
|
868 |
// accuracy is that of a minute |
|
869 |
FieldDef("smalldatetime", QVariant::DateTime, QDateTime(QDate::currentDate(), QTime(1, 2, 0, 0))), |
|
870 |
// accuracy is that of a second |
|
871 |
FieldDef("datetime", QVariant::DateTime, QDateTime(QDate::currentDate(), QTime(1, 2, 3, 0))), |
|
872 |
FieldDef("char(20)", QVariant::String, "blah1"), |
|
873 |
FieldDef("varchar(20)", QVariant::String, "blah2"), |
|
874 |
FieldDef("nchar(20)", QVariant::String, "blah3"), |
|
875 |
FieldDef("nvarchar(20)", QVariant::String, "blah4"), |
|
876 |
FieldDef("text", QVariant::String, "blah5"), |
|
877 |
#ifdef QT3_SUPPORT |
|
878 |
FieldDef("binary(20)", QVariant::ByteArray, Q3CString("blah6")), |
|
879 |
FieldDef("varbinary(20)", QVariant::ByteArray, Q3CString("blah7")), |
|
880 |
FieldDef("image", QVariant::ByteArray, Q3CString("blah8")), |
|
881 |
#endif |
|
882 |
FieldDef("bit", QVariant::Int, 1, false), |
|
883 |
||
884 |
FieldDef() |
|
885 |
}; |
|
886 |
||
887 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
888 |
QVERIFY(fieldCount > 0); |
|
889 |
||
890 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
891 |
checkNullValues(fieldDefs, db); |
|
892 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
893 |
checkValues(fieldDefs, db); |
|
894 |
} |
|
895 |
} |
|
896 |
||
897 |
void tst_QSqlDatabase::recordOCI() |
|
898 |
{ |
|
899 |
bool hasTimeStamp = false; |
|
900 |
||
901 |
QFETCH(QString, dbName); |
|
902 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
903 |
CHECK_DATABASE(db); |
|
904 |
||
905 |
// runtime check for Oracle version since V8 doesn't support TIMESTAMPs |
|
906 |
if (tst_Databases::getOraVersion(db) >= 9) { |
|
907 |
qDebug("Detected Oracle >= 9, TIMESTAMP test enabled"); |
|
908 |
hasTimeStamp = true; |
|
909 |
} else { |
|
910 |
qDebug("Detected Oracle < 9, TIMESTAMP test disabled"); |
|
911 |
} |
|
912 |
||
913 |
FieldDef tsdef; |
|
914 |
FieldDef tstzdef; |
|
915 |
FieldDef tsltzdef; |
|
916 |
FieldDef intytm; |
|
917 |
FieldDef intdts; |
|
918 |
||
919 |
static const QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0)); |
|
920 |
||
921 |
if (hasTimeStamp) { |
|
922 |
tsdef = FieldDef("timestamp", QVariant::DateTime, dt); |
|
923 |
tstzdef = FieldDef("timestamp with time zone", QVariant::DateTime, dt); |
|
924 |
tsltzdef = FieldDef("timestamp with local time zone", QVariant::DateTime, dt); |
|
925 |
intytm = FieldDef("interval year to month", QVariant::String, QString("+01-01")); |
|
926 |
intdts = FieldDef("interval day to second", QVariant::String, QString("+01 00:00:01.000000")); |
|
927 |
} |
|
928 |
||
929 |
const FieldDef fieldDefs[] = { |
|
930 |
FieldDef("char(20)", QVariant::String, QString("blah1")), |
|
931 |
FieldDef("varchar(20)", QVariant::String, QString("blah2")), |
|
932 |
FieldDef("nchar(20)", QVariant::String, QString("blah3")), |
|
933 |
FieldDef("nvarchar2(20)", QVariant::String, QString("blah4")), |
|
934 |
FieldDef("number(10,5)", QVariant::Double, 1.1234567), |
|
935 |
FieldDef("date", QVariant::DateTime, dt), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
936 |
FieldDef("long raw", QVariant::ByteArray, QByteArray("blah5")), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
937 |
FieldDef("raw(2000)", QVariant::ByteArray, QByteArray("blah6"), false), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
938 |
FieldDef("blob", QVariant::ByteArray, QByteArray("blah7")), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
939 |
FieldDef("clob", QVariant::String, QString("blah8")), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
940 |
FieldDef("nclob", QVariant::String, QString("blah9")), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
941 |
FieldDef("bfile", QVariant::ByteArray, QByteArray("blah10")), |
0 | 942 |
|
943 |
intytm, |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
944 |
// intdts, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
945 |
// tsdef, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
946 |
// tstzdef, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
947 |
// tsltzdef, |
0 | 948 |
FieldDef() |
949 |
}; |
|
950 |
||
951 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
952 |
QVERIFY(fieldCount > 0); |
|
953 |
||
954 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
955 |
checkNullValues(fieldDefs, db); |
|
956 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
957 |
checkValues(fieldDefs, db); |
|
958 |
} |
|
959 |
||
960 |
// some additional tests |
|
961 |
QSqlRecord rec = db.record(qTableName("qtestfields")); |
|
962 |
QCOMPARE(rec.field("T_NUMBER").length(), 10); |
|
963 |
QCOMPARE(rec.field("T_NUMBER").precision(), 5); |
|
964 |
||
965 |
QSqlQuery q(db); |
|
966 |
QVERIFY_SQL(q, exec("SELECT * FROM " + qTableName("qtestfields"))); |
|
967 |
rec = q.record(); |
|
968 |
QCOMPARE(rec.field("T_NUMBER").length(), 10); |
|
969 |
QCOMPARE(rec.field("T_NUMBER").precision(), 5); |
|
970 |
} |
|
971 |
||
972 |
void tst_QSqlDatabase::recordPSQL() |
|
973 |
{ |
|
974 |
QFETCH(QString, dbName); |
|
975 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
976 |
CHECK_DATABASE(db); |
|
977 |
||
978 |
FieldDef byteadef; |
|
979 |
if (db.driver()->hasFeature(QSqlDriver::BLOB)) |
|
980 |
#ifdef QT3_SUPPORT |
|
981 |
byteadef = FieldDef("bytea", QVariant::ByteArray, QByteArray(Q3CString("bl\\ah"))); |
|
982 |
#else |
|
983 |
byteadef = FieldDef("bytea", QVariant::ByteArray, QByteArray("bl\\ah")); |
|
984 |
#endif |
|
985 |
static FieldDef fieldDefs[] = { |
|
986 |
FieldDef("bigint", QVariant::LongLong, Q_INT64_C(9223372036854775807)), |
|
987 |
FieldDef("bigserial", QVariant::LongLong, 100, false), |
|
988 |
FieldDef("bit", QVariant::String, "1"), // a bit in postgres is a bit-string |
|
989 |
#ifdef QT3_SUPPORT |
|
990 |
FieldDef("boolean", QVariant::Bool, QVariant(bool(true), 0)), |
|
991 |
#endif |
|
992 |
FieldDef("box", QVariant::String, "(5,6),(1,2)"), |
|
993 |
FieldDef("char(20)", QVariant::String, "blah5678901234567890"), |
|
994 |
FieldDef("varchar(20)", QVariant::String, "blah5678901234567890"), |
|
995 |
FieldDef("cidr", QVariant::String, "12.123.0.0/24"), |
|
996 |
FieldDef("circle", QVariant::String, "<(1,2),3>"), |
|
997 |
FieldDef("date", QVariant::Date, QDate::currentDate()), |
|
998 |
FieldDef("float8", QVariant::Double, 1.12345678912), |
|
999 |
FieldDef("inet", QVariant::String, "12.123.12.23"), |
|
1000 |
FieldDef("integer", QVariant::Int, 2147483647), |
|
1001 |
FieldDef("interval", QVariant::String, "1 day 12:59:10"), |
|
1002 |
// LOL... you can create a "line" datatype in PostgreSQL <= 7.2.x but |
|
1003 |
// as soon as you want to insert data you get a "not implemented yet" error |
|
1004 |
// FieldDef("line", QVariant::Polygon, QPolygon(QRect(1, 2, 3, 4))), |
|
1005 |
FieldDef("lseg", QVariant::String, "[(1,1),(2,2)]"), |
|
1006 |
FieldDef("macaddr", QVariant::String, "08:00:2b:01:02:03"), |
|
1007 |
FieldDef("money", QVariant::String, "$12.23"), |
|
1008 |
FieldDef("numeric", QVariant::Double, 1.2345678912), |
|
1009 |
FieldDef("path", QVariant::String, "((1,2),(3,2),(3,5),(1,5))"), |
|
1010 |
FieldDef("point", QVariant::String, "(1,2)"), |
|
1011 |
FieldDef("polygon", QVariant::String, "((1,2),(3,2),(3,5),(1,5))"), |
|
1012 |
FieldDef("real", QVariant::Double, 1.1234), |
|
1013 |
FieldDef("smallint", QVariant::Int, 32767), |
|
1014 |
FieldDef("serial", QVariant::Int, 100, false), |
|
1015 |
FieldDef("text", QVariant::String, "blah"), |
|
1016 |
FieldDef("time(6)", QVariant::Time, QTime(1, 2, 3)), |
|
1017 |
FieldDef("timetz", QVariant::Time, QTime(1, 2, 3)), |
|
1018 |
FieldDef("timestamp(6)", QVariant::DateTime, QDateTime::currentDateTime()), |
|
1019 |
FieldDef("timestamptz", QVariant::DateTime, QDateTime::currentDateTime()), |
|
1020 |
byteadef, |
|
1021 |
||
1022 |
FieldDef() |
|
1023 |
}; |
|
1024 |
||
1025 |
QSqlQuery q(db); |
|
1026 |
||
1027 |
if(tst_Databases::isPostgreSQL(db)) |
|
1028 |
QVERIFY_SQL( q, exec("set client_min_messages='warning'")); |
|
1029 |
||
1030 |
q.exec("drop sequence " + qTableName("qtestfields") + "_t_bigserial_seq"); |
|
1031 |
q.exec("drop sequence " + qTableName("qtestfields") + "_t_serial_seq"); |
|
1032 |
// older psql cut off the table name |
|
1033 |
q.exec("drop sequence " + qTableName("qtestfields").left(15) + "_t_bigserial_seq"); |
|
1034 |
q.exec("drop sequence " + qTableName("qtestfields").left(18) + "_t_serial_seq"); |
|
1035 |
||
1036 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
1037 |
QVERIFY(fieldCount > 0); |
|
1038 |
||
1039 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
1040 |
checkNullValues(fieldDefs, db); |
|
1041 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
1042 |
// increase serial values |
|
1043 |
for (int i2 = 0; !fieldDefs[ i2 ].typeName.isNull(); ++i2) { |
|
1044 |
if (fieldDefs[ i2 ].typeName == "serial" || |
|
1045 |
fieldDefs[ i2 ].typeName == "bigserial") { |
|
1046 |
||
1047 |
FieldDef def = fieldDefs[ i2 ]; |
|
1048 |
#ifdef QT3_SUPPORT |
|
1049 |
def.val = def.val.asInt() + 1; |
|
1050 |
#else |
|
1051 |
def.val = def.val.toInt() + 1; |
|
1052 |
#endif |
|
1053 |
fieldDefs[ i2 ] = def; |
|
1054 |
} |
|
1055 |
} |
|
1056 |
checkValues(fieldDefs, db); |
|
1057 |
} |
|
1058 |
} |
|
1059 |
||
1060 |
void tst_QSqlDatabase::recordMySQL() |
|
1061 |
{ |
|
1062 |
QFETCH(QString, dbName); |
|
1063 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1064 |
CHECK_DATABASE(db); |
|
1065 |
||
1066 |
FieldDef bin10, varbin10; |
|
1067 |
int major = tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt(); |
|
1068 |
int minor = tst_Databases::getMySqlVersion( db ).section( QChar('.'), 1, 1 ).toInt(); |
|
1069 |
int revision = tst_Databases::getMySqlVersion( db ).section( QChar('.'), 2, 2 ).toInt(); |
|
1070 |
int vernum = (major << 16) + (minor << 8) + revision; |
|
1071 |
||
1072 |
/* The below is broken in mysql below 5.0.15 |
|
1073 |
see http://dev.mysql.com/doc/refman/5.0/en/binary-varbinary.html |
|
1074 |
specifically: Before MySQL 5.0.15, the pad value is space. Values are right-padded |
|
1075 |
with space on insert, and trailing spaces are removed on select. |
|
1076 |
*/ |
|
1077 |
if( vernum >= ((5 << 16) + 15) ) { |
|
1078 |
#ifdef QT3_SUPPORT |
|
1079 |
bin10 = FieldDef("binary(10)", QVariant::ByteArray, QByteArray(Q3CString("123abc "))); |
|
1080 |
varbin10 = FieldDef("varbinary(10)", QVariant::ByteArray, QByteArray(Q3CString("123abcv "))); |
|
1081 |
#else |
|
1082 |
bin10 = FieldDef("binary(10)", QVariant::ByteArray, QString("123abc ")); |
|
1083 |
varbin10 = FieldDef("varbinary(10)", QVariant::ByteArray, QString("123abcv ")); |
|
1084 |
#endif |
|
1085 |
} |
|
1086 |
||
1087 |
static QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0)); |
|
1088 |
static const FieldDef fieldDefs[] = { |
|
1089 |
FieldDef("tinyint", QVariant::Int, 127), |
|
1090 |
FieldDef("tinyint unsigned", QVariant::UInt, 255), |
|
1091 |
FieldDef("smallint", QVariant::Int, 32767), |
|
1092 |
FieldDef("smallint unsigned", QVariant::UInt, 65535), |
|
1093 |
FieldDef("mediumint", QVariant::Int, 8388607), |
|
1094 |
FieldDef("mediumint unsigned", QVariant::UInt, 16777215), |
|
1095 |
FieldDef("integer", QVariant::Int, 2147483647), |
|
1096 |
FieldDef("integer unsigned", QVariant::UInt, 4294967295u), |
|
1097 |
FieldDef("bigint", QVariant::LongLong, Q_INT64_C(9223372036854775807)), |
|
1098 |
FieldDef("bigint unsigned", QVariant::ULongLong, Q_UINT64_C(18446744073709551615)), |
|
1099 |
FieldDef("float", QVariant::Double, 1.12345), |
|
1100 |
FieldDef("double", QVariant::Double, 1.123456789), |
|
1101 |
FieldDef("decimal(10, 9)", QVariant::Double,1.123456789), |
|
1102 |
FieldDef("numeric(5, 2)", QVariant::Double, 123.67), |
|
1103 |
FieldDef("date", QVariant::Date, QDate::currentDate()), |
|
1104 |
FieldDef("datetime", QVariant::DateTime, dt), |
|
1105 |
FieldDef("timestamp", QVariant::DateTime, dt, false), |
|
1106 |
FieldDef("time", QVariant::Time, dt.time()), |
|
1107 |
FieldDef("year", QVariant::Int, 2003), |
|
1108 |
FieldDef("char(20)", QVariant::String, "Blah"), |
|
1109 |
FieldDef("varchar(20)", QVariant::String, "BlahBlah"), |
|
1110 |
#ifdef QT3_SUPPORT |
|
1111 |
FieldDef("tinyblob", QVariant::ByteArray, QByteArray(Q3CString("blah1"))), |
|
1112 |
FieldDef("blob", QVariant::ByteArray, QByteArray(Q3CString("blah2"))), |
|
1113 |
FieldDef("mediumblob", QVariant::ByteArray,QByteArray(Q3CString("blah3"))), |
|
1114 |
FieldDef("longblob", QVariant::ByteArray, QByteArray(Q3CString("blah4"))), |
|
1115 |
#endif |
|
1116 |
FieldDef("tinytext", QVariant::String, QString("blah5")), |
|
1117 |
FieldDef("text", QVariant::String, QString("blah6")), |
|
1118 |
FieldDef("mediumtext", QVariant::String, QString("blah7")), |
|
1119 |
FieldDef("longtext", QVariant::String, QString("blah8")), |
|
1120 |
#ifdef QT3_SUPPORT |
|
1121 |
bin10, |
|
1122 |
varbin10, |
|
1123 |
#endif |
|
1124 |
// SET OF? |
|
1125 |
||
1126 |
FieldDef() |
|
1127 |
}; |
|
1128 |
||
1129 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
1130 |
QVERIFY(fieldCount > 0); |
|
1131 |
||
1132 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
1133 |
checkNullValues(fieldDefs, db); |
|
1134 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
1135 |
checkValues(fieldDefs, db); |
|
1136 |
} |
|
1137 |
||
1138 |
QSqlQuery q(db); |
|
1139 |
QVERIFY_SQL(q, exec("SELECT DATE_SUB(CURDATE(), INTERVAL 2 DAY)")); |
|
1140 |
QVERIFY(q.next()); |
|
1141 |
QCOMPARE(q.value(0).toDateTime().date(), QDate::currentDate().addDays(-2)); |
|
1142 |
} |
|
1143 |
||
1144 |
void tst_QSqlDatabase::recordDB2() |
|
1145 |
{ |
|
1146 |
QFETCH(QString, dbName); |
|
1147 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1148 |
CHECK_DATABASE(db); |
|
1149 |
||
1150 |
static const FieldDef fieldDefs[] = { |
|
1151 |
FieldDef("char(20)", QVariant::String, QString("Blah1")), |
|
1152 |
FieldDef("varchar(20)", QVariant::String, QString("Blah2")), |
|
1153 |
FieldDef("long varchar", QVariant::String, QString("Blah3")), |
|
1154 |
// using BOOLEAN results in "SQL0486N The BOOLEAN data type is currently only supported internally." |
|
1155 |
//X FieldDef("boolean" , QVariant::Bool, QVariant(true, 1)), |
|
1156 |
FieldDef("smallint", QVariant::Int, 32767), |
|
1157 |
FieldDef("integer", QVariant::Int, 2147483647), |
|
1158 |
FieldDef("bigint", QVariant::LongLong, Q_INT64_C(9223372036854775807)), |
|
1159 |
FieldDef("real", QVariant::Double, 1.12345), |
|
1160 |
FieldDef("double", QVariant::Double, 1.23456789), |
|
1161 |
FieldDef("float", QVariant::Double, 1.23456789), |
|
1162 |
FieldDef("decimal(10,9)", QVariant::Double, 1.234567891), |
|
1163 |
FieldDef("numeric(10,9)", QVariant::Double, 1.234567891), |
|
1164 |
FieldDef("date", QVariant::Date, QDate::currentDate()), |
|
1165 |
FieldDef("time", QVariant::Time, QTime(1, 2, 3)), |
|
1166 |
FieldDef("timestamp", QVariant::DateTime, QDateTime::currentDateTime()), |
|
1167 |
// FieldDef("graphic(20)", QVariant::String, QString("Blah4")), |
|
1168 |
// FieldDef("vargraphic(20)", QVariant::String, QString("Blah5")), |
|
1169 |
// FieldDef("long vargraphic", QVariant::String, QString("Blah6")), |
|
1170 |
#ifdef QT3_SUPPORT |
|
1171 |
// FieldDef("clob(20)", QVariant::CString, QString("Blah7")), |
|
1172 |
// FieldDef("dbclob(20)", QVariant::CString, QString("Blah8")), |
|
1173 |
// FieldDef("blob(20)", QVariant::ByteArray, QByteArray(Q3CString("Blah9"))), |
|
1174 |
#endif |
|
1175 |
//X FieldDef("datalink", QVariant::String, QString("DLVALUE('Blah10')")), |
|
1176 |
FieldDef() |
|
1177 |
}; |
|
1178 |
||
1179 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
1180 |
QVERIFY(fieldCount > 0); |
|
1181 |
||
1182 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
1183 |
checkNullValues(fieldDefs, db); |
|
1184 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
1185 |
checkValues(fieldDefs, db); |
|
1186 |
} |
|
1187 |
} |
|
1188 |
||
1189 |
void tst_QSqlDatabase::recordIBase() |
|
1190 |
{ |
|
1191 |
QFETCH(QString, dbName); |
|
1192 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1193 |
CHECK_DATABASE(db); |
|
1194 |
||
1195 |
static const FieldDef fieldDefs[] = { |
|
1196 |
FieldDef("char(20)", QVariant::String, QString("Blah1"), false), |
|
1197 |
FieldDef("varchar(20)", QVariant::String, QString("Blah2")), |
|
1198 |
FieldDef("smallint", QVariant::Int, 32767), |
|
1199 |
FieldDef("float", QVariant::Double, 1.2345), |
|
1200 |
FieldDef("double precision", QVariant::Double, 1.2345678), |
|
1201 |
FieldDef("timestamp", QVariant::DateTime, QDateTime::currentDateTime()), |
|
1202 |
FieldDef("time", QVariant::Time, QTime::currentTime()), |
|
1203 |
FieldDef("decimal(18)", QVariant::LongLong, Q_INT64_C(9223372036854775807)), |
|
1204 |
FieldDef("numeric(5,2)", QVariant::Double, 123.45), |
|
1205 |
||
1206 |
FieldDef() |
|
1207 |
}; |
|
1208 |
||
1209 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
1210 |
QVERIFY(fieldCount > 0); |
|
1211 |
||
1212 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
1213 |
checkNullValues(fieldDefs, db); |
|
1214 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
1215 |
checkValues(fieldDefs, db); |
|
1216 |
} |
|
1217 |
} |
|
1218 |
||
1219 |
void tst_QSqlDatabase::recordSQLite() |
|
1220 |
{ |
|
1221 |
QFETCH(QString, dbName); |
|
1222 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1223 |
CHECK_DATABASE(db); |
|
1224 |
||
1225 |
static const FieldDef fieldDefs[] = { |
|
1226 |
// The affinity of these fields are TEXT so SQLite should give us strings, not ints or doubles. |
|
1227 |
FieldDef("char(20)", QVariant::String, QString("123")), |
|
1228 |
FieldDef("varchar(20)", QVariant::String, QString("123.4")), |
|
1229 |
FieldDef("clob", QVariant::String, QString("123.45")), |
|
1230 |
FieldDef("text", QVariant::String, QString("123.456")), |
|
1231 |
||
1232 |
FieldDef("integer", QVariant::Int, QVariant(13)), |
|
1233 |
FieldDef("int", QVariant::Int, QVariant(12)), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1234 |
FieldDef("real", QVariant::String, QVariant(1.234567890123456)), |
0 | 1235 |
|
1236 |
FieldDef() |
|
1237 |
}; |
|
1238 |
||
1239 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
1240 |
QVERIFY(fieldCount > 0); |
|
1241 |
||
1242 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
1243 |
checkNullValues(fieldDefs, db); |
|
1244 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
1245 |
checkValues(fieldDefs, db); |
|
1246 |
} |
|
1247 |
} |
|
1248 |
||
1249 |
void tst_QSqlDatabase::recordSQLServer() |
|
1250 |
{ |
|
1251 |
QFETCH(QString, dbName); |
|
1252 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1253 |
CHECK_DATABASE(db); |
|
1254 |
||
1255 |
if (!tst_Databases::isSqlServer(db)) { |
|
1256 |
QSKIP("SQL server specific test", SkipSingle); |
|
1257 |
return; |
|
1258 |
} |
|
1259 |
||
1260 |
// ### TODO: Add the rest of the fields |
|
1261 |
static const FieldDef fieldDefs[] = { |
|
1262 |
FieldDef("varchar(20)", QVariant::String, QString("Blah1")), |
|
1263 |
FieldDef("bigint", QVariant::LongLong, 12345), |
|
1264 |
FieldDef("int", QVariant::Int, 123456), |
|
1265 |
FieldDef("tinyint", QVariant::UInt, 255), |
|
1266 |
#ifdef QT3_SUPPORT |
|
1267 |
FieldDef("image", QVariant::ByteArray, Q3CString("Blah1")), |
|
1268 |
#endif |
|
1269 |
FieldDef("float", QVariant::Double, 1.12345), |
|
1270 |
FieldDef("numeric(5,2)", QVariant::Double, 123.45), |
|
1271 |
FieldDef("uniqueidentifier", QVariant::String, |
|
1272 |
QString("AA7DF450-F119-11CD-8465-00AA00425D90")), |
|
1273 |
||
1274 |
FieldDef() |
|
1275 |
}; |
|
1276 |
||
1277 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
1278 |
QVERIFY(fieldCount > 0); |
|
1279 |
||
1280 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
1281 |
checkNullValues(fieldDefs, db); |
|
1282 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
1283 |
checkValues(fieldDefs, db); |
|
1284 |
} |
|
1285 |
} |
|
1286 |
||
1287 |
void tst_QSqlDatabase::recordAccess() |
|
1288 |
{ |
|
1289 |
QFETCH(QString, dbName); |
|
1290 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1291 |
CHECK_DATABASE(db); |
|
1292 |
||
1293 |
if (!tst_Databases::isMSAccess(db)) { |
|
1294 |
QSKIP("MS Access specific test", SkipSingle); |
|
1295 |
return; |
|
1296 |
} |
|
1297 |
||
1298 |
QString memo; |
|
1299 |
for (int i = 0; i < 32; i++) |
|
1300 |
memo.append("ABCDEFGH12345678abcdefgh12345678"); |
|
1301 |
||
1302 |
// ### TODO: Add the rest of the fields |
|
1303 |
static const FieldDef fieldDefs[] = { |
|
1304 |
FieldDef("varchar(20)", QVariant::String, QString("Blah1")), |
|
1305 |
FieldDef("single", QVariant::Double, 1.12345), |
|
1306 |
FieldDef("double", QVariant::Double, 1.123456), |
|
1307 |
FieldDef("byte", QVariant::UInt, 255), |
|
1308 |
#ifdef QT3_SUPPORT |
|
1309 |
FieldDef("binary(5)", QVariant::ByteArray, Q3CString("Blah2")), |
|
1310 |
#endif |
|
1311 |
FieldDef("long", QVariant::Int, 2147483647), |
|
1312 |
FieldDef("memo", QVariant::String, memo), |
|
1313 |
FieldDef() |
|
1314 |
}; |
|
1315 |
||
1316 |
const int fieldCount = createFieldTable(fieldDefs, db); |
|
1317 |
QVERIFY(fieldCount > 0); |
|
1318 |
||
1319 |
commonFieldTest(fieldDefs, db, fieldCount); |
|
1320 |
checkNullValues(fieldDefs, db); |
|
1321 |
for (int i = 0; i < ITERATION_COUNT; ++i) { |
|
1322 |
checkValues(fieldDefs, db); |
|
1323 |
} |
|
1324 |
} |
|
1325 |
||
1326 |
void tst_QSqlDatabase::transaction() |
|
1327 |
{ |
|
1328 |
QFETCH(QString, dbName); |
|
1329 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1330 |
CHECK_DATABASE(db); |
|
1331 |
||
1332 |
if (!db.driver()->hasFeature(QSqlDriver::Transactions)) { |
|
1333 |
QSKIP("DBMS not transaction capable", SkipSingle); |
|
1334 |
} |
|
1335 |
||
1336 |
QVERIFY(db.transaction()); |
|
1337 |
||
1338 |
QSqlQuery q(db); |
|
1339 |
QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " values (40, 'VarChar40', 'Char40', 40.40)")); |
|
1340 |
QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 40")); |
|
1341 |
QVERIFY(q.next()); |
|
1342 |
QCOMPARE(q.value(0).toInt(), 40); |
|
1343 |
q.clear(); |
|
1344 |
||
1345 |
QVERIFY(db.commit()); |
|
1346 |
||
1347 |
QVERIFY(db.transaction()); |
|
1348 |
QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 40")); |
|
1349 |
QVERIFY(q.next()); |
|
1350 |
QCOMPARE(q.value(0).toInt(), 40); |
|
1351 |
q.clear(); |
|
1352 |
QVERIFY(db.commit()); |
|
1353 |
||
1354 |
QVERIFY(db.transaction()); |
|
1355 |
QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " values (41, 'VarChar41', 'Char41', 41.41)")); |
|
1356 |
QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 41")); |
|
1357 |
QVERIFY(q.next()); |
|
1358 |
QCOMPARE(q.value(0).toInt(), 41); |
|
1359 |
q.clear(); // for SQLite which does not allow any references on rows that shall be rolled back |
|
1360 |
if (!db.rollback()) { |
|
1361 |
if (db.driverName().startsWith("QMYSQL")) { |
|
1362 |
qDebug("MySQL: " + tst_Databases::printError(db.lastError())); |
|
1363 |
QSKIP("MySQL transaction failed ", SkipSingle); //non-fatal |
|
1364 |
} else { |
|
1365 |
QFAIL("Could not rollback transaction: " + tst_Databases::printError(db.lastError())); |
|
1366 |
} |
|
1367 |
} |
|
1368 |
||
1369 |
QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 41")); |
|
1370 |
if(db.driverName().startsWith("QODBC") && dbName.contains("MySQL")) |
|
1371 |
QEXPECT_FAIL("", "Some odbc drivers don't actually roll back despite telling us they do, especially the mysql driver", Continue); |
|
1372 |
QVERIFY(!q.next()); |
|
1373 |
||
1374 |
populateTestTables(db); |
|
1375 |
} |
|
1376 |
||
1377 |
void tst_QSqlDatabase::bigIntField() |
|
1378 |
{ |
|
1379 |
QFETCH(QString, dbName); |
|
1380 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1381 |
CHECK_DATABASE(db); |
|
1382 |
QString drvName = db.driverName(); |
|
1383 |
||
1384 |
QSqlQuery q(db); |
|
1385 |
q.setForwardOnly(true); |
|
1386 |
if (drvName.startsWith("QOCI")) |
|
1387 |
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64); |
|
1388 |
||
1389 |
if (drvName.startsWith("QMYSQL")) { |
|
1390 |
QVERIFY_SQL(q, exec("create table " + qTableName("qtest_bigint") + " (id int, t_s64bit bigint, t_u64bit bigint unsigned)")); |
|
1391 |
} else if (drvName.startsWith("QPSQL") |
|
1392 |
|| drvName.startsWith("QDB2") |
|
1393 |
|| tst_Databases::isSqlServer(db)) { |
|
1394 |
QVERIFY_SQL(q, exec("create table " + qTableName("qtest_bigint") + "(id int, t_s64bit bigint, t_u64bit bigint)")); |
|
1395 |
} else if (drvName.startsWith("QOCI")) { |
|
1396 |
QVERIFY_SQL(q, exec("create table " + qTableName("qtest_bigint") + " (id int, t_s64bit int, t_u64bit int)")); |
|
1397 |
//} else if (drvName.startsWith("QIBASE")) { |
|
1398 |
// QVERIFY_SQL(q, exec("create table " + qTableName("qtest_bigint") + " (id int, t_s64bit int64, t_u64bit int64)")); |
|
1399 |
} else { |
|
1400 |
QSKIP("no 64 bit integer support", SkipAll); |
|
1401 |
} |
|
1402 |
QVERIFY(q.prepare("insert into " + qTableName("qtest_bigint") + " values (?, ?, ?)")); |
|
1403 |
qlonglong ll = Q_INT64_C(9223372036854775807); |
|
1404 |
qulonglong ull = Q_UINT64_C(18446744073709551615); |
|
1405 |
||
1406 |
if (drvName.startsWith("QMYSQL") || drvName.startsWith("QOCI")) { |
|
1407 |
q.bindValue(0, 0); |
|
1408 |
q.bindValue(1, ll); |
|
1409 |
q.bindValue(2, ull); |
|
1410 |
QVERIFY_SQL(q, exec()); |
|
1411 |
q.bindValue(0, 1); |
|
1412 |
q.bindValue(1, -ll); |
|
1413 |
q.bindValue(2, ull); |
|
1414 |
QVERIFY_SQL(q, exec()); |
|
1415 |
} else { |
|
1416 |
// usinged bigint fields not supported - a cast is necessary |
|
1417 |
q.bindValue(0, 0); |
|
1418 |
q.bindValue(1, ll); |
|
1419 |
q.bindValue(2, (qlonglong) ull); |
|
1420 |
QVERIFY_SQL(q, exec()); |
|
1421 |
q.bindValue(0, 1); |
|
1422 |
q.bindValue(1, -ll); |
|
1423 |
q.bindValue(2, (qlonglong) ull); |
|
1424 |
QVERIFY_SQL(q, exec()); |
|
1425 |
} |
|
1426 |
QVERIFY(q.exec("select * from " + qTableName("qtest_bigint") + " order by id")); |
|
1427 |
QVERIFY(q.next()); |
|
1428 |
QCOMPARE(q.value(1).toDouble(), (double)ll); |
|
1429 |
QCOMPARE(q.value(1).toLongLong(), ll); |
|
1430 |
if(drvName.startsWith("QOCI")) |
|
1431 |
QEXPECT_FAIL("", "Oracle driver lacks support for unsigned int64 types", Continue); |
|
1432 |
QCOMPARE(q.value(2).toULongLong(), ull); |
|
1433 |
QVERIFY(q.next()); |
|
1434 |
QCOMPARE(q.value(1).toLongLong(), -ll); |
|
1435 |
if(drvName.startsWith("QOCI")) |
|
1436 |
QEXPECT_FAIL("", "Oracle driver lacks support for unsigned int64 types", Continue); |
|
1437 |
QCOMPARE(q.value(2).toULongLong(), ull); |
|
1438 |
} |
|
1439 |
||
1440 |
void tst_QSqlDatabase::caseSensivity() |
|
1441 |
{ |
|
1442 |
QFETCH(QString, dbName); |
|
1443 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1444 |
CHECK_DATABASE(db); |
|
1445 |
||
1446 |
bool cs = false; |
|
1447 |
if (db.driverName().startsWith("QMYSQL") |
|
1448 |
|| db.driverName().startsWith("QSQLITE") |
|
1449 |
|| db.driverName().startsWith("QTDS") |
|
1450 |
|| db.driverName().startsWith("QODBC")) |
|
1451 |
cs = true; |
|
1452 |
||
1453 |
QSqlRecord rec = db.record(qTableName("qtest")); |
|
1454 |
QVERIFY((int)rec.count() > 0); |
|
1455 |
if (!cs) { |
|
1456 |
rec = db.record(qTableName("QTEST").toUpper()); |
|
1457 |
QVERIFY((int)rec.count() > 0); |
|
1458 |
rec = db.record(qTableName("qTesT")); |
|
1459 |
QVERIFY((int)rec.count() > 0); |
|
1460 |
} |
|
1461 |
||
1462 |
#ifdef QT3_SUPPORT |
|
1463 |
Q3SqlRecordInfo rInf = db.recordInfo(qTableName("qtest")); |
|
1464 |
QVERIFY((int)rInf.count() > 0); |
|
1465 |
if (!cs) { |
|
1466 |
rInf = db.recordInfo(qTableName("QTEST").upper()); |
|
1467 |
QVERIFY((int)rInf.count() > 0); |
|
1468 |
rInf = db.recordInfo(qTableName("qTesT")); |
|
1469 |
QVERIFY((int)rInf.count() > 0); |
|
1470 |
} |
|
1471 |
#endif |
|
1472 |
||
1473 |
rec = db.primaryIndex(qTableName("qtest")); |
|
1474 |
QVERIFY((int)rec.count() > 0); |
|
1475 |
if (!cs) { |
|
1476 |
rec = db.primaryIndex(qTableName("QTEST").toUpper()); |
|
1477 |
QVERIFY((int)rec.count() > 0); |
|
1478 |
rec = db.primaryIndex(qTableName("qTesT")); |
|
1479 |
QVERIFY((int)rec.count() > 0); |
|
1480 |
} |
|
1481 |
} |
|
1482 |
||
1483 |
void tst_QSqlDatabase::noEscapedFieldNamesInRecord() |
|
1484 |
{ |
|
1485 |
QFETCH(QString, dbName); |
|
1486 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1487 |
CHECK_DATABASE(db); |
|
1488 |
||
1489 |
QString fieldname("t_varchar"); |
|
1490 |
if (db.driverName().startsWith("QOCI") || db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QDB2")) |
|
1491 |
fieldname = fieldname.toUpper(); |
|
1492 |
||
1493 |
QSqlQuery q(db); |
|
1494 |
QString query = "SELECT " + db.driver()->escapeIdentifier(fieldname, QSqlDriver::FieldName) + " FROM " + qTableName("qtest"); |
|
1495 |
QVERIFY_SQL(q, exec(query)); |
|
1496 |
QCOMPARE(q.record().fieldName(0), fieldname); |
|
1497 |
} |
|
1498 |
||
1499 |
void tst_QSqlDatabase::psql_schemas() |
|
1500 |
{ |
|
1501 |
QFETCH(QString, dbName); |
|
1502 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1503 |
CHECK_DATABASE(db); |
|
1504 |
||
1505 |
if (!db.tables(QSql::SystemTables).contains("pg_namespace")) |
|
1506 |
QSKIP("server does not support schemas", SkipSingle); |
|
1507 |
||
1508 |
QSqlQuery q(db); |
|
1509 |
||
1510 |
if(tst_Databases::isPostgreSQL(db)) { |
|
1511 |
QVERIFY_SQL( q, exec("set client_min_messages='warning'")); |
|
1512 |
} |
|
1513 |
||
1514 |
QVERIFY_SQL(q, exec("CREATE SCHEMA " + qTableName("qtestschema"))); |
|
1515 |
||
1516 |
QString table = qTableName("qtestschema") + '.' + qTableName("qtesttable"); |
|
1517 |
QVERIFY_SQL(q, exec("CREATE TABLE " + table + " (id int primary key, name varchar(20))")); |
|
1518 |
||
1519 |
QVERIFY(db.tables().contains(table)); |
|
1520 |
||
1521 |
QSqlRecord rec = db.record(table); |
|
1522 |
QCOMPARE(rec.count(), 2); |
|
1523 |
QCOMPARE(rec.fieldName(0), QString("id")); |
|
1524 |
QCOMPARE(rec.fieldName(1), QString("name")); |
|
1525 |
||
1526 |
#ifdef QT3_SUPPORT |
|
1527 |
rec = db.record(QSqlQuery("select * from " + table, db)); |
|
1528 |
QCOMPARE(rec.count(), 2); |
|
1529 |
QCOMPARE(rec.fieldName(0), QString("id")); |
|
1530 |
QCOMPARE(rec.fieldName(1), QString("name")); |
|
1531 |
#endif |
|
1532 |
QSqlIndex idx = db.primaryIndex(table); |
|
1533 |
QCOMPARE(idx.count(), 1); |
|
1534 |
QCOMPARE(idx.fieldName(0), QString("id")); |
|
1535 |
} |
|
1536 |
||
1537 |
void tst_QSqlDatabase::psql_escapedIdentifiers() |
|
1538 |
{ |
|
1539 |
QFETCH(QString, dbName); |
|
1540 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1541 |
QSqlDriver* drv = db.driver(); |
|
1542 |
CHECK_DATABASE(db); |
|
1543 |
||
1544 |
if (!db.tables(QSql::SystemTables).contains("pg_namespace")) |
|
1545 |
QSKIP("server does not support schemas", SkipSingle); |
|
1546 |
||
1547 |
QSqlQuery q(db); |
|
1548 |
||
1549 |
if(tst_Databases::isPostgreSQL(db)) |
|
1550 |
QVERIFY_SQL( q, exec("set client_min_messages='warning'")); |
|
1551 |
||
1552 |
QString schemaName = qTableName("qtestScHeMa"); |
|
1553 |
QString tableName = qTableName("qtest"); |
|
1554 |
QString field1Name = QString("fIeLdNaMe"); |
|
1555 |
QString field2Name = QString("ZuLu"); |
|
1556 |
||
1557 |
q.exec(QString("DROP SCHEMA \"%1\" CASCADE").arg(schemaName)); |
|
1558 |
QString createSchema = QString("CREATE SCHEMA \"%1\"").arg(schemaName); |
|
1559 |
QVERIFY_SQL(q, exec(createSchema)); |
|
1560 |
QString createTable = QString("CREATE TABLE \"%1\".\"%2\" (\"%3\" int PRIMARY KEY, \"%4\" varchar(20))").arg(schemaName).arg(tableName).arg(field1Name).arg(field2Name); |
|
1561 |
QVERIFY_SQL(q, exec(createTable)); |
|
1562 |
||
1563 |
QVERIFY(db.tables().contains(schemaName + '.' + tableName, Qt::CaseSensitive)); |
|
1564 |
||
1565 |
QSqlField fld1(field1Name, QVariant::Int); |
|
1566 |
QSqlField fld2(field2Name, QVariant::String); |
|
1567 |
QSqlRecord rec; |
|
1568 |
rec.append(fld1); |
|
1569 |
rec.append(fld2); |
|
1570 |
||
1571 |
QVERIFY_SQL(q, exec(drv->sqlStatement(QSqlDriver::SelectStatement, db.driver()->escapeIdentifier(schemaName, QSqlDriver::TableName) + '.' + db.driver()->escapeIdentifier(tableName, QSqlDriver::TableName), rec, false))); |
|
1572 |
||
1573 |
rec = q.record(); |
|
1574 |
QCOMPARE(rec.count(), 2); |
|
1575 |
QCOMPARE(rec.fieldName(0), field1Name); |
|
1576 |
QCOMPARE(rec.fieldName(1), field2Name); |
|
1577 |
QCOMPARE(rec.field(0).type(), QVariant::Int); |
|
1578 |
||
1579 |
q.exec(QString("DROP SCHEMA \"%1\" CASCADE").arg(schemaName)); |
|
1580 |
} |
|
1581 |
||
1582 |
||
1583 |
void tst_QSqlDatabase::psql_escapeBytea() |
|
1584 |
{ |
|
1585 |
QFETCH(QString, dbName); |
|
1586 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1587 |
CHECK_DATABASE(db); |
|
1588 |
||
1589 |
const char dta[4] = {'\x71', '\x14', '\x32', '\x81'}; |
|
1590 |
QByteArray ba(dta, 4); |
|
1591 |
||
1592 |
QSqlQuery q(db); |
|
1593 |
QString tableName = qTableName("batable"); |
|
1594 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (ba bytea)").arg(tableName))); |
|
1595 |
||
1596 |
QSqlQuery iq(db); |
|
1597 |
QVERIFY_SQL(iq, prepare(QString("INSERT INTO %1 VALUES (?)").arg(tableName))); |
|
1598 |
iq.bindValue(0, QVariant(ba)); |
|
1599 |
QVERIFY_SQL(iq, exec()); |
|
1600 |
||
1601 |
QVERIFY_SQL(q, exec(QString("SELECT ba FROM %1").arg(tableName))); |
|
1602 |
QVERIFY_SQL(q, next()); |
|
1603 |
||
1604 |
QByteArray res = q.value(0).toByteArray(); |
|
1605 |
int i = 0; |
|
1606 |
for (; i < ba.size(); ++i){ |
|
1607 |
if (ba[i] != res[i]) |
|
1608 |
break; |
|
1609 |
} |
|
1610 |
||
1611 |
QCOMPARE(i, 4); |
|
1612 |
} |
|
1613 |
||
1614 |
void tst_QSqlDatabase::bug_249059() |
|
1615 |
{ |
|
1616 |
QFETCH(QString, dbName); |
|
1617 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1618 |
CHECK_DATABASE(db); |
|
1619 |
||
1620 |
QString version=tst_Databases::getPSQLVersion( db ); |
|
1621 |
double ver=version.section(QChar::fromLatin1('.'),0,1).toDouble(); |
|
1622 |
if (ver < 7.3) |
|
1623 |
QSKIP("Test requires PostgreSQL >= 7.3", SkipSingle); |
|
1624 |
||
1625 |
QSqlQuery q(db); |
|
1626 |
QString tableName = qTableName("bug_249059"); |
|
1627 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (dt timestamp, t time)").arg(tableName))); |
|
1628 |
||
1629 |
QSqlQuery iq(db); |
|
1630 |
QVERIFY_SQL(iq, prepare(QString("INSERT INTO %1 VALUES (?, ?)").arg(tableName))); |
|
1631 |
iq.bindValue(0, QVariant(QString("2001-09-09 04:05:06.789 -5:00"))); |
|
1632 |
iq.bindValue(1, QVariant(QString("04:05:06.789 -5:00"))); |
|
1633 |
QVERIFY_SQL(iq, exec()); |
|
1634 |
iq.bindValue(0, QVariant(QString("2001-09-09 04:05:06.789 +5:00"))); |
|
1635 |
iq.bindValue(1, QVariant(QString("04:05:06.789 +5:00"))); |
|
1636 |
QVERIFY_SQL(iq, exec()); |
|
1637 |
||
1638 |
QVERIFY_SQL(q, exec(QString("SELECT dt, t FROM %1").arg(tableName))); |
|
1639 |
QVERIFY_SQL(q, next()); |
|
1640 |
QDateTime dt1=q.value(0).toDateTime(); |
|
1641 |
QTime t1=q.value(1).toTime(); |
|
1642 |
QVERIFY_SQL(q, next()); |
|
1643 |
QDateTime dt2=q.value(0).toDateTime(); |
|
1644 |
QTime t2=q.value(1).toTime(); |
|
1645 |
||
1646 |
// These will fail when timezone support is added, when that's the case, set the second record to 14:05:06.789 and it should work correctly |
|
1647 |
QCOMPARE(dt1, dt2); |
|
1648 |
QCOMPARE(t1, t2); |
|
1649 |
} |
|
1650 |
||
1651 |
// This test should be rewritten to work with Oracle as well - or the Oracle driver |
|
1652 |
// should be fixed to make this test pass (handle overflows) |
|
1653 |
void tst_QSqlDatabase::precisionPolicy() |
|
1654 |
{ |
|
1655 |
QFETCH(QString, dbName); |
|
1656 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1657 |
CHECK_DATABASE(db); |
|
1658 |
// DBMS_SPECIFIC(db, "QPSQL"); |
|
1659 |
||
1660 |
QSqlQuery q(db); |
|
1661 |
QString tableName = qTableName("qtest_prec"); |
|
1662 |
if(!db.driver()->hasFeature(QSqlDriver::LowPrecisionNumbers)) |
|
1663 |
QSKIP("Driver or database doesn't support setting precision policy", SkipSingle); |
|
1664 |
||
1665 |
// Create a test table with some data |
|
1666 |
if(tst_Databases::isMSAccess(db)) |
|
1667 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id smallint, num number)").arg(tableName))); |
|
1668 |
else |
|
1669 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id smallint, num numeric(18,5))").arg(tableName))); |
|
1670 |
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?, ?)").arg(tableName))); |
|
1671 |
q.bindValue(0, 1); |
|
1672 |
q.bindValue(1, 123); |
|
1673 |
QVERIFY_SQL(q, exec()); |
|
1674 |
q.bindValue(0, 2); |
|
1675 |
q.bindValue(1, 1850000000000.0001); |
|
1676 |
QVERIFY_SQL(q, exec()); |
|
1677 |
||
1678 |
// These are expected to pass |
|
1679 |
q.setNumericalPrecisionPolicy(QSql::HighPrecision); |
|
1680 |
QString query = QString("SELECT num FROM %1 WHERE id = 1").arg(tableName); |
|
1681 |
QVERIFY_SQL(q, exec(query)); |
|
1682 |
QVERIFY_SQL(q, next()); |
|
1683 |
if(db.driverName().startsWith("QSQLITE")) |
|
1684 |
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue); |
|
1685 |
QCOMPARE(q.value(0).type(), QVariant::String); |
|
1686 |
||
1687 |
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64); |
|
1688 |
QVERIFY_SQL(q, exec(query)); |
|
1689 |
QVERIFY_SQL(q, next()); |
|
1690 |
if(q.value(0).type() != QVariant::LongLong) |
|
1691 |
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue); |
|
1692 |
QCOMPARE(q.value(0).type(), QVariant::LongLong); |
|
1693 |
QCOMPARE(q.value(0).toLongLong(), (qlonglong)123); |
|
1694 |
||
1695 |
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt32); |
|
1696 |
QVERIFY_SQL(q, exec(query)); |
|
1697 |
if(db.driverName().startsWith("QOCI")) |
|
1698 |
QEXPECT_FAIL("", "Oracle fails to move to next when data columns are oversize", Abort); |
|
1699 |
QVERIFY_SQL(q, next()); |
|
1700 |
if(db.driverName().startsWith("QSQLITE")) |
|
1701 |
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue); |
|
1702 |
QCOMPARE(q.value(0).type(), QVariant::Int); |
|
1703 |
QCOMPARE(q.value(0).toInt(), 123); |
|
1704 |
||
1705 |
q.setNumericalPrecisionPolicy(QSql::LowPrecisionDouble); |
|
1706 |
QVERIFY_SQL(q, exec(query)); |
|
1707 |
QVERIFY_SQL(q, next()); |
|
1708 |
if(db.driverName().startsWith("QSQLITE")) |
|
1709 |
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue); |
|
1710 |
QCOMPARE(q.value(0).type(), QVariant::Double); |
|
1711 |
QCOMPARE(q.value(0).toDouble(), (double)123); |
|
1712 |
||
1713 |
query = QString("SELECT num FROM %1 WHERE id = 2").arg(tableName); |
|
1714 |
QVERIFY_SQL(q, exec(query)); |
|
1715 |
QVERIFY_SQL(q, next()); |
|
1716 |
if(db.driverName().startsWith("QSQLITE")) |
|
1717 |
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue); |
|
1718 |
QCOMPARE(q.value(0).type(), QVariant::Double); |
|
1719 |
QCOMPARE(q.value(0).toDouble(), QString("1850000000000.0001").toDouble()); |
|
1720 |
||
1721 |
// Postgres returns invalid QVariants on overflow |
|
1722 |
q.setNumericalPrecisionPolicy(QSql::HighPrecision); |
|
1723 |
QVERIFY_SQL(q, exec(query)); |
|
1724 |
QVERIFY_SQL(q, next()); |
|
1725 |
if(db.driverName().startsWith("QSQLITE")) |
|
1726 |
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue); |
|
1727 |
QCOMPARE(q.value(0).type(), QVariant::String); |
|
1728 |
||
1729 |
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64); |
|
1730 |
QEXPECT_FAIL("QOCI", "Oracle fails here, to retrieve next", Continue); |
|
1731 |
QVERIFY_SQL(q, exec(query)); |
|
1732 |
QVERIFY_SQL(q, next()); |
|
1733 |
QCOMPARE(q.value(0).type(), QVariant::LongLong); |
|
1734 |
||
1735 |
QSql::NumericalPrecisionPolicy oldPrecision= db.numericalPrecisionPolicy(); |
|
1736 |
db.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64); |
|
1737 |
QSqlQuery q2(db); |
|
1738 |
q2.exec(QString("SELECT num FROM %1 WHERE id = 2").arg(tableName)); |
|
1739 |
QVERIFY_SQL(q2, exec(query)); |
|
1740 |
QVERIFY_SQL(q2, next()); |
|
1741 |
QCOMPARE(q2.value(0).type(), QVariant::LongLong); |
|
1742 |
db.setNumericalPrecisionPolicy(oldPrecision); |
|
1743 |
} |
|
1744 |
||
1745 |
// This test needs a ODBC data source containing MYSQL in it's name |
|
1746 |
void tst_QSqlDatabase::mysqlOdbc_unsignedIntegers() |
|
1747 |
{ |
|
1748 |
QFETCH(QString, dbName); |
|
1749 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1750 |
CHECK_DATABASE(db); |
|
1751 |
||
1752 |
if (!db.driverName().startsWith("QODBC") || !dbName.toUpper().contains("MYSQL")) { |
|
1753 |
QSKIP("MySQL through ODBC-driver specific test", SkipSingle); |
|
1754 |
return; |
|
1755 |
} |
|
1756 |
||
1757 |
QSqlQuery q(db); |
|
1758 |
QString tableName = qTableName("uint"); |
|
1759 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (foo integer(10) unsigned, bar integer(10))").arg(tableName))); |
|
1760 |
QVERIFY_SQL(q, exec(QString("INSERT INTO %1 VALUES (-4000000000, -4000000000)").arg(tableName))); |
|
1761 |
QVERIFY_SQL(q, exec(QString("INSERT INTO %1 VALUES (4000000000, 4000000000)").arg(tableName))); |
|
1762 |
||
1763 |
QVERIFY_SQL(q, exec(QString("SELECT foo, bar FROM %1").arg(tableName))); |
|
1764 |
QVERIFY(q.next()); |
|
1765 |
QCOMPARE(q.value(0).toString(), QString("0")); |
|
1766 |
QCOMPARE(q.value(1).toString(), QString("-2147483648")); |
|
1767 |
QVERIFY(q.next()); |
|
1768 |
QCOMPARE(q.value(0).toString(), QString("4000000000")); |
|
1769 |
QCOMPARE(q.value(1).toString(), QString("2147483647")); |
|
1770 |
} |
|
1771 |
||
1772 |
void tst_QSqlDatabase::accessOdbc_strings() |
|
1773 |
{ |
|
1774 |
QFETCH(QString, dbName); |
|
1775 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1776 |
CHECK_DATABASE(db); |
|
1777 |
||
1778 |
if (!tst_Databases::isMSAccess(db)) { |
|
1779 |
QSKIP("MS Access specific test", SkipSingle); |
|
1780 |
return; |
|
1781 |
} |
|
1782 |
||
1783 |
QSqlQuery q(db); |
|
1784 |
QString tableName = qTableName("strings"); |
|
1785 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (aStr memo, bStr memo, cStr memo, dStr memo" |
|
1786 |
", eStr memo, fStr memo, gStr memo, hStr memo)").arg(tableName))); |
|
1787 |
||
1788 |
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?, ?, ?, ?, ?, ?, ?, ?)").arg(tableName))); |
|
1789 |
QString aStr, bStr, cStr, dStr, eStr, fStr, gStr, hStr; |
|
1790 |
||
1791 |
q.bindValue(0, aStr.fill('A', 32)); |
|
1792 |
q.bindValue(1, bStr.fill('B', 127)); |
|
1793 |
q.bindValue(2, cStr.fill('C', 128)); |
|
1794 |
q.bindValue(3, dStr.fill('D', 129)); |
|
1795 |
q.bindValue(4, eStr.fill('E', 254)); |
|
1796 |
q.bindValue(5, fStr.fill('F', 255)); |
|
1797 |
q.bindValue(6, gStr.fill('G', 256)); |
|
1798 |
q.bindValue(7, hStr.fill('H', 512)); |
|
1799 |
||
1800 |
QVERIFY_SQL(q, exec()); |
|
1801 |
||
1802 |
QVERIFY_SQL(q, exec(QString("SELECT aStr, bStr, cStr, dStr, eStr, fStr, gStr, hStr FROM %1").arg(tableName))); |
|
1803 |
q.next(); |
|
1804 |
QCOMPARE(q.value(0).toString(), aStr); |
|
1805 |
QCOMPARE(q.value(1).toString(), bStr); |
|
1806 |
QCOMPARE(q.value(2).toString(), cStr); |
|
1807 |
QCOMPARE(q.value(3).toString(), dStr); |
|
1808 |
QCOMPARE(q.value(4).toString(), eStr); |
|
1809 |
QCOMPARE(q.value(5).toString(), fStr); |
|
1810 |
QCOMPARE(q.value(6).toString(), gStr); |
|
1811 |
QCOMPARE(q.value(7).toString(), hStr); |
|
1812 |
} |
|
1813 |
||
1814 |
// For task 125053 |
|
1815 |
void tst_QSqlDatabase::ibase_numericFields() |
|
1816 |
{ |
|
1817 |
QFETCH(QString, dbName); |
|
1818 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1819 |
CHECK_DATABASE(db); |
|
1820 |
||
1821 |
QSqlQuery q(db); |
|
1822 |
QString tableName = qTableName("numericfields"); |
|
1823 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id int not null, num1 NUMERIC(2,1), " |
|
1824 |
"num2 NUMERIC(5,2), num3 NUMERIC(10,3), " |
|
1825 |
"num4 NUMERIC(18,4))").arg(tableName))); |
|
1826 |
||
1827 |
QVERIFY_SQL(q, exec(QString("INSERT INTO %1 VALUES (1, 1.1, 123.45, 1234567.123, 10203040506070.8090)").arg(tableName))); |
|
1828 |
||
1829 |
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?, ?, ?, ?, ?)").arg(tableName))); |
|
1830 |
||
1831 |
double num1 = 1.1; |
|
1832 |
double num2 = 123.45; |
|
1833 |
double num3 = 1234567.123; |
|
1834 |
double num4 = 10203040506070.8090; |
|
1835 |
||
1836 |
q.bindValue(0, 2); |
|
1837 |
q.bindValue(1, QVariant(num1)); |
|
1838 |
q.bindValue(2, QVariant(num2)); |
|
1839 |
q.bindValue(3, QVariant(num3)); |
|
1840 |
q.bindValue(4, QVariant(num4)); |
|
1841 |
QVERIFY_SQL(q, exec()); |
|
1842 |
||
1843 |
QVERIFY_SQL(q, exec(QString("SELECT id, num1, num2, num3, num4 FROM %1").arg(tableName))); |
|
1844 |
||
1845 |
int id = 0; |
|
1846 |
while (q.next()) { |
|
1847 |
QCOMPARE(q.value(0).toInt(), ++id); |
|
1848 |
QCOMPARE(q.value(1).toString(), QString("%1").arg(num1)); |
|
1849 |
QCOMPARE(q.value(2).toString(), QString("%1").arg(num2)); |
|
1850 |
QCOMPARE(QString("%1").arg(q.value(3).toDouble()), QString("%1").arg(num3)); |
|
1851 |
QCOMPARE(QString("%1").arg(q.value(4).toDouble()), QString("%1").arg(num4)); |
|
1852 |
QVERIFY(q.value(0).type() == QVariant::Int); |
|
1853 |
QVERIFY(q.value(1).type() == QVariant::Double); |
|
1854 |
QVERIFY(q.value(2).type() == QVariant::Double); |
|
1855 |
QVERIFY(q.value(3).type() == QVariant::Double); |
|
1856 |
QVERIFY(q.value(4).type() == QVariant::Double); |
|
1857 |
||
1858 |
QCOMPARE(q.record().field(1).length(), 2); |
|
1859 |
QCOMPARE(q.record().field(1).precision(), 1); |
|
1860 |
QCOMPARE(q.record().field(2).length(), 5); |
|
1861 |
QCOMPARE(q.record().field(2).precision(), 2); |
|
1862 |
QCOMPARE(q.record().field(3).length(), 10); |
|
1863 |
QCOMPARE(q.record().field(3).precision(), 3); |
|
1864 |
QCOMPARE(q.record().field(4).length(), 18); |
|
1865 |
QCOMPARE(q.record().field(4).precision(), 4); |
|
1866 |
QVERIFY(q.record().field(0).requiredStatus() == QSqlField::Required); |
|
1867 |
QVERIFY(q.record().field(1).requiredStatus() == QSqlField::Optional); |
|
1868 |
} |
|
1869 |
||
1870 |
QSqlRecord r = db.record(tableName); |
|
1871 |
QVERIFY(r.field(0).type() == QVariant::Int); |
|
1872 |
QVERIFY(r.field(1).type() == QVariant::Double); |
|
1873 |
QVERIFY(r.field(2).type() == QVariant::Double); |
|
1874 |
QVERIFY(r.field(3).type() == QVariant::Double); |
|
1875 |
QVERIFY(r.field(4).type() == QVariant::Double); |
|
1876 |
QCOMPARE(r.field(1).length(), 2); |
|
1877 |
QCOMPARE(r.field(1).precision(), 1); |
|
1878 |
QCOMPARE(r.field(2).length(), 5); |
|
1879 |
QCOMPARE(r.field(2).precision(), 2); |
|
1880 |
QCOMPARE(r.field(3).length(), 10); |
|
1881 |
QCOMPARE(r.field(3).precision(), 3); |
|
1882 |
QCOMPARE(r.field(4).length(), 18); |
|
1883 |
QCOMPARE(r.field(4).precision(), 4); |
|
1884 |
QVERIFY(r.field(0).requiredStatus() == QSqlField::Required); |
|
1885 |
QVERIFY(r.field(1).requiredStatus() == QSqlField::Optional); |
|
1886 |
} |
|
1887 |
||
1888 |
void tst_QSqlDatabase::ibase_fetchBlobs() |
|
1889 |
{ |
|
1890 |
QFETCH(QString, dbName); |
|
1891 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1892 |
CHECK_DATABASE(db); |
|
1893 |
||
1894 |
QString tableName = qTableName("qtest_ibaseblobs"); |
|
1895 |
QSqlQuery q(db); |
|
1896 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (blob1 BLOB segment size 256)").arg(tableName))); |
|
1897 |
||
1898 |
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?)").arg(tableName))); |
|
1899 |
q.bindValue(0, QByteArray().fill('x', 1024)); |
|
1900 |
QVERIFY_SQL(q, exec()); |
|
1901 |
||
1902 |
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?)").arg(tableName))); |
|
1903 |
q.bindValue(0, QByteArray().fill('x', 16383)); |
|
1904 |
QVERIFY_SQL(q, exec()); |
|
1905 |
||
1906 |
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?)").arg(tableName))); |
|
1907 |
q.bindValue(0, QByteArray().fill('x', 17408)); |
|
1908 |
QVERIFY_SQL(q, exec()); |
|
1909 |
||
1910 |
QVERIFY_SQL(q, exec(QString("SELECT * FROM %1").arg(tableName))); |
|
1911 |
||
1912 |
QVERIFY_SQL(q, next()); |
|
1913 |
QCOMPARE(q.value(0).toByteArray().size(), 1024); |
|
1914 |
QVERIFY_SQL(q, next()); |
|
1915 |
QCOMPARE(q.value(0).toByteArray().size(), 16383); |
|
1916 |
QVERIFY_SQL(q, next()); |
|
1917 |
QCOMPARE(q.value(0).toByteArray().size(), 17408); |
|
1918 |
} |
|
1919 |
||
1920 |
void tst_QSqlDatabase::ibase_procWithoutReturnValues() |
|
1921 |
{ |
|
1922 |
QFETCH(QString, dbName); |
|
1923 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1924 |
CHECK_DATABASE(db); |
|
1925 |
||
1926 |
QSqlQuery q(db); |
|
1927 |
QString procName = qTableName("qtest_proc1"); |
|
1928 |
q.exec(QString("drop procedure %1").arg(procName)); |
|
1929 |
QVERIFY_SQL(q, exec("CREATE PROCEDURE " + procName + " (str VARCHAR(10))\nAS BEGIN\nstr='test';\nEND;")); |
|
1930 |
QVERIFY_SQL(q, exec(QString("execute procedure %1('qtest')").arg(procName))); |
|
1931 |
q.exec(QString("drop procedure %1").arg(procName)); |
|
1932 |
} |
|
1933 |
||
1934 |
void tst_QSqlDatabase::ibase_procWithReturnValues() |
|
1935 |
{ |
|
1936 |
QFETCH(QString, dbName); |
|
1937 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1938 |
CHECK_DATABASE(db); |
|
1939 |
||
1940 |
if (!db.driverName().startsWith("QIBASE")) { |
|
1941 |
QSKIP("InterBase specific test", SkipSingle); |
|
1942 |
return; |
|
1943 |
} |
|
1944 |
||
1945 |
QString procName = qTableName("qtest_proc2"); |
|
1946 |
||
1947 |
QSqlQuery q(db); |
|
1948 |
q.exec(QString("drop procedure %1").arg(procName)); |
|
1949 |
QVERIFY_SQL(q, exec("CREATE PROCEDURE " + procName + " (" |
|
1950 |
"\nABC INTEGER)" |
|
1951 |
"\nRETURNS (" |
|
1952 |
"\nRESULT INTEGER)" |
|
1953 |
"\nAS" |
|
1954 |
"\nbegin" |
|
1955 |
"\nRESULT = 10 * ABC;" |
|
1956 |
"\nsuspend;" |
|
1957 |
"\nend")); |
|
1958 |
||
1959 |
// Interbase procedures can be executed in two ways: EXECUTE PROCEDURE or SELECT |
|
1960 |
QVERIFY_SQL(q, exec(QString("execute procedure %1(123)").arg(procName))); |
|
1961 |
QVERIFY_SQL(q, next()); |
|
1962 |
QCOMPARE(q.value(0).toInt(), 1230); |
|
1963 |
QVERIFY_SQL(q, exec(QString("select result from %1(456)").arg(procName))); |
|
1964 |
QVERIFY_SQL(q, next()); |
|
1965 |
QCOMPARE(q.value(0).toInt(), 4560); |
|
1966 |
QVERIFY_SQL(q, prepare(QLatin1String("execute procedure ")+procName+QLatin1String("(?)"))); |
|
1967 |
q.bindValue(0, 123); |
|
1968 |
QVERIFY_SQL(q, exec()); |
|
1969 |
QVERIFY_SQL(q, next()); |
|
1970 |
QCOMPARE(q.value(0).toInt(), 1230); |
|
1971 |
q.bindValue(0, 456); |
|
1972 |
QVERIFY_SQL(q, exec()); |
|
1973 |
QVERIFY_SQL(q, next()); |
|
1974 |
QCOMPARE(q.value(0).toInt(), 4560); |
|
1975 |
||
1976 |
q.exec(QString("drop procedure %1").arg(procName)); |
|
1977 |
} |
|
1978 |
||
1979 |
void tst_QSqlDatabase::formatValueTrimStrings() |
|
1980 |
{ |
|
1981 |
QFETCH(QString, dbName); |
|
1982 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1983 |
CHECK_DATABASE(db); |
|
1984 |
||
1985 |
QSqlQuery q(db); |
|
1986 |
||
1987 |
QVERIFY_SQL(q, exec(QString("INSERT INTO %1 (id, t_varchar, t_char) values (50, 'Trim Test ', 'Trim Test 2 ')").arg(qTableName("qtest")))); |
|
1988 |
QVERIFY_SQL(q, exec(QString("INSERT INTO %1 (id, t_varchar, t_char) values (51, 'TrimTest', 'Trim Test 2')").arg(qTableName("qtest")))); |
|
1989 |
QVERIFY_SQL(q, exec(QString("INSERT INTO %1 (id, t_varchar, t_char) values (52, ' ', ' ')").arg(qTableName("qtest")))); |
|
1990 |
||
1991 |
QVERIFY_SQL(q, exec(QString("SELECT t_varchar, t_char FROM %1 WHERE id >= 50 AND id <= 52 ORDER BY id").arg(qTableName("qtest")))); |
|
1992 |
||
1993 |
QVERIFY_SQL(q, next()); |
|
1994 |
||
1995 |
QCOMPARE(db.driver()->formatValue(q.record().field(0), true), QString("'Trim Test'")); |
|
1996 |
QCOMPARE(db.driver()->formatValue(q.record().field(1), true), QString("'Trim Test 2'")); |
|
1997 |
||
1998 |
QVERIFY_SQL(q, next()); |
|
1999 |
QCOMPARE(db.driver()->formatValue(q.record().field(0), true), QString("'TrimTest'")); |
|
2000 |
QCOMPARE(db.driver()->formatValue(q.record().field(1), true), QString("'Trim Test 2'")); |
|
2001 |
||
2002 |
QVERIFY_SQL(q, next()); |
|
2003 |
QCOMPARE(db.driver()->formatValue(q.record().field(0), true), QString("''")); |
|
2004 |
QCOMPARE(db.driver()->formatValue(q.record().field(1), true), QString("''")); |
|
2005 |
||
2006 |
} |
|
2007 |
||
2008 |
void tst_QSqlDatabase::odbc_reopenDatabase() |
|
2009 |
{ |
|
2010 |
QFETCH(QString, dbName); |
|
2011 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2012 |
CHECK_DATABASE(db); |
|
2013 |
||
2014 |
QSqlQuery q(db); |
|
2015 |
QVERIFY_SQL(q, exec("SELECT * from " + qTableName("qtest"))); |
|
2016 |
QVERIFY_SQL(q, next()); |
|
2017 |
db.open(); |
|
2018 |
QVERIFY_SQL(q, exec("SELECT * from " + qTableName("qtest"))); |
|
2019 |
QVERIFY_SQL(q, next()); |
|
2020 |
db.open(); |
|
2021 |
} |
|
2022 |
||
2023 |
void tst_QSqlDatabase::odbc_bindBoolean() |
|
2024 |
{ |
|
2025 |
QFETCH(QString, dbName); |
|
2026 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2027 |
CHECK_DATABASE(db); |
|
2028 |
||
2029 |
if (tst_Databases::isMySQL(db)) { |
|
2030 |
QSKIP("MySql has inconsistent behaviour of bit field type across versions.", SkipSingle); |
|
2031 |
return; |
|
2032 |
} |
|
2033 |
||
2034 |
QSqlQuery q(db); |
|
2035 |
QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("qtestBindBool") + "(id int, boolvalue bit)")); |
|
2036 |
||
2037 |
// Bind and insert |
|
2038 |
QVERIFY_SQL(q, prepare("INSERT INTO " + qTableName("qtestBindBool") + " VALUES(?, ?)")); |
|
2039 |
q.bindValue(0, 1); |
|
2040 |
q.bindValue(1, true); |
|
2041 |
QVERIFY_SQL(q, exec()); |
|
2042 |
q.bindValue(0, 2); |
|
2043 |
q.bindValue(1, false); |
|
2044 |
QVERIFY_SQL(q, exec()); |
|
2045 |
||
2046 |
// Retrive |
|
2047 |
QVERIFY_SQL(q, exec("SELECT id, boolvalue FROM " + qTableName("qtestBindBool") + " ORDER BY id")); |
|
2048 |
QVERIFY_SQL(q, next()); |
|
2049 |
QCOMPARE(q.value(0).toInt(), 1); |
|
2050 |
QCOMPARE(q.value(1).toBool(), true); |
|
2051 |
QVERIFY_SQL(q, next()); |
|
2052 |
QCOMPARE(q.value(0).toInt(), 2); |
|
2053 |
QCOMPARE(q.value(1).toBool(), false); |
|
2054 |
} |
|
2055 |
||
2056 |
void tst_QSqlDatabase::odbc_testqGetString() |
|
2057 |
{ |
|
2058 |
QFETCH(QString, dbName); |
|
2059 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2060 |
CHECK_DATABASE(db); |
|
2061 |
||
2062 |
QSqlQuery q(db); |
|
2063 |
if (tst_Databases::isSqlServer(db)) |
|
2064 |
QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("testqGetString") + "(id int, vcvalue varchar(MAX))")); |
|
2065 |
else if(tst_Databases::isMSAccess(db)) |
|
2066 |
QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("testqGetString") + "(id int, vcvalue memo)")); |
|
2067 |
else |
|
2068 |
QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("testqGetString") + "(id int, vcvalue varchar(65538))")); |
|
2069 |
||
2070 |
QString largeString; |
|
2071 |
largeString.fill('A', 65536); |
|
2072 |
||
2073 |
// Bind and insert |
|
2074 |
QVERIFY_SQL(q, prepare("INSERT INTO " + qTableName("testqGetString") + " VALUES(?, ?)")); |
|
2075 |
q.bindValue(0, 1); |
|
2076 |
q.bindValue(1, largeString); |
|
2077 |
QVERIFY_SQL(q, exec()); |
|
2078 |
q.bindValue(0, 2); |
|
2079 |
q.bindValue(1, largeString+QLatin1Char('B')); |
|
2080 |
QVERIFY_SQL(q, exec()); |
|
2081 |
q.bindValue(0, 3); |
|
2082 |
q.bindValue(1, largeString+QLatin1Char('B')+QLatin1Char('C')); |
|
2083 |
QVERIFY_SQL(q, exec()); |
|
2084 |
||
2085 |
// Retrive |
|
2086 |
QVERIFY_SQL(q, exec("SELECT id, vcvalue FROM " + qTableName("testqGetString") + " ORDER BY id")); |
|
2087 |
QVERIFY_SQL(q, next()); |
|
2088 |
QCOMPARE(q.value(0).toInt(), 1); |
|
2089 |
QCOMPARE(q.value(1).toString().length(), 65536); |
|
2090 |
QVERIFY_SQL(q, next()); |
|
2091 |
QCOMPARE(q.value(0).toInt(), 2); |
|
2092 |
QCOMPARE(q.value(1).toString().length(), 65537); |
|
2093 |
QVERIFY_SQL(q, next()); |
|
2094 |
QCOMPARE(q.value(0).toInt(), 3); |
|
2095 |
QCOMPARE(q.value(1).toString().length(), 65538); |
|
2096 |
} |
|
2097 |
||
2098 |
||
2099 |
void tst_QSqlDatabase::mysql_multiselect() |
|
2100 |
{ |
|
2101 |
QFETCH(QString, dbName); |
|
2102 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2103 |
CHECK_DATABASE(db); |
|
2104 |
||
2105 |
QSqlQuery q(db); |
|
2106 |
QString version=tst_Databases::getMySqlVersion( db ); |
|
2107 |
double ver=version.section(QChar::fromLatin1('.'),0,1).toDouble(); |
|
2108 |
if (ver < 4.1) |
|
2109 |
QSKIP("Test requires MySQL >= 4.1", SkipSingle); |
|
2110 |
||
2111 |
QVERIFY_SQL(q, exec("SELECT * FROM " + qTableName("qtest") + "; SELECT * FROM " + qTableName("qtest"))); |
|
2112 |
QVERIFY_SQL(q, next()); |
|
2113 |
QVERIFY_SQL(q, exec("SELECT * FROM " + qTableName("qtest") + "; SELECT * FROM " + qTableName("qtest"))); |
|
2114 |
QVERIFY_SQL(q, next()); |
|
2115 |
QVERIFY_SQL(q, exec("SELECT * FROM " + qTableName("qtest"))); |
|
2116 |
} |
|
2117 |
||
2118 |
void tst_QSqlDatabase::ibase_useCustomCharset() |
|
2119 |
{ |
|
2120 |
QFETCH(QString, dbName); |
|
2121 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2122 |
CHECK_DATABASE(db); |
|
2123 |
QString nonlatin1string("��"); |
|
2124 |
||
2125 |
db.close(); |
|
2126 |
db.setConnectOptions("ISC_DPB_LC_CTYPE=Latin1"); |
|
2127 |
db.open(); |
|
2128 |
||
2129 |
QString tableName = qTableName("latin1table"); |
|
2130 |
||
2131 |
QSqlQuery q(db); |
|
2132 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(text VARCHAR(6) CHARACTER SET Latin1)").arg(tableName))); |
|
2133 |
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES(?)").arg(tableName))); |
|
2134 |
q.addBindValue(nonlatin1string); |
|
2135 |
QVERIFY_SQL(q, exec()); |
|
2136 |
QVERIFY_SQL(q, exec(QString("SELECT text FROM %1").arg(tableName))); |
|
2137 |
QVERIFY_SQL(q, next()); |
|
2138 |
QCOMPARE(toHex(q.value(0).toString()), toHex(nonlatin1string)); |
|
2139 |
} |
|
2140 |
||
2141 |
void tst_QSqlDatabase::oci_serverDetach() |
|
2142 |
{ |
|
2143 |
QFETCH(QString, dbName); |
|
2144 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2145 |
CHECK_DATABASE(db); |
|
2146 |
||
2147 |
for (int i = 0; i < 2; i++) { |
|
2148 |
db.close(); |
|
2149 |
if (db.open()) { |
|
2150 |
QSqlQuery query(db); |
|
2151 |
query.exec("SELECT 1 FROM DUAL"); |
|
2152 |
db.close(); |
|
2153 |
} else { |
|
2154 |
QFAIL(tst_Databases::printError(db.lastError(), db)); |
|
2155 |
} |
|
2156 |
} |
|
2157 |
if(!db.open()) |
|
2158 |
qFatal(tst_Databases::printError(db.lastError(), db)); |
|
2159 |
} |
|
2160 |
||
2161 |
void tst_QSqlDatabase::oci_xmltypeSupport() |
|
2162 |
{ |
|
2163 |
QFETCH(QString, dbName); |
|
2164 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2165 |
CHECK_DATABASE(db); |
|
2166 |
||
2167 |
QString tableName = qTableName("qtest_xmltype"); |
|
2168 |
QString xml("<?xml version=\"1.0\"?><TABLE_NAME>MY_TABLE</TABLE_NAME>"); |
|
2169 |
QSqlQuery q(db); |
|
2170 |
||
2171 |
// Embedding the XML in the statement |
|
2172 |
if(!q.exec(QString("CREATE TABLE %1(xmldata xmltype)").arg(tableName))) |
|
2173 |
QSKIP("This test requries xml type support", SkipSingle); |
|
2174 |
QVERIFY_SQL(q, exec(QString("INSERT INTO %1 values('%2')").arg(tableName).arg(xml))); |
|
2175 |
QVERIFY_SQL(q, exec(QString("SELECT a.xmldata.getStringVal() FROM %1 a").arg(tableName))); |
|
2176 |
QVERIFY_SQL(q, last()); |
|
2177 |
QCOMPARE(q.value(0).toString(), xml); |
|
2178 |
||
2179 |
// Binding the XML with a prepared statement |
|
2180 |
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 values(?)").arg(tableName))); |
|
2181 |
q.addBindValue(xml); |
|
2182 |
QVERIFY_SQL(q, exec()); |
|
2183 |
QVERIFY_SQL(q, exec(QString("SELECT a.xmldata.getStringVal() FROM %1 a").arg(tableName))); |
|
2184 |
QVERIFY_SQL(q, last()); |
|
2185 |
QCOMPARE(q.value(0).toString(), xml); |
|
2186 |
} |
|
2187 |
||
2188 |
||
2189 |
void tst_QSqlDatabase::oci_fieldLength() |
|
2190 |
{ |
|
2191 |
QFETCH(QString, dbName); |
|
2192 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2193 |
CHECK_DATABASE(db); |
|
2194 |
||
2195 |
QString tableName = qTableName("qtest"); |
|
2196 |
QSqlQuery q(db); |
|
2197 |
||
2198 |
QVERIFY_SQL(q, exec(QString("SELECT t_varchar, t_char FROM %1").arg(tableName))); |
|
2199 |
QVERIFY_SQL(q, next()); |
|
2200 |
QCOMPARE(q.record().field(0).length(), 40); |
|
2201 |
QCOMPARE(q.record().field(1).length(), 40); |
|
2202 |
} |
|
2203 |
||
2204 |
void tst_QSqlDatabase::oci_synonymstest() |
|
2205 |
{ |
|
2206 |
QFETCH(QString, dbName); |
|
2207 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2208 |
CHECK_DATABASE(db); |
|
2209 |
||
2210 |
QSqlQuery q(db); |
|
2211 |
QString creator(qTableName("CREATOR")), appuser(qTableName("APPUSER")), table1(qTableName("TABLE1")); |
|
2212 |
// QVERIFY_SQL(q, exec("drop public synonym "+table1)); |
|
2213 |
QVERIFY_SQL(q, exec(QString("create user %1 identified by %2 default tablespace users temporary tablespace temp").arg(creator).arg(creator))); |
|
2214 |
QVERIFY_SQL(q, exec(QString("grant CONNECT to %1").arg(creator))); |
|
2215 |
QVERIFY_SQL(q, exec(QString("grant RESOURCE to %1").arg(creator))); |
|
2216 |
QSqlDatabase db2=db.cloneDatabase(db, QLatin1String("oci_synonymstest")); |
|
2217 |
db2.close(); |
|
2218 |
QVERIFY_SQL(db2, open(creator,creator)); |
|
2219 |
QSqlQuery q2(db2); |
|
2220 |
QVERIFY_SQL(q2, exec(QString("create table %1(id int primary key)").arg(table1))); |
|
2221 |
QVERIFY_SQL(q, exec(QString("create user %1 identified by %2 default tablespace users temporary tablespace temp").arg(appuser).arg(appuser))); |
|
2222 |
QVERIFY_SQL(q, exec(QString("grant CREATE ANY SYNONYM to %1").arg(appuser))); |
|
2223 |
QVERIFY_SQL(q, exec(QString("grant CONNECT to %1").arg(appuser))); |
|
2224 |
QVERIFY_SQL(q2, exec(QString("grant select, insert, update, delete on %1 to %2").arg(table1).arg(appuser))); |
|
2225 |
QSqlDatabase db3=db.cloneDatabase(db, QLatin1String("oci_synonymstest2")); |
|
2226 |
db3.close(); |
|
2227 |
QVERIFY_SQL(db3, open(appuser,appuser)); |
|
2228 |
QSqlQuery q3(db3); |
|
2229 |
QVERIFY_SQL(q3, exec("create synonym "+appuser+'.'+qTableName("synonyms")+" for "+creator+'.'+table1)); |
|
2230 |
QVERIFY_SQL(db3, tables().filter(qTableName("synonyms"), Qt::CaseInsensitive).count() >= 1); |
|
2231 |
} |
|
2232 |
||
2233 |
||
2234 |
// This test isn't really necessary as SQL_GUID / uniqueidentifier is |
|
2235 |
// already tested in recordSQLServer(). |
|
2236 |
void tst_QSqlDatabase::odbc_uniqueidentifier() |
|
2237 |
{ |
|
2238 |
QFETCH(QString, dbName); |
|
2239 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2240 |
CHECK_DATABASE(db); |
|
2241 |
if (!tst_Databases::isSqlServer(db)) { |
|
2242 |
QSKIP("SQL Server (ODBC) specific test", SkipSingle); |
|
2243 |
return; |
|
2244 |
} |
|
2245 |
||
2246 |
QString tableName = qTableName("qtest_sqlguid"); |
|
2247 |
QString guid = QString("AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"); |
|
2248 |
QString invalidGuid = QString("GAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"); |
|
2249 |
||
2250 |
QSqlQuery q(db); |
|
2251 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(id uniqueidentifier)").arg(tableName))); |
|
2252 |
||
2253 |
q.prepare(QString("INSERT INTO %1 VALUES(?)").arg(tableName));; |
|
2254 |
q.addBindValue(guid); |
|
2255 |
QVERIFY_SQL(q, exec()); |
|
2256 |
||
2257 |
q.addBindValue(invalidGuid); |
|
2258 |
QEXPECT_FAIL("", "The GUID string is required to be correctly formated!", |
|
2259 |
Continue); |
|
2260 |
QVERIFY_SQL(q, exec()); |
|
2261 |
||
2262 |
QVERIFY_SQL(q, exec(QString("SELECT id FROM %1").arg(tableName))); |
|
2263 |
QVERIFY_SQL(q, next()); |
|
2264 |
QCOMPARE(q.value(0).toString(), guid); |
|
2265 |
} |
|
2266 |
||
2267 |
void tst_QSqlDatabase::getConnectionName() |
|
2268 |
{ |
|
2269 |
QFETCH(QString, dbName); |
|
2270 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2271 |
CHECK_DATABASE(db); |
|
2272 |
||
2273 |
QCOMPARE(db.connectionName(), dbName); |
|
2274 |
QSqlDatabase clone = QSqlDatabase::cloneDatabase(db, "clonedDatabase"); |
|
2275 |
QCOMPARE(clone.connectionName(), QString("clonedDatabase")); |
|
2276 |
QTest::ignoreMessage(QtWarningMsg, "QSqlDatabasePrivate::removeDatabase: " |
|
2277 |
"connection 'clonedDatabase' is still in use, all queries will cease to work."); |
|
2278 |
QSqlDatabase::removeDatabase("clonedDatabase"); |
|
2279 |
QCOMPARE(clone.connectionName(), QString()); |
|
2280 |
QCOMPARE(db.connectionName(), dbName); |
|
2281 |
} |
|
2282 |
||
2283 |
void tst_QSqlDatabase::odbc_uintfield() |
|
2284 |
{ |
|
2285 |
QFETCH(QString, dbName); |
|
2286 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2287 |
CHECK_DATABASE(db); |
|
2288 |
||
2289 |
QString tableName = qTableName("uint_table"); |
|
2290 |
unsigned int val = 4294967295U; |
|
2291 |
||
2292 |
QSqlQuery q(db); |
|
2293 |
if ( tst_Databases::isMSAccess( db ) ) |
|
2294 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(num number)").arg(tableName))); |
|
2295 |
else |
|
2296 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(num numeric(10))").arg(tableName))); |
|
2297 |
q.prepare(QString("INSERT INTO %1 VALUES(?)").arg(tableName)); |
|
2298 |
q.addBindValue(val); |
|
2299 |
QVERIFY_SQL(q, exec()); |
|
2300 |
||
2301 |
q.exec(QString("SELECT num FROM %1").arg(tableName)); |
|
2302 |
if (q.next()) |
|
2303 |
QCOMPARE(q.value(0).toUInt(), val); |
|
2304 |
} |
|
2305 |
||
2306 |
void tst_QSqlDatabase::eventNotification() |
|
2307 |
{ |
|
2308 |
QFETCH(QString, dbName); |
|
2309 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2310 |
CHECK_DATABASE(db); |
|
2311 |
||
2312 |
QSqlDriver *driver = db.driver(); |
|
2313 |
if (!driver->hasFeature(QSqlDriver::EventNotifications)) |
|
2314 |
QSKIP("DBMS doesn't support event notifications", SkipSingle); |
|
2315 |
||
2316 |
// Not subscribed to any events yet |
|
2317 |
QCOMPARE(driver->subscribedToNotifications().size(), 0); |
|
2318 |
||
2319 |
// Subscribe to "event_foo" |
|
2320 |
QVERIFY_SQL(*driver, subscribeToNotification(QLatin1String("event_foo"))); |
|
2321 |
QCOMPARE(driver->subscribedToNotifications().size(), 1); |
|
2322 |
QVERIFY(driver->subscribedToNotifications().contains("event_foo")); |
|
2323 |
||
2324 |
// Can't subscribe to the same event multiple times |
|
2325 |
QVERIFY2(!driver->subscribeToNotification(QLatin1String("event_foo")), "Shouldn't be able to subscribe to event_foo twice"); |
|
2326 |
QCOMPARE(driver->subscribedToNotifications().size(), 1); |
|
2327 |
||
2328 |
// Unsubscribe from "event_foo" |
|
2329 |
QVERIFY_SQL(*driver, unsubscribeFromNotification(QLatin1String("event_foo"))); |
|
2330 |
QCOMPARE(driver->subscribedToNotifications().size(), 0); |
|
2331 |
||
2332 |
// Re-subscribing to "event_foo" now is allowed |
|
2333 |
QVERIFY_SQL(*driver, subscribeToNotification(QLatin1String("event_foo"))); |
|
2334 |
QCOMPARE(driver->subscribedToNotifications().size(), 1); |
|
2335 |
||
2336 |
// closing the connection causes automatically unsubscription from all events |
|
2337 |
db.close(); |
|
2338 |
QCOMPARE(driver->subscribedToNotifications().size(), 0); |
|
2339 |
||
2340 |
// Can't subscribe to anything while database is closed |
|
2341 |
QVERIFY2(!driver->subscribeToNotification(QLatin1String("event_foo")), "Shouldn't be able to subscribe to event_foo"); |
|
2342 |
QCOMPARE(driver->subscribedToNotifications().size(), 0); |
|
2343 |
||
2344 |
db.open(); |
|
2345 |
} |
|
2346 |
||
2347 |
void tst_QSqlDatabase::eventNotificationIBase() |
|
2348 |
{ |
|
2349 |
QFETCH(QString, dbName); |
|
2350 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2351 |
CHECK_DATABASE(db); |
|
2352 |
||
2353 |
QString procedureName = qTableName("posteventProc"); |
|
2354 |
QSqlDriver *driver=db.driver(); |
|
2355 |
QVERIFY_SQL(*driver, subscribeToNotification(procedureName)); |
|
2356 |
QTest::qWait(300); // Interbase needs some time to call the driver callback. |
|
2357 |
||
2358 |
db.transaction(); // InterBase events are posted from within transactions. |
|
2359 |
QSqlQuery q(db); |
|
2360 |
q.exec(QString("DROP PROCEDURE %1").arg(procedureName)); |
|
2361 |
q.exec(QString("CREATE PROCEDURE %1\nAS BEGIN\nPOST_EVENT '%1';\nEND;").arg(procedureName)); |
|
2362 |
q.exec(QString("EXECUTE PROCEDURE %1").arg(procedureName)); |
|
2363 |
QSignalSpy spy(driver, SIGNAL(notification(const QString&))); |
|
2364 |
db.commit(); // No notifications are posted until the transaction is committed. |
|
2365 |
QTest::qWait(300); // Interbase needs some time to post the notification and call the driver callback. |
|
2366 |
// This happends from another thread, and we have to process events in order for the |
|
2367 |
// event handler in the driver to be executed and emit the notification signal. |
|
2368 |
||
2369 |
QCOMPARE(spy.count(), 1); |
|
2370 |
QList<QVariant> arguments = spy.takeFirst(); |
|
2371 |
QVERIFY(arguments.at(0).toString() == procedureName); |
|
2372 |
QVERIFY_SQL(*driver, unsubscribeFromNotification(procedureName)); |
|
2373 |
q.exec(QString("DROP PROCEDURE %1").arg(procedureName)); |
|
2374 |
} |
|
2375 |
||
2376 |
void tst_QSqlDatabase::eventNotificationPSQL() |
|
2377 |
{ |
|
2378 |
QFETCH(QString, dbName); |
|
2379 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2380 |
CHECK_DATABASE(db); |
|
2381 |
||
2382 |
#if defined(Q_OS_LINUX) |
|
2383 |
QSKIP( "Event support doesn't work on linux", SkipAll ); |
|
2384 |
#endif |
|
2385 |
||
2386 |
QSqlQuery query(db); |
|
2387 |
QString procedureName = qTableName("posteventProc"); |
|
2388 |
||
2389 |
QSqlDriver &driver=*(db.driver()); |
|
2390 |
QVERIFY_SQL(driver, subscribeToNotification(procedureName)); |
|
2391 |
QSignalSpy spy(db.driver(), SIGNAL(notification(const QString&))); |
|
2392 |
query.exec(QString("NOTIFY \"%1\"").arg(procedureName)); |
|
2393 |
QCoreApplication::processEvents(); |
|
2394 |
QCOMPARE(spy.count(), 1); |
|
2395 |
QList<QVariant> arguments = spy.takeFirst(); |
|
2396 |
QVERIFY(arguments.at(0).toString() == procedureName); |
|
2397 |
QVERIFY_SQL(driver, unsubscribeFromNotification(procedureName)); |
|
2398 |
} |
|
2399 |
||
2400 |
void tst_QSqlDatabase::sqlite_bindAndFetchUInt() |
|
2401 |
{ |
|
2402 |
QFETCH(QString, dbName); |
|
2403 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2404 |
CHECK_DATABASE(db); |
|
2405 |
if (db.driverName().startsWith("QSQLITE2")) { |
|
2406 |
QSKIP("SQLite3 specific test", SkipSingle); |
|
2407 |
return; |
|
2408 |
} |
|
2409 |
||
2410 |
QSqlQuery q(db); |
|
2411 |
QString tableName = qTableName("uint_test"); |
|
2412 |
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(uint_field UNSIGNED INTEGER)").arg(tableName))); |
|
2413 |
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES(?)").arg(tableName))); |
|
2414 |
q.addBindValue(4000000000U); |
|
2415 |
QVERIFY_SQL(q, exec()); |
|
2416 |
QVERIFY_SQL(q, exec(QString("SELECT uint_field FROM %1").arg(tableName))); |
|
2417 |
QVERIFY_SQL(q, next()); |
|
2418 |
||
2419 |
// All integers in SQLite are signed, so even though we bound the value |
|
2420 |
// as an UInt it will come back as a LongLong |
|
2421 |
QCOMPARE(q.value(0).type(), QVariant::LongLong); |
|
2422 |
QCOMPARE(q.value(0).toUInt(), 4000000000U); |
|
2423 |
} |
|
2424 |
||
2425 |
void tst_QSqlDatabase::db2_valueCacheUpdate() |
|
2426 |
{ |
|
2427 |
QFETCH(QString, dbName); |
|
2428 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2429 |
CHECK_DATABASE(db); |
|
2430 |
||
2431 |
QString tableName = qTableName("qtest"); |
|
2432 |
QSqlQuery q(db); |
|
2433 |
q.exec(QString("SELECT id, t_varchar, t_char, t_numeric FROM %1").arg(tableName)); |
|
2434 |
q.next(); |
|
2435 |
QVariant c4 = q.value(3); |
|
2436 |
QVariant c3 = q.value(2); |
|
2437 |
QVariant c2 = q.value(1); |
|
2438 |
QVariant c1 = q.value(0); |
|
2439 |
QCOMPARE(c4.toString(), q.value(3).toString()); |
|
2440 |
QCOMPARE(c3.toString(), q.value(2).toString()); |
|
2441 |
QCOMPARE(c2.toString(), q.value(1).toString()); |
|
2442 |
QCOMPARE(c1.toString(), q.value(0).toString()); |
|
2443 |
} |
|
2444 |
||
2445 |
void tst_QSqlDatabase::sqlStatementUseIsNull_189093() |
|
2446 |
{ |
|
2447 |
// NULL = NULL is unknown, the sqlStatment must use IS NULL |
|
2448 |
QFETCH(QString, dbName); |
|
2449 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2450 |
CHECK_DATABASE(db); |
|
2451 |
||
2452 |
// select a record with NULL value |
|
2453 |
QSqlQuery q(QString::null, db); |
|
2454 |
QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 4")); |
|
2455 |
QVERIFY_SQL(q, next()); |
|
2456 |
||
2457 |
QSqlDriver *driver = db.driver(); |
|
2458 |
QVERIFY(driver); |
|
2459 |
||
2460 |
QString preparedStatment = driver->sqlStatement(QSqlDriver::WhereStatement, QString("qtest"), q.record(), true); |
|
2461 |
QCOMPARE(preparedStatment.count("IS NULL", Qt::CaseInsensitive), 2); |
|
2462 |
||
2463 |
QString statment = driver->sqlStatement(QSqlDriver::WhereStatement, QString("qtest"), q.record(), false); |
|
2464 |
QCOMPARE(statment.count("IS NULL", Qt::CaseInsensitive), 2); |
|
2465 |
} |
|
2466 |
||
2467 |
void tst_QSqlDatabase::mysql_savepointtest() |
|
2468 |
{ |
|
2469 |
QFETCH(QString, dbName); |
|
2470 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2471 |
CHECK_DATABASE(db); |
|
2472 |
if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 1 ).toDouble()<4.1 ) |
|
2473 |
QSKIP( "Test requires MySQL >= 4.1", SkipSingle ); |
|
2474 |
||
2475 |
QSqlQuery q(db); |
|
2476 |
QVERIFY_SQL(q, exec("begin")); |
|
2477 |
QVERIFY_SQL(q, exec("insert into "+qTableName("qtest")+" VALUES (54, 'foo', 'foo', 54.54)")); |
|
2478 |
QVERIFY_SQL(q, exec("savepoint foo")); |
|
2479 |
} |
|
2480 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2481 |
void tst_QSqlDatabase::oci_tables() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2482 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2483 |
QFETCH(QString, dbName); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2484 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2485 |
CHECK_DATABASE(db); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2486 |
QSqlQuery q(db); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2487 |
QString systemTableName("system."+qTableName("mypassword")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2488 |
QVERIFY_SQL(q, exec("CREATE TABLE "+systemTableName+"(name VARCHAR(20))")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2489 |
QVERIFY(!db.tables().contains(systemTableName.toUpper())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2490 |
QVERIFY(db.tables(QSql::SystemTables).contains(systemTableName.toUpper())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2491 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2492 |
|
0 | 2493 |
QTEST_MAIN(tst_QSqlDatabase) |
2494 |
#include "tst_qsqldatabase.moc" |