sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: RTest TheTest(_L("t_sqlcollate test")); sl@0: sl@0: _LIT(KTestDir, "c:\\test\\"); sl@0: _LIT(KTestDbName1, "c:\\test\\t_sqlcollate.db"); sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void DeleteTestFiles() sl@0: { sl@0: RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macros and functions sl@0: void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: DeleteTestFiles(); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: DeleteTestFiles(); sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void CreateTestDir() sl@0: { sl@0: RFs fs; sl@0: TInt err = fs.Connect(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = fs.MkDir(KTestDir); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: sl@0: fs.Close(); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: //Compare aLeft and aRight strings using collated comparison, level 3, default collation method. sl@0: //This function is used when sorting the test names array in CollationTest1L(). sl@0: TInt StrSortC3(const TPtrC& aLeft, const TPtrC& aRight) sl@0: { sl@0: return aLeft.CompareC(aRight, 3, NULL); sl@0: } sl@0: sl@0: //Compare aLeft and aRight strings using collated comparison, level 1, default collation method. sl@0: //This function is used when sorting the test names array in CollationTest3L(). sl@0: TInt StrSortC1(const TPtrC& aLeft, const TPtrC& aRight) sl@0: { sl@0: return aLeft.CompareC(aRight, 1, NULL); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1609 sl@0: @SYMTestCaseDesc Create a table with a text column with default collation "CompareF" sl@0: and insert some records there. sl@0: Test how the searching operations work executing some SELECT SQL statements. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Testing database search operations using "CompareF" and "CompareC3" collations. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5907 sl@0: */ sl@0: void CollationTest1L() sl@0: { sl@0: RSqlDatabase db; sl@0: TInt err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //Create test database sl@0: RDebug::Print(_L("###Create test database\r\n")); sl@0: _LIT(KCreateSql, "CREATE TABLE A(Name VARCHAR(100) COLLATE CompareF); CREATE INDEX AIdx ON A(Name COLLATE CompareF);"); sl@0: err = db.Exec(KCreateSql); sl@0: TEST(err >= 0); sl@0: sl@0: //Insert some records. The column "Name" of each record contains the same name but the name characters are sl@0: //variation of upper/lower case letters. sl@0: RDebug::Print(_L("###Insert some records\r\n")); sl@0: _LIT(KInsertSql, "INSERT INTO A(Name) VALUES("); sl@0: //Collation sort order: KNames[1] KNames[3] KNames[0] KNames[2] sl@0: //Long "aaaa..." added to the end of each column value because SQLITE may use non-aligned strings sl@0: //only when the string length is in [32..] interval. sl@0: TPtrC KNames[] = { sl@0: _L("aLex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), sl@0: _L("ALeX-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), sl@0: _L("aleX-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), sl@0: _L("Alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")}; sl@0: const TInt KInsertSqlStmtCnt = sizeof(KNames)/sizeof(KNames[0]); sl@0: RArray sortedNames; sl@0: TLinearOrder order(&StrSortC3); sl@0: sl@0: for(TInt i=0;i sql(KInsertSql); sl@0: sql.Append(_L("'")); sl@0: sql.Append(KNames[i]); sl@0: sql.Append(_L("')")); sl@0: err = db.Exec(sql); sl@0: TEST2(err, 1); sl@0: } sl@0: sl@0: //The next "SELECT" statement must return a set containing all table records sl@0: RDebug::Print(_L("###Select all records\r\n")); sl@0: _LIT(KSelectSql1, "SELECT * FROM A WHERE NAME = 'alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'"); sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(db, KSelectSql1); sl@0: TEST2(err, KErrNone); sl@0: TInt recCount = 0; sl@0: while(stmt.Next() == KSqlAtRow) sl@0: { sl@0: ++recCount; sl@0: TPtrC name = stmt.ColumnTextL(0); sl@0: RDebug::Print(_L("%S\r\n"), &name); sl@0: } sl@0: stmt.Close(); sl@0: TEST(recCount == KInsertSqlStmtCnt); sl@0: sl@0: //The next "SELECT" statement must return a set containing all table records sl@0: // this tests a LIKE clause with a bound parameter (with wildcards) sl@0: RDebug::Print(_L("###Select all records (LIKE with wildcard)\r\n")); sl@0: _LIT(KSelectSql1a, "SELECT * FROM A WHERE NAME LIKE :Val"); sl@0: _LIT(KSearchString,"alex-aaaa%"); sl@0: err = stmt.Prepare(db, KSelectSql1a); sl@0: TEST2(err, KErrNone); sl@0: TInt idx=stmt.ParameterIndex(_L(":Val")); sl@0: err=stmt.BindText(idx,KSearchString); sl@0: TEST2(err, KErrNone); sl@0: recCount = 0; sl@0: while(stmt.Next() == KSqlAtRow) sl@0: { sl@0: ++recCount; sl@0: TPtrC name = stmt.ColumnTextL(0); sl@0: RDebug::Print(_L("%S\r\n"), &name); sl@0: } sl@0: stmt.Close(); sl@0: TEST(recCount == KInsertSqlStmtCnt); sl@0: sl@0: //The next "SELECT" statement must return a set containing all table records sl@0: // this tests a LIKE clause with a bound parameter (with no wildcards) sl@0: RDebug::Print(_L("###Select all records (LIKE with no wildcard)\r\n")); sl@0: _LIT(KSelectSql1b, "SELECT * FROM A WHERE NAME LIKE :Val"); sl@0: _LIT(KSearchStringA, sl@0: "alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); sl@0: err = stmt.Prepare(db, KSelectSql1b); sl@0: idx=stmt.ParameterIndex(_L(":Val")); sl@0: TEST2(err, KErrNone); sl@0: err=stmt.BindText(idx,KSearchStringA); sl@0: recCount = 0; sl@0: while(stmt.Next() == KSqlAtRow) sl@0: { sl@0: ++recCount; sl@0: TPtrC name = stmt.ColumnTextL(0); sl@0: RDebug::Print(_L("%S\r\n"), &name); sl@0: } sl@0: stmt.Close(); sl@0: TEST(recCount == KInsertSqlStmtCnt); sl@0: sl@0: //The next "SELECT" statement must return a row sl@0: // this tests a LIKE clause with a bound parameter and funny characters sl@0: RDebug::Print(_L("###Select one records (LIKE with bound param with URL chars)\r\n")); sl@0: err=db.Exec(_L("INSERT INTO A(Name) VALUES('http://a.b.c#d')")); sl@0: TEST2(err,1); sl@0: _LIT(KSelectSql1c, "SELECT * FROM A WHERE NAME LIKE :Val"); sl@0: _LIT(KSearchStringB,"http%"); sl@0: err = stmt.Prepare(db, KSelectSql1c); sl@0: idx=stmt.ParameterIndex(_L(":Val")); sl@0: TEST2(err, KErrNone); sl@0: err=stmt.BindText(idx,KSearchStringB); sl@0: recCount = 0; sl@0: while(stmt.Next() == KSqlAtRow) sl@0: { sl@0: ++recCount; sl@0: TPtrC name = stmt.ColumnTextL(0); sl@0: RDebug::Print(_L("%S\r\n"), &name); sl@0: } sl@0: stmt.Close(); sl@0: TEST(recCount == 1); sl@0: sl@0: sl@0: //The next "SELECT" statement must return a set containing all table records, folded comparison used for sorting sl@0: RDebug::Print(_L("###Select all records, folded string comparison\r\n")); sl@0: _LIT(KSelectSql2, "SELECT * FROM A WHERE NAME = 'alex-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ORDER BY NAME COLLATE CompareF"); sl@0: err = stmt.Prepare(db, KSelectSql2); sl@0: TEST2(err, KErrNone); sl@0: sl@0: recCount = 0; sl@0: for(TInt j=0;j= 0); sl@0: sl@0: //Insert some records. sl@0: RDebug::Print(_L("###Insert some records\r\n")); sl@0: _LIT(KInsertSql, "INSERT INTO A(Name) VALUES("); sl@0: TPtrC KNames[] = { sl@0: _L("aAaA"), sl@0: _L("AAaa"), sl@0: _L("aaAA"), sl@0: _L("aaaA")}; sl@0: const TInt KInsertSqlStmtCnt = sizeof(KNames)/sizeof(KNames[0]); sl@0: sl@0: for(TInt i=0;i sql(KInsertSql); sl@0: sql.Append(_L("'")); sl@0: sql.Append(KNames[i]); sl@0: sql.Append(_L("')")); sl@0: err = db.Exec(sql); sl@0: TEST2(err, 1); sl@0: } sl@0: sl@0: RSqlStatement stmt; sl@0: sl@0: //The next "SELECT" statement must return a set containing all table sl@0: //records which Name column value is bigger than "aaAA" sl@0: RDebug::Print(_L("###Select all records, which Name column value is bigger than 'aaAA'\r\n")); sl@0: _LIT(KSelectSql2, "SELECT * FROM A WHERE NAME > 'aaAA'"); sl@0: err = stmt.Prepare(db, KSelectSql2); sl@0: TEST2(err, KErrNone); sl@0: sl@0: while((err = stmt.Next()) == KSqlAtRow) sl@0: { sl@0: TPtrC name = stmt.ColumnTextL(0); sl@0: RDebug::Print(_L("%S\r\n"), &name); sl@0: TInt res = name.CompareC(KNames[2], 3, NULL); sl@0: TEST(res > 0); sl@0: } sl@0: stmt.Close(); sl@0: TEST2(err, KSqlAtEnd); sl@0: sl@0: //Cleanup sl@0: db.Close(); sl@0: RDebug::Print(_L("###Delete test database\r\n")); sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1627 sl@0: @SYMTestCaseDesc Create a table with a text column "NAME" with default collation "CompareC0" sl@0: and insert some records there. All inserted names are equal if compared at sl@0: collation level 0, but some of them contain accented letters. sl@0: Test how the searching operations work executing some SELECT SQL statements. sl@0: Test how the sorting operations work executing some SELECT SQL statements. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Testing database sorting operations using "CompareC0", "CompareC1", and "CompareC2" collations. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5907 sl@0: */ sl@0: void CollationTest3L() sl@0: { sl@0: RSqlDatabase db; sl@0: TInt err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //Create test database sl@0: RDebug::Print(_L("###Create test database\r\n")); sl@0: _LIT(KCreateSql, "CREATE TABLE A(Name VARCHAR(100) COLLATE CompareC0)"); sl@0: err = db.Exec(KCreateSql); sl@0: TEST(err >= 0); sl@0: sl@0: //Insert some records. Some of the inserted names have accented letters. sl@0: //But all names are equal if compared at collation level 0. sl@0: RDebug::Print(_L("###Insert some records\r\n")); sl@0: _LIT(KInsertSql, "INSERT INTO A(Name) VALUES("); sl@0: TBuf<10> name1(_L("Dvorak")); sl@0: TBuf<10> name2; sl@0: name2.SetLength(6); sl@0: name2[0] = TChar('D'); sl@0: name2[1] = TChar('v'); sl@0: name2[2] = TChar('o'); sl@0: name2[3] = 0x0158;//LATIN SMALL LETTER R HACEK sl@0: name2[4] = 0x00C1;//LATIN SMALL LETTER A ACUTE sl@0: name2[5] = TChar('k'); sl@0: const TPtrC KNames[] = {name1, name2}; sl@0: const TInt KInsertSqlStmtCnt = sizeof(KNames)/sizeof(KNames[0]); sl@0: RArray sortedNames; sl@0: TLinearOrder order(&StrSortC1); sl@0: sl@0: //Insert the records. Also, check how many names are equal to 'dvorak' using collation level 0. sl@0: _LIT(KTestName, "dvorak"); sl@0: TInt matchNameCnt = 0; sl@0: for(TInt i=0;i sql(KInsertSql); sl@0: sql.Append(_L("'")); sl@0: sql.Append(KNames[i]); sl@0: sql.Append(_L("')")); sl@0: err = db.Exec(sql); sl@0: TEST2(err, 1); sl@0: } sl@0: sl@0: //The next "SELECT" statement must return a set, which record count must be matchNameCnt. sl@0: RDebug::Print(_L("###Select all records, collated string comparison, level 0\r\n")); sl@0: _LIT(KSelectSql2, "SELECT * FROM A WHERE NAME = 'dvorak'"); sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(db, KSelectSql2); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TInt recCount = 0; sl@0: while((err = stmt.Next()) == KSqlAtRow) sl@0: { sl@0: TPtrC name = stmt.ColumnTextL(0); sl@0: RDebug::Print(_L("%S\r\n"), &name); sl@0: TEST(name == KNames[recCount]); sl@0: ++recCount; sl@0: } sl@0: stmt.Close(); sl@0: TEST(recCount == matchNameCnt); sl@0: sl@0: //The next "SELECT" statement must return an ordered set containing all table records. sl@0: RDebug::Print(_L("###Select all records, collated string comparison, level 1\r\n")); sl@0: _LIT(KSelectSql3, "SELECT * FROM A WHERE NAME = 'dvorak' ORDER BY NAME COLLATE CompareC1 DESC"); sl@0: err = stmt.Prepare(db, KSelectSql3); sl@0: TEST2(err, KErrNone); sl@0: sl@0: for(TInt k=0;k= 0); sl@0: err = db.Exec(_L("INSERT INTO A(Id, Name) VALUES(1, 'Dvorak')")); sl@0: TEST2(err, 1); sl@0: err = db.Exec(_L("INSERT INTO A(Id, Name) VALUES(2, 'Dvorák')")); sl@0: TEST2(err, 1); sl@0: //Create a statement object and issue a SELECT SQL statement + LIKE clause sl@0: //Test case 1 = full name search with LIKE sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 'DVORAK'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: TInt cnt = stmt.ColumnInt(0); sl@0: TEST2(cnt, 2); sl@0: stmt.Close(); sl@0: //Test case 2 = wild card used sequence character in the search pattern + LIKE sl@0: err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE '%RA%'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: cnt = stmt.ColumnInt(0); sl@0: TEST2(cnt, 2); sl@0: stmt.Close(); sl@0: //Test case 3 = wild card character used in the search pattern + LIKE sl@0: err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 'DV___K'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: cnt = stmt.ColumnInt(0); sl@0: TEST2(cnt, 2); sl@0: stmt.Close(); sl@0: //Insert one more record sl@0: err = db.Exec(_L("INSERT INTO A(Id, Name) VALUES(3, 't_sqltest')")); sl@0: TEST2(err, 1); sl@0: //Test case 4 = wild card character used in the search pattern + LIKE + ESCAPE sl@0: err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 't/_sqlte__' ESCAPE '/'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: cnt = stmt.ColumnInt(0); sl@0: TEST2(cnt, 1); sl@0: stmt.Close(); sl@0: //Test case 5 = wild card character used in the search pattern + LIKE + ESCAPE without an escape character sl@0: err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 't/_sqltest' ESCAPE ''")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST(err != KErrNone); sl@0: TEST2(::SqlRetCodeClass(err), ESqlDbError); sl@0: TPtrC errMsg = db.LastErrorMessage(); sl@0: RDebug::Print(_L("!! error=\"%S\"\r\n"), &errMsg); sl@0: stmt.Close(); sl@0: //Test case 6 = wild card character used in the search pattern + LIKE + ESCAPE with more than one escape characters sl@0: err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE 't/_sqltest' ESCAPE '1234'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST(err != KErrNone); sl@0: TEST2(::SqlRetCodeClass(err), ESqlDbError); sl@0: errMsg.Set(db.LastErrorMessage()); sl@0: RDebug::Print(_L("!! error=\"%S\"\r\n"), &errMsg); sl@0: stmt.Close(); sl@0: //Test case 7 = blank pattern string sl@0: err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM A WHERE Name LIKE ''")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: cnt = stmt.ColumnInt(0); sl@0: TEST2(cnt, 0); sl@0: stmt.Close(); sl@0: sl@0: //Cleanup sl@0: db.Close(); sl@0: RDebug::Print(_L("###Delete test database\r\n")); sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1761 sl@0: @SYMTestCaseDesc Verifying that all 'LIKE + ESCAPE' test cases which work with the old DBMS component, sl@0: pass successfully with the new SQL component. The test includes positive and negative test cases. sl@0: Not all negative test cases from the old DBMS pass, because the DBMS supports limited implementation of sl@0: the ESCAPE clause. Here the old negative tests were converted to a positive test cases. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Testing SQL LIKE operator and ESCAPE clause. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5907 sl@0: */ sl@0: void LikeTest2() sl@0: { sl@0: RSqlDatabase db; sl@0: TInt err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: //Create a test table sl@0: err = db.Exec(_L("CREATE TABLE A(Fld1 TEXT, Fld2 TEXT)")); sl@0: TEST(err >= 0); sl@0: //Insert some records sl@0: err = db.Exec(_L("INSERT INTO A(Fld1, Fld2) VALUES('ACDC\\','BLAH')")); // Rec1 sl@0: TEST2(err, 1); sl@0: err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('ABCDEFGH')")); // Rec2 sl@0: TEST2(err, 1); sl@0: err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('A_CDEFGH')")); // Rec3 sl@0: TEST2(err, 1); sl@0: err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('A_%_CDEFGH')")); // Rec4 sl@0: TEST2(err, 1); sl@0: err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('A%CDEFGH')")); // Rec5 sl@0: TEST2(err, 1); sl@0: err = db.Exec(_L("INSERT INTO A(Fld1, Fld2) VALUES('ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP','ADCB')")); //Rec6 sl@0: TEST2(err, 1); sl@0: err = db.Exec(_L("INSERT INTO A(Fld1) VALUES('XZD\\FZX')")); // Rec7 sl@0: TEST2(err, 1); sl@0: //Prepare SELECT query, step and check the record set content sl@0: TPtrC res; sl@0: //Test 1 - only Rec1 satisfies the WHILE condition sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(db, _L("SELECT Fld2 FROM A WHERE Fld1 LIKE 'ACDC\\' AND Fld2 LIKE '%BL%'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("BLAH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 2 - only Rec5 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%A\\%C%' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("A%CDEFGH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 3 - only Rec3 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%A\\_C%' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("A_CDEFGH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 4 - only Rec4 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%A\\_\\%\\_C%' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("A_%_CDEFGH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 5 - only Rec6 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE '%1234%'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP")); sl@0: err = stmt.ColumnText(1, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("ADCB")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 6 - only Rec1 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE '%AC%' AND Fld2 LIKE '_LA_'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("ACDC\\")); sl@0: err = stmt.ColumnText(1, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("BLAH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 7 - only Rec1 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE 'NOTINTABLE' OR Fld2 LIKE '_LA_'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("ACDC\\")); sl@0: err = stmt.ColumnText(1, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("BLAH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 8 - only Rec6 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT Fld1, Fld2 FROM A WHERE Fld1 LIKE '%ADC%' AND Fld2 LIKE 'ADC_'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP")); sl@0: err = stmt.ColumnText(1, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("ADCB")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 9 - only Rec5 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%\\%C%' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("A%CDEFGH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 10 - only Rec7 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT Fld1 FROM A WHERE Fld1 LIKE '%D\\\\%' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("XZD\\FZX")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 11 - only Rec4 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '%A\\__\\_C%' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("A_%_CDEFGH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 12 - only Rec5 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '%A%\\%C%' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("A%CDEFGH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 13 - only Rec2 satisfies the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'ABC%' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: err = stmt.ColumnText(0, res); sl@0: TEST2(err, KErrNone); sl@0: TEST(res == _L("ABCDEFGH")); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 14 - there is no record satisfying the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'A_C' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 15 - there is no record satisfying the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'A%C' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 16 - there is no record satisfying the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '_A\\_C' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 17 - there is no record satisfying the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '_A\\_C_' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 18 - there is no record satisfying the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE 'ABC' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Test 19 - there is no record satisfying the WHILE condition sl@0: err = stmt.Prepare(db, _L("SELECT * FROM A WHERE Fld1 LIKE '%ABC' ESCAPE '\\'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: //Cleanup sl@0: db.Close(); sl@0: RDebug::Print(_L("###Delete test database\r\n")); sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: void DoTestsL() sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1609 Folding & Collation test 1 ")); sl@0: CollationTest1L(); sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1610 Folding & Collation test 2 ")); sl@0: CollationTest2L(); sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627 Collation test 3 ")); sl@0: CollationTest3L(); sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1760 LIKE & ESCAPE test 1 ")); sl@0: LikeTest1(); sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1761 LIKE & ESCAPE test 2 ")); sl@0: LikeTest2(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: TheTest.Title(); sl@0: sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: CreateTestDir(); sl@0: DeleteTestFiles(); sl@0: TRAPD(err, DoTestsL()); sl@0: DeleteTestFiles(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: delete tc; sl@0: sl@0: User::Heap().Check(); sl@0: return KErrNone; sl@0: }