author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 09:15:16 +0300 | |
branch | RCL_3 |
changeset 10 | 68d3b337861b |
parent 7 | 3f74d0d4af4c |
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 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <QtSql/QtSql> |
|
45 |
||
46 |
#include "../qsqldatabase/tst_databases.h" |
|
47 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
48 |
const QString reltest1(qTableName("reltest1", __FILE__)), |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
49 |
reltest2(qTableName("reltest2", __FILE__)), |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
50 |
reltest3(qTableName("reltest3", __FILE__)), |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
51 |
reltest4(qTableName("reltest4", __FILE__)), |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
52 |
reltest5(qTableName("reltest5", __FILE__)); |
0 | 53 |
|
54 |
||
55 |
//TESTED_CLASS= |
|
56 |
//TESTED_FILES= |
|
57 |
||
58 |
class tst_QSqlRelationalTableModel : public QObject |
|
59 |
{ |
|
60 |
Q_OBJECT |
|
61 |
||
62 |
public: |
|
63 |
void recreateTestTables(QSqlDatabase); |
|
64 |
||
65 |
tst_Databases dbs; |
|
66 |
||
67 |
public slots: |
|
68 |
void initTestCase_data(); |
|
69 |
void initTestCase(); |
|
70 |
void cleanupTestCase(); |
|
71 |
void init(); |
|
72 |
void cleanup(); |
|
73 |
||
74 |
private slots: |
|
75 |
void data(); |
|
76 |
void setData(); |
|
77 |
void multipleRelation(); |
|
78 |
void insertRecord(); |
|
79 |
void setRecord(); |
|
80 |
void insertWithStrategies(); |
|
81 |
void removeColumn(); |
|
82 |
void filter(); |
|
83 |
void sort(); |
|
84 |
void revert(); |
|
85 |
||
86 |
void clearDisplayValuesCache(); |
|
87 |
void insertRecordDuplicateFieldNames(); |
|
88 |
void invalidData(); |
|
89 |
void relationModel(); |
|
90 |
void casing(); |
|
91 |
void escapedRelations(); |
|
92 |
void escapedTableName(); |
|
93 |
void whiteSpaceInIdentifiers(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
void psqlSchemaTest(); |
0 | 95 |
|
96 |
private: |
|
97 |
void dropTestTables( QSqlDatabase db ); |
|
98 |
}; |
|
99 |
||
100 |
||
101 |
void tst_QSqlRelationalTableModel::initTestCase_data() |
|
102 |
{ |
|
103 |
dbs.open(); |
|
104 |
if (dbs.fillTestTable() == 0) { |
|
105 |
qWarning("NO DATABASES"); |
|
106 |
QSKIP("No database drivers are available in this Qt configuration", SkipAll); |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
void tst_QSqlRelationalTableModel::recreateTestTables(QSqlDatabase db) |
|
111 |
{ |
|
112 |
dropTestTables(db); |
|
113 |
||
114 |
QSqlQuery q(db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
115 |
QVERIFY_SQL( q, exec("create table " + reltest1 + |
0 | 116 |
" (id int not null primary key, name varchar(20), title_key int, another_title_key int)")); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
117 |
QVERIFY_SQL( q, exec("insert into " + reltest1 + " values(1, 'harry', 1, 2)")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
118 |
QVERIFY_SQL( q, exec("insert into " + reltest1 + " values(2, 'trond', 2, 1)")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
119 |
QVERIFY_SQL( q, exec("insert into " + reltest1 + " values(3, 'vohi', 1, 2)")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
120 |
QVERIFY_SQL( q, exec("insert into " + reltest1 + " values(4, 'boris', 2, 2)")); |
0 | 121 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
122 |
QVERIFY_SQL( q, exec("create table " + reltest2 + " (tid int not null primary key, title varchar(20))")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
123 |
QVERIFY_SQL( q, exec("insert into " + reltest2 + " values(1, 'herr')")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
124 |
QVERIFY_SQL( q, exec("insert into " + reltest2 + " values(2, 'mister')")); |
0 | 125 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
126 |
QVERIFY_SQL( q, exec("create table " + reltest3 + " (id int not null primary key, name varchar(20), city_key int)")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
127 |
QVERIFY_SQL( q, exec("insert into " + reltest3 + " values(1, 'Gustav', 1)")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
128 |
QVERIFY_SQL( q, exec("insert into " + reltest3 + " values(2, 'Heidi', 2)")); |
0 | 129 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
130 |
QVERIFY_SQL( q, exec("create table " + reltest4 + " (id int not null primary key, name varchar(20))")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
131 |
QVERIFY_SQL( q, exec("insert into " + reltest4 + " values(1, 'Oslo')")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
132 |
QVERIFY_SQL( q, exec("insert into " + reltest4 + " values(2, 'Trondheim')")); |
0 | 133 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
134 |
QVERIFY_SQL( q, exec("create table " + reltest5 + " (title varchar(20) not null primary key, abbrev varchar(20))")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
135 |
QVERIFY_SQL( q, exec("insert into " + reltest5 + " values('herr', 'Hr')")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
136 |
QVERIFY_SQL( q, exec("insert into " + reltest5 + " values('mister', 'Mr')")); |
0 | 137 |
|
138 |
if (testWhiteSpaceNames(db.driverName())) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
139 |
QString reltest6 = db.driver()->escapeIdentifier(qTableName("rel", __FILE__)+" test6", QSqlDriver::TableName); |
0 | 140 |
QVERIFY_SQL( q, exec("create table " + reltest6 + " (id int not null primary key, " + db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName) + |
141 |
" int, " + db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName) + " int)")); |
|
142 |
QVERIFY_SQL( q, exec("insert into " + reltest6 + " values(1, 1,9)")); |
|
143 |
QVERIFY_SQL( q, exec("insert into " + reltest6 + " values(2, 2,8)")); |
|
144 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
145 |
QString reltest7 = db.driver()->escapeIdentifier(qTableName("rel", __FILE__)+" test7", QSqlDriver::TableName); |
0 | 146 |
QVERIFY_SQL( q, exec("create table " + reltest7 + " (" + db.driver()->escapeIdentifier("city id", QSqlDriver::TableName) + " int not null primary key, " + db.driver()->escapeIdentifier("city name", QSqlDriver::FieldName) + " varchar(20))")); |
147 |
QVERIFY_SQL( q, exec("insert into " + reltest7 + " values(1, 'New York')")); |
|
148 |
QVERIFY_SQL( q, exec("insert into " + reltest7 + " values(2, 'Washington')")); |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
void tst_QSqlRelationalTableModel::initTestCase() |
|
153 |
{ |
|
154 |
foreach (const QString &dbname, dbs.dbNames) { |
|
155 |
QSqlDatabase db=QSqlDatabase::database(dbname); |
|
156 |
if (db.driverName().startsWith("QIBASE")) |
|
157 |
db.exec("SET DIALECT 3"); |
|
158 |
else if (tst_Databases::isSqlServer(db)) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
db.exec("SET ANSI_DEFAULTS ON"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
db.exec("SET IMPLICIT_TRANSACTIONS OFF"); |
0 | 161 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
else if(tst_Databases::isPostgreSQL(db)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
db.exec("set client_min_messages='warning'"); |
0 | 164 |
recreateTestTables(db); |
165 |
} |
|
166 |
} |
|
167 |
||
168 |
void tst_QSqlRelationalTableModel::cleanupTestCase() |
|
169 |
{ |
|
170 |
foreach (const QString &dbName, dbs.dbNames) { |
|
171 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
172 |
CHECK_DATABASE( db ); |
|
173 |
dropTestTables( QSqlDatabase::database(dbName) ); |
|
174 |
} |
|
175 |
dbs.close(); |
|
176 |
} |
|
177 |
||
178 |
void tst_QSqlRelationalTableModel::dropTestTables( QSqlDatabase db ) |
|
179 |
{ |
|
180 |
QStringList tableNames; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
181 |
tableNames << reltest1 |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
182 |
<< reltest2 |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
183 |
<< reltest3 |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
184 |
<< reltest4 |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
185 |
<< reltest5 |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
186 |
<< (qTableName( "rel", __FILE__)+" test6") |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
187 |
<< (qTableName( "rel", __FILE__)+" test7") |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
188 |
<< qTableName("CASETEST1", db.driver() ) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
189 |
<< qTableName("casetest1", db.driver() ); |
0 | 190 |
tst_Databases::safeDropTables( db, tableNames ); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
192 |
db.exec("DROP SCHEMA "+qTableName("QTBUG_5373", __FILE__)+" CASCADE"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
193 |
db.exec("DROP SCHEMA "+qTableName("QTBUG_5373_s2", __FILE__)+" CASCADE"); |
0 | 194 |
} |
195 |
||
196 |
void tst_QSqlRelationalTableModel::init() |
|
197 |
{ |
|
198 |
} |
|
199 |
||
200 |
void tst_QSqlRelationalTableModel::cleanup() |
|
201 |
{ |
|
202 |
} |
|
203 |
||
204 |
void tst_QSqlRelationalTableModel::data() |
|
205 |
{ |
|
206 |
QFETCH_GLOBAL(QString, dbName); |
|
207 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
208 |
CHECK_DATABASE(db); |
|
209 |
||
210 |
QSqlRelationalTableModel model(0, db); |
|
211 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
212 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
213 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 214 |
QVERIFY_SQL(model, select()); |
215 |
||
216 |
QCOMPARE(model.columnCount(), 4); |
|
217 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); |
|
218 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); |
|
219 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
220 |
||
221 |
//try a non-existant index |
|
222 |
QVERIFY2(model.data(model.index(0,4)).isValid() == false,"Invalid index returned valid QVariant"); |
|
223 |
||
224 |
//check data retrieval when relational key is a non-integer type |
|
225 |
//in this case a string |
|
226 |
QSqlRelationalTableModel model2(0,db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
227 |
model2.setTable(reltest2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
228 |
model2.setRelation(1, QSqlRelation(reltest5,"title","abbrev")); |
0 | 229 |
QVERIFY_SQL(model2, select()); |
230 |
||
231 |
QCOMPARE(model2.data(model2.index(0, 1)).toString(), QString("Hr")); |
|
232 |
QCOMPARE(model2.data(model2.index(1, 1)).toString(), QString("Mr")); |
|
233 |
} |
|
234 |
||
235 |
void tst_QSqlRelationalTableModel::setData() |
|
236 |
{ |
|
237 |
QFETCH_GLOBAL(QString, dbName); |
|
238 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
239 |
CHECK_DATABASE(db); |
|
240 |
||
241 |
// set the values using OnRowChange Strategy |
|
242 |
{ |
|
243 |
QSqlRelationalTableModel model(0, db); |
|
244 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
245 |
model.setTable(reltest1); |
0 | 246 |
model.setSort(0, Qt::AscendingOrder); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
247 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 248 |
QVERIFY_SQL(model, select()); |
249 |
||
250 |
QVERIFY(model.setData(model.index(0, 1), QString("harry2"))); |
|
251 |
QVERIFY(model.setData(model.index(0, 2), 2)); |
|
252 |
||
253 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry2")); |
|
254 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); |
|
255 |
||
256 |
model.submit(); |
|
257 |
||
258 |
QVERIFY(model.setData(model.index(3,1), QString("boris2"))); |
|
259 |
QVERIFY(model.setData(model.index(3, 2), 1)); |
|
260 |
||
261 |
QCOMPARE(model.data(model.index(3,1)).toString(), QString("boris2")); |
|
262 |
QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); |
|
263 |
||
264 |
model.submit(); |
|
265 |
} |
|
266 |
{ //verify values |
|
267 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
268 |
model.setTable(reltest1); |
0 | 269 |
model.setSort(0, Qt::AscendingOrder); |
270 |
QVERIFY_SQL(model, select()); |
|
271 |
||
272 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry2")); |
|
273 |
QCOMPARE(model.data(model.index(0, 2)).toInt(), 2); |
|
274 |
QCOMPARE(model.data(model.index(3, 1)).toString(), QString("boris2")); |
|
275 |
QCOMPARE(model.data(model.index(3, 2)).toInt(), 1); |
|
276 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
277 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 278 |
QVERIFY_SQL(model, select()); |
279 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); |
|
280 |
QCOMPARE(model.data(model.index(3,2)).toString(), QString("herr")); |
|
281 |
||
282 |
} |
|
283 |
||
284 |
//set the values using OnFieldChange strategy |
|
285 |
{ |
|
286 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
287 |
model.setTable(reltest1); |
0 | 288 |
model.setEditStrategy(QSqlTableModel::OnFieldChange); |
289 |
model.setSort(0, Qt::AscendingOrder); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
290 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 291 |
QVERIFY_SQL(model, select()); |
292 |
||
293 |
QVERIFY(model.setData(model.index(1,1), QString("trond2"))); |
|
294 |
QVERIFY(model.setData(model.index(2,2), 2)); |
|
295 |
||
296 |
QCOMPARE(model.data(model.index(1,1)).toString(), QString("trond2")); |
|
297 |
QCOMPARE(model.data(model.index(2,2)).toString(), QString("mister")); |
|
298 |
} |
|
299 |
{ //verify values |
|
300 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
301 |
model.setTable(reltest1); |
0 | 302 |
model.setSort(0, Qt::AscendingOrder); |
303 |
QVERIFY_SQL(model, select()); |
|
304 |
||
305 |
QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond2")); |
|
306 |
QCOMPARE(model.data(model.index(2, 2)).toInt(), 2); |
|
307 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
308 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 309 |
QVERIFY_SQL(model, select()); |
310 |
QCOMPARE(model.data(model.index(2, 2)).toString(), QString("mister")); |
|
311 |
} |
|
312 |
||
313 |
//set values using OnManualSubmit strategy |
|
314 |
{ |
|
315 |
QSqlRelationalTableModel model(0, db); |
|
316 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
317 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
318 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 319 |
|
320 |
//sybase doesn't allow tables with the same alias used twice as col names |
|
321 |
//so don't set up an identical relation when using the tds driver |
|
322 |
if (!db.driverName().startsWith("QTDS")) |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
323 |
model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); |
0 | 324 |
|
325 |
model.setEditStrategy(QSqlTableModel::OnManualSubmit); |
|
326 |
model.setSort(0, Qt::AscendingOrder); |
|
327 |
QVERIFY_SQL(model, select()); |
|
328 |
||
329 |
QVERIFY(model.setData(model.index(2, 1), QString("vohi2"))); |
|
330 |
QVERIFY(model.setData(model.index(3, 2), 1)); |
|
331 |
QVERIFY(model.setData(model.index(0, 3), 1)); |
|
332 |
||
333 |
QCOMPARE(model.data(model.index(2, 1)).toString(), QString("vohi2")); |
|
334 |
QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); |
|
335 |
if (!db.driverName().startsWith("QTDS")) |
|
336 |
QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); |
|
337 |
else |
|
338 |
QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); |
|
339 |
||
340 |
QVERIFY_SQL(model, submitAll()); |
|
341 |
} |
|
342 |
{ //verify values |
|
343 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
344 |
model.setTable(reltest1); |
0 | 345 |
model.setSort(0, Qt::AscendingOrder); |
346 |
QVERIFY_SQL(model, select()); |
|
347 |
||
348 |
QCOMPARE(model.data(model.index(2, 1)).toString(), QString("vohi2")); |
|
349 |
QCOMPARE(model.data(model.index(3, 2)).toInt(), 1); |
|
350 |
QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); |
|
351 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
352 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 353 |
if (!db.driverName().startsWith("QTDS")) |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
354 |
model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); |
0 | 355 |
QVERIFY_SQL(model, select()); |
356 |
QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); |
|
357 |
||
358 |
if (!db.driverName().startsWith("QTDS")) |
|
359 |
QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); |
|
360 |
else |
|
361 |
QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); |
|
362 |
} |
|
363 |
||
364 |
//check setting of data when the relational key is a non-integer type |
|
365 |
//in this case a string. |
|
366 |
{ |
|
367 |
QSqlRelationalTableModel model(0, db); |
|
368 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
369 |
model.setTable(reltest2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
370 |
model.setRelation(1, QSqlRelation(reltest5, "title", "abbrev")); |
0 | 371 |
model.setEditStrategy(QSqlTableModel::OnManualSubmit); |
372 |
QVERIFY_SQL(model, select()); |
|
373 |
||
374 |
QCOMPARE(model.data(model.index(0,1)).toString(), QString("Hr")); |
|
375 |
QVERIFY(model.setData(model.index(0,1), QString("mister"))); |
|
376 |
QCOMPARE(model.data(model.index(0,1)).toString(), QString("Mr")); |
|
377 |
QVERIFY_SQL(model, submitAll()); |
|
378 |
||
379 |
QCOMPARE(model.data(model.index(0,1)).toString(), QString("Mr")); |
|
380 |
} |
|
381 |
||
382 |
} |
|
383 |
||
384 |
void tst_QSqlRelationalTableModel::multipleRelation() |
|
385 |
{ |
|
386 |
QFETCH_GLOBAL(QString, dbName); |
|
387 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
388 |
CHECK_DATABASE(db); |
|
389 |
recreateTestTables(db); |
|
390 |
||
391 |
QSqlRelationalTableModel model(0, db); |
|
392 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
393 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
394 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
395 |
model.setRelation(3, QSqlRelation(reltest4, "id", "name")); |
0 | 396 |
model.setSort(0, Qt::AscendingOrder); |
397 |
QVERIFY_SQL(model, select()); |
|
398 |
||
399 |
QCOMPARE(model.data(model.index(2, 0)).toInt(), 3); |
|
400 |
||
401 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); |
|
402 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); |
|
403 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
404 |
QCOMPARE(model.data(model.index(0, 3)).toString(), QString("Trondheim")); |
|
405 |
} |
|
406 |
||
407 |
void tst_QSqlRelationalTableModel::insertRecord() |
|
408 |
{ |
|
409 |
QFETCH_GLOBAL(QString, dbName); |
|
410 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
411 |
CHECK_DATABASE(db); |
|
412 |
||
413 |
QSqlRelationalTableModel model(0, db); |
|
414 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
415 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
416 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 417 |
model.setSort(0, Qt::AscendingOrder); |
418 |
QVERIFY_SQL(model, select()); |
|
419 |
||
420 |
QSqlRecord rec; |
|
421 |
QSqlField f1("id", QVariant::Int); |
|
422 |
QSqlField f2("name", QVariant::String); |
|
423 |
QSqlField f3("title_key", QVariant::Int); |
|
424 |
QSqlField f4("another_title_key", QVariant::Int); |
|
425 |
||
426 |
f1.setValue(5); |
|
427 |
f2.setValue("test"); |
|
428 |
f3.setValue(1); |
|
429 |
f4.setValue(2); |
|
430 |
||
431 |
f1.setGenerated(true); |
|
432 |
f2.setGenerated(true); |
|
433 |
f3.setGenerated(true); |
|
434 |
f4.setGenerated(true); |
|
435 |
||
436 |
rec.append(f1); |
|
437 |
rec.append(f2); |
|
438 |
rec.append(f3); |
|
439 |
rec.append(f4); |
|
440 |
||
441 |
QVERIFY_SQL(model, insertRecord(-1, rec)); |
|
442 |
||
443 |
QCOMPARE(model.data(model.index(4, 0)).toInt(), 5); |
|
444 |
QCOMPARE(model.data(model.index(4, 1)).toString(), QString("test")); |
|
445 |
QCOMPARE(model.data(model.index(4, 2)).toString(), QString("herr")); |
|
446 |
} |
|
447 |
||
448 |
void tst_QSqlRelationalTableModel::setRecord() |
|
449 |
{ |
|
450 |
QFETCH_GLOBAL(QString, dbName); |
|
451 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
452 |
CHECK_DATABASE(db); |
|
453 |
recreateTestTables(db); |
|
454 |
||
455 |
QSqlRelationalTableModel model(0, db); |
|
456 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
457 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
458 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 459 |
model.setSort(0, Qt::AscendingOrder); |
460 |
QVERIFY_SQL(model, select()); |
|
461 |
||
462 |
QSqlRecord rec; |
|
463 |
QSqlField f1("id", QVariant::Int); |
|
464 |
QSqlField f2("name", QVariant::String); |
|
465 |
QSqlField f3("title_key", QVariant::Int); |
|
466 |
QSqlField f4("another_title_key", QVariant::Int); |
|
467 |
||
468 |
f1.setValue(5); |
|
469 |
f2.setValue("tester"); |
|
470 |
f3.setValue(1); |
|
471 |
f4.setValue(2); |
|
472 |
||
473 |
f1.setGenerated(true); |
|
474 |
f2.setGenerated(true); |
|
475 |
f3.setGenerated(true); |
|
476 |
f4.setGenerated(true); |
|
477 |
||
478 |
rec.append(f1); |
|
479 |
rec.append(f2); |
|
480 |
rec.append(f3); |
|
481 |
rec.append(f4); |
|
482 |
||
483 |
QCOMPARE(model.data(model.index(1, 0)).toInt(), 2); |
|
484 |
QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond")); |
|
485 |
QCOMPARE(model.data(model.index(1, 2)).toString(), QString("mister")); |
|
486 |
||
487 |
QVERIFY_SQL(model, setRecord(1, rec)); |
|
488 |
||
489 |
QCOMPARE(model.data(model.index(1, 0)).toInt(), 5); |
|
490 |
QCOMPARE(model.data(model.index(1, 1)).toString(), QString("tester")); |
|
491 |
QCOMPARE(model.data(model.index(1, 2)).toString(), QString("herr")); |
|
492 |
||
493 |
model.setSort(0, Qt::AscendingOrder); |
|
494 |
QVERIFY_SQL(model, submit()); |
|
495 |
||
496 |
QCOMPARE(model.data(model.index(3, 0)).toInt(), 5); |
|
497 |
QCOMPARE(model.data(model.index(3, 1)).toString(), QString("tester")); |
|
498 |
QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); |
|
499 |
||
500 |
} |
|
501 |
||
502 |
void tst_QSqlRelationalTableModel::insertWithStrategies() |
|
503 |
{ |
|
504 |
QFETCH_GLOBAL(QString, dbName); |
|
505 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
506 |
CHECK_DATABASE(db); |
|
507 |
||
508 |
QSqlRelationalTableModel model(0, db); |
|
509 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
510 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
511 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 512 |
model.setSort(0, Qt::AscendingOrder); |
513 |
||
514 |
if (!db.driverName().startsWith("QTDS")) |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
515 |
model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); |
0 | 516 |
QVERIFY_SQL(model, select()); |
517 |
||
518 |
QCOMPARE(model.data(model.index(0,0)).toInt(), 1); |
|
519 |
QCOMPARE(model.data(model.index(0,1)).toString(), QString("harry")); |
|
520 |
QCOMPARE(model.data(model.index(0,2)).toString(), QString("herr")); |
|
521 |
if (!db.driverName().startsWith("QTDS")) |
|
522 |
QCOMPARE(model.data(model.index(0,3)).toString(), QString("mister")); |
|
523 |
else |
|
524 |
QCOMPARE(model.data(model.index(0,3)).toInt(), 2); |
|
525 |
||
526 |
model.insertRows(0, 1); |
|
527 |
model.setData(model.index(0, 0), 1011); |
|
528 |
model.setData(model.index(0, 1), "test"); |
|
529 |
model.setData(model.index(0, 2), 2); |
|
530 |
model.setData(model.index(0, 3), 1); |
|
531 |
||
532 |
QCOMPARE(model.data(model.index(0,0)).toInt(), 1011); |
|
533 |
QCOMPARE(model.data(model.index(0,1)).toString(), QString("test")); |
|
534 |
QCOMPARE(model.data(model.index(0,2)).toString(), QString("mister")); |
|
535 |
if (!db.driverName().startsWith("QTDS")) |
|
536 |
QCOMPARE(model.data(model.index(0,3)).toString(), QString("herr")); |
|
537 |
else |
|
538 |
QCOMPARE(model.data(model.index(0,3)).toInt(), 1); |
|
539 |
||
540 |
QCOMPARE(model.data(model.index(1,0)).toInt(), 1); |
|
541 |
QCOMPARE(model.data(model.index(1,1)).toString(), QString("harry")); |
|
542 |
QCOMPARE(model.data(model.index(1,2)).toString(), QString("herr")); |
|
543 |
if (!db.driverName().startsWith("QTDS")) |
|
544 |
QCOMPARE(model.data(model.index(1,3)).toString(), QString("mister")); |
|
545 |
else |
|
546 |
QCOMPARE(model.data(model.index(1,3)).toInt(), 2); |
|
547 |
||
548 |
||
549 |
||
550 |
QVERIFY_SQL(model, submitAll()); |
|
551 |
||
552 |
model.setEditStrategy(QSqlTableModel::OnManualSubmit); |
|
553 |
||
554 |
QCOMPARE(model.data(model.index(0,0)).toInt(), 1); |
|
555 |
QCOMPARE(model.data(model.index(0,1)).toString(), QString("harry")); |
|
556 |
QCOMPARE(model.data(model.index(0,2)).toString(), QString("herr")); |
|
557 |
||
558 |
if (!db.driverName().startsWith("QTDS")) { |
|
559 |
QCOMPARE(model.data(model.index(0,3)).toString(), QString("mister")); |
|
560 |
model.setData(model.index(0,3),1); |
|
561 |
QCOMPARE(model.data(model.index(0,3)).toString(), QString("herr")); |
|
562 |
} else { |
|
563 |
QCOMPARE(model.data(model.index(0,3)).toInt(), 2); |
|
564 |
model.setData(model.index(0,3),1); |
|
565 |
QCOMPARE(model.data(model.index(0,3)).toInt(), 1); |
|
566 |
} |
|
567 |
||
568 |
model.insertRows(0, 2); |
|
569 |
model.setData(model.index(0, 0), 1012); |
|
570 |
model.setData(model.index(0, 1), "george"); |
|
571 |
model.setData(model.index(0, 2), 2); |
|
572 |
model.setData(model.index(0, 3), 2); |
|
573 |
||
574 |
model.setData(model.index(1, 0), 1013); |
|
575 |
model.setData(model.index(1, 1), "kramer"); |
|
576 |
model.setData(model.index(1, 2), 2); |
|
577 |
model.setData(model.index(1, 3), 1); |
|
578 |
||
579 |
QCOMPARE(model.data(model.index(0,0)).toInt(),1012); |
|
580 |
QCOMPARE(model.data(model.index(0,1)).toString(), QString("george")); |
|
581 |
QCOMPARE(model.data(model.index(0,2)).toString(), QString("mister")); |
|
582 |
if (!db.driverName().startsWith("QTDS")) |
|
583 |
QCOMPARE(model.data(model.index(0,3)).toString(), QString("mister")); |
|
584 |
else |
|
585 |
QCOMPARE(model.data(model.index(0,3)).toInt(), 2); |
|
586 |
||
587 |
||
588 |
QCOMPARE(model.data(model.index(1,0)).toInt(),1013); |
|
589 |
QCOMPARE(model.data(model.index(1,1)).toString(), QString("kramer")); |
|
590 |
QCOMPARE(model.data(model.index(1,2)).toString(), QString("mister")); |
|
591 |
if (!db.driverName().startsWith("QTDS")) |
|
592 |
QCOMPARE(model.data(model.index(1,3)).toString(), QString("herr")); |
|
593 |
else |
|
594 |
QCOMPARE(model.data(model.index(1,3)).toInt(), 1); |
|
595 |
||
596 |
QCOMPARE(model.data(model.index(2,0)).toInt(), 1); |
|
597 |
QCOMPARE(model.data(model.index(2,1)).toString(), QString("harry")); |
|
598 |
QCOMPARE(model.data(model.index(2,2)).toString(), QString("herr")); |
|
599 |
if (!db.driverName().startsWith("QTDS")) |
|
600 |
QCOMPARE(model.data(model.index(2,3)).toString(), QString("herr")); |
|
601 |
else |
|
602 |
QCOMPARE(model.data(model.index(2,3)).toInt(), 1); |
|
603 |
||
604 |
QVERIFY_SQL(model, submitAll()); |
|
605 |
} |
|
606 |
||
607 |
void tst_QSqlRelationalTableModel::removeColumn() |
|
608 |
{ |
|
609 |
QFETCH_GLOBAL(QString, dbName); |
|
610 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
611 |
CHECK_DATABASE(db); |
|
612 |
recreateTestTables(db); |
|
613 |
||
614 |
QSqlRelationalTableModel model(0, db); |
|
615 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
616 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
617 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 618 |
QVERIFY_SQL(model, select()); |
619 |
||
620 |
QVERIFY_SQL(model, removeColumn(3)); |
|
621 |
QVERIFY_SQL(model, select()); |
|
622 |
||
623 |
QCOMPARE(model.columnCount(), 3); |
|
624 |
||
625 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); |
|
626 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); |
|
627 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
628 |
QCOMPARE(model.data(model.index(0, 3)), QVariant()); |
|
629 |
||
630 |
// try removing more than one column |
|
631 |
QVERIFY_SQL(model, removeColumns(1, 2)); |
|
632 |
QCOMPARE(model.columnCount(), 1); |
|
633 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); |
|
634 |
QCOMPARE(model.data(model.index(0, 1)), QVariant()); |
|
635 |
||
636 |
} |
|
637 |
||
638 |
void tst_QSqlRelationalTableModel::filter() |
|
639 |
{ |
|
640 |
QFETCH_GLOBAL(QString, dbName); |
|
641 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
642 |
CHECK_DATABASE(db); |
|
643 |
recreateTestTables(db); |
|
644 |
||
645 |
QSqlRelationalTableModel model(0, db); |
|
646 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
647 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
648 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 649 |
model.setFilter("title = 'herr'"); |
650 |
||
651 |
QVERIFY_SQL(model, select()); |
|
652 |
QCOMPARE(model.rowCount(), 2); |
|
653 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
654 |
QCOMPARE(model.data(model.index(1, 2)).toString(), QString("herr")); |
|
655 |
} |
|
656 |
||
657 |
void tst_QSqlRelationalTableModel::sort() |
|
658 |
{ |
|
659 |
QFETCH_GLOBAL(QString, dbName); |
|
660 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
661 |
CHECK_DATABASE(db); |
|
662 |
||
663 |
QSqlRelationalTableModel model(0, db); |
|
664 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
665 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
666 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 667 |
if (!db.driverName().startsWith("QTDS")) |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
668 |
model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); |
0 | 669 |
|
670 |
model.setSort(2, Qt::DescendingOrder); |
|
671 |
QVERIFY_SQL(model, select()); |
|
672 |
||
673 |
QCOMPARE(model.rowCount(), 4); |
|
674 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); |
|
675 |
QCOMPARE(model.data(model.index(1, 2)).toString(), QString("mister")); |
|
676 |
QCOMPARE(model.data(model.index(2, 2)).toString(), QString("herr")); |
|
677 |
QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); |
|
678 |
||
679 |
||
680 |
model.setSort(3, Qt::AscendingOrder); |
|
681 |
QVERIFY_SQL(model, select()); |
|
682 |
||
683 |
if (!db.driverName().startsWith("QTDS")) { |
|
684 |
QCOMPARE(model.rowCount(), 4); |
|
685 |
QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); |
|
686 |
QCOMPARE(model.data(model.index(1, 3)).toString(), QString("mister")); |
|
687 |
QCOMPARE(model.data(model.index(2, 3)).toString(), QString("mister")); |
|
688 |
QCOMPARE(model.data(model.index(3, 3)).toString(), QString("mister")); |
|
689 |
} else { |
|
690 |
QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); |
|
691 |
QCOMPARE(model.data(model.index(1, 3)).toInt(), 2); |
|
692 |
QCOMPARE(model.data(model.index(2, 3)).toInt(), 2); |
|
693 |
QCOMPARE(model.data(model.index(3, 3)).toInt(), 2); |
|
694 |
} |
|
695 |
||
696 |
} |
|
697 |
||
698 |
static void testRevert(QSqlRelationalTableModel &model) |
|
699 |
{ |
|
700 |
/* revert single row */ |
|
701 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
702 |
QVERIFY(model.setData(model.index(0, 2), 2, Qt::EditRole)); |
|
703 |
||
704 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); |
|
705 |
model.revertRow(0); |
|
706 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
707 |
||
708 |
/* revert all */ |
|
709 |
QVERIFY(model.setData(model.index(0, 2), 2, Qt::EditRole)); |
|
710 |
||
711 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); |
|
712 |
model.revertAll(); |
|
713 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
714 |
||
715 |
// the following only works for OnManualSubmit |
|
716 |
if (model.editStrategy() != QSqlTableModel::OnManualSubmit) |
|
717 |
return; |
|
718 |
||
719 |
/* revert inserted rows */ |
|
720 |
int initialRowCount = model.rowCount(); |
|
721 |
QVERIFY(model.insertRows(4, 4)); |
|
722 |
QVERIFY(model.rowCount() == (initialRowCount + 4)); |
|
723 |
||
724 |
/* make sure the new rows are initialized to nothing */ |
|
725 |
QVERIFY(model.data(model.index(4, 2)).toString().isEmpty()); |
|
726 |
QVERIFY(model.data(model.index(5, 2)).toString().isEmpty()); |
|
727 |
QVERIFY(model.data(model.index(6, 2)).toString().isEmpty()); |
|
728 |
QVERIFY(model.data(model.index(7, 2)).toString().isEmpty()); |
|
729 |
||
730 |
/* Set some values */ |
|
731 |
QVERIFY(model.setData(model.index(4, 0), 42, Qt::EditRole)); |
|
732 |
QVERIFY(model.setData(model.index(5, 0), 43, Qt::EditRole)); |
|
733 |
QVERIFY(model.setData(model.index(6, 0), 44, Qt::EditRole)); |
|
734 |
QVERIFY(model.setData(model.index(7, 0), 45, Qt::EditRole)); |
|
735 |
||
736 |
QVERIFY(model.setData(model.index(4, 2), 2, Qt::EditRole)); |
|
737 |
QVERIFY(model.setData(model.index(5, 2), 2, Qt::EditRole)); |
|
738 |
QVERIFY(model.setData(model.index(6, 2), 1, Qt::EditRole)); |
|
739 |
QVERIFY(model.setData(model.index(7, 2), 2, Qt::EditRole)); |
|
740 |
||
741 |
/* Now revert the newly inserted rows */ |
|
742 |
model.revertAll(); |
|
743 |
QVERIFY(model.rowCount() == initialRowCount); |
|
744 |
||
745 |
/* Insert rows again */ |
|
746 |
QVERIFY(model.insertRows(4, 4)); |
|
747 |
||
748 |
/* make sure the new rows are initialized to nothing */ |
|
749 |
QVERIFY(model.data(model.index(4, 2)).toString().isEmpty()); |
|
750 |
QVERIFY(model.data(model.index(5, 2)).toString().isEmpty()); |
|
751 |
QVERIFY(model.data(model.index(6, 2)).toString().isEmpty()); |
|
752 |
QVERIFY(model.data(model.index(7, 2)).toString().isEmpty()); |
|
753 |
} |
|
754 |
||
755 |
void tst_QSqlRelationalTableModel::revert() |
|
756 |
{ |
|
757 |
QFETCH_GLOBAL(QString, dbName); |
|
758 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
759 |
CHECK_DATABASE(db); |
|
760 |
||
761 |
QSqlRelationalTableModel model(0, db); |
|
762 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
763 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
764 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
765 |
model.setRelation(3, QSqlRelation(reltest4, "id", "name")); |
0 | 766 |
|
767 |
model.setSort(0, Qt::AscendingOrder); |
|
768 |
||
769 |
QVERIFY_SQL(model, select()); |
|
770 |
QCOMPARE(model.data(model.index(0, 0)).toString(), QString("1")); |
|
771 |
||
772 |
testRevert(model); |
|
773 |
if (QTest::currentTestFailed()) |
|
774 |
return; |
|
775 |
||
776 |
/* and again with OnManualSubmit */ |
|
777 |
model.setEditStrategy(QSqlTableModel::OnManualSubmit); |
|
778 |
testRevert(model); |
|
779 |
} |
|
780 |
||
781 |
void tst_QSqlRelationalTableModel::clearDisplayValuesCache() |
|
782 |
{ |
|
783 |
QFETCH_GLOBAL(QString, dbName); |
|
784 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
785 |
CHECK_DATABASE(db); |
|
786 |
||
787 |
QSqlRelationalTableModel model(0, db); |
|
788 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
789 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
790 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 791 |
|
792 |
if (!db.driverName().startsWith("QTDS")) |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
793 |
model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); |
0 | 794 |
model.setSort(1, Qt::AscendingOrder); |
795 |
model.setEditStrategy(QSqlTableModel::OnManualSubmit); |
|
796 |
||
797 |
QVERIFY_SQL(model, select()); |
|
798 |
||
799 |
QCOMPARE(model.data(model.index(3, 0)).toInt(), 3); |
|
800 |
QCOMPARE(model.data(model.index(3, 1)).toString(), QString("vohi")); |
|
801 |
QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); |
|
802 |
if (!db.driverName().startsWith("QTDS")) |
|
803 |
QCOMPARE(model.data(model.index(3, 3)).toString(), QString("mister")); |
|
804 |
else |
|
805 |
QCOMPARE(model.data(model.index(3, 3)).toInt(), 2 ); |
|
806 |
||
807 |
model.insertRow(model.rowCount()); |
|
808 |
QVERIFY(model.setData(model.index(4, 0), 5, Qt::EditRole)); |
|
809 |
QVERIFY(model.setData(model.index(4, 1), "anders", Qt::EditRole)); |
|
810 |
QVERIFY(model.setData(model.index(4, 2), 1, Qt::EditRole)); |
|
811 |
QVERIFY(model.setData(model.index(4, 3), 1, Qt::EditRole)); |
|
812 |
model.submitAll(); |
|
813 |
||
814 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 5); |
|
815 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("anders")); |
|
816 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
817 |
if (!db.driverName().startsWith("QTDS")) |
|
818 |
QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); |
|
819 |
else |
|
820 |
QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); |
|
821 |
||
822 |
QCOMPARE(model.data(model.index(4, 0)).toInt(), 3); |
|
823 |
QCOMPARE(model.data(model.index(4, 1)).toString(), QString("vohi")); |
|
824 |
QCOMPARE(model.data(model.index(4, 2)).toString(), QString("herr")); |
|
825 |
if (!db.driverName().startsWith("QTDS")) |
|
826 |
QCOMPARE(model.data(model.index(4, 3)).toString(), QString("mister")); |
|
827 |
else |
|
828 |
QCOMPARE(model.data(model.index(4, 3)).toInt(), 2); |
|
829 |
} |
|
830 |
||
831 |
// For task 140782 and 176374: If the main table and the the related tables uses the same |
|
832 |
// name for a column or display column then insertRecord() would return true though it |
|
833 |
// actually failed. |
|
834 |
void tst_QSqlRelationalTableModel::insertRecordDuplicateFieldNames() |
|
835 |
{ |
|
836 |
QFETCH_GLOBAL(QString, dbName); |
|
837 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
838 |
CHECK_DATABASE(db); |
|
839 |
||
840 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
841 |
model.setTable(reltest3); |
0 | 842 |
model.setEditStrategy(QSqlTableModel::OnManualSubmit); |
843 |
model.setSort(0, Qt::AscendingOrder); |
|
844 |
||
845 |
// Duplication of "name", used in both reltest3 and reltest4. |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
846 |
model.setRelation(2, QSqlRelation(reltest4, "id", "name")); |
0 | 847 |
QVERIFY_SQL(model, select()); |
848 |
||
849 |
if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
850 |
QCOMPARE(model.record(1).value((reltest4+QLatin1String("_name_2")).toUpper()).toString(), |
0 | 851 |
QString("Trondheim")); |
852 |
} else { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
853 |
QCOMPARE(model.record(1).value((reltest4+QLatin1String("_name_2"))).toString(), |
0 | 854 |
QString("Trondheim")); |
855 |
} |
|
856 |
||
857 |
QSqlRecord rec = model.record(); |
|
858 |
rec.setValue(0, 3); |
|
859 |
rec.setValue(1, "Berge"); |
|
860 |
rec.setValue(2, 1); // Must insert the key value |
|
861 |
||
862 |
if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { |
|
863 |
QCOMPARE(rec.fieldName(0), QLatin1String("ID")); |
|
864 |
QCOMPARE(rec.fieldName(1), QLatin1String("NAME")); // This comes from main table |
|
865 |
} else { |
|
866 |
QCOMPARE(rec.fieldName(0), QLatin1String("id")); |
|
867 |
QCOMPARE(rec.fieldName(1), QLatin1String("name")); |
|
868 |
} |
|
869 |
||
870 |
// The duplicate field names is aliased because it's comes from the relation's display column. |
|
871 |
if(db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
872 |
QCOMPARE(rec.fieldName(2), (reltest4+QLatin1String("_name_2")).toUpper()); |
0 | 873 |
else |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
874 |
QCOMPARE(rec.fieldName(2), reltest4+QLatin1String("_name_2")); |
0 | 875 |
|
876 |
QVERIFY(model.insertRecord(-1, rec)); |
|
877 |
QCOMPARE(model.data(model.index(2, 2)).toString(), QString("Oslo")); |
|
878 |
QVERIFY(model.submitAll()); |
|
879 |
QCOMPARE(model.data(model.index(2, 2)).toString(), QString("Oslo")); |
|
880 |
} |
|
881 |
||
882 |
void tst_QSqlRelationalTableModel::invalidData() |
|
883 |
{ |
|
884 |
QFETCH_GLOBAL(QString, dbName); |
|
885 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
886 |
CHECK_DATABASE(db); |
|
887 |
||
888 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
889 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
890 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 891 |
QVERIFY_SQL(model, select()); |
892 |
||
893 |
//try set a non-existent relational key |
|
894 |
QVERIFY(model.setData(model.index(0, 2), 3) == false); |
|
895 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
896 |
||
897 |
//try to set data in non valid index |
|
898 |
QVERIFY(model.setData(model.index(0,10),5) == false); |
|
899 |
} |
|
900 |
||
901 |
void tst_QSqlRelationalTableModel::relationModel() |
|
902 |
{ |
|
903 |
QFETCH_GLOBAL(QString, dbName); |
|
904 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
905 |
CHECK_DATABASE(db); |
|
906 |
||
907 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
908 |
model.setTable(reltest1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
909 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 910 |
QVERIFY_SQL(model, select()); |
911 |
||
912 |
QVERIFY(model.relationModel(0) == NULL); |
|
913 |
QVERIFY(model.relationModel(1) == NULL); |
|
914 |
QVERIFY(model.relationModel(2) != NULL); |
|
915 |
QVERIFY(model.relationModel(3) == NULL); |
|
916 |
QVERIFY(model.relationModel(4) == NULL); |
|
917 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
918 |
model.setRelation(3, QSqlRelation(reltest4, "id", "name")); |
0 | 919 |
QVERIFY_SQL(model, select()); |
920 |
||
921 |
QVERIFY(model.relationModel(0) == NULL); |
|
922 |
QVERIFY(model.relationModel(1) == NULL); |
|
923 |
QVERIFY(model.relationModel(2) != NULL); |
|
924 |
QVERIFY(model.relationModel(3) != NULL); |
|
925 |
QVERIFY(model.relationModel(4) == NULL); |
|
926 |
||
927 |
QSqlTableModel *rel_model = model.relationModel(2); |
|
928 |
QCOMPARE(rel_model->data(rel_model->index(0,1)).toString(), QString("herr")); |
|
929 |
} |
|
930 |
||
931 |
void tst_QSqlRelationalTableModel::casing() |
|
932 |
{ |
|
933 |
QFETCH_GLOBAL(QString, dbName); |
|
934 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
935 |
CHECK_DATABASE(db); |
|
936 |
||
937 |
if (db.driverName().startsWith("QSQLITE") || db.driverName().startsWith("QIBASE") || tst_Databases::isSqlServer(db)) |
|
938 |
QSKIP("The casing test for this database is irrelevant since this database does not treat different cases as separate entities", SkipAll); |
|
939 |
||
940 |
QSqlQuery q(db); |
|
941 |
QVERIFY_SQL( q, exec("create table " + qTableName("CASETEST1", db.driver()).toUpper() + |
|
942 |
" (id int not null primary key, name varchar(20), title_key int, another_title_key int)")); |
|
943 |
||
944 |
if( !q.exec("create table " + qTableName("casetest1", db.driver()) + |
|
945 |
" (ident int not null primary key, name varchar(20), title_key int)")) |
|
946 |
QSKIP("The casing test for this database is irrelevant since this database does not treat different cases as separate entities", SkipAll); |
|
947 |
||
948 |
QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db.driver()).toUpper() + " values(1, 'harry', 1, 2)")); |
|
949 |
QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db.driver()).toUpper() + " values(2, 'trond', 2, 1)")); |
|
950 |
QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db.driver()).toUpper() + " values(3, 'vohi', 1, 2)")); |
|
951 |
QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db.driver()).toUpper() + " values(4, 'boris', 2, 2)")); |
|
952 |
QVERIFY_SQL( q, exec("insert into " + qTableName("casetest1", db.driver()) + " values(1, 'jerry', 1)")); |
|
953 |
QVERIFY_SQL( q, exec("insert into " + qTableName("casetest1", db.driver()) + " values(2, 'george', 2)")); |
|
954 |
QVERIFY_SQL( q, exec("insert into " + qTableName("casetest1", db.driver()) + " values(4, 'kramer', 2)")); |
|
955 |
||
956 |
if (db.driverName().startsWith("QOCI")) { |
|
957 |
//try an owner that doesn't exist |
|
958 |
QSqlRecord rec = db.driver()->record("doug." + qTableName("CASETEST1", db.driver()).toUpper()); |
|
959 |
QCOMPARE( rec.count(), 0); |
|
960 |
||
961 |
//try an owner that does exist |
|
962 |
rec = db.driver()->record(db.userName() + "." + qTableName("CASETEST1", db.driver()).toUpper()); |
|
963 |
QCOMPARE( rec.count(), 4); |
|
964 |
} |
|
965 |
QSqlRecord rec = db.driver()->record(qTableName("CASETEST1", db.driver()).toUpper()); |
|
966 |
QCOMPARE( rec.count(), 4); |
|
967 |
||
968 |
rec = db.driver()->record(qTableName("casetest1", db.driver())); |
|
969 |
QCOMPARE( rec.count(), 3); |
|
970 |
||
971 |
QSqlTableModel upperCaseModel(0, db); |
|
972 |
upperCaseModel.setTable(qTableName("CASETEST1", db.driver()).toUpper()); |
|
973 |
||
974 |
QCOMPARE(upperCaseModel.tableName(),qTableName("CASETEST1",db.driver()).toUpper()); |
|
975 |
||
976 |
QVERIFY_SQL(upperCaseModel, select()); |
|
977 |
||
978 |
QCOMPARE(upperCaseModel.rowCount(), 4); |
|
979 |
||
980 |
QSqlTableModel lowerCaseModel(0, db); |
|
981 |
lowerCaseModel.setTable(qTableName("casetest1", db.driver())); |
|
982 |
QCOMPARE(lowerCaseModel.tableName(), qTableName("casetest1",db.driver())); |
|
983 |
QVERIFY_SQL(lowerCaseModel, select()); |
|
984 |
||
985 |
QCOMPARE(lowerCaseModel.rowCount(), 3); |
|
986 |
||
987 |
QSqlRelationalTableModel model(0, db); |
|
988 |
model.setTable(qTableName("CASETEST1", db.driver()).toUpper()); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
989 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 990 |
QVERIFY_SQL(model, select()); |
991 |
||
992 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); |
|
993 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); |
|
994 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
995 |
} |
|
996 |
||
997 |
void tst_QSqlRelationalTableModel::escapedRelations() |
|
998 |
{ |
|
999 |
QFETCH_GLOBAL(QString, dbName); |
|
1000 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1001 |
CHECK_DATABASE(db); |
|
1002 |
recreateTestTables(db); |
|
1003 |
||
1004 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1005 |
model.setTable(reltest1); |
0 | 1006 |
|
1007 |
//try with relation table name quoted |
|
1008 |
if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1009 |
model.setRelation(2, QSqlRelation(db.driver()->escapeIdentifier(reltest2.toUpper(),QSqlDriver::TableName), |
0 | 1010 |
"tid", |
1011 |
"title")); |
|
1012 |
} else { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1013 |
model.setRelation(2, QSqlRelation(db.driver()->escapeIdentifier(reltest2,QSqlDriver::TableName), |
0 | 1014 |
"tid", |
1015 |
"title")); |
|
1016 |
||
1017 |
} |
|
1018 |
QVERIFY_SQL(model, select()); |
|
1019 |
||
1020 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); |
|
1021 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); |
|
1022 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
1023 |
||
1024 |
//try with index column quoted |
|
1025 |
if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1026 |
model.setRelation(2, QSqlRelation(reltest2, |
0 | 1027 |
db.driver()->escapeIdentifier("tid", QSqlDriver::FieldName).toUpper(), |
1028 |
"title")); |
|
1029 |
} else { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1030 |
model.setRelation(2, QSqlRelation(reltest2, |
0 | 1031 |
db.driver()->escapeIdentifier("tid", QSqlDriver::FieldName), |
1032 |
"title")); |
|
1033 |
} |
|
1034 |
QVERIFY_SQL(model, select()); |
|
1035 |
||
1036 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); |
|
1037 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); |
|
1038 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
1039 |
||
1040 |
//try with display column quoted |
|
1041 |
||
1042 |
if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { |
|
1043 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1044 |
model.setRelation(2, QSqlRelation(reltest2, |
0 | 1045 |
"tid", |
1046 |
db.driver()->escapeIdentifier("title", QSqlDriver::FieldName).toUpper())); |
|
1047 |
} else { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1048 |
model.setRelation(2, QSqlRelation(reltest2, |
0 | 1049 |
"tid", |
1050 |
db.driver()->escapeIdentifier("title", QSqlDriver::FieldName))); |
|
1051 |
} |
|
1052 |
||
1053 |
QVERIFY_SQL(model, select()); |
|
1054 |
||
1055 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); |
|
1056 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); |
|
1057 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
1058 |
||
1059 |
//try with tablename and index and display columns quoted in the relation |
|
1060 |
||
1061 |
if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1062 |
model.setRelation(2, QSqlRelation(reltest2, |
0 | 1063 |
"tid", |
1064 |
db.driver()->escapeIdentifier("title", QSqlDriver::FieldName).toUpper())); |
|
1065 |
} else { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1066 |
model.setRelation(2, QSqlRelation(reltest2, |
0 | 1067 |
"tid", |
1068 |
db.driver()->escapeIdentifier("title", QSqlDriver::FieldName))); |
|
1069 |
} |
|
1070 |
QVERIFY_SQL(model, select()); |
|
1071 |
||
1072 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); |
|
1073 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); |
|
1074 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); |
|
1075 |
} |
|
1076 |
||
1077 |
void tst_QSqlRelationalTableModel::escapedTableName() |
|
1078 |
{ |
|
1079 |
QFETCH_GLOBAL(QString, dbName); |
|
1080 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1081 |
CHECK_DATABASE(db); |
|
1082 |
||
1083 |
// set the values using OnRowChange Strategy with an escaped tablename |
|
1084 |
{ |
|
1085 |
QSqlRelationalTableModel model(0, db); |
|
1086 |
||
1087 |
if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1088 |
model.setTable(db.driver()->escapeIdentifier(reltest1.toUpper(), QSqlDriver::TableName)); |
0 | 1089 |
} else { |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1090 |
model.setTable(db.driver()->escapeIdentifier(reltest1, QSqlDriver::TableName)); |
0 | 1091 |
} |
1092 |
model.setSort(0, Qt::AscendingOrder); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1093 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 1094 |
QVERIFY_SQL(model, select()); |
1095 |
||
1096 |
QVERIFY(model.setData(model.index(0, 1), QString("harry2"))); |
|
1097 |
QVERIFY(model.setData(model.index(0, 2), 2)); |
|
1098 |
||
1099 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry2")); |
|
1100 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); |
|
1101 |
||
1102 |
model.submit(); |
|
1103 |
||
1104 |
QVERIFY(model.setData(model.index(3,1), QString("boris2"))); |
|
1105 |
QVERIFY(model.setData(model.index(3, 2), 1)); |
|
1106 |
||
1107 |
QCOMPARE(model.data(model.index(3,1)).toString(), QString("boris2")); |
|
1108 |
QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); |
|
1109 |
||
1110 |
model.submit(); |
|
1111 |
} |
|
1112 |
{ //verify values |
|
1113 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1114 |
model.setTable(reltest1); |
0 | 1115 |
model.setSort(0, Qt::AscendingOrder); |
1116 |
QVERIFY_SQL(model, select()); |
|
1117 |
||
1118 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry2")); |
|
1119 |
QCOMPARE(model.data(model.index(0, 2)).toInt(), 2); |
|
1120 |
QCOMPARE(model.data(model.index(3, 1)).toString(), QString("boris2")); |
|
1121 |
QCOMPARE(model.data(model.index(3, 2)).toInt(), 1); |
|
1122 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1123 |
model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); |
0 | 1124 |
QVERIFY_SQL(model, select()); |
1125 |
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); |
|
1126 |
QCOMPARE(model.data(model.index(3,2)).toString(), QString("herr")); |
|
1127 |
||
1128 |
} |
|
1129 |
} |
|
1130 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1131 |
void tst_QSqlRelationalTableModel::whiteSpaceInIdentifiers() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1132 |
{ |
0 | 1133 |
QFETCH_GLOBAL(QString, dbName); |
1134 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
|
1135 |
CHECK_DATABASE(db); |
|
1136 |
||
1137 |
if (!testWhiteSpaceNames(db.driverName())) |
|
1138 |
QSKIP("White space test irrelevant for driver", SkipAll); |
|
1139 |
QSqlRelationalTableModel model(0, db); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1140 |
model.setTable(db.driver()->escapeIdentifier(qTableName("rel", __FILE__)+" test6", QSqlDriver::TableName)); |
0 | 1141 |
model.setSort(0, Qt::DescendingOrder); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1142 |
model.setRelation(1, QSqlRelation(db.driver()->escapeIdentifier(qTableName("rel", __FILE__)+" test7", QSqlDriver::TableName), |
0 | 1143 |
db.driver()->escapeIdentifier("city id", QSqlDriver::FieldName), |
1144 |
db.driver()->escapeIdentifier("city name", QSqlDriver::FieldName))); |
|
1145 |
QVERIFY_SQL(model, select()); |
|
1146 |
||
1147 |
QCOMPARE(model.data(model.index(0,1)).toString(), QString("Washington")); |
|
1148 |
QCOMPARE(model.data(model.index(1,1)).toString(), QString("New York")); |
|
1149 |
||
1150 |
QSqlRecord rec; |
|
1151 |
QSqlField f1("id", QVariant::Int); |
|
1152 |
QSqlField f2(db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName), QVariant::Int); |
|
1153 |
QSqlField f3(db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName), QVariant::Int); |
|
1154 |
||
1155 |
f1.setValue(3); |
|
1156 |
f2.setValue(2); |
|
1157 |
f3.setValue(7); |
|
1158 |
||
1159 |
f1.setGenerated(true); |
|
1160 |
f2.setGenerated(true); |
|
1161 |
f3.setGenerated(true); |
|
1162 |
||
1163 |
rec.append(f1); |
|
1164 |
rec.append(f2); |
|
1165 |
rec.append(f3); |
|
1166 |
||
1167 |
QVERIFY_SQL(model, insertRecord(-1, rec)); |
|
1168 |
model.submitAll(); |
|
1169 |
||
1170 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 3); |
|
1171 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("Washington")); |
|
1172 |
QCOMPARE(model.data(model.index(0, 2)).toInt(), 7); |
|
1173 |
||
1174 |
//TODO: For some reson setting a record using manual submit fails |
|
1175 |
//model.setEditStrategy(QSqlTableModel::OnManualSubmit); |
|
1176 |
||
1177 |
QSqlRecord recNew; |
|
1178 |
QSqlField f1New("id", QVariant::Int); |
|
1179 |
QSqlField f2New(db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName), QVariant::Int); |
|
1180 |
QSqlField f3New(db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName), QVariant::Int); |
|
1181 |
||
1182 |
f1New.setValue(4); |
|
1183 |
f2New.setValue(1); |
|
1184 |
f3New.setValue(6); |
|
1185 |
||
1186 |
f1New.setGenerated(true); |
|
1187 |
f2New.setGenerated(true); |
|
1188 |
f3New.setGenerated(true); |
|
1189 |
||
1190 |
recNew.append(f1New); |
|
1191 |
recNew.append(f2New); |
|
1192 |
recNew.append(f3New); |
|
1193 |
||
1194 |
QVERIFY_SQL(model, setRecord(0, recNew)); |
|
1195 |
||
1196 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 4); |
|
1197 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("New York")); |
|
1198 |
QCOMPARE(model.data(model.index(0, 2)).toInt(), 6); |
|
1199 |
||
1200 |
QVERIFY_SQL(model, submitAll()); |
|
1201 |
QCOMPARE(model.data(model.index(0, 0)).toInt(), 4); |
|
1202 |
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("New York")); |
|
1203 |
QCOMPARE(model.data(model.index(0, 2)).toInt(), 6); |
|
1204 |
} |
|
1205 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1206 |
void tst_QSqlRelationalTableModel::psqlSchemaTest() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1207 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1208 |
QFETCH_GLOBAL(QString, dbName); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1209 |
QSqlDatabase db = QSqlDatabase::database(dbName); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1210 |
CHECK_DATABASE(db); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1211 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1212 |
if(!tst_Databases::isPostgreSQL(db)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1213 |
QSKIP("Postgresql specific test", SkipSingle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1214 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1215 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1216 |
QSqlRelationalTableModel model(0, db); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1217 |
QSqlQuery q(db); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1218 |
QVERIFY_SQL(q, exec("create schema "+qTableName("QTBUG_5373", __FILE__))); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1219 |
QVERIFY_SQL(q, exec("create schema "+qTableName("QTBUG_5373_s2", __FILE__))); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1220 |
QVERIFY_SQL(q, exec("create table "+qTableName("QTBUG_5373", __FILE__)+"."+qTableName("document", __FILE__)+"(document_id int primary key, relatingid int, userid int)")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1221 |
QVERIFY_SQL(q, exec("create table "+qTableName("QTBUG_5373_s2", __FILE__)+"."+qTableName("user", __FILE__)+"(userid int primary key, username char(40))")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1222 |
model.setTable(qTableName("QTBUG_5373", __FILE__)+"."+qTableName("document", __FILE__)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1223 |
model.setRelation(1, QSqlRelation(qTableName("QTBUG_5373_s2", __FILE__)+"."+qTableName("user", __FILE__), "userid", "username")); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1224 |
model.setRelation(2, QSqlRelation(qTableName("QTBUG_5373_s2", __FILE__)+"."+qTableName("user", __FILE__), "userid", "username")); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1225 |
QVERIFY_SQL(model, select()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1226 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1227 |
|
0 | 1228 |
QTEST_MAIN(tst_QSqlRelationalTableModel) |
1229 |
#include "tst_qsqlrelationaltablemodel.moc" |