Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 ///////////////////////////////////////////////////////////////////////////////////////
22 RTest TheTest(_L("t_sqlcollate test"));
24 _LIT(KTestDir, "c:\\test\\");
25 _LIT(KTestDbName1, "c:\\test\\t_sqlcollate.db");
27 ///////////////////////////////////////////////////////////////////////////////////////
29 void DeleteTestFiles()
31 RSqlDatabase::Delete(KTestDbName1);
34 ///////////////////////////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////////////////
36 //Test macros and functions
37 void Check(TInt aValue, TInt aLine)
42 TheTest(EFalse, aLine);
45 void Check(TInt aValue, TInt aExpected, TInt aLine)
47 if(aValue != aExpected)
50 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
51 TheTest(EFalse, aLine);
54 #define TEST(arg) ::Check((arg), __LINE__)
55 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
57 ///////////////////////////////////////////////////////////////////////////////////////
62 TInt err = fs.Connect();
65 err = fs.MkDir(KTestDir);
66 TEST(err == KErrNone || err == KErrAlreadyExists);
71 ///////////////////////////////////////////////////////////////////////////////////////
73 //Compare aLeft and aRight strings using collated comparison, level 3, default collation method.
74 //This function is used when sorting the test names array in CollationTest1L().
75 TInt StrSortC3(const TPtrC& aLeft, const TPtrC& aRight)
77 return aLeft.CompareC(aRight, 3, NULL);
80 //Compare aLeft and aRight strings using collated comparison, level 1, default collation method.
81 //This function is used when sorting the test names array in CollationTest3L().
82 TInt StrSortC1(const TPtrC& aLeft, const TPtrC& aRight)
84 return aLeft.CompareC(aRight, 1, NULL);
87 ///////////////////////////////////////////////////////////////////////////////////////
90 @SYMTestCaseID SYSLIB-SQL-CT-1609
91 @SYMTestCaseDesc Create a table with a text column with default collation "CompareF"
92 and insert some records there.
93 Test how the searching operations work executing some SELECT SQL statements.
95 @SYMTestActions Testing database search operations using "CompareF" and "CompareC3" collations.
96 @SYMTestExpectedResults Test must not fail
99 void CollationTest1L()
102 TInt err = db.Create(KTestDbName1);
103 TEST2(err, KErrNone);
105 //Create test database
106 RDebug::Print(_L("###Create test database\r\n"));
107 _LIT(KCreateSql, "CREATE TABLE A(Name VARCHAR(100) COLLATE CompareF); CREATE INDEX AIdx ON A(Name COLLATE CompareF);");
108 err = db.Exec(KCreateSql);
111 //Insert some records. The column "Name" of each record contains the same name but the name characters are
112 //variation of upper/lower case letters.
113 RDebug::Print(_L("###Insert some records\r\n"));
114 _LIT(KInsertSql, "INSERT INTO A(Name) VALUES(");
115 //Collation sort order: KNames[1] KNames[3] KNames[0] KNames[2]
116 //Long "aaaa..." added to the end of each column value because SQLITE may use non-aligned strings
117 //only when the string length is in [32..<cache_page_size>] interval.
119 _L("aLex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
120 _L("ALeX-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
121 _L("aleX-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
122 _L("Alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")};
123 const TInt KInsertSqlStmtCnt = sizeof(KNames)/sizeof(KNames[0]);
124 RArray<TPtrC> sortedNames;
125 TLinearOrder<TPtrC> order(&StrSortC3);
127 for(TInt i=0;i<KInsertSqlStmtCnt;++i)
129 err = sortedNames.InsertInOrder(KNames[i], order);
130 TEST2(err, KErrNone);
132 TBuf<128> sql(KInsertSql);
134 sql.Append(KNames[i]);
135 sql.Append(_L("')"));
140 //The next "SELECT" statement must return a set containing all table records
141 RDebug::Print(_L("###Select all records\r\n"));
142 _LIT(KSelectSql1, "SELECT * FROM A WHERE NAME = 'alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'");
144 err = stmt.Prepare(db, KSelectSql1);
145 TEST2(err, KErrNone);
147 while(stmt.Next() == KSqlAtRow)
150 TPtrC name = stmt.ColumnTextL(0);
151 RDebug::Print(_L("%S\r\n"), &name);
154 TEST(recCount == KInsertSqlStmtCnt);
156 //The next "SELECT" statement must return a set containing all table records
157 // this tests a LIKE clause with a bound parameter (with wildcards)
158 RDebug::Print(_L("###Select all records (LIKE with wildcard)\r\n"));
159 _LIT(KSelectSql1a, "SELECT * FROM A WHERE NAME LIKE :Val");
160 _LIT(KSearchString,"alex-aaaa%");
161 err = stmt.Prepare(db, KSelectSql1a);
162 TEST2(err, KErrNone);
163 TInt idx=stmt.ParameterIndex(_L(":Val"));
164 err=stmt.BindText(idx,KSearchString);
165 TEST2(err, KErrNone);
167 while(stmt.Next() == KSqlAtRow)
170 TPtrC name = stmt.ColumnTextL(0);
171 RDebug::Print(_L("%S\r\n"), &name);
174 TEST(recCount == KInsertSqlStmtCnt);
176 //The next "SELECT" statement must return a set containing all table records
177 // this tests a LIKE clause with a bound parameter (with no wildcards)
178 RDebug::Print(_L("###Select all records (LIKE with no wildcard)\r\n"));
179 _LIT(KSelectSql1b, "SELECT * FROM A WHERE NAME LIKE :Val");
181 "alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
182 err = stmt.Prepare(db, KSelectSql1b);
183 idx=stmt.ParameterIndex(_L(":Val"));
184 TEST2(err, KErrNone);
185 err=stmt.BindText(idx,KSearchStringA);
187 while(stmt.Next() == KSqlAtRow)
190 TPtrC name = stmt.ColumnTextL(0);
191 RDebug::Print(_L("%S\r\n"), &name);
194 TEST(recCount == KInsertSqlStmtCnt);
196 //The next "SELECT" statement must return a row
197 // this tests a LIKE clause with a bound parameter and funny characters
198 RDebug::Print(_L("###Select one records (LIKE with bound param with URL chars)\r\n"));
199 err=db.Exec(_L("INSERT INTO A(Name) VALUES('http://a.b.c#d')"));
201 _LIT(KSelectSql1c, "SELECT * FROM A WHERE NAME LIKE :Val");
202 _LIT(KSearchStringB,"http%");
203 err = stmt.Prepare(db, KSelectSql1c);
204 idx=stmt.ParameterIndex(_L(":Val"));
205 TEST2(err, KErrNone);
206 err=stmt.BindText(idx,KSearchStringB);
208 while(stmt.Next() == KSqlAtRow)
211 TPtrC name = stmt.ColumnTextL(0);
212 RDebug::Print(_L("%S\r\n"), &name);
218 //The next "SELECT" statement must return a set containing all table records, folded comparison used for sorting
219 RDebug::Print(_L("###Select all records, folded string comparison\r\n"));
220 _LIT(KSelectSql2, "SELECT * FROM A WHERE NAME = 'alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ORDER BY NAME COLLATE CompareF");
221 err = stmt.Prepare(db, KSelectSql2);
222 TEST2(err, KErrNone);
225 for(TInt j=0;j<KInsertSqlStmtCnt;++j)
228 TEST2(err, KSqlAtRow);
230 TPtrC name = stmt.ColumnTextL(0);
231 RDebug::Print(_L("%S\r\n"), &name);
232 TEST(name == KNames[j]);
235 TEST(recCount == KInsertSqlStmtCnt);
237 //The next "SELECT" statement must return a set containing all table records, collated comparison used for sorting
238 RDebug::Print(_L("###Select all records, collated string comparison\r\n"));
239 _LIT(KSelectSql3, "SELECT * FROM A ORDER BY NAME COLLATE CompareC3");
240 err = stmt.Prepare(db, KSelectSql3);
241 TEST2(err, KErrNone);
243 for(TInt k=0;k<KInsertSqlStmtCnt;++k)
246 TEST2(err, KSqlAtRow);
247 TPtrC name = stmt.ColumnTextL(0);
248 RDebug::Print(_L("%S\r\n"), &name);
249 TEST(name == sortedNames[k]);
258 //To debug database reindexing
259 err = db.Open(KTestDbName1);
260 TEST2(err, KErrNone);
263 RDebug::Print(_L("###Delete test database\r\n"));
264 (void)RSqlDatabase::Delete(KTestDbName1);
268 @SYMTestCaseID SYSLIB-SQL-CT-1610
269 @SYMTestCaseDesc Create a table with a text column with default collation "CompareC3"
270 and insert some records there.
271 Test how the searching operations work executing some SELECT SQL statements.
272 @SYMTestPriority High
273 @SYMTestActions Testing database sorting operations using "CompareC3" collation.
274 @SYMTestExpectedResults Test must not fail
277 void CollationTest2L()
280 TInt err = db.Create(KTestDbName1);
281 TEST2(err, KErrNone);
283 //Create test database
284 RDebug::Print(_L("###Create test database\r\n"));
285 _LIT(KCreateSql, "CREATE TABLE A(Name VARCHAR(100) COLLATE CompareC3)");
286 err = db.Exec(KCreateSql);
289 //Insert some records.
290 RDebug::Print(_L("###Insert some records\r\n"));
291 _LIT(KInsertSql, "INSERT INTO A(Name) VALUES(");
297 const TInt KInsertSqlStmtCnt = sizeof(KNames)/sizeof(KNames[0]);
299 for(TInt i=0;i<KInsertSqlStmtCnt;++i)
301 TBuf<128> sql(KInsertSql);
303 sql.Append(KNames[i]);
304 sql.Append(_L("')"));
311 //The next "SELECT" statement must return a set containing all table
312 //records which Name column value is bigger than "aaAA"
313 RDebug::Print(_L("###Select all records, which Name column value is bigger than 'aaAA'\r\n"));
314 _LIT(KSelectSql2, "SELECT * FROM A WHERE NAME > 'aaAA'");
315 err = stmt.Prepare(db, KSelectSql2);
316 TEST2(err, KErrNone);
318 while((err = stmt.Next()) == KSqlAtRow)
320 TPtrC name = stmt.ColumnTextL(0);
321 RDebug::Print(_L("%S\r\n"), &name);
322 TInt res = name.CompareC(KNames[2], 3, NULL);
326 TEST2(err, KSqlAtEnd);
330 RDebug::Print(_L("###Delete test database\r\n"));
331 (void)RSqlDatabase::Delete(KTestDbName1);
335 @SYMTestCaseID SYSLIB-SQL-CT-1627
336 @SYMTestCaseDesc Create a table with a text column "NAME" with default collation "CompareC0"
337 and insert some records there. All inserted names are equal if compared at
338 collation level 0, but some of them contain accented letters.
339 Test how the searching operations work executing some SELECT SQL statements.
340 Test how the sorting operations work executing some SELECT SQL statements.
341 @SYMTestPriority High
342 @SYMTestActions Testing database sorting operations using "CompareC0", "CompareC1", and "CompareC2" collations.
343 @SYMTestExpectedResults Test must not fail
346 void CollationTest3L()
349 TInt err = db.Create(KTestDbName1);
350 TEST2(err, KErrNone);
352 //Create test database
353 RDebug::Print(_L("###Create test database\r\n"));
354 _LIT(KCreateSql, "CREATE TABLE A(Name VARCHAR(100) COLLATE CompareC0)");
355 err = db.Exec(KCreateSql);
358 //Insert some records. Some of the inserted names have accented letters.
359 //But all names are equal if compared at collation level 0.
360 RDebug::Print(_L("###Insert some records\r\n"));
361 _LIT(KInsertSql, "INSERT INTO A(Name) VALUES(");
362 TBuf<10> name1(_L("Dvorak"));
365 name2[0] = TChar('D');
366 name2[1] = TChar('v');
367 name2[2] = TChar('o');
368 name2[3] = 0x0158;//LATIN SMALL LETTER R HACEK
369 name2[4] = 0x00C1;//LATIN SMALL LETTER A ACUTE
370 name2[5] = TChar('k');
371 const TPtrC KNames[] = {name1, name2};
372 const TInt KInsertSqlStmtCnt = sizeof(KNames)/sizeof(KNames[0]);
373 RArray<TPtrC> sortedNames;
374 TLinearOrder<TPtrC> order(&StrSortC1);
376 //Insert the records. Also, check how many names are equal to 'dvorak' using collation level 0.
377 _LIT(KTestName, "dvorak");
378 TInt matchNameCnt = 0;
379 for(TInt i=0;i<KInsertSqlStmtCnt;++i)
381 if(KNames[i].CompareC(KTestName, 0, NULL) == 0)
386 err = sortedNames.InsertInOrder(KNames[i], order);
387 TEST2(err, KErrNone);
389 TBuf<128> sql(KInsertSql);
391 sql.Append(KNames[i]);
392 sql.Append(_L("')"));
397 //The next "SELECT" statement must return a set, which record count must be matchNameCnt.
398 RDebug::Print(_L("###Select all records, collated string comparison, level 0\r\n"));
399 _LIT(KSelectSql2, "SELECT * FROM A WHERE NAME = 'dvorak'");
401 err = stmt.Prepare(db, KSelectSql2);
402 TEST2(err, KErrNone);
405 while((err = stmt.Next()) == KSqlAtRow)
407 TPtrC name = stmt.ColumnTextL(0);
408 RDebug::Print(_L("%S\r\n"), &name);
409 TEST(name == KNames[recCount]);
413 TEST(recCount == matchNameCnt);
415 //The next "SELECT" statement must return an ordered set containing all table records.
416 RDebug::Print(_L("###Select all records, collated string comparison, level 1\r\n"));
417 _LIT(KSelectSql3, "SELECT * FROM A WHERE NAME = 'dvorak' ORDER BY NAME COLLATE CompareC1 DESC");
418 err = stmt.Prepare(db, KSelectSql3);
419 TEST2(err, KErrNone);
421 for(TInt k=0;k<KInsertSqlStmtCnt;++k)
424 TEST2(err, KSqlAtRow);
425 TPtrC name = stmt.ColumnTextL(0);
426 RDebug::Print(_L("%S %S\r\n"), &name, &sortedNames[k]);
427 TEST(name == sortedNames[KInsertSqlStmtCnt - k - 1]);//descending order
431 //CompareC2 collation used in the SELECT statement
432 err = stmt.Prepare(db, _L("SELECT NAME FROM A WHERE NAME = 'Dvorak' COLLATE CompareC2"));
433 TEST2(err, KErrNone);
435 TEST2(err, KSqlAtRow);
436 TPtrC name3 = stmt.ColumnTextL(0);
437 TEST(name3 == name1);
439 TEST2(err, KSqlAtEnd);
445 RDebug::Print(_L("###Delete test database\r\n"));
446 (void)RSqlDatabase::Delete(KTestDbName1);
450 @SYMTestCaseID SYSLIB-SQL-CT-1760
451 @SYMTestCaseDesc Creating a test table with a text field. Inserting some records there and
452 testing how LIKE operator works. The test cases include: accented text column values,
453 using '_' and '%' wild cards, using ESCAPE clause, blank pattern string, blank ESCAPE
454 string, multi-character ESCAPE string.
455 @SYMTestPriority High
456 @SYMTestActions Testing SQL LIKE operator and ESCAPE clause.
457 @SYMTestExpectedResults Test must not fail
463 TInt err = db.Create(KTestDbName1);
464 TEST2(err, KErrNone);
465 //Create a test table and insert some records
466 err = db.Exec(_L("CREATE TABLE A(Id INTEGER PRIMARY KEY, Name TEXT)"));
468 err = db.Exec(_L("INSERT INTO A(Id, Name) VALUES(1, 'Dvorak')"));
470 err = db.Exec(_L("INSERT INTO A(Id, Name) VALUES(2, 'Dvorák')"));
472 //Create a statement object and issue a SELECT SQL statement + LIKE clause
473 //Test case 1 = full name search with LIKE
475 err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 'DVORAK'"));
476 TEST2(err, KErrNone);
478 TEST2(err, KSqlAtRow);
479 TInt cnt = stmt.ColumnInt(0);
482 //Test case 2 = wild card used sequence character in the search pattern + LIKE
483 err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE '%RA%'"));
484 TEST2(err, KErrNone);
486 TEST2(err, KSqlAtRow);
487 cnt = stmt.ColumnInt(0);
490 //Test case 3 = wild card character used in the search pattern + LIKE
491 err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 'DV___K'"));
492 TEST2(err, KErrNone);
494 TEST2(err, KSqlAtRow);
495 cnt = stmt.ColumnInt(0);
498 //Insert one more record
499 err = db.Exec(_L("INSERT INTO A(Id, Name) VALUES(3, 't_sqltest')"));
501 //Test case 4 = wild card character used in the search pattern + LIKE + ESCAPE
502 err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 't/_sqlte__' ESCAPE '/'"));
503 TEST2(err, KErrNone);
505 TEST2(err, KSqlAtRow);
506 cnt = stmt.ColumnInt(0);
509 //Test case 5 = wild card character used in the search pattern + LIKE + ESCAPE without an escape character
510 err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 't/_sqltest' ESCAPE ''"));
511 TEST2(err, KErrNone);
513 TEST(err != KErrNone);
514 TEST2(::SqlRetCodeClass(err), ESqlDbError);
515 TPtrC errMsg = db.LastErrorMessage();
516 RDebug::Print(_L("!! error=\"%S\"\r\n"), &errMsg);
518 //Test case 6 = wild card character used in the search pattern + LIKE + ESCAPE with more than one escape characters
519 err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 't/_sqltest' ESCAPE '1234'"));
520 TEST2(err, KErrNone);
522 TEST(err != KErrNone);
523 TEST2(::SqlRetCodeClass(err), ESqlDbError);
524 errMsg.Set(db.LastErrorMessage());
525 RDebug::Print(_L("!! error=\"%S\"\r\n"), &errMsg);
527 //Test case 7 = blank pattern string
528 err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE ''"));
529 TEST2(err, KErrNone);
531 TEST2(err, KSqlAtRow);
532 cnt = stmt.ColumnInt(0);
538 RDebug::Print(_L("###Delete test database\r\n"));
539 (void)RSqlDatabase::Delete(KTestDbName1);
543 @SYMTestCaseID SYSLIB-SQL-CT-1761
544 @SYMTestCaseDesc Verifying that all 'LIKE + ESCAPE' test cases which work with the old DBMS component,
545 pass successfully with the new SQL component. The test includes positive and negative test cases.
546 Not all negative test cases from the old DBMS pass, because the DBMS supports limited implementation of
547 the ESCAPE clause. Here the old negative tests were converted to a positive test cases.
548 @SYMTestPriority High
549 @SYMTestActions Testing SQL LIKE operator and ESCAPE clause.
550 @SYMTestExpectedResults Test must not fail
556 TInt err = db.Create(KTestDbName1);
557 TEST2(err, KErrNone);
558 //Create a test table
559 err = db.Exec(_L("CREATE TABLE A(Fld1 TEXT, Fld2 TEXT)"));
561 //Insert some records
562 err = db.Exec(_L("INSERT INTO A(Fld1, Fld2) VALUES('ACDC\\','BLAH')")); // Rec1
564 err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('ABCDEFGH')")); // Rec2
566 err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('A_CDEFGH')")); // Rec3
568 err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('A_%_CDEFGH')")); // Rec4
570 err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('A%CDEFGH')")); // Rec5
572 err = db.Exec(_L("INSERT INTO A(Fld1, Fld2) VALUES('ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP','ADCB')")); //Rec6
574 err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('XZD\\FZX')")); // Rec7
576 //Prepare SELECT query, step and check the record set content
578 //Test 1 - only Rec1 satisfies the WHILE condition
580 err = stmt.Prepare(db, _L("SELECT Fld2 FROM A WHERE Fld1 LIKE 'ACDC\\' AND Fld2 LIKE '%BL%'"));
581 TEST2(err, KErrNone);
583 TEST2(err, KSqlAtRow);
584 err = stmt.ColumnText(0, res);
585 TEST2(err, KErrNone);
586 TEST(res == _L("BLAH"));
588 TEST2(err, KSqlAtEnd);
590 //Test 2 - only Rec5 satisfies the WHILE condition
591 err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%A\\%C%' ESCAPE '\\'"));
592 TEST2(err, KErrNone);
594 TEST2(err, KSqlAtRow);
595 err = stmt.ColumnText(0, res);
596 TEST2(err, KErrNone);
597 TEST(res == _L("A%CDEFGH"));
599 TEST2(err, KSqlAtEnd);
601 //Test 3 - only Rec3 satisfies the WHILE condition
602 err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%A\\_C%' ESCAPE '\\'"));
603 TEST2(err, KErrNone);
605 TEST2(err, KSqlAtRow);
606 err = stmt.ColumnText(0, res);
607 TEST2(err, KErrNone);
608 TEST(res == _L("A_CDEFGH"));
610 TEST2(err, KSqlAtEnd);
612 //Test 4 - only Rec4 satisfies the WHILE condition
613 err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%A\\_\\%\\_C%' ESCAPE '\\'"));
614 TEST2(err, KErrNone);
616 TEST2(err, KSqlAtRow);
617 err = stmt.ColumnText(0, res);
618 TEST2(err, KErrNone);
619 TEST(res == _L("A_%_CDEFGH"));
621 TEST2(err, KSqlAtEnd);
623 //Test 5 - only Rec6 satisfies the WHILE condition
624 err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE '%1234%'"));
625 TEST2(err, KErrNone);
627 TEST2(err, KSqlAtRow);
628 err = stmt.ColumnText(0, res);
629 TEST2(err, KErrNone);
630 TEST(res == _L("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP"));
631 err = stmt.ColumnText(1, res);
632 TEST2(err, KErrNone);
633 TEST(res == _L("ADCB"));
635 TEST2(err, KSqlAtEnd);
637 //Test 6 - only Rec1 satisfies the WHILE condition
638 err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE '%AC%' AND Fld2 LIKE '_LA_'"));
639 TEST2(err, KErrNone);
641 TEST2(err, KSqlAtRow);
642 err = stmt.ColumnText(0, res);
643 TEST2(err, KErrNone);
644 TEST(res == _L("ACDC\\"));
645 err = stmt.ColumnText(1, res);
646 TEST2(err, KErrNone);
647 TEST(res == _L("BLAH"));
649 TEST2(err, KSqlAtEnd);
651 //Test 7 - only Rec1 satisfies the WHILE condition
652 err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE 'NOTINTABLE' OR Fld2 LIKE '_LA_'"));
653 TEST2(err, KErrNone);
655 TEST2(err, KSqlAtRow);
656 err = stmt.ColumnText(0, res);
657 TEST2(err, KErrNone);
658 TEST(res == _L("ACDC\\"));
659 err = stmt.ColumnText(1, res);
660 TEST2(err, KErrNone);
661 TEST(res == _L("BLAH"));
663 TEST2(err, KSqlAtEnd);
665 //Test 8 - only Rec6 satisfies the WHILE condition
666 err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE '%ADC%' AND Fld2 LIKE 'ADC_'"));
667 TEST2(err, KErrNone);
669 TEST2(err, KSqlAtRow);
670 err = stmt.ColumnText(0, res);
671 TEST2(err, KErrNone);
672 TEST(res == _L("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP"));
673 err = stmt.ColumnText(1, res);
674 TEST2(err, KErrNone);
675 TEST(res == _L("ADCB"));
677 TEST2(err, KSqlAtEnd);
679 //Test 9 - only Rec5 satisfies the WHILE condition
680 err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%\\%C%' ESCAPE '\\'"));
681 TEST2(err, KErrNone);
683 TEST2(err, KSqlAtRow);
684 err = stmt.ColumnText(0, res);
685 TEST2(err, KErrNone);
686 TEST(res == _L("A%CDEFGH"));
688 TEST2(err, KSqlAtEnd);
690 //Test 10 - only Rec7 satisfies the WHILE condition
691 err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%D\\\\%' ESCAPE '\\'"));
692 TEST2(err, KErrNone);
694 TEST2(err, KSqlAtRow);
695 err = stmt.ColumnText(0, res);
696 TEST2(err, KErrNone);
697 TEST(res == _L("XZD\\FZX"));
699 TEST2(err, KSqlAtEnd);
701 //Test 11 - only Rec4 satisfies the WHILE condition
702 err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '%A\\__\\_C%' ESCAPE '\\'"));
703 TEST2(err, KErrNone);
705 TEST2(err, KSqlAtRow);
706 err = stmt.ColumnText(0, res);
707 TEST2(err, KErrNone);
708 TEST(res == _L("A_%_CDEFGH"));
710 TEST2(err, KSqlAtEnd);
712 //Test 12 - only Rec5 satisfies the WHILE condition
713 err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '%A%\\%C%' ESCAPE '\\'"));
714 TEST2(err, KErrNone);
716 TEST2(err, KSqlAtRow);
717 err = stmt.ColumnText(0, res);
718 TEST2(err, KErrNone);
719 TEST(res == _L("A%CDEFGH"));
721 TEST2(err, KSqlAtEnd);
723 //Test 13 - only Rec2 satisfies the WHILE condition
724 err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'ABC%' ESCAPE '\\'"));
725 TEST2(err, KErrNone);
727 TEST2(err, KSqlAtRow);
728 err = stmt.ColumnText(0, res);
729 TEST2(err, KErrNone);
730 TEST(res == _L("ABCDEFGH"));
732 TEST2(err, KSqlAtEnd);
734 //Test 14 - there is no record satisfying the WHILE condition
735 err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'A_C' ESCAPE '\\'"));
736 TEST2(err, KErrNone);
738 TEST2(err, KSqlAtEnd);
740 //Test 15 - there is no record satisfying the WHILE condition
741 err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'A%C' ESCAPE '\\'"));
742 TEST2(err, KErrNone);
744 TEST2(err, KSqlAtEnd);
746 //Test 16 - there is no record satisfying the WHILE condition
747 err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '_A\\_C' ESCAPE '\\'"));
748 TEST2(err, KErrNone);
750 TEST2(err, KSqlAtEnd);
752 //Test 17 - there is no record satisfying the WHILE condition
753 err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '_A\\_C_' ESCAPE '\\'"));
754 TEST2(err, KErrNone);
756 TEST2(err, KSqlAtEnd);
758 //Test 18 - there is no record satisfying the WHILE condition
759 err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'ABC' ESCAPE '\\'"));
760 TEST2(err, KErrNone);
762 TEST2(err, KSqlAtEnd);
764 //Test 19 - there is no record satisfying the WHILE condition
765 err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '%ABC' ESCAPE '\\'"));
766 TEST2(err, KErrNone);
768 TEST2(err, KSqlAtEnd);
772 RDebug::Print(_L("###Delete test database\r\n"));
773 (void)RSqlDatabase::Delete(KTestDbName1);
778 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1609 Folding & Collation test 1 "));
780 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1610 Folding & Collation test 2 "));
782 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627 Collation test 3 "));
784 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1760 LIKE & ESCAPE test 1 "));
786 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1761 LIKE & ESCAPE test 2 "));
794 CTrapCleanup* tc = CTrapCleanup::New();
800 TRAPD(err, DoTestsL());
802 TEST2(err, KErrNone);
811 User::Heap().Check();