sl@0
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <e32test.h>
|
sl@0
|
17 |
#include <bautils.h>
|
sl@0
|
18 |
#include <sqldb.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
21 |
|
sl@0
|
22 |
RTest TheTest(_L("t_sqlcollate test"));
|
sl@0
|
23 |
|
sl@0
|
24 |
_LIT(KTestDir, "c:\\test\\");
|
sl@0
|
25 |
_LIT(KTestDbName1, "c:\\test\\t_sqlcollate.db");
|
sl@0
|
26 |
|
sl@0
|
27 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
28 |
|
sl@0
|
29 |
void DeleteTestFiles()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
35 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
36 |
//Test macros and functions
|
sl@0
|
37 |
void Check(TInt aValue, TInt aLine)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
if(!aValue)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
DeleteTestFiles();
|
sl@0
|
42 |
TheTest(EFalse, aLine);
|
sl@0
|
43 |
}
|
sl@0
|
44 |
}
|
sl@0
|
45 |
void Check(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
if(aValue != aExpected)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
DeleteTestFiles();
|
sl@0
|
50 |
RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
sl@0
|
51 |
TheTest(EFalse, aLine);
|
sl@0
|
52 |
}
|
sl@0
|
53 |
}
|
sl@0
|
54 |
#define TEST(arg) ::Check((arg), __LINE__)
|
sl@0
|
55 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
56 |
|
sl@0
|
57 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
58 |
|
sl@0
|
59 |
void CreateTestDir()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
RFs fs;
|
sl@0
|
62 |
TInt err = fs.Connect();
|
sl@0
|
63 |
TEST2(err, KErrNone);
|
sl@0
|
64 |
|
sl@0
|
65 |
err = fs.MkDir(KTestDir);
|
sl@0
|
66 |
TEST(err == KErrNone || err == KErrAlreadyExists);
|
sl@0
|
67 |
|
sl@0
|
68 |
fs.Close();
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
72 |
|
sl@0
|
73 |
//Compare aLeft and aRight strings using collated comparison, level 3, default collation method.
|
sl@0
|
74 |
//This function is used when sorting the test names array in CollationTest1L().
|
sl@0
|
75 |
TInt StrSortC3(const TPtrC& aLeft, const TPtrC& aRight)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
return aLeft.CompareC(aRight, 3, NULL);
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
//Compare aLeft and aRight strings using collated comparison, level 1, default collation method.
|
sl@0
|
81 |
//This function is used when sorting the test names array in CollationTest3L().
|
sl@0
|
82 |
TInt StrSortC1(const TPtrC& aLeft, const TPtrC& aRight)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
return aLeft.CompareC(aRight, 1, NULL);
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
88 |
|
sl@0
|
89 |
/**
|
sl@0
|
90 |
@SYMTestCaseID SYSLIB-SQL-CT-1609
|
sl@0
|
91 |
@SYMTestCaseDesc Create a table with a text column with default collation "CompareF"
|
sl@0
|
92 |
and insert some records there.
|
sl@0
|
93 |
Test how the searching operations work executing some SELECT SQL statements.
|
sl@0
|
94 |
@SYMTestPriority High
|
sl@0
|
95 |
@SYMTestActions Testing database search operations using "CompareF" and "CompareC3" collations.
|
sl@0
|
96 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
97 |
@SYMREQ REQ5907
|
sl@0
|
98 |
*/
|
sl@0
|
99 |
void CollationTest1L()
|
sl@0
|
100 |
{
|
sl@0
|
101 |
RSqlDatabase db;
|
sl@0
|
102 |
TInt err = db.Create(KTestDbName1);
|
sl@0
|
103 |
TEST2(err, KErrNone);
|
sl@0
|
104 |
|
sl@0
|
105 |
//Create test database
|
sl@0
|
106 |
RDebug::Print(_L("###Create test database\r\n"));
|
sl@0
|
107 |
_LIT(KCreateSql, "CREATE TABLE A(Name VARCHAR(100) COLLATE CompareF); CREATE INDEX AIdx ON A(Name COLLATE CompareF);");
|
sl@0
|
108 |
err = db.Exec(KCreateSql);
|
sl@0
|
109 |
TEST(err >= 0);
|
sl@0
|
110 |
|
sl@0
|
111 |
//Insert some records. The column "Name" of each record contains the same name but the name characters are
|
sl@0
|
112 |
//variation of upper/lower case letters.
|
sl@0
|
113 |
RDebug::Print(_L("###Insert some records\r\n"));
|
sl@0
|
114 |
_LIT(KInsertSql, "INSERT INTO A(Name) VALUES(");
|
sl@0
|
115 |
//Collation sort order: KNames[1] KNames[3] KNames[0] KNames[2]
|
sl@0
|
116 |
//Long "aaaa..." added to the end of each column value because SQLITE may use non-aligned strings
|
sl@0
|
117 |
//only when the string length is in [32..<cache_page_size>] interval.
|
sl@0
|
118 |
TPtrC KNames[] = {
|
sl@0
|
119 |
_L("aLex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
|
sl@0
|
120 |
_L("ALeX-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
|
sl@0
|
121 |
_L("aleX-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
|
sl@0
|
122 |
_L("Alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")};
|
sl@0
|
123 |
const TInt KInsertSqlStmtCnt = sizeof(KNames)/sizeof(KNames[0]);
|
sl@0
|
124 |
RArray<TPtrC> sortedNames;
|
sl@0
|
125 |
TLinearOrder<TPtrC> order(&StrSortC3);
|
sl@0
|
126 |
|
sl@0
|
127 |
for(TInt i=0;i<KInsertSqlStmtCnt;++i)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
err = sortedNames.InsertInOrder(KNames[i], order);
|
sl@0
|
130 |
TEST2(err, KErrNone);
|
sl@0
|
131 |
|
sl@0
|
132 |
TBuf<128> sql(KInsertSql);
|
sl@0
|
133 |
sql.Append(_L("'"));
|
sl@0
|
134 |
sql.Append(KNames[i]);
|
sl@0
|
135 |
sql.Append(_L("')"));
|
sl@0
|
136 |
err = db.Exec(sql);
|
sl@0
|
137 |
TEST2(err, 1);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
//The next "SELECT" statement must return a set containing all table records
|
sl@0
|
141 |
RDebug::Print(_L("###Select all records\r\n"));
|
sl@0
|
142 |
_LIT(KSelectSql1, "SELECT * FROM A WHERE NAME = 'alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'");
|
sl@0
|
143 |
RSqlStatement stmt;
|
sl@0
|
144 |
err = stmt.Prepare(db, KSelectSql1);
|
sl@0
|
145 |
TEST2(err, KErrNone);
|
sl@0
|
146 |
TInt recCount = 0;
|
sl@0
|
147 |
while(stmt.Next() == KSqlAtRow)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
++recCount;
|
sl@0
|
150 |
TPtrC name = stmt.ColumnTextL(0);
|
sl@0
|
151 |
RDebug::Print(_L("%S\r\n"), &name);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
stmt.Close();
|
sl@0
|
154 |
TEST(recCount == KInsertSqlStmtCnt);
|
sl@0
|
155 |
|
sl@0
|
156 |
//The next "SELECT" statement must return a set containing all table records
|
sl@0
|
157 |
// this tests a LIKE clause with a bound parameter (with wildcards)
|
sl@0
|
158 |
RDebug::Print(_L("###Select all records (LIKE with wildcard)\r\n"));
|
sl@0
|
159 |
_LIT(KSelectSql1a, "SELECT * FROM A WHERE NAME LIKE :Val");
|
sl@0
|
160 |
_LIT(KSearchString,"alex-aaaa%");
|
sl@0
|
161 |
err = stmt.Prepare(db, KSelectSql1a);
|
sl@0
|
162 |
TEST2(err, KErrNone);
|
sl@0
|
163 |
TInt idx=stmt.ParameterIndex(_L(":Val"));
|
sl@0
|
164 |
err=stmt.BindText(idx,KSearchString);
|
sl@0
|
165 |
TEST2(err, KErrNone);
|
sl@0
|
166 |
recCount = 0;
|
sl@0
|
167 |
while(stmt.Next() == KSqlAtRow)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
++recCount;
|
sl@0
|
170 |
TPtrC name = stmt.ColumnTextL(0);
|
sl@0
|
171 |
RDebug::Print(_L("%S\r\n"), &name);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
stmt.Close();
|
sl@0
|
174 |
TEST(recCount == KInsertSqlStmtCnt);
|
sl@0
|
175 |
|
sl@0
|
176 |
//The next "SELECT" statement must return a set containing all table records
|
sl@0
|
177 |
// this tests a LIKE clause with a bound parameter (with no wildcards)
|
sl@0
|
178 |
RDebug::Print(_L("###Select all records (LIKE with no wildcard)\r\n"));
|
sl@0
|
179 |
_LIT(KSelectSql1b, "SELECT * FROM A WHERE NAME LIKE :Val");
|
sl@0
|
180 |
_LIT(KSearchStringA,
|
sl@0
|
181 |
"alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
sl@0
|
182 |
err = stmt.Prepare(db, KSelectSql1b);
|
sl@0
|
183 |
idx=stmt.ParameterIndex(_L(":Val"));
|
sl@0
|
184 |
TEST2(err, KErrNone);
|
sl@0
|
185 |
err=stmt.BindText(idx,KSearchStringA);
|
sl@0
|
186 |
recCount = 0;
|
sl@0
|
187 |
while(stmt.Next() == KSqlAtRow)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
++recCount;
|
sl@0
|
190 |
TPtrC name = stmt.ColumnTextL(0);
|
sl@0
|
191 |
RDebug::Print(_L("%S\r\n"), &name);
|
sl@0
|
192 |
}
|
sl@0
|
193 |
stmt.Close();
|
sl@0
|
194 |
TEST(recCount == KInsertSqlStmtCnt);
|
sl@0
|
195 |
|
sl@0
|
196 |
//The next "SELECT" statement must return a row
|
sl@0
|
197 |
// this tests a LIKE clause with a bound parameter and funny characters
|
sl@0
|
198 |
RDebug::Print(_L("###Select one records (LIKE with bound param with URL chars)\r\n"));
|
sl@0
|
199 |
err=db.Exec(_L("INSERT INTO A(Name) VALUES('http://a.b.c#d')"));
|
sl@0
|
200 |
TEST2(err,1);
|
sl@0
|
201 |
_LIT(KSelectSql1c, "SELECT * FROM A WHERE NAME LIKE :Val");
|
sl@0
|
202 |
_LIT(KSearchStringB,"http%");
|
sl@0
|
203 |
err = stmt.Prepare(db, KSelectSql1c);
|
sl@0
|
204 |
idx=stmt.ParameterIndex(_L(":Val"));
|
sl@0
|
205 |
TEST2(err, KErrNone);
|
sl@0
|
206 |
err=stmt.BindText(idx,KSearchStringB);
|
sl@0
|
207 |
recCount = 0;
|
sl@0
|
208 |
while(stmt.Next() == KSqlAtRow)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
++recCount;
|
sl@0
|
211 |
TPtrC name = stmt.ColumnTextL(0);
|
sl@0
|
212 |
RDebug::Print(_L("%S\r\n"), &name);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
stmt.Close();
|
sl@0
|
215 |
TEST(recCount == 1);
|
sl@0
|
216 |
|
sl@0
|
217 |
|
sl@0
|
218 |
//The next "SELECT" statement must return a set containing all table records, folded comparison used for sorting
|
sl@0
|
219 |
RDebug::Print(_L("###Select all records, folded string comparison\r\n"));
|
sl@0
|
220 |
_LIT(KSelectSql2, "SELECT * FROM A WHERE NAME = 'alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ORDER BY NAME COLLATE CompareF");
|
sl@0
|
221 |
err = stmt.Prepare(db, KSelectSql2);
|
sl@0
|
222 |
TEST2(err, KErrNone);
|
sl@0
|
223 |
|
sl@0
|
224 |
recCount = 0;
|
sl@0
|
225 |
for(TInt j=0;j<KInsertSqlStmtCnt;++j)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
err = stmt.Next();
|
sl@0
|
228 |
TEST2(err, KSqlAtRow);
|
sl@0
|
229 |
++recCount;
|
sl@0
|
230 |
TPtrC name = stmt.ColumnTextL(0);
|
sl@0
|
231 |
RDebug::Print(_L("%S\r\n"), &name);
|
sl@0
|
232 |
TEST(name == KNames[j]);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
stmt.Close();
|
sl@0
|
235 |
TEST(recCount == KInsertSqlStmtCnt);
|
sl@0
|
236 |
|
sl@0
|
237 |
//The next "SELECT" statement must return a set containing all table records, collated comparison used for sorting
|
sl@0
|
238 |
RDebug::Print(_L("###Select all records, collated string comparison\r\n"));
|
sl@0
|
239 |
_LIT(KSelectSql3, "SELECT * FROM A ORDER BY NAME COLLATE CompareC3");
|
sl@0
|
240 |
err = stmt.Prepare(db, KSelectSql3);
|
sl@0
|
241 |
TEST2(err, KErrNone);
|
sl@0
|
242 |
|
sl@0
|
243 |
for(TInt k=0;k<KInsertSqlStmtCnt;++k)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
err = stmt.Next();
|
sl@0
|
246 |
TEST2(err, KSqlAtRow);
|
sl@0
|
247 |
TPtrC name = stmt.ColumnTextL(0);
|
sl@0
|
248 |
RDebug::Print(_L("%S\r\n"), &name);
|
sl@0
|
249 |
TEST(name == sortedNames[k]);
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
stmt.Close();
|
sl@0
|
253 |
|
sl@0
|
254 |
//Cleanup
|
sl@0
|
255 |
sortedNames.Close();
|
sl@0
|
256 |
db.Close();
|
sl@0
|
257 |
|
sl@0
|
258 |
//To debug database reindexing
|
sl@0
|
259 |
err = db.Open(KTestDbName1);
|
sl@0
|
260 |
TEST2(err, KErrNone);
|
sl@0
|
261 |
db.Close();
|
sl@0
|
262 |
|
sl@0
|
263 |
RDebug::Print(_L("###Delete test database\r\n"));
|
sl@0
|
264 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
265 |
}
|
sl@0
|
266 |
|
sl@0
|
267 |
/**
|
sl@0
|
268 |
@SYMTestCaseID SYSLIB-SQL-CT-1610
|
sl@0
|
269 |
@SYMTestCaseDesc Create a table with a text column with default collation "CompareC3"
|
sl@0
|
270 |
and insert some records there.
|
sl@0
|
271 |
Test how the searching operations work executing some SELECT SQL statements.
|
sl@0
|
272 |
@SYMTestPriority High
|
sl@0
|
273 |
@SYMTestActions Testing database sorting operations using "CompareC3" collation.
|
sl@0
|
274 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
275 |
@SYMREQ REQ5907
|
sl@0
|
276 |
*/
|
sl@0
|
277 |
void CollationTest2L()
|
sl@0
|
278 |
{
|
sl@0
|
279 |
RSqlDatabase db;
|
sl@0
|
280 |
TInt err = db.Create(KTestDbName1);
|
sl@0
|
281 |
TEST2(err, KErrNone);
|
sl@0
|
282 |
|
sl@0
|
283 |
//Create test database
|
sl@0
|
284 |
RDebug::Print(_L("###Create test database\r\n"));
|
sl@0
|
285 |
_LIT(KCreateSql, "CREATE TABLE A(Name VARCHAR(100) COLLATE CompareC3)");
|
sl@0
|
286 |
err = db.Exec(KCreateSql);
|
sl@0
|
287 |
TEST(err >= 0);
|
sl@0
|
288 |
|
sl@0
|
289 |
//Insert some records.
|
sl@0
|
290 |
RDebug::Print(_L("###Insert some records\r\n"));
|
sl@0
|
291 |
_LIT(KInsertSql, "INSERT INTO A(Name) VALUES(");
|
sl@0
|
292 |
TPtrC KNames[] = {
|
sl@0
|
293 |
_L("aAaA"),
|
sl@0
|
294 |
_L("AAaa"),
|
sl@0
|
295 |
_L("aaAA"),
|
sl@0
|
296 |
_L("aaaA")};
|
sl@0
|
297 |
const TInt KInsertSqlStmtCnt = sizeof(KNames)/sizeof(KNames[0]);
|
sl@0
|
298 |
|
sl@0
|
299 |
for(TInt i=0;i<KInsertSqlStmtCnt;++i)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
TBuf<128> sql(KInsertSql);
|
sl@0
|
302 |
sql.Append(_L("'"));
|
sl@0
|
303 |
sql.Append(KNames[i]);
|
sl@0
|
304 |
sql.Append(_L("')"));
|
sl@0
|
305 |
err = db.Exec(sql);
|
sl@0
|
306 |
TEST2(err, 1);
|
sl@0
|
307 |
}
|
sl@0
|
308 |
|
sl@0
|
309 |
RSqlStatement stmt;
|
sl@0
|
310 |
|
sl@0
|
311 |
//The next "SELECT" statement must return a set containing all table
|
sl@0
|
312 |
//records which Name column value is bigger than "aaAA"
|
sl@0
|
313 |
RDebug::Print(_L("###Select all records, which Name column value is bigger than 'aaAA'\r\n"));
|
sl@0
|
314 |
_LIT(KSelectSql2, "SELECT * FROM A WHERE NAME > 'aaAA'");
|
sl@0
|
315 |
err = stmt.Prepare(db, KSelectSql2);
|
sl@0
|
316 |
TEST2(err, KErrNone);
|
sl@0
|
317 |
|
sl@0
|
318 |
while((err = stmt.Next()) == KSqlAtRow)
|
sl@0
|
319 |
{
|
sl@0
|
320 |
TPtrC name = stmt.ColumnTextL(0);
|
sl@0
|
321 |
RDebug::Print(_L("%S\r\n"), &name);
|
sl@0
|
322 |
TInt res = name.CompareC(KNames[2], 3, NULL);
|
sl@0
|
323 |
TEST(res > 0);
|
sl@0
|
324 |
}
|
sl@0
|
325 |
stmt.Close();
|
sl@0
|
326 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
327 |
|
sl@0
|
328 |
//Cleanup
|
sl@0
|
329 |
db.Close();
|
sl@0
|
330 |
RDebug::Print(_L("###Delete test database\r\n"));
|
sl@0
|
331 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
332 |
}
|
sl@0
|
333 |
|
sl@0
|
334 |
/**
|
sl@0
|
335 |
@SYMTestCaseID SYSLIB-SQL-CT-1627
|
sl@0
|
336 |
@SYMTestCaseDesc Create a table with a text column "NAME" with default collation "CompareC0"
|
sl@0
|
337 |
and insert some records there. All inserted names are equal if compared at
|
sl@0
|
338 |
collation level 0, but some of them contain accented letters.
|
sl@0
|
339 |
Test how the searching operations work executing some SELECT SQL statements.
|
sl@0
|
340 |
Test how the sorting operations work executing some SELECT SQL statements.
|
sl@0
|
341 |
@SYMTestPriority High
|
sl@0
|
342 |
@SYMTestActions Testing database sorting operations using "CompareC0", "CompareC1", and "CompareC2" collations.
|
sl@0
|
343 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
344 |
@SYMREQ REQ5907
|
sl@0
|
345 |
*/
|
sl@0
|
346 |
void CollationTest3L()
|
sl@0
|
347 |
{
|
sl@0
|
348 |
RSqlDatabase db;
|
sl@0
|
349 |
TInt err = db.Create(KTestDbName1);
|
sl@0
|
350 |
TEST2(err, KErrNone);
|
sl@0
|
351 |
|
sl@0
|
352 |
//Create test database
|
sl@0
|
353 |
RDebug::Print(_L("###Create test database\r\n"));
|
sl@0
|
354 |
_LIT(KCreateSql, "CREATE TABLE A(Name VARCHAR(100) COLLATE CompareC0)");
|
sl@0
|
355 |
err = db.Exec(KCreateSql);
|
sl@0
|
356 |
TEST(err >= 0);
|
sl@0
|
357 |
|
sl@0
|
358 |
//Insert some records. Some of the inserted names have accented letters.
|
sl@0
|
359 |
//But all names are equal if compared at collation level 0.
|
sl@0
|
360 |
RDebug::Print(_L("###Insert some records\r\n"));
|
sl@0
|
361 |
_LIT(KInsertSql, "INSERT INTO A(Name) VALUES(");
|
sl@0
|
362 |
TBuf<10> name1(_L("Dvorak"));
|
sl@0
|
363 |
TBuf<10> name2;
|
sl@0
|
364 |
name2.SetLength(6);
|
sl@0
|
365 |
name2[0] = TChar('D');
|
sl@0
|
366 |
name2[1] = TChar('v');
|
sl@0
|
367 |
name2[2] = TChar('o');
|
sl@0
|
368 |
name2[3] = 0x0158;//LATIN SMALL LETTER R HACEK
|
sl@0
|
369 |
name2[4] = 0x00C1;//LATIN SMALL LETTER A ACUTE
|
sl@0
|
370 |
name2[5] = TChar('k');
|
sl@0
|
371 |
const TPtrC KNames[] = {name1, name2};
|
sl@0
|
372 |
const TInt KInsertSqlStmtCnt = sizeof(KNames)/sizeof(KNames[0]);
|
sl@0
|
373 |
RArray<TPtrC> sortedNames;
|
sl@0
|
374 |
TLinearOrder<TPtrC> order(&StrSortC1);
|
sl@0
|
375 |
|
sl@0
|
376 |
//Insert the records. Also, check how many names are equal to 'dvorak' using collation level 0.
|
sl@0
|
377 |
_LIT(KTestName, "dvorak");
|
sl@0
|
378 |
TInt matchNameCnt = 0;
|
sl@0
|
379 |
for(TInt i=0;i<KInsertSqlStmtCnt;++i)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
if(KNames[i].CompareC(KTestName, 0, NULL) == 0)
|
sl@0
|
382 |
{
|
sl@0
|
383 |
++matchNameCnt;
|
sl@0
|
384 |
}
|
sl@0
|
385 |
|
sl@0
|
386 |
err = sortedNames.InsertInOrder(KNames[i], order);
|
sl@0
|
387 |
TEST2(err, KErrNone);
|
sl@0
|
388 |
|
sl@0
|
389 |
TBuf<128> sql(KInsertSql);
|
sl@0
|
390 |
sql.Append(_L("'"));
|
sl@0
|
391 |
sql.Append(KNames[i]);
|
sl@0
|
392 |
sql.Append(_L("')"));
|
sl@0
|
393 |
err = db.Exec(sql);
|
sl@0
|
394 |
TEST2(err, 1);
|
sl@0
|
395 |
}
|
sl@0
|
396 |
|
sl@0
|
397 |
//The next "SELECT" statement must return a set, which record count must be matchNameCnt.
|
sl@0
|
398 |
RDebug::Print(_L("###Select all records, collated string comparison, level 0\r\n"));
|
sl@0
|
399 |
_LIT(KSelectSql2, "SELECT * FROM A WHERE NAME = 'dvorak'");
|
sl@0
|
400 |
RSqlStatement stmt;
|
sl@0
|
401 |
err = stmt.Prepare(db, KSelectSql2);
|
sl@0
|
402 |
TEST2(err, KErrNone);
|
sl@0
|
403 |
|
sl@0
|
404 |
TInt recCount = 0;
|
sl@0
|
405 |
while((err = stmt.Next()) == KSqlAtRow)
|
sl@0
|
406 |
{
|
sl@0
|
407 |
TPtrC name = stmt.ColumnTextL(0);
|
sl@0
|
408 |
RDebug::Print(_L("%S\r\n"), &name);
|
sl@0
|
409 |
TEST(name == KNames[recCount]);
|
sl@0
|
410 |
++recCount;
|
sl@0
|
411 |
}
|
sl@0
|
412 |
stmt.Close();
|
sl@0
|
413 |
TEST(recCount == matchNameCnt);
|
sl@0
|
414 |
|
sl@0
|
415 |
//The next "SELECT" statement must return an ordered set containing all table records.
|
sl@0
|
416 |
RDebug::Print(_L("###Select all records, collated string comparison, level 1\r\n"));
|
sl@0
|
417 |
_LIT(KSelectSql3, "SELECT * FROM A WHERE NAME = 'dvorak' ORDER BY NAME COLLATE CompareC1 DESC");
|
sl@0
|
418 |
err = stmt.Prepare(db, KSelectSql3);
|
sl@0
|
419 |
TEST2(err, KErrNone);
|
sl@0
|
420 |
|
sl@0
|
421 |
for(TInt k=0;k<KInsertSqlStmtCnt;++k)
|
sl@0
|
422 |
{
|
sl@0
|
423 |
err = stmt.Next();
|
sl@0
|
424 |
TEST2(err, KSqlAtRow);
|
sl@0
|
425 |
TPtrC name = stmt.ColumnTextL(0);
|
sl@0
|
426 |
RDebug::Print(_L("%S %S\r\n"), &name, &sortedNames[k]);
|
sl@0
|
427 |
TEST(name == sortedNames[KInsertSqlStmtCnt - k - 1]);//descending order
|
sl@0
|
428 |
}
|
sl@0
|
429 |
stmt.Close();
|
sl@0
|
430 |
|
sl@0
|
431 |
//CompareC2 collation used in the SELECT statement
|
sl@0
|
432 |
err = stmt.Prepare(db, _L("SELECT NAME FROM A WHERE NAME = 'Dvorak' COLLATE CompareC2"));
|
sl@0
|
433 |
TEST2(err, KErrNone);
|
sl@0
|
434 |
err = stmt.Next();
|
sl@0
|
435 |
TEST2(err, KSqlAtRow);
|
sl@0
|
436 |
TPtrC name3 = stmt.ColumnTextL(0);
|
sl@0
|
437 |
TEST(name3 == name1);
|
sl@0
|
438 |
err = stmt.Next();
|
sl@0
|
439 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
440 |
stmt.Close();
|
sl@0
|
441 |
|
sl@0
|
442 |
//Cleanup
|
sl@0
|
443 |
sortedNames.Close();
|
sl@0
|
444 |
db.Close();
|
sl@0
|
445 |
RDebug::Print(_L("###Delete test database\r\n"));
|
sl@0
|
446 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
447 |
}
|
sl@0
|
448 |
|
sl@0
|
449 |
/**
|
sl@0
|
450 |
@SYMTestCaseID SYSLIB-SQL-CT-1760
|
sl@0
|
451 |
@SYMTestCaseDesc Creating a test table with a text field. Inserting some records there and
|
sl@0
|
452 |
testing how LIKE operator works. The test cases include: accented text column values,
|
sl@0
|
453 |
using '_' and '%' wild cards, using ESCAPE clause, blank pattern string, blank ESCAPE
|
sl@0
|
454 |
string, multi-character ESCAPE string.
|
sl@0
|
455 |
@SYMTestPriority High
|
sl@0
|
456 |
@SYMTestActions Testing SQL LIKE operator and ESCAPE clause.
|
sl@0
|
457 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
458 |
@SYMREQ REQ5907
|
sl@0
|
459 |
*/
|
sl@0
|
460 |
void LikeTest1()
|
sl@0
|
461 |
{
|
sl@0
|
462 |
RSqlDatabase db;
|
sl@0
|
463 |
TInt err = db.Create(KTestDbName1);
|
sl@0
|
464 |
TEST2(err, KErrNone);
|
sl@0
|
465 |
//Create a test table and insert some records
|
sl@0
|
466 |
err = db.Exec(_L("CREATE TABLE A(Id INTEGER PRIMARY KEY, Name TEXT)"));
|
sl@0
|
467 |
TEST(err >= 0);
|
sl@0
|
468 |
err = db.Exec(_L("INSERT INTO A(Id, Name) VALUES(1, 'Dvorak')"));
|
sl@0
|
469 |
TEST2(err, 1);
|
sl@0
|
470 |
err = db.Exec(_L("INSERT INTO A(Id, Name) VALUES(2, 'Dvorák')"));
|
sl@0
|
471 |
TEST2(err, 1);
|
sl@0
|
472 |
//Create a statement object and issue a SELECT SQL statement + LIKE clause
|
sl@0
|
473 |
//Test case 1 = full name search with LIKE
|
sl@0
|
474 |
RSqlStatement stmt;
|
sl@0
|
475 |
err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 'DVORAK'"));
|
sl@0
|
476 |
TEST2(err, KErrNone);
|
sl@0
|
477 |
err = stmt.Next();
|
sl@0
|
478 |
TEST2(err, KSqlAtRow);
|
sl@0
|
479 |
TInt cnt = stmt.ColumnInt(0);
|
sl@0
|
480 |
TEST2(cnt, 2);
|
sl@0
|
481 |
stmt.Close();
|
sl@0
|
482 |
//Test case 2 = wild card used sequence character in the search pattern + LIKE
|
sl@0
|
483 |
err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE '%RA%'"));
|
sl@0
|
484 |
TEST2(err, KErrNone);
|
sl@0
|
485 |
err = stmt.Next();
|
sl@0
|
486 |
TEST2(err, KSqlAtRow);
|
sl@0
|
487 |
cnt = stmt.ColumnInt(0);
|
sl@0
|
488 |
TEST2(cnt, 2);
|
sl@0
|
489 |
stmt.Close();
|
sl@0
|
490 |
//Test case 3 = wild card character used in the search pattern + LIKE
|
sl@0
|
491 |
err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 'DV___K'"));
|
sl@0
|
492 |
TEST2(err, KErrNone);
|
sl@0
|
493 |
err = stmt.Next();
|
sl@0
|
494 |
TEST2(err, KSqlAtRow);
|
sl@0
|
495 |
cnt = stmt.ColumnInt(0);
|
sl@0
|
496 |
TEST2(cnt, 2);
|
sl@0
|
497 |
stmt.Close();
|
sl@0
|
498 |
//Insert one more record
|
sl@0
|
499 |
err = db.Exec(_L("INSERT INTO A(Id, Name) VALUES(3, 't_sqltest')"));
|
sl@0
|
500 |
TEST2(err, 1);
|
sl@0
|
501 |
//Test case 4 = wild card character used in the search pattern + LIKE + ESCAPE
|
sl@0
|
502 |
err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 't/_sqlte__' ESCAPE '/'"));
|
sl@0
|
503 |
TEST2(err, KErrNone);
|
sl@0
|
504 |
err = stmt.Next();
|
sl@0
|
505 |
TEST2(err, KSqlAtRow);
|
sl@0
|
506 |
cnt = stmt.ColumnInt(0);
|
sl@0
|
507 |
TEST2(cnt, 1);
|
sl@0
|
508 |
stmt.Close();
|
sl@0
|
509 |
//Test case 5 = wild card character used in the search pattern + LIKE + ESCAPE without an escape character
|
sl@0
|
510 |
err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 't/_sqltest' ESCAPE ''"));
|
sl@0
|
511 |
TEST2(err, KErrNone);
|
sl@0
|
512 |
err = stmt.Next();
|
sl@0
|
513 |
TEST(err != KErrNone);
|
sl@0
|
514 |
TEST2(::SqlRetCodeClass(err), ESqlDbError);
|
sl@0
|
515 |
TPtrC errMsg = db.LastErrorMessage();
|
sl@0
|
516 |
RDebug::Print(_L("!! error=\"%S\"\r\n"), &errMsg);
|
sl@0
|
517 |
stmt.Close();
|
sl@0
|
518 |
//Test case 6 = wild card character used in the search pattern + LIKE + ESCAPE with more than one escape characters
|
sl@0
|
519 |
err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 't/_sqltest' ESCAPE '1234'"));
|
sl@0
|
520 |
TEST2(err, KErrNone);
|
sl@0
|
521 |
err = stmt.Next();
|
sl@0
|
522 |
TEST(err != KErrNone);
|
sl@0
|
523 |
TEST2(::SqlRetCodeClass(err), ESqlDbError);
|
sl@0
|
524 |
errMsg.Set(db.LastErrorMessage());
|
sl@0
|
525 |
RDebug::Print(_L("!! error=\"%S\"\r\n"), &errMsg);
|
sl@0
|
526 |
stmt.Close();
|
sl@0
|
527 |
//Test case 7 = blank pattern string
|
sl@0
|
528 |
err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE ''"));
|
sl@0
|
529 |
TEST2(err, KErrNone);
|
sl@0
|
530 |
err = stmt.Next();
|
sl@0
|
531 |
TEST2(err, KSqlAtRow);
|
sl@0
|
532 |
cnt = stmt.ColumnInt(0);
|
sl@0
|
533 |
TEST2(cnt, 0);
|
sl@0
|
534 |
stmt.Close();
|
sl@0
|
535 |
|
sl@0
|
536 |
//Cleanup
|
sl@0
|
537 |
db.Close();
|
sl@0
|
538 |
RDebug::Print(_L("###Delete test database\r\n"));
|
sl@0
|
539 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
540 |
}
|
sl@0
|
541 |
|
sl@0
|
542 |
/**
|
sl@0
|
543 |
@SYMTestCaseID SYSLIB-SQL-CT-1761
|
sl@0
|
544 |
@SYMTestCaseDesc Verifying that all 'LIKE + ESCAPE' test cases which work with the old DBMS component,
|
sl@0
|
545 |
pass successfully with the new SQL component. The test includes positive and negative test cases.
|
sl@0
|
546 |
Not all negative test cases from the old DBMS pass, because the DBMS supports limited implementation of
|
sl@0
|
547 |
the ESCAPE clause. Here the old negative tests were converted to a positive test cases.
|
sl@0
|
548 |
@SYMTestPriority High
|
sl@0
|
549 |
@SYMTestActions Testing SQL LIKE operator and ESCAPE clause.
|
sl@0
|
550 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
551 |
@SYMREQ REQ5907
|
sl@0
|
552 |
*/
|
sl@0
|
553 |
void LikeTest2()
|
sl@0
|
554 |
{
|
sl@0
|
555 |
RSqlDatabase db;
|
sl@0
|
556 |
TInt err = db.Create(KTestDbName1);
|
sl@0
|
557 |
TEST2(err, KErrNone);
|
sl@0
|
558 |
//Create a test table
|
sl@0
|
559 |
err = db.Exec(_L("CREATE TABLE A(Fld1 TEXT, Fld2 TEXT)"));
|
sl@0
|
560 |
TEST(err >= 0);
|
sl@0
|
561 |
//Insert some records
|
sl@0
|
562 |
err = db.Exec(_L("INSERT INTO A(Fld1, Fld2) VALUES('ACDC\\','BLAH')")); // Rec1
|
sl@0
|
563 |
TEST2(err, 1);
|
sl@0
|
564 |
err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('ABCDEFGH')")); // Rec2
|
sl@0
|
565 |
TEST2(err, 1);
|
sl@0
|
566 |
err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('A_CDEFGH')")); // Rec3
|
sl@0
|
567 |
TEST2(err, 1);
|
sl@0
|
568 |
err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('A_%_CDEFGH')")); // Rec4
|
sl@0
|
569 |
TEST2(err, 1);
|
sl@0
|
570 |
err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('A%CDEFGH')")); // Rec5
|
sl@0
|
571 |
TEST2(err, 1);
|
sl@0
|
572 |
err = db.Exec(_L("INSERT INTO A(Fld1, Fld2) VALUES('ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP','ADCB')")); //Rec6
|
sl@0
|
573 |
TEST2(err, 1);
|
sl@0
|
574 |
err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('XZD\\FZX')")); // Rec7
|
sl@0
|
575 |
TEST2(err, 1);
|
sl@0
|
576 |
//Prepare SELECT query, step and check the record set content
|
sl@0
|
577 |
TPtrC res;
|
sl@0
|
578 |
//Test 1 - only Rec1 satisfies the WHILE condition
|
sl@0
|
579 |
RSqlStatement stmt;
|
sl@0
|
580 |
err = stmt.Prepare(db, _L("SELECT Fld2 FROM A WHERE Fld1 LIKE 'ACDC\\' AND Fld2 LIKE '%BL%'"));
|
sl@0
|
581 |
TEST2(err, KErrNone);
|
sl@0
|
582 |
err = stmt.Next();
|
sl@0
|
583 |
TEST2(err, KSqlAtRow);
|
sl@0
|
584 |
err = stmt.ColumnText(0, res);
|
sl@0
|
585 |
TEST2(err, KErrNone);
|
sl@0
|
586 |
TEST(res == _L("BLAH"));
|
sl@0
|
587 |
err = stmt.Next();
|
sl@0
|
588 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
589 |
stmt.Close();
|
sl@0
|
590 |
//Test 2 - only Rec5 satisfies the WHILE condition
|
sl@0
|
591 |
err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%A\\%C%' ESCAPE '\\'"));
|
sl@0
|
592 |
TEST2(err, KErrNone);
|
sl@0
|
593 |
err = stmt.Next();
|
sl@0
|
594 |
TEST2(err, KSqlAtRow);
|
sl@0
|
595 |
err = stmt.ColumnText(0, res);
|
sl@0
|
596 |
TEST2(err, KErrNone);
|
sl@0
|
597 |
TEST(res == _L("A%CDEFGH"));
|
sl@0
|
598 |
err = stmt.Next();
|
sl@0
|
599 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
600 |
stmt.Close();
|
sl@0
|
601 |
//Test 3 - only Rec3 satisfies the WHILE condition
|
sl@0
|
602 |
err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%A\\_C%' ESCAPE '\\'"));
|
sl@0
|
603 |
TEST2(err, KErrNone);
|
sl@0
|
604 |
err = stmt.Next();
|
sl@0
|
605 |
TEST2(err, KSqlAtRow);
|
sl@0
|
606 |
err = stmt.ColumnText(0, res);
|
sl@0
|
607 |
TEST2(err, KErrNone);
|
sl@0
|
608 |
TEST(res == _L("A_CDEFGH"));
|
sl@0
|
609 |
err = stmt.Next();
|
sl@0
|
610 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
611 |
stmt.Close();
|
sl@0
|
612 |
//Test 4 - only Rec4 satisfies the WHILE condition
|
sl@0
|
613 |
err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%A\\_\\%\\_C%' ESCAPE '\\'"));
|
sl@0
|
614 |
TEST2(err, KErrNone);
|
sl@0
|
615 |
err = stmt.Next();
|
sl@0
|
616 |
TEST2(err, KSqlAtRow);
|
sl@0
|
617 |
err = stmt.ColumnText(0, res);
|
sl@0
|
618 |
TEST2(err, KErrNone);
|
sl@0
|
619 |
TEST(res == _L("A_%_CDEFGH"));
|
sl@0
|
620 |
err = stmt.Next();
|
sl@0
|
621 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
622 |
stmt.Close();
|
sl@0
|
623 |
//Test 5 - only Rec6 satisfies the WHILE condition
|
sl@0
|
624 |
err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE '%1234%'"));
|
sl@0
|
625 |
TEST2(err, KErrNone);
|
sl@0
|
626 |
err = stmt.Next();
|
sl@0
|
627 |
TEST2(err, KSqlAtRow);
|
sl@0
|
628 |
err = stmt.ColumnText(0, res);
|
sl@0
|
629 |
TEST2(err, KErrNone);
|
sl@0
|
630 |
TEST(res == _L("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP"));
|
sl@0
|
631 |
err = stmt.ColumnText(1, res);
|
sl@0
|
632 |
TEST2(err, KErrNone);
|
sl@0
|
633 |
TEST(res == _L("ADCB"));
|
sl@0
|
634 |
err = stmt.Next();
|
sl@0
|
635 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
636 |
stmt.Close();
|
sl@0
|
637 |
//Test 6 - only Rec1 satisfies the WHILE condition
|
sl@0
|
638 |
err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE '%AC%' AND Fld2 LIKE '_LA_'"));
|
sl@0
|
639 |
TEST2(err, KErrNone);
|
sl@0
|
640 |
err = stmt.Next();
|
sl@0
|
641 |
TEST2(err, KSqlAtRow);
|
sl@0
|
642 |
err = stmt.ColumnText(0, res);
|
sl@0
|
643 |
TEST2(err, KErrNone);
|
sl@0
|
644 |
TEST(res == _L("ACDC\\"));
|
sl@0
|
645 |
err = stmt.ColumnText(1, res);
|
sl@0
|
646 |
TEST2(err, KErrNone);
|
sl@0
|
647 |
TEST(res == _L("BLAH"));
|
sl@0
|
648 |
err = stmt.Next();
|
sl@0
|
649 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
650 |
stmt.Close();
|
sl@0
|
651 |
//Test 7 - only Rec1 satisfies the WHILE condition
|
sl@0
|
652 |
err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE 'NOTINTABLE' OR Fld2 LIKE '_LA_'"));
|
sl@0
|
653 |
TEST2(err, KErrNone);
|
sl@0
|
654 |
err = stmt.Next();
|
sl@0
|
655 |
TEST2(err, KSqlAtRow);
|
sl@0
|
656 |
err = stmt.ColumnText(0, res);
|
sl@0
|
657 |
TEST2(err, KErrNone);
|
sl@0
|
658 |
TEST(res == _L("ACDC\\"));
|
sl@0
|
659 |
err = stmt.ColumnText(1, res);
|
sl@0
|
660 |
TEST2(err, KErrNone);
|
sl@0
|
661 |
TEST(res == _L("BLAH"));
|
sl@0
|
662 |
err = stmt.Next();
|
sl@0
|
663 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
664 |
stmt.Close();
|
sl@0
|
665 |
//Test 8 - only Rec6 satisfies the WHILE condition
|
sl@0
|
666 |
err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE '%ADC%' AND Fld2 LIKE 'ADC_'"));
|
sl@0
|
667 |
TEST2(err, KErrNone);
|
sl@0
|
668 |
err = stmt.Next();
|
sl@0
|
669 |
TEST2(err, KSqlAtRow);
|
sl@0
|
670 |
err = stmt.ColumnText(0, res);
|
sl@0
|
671 |
TEST2(err, KErrNone);
|
sl@0
|
672 |
TEST(res == _L("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP"));
|
sl@0
|
673 |
err = stmt.ColumnText(1, res);
|
sl@0
|
674 |
TEST2(err, KErrNone);
|
sl@0
|
675 |
TEST(res == _L("ADCB"));
|
sl@0
|
676 |
err = stmt.Next();
|
sl@0
|
677 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
678 |
stmt.Close();
|
sl@0
|
679 |
//Test 9 - only Rec5 satisfies the WHILE condition
|
sl@0
|
680 |
err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%\\%C%' ESCAPE '\\'"));
|
sl@0
|
681 |
TEST2(err, KErrNone);
|
sl@0
|
682 |
err = stmt.Next();
|
sl@0
|
683 |
TEST2(err, KSqlAtRow);
|
sl@0
|
684 |
err = stmt.ColumnText(0, res);
|
sl@0
|
685 |
TEST2(err, KErrNone);
|
sl@0
|
686 |
TEST(res == _L("A%CDEFGH"));
|
sl@0
|
687 |
err = stmt.Next();
|
sl@0
|
688 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
689 |
stmt.Close();
|
sl@0
|
690 |
//Test 10 - only Rec7 satisfies the WHILE condition
|
sl@0
|
691 |
err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%D\\\\%' ESCAPE '\\'"));
|
sl@0
|
692 |
TEST2(err, KErrNone);
|
sl@0
|
693 |
err = stmt.Next();
|
sl@0
|
694 |
TEST2(err, KSqlAtRow);
|
sl@0
|
695 |
err = stmt.ColumnText(0, res);
|
sl@0
|
696 |
TEST2(err, KErrNone);
|
sl@0
|
697 |
TEST(res == _L("XZD\\FZX"));
|
sl@0
|
698 |
err = stmt.Next();
|
sl@0
|
699 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
700 |
stmt.Close();
|
sl@0
|
701 |
//Test 11 - only Rec4 satisfies the WHILE condition
|
sl@0
|
702 |
err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '%A\\__\\_C%' ESCAPE '\\'"));
|
sl@0
|
703 |
TEST2(err, KErrNone);
|
sl@0
|
704 |
err = stmt.Next();
|
sl@0
|
705 |
TEST2(err, KSqlAtRow);
|
sl@0
|
706 |
err = stmt.ColumnText(0, res);
|
sl@0
|
707 |
TEST2(err, KErrNone);
|
sl@0
|
708 |
TEST(res == _L("A_%_CDEFGH"));
|
sl@0
|
709 |
err = stmt.Next();
|
sl@0
|
710 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
711 |
stmt.Close();
|
sl@0
|
712 |
//Test 12 - only Rec5 satisfies the WHILE condition
|
sl@0
|
713 |
err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '%A%\\%C%' ESCAPE '\\'"));
|
sl@0
|
714 |
TEST2(err, KErrNone);
|
sl@0
|
715 |
err = stmt.Next();
|
sl@0
|
716 |
TEST2(err, KSqlAtRow);
|
sl@0
|
717 |
err = stmt.ColumnText(0, res);
|
sl@0
|
718 |
TEST2(err, KErrNone);
|
sl@0
|
719 |
TEST(res == _L("A%CDEFGH"));
|
sl@0
|
720 |
err = stmt.Next();
|
sl@0
|
721 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
722 |
stmt.Close();
|
sl@0
|
723 |
//Test 13 - only Rec2 satisfies the WHILE condition
|
sl@0
|
724 |
err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'ABC%' ESCAPE '\\'"));
|
sl@0
|
725 |
TEST2(err, KErrNone);
|
sl@0
|
726 |
err = stmt.Next();
|
sl@0
|
727 |
TEST2(err, KSqlAtRow);
|
sl@0
|
728 |
err = stmt.ColumnText(0, res);
|
sl@0
|
729 |
TEST2(err, KErrNone);
|
sl@0
|
730 |
TEST(res == _L("ABCDEFGH"));
|
sl@0
|
731 |
err = stmt.Next();
|
sl@0
|
732 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
733 |
stmt.Close();
|
sl@0
|
734 |
//Test 14 - there is no record satisfying the WHILE condition
|
sl@0
|
735 |
err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'A_C' ESCAPE '\\'"));
|
sl@0
|
736 |
TEST2(err, KErrNone);
|
sl@0
|
737 |
err = stmt.Next();
|
sl@0
|
738 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
739 |
stmt.Close();
|
sl@0
|
740 |
//Test 15 - there is no record satisfying the WHILE condition
|
sl@0
|
741 |
err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'A%C' ESCAPE '\\'"));
|
sl@0
|
742 |
TEST2(err, KErrNone);
|
sl@0
|
743 |
err = stmt.Next();
|
sl@0
|
744 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
745 |
stmt.Close();
|
sl@0
|
746 |
//Test 16 - there is no record satisfying the WHILE condition
|
sl@0
|
747 |
err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '_A\\_C' ESCAPE '\\'"));
|
sl@0
|
748 |
TEST2(err, KErrNone);
|
sl@0
|
749 |
err = stmt.Next();
|
sl@0
|
750 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
751 |
stmt.Close();
|
sl@0
|
752 |
//Test 17 - there is no record satisfying the WHILE condition
|
sl@0
|
753 |
err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '_A\\_C_' ESCAPE '\\'"));
|
sl@0
|
754 |
TEST2(err, KErrNone);
|
sl@0
|
755 |
err = stmt.Next();
|
sl@0
|
756 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
757 |
stmt.Close();
|
sl@0
|
758 |
//Test 18 - there is no record satisfying the WHILE condition
|
sl@0
|
759 |
err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'ABC' ESCAPE '\\'"));
|
sl@0
|
760 |
TEST2(err, KErrNone);
|
sl@0
|
761 |
err = stmt.Next();
|
sl@0
|
762 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
763 |
stmt.Close();
|
sl@0
|
764 |
//Test 19 - there is no record satisfying the WHILE condition
|
sl@0
|
765 |
err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '%ABC' ESCAPE '\\'"));
|
sl@0
|
766 |
TEST2(err, KErrNone);
|
sl@0
|
767 |
err = stmt.Next();
|
sl@0
|
768 |
TEST2(err, KSqlAtEnd);
|
sl@0
|
769 |
stmt.Close();
|
sl@0
|
770 |
//Cleanup
|
sl@0
|
771 |
db.Close();
|
sl@0
|
772 |
RDebug::Print(_L("###Delete test database\r\n"));
|
sl@0
|
773 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
774 |
}
|
sl@0
|
775 |
|
sl@0
|
776 |
void DoTestsL()
|
sl@0
|
777 |
{
|
sl@0
|
778 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1609 Folding & Collation test 1 "));
|
sl@0
|
779 |
CollationTest1L();
|
sl@0
|
780 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1610 Folding & Collation test 2 "));
|
sl@0
|
781 |
CollationTest2L();
|
sl@0
|
782 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627 Collation test 3 "));
|
sl@0
|
783 |
CollationTest3L();
|
sl@0
|
784 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1760 LIKE & ESCAPE test 1 "));
|
sl@0
|
785 |
LikeTest1();
|
sl@0
|
786 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1761 LIKE & ESCAPE test 2 "));
|
sl@0
|
787 |
LikeTest2();
|
sl@0
|
788 |
}
|
sl@0
|
789 |
|
sl@0
|
790 |
TInt E32Main()
|
sl@0
|
791 |
{
|
sl@0
|
792 |
TheTest.Title();
|
sl@0
|
793 |
|
sl@0
|
794 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
795 |
|
sl@0
|
796 |
__UHEAP_MARK;
|
sl@0
|
797 |
|
sl@0
|
798 |
CreateTestDir();
|
sl@0
|
799 |
DeleteTestFiles();
|
sl@0
|
800 |
TRAPD(err, DoTestsL());
|
sl@0
|
801 |
DeleteTestFiles();
|
sl@0
|
802 |
TEST2(err, KErrNone);
|
sl@0
|
803 |
|
sl@0
|
804 |
__UHEAP_MARKEND;
|
sl@0
|
805 |
|
sl@0
|
806 |
TheTest.End();
|
sl@0
|
807 |
TheTest.Close();
|
sl@0
|
808 |
|
sl@0
|
809 |
delete tc;
|
sl@0
|
810 |
|
sl@0
|
811 |
User::Heap().Check();
|
sl@0
|
812 |
return KErrNone;
|
sl@0
|
813 |
}
|