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 |
#include <QtTest/QtTest> |
|
43 |
#include <QtSql/QtSql> |
|
44 |
||
45 |
#include "../qsqldatabase/tst_databases.h" |
|
46 |
||
47 |
//TESTED_FILES= |
|
48 |
||
49 |
class tst_QSqlQuery : public QObject |
|
50 |
{ |
|
51 |
Q_OBJECT |
|
52 |
||
53 |
public: |
|
54 |
tst_QSqlQuery(); |
|
55 |
virtual ~tst_QSqlQuery(); |
|
56 |
||
57 |
public slots: |
|
58 |
void initTestCase(); |
|
59 |
void cleanupTestCase(); |
|
60 |
void init(); |
|
61 |
void cleanup(); |
|
62 |
||
63 |
private slots: |
|
64 |
void value_data() { generic_data(); } |
|
65 |
void value(); |
|
66 |
void isValid_data() { generic_data(); } |
|
67 |
void isValid(); |
|
68 |
void isActive_data() { generic_data(); } |
|
69 |
void isActive(); |
|
70 |
void isSelect_data() { generic_data(); } |
|
71 |
void isSelect(); |
|
72 |
void numRowsAffected_data() { generic_data(); } |
|
73 |
void numRowsAffected(); |
|
74 |
void size_data() { generic_data(); } |
|
75 |
void size(); |
|
76 |
void isNull_data() { generic_data(); } |
|
77 |
void isNull(); |
|
78 |
void query_exec_data() { generic_data(); } |
|
79 |
void query_exec(); |
|
80 |
void execErrorRecovery_data() { generic_data(); } |
|
81 |
void execErrorRecovery(); |
|
82 |
void first_data() { generic_data(); } |
|
83 |
void first(); |
|
84 |
void next_data() { generic_data(); } |
|
85 |
void next(); |
|
86 |
void prev_data() { generic_data(); } |
|
87 |
void prev(); |
|
88 |
void last_data() { generic_data(); } |
|
89 |
void last(); |
|
90 |
void seek_data() { generic_data(); } |
|
91 |
void seek(); |
|
92 |
void transaction_data() { generic_data(); } |
|
93 |
void transaction(); |
|
94 |
void record_data() { generic_data(); } |
|
95 |
void record(); |
|
96 |
void record_sqlite_data() { generic_data("QSQLITE"); } |
|
97 |
void record_sqlite(); |
|
98 |
void finish_data() { generic_data(); } |
|
99 |
void finish(); |
|
100 |
void sqlite_finish_data() { generic_data(); } |
|
101 |
void sqlite_finish(); |
|
102 |
void nextResult_data() { generic_data(); } |
|
103 |
void nextResult(); |
|
104 |
||
105 |
// forwardOnly mode need special treatment |
|
106 |
void forwardOnly_data() { generic_data(); } |
|
107 |
void forwardOnly(); |
|
108 |
||
109 |
// bug specific tests |
|
110 |
void bitField_data() {generic_data("QTDS"); } |
|
111 |
void bitField(); |
|
112 |
void nullBlob_data() { generic_data("QOCI"); } |
|
113 |
void nullBlob(); |
|
114 |
void blob_data() { generic_data(); } |
|
115 |
void blob(); |
|
116 |
void rawField_data() { generic_data("QOCI"); } |
|
117 |
void rawField(); |
|
118 |
void precision_data() { generic_data(); } |
|
119 |
void precision(); |
|
120 |
void nullResult_data() { generic_data(); } |
|
121 |
void nullResult(); |
|
122 |
void joins_data() { generic_data(); } |
|
123 |
void joins(); |
|
124 |
void outValues_data() { generic_data(); } |
|
125 |
void outValues(); |
|
126 |
void char1Select_data() { generic_data(); } |
|
127 |
void char1Select(); |
|
128 |
void char1SelectUnicode_data() { generic_data(); } |
|
129 |
void char1SelectUnicode(); |
|
130 |
void synonyms_data() { generic_data(); } |
|
131 |
void synonyms(); |
|
132 |
void oraOutValues_data() { generic_data("QOCI"); } |
|
133 |
void oraOutValues(); |
|
134 |
void mysqlOutValues_data() { generic_data("QMYSQL"); } |
|
135 |
void mysqlOutValues(); |
|
136 |
void oraClob_data() { generic_data("QOCI"); } |
|
137 |
void oraClob(); |
|
138 |
void oraLong_data() { generic_data("QOCI"); } |
|
139 |
void oraLong(); |
|
140 |
void outValuesDB2_data() { generic_data("QDB2"); } |
|
141 |
void outValuesDB2(); |
|
142 |
void storedProceduresIBase_data() {generic_data("QIBASE"); } |
|
143 |
void storedProceduresIBase(); |
|
144 |
void oraRowId_data() { generic_data("QOCI"); } |
|
145 |
void oraRowId(); |
|
146 |
void prepare_bind_exec_data() { generic_data(); } |
|
147 |
void prepare_bind_exec(); |
|
148 |
void prepared_select_data() { generic_data(); } |
|
149 |
void prepared_select(); |
|
150 |
void sqlServerLongStrings_data() { generic_data(); } |
|
151 |
void sqlServerLongStrings(); |
|
152 |
void invalidQuery_data() { generic_data(); } |
|
153 |
void invalidQuery(); |
|
154 |
void batchExec_data() { generic_data(); } |
|
155 |
void batchExec(); |
|
156 |
void oraArrayBind_data() { generic_data(); } |
|
157 |
void oraArrayBind(); |
|
158 |
void lastInsertId_data() { generic_data(); } |
|
159 |
void lastInsertId(); |
|
160 |
void lastQuery_data() { generic_data(); } |
|
161 |
void lastQuery(); |
|
162 |
void bindWithDoubleColonCastOperator_data() { generic_data(); } |
|
163 |
void bindWithDoubleColonCastOperator(); |
|
164 |
void queryOnInvalidDatabase_data() { generic_data(); } |
|
165 |
void queryOnInvalidDatabase(); |
|
166 |
void createQueryOnClosedDatabase_data() { generic_data(); } |
|
167 |
void createQueryOnClosedDatabase(); |
|
168 |
void seekForwardOnlyQuery_data() { generic_data(); } |
|
169 |
void seekForwardOnlyQuery(); |
|
170 |
void reExecutePreparedForwardOnlyQuery_data() { generic_data(); } |
|
171 |
void reExecutePreparedForwardOnlyQuery(); |
|
172 |
void blobsPreparedQuery_data() { generic_data(); } |
|
173 |
void blobsPreparedQuery(); |
|
174 |
void emptyTableNavigate_data() { generic_data(); } |
|
175 |
void emptyTableNavigate(); |
|
176 |
||
177 |
#ifdef NOT_READY_YET |
|
178 |
void task_229811(); |
|
179 |
void task_229811_data() { generic_data(); } |
|
180 |
void task_234422_data() { generic_data(); } |
|
181 |
void task_234422(); |
|
182 |
#endif |
|
183 |
void task_217003_data() { generic_data(); } |
|
184 |
void task_217003(); |
|
185 |
||
186 |
void task_250026_data() { generic_data("QODBC"); } |
|
187 |
void task_250026(); |
|
188 |
void task_205701_data() { generic_data("QMYSQL"); } |
|
189 |
void task_205701(); |
|
190 |
||
191 |
void task_233829_data() { generic_data("QPSQL"); } |
|
192 |
void task_233829(); |
|
193 |
||
194 |
void sqlServerReturn0_data() { generic_data(); } |
|
195 |
void sqlServerReturn0(); |
|
196 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
void QTBUG_551_data() { generic_data("QOCI"); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
void QTBUG_551(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
void QTBUG_5251_data() { generic_data("QPSQL"); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
void QTBUG_5251(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
void QTBUG_6421_data() { generic_data("QOCI"); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
203 |
void QTBUG_6421(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
void QTBUG_6618_data() { generic_data("QODBC"); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
205 |
void QTBUG_6618(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
|
0 | 207 |
private: |
208 |
// returns all database connections |
|
209 |
void generic_data(const QString &engine=QString()); |
|
210 |
void dropTestTables( QSqlDatabase db ); |
|
211 |
void createTestTables( QSqlDatabase db ); |
|
212 |
void populateTestTables( QSqlDatabase db ); |
|
213 |
||
214 |
tst_Databases dbs; |
|
215 |
}; |
|
216 |
||
217 |
tst_QSqlQuery::tst_QSqlQuery() |
|
218 |
{ |
|
219 |
} |
|
220 |
||
221 |
tst_QSqlQuery::~tst_QSqlQuery() |
|
222 |
{ |
|
223 |
} |
|
224 |
||
225 |
void tst_QSqlQuery::initTestCase() |
|
226 |
{ |
|
227 |
dbs.open(); |
|
228 |
||
229 |
for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) { |
|
230 |
QSqlDatabase db = QSqlDatabase::database(( *it ) ); |
|
231 |
CHECK_DATABASE( db ); |
|
232 |
dropTestTables( db ); //in case of leftovers |
|
233 |
createTestTables( db ); |
|
234 |
populateTestTables( db ); |
|
235 |
} |
|
236 |
} |
|
237 |
||
238 |
void tst_QSqlQuery::cleanupTestCase() |
|
239 |
{ |
|
240 |
for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) { |
|
241 |
QSqlDatabase db = QSqlDatabase::database(( *it ) ); |
|
242 |
CHECK_DATABASE( db ); |
|
243 |
dropTestTables( db ); |
|
244 |
} |
|
245 |
||
246 |
dbs.close(); |
|
247 |
} |
|
248 |
||
249 |
void tst_QSqlQuery::init() |
|
250 |
{ |
|
251 |
} |
|
252 |
||
253 |
void tst_QSqlQuery::cleanup() |
|
254 |
{ |
|
255 |
QFETCH( QString, dbName ); |
|
256 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
257 |
CHECK_DATABASE( db ); |
|
258 |
||
259 |
if ( QTest::currentTestFunction() == QLatin1String( "numRowsAffected" ) |
|
260 |
|| QTest::currentTestFunction() == QLatin1String( "transactions" ) |
|
261 |
|| QTest::currentTestFunction() == QLatin1String( "size" ) |
|
262 |
|| QTest::currentTestFunction() == QLatin1String( "isActive" ) |
|
263 |
|| QTest::currentTestFunction() == QLatin1String( "lastInsertId" ) ) { |
|
264 |
populateTestTables( db ); |
|
265 |
} |
|
266 |
||
267 |
if ( QTest::currentTestFailed() && ( db.driverName().startsWith( "QOCI" ) |
|
268 |
|| db.driverName().startsWith( "QODBC" ) ) ) { |
|
269 |
//since Oracle ODBC totally craps out on error, we init again |
|
270 |
db.close(); |
|
271 |
db.open(); |
|
272 |
} |
|
273 |
} |
|
274 |
||
275 |
void tst_QSqlQuery::generic_data(const QString& engine) |
|
276 |
{ |
|
277 |
if ( dbs.fillTestTable(engine) == 0 ) { |
|
278 |
if(engine.isEmpty()) |
|
279 |
QSKIP( "No database drivers are available in this Qt configuration", SkipAll ); |
|
280 |
else |
|
281 |
QSKIP( (QString("No database drivers of type %1 are available in this Qt configuration").arg(engine)).toLocal8Bit(), SkipAll ); |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) |
|
286 |
{ |
|
287 |
QStringList tablenames; |
|
288 |
// drop all the table in case a testcase failed |
|
289 |
tablenames << qTableName( "qtest" ) |
|
290 |
<< qTableName( "qtest_null" ) |
|
291 |
<< qTableName( "qtest_blob" ) |
|
292 |
<< qTableName( "qtest_bittest" ) |
|
293 |
<< qTableName( "qtest_nullblob" ) |
|
294 |
<< qTableName( "qtest_rawtest" ) |
|
295 |
<< qTableName( "qtest_precision" ) |
|
296 |
<< qTableName( "qtest_prepare" ) |
|
297 |
<< qTableName( "qtestj1" ) |
|
298 |
<< qTableName( "qtestj2" ) |
|
299 |
<< qTableName( "char1Select" ) |
|
300 |
<< qTableName( "char1SelectUnicode" ) |
|
301 |
<< qTableName( "qxmltest" ) |
|
302 |
<< qTableName( "qtest_exerr" ) |
|
303 |
<< qTableName( "qtest_empty" ) |
|
304 |
<< qTableName( "clobby" ) |
|
305 |
<< qTableName( "bindtest" ) |
|
306 |
<< qTableName( "more_results" ) |
|
307 |
<< qTableName( "blobstest" ) |
|
308 |
<< qTableName( "oraRowId" ) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
<< qTableName( "qtest_batch" ) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
310 |
<< qTableName(QLatin1String("bug6421")).toUpper(); |
0 | 311 |
|
312 |
if ( db.driverName().startsWith("QPSQL") ) |
|
313 |
tablenames << qTableName("task_233829"); |
|
314 |
||
315 |
if ( db.driverName().startsWith("QSQLITE") ) |
|
316 |
tablenames << qTableName( "record_sqlite" ); |
|
317 |
||
318 |
if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QOCI" ) ) |
|
319 |
tablenames << qTableName( "qtest_longstr" ); |
|
320 |
||
321 |
tablenames << qTableName( "qtest_lockedtable" ); |
|
322 |
||
323 |
tablenames << qTableName( "Planet" ); |
|
324 |
||
325 |
tablenames << qTableName( "task_250026" ); |
|
326 |
tablenames << qTableName( "task_234422" ); |
|
327 |
||
328 |
if (tst_Databases::isSqlServer( db )) { |
|
329 |
QSqlQuery q( db ); |
|
330 |
q.exec("DROP PROCEDURE " + qTableName("test141895_proc")); |
|
331 |
} |
|
332 |
||
333 |
tablenames << qTableName("test141895"); |
|
334 |
||
335 |
tst_Databases::safeDropTables( db, tablenames ); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
if ( db.driverName().startsWith( "QOCI" ) ) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
QSqlQuery q( db ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
q.exec( "DROP PACKAGE " + qTableName("pkg") ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
340 |
} |
0 | 341 |
} |
342 |
||
343 |
void tst_QSqlQuery::createTestTables( QSqlDatabase db ) |
|
344 |
{ |
|
345 |
QSqlQuery q( db ); |
|
346 |
||
347 |
if ( db.driverName().startsWith( "QMYSQL" ) ) |
|
348 |
// ### stupid workaround until we find a way to hardcode this |
|
349 |
// in the MySQL server startup script |
|
350 |
q.exec( "set table_type=innodb" ); |
|
351 |
else if(tst_Databases::isPostgreSQL(db)) |
|
352 |
QVERIFY_SQL( q, exec("set client_min_messages='warning'")); |
|
353 |
||
354 |
if(tst_Databases::isPostgreSQL(db)) |
|
355 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest" ) + " (id serial NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id)) WITH OIDS" ) ); |
|
356 |
else |
|
357 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest" ) + " (id int "+tst_Databases::autoFieldName(db) +" NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id))" ) ); |
|
358 |
||
359 |
if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QTDS" ) ) |
|
360 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_null" ) + " (id int null, t_varchar varchar(20) null)" ) ); |
|
361 |
else |
|
362 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_null" ) + " (id int, t_varchar varchar(20))" ) ); |
|
363 |
} |
|
364 |
||
365 |
void tst_QSqlQuery::populateTestTables( QSqlDatabase db ) |
|
366 |
{ |
|
367 |
QSqlQuery q( db ); |
|
368 |
q.exec( "delete from " + qTableName( "qtest" ) ); |
|
369 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (1, 'VarChar1', 'Char1')" ) ); |
|
370 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (2, 'VarChar2', 'Char2')" ) ); |
|
371 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (3, 'VarChar3', 'Char3')" ) ); |
|
372 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (4, 'VarChar4', 'Char4')" ) ); |
|
373 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (5, 'VarChar5', 'Char5')" ) ); |
|
374 |
||
375 |
q.exec( "delete from " + qTableName( "qtest_null" ) ); |
|
376 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_null" ) + " values (0, NULL)" ) ); |
|
377 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_null" ) + " values (1, 'n')" ) ); |
|
378 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_null" ) + " values (2, 'i')" ) ); |
|
379 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_null" ) + " values (3, NULL)" ) ); |
|
380 |
} |
|
381 |
||
382 |
// There were problems with char fields of size 1 |
|
383 |
void tst_QSqlQuery::char1Select() |
|
384 |
{ |
|
385 |
QFETCH( QString, dbName ); |
|
386 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
387 |
CHECK_DATABASE( db ); |
|
388 |
||
389 |
{ |
|
390 |
QSqlQuery q( db ); |
|
391 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "char1Select" ) + " (id char(1))" ) ); |
|
392 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "char1Select" ) + " values ('a')" ) ); |
|
393 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "char1Select" ) ) ); |
|
394 |
QVERIFY( q.next() ); |
|
395 |
||
396 |
if ( db.driverName().startsWith( "QIBASE" ) ) |
|
397 |
QCOMPARE( q.value( 0 ).toString().left( 1 ), QString( "a" ) ); |
|
398 |
else |
|
399 |
QCOMPARE( q.value( 0 ).toString(), QString( "a" ) ); |
|
400 |
||
401 |
QVERIFY( !q.next() ); |
|
402 |
} |
|
403 |
} |
|
404 |
||
405 |
void tst_QSqlQuery::char1SelectUnicode() |
|
406 |
{ |
|
407 |
QFETCH( QString, dbName ); |
|
408 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
409 |
CHECK_DATABASE( db ); |
|
410 |
||
411 |
if(db.driverName().startsWith("QDB2")) |
|
412 |
QSKIP("Needs someone with more Unicode knowledge than I have to fix", SkipSingle); |
|
413 |
||
414 |
if ( db.driver()->hasFeature( QSqlDriver::Unicode ) ) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
QString uniStr( QChar(0x0915) ); // DEVANAGARI LETTER KA |
0 | 416 |
QSqlQuery q( db ); |
417 |
||
418 |
if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) |
|
419 |
QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); |
|
420 |
||
421 |
QString createQuery; |
|
422 |
||
423 |
if ( tst_Databases::isSqlServer( db ) ) |
|
424 |
createQuery = "create table " + qTableName( "char1SelectUnicode" ) + "(id nchar(1))"; |
|
425 |
else if ( db.driverName().startsWith( "QDB2" ) |
|
426 |
|| db.driverName().startsWith( "QOCI" ) |
|
427 |
|| db.driverName().startsWith( "QPSQL" ) ) |
|
428 |
createQuery = "create table " + qTableName( "char1SelectUnicode" ) + " (id char(3))"; |
|
429 |
else if ( db.driverName().startsWith( "QIBASE" ) ) |
|
430 |
createQuery = "create table " + qTableName( "char1SelectUnicode" ) + |
|
431 |
" (id char(1) character set unicode_fss)"; |
|
432 |
else if ( db.driverName().startsWith( "QMYSQL" ) ) |
|
433 |
createQuery = "create table " + qTableName( "char1SelectUnicode" ) + " (id char(1)) " |
|
434 |
"default character set 'utf8'"; |
|
435 |
else |
|
436 |
createQuery = "create table " + qTableName( "char1SelectUnicode" ) + " (id char(1))"; |
|
437 |
||
438 |
QVERIFY_SQL( q, exec( createQuery ) ); |
|
439 |
||
440 |
QVERIFY_SQL( q, prepare( "insert into " + qTableName( "char1SelectUnicode" ) + " values(?)" ) ); |
|
441 |
||
442 |
q.bindValue( 0, uniStr ); |
|
443 |
||
444 |
QVERIFY_SQL( q, exec() ); |
|
445 |
||
446 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "char1SelectUnicode" ) ) ); |
|
447 |
||
448 |
QVERIFY( q.next() ); |
|
449 |
||
450 |
if ( !q.value( 0 ).toString().isEmpty() ) |
|
451 |
QCOMPARE( q.value( 0 ).toString()[ 0 ].unicode(), uniStr[0].unicode() ); |
|
452 |
||
453 |
QCOMPARE( q.value( 0 ).toString().trimmed(), uniStr ); |
|
454 |
||
455 |
QVERIFY( !q.next() ); |
|
456 |
} |
|
457 |
else |
|
458 |
QSKIP( "Database not unicode capable", SkipSingle ); |
|
459 |
} |
|
460 |
||
461 |
void tst_QSqlQuery::oraRowId() |
|
462 |
{ |
|
463 |
QFETCH( QString, dbName ); |
|
464 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
465 |
CHECK_DATABASE( db ); |
|
466 |
||
467 |
QSqlQuery q( db ); |
|
468 |
QVERIFY_SQL( q, exec( "select rowid from " + qTableName( "qtest" ) ) ); |
|
469 |
QVERIFY( q.next() ); |
|
470 |
QCOMPARE( q.value( 0 ).type(), QVariant::String ); |
|
471 |
QVERIFY( !q.value( 0 ).toString().isEmpty() ); |
|
472 |
||
473 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "oraRowId" ) + " (id char(1))" ) ); |
|
474 |
||
475 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "oraRowId" ) + " values('a')" ) ); |
|
476 |
QVariant v1 = q.lastInsertId(); |
|
477 |
QVERIFY( v1.isValid() ); |
|
478 |
||
479 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "oraRowId" ) + " values('b')" ) ); |
|
480 |
QVariant v2 = q.lastInsertId(); |
|
481 |
QVERIFY( v2.isValid() ); |
|
482 |
||
483 |
QVERIFY_SQL( q, prepare( "select * from " + qTableName( "oraRowId" ) + " where rowid = ?" ) ); |
|
484 |
q.addBindValue( v1 ); |
|
485 |
QVERIFY_SQL( q, exec() ); |
|
486 |
QVERIFY( q.next() ); |
|
487 |
QCOMPARE( q.value( 0 ).toString(), QString( "a" ) ); |
|
488 |
||
489 |
q.addBindValue( v2 ); |
|
490 |
QVERIFY_SQL( q, exec() ); |
|
491 |
QVERIFY( q.next() ); |
|
492 |
QCOMPARE( q.value( 0 ).toString(), QString( "b" ) ); |
|
493 |
} |
|
494 |
||
495 |
void tst_QSqlQuery::mysqlOutValues() |
|
496 |
{ |
|
497 |
QFETCH( QString, dbName ); |
|
498 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
499 |
CHECK_DATABASE( db ); |
|
500 |
||
501 |
QSqlQuery q( db ); |
|
502 |
||
503 |
if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) |
|
504 |
QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); |
|
505 |
||
506 |
q.exec( "drop function " + qTableName( "hello" ) ); |
|
507 |
||
508 |
QVERIFY_SQL( q, exec( "create function " + qTableName( "hello" ) + " (s char(20)) returns varchar(50) return concat('Hello ', s)" ) ); |
|
509 |
||
510 |
QVERIFY_SQL( q, exec( "select " + qTableName( "hello" ) + "('world')" ) ); |
|
511 |
QVERIFY_SQL( q, next() ); |
|
512 |
||
513 |
QCOMPARE( q.value( 0 ).toString(), QString( "Hello world" ) ); |
|
514 |
||
515 |
QVERIFY_SQL( q, prepare( "select " + qTableName( "hello" ) + "('harald')" ) ); |
|
516 |
QVERIFY_SQL( q, exec() ); |
|
517 |
QVERIFY_SQL( q, next() ); |
|
518 |
||
519 |
QCOMPARE( q.value( 0 ).toString(), QString( "Hello harald" ) ); |
|
520 |
||
521 |
QVERIFY_SQL( q, exec( "drop function " + qTableName( "hello" ) ) ); |
|
522 |
||
523 |
q.exec( "drop procedure " + qTableName( "qtestproc" ) ); |
|
524 |
||
525 |
QVERIFY_SQL( q, exec( "create procedure " + qTableName( "qtestproc" ) + " () " |
|
526 |
"BEGIN select * from " + qTableName( "qtest" ) + " order by id; END" ) ); |
|
527 |
QVERIFY_SQL( q, exec( "call " + qTableName( "qtestproc" ) + "()" ) ); |
|
528 |
QVERIFY_SQL( q, next() ); |
|
529 |
QCOMPARE( q.value( 1 ).toString(), QString( "VarChar1" ) ); |
|
530 |
||
531 |
QVERIFY_SQL( q, exec( "drop procedure " + qTableName( "qtestproc" ) ) ); |
|
532 |
||
533 |
QVERIFY_SQL( q, exec( "create procedure " + qTableName( "qtestproc" ) + " (OUT param1 INT) " |
|
534 |
"BEGIN set param1 = 42; END" ) ); |
|
535 |
||
536 |
QVERIFY_SQL( q, exec( "call " + qTableName( "qtestproc" ) + " (@out)" ) ); |
|
537 |
QVERIFY_SQL( q, exec( "select @out" ) ); |
|
538 |
QCOMPARE( q.record().fieldName( 0 ), QString( "@out" ) ); |
|
539 |
QVERIFY_SQL( q, next() ); |
|
540 |
QCOMPARE( q.value( 0 ).toInt(), 42 ); |
|
541 |
||
542 |
QVERIFY_SQL( q, exec( "drop procedure " + qTableName( "qtestproc" ) ) ); |
|
543 |
} |
|
544 |
||
545 |
void tst_QSqlQuery::oraOutValues() |
|
546 |
{ |
|
547 |
QFETCH( QString, dbName ); |
|
548 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
549 |
CHECK_DATABASE( db ); |
|
550 |
||
551 |
if ( !db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) { |
|
552 |
QSKIP( "Test requires prepared query support", SkipSingle ); |
|
553 |
return; |
|
554 |
} |
|
555 |
||
556 |
QSqlQuery q( db ); |
|
557 |
||
558 |
q.setForwardOnly( true ); |
|
559 |
||
560 |
/*** outvalue int ***/ |
|
561 |
QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x out int) is\n" |
|
562 |
"begin\n" |
|
563 |
" x := 42;\n" |
|
564 |
"end;\n" ) ); |
|
565 |
QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); |
|
566 |
q.addBindValue( 0, QSql::Out ); |
|
567 |
QVERIFY_SQL( q, exec() ); |
|
568 |
QCOMPARE( q.boundValue( 0 ).toInt(), 42 ); |
|
569 |
||
570 |
// bind a null value, make sure the OCI driver resets the null flag |
|
571 |
q.addBindValue( QVariant( QVariant::Int ), QSql::Out ); |
|
572 |
QVERIFY_SQL( q, exec() ); |
|
573 |
QCOMPARE( q.boundValue( 0 ).toInt(), 42 ); |
|
574 |
QVERIFY( !q.boundValue( 0 ).isNull() ); |
|
575 |
||
576 |
/*** outvalue varchar ***/ |
|
577 |
QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x out varchar) is\n" |
|
578 |
"begin\n" |
|
579 |
" x := 'blah';\n" |
|
580 |
"end;\n" ) ); |
|
581 |
QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); |
|
582 |
QString s1( "12345" ); |
|
583 |
s1.reserve( 512 ); |
|
584 |
q.addBindValue( s1, QSql::Out ); |
|
585 |
QVERIFY_SQL( q, exec() ); |
|
586 |
QCOMPARE( q.boundValue( 0 ).toString(), QString( "blah" ) ); |
|
587 |
||
588 |
/*** in/outvalue numeric ***/ |
|
589 |
QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in out numeric) is\n" |
|
590 |
"begin\n" |
|
591 |
" x := x + 10;\n" |
|
592 |
"end;\n" ) ); |
|
593 |
QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); |
|
594 |
q.addBindValue( 10, QSql::Out ); |
|
595 |
QVERIFY_SQL( q, exec() ); |
|
596 |
QCOMPARE( q.boundValue( 0 ).toInt(), 20 ); |
|
597 |
||
598 |
/*** in/outvalue varchar ***/ |
|
599 |
QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in out varchar) is\n" |
|
600 |
"begin\n" |
|
601 |
" x := 'homer';\n" |
|
602 |
"end;\n" ) ); |
|
603 |
QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); |
|
604 |
q.addBindValue( QString( "maggy" ), QSql::Out ); |
|
605 |
QVERIFY_SQL( q, exec() ); |
|
606 |
QCOMPARE( q.boundValue( 0 ).toString(), QString( "homer" ) ); |
|
607 |
||
608 |
/*** in/outvalue varchar ***/ |
|
609 |
QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in out varchar) is\n" |
|
610 |
"begin\n" |
|
611 |
" x := NULL;\n" |
|
612 |
"end;\n" ) ); |
|
613 |
QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); |
|
614 |
q.addBindValue( QString( "maggy" ), QSql::Out ); |
|
615 |
QVERIFY_SQL( q, exec() ); |
|
616 |
QVERIFY( q.boundValue( 0 ).isNull() ); |
|
617 |
||
618 |
/*** in/outvalue int ***/ |
|
619 |
QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in out int) is\n" |
|
620 |
"begin\n" |
|
621 |
" x := NULL;\n" |
|
622 |
"end;\n" ) ); |
|
623 |
QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); |
|
624 |
q.addBindValue( 42, QSql::Out ); |
|
625 |
QVERIFY_SQL( q, exec() ); |
|
626 |
QVERIFY( q.boundValue( 0 ).isNull() ); |
|
627 |
||
628 |
/*** in/outvalue varchar ***/ |
|
629 |
QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in varchar, y out varchar) is\n" |
|
630 |
"begin\n" |
|
631 |
" y := x||'bubulalakikikokololo';\n" |
|
632 |
"end;\n" ) ); |
|
633 |
QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?, ?)" ) ); |
|
634 |
q.addBindValue( QString( "fifi" ), QSql::In ); |
|
635 |
QString out; |
|
636 |
out.reserve( 50 ); |
|
637 |
q.addBindValue( out, QSql::Out ); |
|
638 |
QVERIFY_SQL( q, exec() ); |
|
639 |
QCOMPARE( q.boundValue( 1 ).toString(), QString( "fifibubulalakikikokololo" ) ); |
|
640 |
} |
|
641 |
||
642 |
void tst_QSqlQuery::oraClob() |
|
643 |
{ |
|
644 |
QFETCH( QString, dbName ); |
|
645 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
646 |
CHECK_DATABASE( db ); |
|
647 |
||
648 |
QSqlQuery q( db ); |
|
649 |
||
650 |
// simple short string |
|
651 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "clobby" ) + "(id int primary key, cl clob, bl blob)" ) ); |
|
652 |
QVERIFY_SQL( q, prepare( "insert into " + qTableName( "clobby" ) + " (id, cl, bl) values(?, ?, ?)" ) ); |
|
653 |
q.addBindValue( 1 ); |
|
654 |
q.addBindValue( "bubu" ); |
|
655 |
q.addBindValue( QByteArray("bubu") ); |
|
656 |
QVERIFY_SQL( q, exec() ); |
|
657 |
||
658 |
QVERIFY_SQL( q, exec( "select bl, cl from " + qTableName( "clobby" ) + " where id = 1" ) ); |
|
659 |
QVERIFY( q.next() ); |
|
660 |
QCOMPARE( q.value( 0 ).toString(), QString( "bubu" ) ); |
|
661 |
QCOMPARE( q.value( 1 ).toString(), QString( "bubu" ) ); |
|
662 |
||
663 |
// simple short string with binding |
|
664 |
QVERIFY_SQL( q, prepare( "insert into " + qTableName( "clobby" ) + " (id, cl, bl) values(?, ?, ?)" ) ); |
|
665 |
q.addBindValue( 2 ); |
|
666 |
q.addBindValue( "lala", QSql::Binary ); |
|
667 |
q.addBindValue( QByteArray("lala"), QSql::Binary ); |
|
668 |
QVERIFY_SQL( q, exec() ); |
|
669 |
||
670 |
QVERIFY_SQL( q, exec( "select bl, cl from " + qTableName( "clobby" ) + " where id = 2" ) ); |
|
671 |
QVERIFY( q.next() ); |
|
672 |
QCOMPARE( q.value( 0 ).toString(), QString( "lala" ) ); |
|
673 |
QCOMPARE( q.value( 1 ).toString(), QString( "lala" ) ); |
|
674 |
||
675 |
// loooong string |
|
676 |
QString loong; |
|
677 |
loong.fill( QLatin1Char( 'A' ), 25000 ); |
|
678 |
QVERIFY_SQL( q, prepare( "insert into " + qTableName( "clobby" ) + " (id, cl, bl) values(?, ?, ?)" ) ); |
|
679 |
q.addBindValue( 3 ); |
|
680 |
q.addBindValue( loong, QSql::Binary ); |
|
681 |
q.addBindValue( loong.toLatin1(), QSql::Binary ); |
|
682 |
QVERIFY_SQL( q, exec() ); |
|
683 |
||
684 |
QVERIFY_SQL( q, exec( "select bl, cl from " + qTableName( "clobby" ) + " where id = 3" ) ); |
|
685 |
QVERIFY( q.next() ); |
|
686 |
QCOMPARE( q.value( 0 ).toString().count(), loong.count() ); |
|
687 |
QVERIFY( q.value( 0 ).toString() == loong ); |
|
688 |
QCOMPARE( q.value( 1 ).toByteArray().count(), loong.toLatin1().count() ); |
|
689 |
QVERIFY( q.value( 1 ).toByteArray() == loong.toLatin1() ); |
|
690 |
} |
|
691 |
||
692 |
void tst_QSqlQuery::storedProceduresIBase() |
|
693 |
{ |
|
694 |
QFETCH( QString, dbName ); |
|
695 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
696 |
CHECK_DATABASE( db ); |
|
697 |
||
698 |
QSqlQuery q( db ); |
|
699 |
q.exec( "drop procedure " + qTableName( "TESTPROC" ) ); |
|
700 |
||
701 |
QVERIFY_SQL( q, exec( "create procedure " + qTableName( "TESTPROC" ) + |
|
702 |
" RETURNS (x integer, y varchar(20)) " |
|
703 |
"AS BEGIN " |
|
704 |
" x = 42; " |
|
705 |
" y = 'Hello Anders'; " |
|
706 |
"END" ) ); |
|
707 |
||
708 |
QVERIFY_SQL( q, prepare( "execute procedure " + qTableName( "TestProc" ) ) ); |
|
709 |
QVERIFY_SQL( q, exec() ); |
|
710 |
||
711 |
// check for a valid result set |
|
712 |
QSqlRecord rec = q.record(); |
|
713 |
QCOMPARE( rec.count(), 2 ); |
|
714 |
QCOMPARE( rec.fieldName( 0 ).toUpper(), QString( "X" ) ); |
|
715 |
QCOMPARE( rec.fieldName( 1 ).toUpper(), QString( "Y" ) ); |
|
716 |
||
717 |
// the first next shall suceed |
|
718 |
QVERIFY_SQL( q, next() ); |
|
719 |
QCOMPARE( q.value( 0 ).toInt(), 42 ); |
|
720 |
QCOMPARE( q.value( 1 ).toString(), QString( "Hello Anders" ) ); |
|
721 |
||
722 |
// the second next shall fail |
|
723 |
QVERIFY( !q.next() ); |
|
724 |
||
725 |
q.exec( "drop procedure " + qTableName( "TestProc" ) ); |
|
726 |
} |
|
727 |
||
728 |
void tst_QSqlQuery::outValuesDB2() |
|
729 |
{ |
|
730 |
QFETCH( QString, dbName ); |
|
731 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
732 |
CHECK_DATABASE( db ); |
|
733 |
||
734 |
if ( !db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) { |
|
735 |
QSKIP( "Test requires prepared query support", SkipSingle ); |
|
736 |
return; |
|
737 |
} |
|
738 |
||
739 |
QSqlQuery q( db ); |
|
740 |
||
741 |
q.setForwardOnly( true ); |
|
742 |
||
743 |
q.exec( "drop procedure " + qTableName( "tst_outValues" ) ); //non-fatal |
|
744 |
QVERIFY_SQL( q, exec( "CREATE PROCEDURE " + qTableName( "tst_outValues" ) + |
|
745 |
" (OUT x int, OUT x2 double, OUT x3 char(20))\n" |
|
746 |
"LANGUAGE SQL\n" |
|
747 |
"P1: BEGIN\n" |
|
748 |
" SET x = 42;\n" |
|
749 |
" SET x2 = 4.2;\n" |
|
750 |
" SET x3 = 'Homer';\n" |
|
751 |
"END P1" ) ); |
|
752 |
||
753 |
QVERIFY_SQL( q, prepare( "call " + qTableName( "tst_outValues" ) + "(?, ?, ?)" ) ); |
|
754 |
||
755 |
q.addBindValue( 0, QSql::Out ); |
|
756 |
q.addBindValue( 0.0, QSql::Out ); |
|
757 |
q.addBindValue( "Simpson", QSql::Out ); |
|
758 |
||
759 |
QVERIFY_SQL( q, exec() ); |
|
760 |
||
761 |
QCOMPARE( q.boundValue( 0 ).toInt(), 42 ); |
|
762 |
QCOMPARE( q.boundValue( 1 ).toDouble(), 4.2 ); |
|
763 |
QCOMPARE( q.boundValue( 2 ).toString().trimmed(), QString( "Homer" ) ); |
|
764 |
} |
|
765 |
||
766 |
void tst_QSqlQuery::outValues() |
|
767 |
{ |
|
768 |
QFETCH( QString, dbName ); |
|
769 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
770 |
CHECK_DATABASE( db ); |
|
771 |
||
772 |
if ( !db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) { |
|
773 |
QSKIP( "Test requires prepared query support", SkipSingle ); |
|
774 |
return; |
|
775 |
} |
|
776 |
||
777 |
QSqlQuery q( db ); |
|
778 |
||
779 |
q.setForwardOnly( true ); |
|
780 |
||
781 |
if ( db.driverName().startsWith( "QOCI" ) ) { |
|
782 |
QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x out int) is\n" |
|
783 |
"begin\n" |
|
784 |
" x := 42;\n" |
|
785 |
"end;\n" ) ); |
|
786 |
QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); |
|
787 |
} else if ( db.driverName().startsWith( "QDB2" ) ) { |
|
788 |
q.exec( "drop procedure " + qTableName( "tst_outValues" ) ); //non-fatal |
|
789 |
QVERIFY_SQL( q, exec( "CREATE PROCEDURE " + qTableName( "tst_outValues" ) + " (OUT x int)\n" |
|
790 |
"LANGUAGE SQL\n" |
|
791 |
"P1: BEGIN\n" |
|
792 |
" SET x = 42;\n" |
|
793 |
"END P1" ) ); |
|
794 |
QVERIFY( q.prepare( "call " + qTableName( "tst_outValues" ) + "(?)" ) ); |
|
795 |
} else if ( tst_Databases::isSqlServer( db ) ) { |
|
796 |
q.exec( "drop procedure " + qTableName( "tst_outValues" ) ); //non-fatal |
|
797 |
QVERIFY_SQL( q, exec( "create procedure " + qTableName( "tst_outValues" ) + " (@x int out) as\n" |
|
798 |
"begin\n" |
|
799 |
" set @x = 42\n" |
|
800 |
"end\n" ) ); |
|
801 |
QVERIFY( q.prepare( "{call " + qTableName( "tst_outvalues" ) + "(?)}" ) ); |
|
802 |
} else { |
|
803 |
QSKIP( "Don't know how to create a stored procedure for this database server, please fix this test", SkipSingle ); |
|
804 |
return; |
|
805 |
} |
|
806 |
||
807 |
q.addBindValue( 0, QSql::Out ); |
|
808 |
||
809 |
QVERIFY_SQL( q, exec() ); |
|
810 |
||
811 |
QCOMPARE( q.boundValue( 0 ).toInt(), 42 ); |
|
812 |
} |
|
813 |
||
814 |
void tst_QSqlQuery::blob() |
|
815 |
{ |
|
816 |
static const int BLOBSIZE = 1024 * 10; |
|
817 |
static const int BLOBCOUNT = 2; |
|
818 |
||
819 |
QFETCH( QString, dbName ); |
|
820 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
821 |
CHECK_DATABASE( db ); |
|
822 |
||
823 |
if ( !db.driver()->hasFeature( QSqlDriver::BLOB ) ) |
|
824 |
QSKIP( "DBMS not BLOB capable", SkipSingle ); |
|
825 |
||
826 |
//don' make it too big otherwise sybase and mysql will complain |
|
827 |
QByteArray ba( BLOBSIZE, 0 ); |
|
828 |
||
829 |
int i; |
|
830 |
||
831 |
for ( i = 0; i < ( int )ba.size(); ++i ) |
|
832 |
ba[i] = i % 256; |
|
833 |
||
834 |
QSqlQuery q( db ); |
|
835 |
||
836 |
q.setForwardOnly( true ); |
|
837 |
||
838 |
QString queryString = QString( "create table " + qTableName( "qtest_blob" ) + |
|
839 |
" (id int not null primary key, t_blob %1)" ).arg( tst_Databases::blobTypeName( db, BLOBSIZE ) ); |
|
840 |
QVERIFY_SQL( q, exec( queryString ) ); |
|
841 |
||
842 |
QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_blob" ) + " (id, t_blob) values (?, ?)" ) ); |
|
843 |
||
844 |
for ( i = 0; i < BLOBCOUNT; ++i ) { |
|
845 |
q.addBindValue( i ); |
|
846 |
q.addBindValue( ba ); |
|
847 |
QVERIFY_SQL( q, exec() ); |
|
848 |
} |
|
849 |
||
850 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_blob" ) ) ); |
|
851 |
||
852 |
for ( i = 0; i < BLOBCOUNT; ++i ) { |
|
853 |
QVERIFY( q.next() ); |
|
854 |
QByteArray res = q.value( 1 ).toByteArray(); |
|
855 |
QVERIFY2( res.size() >= ba.size(), |
|
856 |
QString( "array sizes differ, expected %1, got %2" ).arg( ba.size() ).arg( res.size() ).toLatin1() ); |
|
857 |
||
858 |
for ( int i2 = 0; i2 < ( int )ba.size(); ++i2 ) { |
|
859 |
if ( res[i2] != ba[i2] ) |
|
860 |
QFAIL( QString( "ByteArrays differ at position %1, expected %2, got %3" ).arg( |
|
861 |
i2 ).arg(( int )( unsigned char )ba[i2] ).arg(( int )( unsigned char )res[i2] ).toLatin1() ); |
|
862 |
} |
|
863 |
} |
|
864 |
} |
|
865 |
||
866 |
void tst_QSqlQuery::value() |
|
867 |
{ |
|
868 |
QFETCH( QString, dbName ); |
|
869 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
870 |
CHECK_DATABASE( db ); |
|
871 |
||
872 |
QSqlQuery q( db ); |
|
873 |
QVERIFY_SQL( q, exec( "select id, t_varchar, t_char from " + qTableName( "qtest" ) + " order by id" ) ); |
|
874 |
int i = 1; |
|
875 |
||
876 |
while ( q.next() ) { |
|
877 |
QCOMPARE( q.value( 0 ).toInt(), i ); |
|
878 |
||
879 |
if ( db.driverName().startsWith( "QIBASE" ) ) |
|
880 |
QVERIFY( q.value( 1 ).toString().startsWith( "VarChar" + QString::number( i ) ) ); |
|
881 |
else if ( q.value( 1 ).toString().right( 1 ) == " " ) |
|
882 |
QCOMPARE( q.value( 1 ).toString(), ( "VarChar" + QString::number( i ) + " " ) ); |
|
883 |
else |
|
884 |
QCOMPARE( q.value( 1 ).toString(), ( "VarChar" + QString::number( i ) ) ); |
|
885 |
||
886 |
if ( db.driverName().startsWith( "QIBASE" ) ) |
|
887 |
QVERIFY( q.value( 2 ).toString().startsWith( "Char" + QString::number( i ) ) ); |
|
888 |
else if ( q.value( 2 ).toString().right( 1 ) != " " ) |
|
889 |
QCOMPARE( q.value( 2 ).toString(), ( "Char" + QString::number( i ) ) ); |
|
890 |
else |
|
891 |
QCOMPARE( q.value( 2 ).toString(), ( "Char" + QString::number( i ) + " " ) ); |
|
892 |
||
893 |
i++; |
|
894 |
} |
|
895 |
} |
|
896 |
||
897 |
void tst_QSqlQuery::record() |
|
898 |
{ |
|
899 |
QFETCH( QString, dbName ); |
|
900 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
901 |
CHECK_DATABASE( db ); |
|
902 |
||
903 |
QSqlQuery q( db ); |
|
904 |
QVERIFY( q.record().isEmpty() ); |
|
905 |
QVERIFY_SQL( q, exec( "select id, t_varchar, t_char from " + qTableName( "qtest" ) + " order by id" ) ); |
|
906 |
QSqlRecord rec = q.record(); |
|
907 |
QCOMPARE( q.record().fieldName( 0 ).toLower(), QString( "id" ) ); |
|
908 |
QCOMPARE( q.record().fieldName( 1 ).toLower(), QString( "t_varchar" ) ); |
|
909 |
QCOMPARE( q.record().fieldName( 2 ).toLower(), QString( "t_char" ) ); |
|
910 |
QVERIFY( !q.record().value( 0 ).isValid() ); |
|
911 |
QVERIFY( !q.record().value( 1 ).isValid() ); |
|
912 |
QVERIFY( !q.record().value( 2 ).isValid() ); |
|
913 |
||
914 |
QVERIFY( q.next() ); |
|
915 |
QVERIFY( q.next() ); |
|
916 |
||
917 |
QCOMPARE( q.record().fieldName( 0 ).toLower(), QString( "id" ) ); |
|
918 |
QCOMPARE( q.value( 0 ).toInt(), 2 ); |
|
919 |
} |
|
920 |
||
921 |
void tst_QSqlQuery::isValid() |
|
922 |
{ |
|
923 |
QFETCH( QString, dbName ); |
|
924 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
925 |
CHECK_DATABASE( db ); |
|
926 |
||
927 |
QSqlQuery q( db ); |
|
928 |
QVERIFY( !q.isValid() ); |
|
929 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
930 |
QVERIFY( q.first() ); |
|
931 |
QVERIFY( q.isValid() ); |
|
932 |
} |
|
933 |
||
934 |
void tst_QSqlQuery::isActive() |
|
935 |
{ |
|
936 |
QFETCH( QString, dbName ); |
|
937 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
938 |
CHECK_DATABASE( db ); |
|
939 |
||
940 |
QSqlQuery q( db ); |
|
941 |
QVERIFY( !q.isActive() ); |
|
942 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
943 |
QVERIFY( q.isActive() ); |
|
944 |
QVERIFY( q.last() ); |
|
945 |
||
946 |
if ( !tst_Databases::isMSAccess( db ) ) |
|
947 |
// Access is stupid enough to let you scroll over boundaries |
|
948 |
QVERIFY( !q.next() ); |
|
949 |
||
950 |
QVERIFY( q.isActive() ); |
|
951 |
||
952 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (41, 'VarChar41', 'Char41')" ) ); |
|
953 |
||
954 |
QVERIFY( q.isActive() ); |
|
955 |
||
956 |
QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = 42 where id = 41" ) ); |
|
957 |
||
958 |
QVERIFY( q.isActive() ); |
|
959 |
||
960 |
QVERIFY_SQL( q, exec( "delete from " + qTableName( "qtest" ) + " where id = 42" ) ); |
|
961 |
||
962 |
QVERIFY( q.isActive() ); |
|
963 |
} |
|
964 |
||
965 |
void tst_QSqlQuery::numRowsAffected() |
|
966 |
{ |
|
967 |
QFETCH( QString, dbName ); |
|
968 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
969 |
CHECK_DATABASE( db ); |
|
970 |
||
971 |
QSqlQuery q( db ); |
|
972 |
QCOMPARE( q.numRowsAffected(), -1 ); |
|
973 |
||
974 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
975 |
int i = 0; |
|
976 |
||
977 |
while ( q.next() ) |
|
978 |
++i; |
|
979 |
||
980 |
if ( q.numRowsAffected() == -1 || q.numRowsAffected() == 0 ) |
|
981 |
QSKIP("Database doesn't support numRowsAffected", SkipSingle); |
|
982 |
||
983 |
if ( q.numRowsAffected() != -1 && q.numRowsAffected() != 0 && q.numRowsAffected() != i ) { |
|
984 |
// the value is undefined for SELECT, this check is just here for curiosity |
|
985 |
qDebug( "Expected numRowsAffected to be -1, 0 or %d, got %d", i, q.numRowsAffected() ); |
|
986 |
} |
|
987 |
||
988 |
QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = 100 where id = 1" ) ); |
|
989 |
||
990 |
QCOMPARE( q.numRowsAffected(), 1 ); |
|
991 |
QCOMPARE( q.numRowsAffected(), 1 ); // yes, we check twice |
|
992 |
||
993 |
QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = id + 100" ) ); |
|
994 |
QCOMPARE( q.numRowsAffected(), i ); |
|
995 |
QCOMPARE( q.numRowsAffected(), i ); // yes, we check twice |
|
996 |
||
997 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (42000, 'homer', 'marge')" ) ); |
|
998 |
QCOMPARE( q.numRowsAffected(), 1 ); |
|
999 |
QCOMPARE( q.numRowsAffected(), 1 ); // yes, we check twice |
|
1000 |
||
1001 |
QSqlQuery q2( db ); |
|
1002 |
QVERIFY_SQL( q2, exec( "insert into " + qTableName( "qtest" ) + " values (42001, 'homer', 'marge')" ) ); |
|
1003 |
||
1004 |
if ( !db.driverName().startsWith( "QSQLITE2" ) ) { |
|
1005 |
// SQLite 2.x accumulates changed rows in nested queries. See task 33794 |
|
1006 |
QCOMPARE( q2.numRowsAffected(), 1 ); |
|
1007 |
QCOMPARE( q2.numRowsAffected(), 1 ); // yes, we check twice |
|
1008 |
} |
|
1009 |
} |
|
1010 |
||
1011 |
void tst_QSqlQuery::size() |
|
1012 |
{ |
|
1013 |
QFETCH( QString, dbName ); |
|
1014 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1015 |
CHECK_DATABASE( db ); |
|
1016 |
||
1017 |
QSqlQuery q( db ); |
|
1018 |
QCOMPARE( q.size(), -1 ); |
|
1019 |
||
1020 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
1021 |
int i = 0; |
|
1022 |
||
1023 |
while ( q.next() ) |
|
1024 |
++i; |
|
1025 |
||
1026 |
if ( db.driver()->hasFeature( QSqlDriver::QuerySize ) ) { |
|
1027 |
QCOMPARE( q.size(), i ); |
|
1028 |
QCOMPARE( q.size(), i ); // yes, twice |
|
1029 |
} else { |
|
1030 |
QCOMPARE( q.size(), -1 ); |
|
1031 |
QCOMPARE( q.size(), -1 ); // yes, twice |
|
1032 |
} |
|
1033 |
||
1034 |
QSqlQuery q2( "select * from " + qTableName( "qtest" ), db ); |
|
1035 |
||
1036 |
if ( db.driver()->hasFeature( QSqlDriver::QuerySize ) ) |
|
1037 |
QCOMPARE( q.size(), i ); |
|
1038 |
else |
|
1039 |
QCOMPARE( q.size(), -1 ); |
|
1040 |
||
1041 |
q2.clear(); |
|
1042 |
||
1043 |
QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = 100 where id = 1" ) ); |
|
1044 |
QCOMPARE( q.size(), -1 ); |
|
1045 |
QCOMPARE( q.size(), -1 ); // yes, twice |
|
1046 |
} |
|
1047 |
||
1048 |
void tst_QSqlQuery::isSelect() |
|
1049 |
{ |
|
1050 |
QFETCH( QString, dbName ); |
|
1051 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1052 |
CHECK_DATABASE( db ); |
|
1053 |
||
1054 |
QSqlQuery q( db ); |
|
1055 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
1056 |
QVERIFY( q.isSelect() ); |
|
1057 |
||
1058 |
QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = 1 where id = 1" ) ); |
|
1059 |
QVERIFY( q.isSelect() == false ); |
|
1060 |
} |
|
1061 |
||
1062 |
void tst_QSqlQuery::first() |
|
1063 |
{ |
|
1064 |
QFETCH( QString, dbName ); |
|
1065 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1066 |
CHECK_DATABASE( db ); |
|
1067 |
||
1068 |
QSqlQuery q( db ); |
|
1069 |
QVERIFY( q.at() == QSql::BeforeFirstRow ); |
|
1070 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
1071 |
QVERIFY( q.last() ); |
|
1072 |
QVERIFY_SQL( q, first() ); |
|
1073 |
QVERIFY( q.at() == 0 ); |
|
1074 |
} |
|
1075 |
||
1076 |
void tst_QSqlQuery::next() |
|
1077 |
{ |
|
1078 |
QFETCH( QString, dbName ); |
|
1079 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1080 |
CHECK_DATABASE( db ); |
|
1081 |
||
1082 |
QSqlQuery q( db ); |
|
1083 |
QVERIFY( q.at() == QSql::BeforeFirstRow ); |
|
1084 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
1085 |
QVERIFY( q.first() ); |
|
1086 |
QVERIFY( q.next() ); |
|
1087 |
QVERIFY( q.at() == 1 ); |
|
1088 |
} |
|
1089 |
||
1090 |
void tst_QSqlQuery::prev() |
|
1091 |
{ |
|
1092 |
QFETCH( QString, dbName ); |
|
1093 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1094 |
CHECK_DATABASE( db ); |
|
1095 |
||
1096 |
QSqlQuery q( db ); |
|
1097 |
QVERIFY( q.at() == QSql::BeforeFirstRow ); |
|
1098 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
1099 |
QVERIFY( q.first() ); |
|
1100 |
QVERIFY( q.next() ); |
|
1101 |
QVERIFY( q.previous() ); |
|
1102 |
QVERIFY( q.at() == 0 ); |
|
1103 |
} |
|
1104 |
||
1105 |
void tst_QSqlQuery::last() |
|
1106 |
{ |
|
1107 |
QFETCH( QString, dbName ); |
|
1108 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1109 |
CHECK_DATABASE( db ); |
|
1110 |
||
1111 |
QSqlQuery q( db ); |
|
1112 |
QCOMPARE( q.at(), int( QSql::BeforeFirstRow ) ); |
|
1113 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
1114 |
int i = 0; |
|
1115 |
||
1116 |
while ( q.next() ) |
|
1117 |
i++; |
|
1118 |
||
1119 |
QCOMPARE( q.at(), int( QSql::AfterLastRow ) ); |
|
1120 |
||
1121 |
QVERIFY( q.last() ); |
|
1122 |
||
1123 |
if ( !tst_Databases::isMSAccess( db ) ) |
|
1124 |
// Access doesn't return the correct position |
|
1125 |
QCOMPARE( q.at(), ( i-1 ) ); |
|
1126 |
||
1127 |
QSqlQuery q2( "select * from " + qTableName( "qtest" ), db ); |
|
1128 |
||
1129 |
QVERIFY( q2.last() ); |
|
1130 |
||
1131 |
if ( !tst_Databases::isMSAccess( db ) ) |
|
1132 |
// Access doesn't return the correct position |
|
1133 |
QCOMPARE( q.at(), ( i-1 ) ); |
|
1134 |
} |
|
1135 |
||
1136 |
void tst_QSqlQuery::seek() |
|
1137 |
{ |
|
1138 |
QFETCH( QString, dbName ); |
|
1139 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1140 |
CHECK_DATABASE( db ); |
|
1141 |
QSqlQuery q( db ); |
|
1142 |
QVERIFY( q.at() == QSql::BeforeFirstRow ); |
|
1143 |
QVERIFY_SQL( q, exec( QString( "select id from %1 order by id" ).arg( qTableName( "qtest" ) ) ) ); |
|
1144 |
||
1145 |
// NB! The order of the calls below are important! |
|
1146 |
QVERIFY( q.last() ); |
|
1147 |
QVERIFY( !q.seek( QSql::BeforeFirstRow ) ); |
|
1148 |
QCOMPARE( q.at(), int( QSql::BeforeFirstRow ) ); |
|
1149 |
QVERIFY( q.seek( 0 ) ); |
|
1150 |
QCOMPARE( q.at(), 0 ); |
|
1151 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
1152 |
||
1153 |
QVERIFY( q.seek( 1 ) ); |
|
1154 |
QCOMPARE( q.at(), 1 ); |
|
1155 |
QCOMPARE( q.value( 0 ).toInt(), 2 ); |
|
1156 |
||
1157 |
QVERIFY( q.seek( 3 ) ); |
|
1158 |
QCOMPARE( q.at(), 3 ); |
|
1159 |
QCOMPARE( q.value( 0 ).toInt(), 4 ); |
|
1160 |
||
1161 |
QVERIFY( q.seek( -2, true ) ); |
|
1162 |
QCOMPARE( q.at(), 1 ); |
|
1163 |
QVERIFY( q.seek( 0 ) ); |
|
1164 |
QCOMPARE( q.at(), 0 ); |
|
1165 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
1166 |
} |
|
1167 |
||
1168 |
void tst_QSqlQuery::seekForwardOnlyQuery() |
|
1169 |
{ |
|
1170 |
QFETCH( QString, dbName ); |
|
1171 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1172 |
CHECK_DATABASE( db ); |
|
1173 |
||
1174 |
QSqlQuery q( db ); |
|
1175 |
q.setForwardOnly( false ); |
|
1176 |
QVERIFY( !q.isForwardOnly() ); |
|
1177 |
||
1178 |
QVERIFY( q.at() == QSql::BeforeFirstRow ); |
|
1179 |
QVERIFY_SQL( q, exec( QString( "select id from %1 order by id" ).arg( qTableName( "qtest" ) ) ) ); |
|
1180 |
||
1181 |
QSqlRecord rec; |
|
1182 |
||
1183 |
// NB! The order of the calls below are important! |
|
1184 |
QVERIFY( q.seek( 0 ) ); |
|
1185 |
QCOMPARE( q.at(), 0 ); |
|
1186 |
rec = q.record(); |
|
1187 |
QCOMPARE( rec.value( 0 ).toInt(), 1 ); |
|
1188 |
||
1189 |
QVERIFY( q.seek( 1 ) ); |
|
1190 |
QCOMPARE( q.at(), 1 ); |
|
1191 |
rec = q.record(); |
|
1192 |
QCOMPARE( rec.value( 0 ).toInt(), 2 ); |
|
1193 |
||
1194 |
// Make a jump! |
|
1195 |
QVERIFY( q.seek( 3 ) ); |
|
1196 |
QCOMPARE( q.at(), 3 ); |
|
1197 |
rec = q.record(); |
|
1198 |
QCOMPARE( rec.value( 0 ).toInt(), 4 ); |
|
1199 |
||
1200 |
// Last record in result set |
|
1201 |
QVERIFY( q.seek( 4 ) ); |
|
1202 |
QCOMPARE( q.at(), 4 ); |
|
1203 |
rec = q.record(); |
|
1204 |
QCOMPARE( rec.value( 0 ).toInt(), 5 ); |
|
1205 |
} |
|
1206 |
||
1207 |
// tests the forward only mode; |
|
1208 |
void tst_QSqlQuery::forwardOnly() |
|
1209 |
{ |
|
1210 |
QFETCH( QString, dbName ); |
|
1211 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1212 |
CHECK_DATABASE( db ); |
|
1213 |
||
1214 |
QSqlQuery q( db ); |
|
1215 |
q.setForwardOnly( true ); |
|
1216 |
QVERIFY( q.isForwardOnly() ); |
|
1217 |
QVERIFY( q.at() == QSql::BeforeFirstRow ); |
|
1218 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) + " order by id" ) ); |
|
1219 |
QVERIFY( q.at() == QSql::BeforeFirstRow ); |
|
1220 |
QVERIFY( q.first() ); |
|
1221 |
QCOMPARE( q.at(), 0 ); |
|
1222 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
1223 |
QVERIFY( q.next() ); |
|
1224 |
QCOMPARE( q.at(), 1 ); |
|
1225 |
QCOMPARE( q.value( 0 ).toInt(), 2 ); |
|
1226 |
QVERIFY( q.next() ); |
|
1227 |
QCOMPARE( q.at(), 2 ); |
|
1228 |
QCOMPARE( q.value( 0 ).toInt(), 3 ); |
|
1229 |
||
1230 |
// lets make some mistakes to see how robust it is |
|
1231 |
QTest::ignoreMessage( QtWarningMsg, "QSqlQuery::seek: cannot seek backwards in a forward only query" ); |
|
1232 |
QVERIFY( q.first() == false ); |
|
1233 |
QCOMPARE( q.at(), 2 ); |
|
1234 |
QCOMPARE( q.value( 0 ).toInt(), 3 ); |
|
1235 |
QTest::ignoreMessage( QtWarningMsg, "QSqlQuery::seek: cannot seek backwards in a forward only query" ); |
|
1236 |
QVERIFY( q.previous() == false ); |
|
1237 |
QCOMPARE( q.at(), 2 ); |
|
1238 |
QCOMPARE( q.value( 0 ).toInt(), 3 ); |
|
1239 |
QVERIFY( q.next() ); |
|
1240 |
QCOMPARE( q.at(), 3 ); |
|
1241 |
QCOMPARE( q.value( 0 ).toInt(), 4 ); |
|
1242 |
||
1243 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
1244 |
int i = 0; |
|
1245 |
||
1246 |
while ( q.next() ) |
|
1247 |
i++; |
|
1248 |
||
1249 |
QVERIFY( q.at() == QSql::AfterLastRow ); |
|
1250 |
||
1251 |
QSqlQuery q2 = q; |
|
1252 |
||
1253 |
QVERIFY( q2.isForwardOnly() ); |
|
1254 |
||
1255 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) + " order by id" ) ); |
|
1256 |
||
1257 |
QVERIFY( q.isForwardOnly() ); |
|
1258 |
||
1259 |
QVERIFY( q2.isForwardOnly() ); |
|
1260 |
||
1261 |
QCOMPARE( q.at(), int( QSql::BeforeFirstRow ) ); |
|
1262 |
||
1263 |
QVERIFY_SQL( q, seek( 3 ) ); |
|
1264 |
||
1265 |
QCOMPARE( q.at(), 3 ); |
|
1266 |
||
1267 |
QCOMPARE( q.value( 0 ).toInt(), 4 ); |
|
1268 |
||
1269 |
QTest::ignoreMessage( QtWarningMsg, "QSqlQuery::seek: cannot seek backwards in a forward only query" ); |
|
1270 |
||
1271 |
QVERIFY( q.seek( 0 ) == false ); |
|
1272 |
||
1273 |
QCOMPARE( q.value( 0 ).toInt(), 4 ); |
|
1274 |
||
1275 |
QCOMPARE( q.at(), 3 ); |
|
1276 |
||
1277 |
QVERIFY( q.last() ); |
|
1278 |
||
1279 |
QCOMPARE( q.at(), i-1 ); |
|
1280 |
||
1281 |
QTest::ignoreMessage( QtWarningMsg, "QSqlQuery::seek: cannot seek backwards in a forward only query" ); |
|
1282 |
||
1283 |
QVERIFY( q.first() == false ); |
|
1284 |
||
1285 |
QCOMPARE( q.at(), i-1 ); |
|
1286 |
||
1287 |
QVERIFY( q.next() == false ); |
|
1288 |
||
1289 |
QCOMPARE( q.at(), int( QSql::AfterLastRow ) ); |
|
1290 |
} |
|
1291 |
||
1292 |
void tst_QSqlQuery::query_exec() |
|
1293 |
{ |
|
1294 |
QFETCH( QString, dbName ); |
|
1295 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1296 |
CHECK_DATABASE( db ); |
|
1297 |
||
1298 |
QSqlQuery q( db ); |
|
1299 |
QVERIFY( !q.isValid() ); |
|
1300 |
QVERIFY( !q.isActive() ); |
|
1301 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); |
|
1302 |
QVERIFY( q.isActive() ); |
|
1303 |
QVERIFY( q.next() ); |
|
1304 |
QVERIFY( q.isValid() ); |
|
1305 |
} |
|
1306 |
||
1307 |
void tst_QSqlQuery::isNull() |
|
1308 |
{ |
|
1309 |
QFETCH( QString, dbName ); |
|
1310 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1311 |
CHECK_DATABASE( db ); |
|
1312 |
||
1313 |
QSqlQuery q( db ); |
|
1314 |
QVERIFY_SQL( q, exec( "select id, t_varchar from " + qTableName( "qtest_null" ) + " order by id" ) ); |
|
1315 |
QVERIFY( q.next() ); |
|
1316 |
QVERIFY( !q.isNull( 0 ) ); |
|
1317 |
QVERIFY( q.isNull( 1 ) ); |
|
1318 |
QCOMPARE( q.value( 0 ).toInt(), 0 ); |
|
1319 |
QCOMPARE( q.value( 1 ).toString(), QString() ); |
|
1320 |
QVERIFY( !q.value( 0 ).isNull() ); |
|
1321 |
QVERIFY( q.value( 1 ).isNull() ); |
|
1322 |
||
1323 |
QVERIFY( q.next() ); |
|
1324 |
QVERIFY( !q.isNull( 0 ) ); |
|
1325 |
QVERIFY( !q.isNull( 1 ) ); |
|
1326 |
} |
|
1327 |
||
1328 |
/*! TDS specific BIT field test */ |
|
1329 |
void tst_QSqlQuery::bitField() |
|
1330 |
{ |
|
1331 |
QFETCH( QString, dbName ); |
|
1332 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1333 |
CHECK_DATABASE( db ); |
|
1334 |
||
1335 |
if ( !db.driverName().startsWith( "QTDS" ) ) |
|
1336 |
QSKIP( "TDS specific test", SkipSingle ); |
|
1337 |
||
1338 |
QSqlQuery q( db ); |
|
1339 |
||
1340 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_bittest" ) + " (bitty bit)" ) ); |
|
1341 |
||
1342 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_bittest" ) + " values (0)" ) ); |
|
1343 |
||
1344 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_bittest" ) + " values (1)" ) ); |
|
1345 |
||
1346 |
QVERIFY_SQL( q, exec( "select bitty from " + qTableName( "qtest_bittest" ) ) ); |
|
1347 |
||
1348 |
QVERIFY( q.next() ); |
|
1349 |
||
1350 |
QVERIFY( q.value( 0 ).toInt() == 0 ); |
|
1351 |
||
1352 |
QVERIFY( q.next() ); |
|
1353 |
||
1354 |
QVERIFY( q.value( 0 ).toInt() == 1 ); |
|
1355 |
} |
|
1356 |
||
1357 |
||
1358 |
/*! Oracle specific NULL BLOB test */ |
|
1359 |
void tst_QSqlQuery::nullBlob() |
|
1360 |
{ |
|
1361 |
QFETCH( QString, dbName ); |
|
1362 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1363 |
CHECK_DATABASE( db ); |
|
1364 |
||
1365 |
QSqlQuery q( db ); |
|
1366 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_nullblob" ) + " (id int primary key, bb blob)" ) ); |
|
1367 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_nullblob" ) + " values (0, EMPTY_BLOB())" ) ); |
|
1368 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_nullblob" ) + " values (1, NULL)" ) ); |
|
1369 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_nullblob" ) + " values (2, 'aabbcc00112233445566')" ) ); |
|
1370 |
// necessary otherwise oracle will bombard you with internal errors |
|
1371 |
q.setForwardOnly( true ); |
|
1372 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_nullblob" ) + " order by id" ) ); |
|
1373 |
||
1374 |
QVERIFY( q.next() ); |
|
1375 |
QCOMPARE(( int )q.value( 1 ).toByteArray().size(), 0 ); |
|
1376 |
QVERIFY( !q.isNull( 1 ) ); |
|
1377 |
||
1378 |
QVERIFY( q.next() ); |
|
1379 |
QCOMPARE(( int )q.value( 1 ).toByteArray().size(), 0 ); |
|
1380 |
QVERIFY( q.isNull( 1 ) ); |
|
1381 |
||
1382 |
QVERIFY( q.next() ); |
|
1383 |
QCOMPARE(( int )q.value( 1 ).toByteArray().size(), 10 ); |
|
1384 |
QVERIFY( !q.isNull( 1 ) ); |
|
1385 |
} |
|
1386 |
||
1387 |
/* Oracle specific RAW field test */ |
|
1388 |
void tst_QSqlQuery::rawField() |
|
1389 |
{ |
|
1390 |
QFETCH( QString, dbName ); |
|
1391 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1392 |
CHECK_DATABASE( db ); |
|
1393 |
||
1394 |
QSqlQuery q( db ); |
|
1395 |
q.setForwardOnly( true ); |
|
1396 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_rawtest" ) + |
|
1397 |
" (id int, col raw(20))" ) ); |
|
1398 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_rawtest" ) + " values (0, NULL)" ) ); |
|
1399 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_rawtest" ) + " values (1, '00aa1100ddeeff')" ) ); |
|
1400 |
QVERIFY_SQL( q, exec( "select col from " + qTableName( "qtest_rawtest" ) + " order by id" ) ); |
|
1401 |
QVERIFY( q.next() ); |
|
1402 |
QVERIFY( q.isNull( 0 ) ); |
|
1403 |
QCOMPARE(( int )q.value( 0 ).toByteArray().size(), 0 ); |
|
1404 |
QVERIFY( q.next() ); |
|
1405 |
QVERIFY( !q.isNull( 0 ) ); |
|
1406 |
QCOMPARE(( int )q.value( 0 ).toByteArray().size(), 7 ); |
|
1407 |
} |
|
1408 |
||
1409 |
// test whether we can fetch values with more than DOUBLE precision |
|
1410 |
// note that MySQL's 3.x highest precision is that of a double, although |
|
1411 |
// you can define field with higher precision |
|
1412 |
void tst_QSqlQuery::precision() |
|
1413 |
{ |
|
1414 |
QFETCH( QString, dbName ); |
|
1415 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1416 |
CHECK_DATABASE( db ); |
|
1417 |
||
1418 |
static const char* precStr = "1.2345678901234567891"; |
|
1419 |
||
1420 |
if ( db.driverName().startsWith( "QIBASE" ) ) |
|
1421 |
QSKIP( "DB unable to store high precision", SkipSingle ); |
|
1422 |
||
1423 |
{ |
|
1424 |
// need a new scope for SQLITE |
|
1425 |
QSqlQuery q( db ); |
|
1426 |
||
1427 |
if ( tst_Databases::isMSAccess( db ) ) |
|
1428 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_precision" ) + " (col1 number)" ) ); |
|
1429 |
else |
|
1430 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_precision" ) + " (col1 numeric(21, 20))" ) ); |
|
1431 |
||
1432 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_precision" ) + " (col1) values (1.2345678901234567891)" ) ); |
|
1433 |
||
1434 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_precision" ) ) ); |
|
1435 |
QVERIFY( q.next() ); |
|
1436 |
||
1437 |
QString val = q.value( 0 ).toString(); |
|
1438 |
||
1439 |
if ( !val.startsWith( "1.2345678901234567891" ) ) { |
|
1440 |
int i = 0; |
|
1441 |
||
1442 |
while ( precStr[i] != 0 && *( precStr + i ) == val[i].toLatin1() ) |
|
1443 |
i++; |
|
1444 |
||
1445 |
// MySQL and TDS have crappy precisions by default |
|
1446 |
if ( db.driverName().startsWith( "QMYSQL" ) ) { |
|
1447 |
if ( i < 17 ) |
|
1448 |
QWARN( "MySQL didn't return the right precision" ); |
|
1449 |
} else if ( db.driverName().startsWith( "QTDS" ) ) { |
|
1450 |
if ( i < 18 ) |
|
1451 |
QWARN( "TDS didn't return the right precision" ); |
|
1452 |
} else { |
|
1453 |
QWARN( QString( tst_Databases::dbToString( db ) + " didn't return the right precision (" + |
|
1454 |
QString::number( i ) + " out of 21), " + val ).toLatin1() ); |
|
1455 |
} |
|
1456 |
} |
|
1457 |
} // SQLITE scope |
|
1458 |
} |
|
1459 |
||
1460 |
void tst_QSqlQuery::nullResult() |
|
1461 |
{ |
|
1462 |
QFETCH( QString, dbName ); |
|
1463 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1464 |
CHECK_DATABASE( db ); |
|
1465 |
||
1466 |
QSqlQuery q( db ); |
|
1467 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) + " where id > 50000" ) ); |
|
1468 |
||
1469 |
if ( q.driver()->hasFeature( QSqlDriver::QuerySize ) ) |
|
1470 |
QCOMPARE( q.size(), 0 ); |
|
1471 |
||
1472 |
QVERIFY( q.next() == false ); |
|
1473 |
||
1474 |
QVERIFY( q.first() == false ); |
|
1475 |
QVERIFY( q.last() == false ); |
|
1476 |
QVERIFY( q.previous() == false ); |
|
1477 |
QVERIFY( q.seek( 10 ) == false ); |
|
1478 |
QVERIFY( q.seek( 0 ) == false ); |
|
1479 |
} |
|
1480 |
||
1481 |
// this test is just an experiment to see whether we can do query-based transactions |
|
1482 |
// the real transaction test is in tst_QSqlDatabase |
|
1483 |
void tst_QSqlQuery::transaction() |
|
1484 |
{ |
|
1485 |
// query based transaction is not really possible with Qt |
|
1486 |
QSKIP( "only tested manually by trained staff", SkipAll ); |
|
1487 |
||
1488 |
QFETCH( QString, dbName ); |
|
1489 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1490 |
CHECK_DATABASE( db ); |
|
1491 |
||
1492 |
if ( !db.driver()->hasFeature( QSqlDriver::Transactions ) ) |
|
1493 |
QSKIP( "DBMS not transaction capable", SkipSingle ); |
|
1494 |
||
1495 |
// this is the standard SQL |
|
1496 |
QString startTransactionStr( "start transaction" ); |
|
1497 |
||
1498 |
if ( db.driverName().startsWith( "QMYSQL" ) ) |
|
1499 |
startTransactionStr = "begin work"; |
|
1500 |
||
1501 |
QSqlQuery q( db ); |
|
1502 |
||
1503 |
QSqlQuery q2( db ); |
|
1504 |
||
1505 |
// test a working transaction |
|
1506 |
q.exec( startTransactionStr ); |
|
1507 |
||
1508 |
QVERIFY_SQL( q, exec( "insert into" + qTableName( "qtest" ) + " values (40, 'VarChar40', 'Char40')" ) ); |
|
1509 |
||
1510 |
QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 40" ) ); |
|
1511 |
||
1512 |
QVERIFY( q.next() ); |
|
1513 |
||
1514 |
QCOMPARE( q.value( 0 ).toInt(), 40 ); |
|
1515 |
||
1516 |
QVERIFY_SQL( q, exec( "commit" ) ); |
|
1517 |
||
1518 |
QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 40" ) ); |
|
1519 |
||
1520 |
QVERIFY( q.next() ); |
|
1521 |
||
1522 |
QCOMPARE( q.value( 0 ).toInt(), 40 ); |
|
1523 |
||
1524 |
// test a rollback |
|
1525 |
q.exec( startTransactionStr ); |
|
1526 |
||
1527 |
QVERIFY_SQL( q, exec( "insert into" + qTableName( "qtest" ) + " values (41, 'VarChar41', 'Char41')" ) ); |
|
1528 |
||
1529 |
QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 41" ) ); |
|
1530 |
||
1531 |
QVERIFY( q.next() ); |
|
1532 |
||
1533 |
QCOMPARE( q.value( 0 ).toInt(), 41 ); |
|
1534 |
||
1535 |
if ( !q.exec( "rollback" ) ) { |
|
1536 |
if ( db.driverName().startsWith( "QMYSQL" ) ) { |
|
1537 |
qDebug( "MySQL: " + tst_Databases::printError( q.lastError() ) ); |
|
1538 |
QSKIP( "MySQL transaction failed ", SkipSingle ); //non-fatal |
|
1539 |
} else |
|
1540 |
QFAIL( "Could not rollback transaction: " + tst_Databases::printError( q.lastError() ) ); |
|
1541 |
} |
|
1542 |
||
1543 |
QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 41" ) ); |
|
1544 |
||
1545 |
QVERIFY( q.next() == false ); |
|
1546 |
||
1547 |
// test concurrent access |
|
1548 |
q.exec( startTransactionStr ); |
|
1549 |
QVERIFY_SQL( q, exec( "insert into" + qTableName( "qtest" ) + " values (42, 'VarChar42', 'Char42')" ) ); |
|
1550 |
QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 42" ) ); |
|
1551 |
QVERIFY( q.next() ); |
|
1552 |
QCOMPARE( q.value( 0 ).toInt(), 42 ); |
|
1553 |
||
1554 |
QVERIFY_SQL( q2, exec( "select * from" + qTableName( "qtest" ) + " where id = 42" ) ); |
|
1555 |
||
1556 |
if ( q2.next() ) |
|
1557 |
qDebug( QString( "DBMS '%1' doesn't support query based transactions with concurrent access" ).arg( |
|
1558 |
tst_Databases::dbToString( db ) ).toLatin1() ); |
|
1559 |
||
1560 |
QVERIFY_SQL( q, exec( "commit" ) ); |
|
1561 |
||
1562 |
QVERIFY_SQL( q2, exec( "select * from" + qTableName( "qtest" ) + " where id = 42" ) ); |
|
1563 |
||
1564 |
QVERIFY( q2.next() ); |
|
1565 |
||
1566 |
QCOMPARE( q2.value( 0 ).toInt(), 42 ); |
|
1567 |
} |
|
1568 |
||
1569 |
void tst_QSqlQuery::joins() |
|
1570 |
{ |
|
1571 |
QFETCH( QString, dbName ); |
|
1572 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1573 |
CHECK_DATABASE( db ); |
|
1574 |
||
1575 |
if ( db.driverName().startsWith( "QOCI" ) |
|
1576 |
|| db.driverName().startsWith( "QTDS" ) |
|
1577 |
|| db.driverName().startsWith( "QODBC" ) |
|
1578 |
|| db.driverName().startsWith( "QIBASE" ) ) { |
|
1579 |
// Oracle broken beyond recognition - cannot outer join on more than |
|
1580 |
// one table. |
|
1581 |
QSKIP( "DBMS cannot understand standard SQL", SkipSingle ); |
|
1582 |
return; |
|
1583 |
} |
|
1584 |
||
1585 |
QSqlQuery q( db ); |
|
1586 |
||
1587 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtestj1" ) + " (id1 int, id2 int)" ) ); |
|
1588 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtestj2" ) + " (id int, name varchar(20))" ) ); |
|
1589 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtestj1" ) + " values (1, 1)" ) ); |
|
1590 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtestj1" ) + " values (1, 2)" ) ); |
|
1591 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtestj2" ) + " values(1, 'trenton')" ) ); |
|
1592 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtestj2" ) + " values(2, 'marius')" ) ); |
|
1593 |
||
1594 |
QVERIFY_SQL( q, exec( "select qtestj1.id1, qtestj1.id2, qtestj2.id, qtestj2.name, qtestj3.id, qtestj3.name " |
|
1595 |
"from " + qTableName( "qtestj1" ) + " qtestj1 left outer join " + qTableName( "qtestj2" ) + |
|
1596 |
" qtestj2 on (qtestj1.id1 = qtestj2.id) " |
|
1597 |
"left outer join " + qTableName( "qtestj2" ) + " as qtestj3 on (qtestj1.id2 = qtestj3.id)" ) ); |
|
1598 |
||
1599 |
QVERIFY( q.next() ); |
|
1600 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
1601 |
QCOMPARE( q.value( 1 ).toInt(), 1 ); |
|
1602 |
QCOMPARE( q.value( 2 ).toInt(), 1 ); |
|
1603 |
QCOMPARE( q.value( 3 ).toString(), QString( "trenton" ) ); |
|
1604 |
QCOMPARE( q.value( 4 ).toInt(), 1 ); |
|
1605 |
QCOMPARE( q.value( 5 ).toString(), QString( "trenton" ) ); |
|
1606 |
||
1607 |
QVERIFY( q.next() ); |
|
1608 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
1609 |
QCOMPARE( q.value( 1 ).toInt(), 2 ); |
|
1610 |
QCOMPARE( q.value( 2 ).toInt(), 1 ); |
|
1611 |
QCOMPARE( q.value( 3 ).toString(), QString( "trenton" ) ); |
|
1612 |
QCOMPARE( q.value( 4 ).toInt(), 2 ); |
|
1613 |
QCOMPARE( q.value( 5 ).toString(), QString( "marius" ) ); |
|
1614 |
} |
|
1615 |
||
1616 |
void tst_QSqlQuery::synonyms() |
|
1617 |
{ |
|
1618 |
QFETCH( QString, dbName ); |
|
1619 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1620 |
CHECK_DATABASE( db ); |
|
1621 |
||
1622 |
QSqlQuery q(db); |
|
1623 |
QVERIFY_SQL( q, exec("select a.id, a.t_char, a.t_varchar from " + qTableName( "qtest" ) + " a where a.id = 1") ); |
|
1624 |
QVERIFY( q.next() ); |
|
1625 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
1626 |
QCOMPARE( q.value( 1 ).toString().trimmed(), QString( "Char1" ) ); |
|
1627 |
QCOMPARE( q.value( 2 ).toString().trimmed(), QString( "VarChar1" ) ); |
|
1628 |
||
1629 |
QSqlRecord rec = q.record(); |
|
1630 |
QCOMPARE(( int )rec.count(), 3 ); |
|
1631 |
QCOMPARE( rec.field( 0 ).name().toLower(), QString( "id" ) ); |
|
1632 |
QCOMPARE( rec.field( 1 ).name().toLower(), QString( "t_char" ) ); |
|
1633 |
QCOMPARE( rec.field( 2 ).name().toLower(), QString( "t_varchar" ) ); |
|
1634 |
} |
|
1635 |
||
1636 |
// It doesn't make sense to split this into several tests |
|
1637 |
void tst_QSqlQuery::prepare_bind_exec() |
|
1638 |
{ |
|
1639 |
QFETCH( QString, dbName ); |
|
1640 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1641 |
CHECK_DATABASE( db ); |
|
1642 |
if(db.driverName().startsWith("QIBASE") && (db.databaseName() == "silence.nokia.troll.no:c:\\ibase\\testdb_ascii" || db.databaseName() == "/opt/interbase/qttest.gdb")) |
|
1643 |
QSKIP("Can't transliterate extended unicode to ascii", SkipSingle); |
|
1644 |
if(db.driverName().startsWith("QDB2")) |
|
1645 |
QSKIP("Needs someone with more Unicode knowledge than I have to fix", SkipSingle); |
|
1646 |
||
1647 |
{ |
|
1648 |
// new scope for SQLITE |
|
1649 |
static const QString utf8str = QString::fromUtf8( "काचं शक्नोम्यत्तुम् । नोपहिनस्ति माम् ॥" ); |
|
1650 |
||
1651 |
static const QString values[6] = { "Harry", "Trond", "Mark", "Ma?rk", "?", ":id" }; |
|
1652 |
||
1653 |
bool useUnicode = db.driver()->hasFeature( QSqlDriver::Unicode ); |
|
1654 |
||
1655 |
QSqlQuery q( db ); |
|
1656 |
||
1657 |
if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) |
|
1658 |
useUnicode = false; |
|
1659 |
||
1660 |
QString createQuery; |
|
1661 |
||
1662 |
if(tst_Databases::isPostgreSQL(db)) |
|
1663 |
QVERIFY_SQL( q, exec("set client_min_messages='warning'")); |
|
1664 |
||
1665 |
if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QTDS" ) ) |
|
1666 |
createQuery = "create table " + qTableName( "qtest_prepare" ) + " (id int primary key, name nvarchar(200) null)"; |
|
1667 |
else if ( tst_Databases::isMySQL(db) && useUnicode ) |
|
1668 |
createQuery = "create table " + qTableName( "qtest_prepare" ) + " (id int not null primary key, name varchar(200) character set utf8)"; |
|
1669 |
else |
|
1670 |
createQuery = "create table " + qTableName( "qtest_prepare" ) + " (id int not null primary key, name varchar(200))"; |
|
1671 |
||
1672 |
QVERIFY_SQL( q, exec( createQuery ) ); |
|
1673 |
||
1674 |
QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (:id, :name)" ) ); |
|
1675 |
int i; |
|
1676 |
||
1677 |
for ( i = 0; i < 6; ++i ) { |
|
1678 |
q.bindValue( ":name", values[i] ); |
|
1679 |
q.bindValue( ":id", i ); |
|
1680 |
QVERIFY_SQL( q, exec() ); |
|
1681 |
QMap<QString, QVariant> m = q.boundValues(); |
|
1682 |
QCOMPARE(( int ) m.count(), 2 ); |
|
1683 |
QCOMPARE( m[":name"].toString(), values[i] ); |
|
1684 |
QCOMPARE( m[":id"].toInt(), i ); |
|
1685 |
} |
|
1686 |
||
1687 |
q.bindValue( ":id", 8 ); |
|
1688 |
||
1689 |
QVERIFY_SQL( q, exec() ); |
|
1690 |
||
1691 |
if ( useUnicode ) { |
|
1692 |
q.bindValue( ":id", 7 ); |
|
1693 |
q.bindValue( ":name", utf8str ); |
|
1694 |
QVERIFY_SQL( q, exec() ); |
|
1695 |
} |
|
1696 |
||
1697 |
QVERIFY_SQL( q, exec( "SELECT * FROM " + qTableName( "qtest_prepare" ) + " order by id" ) ); |
|
1698 |
||
1699 |
for ( i = 0; i < 6; ++i ) { |
|
1700 |
QVERIFY( q.next() ); |
|
1701 |
QCOMPARE( q.value( 0 ).toInt(), i ); |
|
1702 |
QCOMPARE( q.value( 1 ).toString().trimmed(), values[ i ] ); |
|
1703 |
} |
|
1704 |
||
1705 |
if ( useUnicode ) { |
|
1706 |
QVERIFY_SQL( q, next() ); |
|
1707 |
QCOMPARE( q.value( 0 ).toInt(), 7 ); |
|
1708 |
QCOMPARE( q.value( 1 ).toString(), utf8str ); |
|
1709 |
} |
|
1710 |
||
1711 |
QVERIFY_SQL( q, next() ); |
|
1712 |
||
1713 |
QCOMPARE( q.value( 0 ).toInt(), 8 ); |
|
1714 |
QCOMPARE( q.value( 1 ).toString(), values[5] ); |
|
1715 |
||
1716 |
QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (:id, 'Bart')" ) ); |
|
1717 |
q.bindValue( ":id", 99 ); |
|
1718 |
QVERIFY_SQL( q, exec() ); |
|
1719 |
q.bindValue( ":id", 100 ); |
|
1720 |
QVERIFY_SQL( q, exec() ); |
|
1721 |
QVERIFY( q.exec( "select * from " + qTableName( "qtest_prepare" ) + " where id > 98 order by id" ) ); |
|
1722 |
||
1723 |
for ( i = 99; i <= 100; ++i ) { |
|
1724 |
QVERIFY( q.next() ); |
|
1725 |
QCOMPARE( q.value( 0 ).toInt(), i ); |
|
1726 |
QCOMPARE( q.value( 1 ).toString().trimmed(), QString( "Bart" ) ); |
|
1727 |
} |
|
1728 |
||
1729 |
/*** SELECT stuff ***/ |
|
1730 |
QVERIFY( q.prepare( "select * from " + qTableName( "qtest_prepare" ) + " where id = :id" ) ); |
|
1731 |
||
1732 |
for ( i = 0; i < 6; ++i ) { |
|
1733 |
q.bindValue( ":id", i ); |
|
1734 |
QVERIFY_SQL( q, exec() ); |
|
1735 |
QVERIFY_SQL( q, next() ); |
|
1736 |
QCOMPARE( q.value( 0 ).toInt(), i ); |
|
1737 |
QCOMPARE( q.value( 1 ).toString().trimmed(), values[ i ] ); |
|
1738 |
QSqlRecord rInf = q.record(); |
|
1739 |
QCOMPARE(( int )rInf.count(), 2 ); |
|
1740 |
QCOMPARE( rInf.field( 0 ).name().toUpper(), QString( "ID" ) ); |
|
1741 |
QCOMPARE( rInf.field( 1 ).name().toUpper(), QString( "NAME" ) ); |
|
1742 |
QVERIFY( !q.next() ); |
|
1743 |
} |
|
1744 |
||
1745 |
QVERIFY_SQL( q, exec( "DELETE FROM " + qTableName( "qtest_prepare" ) ) ); |
|
1746 |
||
1747 |
QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (?, ?)" ) ); |
|
1748 |
q.bindValue( 0, 0 ); |
|
1749 |
q.bindValue( 1, values[ 0 ] ); |
|
1750 |
QVERIFY_SQL( q, exec() ); |
|
1751 |
q.addBindValue( 1 ); |
|
1752 |
q.addBindValue( values[ 1 ] ); |
|
1753 |
QVERIFY_SQL( q, exec() ); |
|
1754 |
q.addBindValue( 2 ); |
|
1755 |
q.addBindValue( values[ 2 ] ); |
|
1756 |
QVERIFY_SQL( q, exec() ); |
|
1757 |
q.addBindValue( 3 ); |
|
1758 |
q.addBindValue( values[ 3 ] ); |
|
1759 |
QVERIFY_SQL( q, exec() ); |
|
1760 |
q.addBindValue( 4 ); |
|
1761 |
q.addBindValue( values[ 4 ] ); |
|
1762 |
QVERIFY_SQL( q, exec() ); |
|
1763 |
q.bindValue( 1, values[ 5 ] ); |
|
1764 |
q.bindValue( 0, 5 ); |
|
1765 |
QVERIFY_SQL( q, exec() ); |
|
1766 |
q.bindValue( 0, 6 ); |
|
1767 |
q.bindValue( 1, QString() ); |
|
1768 |
QVERIFY_SQL( q, exec() ); |
|
1769 |
||
1770 |
if ( db.driver()->hasFeature( QSqlDriver::Unicode ) ) { |
|
1771 |
q.bindValue( 0, 7 ); |
|
1772 |
q.bindValue( 1, utf8str ); |
|
1773 |
QVERIFY_SQL( q, exec() ); |
|
1774 |
} |
|
1775 |
||
1776 |
QVERIFY_SQL( q, exec( "SELECT * FROM " + qTableName( "qtest_prepare" ) + " order by id" ) ); |
|
1777 |
||
1778 |
for ( i = 0; i < 6; ++i ) { |
|
1779 |
QVERIFY( q.next() ); |
|
1780 |
QCOMPARE( q.value( 0 ).toInt(), i ); |
|
1781 |
QCOMPARE( q.value( 1 ).toString().trimmed(), values[ i ] ); |
|
1782 |
} |
|
1783 |
||
1784 |
QVERIFY( q.next() ); |
|
1785 |
||
1786 |
QCOMPARE( q.value( 0 ).toInt(), 6 ); |
|
1787 |
QVERIFY( q.isNull( 1 ) ); |
|
1788 |
||
1789 |
if ( useUnicode ) { |
|
1790 |
QVERIFY( q.next() ); |
|
1791 |
QCOMPARE( q.value( 0 ).toInt(), 7 ); |
|
1792 |
QCOMPARE( q.value( 1 ).toString(), utf8str ); |
|
1793 |
} |
|
1794 |
||
1795 |
QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (?, 'Bart')" ) ); |
|
1796 |
||
1797 |
q.bindValue( 0, 99 ); |
|
1798 |
QVERIFY_SQL( q, exec() ); |
|
1799 |
q.addBindValue( 100 ); |
|
1800 |
QVERIFY_SQL( q, exec() ); |
|
1801 |
QVERIFY( q.exec( "select * from " + qTableName( "qtest_prepare" ) + " where id > 98 order by id" ) ); |
|
1802 |
||
1803 |
for ( i = 99; i <= 100; ++i ) { |
|
1804 |
QVERIFY( q.next() ); |
|
1805 |
QCOMPARE( q.value( 0 ).toInt(), i ); |
|
1806 |
QCOMPARE( q.value( 1 ).toString().trimmed(), QString( "Bart" ) ); |
|
1807 |
} |
|
1808 |
||
1809 |
/* insert a duplicate id and make sure the db bails out */ |
|
1810 |
QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (?, ?)" ) ); |
|
1811 |
||
1812 |
q.addBindValue( 99 ); |
|
1813 |
||
1814 |
q.addBindValue( "something silly" ); |
|
1815 |
||
1816 |
QVERIFY( !q.exec() ); |
|
1817 |
||
1818 |
QVERIFY( q.lastError().isValid() ); |
|
1819 |
||
1820 |
QVERIFY( !q.isActive() ); |
|
1821 |
||
1822 |
} // end of SQLite scope |
|
1823 |
} |
|
1824 |
||
1825 |
void tst_QSqlQuery::prepared_select() |
|
1826 |
{ |
|
1827 |
QFETCH( QString, dbName ); |
|
1828 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1829 |
CHECK_DATABASE( db ); |
|
1830 |
||
1831 |
QSqlQuery q( db ); |
|
1832 |
QVERIFY_SQL( q, prepare( "select a.id, a.t_char, a.t_varchar from " + qTableName( "qtest" ) + " a where a.id = ?" ) ); |
|
1833 |
||
1834 |
q.bindValue( 0, 1 ); |
|
1835 |
QVERIFY_SQL( q, exec() ); |
|
1836 |
QCOMPARE( q.at(), ( int )QSql::BeforeFirstRow ); |
|
1837 |
QVERIFY( q.next() ); |
|
1838 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
1839 |
||
1840 |
q.bindValue( 0, 2 ); |
|
1841 |
QVERIFY_SQL( q, exec() ); |
|
1842 |
QCOMPARE( q.at(), ( int )QSql::BeforeFirstRow ); |
|
1843 |
QVERIFY( q.next() ); |
|
1844 |
QCOMPARE( q.value( 0 ).toInt(), 2 ); |
|
1845 |
||
1846 |
q.bindValue( 0, 3 ); |
|
1847 |
QVERIFY_SQL( q, exec() ); |
|
1848 |
QCOMPARE( q.at(), ( int )QSql::BeforeFirstRow ); |
|
1849 |
QVERIFY( q.next() ); |
|
1850 |
QCOMPARE( q.value( 0 ).toInt(), 3 ); |
|
1851 |
||
1852 |
QVERIFY_SQL( q, prepare( "select a.id, a.t_char, a.t_varchar from " + qTableName( "qtest" ) + " a where a.id = ?" ) ); |
|
1853 |
QCOMPARE( q.at(), ( int )QSql::BeforeFirstRow ); |
|
1854 |
QVERIFY( !q.first() ); |
|
1855 |
} |
|
1856 |
||
1857 |
void tst_QSqlQuery::sqlServerLongStrings() |
|
1858 |
{ |
|
1859 |
QFETCH( QString, dbName ); |
|
1860 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1861 |
CHECK_DATABASE( db ); |
|
1862 |
||
1863 |
if ( !tst_Databases::isSqlServer( db ) ) |
|
1864 |
QSKIP( "SQL Server specific test", SkipSingle ); |
|
1865 |
||
1866 |
QSqlQuery q( db ); |
|
1867 |
||
1868 |
QVERIFY_SQL( q, exec( "CREATE TABLE " + qTableName( "qtest_longstr" ) + " (id int primary key, longstring ntext)" ) ); |
|
1869 |
||
1870 |
QVERIFY_SQL( q, prepare( "INSERT INTO " + qTableName( "qtest_longstr" ) + " VALUES (?, ?)" ) ); |
|
1871 |
||
1872 |
q.addBindValue( 0 ); |
|
1873 |
||
1874 |
q.addBindValue( QString::fromLatin1( "bubu" ) ); |
|
1875 |
||
1876 |
QVERIFY_SQL( q, exec() ); |
|
1877 |
||
1878 |
QString testStr; |
|
1879 |
||
1880 |
testStr.fill( QLatin1Char( 'a' ), 85000 ); |
|
1881 |
||
1882 |
q.addBindValue( 1 ); |
|
1883 |
||
1884 |
q.addBindValue( testStr ); |
|
1885 |
||
1886 |
QVERIFY_SQL( q, exec() ); |
|
1887 |
||
1888 |
QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_longstr" ) ) ); |
|
1889 |
||
1890 |
QVERIFY_SQL( q, next() ); |
|
1891 |
||
1892 |
QCOMPARE( q.value( 0 ).toInt(), 0 ); |
|
1893 |
||
1894 |
QCOMPARE( q.value( 1 ).toString(), QString::fromLatin1( "bubu" ) ); |
|
1895 |
||
1896 |
QVERIFY_SQL( q, next() ); |
|
1897 |
||
1898 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
1899 |
||
1900 |
QCOMPARE( q.value( 1 ).toString(), testStr ); |
|
1901 |
} |
|
1902 |
||
1903 |
void tst_QSqlQuery::invalidQuery() |
|
1904 |
{ |
|
1905 |
QFETCH( QString, dbName ); |
|
1906 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1907 |
CHECK_DATABASE( db ); |
|
1908 |
||
1909 |
QSqlQuery q( db ); |
|
1910 |
||
1911 |
QVERIFY( !q.exec() ); |
|
1912 |
||
1913 |
QVERIFY( !q.exec( "blahfasel" ) ); |
|
1914 |
QVERIFY( q.lastError().type() != QSqlError::NoError ); |
|
1915 |
QVERIFY( !q.next() ); |
|
1916 |
QVERIFY( !q.isActive() ); |
|
1917 |
||
1918 |
if ( !db.driverName().startsWith( "QOCI" ) && !db.driverName().startsWith( "QDB2" ) && !db.driverName().startsWith( "QODBC" ) ) { |
|
1919 |
// oracle and db2 just prepares everything without complaining |
|
1920 |
if ( db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) |
|
1921 |
QVERIFY( !q.prepare( "blahfasel" ) ); |
|
1922 |
} |
|
1923 |
||
1924 |
QVERIFY( !q.exec() ); |
|
1925 |
||
1926 |
QVERIFY( !q.isActive() ); |
|
1927 |
QVERIFY( !q.next() ); |
|
1928 |
} |
|
1929 |
||
1930 |
class ResultHelper: public QSqlResult |
|
1931 |
{ |
|
1932 |
||
1933 |
public: |
|
1934 |
ResultHelper(): QSqlResult( 0 ) {} // don't call, it's only for stupid compilers |
|
1935 |
||
1936 |
bool execBatch( bool bindArray = false ) |
|
1937 |
{ |
|
1938 |
return QSqlResult::execBatch( bindArray ); |
|
1939 |
} |
|
1940 |
}; |
|
1941 |
||
1942 |
void tst_QSqlQuery::batchExec() |
|
1943 |
{ |
|
1944 |
QFETCH( QString, dbName ); |
|
1945 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
1946 |
CHECK_DATABASE( db ); |
|
1947 |
||
1948 |
if ( !db.driver()->hasFeature( QSqlDriver::BatchOperations ) ) |
|
1949 |
QSKIP( "Database can't do BatchOperations", SkipSingle ); |
|
1950 |
||
1951 |
QSqlQuery q( db ); |
|
1952 |
QString tableName = qTableName( "qtest_batch" ); |
|
1953 |
||
1954 |
QVERIFY_SQL( q, exec( "create table " + tableName + " (id int, name varchar(20), dt date, num numeric(8, 4))" ) ); |
|
1955 |
QVERIFY_SQL( q, prepare( "insert into " + tableName + " (id, name, dt, num) values (?, ?, ?, ?)" ) ); |
|
1956 |
||
1957 |
QVariantList intCol; |
|
1958 |
intCol << 1 << 2 << QVariant( QVariant::Int ); |
|
1959 |
||
1960 |
QVariantList charCol; |
|
1961 |
charCol << QLatin1String( "harald" ) << QLatin1String( "boris" ) << QVariant( QVariant::String ); |
|
1962 |
||
1963 |
QVariantList dateCol; |
|
1964 |
QDateTime dt = QDateTime( QDate::currentDate(), QTime( 1, 2, 3 ) ); |
|
1965 |
dateCol << dt << dt.addDays( -1 ) << QVariant( QVariant::DateTime ); |
|
1966 |
||
1967 |
QVariantList numCol; |
|
1968 |
numCol << 2.3 << 3.4 << QVariant( QVariant::Double ); |
|
1969 |
||
1970 |
q.addBindValue( intCol ); |
|
1971 |
q.addBindValue( charCol ); |
|
1972 |
q.addBindValue( dateCol ); |
|
1973 |
q.addBindValue( numCol ); |
|
1974 |
||
1975 |
QVERIFY_SQL( q, execBatch() ); |
|
1976 |
QVERIFY_SQL( q, exec( "select id, name, dt, num from " + tableName + " order by id" ) ); |
|
1977 |
||
1978 |
QVERIFY( q.next() ); |
|
1979 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
1980 |
QCOMPARE( q.value( 1 ).toString(), QString( "harald" ) ); |
|
1981 |
QCOMPARE( q.value( 2 ).toDateTime(), dt ); |
|
1982 |
QCOMPARE( q.value( 3 ).toDouble(), 2.3 ); |
|
1983 |
||
1984 |
QVERIFY( q.next() ); |
|
1985 |
QCOMPARE( q.value( 0 ).toInt(), 2 ); |
|
1986 |
QCOMPARE( q.value( 1 ).toString(), QString( "boris" ) ); |
|
1987 |
QCOMPARE( q.value( 2 ).toDateTime(), dt.addDays( -1 ) ); |
|
1988 |
QCOMPARE( q.value( 3 ).toDouble(), 3.4 ); |
|
1989 |
||
1990 |
QVERIFY( q.next() ); |
|
1991 |
QVERIFY( q.value( 0 ).isNull() ); |
|
1992 |
QVERIFY( q.value( 1 ).isNull() ); |
|
1993 |
QVERIFY( q.value( 2 ).isNull() ); |
|
1994 |
QVERIFY( q.value( 3 ).isNull() ); |
|
1995 |
} |
|
1996 |
||
1997 |
void tst_QSqlQuery::oraArrayBind() |
|
1998 |
{ |
|
1999 |
QFETCH( QString, dbName ); |
|
2000 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2001 |
CHECK_DATABASE( db ); |
|
2002 |
||
2003 |
if ( !db.driver()->hasFeature( QSqlDriver::BatchOperations ) ) |
|
2004 |
QSKIP( "Database can't do BatchOperations", SkipSingle ); |
|
2005 |
||
2006 |
QSqlQuery q( db ); |
|
2007 |
||
2008 |
QVERIFY_SQL( q, exec( "CREATE OR REPLACE PACKAGE ora_array_test " |
|
2009 |
"IS " |
|
2010 |
"TYPE names_type IS TABLE OF VARCHAR(64) NOT NULL INDEX BY BINARY_INTEGER; " |
|
2011 |
"names_tab names_type; " |
|
2012 |
"PROCEDURE set_name(name_in IN VARCHAR2, row_in in INTEGER); " |
|
2013 |
"PROCEDURE get_name(row_in IN INTEGER, str_out OUT VARCHAR2); " |
|
2014 |
"PROCEDURE get_table(tbl OUT names_type); " |
|
2015 |
"PROCEDURE set_table(tbl IN names_type); " |
|
2016 |
"END ora_array_test; " ) ); |
|
2017 |
||
2018 |
QVERIFY_SQL( q, exec( "CREATE OR REPLACE PACKAGE BODY ora_array_test " |
|
2019 |
"IS " |
|
2020 |
"PROCEDURE set_name(name_in IN VARCHAR2, row_in in INTEGER) " |
|
2021 |
"IS " |
|
2022 |
"BEGIN " |
|
2023 |
"names_tab(row_in) := name_in; " |
|
2024 |
"END set_name; " |
|
2025 |
||
2026 |
"PROCEDURE get_name(row_in IN INTEGER, str_out OUT VARCHAR2) " |
|
2027 |
"IS " |
|
2028 |
"BEGIN " |
|
2029 |
"str_out := names_tab(row_in); " |
|
2030 |
"END get_name; " |
|
2031 |
||
2032 |
"PROCEDURE get_table(tbl OUT names_type) " |
|
2033 |
"IS " |
|
2034 |
"BEGIN " |
|
2035 |
"tbl:=names_tab; " |
|
2036 |
"END get_table; " |
|
2037 |
||
2038 |
"PROCEDURE set_table(tbl IN names_type) " |
|
2039 |
"IS " |
|
2040 |
"BEGIN " |
|
2041 |
"names_tab := tbl; " |
|
2042 |
"END set_table; " |
|
2043 |
"END ora_array_test; " ) ); |
|
2044 |
||
2045 |
QVariantList list; |
|
2046 |
||
2047 |
list << QString( "lorem" ) << QString( "ipsum" ) << QString( "dolor" ) << QString( "sit" ) << QString( "amet" ); |
|
2048 |
||
2049 |
QVERIFY_SQL( q, prepare( "BEGIN " |
|
2050 |
"ora_array_test.set_table(?); " |
|
2051 |
"END;" ) ); |
|
2052 |
||
2053 |
q.bindValue( 0, list, QSql::In ); |
|
2054 |
||
2055 |
QVERIFY_SQL( q, execBatch( QSqlQuery::ValuesAsColumns ) ); |
|
2056 |
||
2057 |
QVERIFY_SQL( q, prepare( "BEGIN " |
|
2058 |
"ora_array_test.get_table(?); " |
|
2059 |
"END;" ) ); |
|
2060 |
||
2061 |
list.clear(); |
|
2062 |
||
2063 |
list << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ); |
|
2064 |
||
2065 |
q.bindValue( 0, list, QSql::Out ); |
|
2066 |
||
2067 |
QVERIFY_SQL( q, execBatch( QSqlQuery::ValuesAsColumns ) ); |
|
2068 |
||
2069 |
QVariantList out_list = q.boundValue( 0 ).toList(); |
|
2070 |
||
2071 |
QCOMPARE( out_list.at( 0 ).toString(), QString( "lorem" ) ); |
|
2072 |
||
2073 |
QCOMPARE( out_list.at( 1 ).toString(), QString( "ipsum" ) ); |
|
2074 |
||
2075 |
QCOMPARE( out_list.at( 2 ).toString(), QString( "dolor" ) ); |
|
2076 |
||
2077 |
QCOMPARE( out_list.at( 3 ).toString(), QString( "sit" ) ); |
|
2078 |
||
2079 |
QCOMPARE( out_list.at( 4 ).toString(), QString( "amet" ) ); |
|
2080 |
||
2081 |
QVERIFY_SQL( q, exec( "DROP PACKAGE ora_array_test" ) ); |
|
2082 |
} |
|
2083 |
||
2084 |
/* |
|
2085 |
Tests that QSqlDatabase::record and QSqlQuery::record returns the same thing |
|
2086 |
otherwise our models get confused. |
|
2087 |
*/ |
|
2088 |
void tst_QSqlQuery::record_sqlite() |
|
2089 |
{ |
|
2090 |
QFETCH( QString, dbName ); |
|
2091 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2092 |
CHECK_DATABASE( db ); |
|
2093 |
||
2094 |
QSqlQuery q( db ); |
|
2095 |
||
2096 |
QVERIFY_SQL( q, exec( "create table "+qTableName( "record_sqlite" )+"(id integer primary key, name varchar, title int)" ) ); |
|
2097 |
||
2098 |
QSqlRecord rec = db.record( qTableName( "record_sqlite" ) ); |
|
2099 |
||
2100 |
QCOMPARE( rec.count(), 3 ); |
|
2101 |
QCOMPARE( rec.field( 0 ).type(), QVariant::Int ); |
|
2102 |
QCOMPARE( rec.field( 1 ).type(), QVariant::String ); |
|
2103 |
QCOMPARE( rec.field( 2 ).type(), QVariant::Int ); |
|
2104 |
||
2105 |
/* important - select from an empty table */ |
|
2106 |
QVERIFY_SQL( q, exec( "select id, name, title from "+qTableName( "record_sqlite" ) ) ); |
|
2107 |
||
2108 |
rec = q.record(); |
|
2109 |
QCOMPARE( rec.count(), 3 ); |
|
2110 |
QCOMPARE( rec.field( 0 ).type(), QVariant::Int ); |
|
2111 |
QCOMPARE( rec.field( 1 ).type(), QVariant::String ); |
|
2112 |
QCOMPARE( rec.field( 2 ).type(), QVariant::Int ); |
|
2113 |
} |
|
2114 |
||
2115 |
void tst_QSqlQuery::oraLong() |
|
2116 |
{ |
|
2117 |
QFETCH( QString, dbName ); |
|
2118 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2119 |
CHECK_DATABASE( db ); |
|
2120 |
||
2121 |
QSqlQuery q( db ); |
|
2122 |
||
2123 |
QString aLotOfText( 127000, QLatin1Char( 'H' ) ); |
|
2124 |
||
2125 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_longstr" ) + " (id int primary key, astr long)" ) ); |
|
2126 |
QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_longstr" ) + " (id, astr) values (?, ?)" ) ); |
|
2127 |
q.addBindValue( 1 ); |
|
2128 |
q.addBindValue( aLotOfText ); |
|
2129 |
QVERIFY_SQL( q, exec() ); |
|
2130 |
||
2131 |
QVERIFY_SQL( q, exec( "select id,astr from " + qTableName( "qtest_longstr" ) ) ); |
|
2132 |
||
2133 |
QVERIFY( q.next() ); |
|
2134 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
2135 |
QCOMPARE( q.value( 1 ).toString(), aLotOfText ); |
|
2136 |
} |
|
2137 |
||
2138 |
void tst_QSqlQuery::execErrorRecovery() |
|
2139 |
{ |
|
2140 |
QFETCH( QString, dbName ); |
|
2141 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2142 |
CHECK_DATABASE( db ); |
|
2143 |
||
2144 |
QSqlQuery q( db ); |
|
2145 |
||
2146 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_exerr" ) + " (id int not null primary key)" ) ); |
|
2147 |
QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_exerr" ) + " values (?)" ) ); |
|
2148 |
||
2149 |
q.addBindValue( 1 ); |
|
2150 |
QVERIFY_SQL( q, exec() ); |
|
2151 |
||
2152 |
q.addBindValue( 1 ); // binding the same pkey - should fail |
|
2153 |
QVERIFY( !q.exec() ); |
|
2154 |
||
2155 |
q.addBindValue( 2 ); // this should work again |
|
2156 |
QVERIFY_SQL( q, exec() ); |
|
2157 |
} |
|
2158 |
||
2159 |
void tst_QSqlQuery::lastInsertId() |
|
2160 |
{ |
|
2161 |
QFETCH( QString, dbName ); |
|
2162 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2163 |
CHECK_DATABASE( db ); |
|
2164 |
||
2165 |
if ( !db.driver()->hasFeature( QSqlDriver::LastInsertId ) ) |
|
2166 |
QSKIP( "Database doesn't support lastInsertId", SkipSingle ); |
|
2167 |
||
2168 |
QSqlQuery q( db ); |
|
2169 |
||
2170 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (41, 'VarChar41', 'Char41')" ) ); |
|
2171 |
||
2172 |
QVariant v = q.lastInsertId(); |
|
2173 |
||
2174 |
QVERIFY( v.isValid() ); |
|
2175 |
} |
|
2176 |
||
2177 |
void tst_QSqlQuery::lastQuery() |
|
2178 |
{ |
|
2179 |
QFETCH( QString, dbName ); |
|
2180 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2181 |
CHECK_DATABASE( db ); |
|
2182 |
||
2183 |
QSqlQuery q( db ); |
|
2184 |
QString sql = "select * from " + qTableName( "qtest" ); |
|
2185 |
QVERIFY_SQL( q, exec( sql ) ); |
|
2186 |
QCOMPARE( q.lastQuery(), sql ); |
|
2187 |
QCOMPARE( q.executedQuery(), sql ); |
|
2188 |
} |
|
2189 |
||
2190 |
void tst_QSqlQuery::bindWithDoubleColonCastOperator() |
|
2191 |
{ |
|
2192 |
QFETCH( QString, dbName ); |
|
2193 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2194 |
CHECK_DATABASE( db ); |
|
2195 |
||
2196 |
// Only PostgreSQL support the double-colon cast operator |
|
2197 |
||
2198 |
if ( !db.driverName().startsWith( "QPSQL" ) ) { |
|
2199 |
QSKIP( "Test requires PostgreSQL", SkipSingle ); |
|
2200 |
return; |
|
2201 |
} |
|
2202 |
||
2203 |
QString tablename = qTableName( "bindtest" ); |
|
2204 |
||
2205 |
QSqlQuery q( db ); |
|
2206 |
||
2207 |
QVERIFY_SQL( q, exec( "create table " + tablename + " (id1 int, id2 int, id3 int, fld1 int, fld2 int)" ) ); |
|
2208 |
QVERIFY_SQL( q, exec( "insert into " + tablename + " values (1, 2, 3, 10, 5)" ) ); |
|
2209 |
||
2210 |
QVERIFY_SQL( q, prepare( "select sum((fld1 - fld2)::int) from " + tablename + " where id1 = :myid1 and id2 =:myid2 and id3=:myid3" ) ); |
|
2211 |
q.bindValue( ":myid1", 1 ); |
|
2212 |
q.bindValue( ":myid2", 2 ); |
|
2213 |
q.bindValue( ":myid3", 3 ); |
|
2214 |
||
2215 |
QVERIFY_SQL( q, exec() ); |
|
2216 |
QVERIFY_SQL( q, next() ); |
|
2217 |
||
2218 |
if ( db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) |
|
2219 |
QCOMPARE( q.executedQuery(), QString( "select sum((fld1 - fld2)::int) from " + tablename + " where id1 = ? and id2 =? and id3=?" ) ); |
|
2220 |
else |
|
2221 |
QCOMPARE( q.executedQuery(), QString( "select sum((fld1 - fld2)::int) from " + tablename + " where id1 = 1 and id2 =2 and id3=3" ) ); |
|
2222 |
} |
|
2223 |
||
2224 |
/* For task 157397: Using QSqlQuery with an invalid QSqlDatabase |
|
2225 |
does not set the last error of the query. |
|
2226 |
This test function will output some warnings, that's ok. |
|
2227 |
*/ |
|
2228 |
void tst_QSqlQuery::queryOnInvalidDatabase() |
|
2229 |
{ |
|
2230 |
{ |
|
2231 |
QTest::ignoreMessage( QtWarningMsg, "QSqlDatabase: INVALID driver not loaded" ); |
|
2232 |
QSqlDatabase db = QSqlDatabase::addDatabase( "INVALID", "invalidConnection" ); |
|
2233 |
QVERIFY2( db.lastError().isValid(), |
|
2234 |
qPrintable( QString( "db.lastError().isValid() should be true!" ) ) ); |
|
2235 |
||
2236 |
QTest::ignoreMessage( QtWarningMsg, "QSqlQuery::exec: database not open" ); |
|
2237 |
QSqlQuery query( "SELECT 1 AS ID", db ); |
|
2238 |
QVERIFY2( query.lastError().isValid(), |
|
2239 |
qPrintable( QString( "query.lastError().isValid() should be true!" ) ) ); |
|
2240 |
} |
|
2241 |
||
2242 |
QSqlDatabase::removeDatabase( "invalidConnection" ); |
|
2243 |
||
2244 |
{ |
|
2245 |
QSqlDatabase db = QSqlDatabase::database( "this connection does not exist" ); |
|
2246 |
QTest::ignoreMessage( QtWarningMsg, "QSqlQuery::exec: database not open" ); |
|
2247 |
QSqlQuery query( "SELECT 1 AS ID", db ); |
|
2248 |
QVERIFY2( query.lastError().isValid(), |
|
2249 |
qPrintable( QString( "query.lastError().isValid() should be true!" ) ) ); |
|
2250 |
} |
|
2251 |
} |
|
2252 |
||
2253 |
/* For task 159138: Error on instantiating a sql-query before explicitly |
|
2254 |
opening the database. This is something we don't support, so this isn't |
|
2255 |
really a bug. However some of the drivers are nice enough to support it. |
|
2256 |
*/ |
|
2257 |
void tst_QSqlQuery::createQueryOnClosedDatabase() |
|
2258 |
{ |
|
2259 |
QFETCH( QString, dbName ); |
|
2260 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2261 |
CHECK_DATABASE( db ); |
|
2262 |
||
2263 |
// Only supported by these drivers |
|
2264 |
||
2265 |
if ( !db.driverName().startsWith( "QPSQL" ) |
|
2266 |
&& !db.driverName().startsWith( "QOCI" ) |
|
2267 |
&& !db.driverName().startsWith( "QMYSQL" ) |
|
2268 |
&& !db.driverName().startsWith( "QDB2" ) ) { |
|
2269 |
QSKIP( "Test is specific for PostgreSQL, Oracle, MySql and DB2", SkipSingle ); |
|
2270 |
return; |
|
2271 |
} |
|
2272 |
||
2273 |
db.close(); |
|
2274 |
||
2275 |
QSqlQuery q( db ); |
|
2276 |
db.open(); |
|
2277 |
QVERIFY_SQL( q, exec( QString( "select * from %1 where id = 1" ).arg( qTableName( "qtest" ) ) ) ); |
|
2278 |
||
2279 |
QVERIFY_SQL( q, next() ); |
|
2280 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
2281 |
QCOMPARE( q.value( 1 ).toString().trimmed(), QLatin1String( "VarChar1" ) ); |
|
2282 |
QCOMPARE( q.value( 2 ).toString().trimmed(), QLatin1String( "Char1" ) ); |
|
2283 |
||
2284 |
db.close(); |
|
2285 |
QVERIFY2( !q.exec( QString( "select * from %1 where id = 1" ).arg( qTableName( "qtest" ) ) ), |
|
2286 |
qPrintable( QString( "This can't happen! The query should not have been executed!" ) ) ); |
|
2287 |
} |
|
2288 |
||
2289 |
void tst_QSqlQuery::reExecutePreparedForwardOnlyQuery() |
|
2290 |
{ |
|
2291 |
QFETCH( QString, dbName ); |
|
2292 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2293 |
CHECK_DATABASE( db ); |
|
2294 |
||
2295 |
QSqlQuery q( db ); |
|
2296 |
q.setForwardOnly( true ); |
|
2297 |
||
2298 |
QVERIFY_SQL( q, prepare( QString( "SELECT id, t_varchar, t_char FROM %1 WHERE id = :id" ).arg( qTableName( "qtest" ) ) ) ); |
|
2299 |
q.bindValue( ":id", 1 ); |
|
2300 |
QVERIFY_SQL( q, exec() ); |
|
2301 |
||
2302 |
// Do something, like iterate over the result, or skip to the end |
|
2303 |
QVERIFY_SQL( q, last() ); |
|
2304 |
||
2305 |
QVERIFY_SQL( q, exec() ); |
|
2306 |
/* This was broken with SQLite because the cache size was set to 0 in the 2nd execute. |
|
2307 |
When forwardOnly is set we don't cahce the entire result, but we do cache the current row |
|
2308 |
but this requires the cache size to be equal to the column count. |
|
2309 |
*/ |
|
2310 |
QVERIFY_SQL( q, next() ); |
|
2311 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
2312 |
QCOMPARE( q.value( 1 ).toString().trimmed(), QString( "VarChar1" ) ); |
|
2313 |
QCOMPARE( q.value( 2 ).toString().trimmed(), QString( "Char1" ) ); |
|
2314 |
} |
|
2315 |
||
2316 |
void tst_QSqlQuery::finish() |
|
2317 |
{ |
|
2318 |
QFETCH( QString, dbName ); |
|
2319 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2320 |
CHECK_DATABASE( db ); |
|
2321 |
||
2322 |
QSqlQuery q( db ); |
|
2323 |
QVERIFY_SQL( q, prepare( "SELECT id FROM " + qTableName( "qtest" ) + " WHERE id = ?" ) ); |
|
2324 |
||
2325 |
int id = 4; |
|
2326 |
q.bindValue( 0, id ); |
|
2327 |
QVERIFY_SQL( q, exec() ); |
|
2328 |
QVERIFY( q.isActive() ); |
|
2329 |
QVERIFY_SQL( q, next() ); |
|
2330 |
QCOMPARE( q.value( 0 ).toInt(), id ); |
|
2331 |
||
2332 |
q.finish(); |
|
2333 |
QVERIFY( !q.isActive() ); // query is now inactive |
|
2334 |
QCOMPARE( q.boundValue( 0 ).toInt(), id ); // bound values are retained |
|
2335 |
||
2336 |
QVERIFY_SQL( q, exec() ); // no prepare necessary |
|
2337 |
QVERIFY( q.isActive() ); |
|
2338 |
QVERIFY_SQL( q, next() ); |
|
2339 |
QCOMPARE( q.value( 0 ).toInt(), id ); |
|
2340 |
||
2341 |
q.finish(); |
|
2342 |
QVERIFY( !q.isActive() ); |
|
2343 |
||
2344 |
QVERIFY_SQL( q, exec( "SELECT id FROM " + qTableName( "qtest" ) + " WHERE id = 1" ) ); |
|
2345 |
QVERIFY( q.isActive() ); |
|
2346 |
QVERIFY_SQL( q, next() ); |
|
2347 |
QCOMPARE( q.value( 0 ).toInt(), 1 ); |
|
2348 |
QCOMPARE( q.record().count(), 1 ); |
|
2349 |
} |
|
2350 |
||
2351 |
void tst_QSqlQuery::sqlite_finish() |
|
2352 |
{ |
|
2353 |
QFETCH( QString, dbName ); |
|
2354 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2355 |
CHECK_DATABASE( db ); |
|
2356 |
if (db.driverName() != QLatin1String("QSQLITE")) { |
|
2357 |
QSKIP("Sqlite3 specific test", SkipSingle); |
|
2358 |
return; |
|
2359 |
} |
|
2360 |
||
2361 |
if ( db.databaseName().startsWith( ':' ) ) |
|
2362 |
QSKIP( "This test requires a database on the filesystem, not in-memory", SkipAll ); |
|
2363 |
||
2364 |
{ |
|
2365 |
QSqlDatabase db2 = QSqlDatabase::addDatabase( "QSQLITE", "sqlite_finish_sqlite" ); |
|
2366 |
db2.setDatabaseName( db.databaseName() ); |
|
2367 |
QVERIFY_SQL( db2, open() ); |
|
2368 |
||
2369 |
QString tableName = qTableName( "qtest_lockedtable" ); |
|
2370 |
QSqlQuery q( db ); |
|
2371 |
||
2372 |
tst_Databases::safeDropTable( db, tableName ); |
|
2373 |
q.exec( "CREATE TABLE " + tableName + " (pk_id INTEGER PRIMARY KEY, whatever TEXT)" ); |
|
2374 |
q.exec( "INSERT INTO " + tableName + " values(1, 'whatever')" ); |
|
2375 |
q.exec( "INSERT INTO " + tableName + " values(2, 'whatever more')" ); |
|
2376 |
||
2377 |
// This creates a read-lock in the database |
|
2378 |
QVERIFY_SQL( q, exec( "SELECT * FROM " + tableName + " WHERE pk_id = 1 or pk_id = 2" ) ); |
|
2379 |
QVERIFY_SQL( q, next() ); |
|
2380 |
||
2381 |
// The DELETE will fail because of the read-lock |
|
2382 |
QSqlQuery q2( db2 ); |
|
2383 |
QVERIFY( !q2.exec( "DELETE FROM " + tableName + " WHERE pk_id=2" ) ); |
|
2384 |
QCOMPARE( q2.numRowsAffected(), -1 ); |
|
2385 |
||
2386 |
// The DELETE will succeed now because finish() removes the lock |
|
2387 |
q.finish(); |
|
2388 |
QVERIFY_SQL( q2, exec( "DELETE FROM " + tableName + " WHERE pk_id=2" ) ); |
|
2389 |
QCOMPARE( q2.numRowsAffected(), 1 ); |
|
2390 |
||
2391 |
tst_Databases::safeDropTable( db, tableName ); |
|
2392 |
} |
|
2393 |
||
2394 |
QSqlDatabase::removeDatabase( "sqlite_finish_sqlite" ); |
|
2395 |
} |
|
2396 |
||
2397 |
void tst_QSqlQuery::nextResult() |
|
2398 |
{ |
|
2399 |
QFETCH( QString, dbName ); |
|
2400 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2401 |
CHECK_DATABASE( db ); |
|
2402 |
||
2403 |
if ( !db.driver()->hasFeature( QSqlDriver::MultipleResultSets ) || !db.driver()->hasFeature( QSqlDriver::BatchOperations ) ) |
|
2404 |
QSKIP( "DBMS does not support multiple result sets or batch operations", SkipSingle ); |
|
2405 |
||
2406 |
QSqlQuery q( db ); |
|
2407 |
||
2408 |
if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) |
|
2409 |
QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); |
|
2410 |
||
2411 |
enum DriverType { ODBC, MYSQL, DB2 }; |
|
2412 |
DriverType driverType = ODBC; |
|
2413 |
||
2414 |
if ( db.driverName().startsWith( "QMYSQL" ) ) |
|
2415 |
driverType = MYSQL; |
|
2416 |
else if ( db.driverName().startsWith( "QDB2" ) ) |
|
2417 |
driverType = DB2; |
|
2418 |
||
2419 |
QString tableName = qTableName( "more_results" ); |
|
2420 |
||
2421 |
QVERIFY_SQL( q, exec( "CREATE TABLE " + tableName + " (id integer, text varchar(20), num numeric(6, 3), empty varchar(10));" ) ); |
|
2422 |
||
2423 |
QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " VALUES(1, 'one', 1.1, '');" ) ); |
|
2424 |
||
2425 |
QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " VALUES(2, 'two', 2.2, '');" ) ); |
|
2426 |
||
2427 |
QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " VALUES(3, 'three', 3.3, '');" ) ); |
|
2428 |
||
2429 |
QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " VALUES(4, 'four', 4.4, '');" ) ); |
|
2430 |
||
2431 |
QStringList tstStrings; |
|
2432 |
||
2433 |
tstStrings << "one" << "two" << "three" << "four"; |
|
2434 |
||
2435 |
// Query that returns only one result set, nothing special about this |
|
2436 |
QVERIFY_SQL( q, exec( QString( "SELECT * FROM %1;" ).arg( tableName ) ) ); |
|
2437 |
||
2438 |
QVERIFY( q.next() ); // Move to first row of the result set |
|
2439 |
||
2440 |
QVERIFY( !q.nextResult() ); // No more result sets are available |
|
2441 |
||
2442 |
QVERIFY( !q.isActive() ); // So the query is no longer active |
|
2443 |
||
2444 |
QVERIFY( !q.next() ); // ... and no data is available as the call |
|
2445 |
||
2446 |
// to nextResult() discarded the result set |
|
2447 |
||
2448 |
// Query that returns two result sets (batch sql) |
|
2449 |
// When working with multiple result sets SQL Server insists on non-scrollable cursors |
|
2450 |
if ( driverType == ODBC ) |
|
2451 |
q.setForwardOnly( true ); |
|
2452 |
||
2453 |
QVERIFY_SQL( q, exec( "SELECT id FROM " + tableName + "; SELECT text, num FROM " + tableName + ';' ) ); |
|
2454 |
||
2455 |
QCOMPARE( q.record().count(), 1 ); // Check that the meta data is as expected |
|
2456 |
||
2457 |
QCOMPARE( q.record().field( 0 ).name().toUpper(), QString( "ID" ) ); |
|
2458 |
||
2459 |
QCOMPARE( q.record().field( 0 ).type(), QVariant::Int ); |
|
2460 |
||
2461 |
QVERIFY( q.nextResult() ); // Discards first result set and move to the next |
|
2462 |
||
2463 |
QCOMPARE( q.record().count(), 2 ); // New meta data should be available |
|
2464 |
||
2465 |
QCOMPARE( q.record().field( 0 ).name().toUpper(), QString( "TEXT" ) ); |
|
2466 |
||
2467 |
QCOMPARE( q.record().field( 0 ).type(), QVariant::String ); |
|
2468 |
||
2469 |
QCOMPARE( q.record().field( 1 ).name().toUpper(), QString( "NUM" ) ); |
|
2470 |
||
2471 |
if ( driverType == MYSQL ) |
|
2472 |
QCOMPARE( q.record().field( 1 ).type(), QVariant::String ); |
|
2473 |
else |
|
2474 |
QCOMPARE( q.record().field( 1 ).type(), QVariant::Double ); |
|
2475 |
||
2476 |
QVERIFY( q.next() ); // Move to first row of the second result set |
|
2477 |
||
2478 |
QFAIL_SQL(q, nextResult()); // No more result sets after this |
|
2479 |
||
2480 |
QVERIFY( !q.isActive() ); // So the query is no longer active |
|
2481 |
||
2482 |
QVERIFY( !q.next() ); // ... and no data is available as the call to |
|
2483 |
||
2484 |
// nextResult() discarded the result set |
|
2485 |
||
2486 |
// Query that returns one result set, a count of affected rows and then another result set |
|
2487 |
QString query1 = QString( "SELECT id, text, num, empty FROM %1 WHERE id <= 3" ).arg( tableName ); |
|
2488 |
||
2489 |
QString query2 = QString( "UPDATE %1 SET empty = 'Yatta!'" ).arg( tableName ); |
|
2490 |
||
2491 |
QString query3 = QString( "SELECT id, empty FROM %1 WHERE id <=2" ).arg( tableName ); |
|
2492 |
||
2493 |
QVERIFY_SQL( q, exec( QString( "%1; %2; %3;" ).arg( query1 ).arg( query2 ).arg( query3 ) ) ); |
|
2494 |
||
2495 |
// Check result set returned by first statement |
|
2496 |
QVERIFY( q.isSelect() ); // The first statement is a select |
|
2497 |
||
2498 |
for ( int i = 0; i < 3; i++ ) { |
|
2499 |
QVERIFY_SQL( q, next() ); |
|
2500 |
QCOMPARE( q.value( 0 ).toInt(), 1+i ); |
|
2501 |
QCOMPARE( q.value( 1 ).toString(), tstStrings.at( i ) ); |
|
2502 |
QCOMPARE( q.value( 2 ).toDouble(), 1.1*( i+1 ) ); |
|
2503 |
QVERIFY( q.value( 3 ).toString().isEmpty() ); |
|
2504 |
} |
|
2505 |
||
2506 |
QVERIFY_SQL( q, nextResult() ); |
|
2507 |
||
2508 |
QVERIFY( !q.isSelect() ); // The second statement isn't a SELECT |
|
2509 |
QVERIFY( !q.next() ); // ... so no result set is available |
|
2510 |
QCOMPARE( q.numRowsAffected(), 4 ); // 4 rows was affected by the UPDATE |
|
2511 |
||
2512 |
// Check result set returned by third statement |
|
2513 |
QVERIFY_SQL( q, nextResult() ); |
|
2514 |
QVERIFY( q.isSelect() ); // The third statement is a SELECT |
|
2515 |
||
2516 |
for ( int i = 0; i < 2; i++ ) { |
|
2517 |
QVERIFY_SQL( q, next() ); |
|
2518 |
QCOMPARE( q.value( 0 ).toInt(), 1+i ); |
|
2519 |
QCOMPARE( q.value( 1 ).toString(), QString( "Yatta!" ) ); |
|
2520 |
} |
|
2521 |
||
2522 |
// Stored procedure with multiple result sets |
|
2523 |
QString procName = qTableName( "proc_more_res" ); |
|
2524 |
||
2525 |
q.exec( QString( "DROP PROCEDURE %1;" ).arg( procName ) ); |
|
2526 |
||
2527 |
if ( driverType == MYSQL ) |
|
2528 |
QVERIFY_SQL( q, exec( QString( "CREATE PROCEDURE %1()" |
|
2529 |
"\nBEGIN" |
|
2530 |
"\nSELECT id, text FROM %2;" |
|
2531 |
"\nSELECT empty, num, text, id FROM %3;" |
|
2532 |
"\nEND" ).arg( procName ).arg( tableName ).arg( tableName ) ) ); |
|
2533 |
else if ( driverType == DB2 ) |
|
2534 |
QVERIFY_SQL( q, exec( QString( "CREATE PROCEDURE %1()" |
|
2535 |
"\nRESULT SETS 2" |
|
2536 |
"\nLANGUAGE SQL" |
|
2537 |
"\np1:BEGIN" |
|
2538 |
"\nDECLARE cursor1 CURSOR WITH RETURN FOR SELECT id, text FROM %2;" |
|
2539 |
"\nDECLARE cursor2 CURSOR WITH RETURN FOR SELECT empty, num, text, id FROM %3;" |
|
2540 |
"\nOPEN cursor1;" |
|
2541 |
"\nOPEN cursor2;" |
|
2542 |
"\nEND p1" ).arg( procName ).arg( tableName ).arg( tableName ) ) ); |
|
2543 |
else |
|
2544 |
QVERIFY_SQL( q, exec( QString( "CREATE PROCEDURE %1" |
|
2545 |
"\nAS" |
|
2546 |
"\nSELECT id, text FROM %2" |
|
2547 |
"\nSELECT empty, num, text, id FROM %3" ).arg( procName ).arg( tableName ).arg( tableName ) ) ); |
|
2548 |
||
2549 |
if ( driverType == MYSQL || driverType == DB2 ) { |
|
2550 |
q.setForwardOnly( true ); |
|
2551 |
QVERIFY_SQL( q, exec( QString( "CALL %1()" ).arg( procName ) ) ); |
|
2552 |
} else { |
|
2553 |
QVERIFY_SQL( q, exec( QString( "EXEC %1" ).arg( procName ) ) ); |
|
2554 |
} |
|
2555 |
||
2556 |
for ( int i = 0; i < 4; i++ ) { |
|
2557 |
QVERIFY_SQL( q, next() ); |
|
2558 |
QCOMPARE( q.value( 0 ).toInt(), i+1 ); |
|
2559 |
QCOMPARE( q.value( 1 ).toString(), tstStrings.at( i ) ); |
|
2560 |
} |
|
2561 |
||
2562 |
QVERIFY_SQL( q, nextResult() ); |
|
2563 |
||
2564 |
QVERIFY_SQL( q, isActive() ); |
|
2565 |
||
2566 |
for ( int i = 0; i < 4; i++ ) { |
|
2567 |
QVERIFY_SQL( q, next() ); |
|
2568 |
QCOMPARE( q.value( 0 ).toString(), QString( "Yatta!" ) ); |
|
2569 |
QCOMPARE( q.value( 1 ).toDouble(), 1.1*( 1+i ) ); |
|
2570 |
QCOMPARE( q.value( 2 ).toString(), tstStrings.at( i ) ); |
|
2571 |
QCOMPARE( q.value( 3 ).toInt(), 1+i ); |
|
2572 |
} |
|
2573 |
||
2574 |
// MySQL also counts the CALL itself as a result |
|
2575 |
if ( driverType == MYSQL ) { |
|
2576 |
QVERIFY( q.nextResult() ); |
|
2577 |
QVERIFY( !q.isSelect() ); // ... but it's not a select |
|
2578 |
QCOMPARE( q.numRowsAffected(), 0 ); // ... and no rows are affected (at least not with this procedure) |
|
2579 |
} |
|
2580 |
||
2581 |
QVERIFY( !q.nextResult() ); |
|
2582 |
||
2583 |
QVERIFY( !q.isActive() ); |
|
2584 |
||
2585 |
q.exec( QString( "DROP PROCEDURE %1;" ).arg( procName ) ); |
|
2586 |
} |
|
2587 |
||
2588 |
||
2589 |
// For task 190311. Problem: Truncation happens on the 2nd execution if that BLOB is larger |
|
2590 |
// than the BLOB on the 1st execution. This was only for MySQL, but the test is general |
|
2591 |
// enough to be run with all backends. |
|
2592 |
void tst_QSqlQuery::blobsPreparedQuery() |
|
2593 |
{ |
|
2594 |
QFETCH( QString, dbName ); |
|
2595 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2596 |
CHECK_DATABASE( db ); |
|
2597 |
||
2598 |
if ( !db.driver()->hasFeature( QSqlDriver::BLOB ) || !db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) |
|
2599 |
QSKIP( "DBMS does not support BLOBs or prepared queries", SkipSingle ); |
|
2600 |
||
2601 |
QString tableName = qTableName( "blobstest" ); |
|
2602 |
||
2603 |
QSqlQuery q( db ); |
|
2604 |
q.setForwardOnly( true ); // This is needed to make the test work with DB2. |
|
2605 |
QString shortBLOB( "abc" ); |
|
2606 |
QString longerBLOB( "abcdefghijklmnopqrstuvxyz¿äëïöü¡ " ); |
|
2607 |
||
2608 |
// In PostgreSQL a BLOB is not called a BLOB, but a BYTEA! :-) |
|
2609 |
// ... and in SQL Server it can be called a lot, but IMAGE will do. |
|
2610 |
QString typeName( "BLOB" ); |
|
2611 |
if ( db.driverName().startsWith( "QPSQL" ) ) |
|
2612 |
typeName = "BYTEA"; |
|
2613 |
else if ( db.driverName().startsWith( "QODBC" ) && tst_Databases::isSqlServer( db )) |
|
2614 |
typeName = "IMAGE"; |
|
2615 |
||
2616 |
QVERIFY_SQL( q, exec( QString( "CREATE TABLE %1(id INTEGER, data %2)" ).arg( tableName ).arg( typeName ) ) ); |
|
2617 |
q.prepare( QString( "INSERT INTO %1(id, data) VALUES(:id, :data)" ).arg( tableName ) ); |
|
2618 |
q.bindValue( ":id", 1 ); |
|
2619 |
q.bindValue( ":data", shortBLOB.toAscii() ); |
|
2620 |
QVERIFY_SQL( q, exec() ); |
|
2621 |
||
2622 |
q.bindValue( ":id", 2 ); |
|
2623 |
q.bindValue( ":data", longerBLOB.toAscii() ); |
|
2624 |
QVERIFY_SQL( q, exec() ); |
|
2625 |
||
2626 |
// Two executions and result sets |
|
2627 |
q.prepare( QString( "SELECT data FROM %1 WHERE id = ?" ).arg( tableName ) ); |
|
2628 |
q.bindValue( 0, QVariant( 1 ) ); |
|
2629 |
QVERIFY_SQL( q, exec() ); |
|
2630 |
QVERIFY_SQL( q, next() ); |
|
2631 |
QCOMPARE( q.value( 0 ).toString(), shortBLOB ); |
|
2632 |
||
2633 |
q.bindValue( 0, QVariant( 2 ) ); |
|
2634 |
QVERIFY_SQL( q, exec() ); |
|
2635 |
QVERIFY_SQL( q, next() ); |
|
2636 |
QCOMPARE( q.value( 0 ).toString(), longerBLOB ); |
|
2637 |
||
2638 |
// Only one execution and result set |
|
2639 |
q.prepare( QString( "SELECT id, data FROM %1 ORDER BY id" ).arg( tableName ) ); |
|
2640 |
QVERIFY_SQL( q, exec() ); |
|
2641 |
QVERIFY_SQL( q, next() ); |
|
2642 |
QCOMPARE( q.value( 1 ).toString(), shortBLOB ); |
|
2643 |
QVERIFY_SQL( q, next() ); |
|
2644 |
QCOMPARE( q.value( 1 ).toString(), longerBLOB ); |
|
2645 |
} |
|
2646 |
||
2647 |
// There were problems with navigating past the end of a table returning an error on mysql |
|
2648 |
void tst_QSqlQuery::emptyTableNavigate() |
|
2649 |
{ |
|
2650 |
QFETCH( QString, dbName ); |
|
2651 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2652 |
CHECK_DATABASE( db ); |
|
2653 |
||
2654 |
{ |
|
2655 |
QSqlQuery q( db ); |
|
2656 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_empty" ) + " (id char(10))" ) ); |
|
2657 |
QVERIFY_SQL( q, prepare( "select * from " + qTableName( "qtest_empty" ) ) ); |
|
2658 |
QVERIFY_SQL( q, exec() ); |
|
2659 |
QVERIFY( !q.next() ); |
|
2660 |
QCOMPARE( q.lastError().isValid(), false ); |
|
2661 |
} |
|
2662 |
} |
|
2663 |
||
2664 |
void tst_QSqlQuery::task_217003() |
|
2665 |
{ |
|
2666 |
QFETCH( QString, dbName ); |
|
2667 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2668 |
CHECK_DATABASE( db ); |
|
2669 |
QSqlQuery q( db ); |
|
2670 |
||
2671 |
QVERIFY_SQL( q, exec( "create table " + qTableName( "Planet" ) + " (Name varchar(20))" ) ); |
|
2672 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "Planet" ) + " VALUES ('Mercury')" ) ); |
|
2673 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "Planet" ) + " VALUES ('Venus')" ) ); |
|
2674 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "Planet" ) + " VALUES ('Earth')" ) ); |
|
2675 |
QVERIFY_SQL( q, exec( "insert into " + qTableName( "Planet" ) + " VALUES ('Mars')" ) ); |
|
2676 |
||
2677 |
QVERIFY_SQL( q, exec( "SELECT Name FROM "+qTableName( "Planet" ) ) ); |
|
2678 |
QVERIFY_SQL( q, seek( 3 ) ); |
|
2679 |
QCOMPARE( q.value( 0 ).toString(), QString( "Mars" ) ); |
|
2680 |
QVERIFY_SQL( q, seek( 1 ) ); |
|
2681 |
QCOMPARE( q.value( 0 ).toString(), QString( "Venus" ) ); |
|
2682 |
QVERIFY_SQL( q, exec( "SELECT Name FROM "+qTableName( "Planet" ) ) ); |
|
2683 |
QVERIFY_SQL( q, seek( 3 ) ); |
|
2684 |
QCOMPARE( q.value( 0 ).toString(), QString( "Mars" ) ); |
|
2685 |
QVERIFY_SQL( q, seek( 0 ) ); |
|
2686 |
QCOMPARE( q.value( 0 ).toString(), QString( "Mercury" ) ); |
|
2687 |
QVERIFY_SQL( q, seek( 1 ) ); |
|
2688 |
QCOMPARE( q.value( 0 ).toString(), QString( "Venus" ) ); |
|
2689 |
} |
|
2690 |
||
2691 |
void tst_QSqlQuery::task_250026() |
|
2692 |
{ |
|
2693 |
QString data258, data1026; |
|
2694 |
QFETCH( QString, dbName ); |
|
2695 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2696 |
CHECK_DATABASE( db ); |
|
2697 |
QSqlQuery q( db ); |
|
2698 |
||
2699 |
QString tableName = qTableName( "task_250026" ); |
|
2700 |
||
2701 |
if ( !q.exec( "create table " + tableName + " (longfield varchar(1100))" ) ) { |
|
2702 |
qDebug() << "Error" << q.lastError(); |
|
2703 |
QSKIP( "Db doesn't support \"1100\" as a size for fields", SkipSingle ); |
|
2704 |
} |
|
2705 |
||
2706 |
data258.fill( 'A', 258 ); |
|
2707 |
data1026.fill( 'A', 1026 ); |
|
2708 |
QVERIFY_SQL( q, prepare( "insert into " + tableName + "(longfield) VALUES (:longfield)" ) ); |
|
2709 |
q.bindValue( "longfield", data258 ); |
|
2710 |
QVERIFY_SQL( q, exec() ); |
|
2711 |
q.bindValue( "longfield", data1026 ); |
|
2712 |
QVERIFY_SQL( q, exec() ); |
|
2713 |
QVERIFY_SQL( q, exec( "select * from " + tableName ) ); |
|
2714 |
QVERIFY_SQL( q, next() ); |
|
2715 |
QCOMPARE( q.value( 0 ).toString().length(), data258.length() ); |
|
2716 |
QVERIFY_SQL( q, next() ); |
|
2717 |
QCOMPARE( q.value( 0 ).toString().length(), data1026.length() ); |
|
2718 |
} |
|
2719 |
||
2720 |
void tst_QSqlQuery::task_205701() |
|
2721 |
{ |
|
2722 |
QSqlDatabase qsdb = QSqlDatabase::addDatabase("QMYSQL", "atest"); |
|
2723 |
qsdb.setHostName("test"); |
|
2724 |
qsdb.setDatabaseName("test"); |
|
2725 |
qsdb.setUserName("test"); |
|
2726 |
qsdb.setPassword("test"); |
|
2727 |
qsdb.open(); |
|
2728 |
||
2729 |
// { |
|
2730 |
QSqlQuery query(qsdb); |
|
2731 |
// } |
|
2732 |
QSqlDatabase::removeDatabase("atest"); |
|
2733 |
} |
|
2734 |
||
2735 |
#ifdef NOT_READY_YET |
|
2736 |
// For task: 229811 |
|
2737 |
void tst_QSqlQuery::task_229811() |
|
2738 |
{ |
|
2739 |
QFETCH( QString, dbName ); |
|
2740 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2741 |
CHECK_DATABASE( db ); |
|
2742 |
||
2743 |
if (!db.driverName().startsWith( "QODBC" )) return; |
|
2744 |
||
2745 |
QSqlQuery q( db ); |
|
2746 |
||
2747 |
QString tableName = qTableName( "task_229811" ); |
|
2748 |
||
2749 |
if ( !q.exec( "CREATE TABLE " + tableName + " (Word varchar(20))" ) ) { |
|
2750 |
qDebug() << "Warning" << q.lastError(); |
|
2751 |
} |
|
2752 |
||
2753 |
QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('Albert')" ) ); |
|
2754 |
QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('Beehive')" ) ); |
|
2755 |
QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('Alimony')" ) ); |
|
2756 |
QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('Bohemian')" ) ); |
|
2757 |
QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('AllStars')" ) ); |
|
2758 |
||
2759 |
||
2760 |
QString stmt = "SELECT * FROM " + tableName + " WHERE Word LIKE :name"; |
|
2761 |
QVERIFY_SQL(q,prepare(stmt)); |
|
2762 |
q.bindValue(":name", "A%"); |
|
2763 |
QVERIFY_SQL(q,exec()); |
|
2764 |
||
2765 |
QVERIFY(q.isActive()); |
|
2766 |
QVERIFY(q.isSelect()); |
|
2767 |
QVERIFY(q.first()); |
|
2768 |
||
2769 |
QSqlRecord rec = q.record(); |
|
2770 |
QCOMPARE(rec.field(0).value().toString(), QString("Albert")); |
|
2771 |
QVERIFY(q.next()); |
|
2772 |
rec = q.record(); |
|
2773 |
QCOMPARE(rec.field(0).value().toString(), QString("Alimony")); |
|
2774 |
QVERIFY(q.next()); |
|
2775 |
rec = q.record(); |
|
2776 |
QCOMPARE(rec.field(0).value().toString(),QString("AllStars")); |
|
2777 |
||
2778 |
q.exec("DROP TABLE " + tableName ); |
|
2779 |
} |
|
2780 |
||
2781 |
void tst_QSqlQuery::task_234422() |
|
2782 |
{ |
|
2783 |
QFETCH( QString, dbName ); |
|
2784 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2785 |
CHECK_DATABASE( db ); |
|
2786 |
||
2787 |
QSqlQuery query(db); |
|
2788 |
QStringList m_airlines; |
|
2789 |
QStringList m_countries; |
|
2790 |
||
2791 |
m_airlines << "Lufthansa" << "SAS" << "United" << "KLM" << "Aeroflot"; |
|
2792 |
m_countries << "DE" << "SE" << "US" << "NL" << "RU"; |
|
2793 |
||
2794 |
QString tableName = qTableName( "task_234422" ); |
|
2795 |
||
2796 |
QVERIFY_SQL(query,exec("CREATE TABLE " + tableName + " (id int primary key, " |
|
2797 |
"name varchar(20), homecountry varchar(2))")); |
|
2798 |
for (int i = 0; i < m_airlines.count(); ++i) { |
|
2799 |
QVERIFY(query.exec(QString("INSERT INTO " + tableName + " values(%1, '%2', '%3')") |
|
2800 |
.arg(i).arg(m_airlines[i], m_countries[i]))); |
|
2801 |
} |
|
2802 |
||
2803 |
QVERIFY_SQL(query, exec("SELECT name FROM " + tableName)); |
|
2804 |
QVERIFY(query.isSelect()); |
|
2805 |
QVERIFY(query.first()); |
|
2806 |
QVERIFY(query.next()); |
|
2807 |
QCOMPARE(query.at(), 1); |
|
2808 |
||
2809 |
QSqlQuery query2(query); |
|
2810 |
||
2811 |
QVERIFY_SQL(query2,exec()); |
|
2812 |
QVERIFY(query2.first()); |
|
2813 |
QCOMPARE(query2.at(), 0); |
|
2814 |
QCOMPARE(query.at(), 1); |
|
2815 |
} |
|
2816 |
||
2817 |
#endif |
|
2818 |
||
2819 |
void tst_QSqlQuery::task_233829() |
|
2820 |
{ |
|
2821 |
QFETCH( QString, dbName ); |
|
2822 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2823 |
CHECK_DATABASE( db ); |
|
2824 |
||
2825 |
QSqlQuery q( db ); |
|
2826 |
QString tableName = qTableName("task_233829"); |
|
2827 |
QVERIFY_SQL(q,exec("CREATE TABLE " + tableName + "(dbl1 double precision,dbl2 double precision) without oids;")); |
|
2828 |
||
2829 |
QString queryString("INSERT INTO " + tableName +"(dbl1, dbl2) VALUES(?,?)"); |
|
2830 |
||
2831 |
double k = 0.0; |
|
2832 |
QVERIFY_SQL(q,prepare(queryString)); |
|
2833 |
q.bindValue(0,0.0 / k); // nan |
|
2834 |
q.bindValue(1,0.0 / k); // nan |
|
2835 |
QVERIFY_SQL(q,exec()); |
|
2836 |
} |
|
2837 |
||
2838 |
void tst_QSqlQuery::sqlServerReturn0() |
|
2839 |
{ |
|
2840 |
QFETCH( QString, dbName ); |
|
2841 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
|
2842 |
CHECK_DATABASE( db ); |
|
2843 |
if (!tst_Databases::isSqlServer( db )) |
|
2844 |
QSKIP("SQL Server specific test", SkipSingle); |
|
2845 |
||
2846 |
QString tableName(qTableName("test141895")), procName(qTableName("test141895_proc")); |
|
2847 |
QSqlQuery q( db ); |
|
2848 |
q.exec("DROP TABLE " + tableName); |
|
2849 |
q.exec("DROP PROCEDURE " + procName); |
|
2850 |
QVERIFY_SQL(q, exec("CREATE TABLE "+tableName+" (id integer)")); |
|
2851 |
QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (1)")); |
|
2852 |
QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (2)")); |
|
2853 |
QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (2)")); |
|
2854 |
QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (3)")); |
|
2855 |
QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (1)")); |
|
2856 |
QVERIFY_SQL(q, exec("CREATE PROCEDURE "+procName+ |
|
2857 |
" AS " |
|
2858 |
"SELECT * FROM "+tableName+" WHERE ID = 2 " |
|
2859 |
"RETURN 0")); |
|
2860 |
||
2861 |
QVERIFY_SQL(q, exec("{CALL "+procName+"}")); |
|
2862 |
||
2863 |
QVERIFY_SQL(q, next()); |
|
2864 |
} |
|
2865 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2866 |
void tst_QSqlQuery::QTBUG_551() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2867 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2868 |
QFETCH( QString, dbName ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2869 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2870 |
CHECK_DATABASE( db ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2871 |
QSqlQuery q(db); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2872 |
QString pkgname=qTableName("pkg"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2873 |
QVERIFY_SQL(q, exec("CREATE OR REPLACE PACKAGE "+pkgname+" IS \n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2874 |
\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2875 |
TYPE IntType IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2876 |
TYPE VCType IS TABLE OF VARCHAR2(60) INDEX BY BINARY_INTEGER;\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2877 |
PROCEDURE P (Inp IN IntType, Outp OUT VCType);\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2878 |
END "+pkgname+";")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2879 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2880 |
QVERIFY_SQL(q, exec("CREATE OR REPLACE PACKAGE BODY "+pkgname+" IS\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2881 |
PROCEDURE P (Inp IN IntType, Outp OUT VCType)\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2882 |
IS\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2883 |
BEGIN\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2884 |
Outp(1) := '1. Value is ' ||TO_CHAR(Inp(1));\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2885 |
Outp(2) := '2. Value is ' ||TO_CHAR(Inp(2));\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2886 |
Outp(3) := '3. Value is ' ||TO_CHAR(Inp(3));\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2887 |
END p;\n\ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2888 |
END "+pkgname+";")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2889 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2890 |
QVariantList inLst, outLst, res_outLst; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2891 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2892 |
q.prepare("begin "+pkgname+".p(:inp, :outp); end;"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2893 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2894 |
QString StVal; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2895 |
StVal.reserve(60); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2896 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2897 |
// loading arrays |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2898 |
for (int Cnt=0; Cnt < 3; Cnt++) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2899 |
inLst << Cnt; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2900 |
outLst << StVal; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2901 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2902 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2903 |
q.bindValue(":inp", inLst); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2904 |
q.bindValue(":outp", outLst, QSql::Out); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2905 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2906 |
QVERIFY_SQL(q, execBatch(QSqlQuery::ValuesAsColumns) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2907 |
res_outLst = qVariantValue<QVariantList>(q.boundValues()[":outp"]); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2908 |
QCOMPARE(res_outLst[0].toString(), QLatin1String("1. Value is 0")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2909 |
QCOMPARE(res_outLst[1].toString(), QLatin1String("2. Value is 1")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2910 |
QCOMPARE(res_outLst[2].toString(), QLatin1String("3. Value is 2")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2911 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2912 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2913 |
void tst_QSqlQuery::QTBUG_5251() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2914 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2915 |
QFETCH( QString, dbName ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2916 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2917 |
CHECK_DATABASE( db ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2918 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2919 |
if (!db.driverName().startsWith( "QPSQL" )) return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2920 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2921 |
QSqlQuery q(db); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2922 |
q.exec("DROP TABLE " + qTableName("timetest")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2923 |
QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("timetest") + " (t TIME)")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2924 |
QVERIFY_SQL(q, exec("INSERT INTO " + qTableName("timetest") + " VALUES ('1:2:3.666')")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2925 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2926 |
QSqlTableModel timetestModel(0,db); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2927 |
timetestModel.setEditStrategy(QSqlTableModel::OnManualSubmit); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2928 |
timetestModel.setTable(qTableName("timetest")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2929 |
QVERIFY_SQL(timetestModel, select()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2930 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2931 |
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("01:02:03.666")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2932 |
QVERIFY_SQL(timetestModel,setData(timetestModel.index(0, 0), QTime(0,12,34,500))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2933 |
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2934 |
QVERIFY_SQL(timetestModel, submitAll()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2935 |
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2936 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2937 |
QVERIFY_SQL(q, exec("UPDATE " + qTableName("timetest") + " SET t = '0:11:22.33'")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2938 |
QVERIFY_SQL(timetestModel, select()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2939 |
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:11:22.330")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2940 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2941 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2942 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2943 |
void tst_QSqlQuery::QTBUG_6421() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2944 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2945 |
QFETCH( QString, dbName ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2946 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2947 |
CHECK_DATABASE( db ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2948 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2949 |
QSqlQuery q(db); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2950 |
QString tableName=qTableName(QLatin1String("bug6421")).toUpper(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2951 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2952 |
QVERIFY_SQL(q, exec("create table "+tableName+"(COL1 char(10), COL2 char(10), COL3 char(10))")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2953 |
QVERIFY_SQL(q, exec("create index INDEX1 on "+tableName+" (COL1 desc)")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2954 |
QVERIFY_SQL(q, exec("create index INDEX2 on "+tableName+" (COL2 desc)")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2955 |
QVERIFY_SQL(q, exec("create index INDEX3 on "+tableName+" (COL3 desc)")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2956 |
q.setForwardOnly(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2957 |
QVERIFY_SQL(q, exec("select COLUMN_EXPRESSION from ALL_IND_EXPRESSIONS where TABLE_NAME='"+tableName+"'")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2958 |
QVERIFY_SQL(q, next()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2959 |
QCOMPARE(q.value(0).toString(), QLatin1String("\"COL1\"")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2960 |
QVERIFY_SQL(q, next()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2961 |
QCOMPARE(q.value(0).toString(), QLatin1String("\"COL2\"")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2962 |
QVERIFY_SQL(q, next()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2963 |
QCOMPARE(q.value(0).toString(), QLatin1String("\"COL3\"")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2964 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2965 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2966 |
void tst_QSqlQuery::QTBUG_6618() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2967 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2968 |
QFETCH( QString, dbName ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2969 |
QSqlDatabase db = QSqlDatabase::database( dbName ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2970 |
CHECK_DATABASE( db ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2971 |
if (!tst_Databases::isSqlServer( db )) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2972 |
QSKIP("SQL Server specific test", SkipSingle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2973 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2974 |
QSqlQuery q(db); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2975 |
q.exec( "drop procedure " + qTableName( "tst_raiseError" ) ); //non-fatal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2976 |
QString errorString; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2977 |
for (int i=0;i<110;i++) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2978 |
errorString+="reallylong"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2979 |
errorString+=" error"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2980 |
QVERIFY_SQL( q, exec("create procedure " + qTableName( "tst_raiseError" ) + " as\n" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2981 |
"begin\n" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2982 |
" raiserror('" + errorString + "', 16, 1)\n" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2983 |
"end\n" )); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2984 |
q.exec( "{call " + qTableName( "tst_raiseError" ) + "}" ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2985 |
QVERIFY(q.lastError().text().contains(errorString)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2986 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2987 |
|
0 | 2988 |
QTEST_MAIN( tst_QSqlQuery ) |
2989 |
#include "tst_qsqlquery.moc" |