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