sl@0: // Copyright (c) 2006-2010 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: // NTT DOCOMO, INC - Fix for Bug 1915 "SQL server panics when using long column type strings" sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "SqlResourceProfiler.h" sl@0: #include "SqlResourceTester.h" sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: static RFs TheFs; sl@0: RTest TheTest(_L("t_sqldefect test")); sl@0: RSqlDatabase TheDb; sl@0: sl@0: _LIT(KTestDir, "c:\\test\\"); sl@0: _LIT(KTestDatabase1, "c:\\test\\t_sqldefect_1.db"); sl@0: _LIT(KTestDatabase2, "c:\\test\\t_sqldefect_2.db"); sl@0: _LIT(KCorruptDb, "c:\\test\\t_SqlShortNonDb.db"); sl@0: _LIT(KCorruptDbZ, "z:\\test\\t_SqlShortNonDb.db"); //Created outside this test app sl@0: _LIT(KSecureTestDb1, "c:[21212122]BBDb2.db"); //Created outside this test app sl@0: _LIT(KTestDatabase3, "c:\\test\\t_sqldefect_3.db"); sl@0: _LIT(KTestDatabase4, "z:\\test\\t_inc095412.db"); //Created outside this test app sl@0: _LIT(KTestDatabase5, "c:\\test\\t_sqldefect_5.db"); sl@0: _LIT(KTestDatabase6, "c:\\test\\t_def120237.db"); sl@0: _LIT(KTestDatabase7, "c:\\test\\t_def144027.db"); sl@0: _LIT(KTestDatabase7Journal, "c:\\test\\t_def144027.db-journal"); sl@0: sl@0: // This value has been found by performing the OOM test sl@0: // with an allocation limit of 2000 and then taking a value sl@0: // which is just above the allocation failure rate. sl@0: const TInt KDEF115954MaxAllocLimit = 1300; sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: //Deletes all created test files. sl@0: void DeleteTestFiles() sl@0: { sl@0: TheDb.Close(); sl@0: (void)TheFs.Delete(KTestDatabase7Journal); sl@0: (void)RSqlDatabase::Delete(KTestDatabase7); sl@0: (void)RSqlDatabase::Delete(KTestDatabase6); sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: (void)RSqlDatabase::Delete(KTestDatabase2); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: (void)RSqlDatabase::Delete(KCorruptDb); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macros and functions sl@0: void Check1(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: DeleteTestFiles(); sl@0: RDebug::Print(_L("*** Line %d\r\n"), aLine); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: void Check2(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: DeleteTestFiles(); sl@0: RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check1((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: //Creates file session instance and the test directory sl@0: void CreateTestEnv() sl@0: { sl@0: TInt err = TheFs.Connect(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = TheFs.MkDir(KTestDir); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1763 sl@0: @SYMTestCaseDesc The test creates database 1 and attaches database 2. sl@0: Then the test prepares a SELECT sql statement which is supposed to sl@0: retrieve records from the attached database 2. Then the test tries to detach sl@0: database 2. The expectation is that the detaching operation must fail. sl@0: The database can be detached only when there are no alive sql statements prepared on it. sl@0: @SYMTestPriority High sl@0: @SYMTestActions SQL, "Detach database" test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void SqlDetachedDbTest() sl@0: { sl@0: TInt err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L8("CREATE TABLE A(Id INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(1)")); sl@0: TEST2(err, 1); sl@0: TheDb.Close(); sl@0: sl@0: err = TheDb.Create(KTestDatabase2); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L8("CREATE TABLE B(N INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(10)")); sl@0: TEST2(err, 1); sl@0: err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(20)")); sl@0: TEST2(err, 1); sl@0: TheDb.Close(); sl@0: sl@0: err = TheDb.Open(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Attach(KTestDatabase2, _L("Db2")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, _L8("SELECT * FROM B")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: sl@0: err = TheDb.Detach(_L("Db2")); sl@0: TEST(err != KErrNone); sl@0: TPtrC errMsg = TheDb.LastErrorMessage(); sl@0: RDebug::Print(_L("Detach err: %S\r\n"), &errMsg); sl@0: sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: stmt.Close(); sl@0: sl@0: err = TheDb.Detach(_L("Db2")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase2); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4034 sl@0: @SYMTestCaseDesc Corrupted database test. sl@0: The test tries to open a corrupted database file which length is too short. sl@0: The 'database open' operation is expected to fail with KSqlErrNotDb error. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Corrupted database test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: */ sl@0: void CorruptDbFileTest() sl@0: { sl@0: TInt err = TheDb.Open(KCorruptDb); sl@0: TEST2(err, KSqlErrNotDb); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4035 sl@0: @SYMTestCaseDesc Attach database with bad name. sl@0: Attempt to attach a file which name cannot be parsed. sl@0: The 'attach database' operation is expected to fail with KErrBadName error. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Attach database with bad name. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: */ sl@0: void AttachBadDbFileNameTest() sl@0: { sl@0: TInt err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Attach(_L("\"c:\\test\\d12345678.db\""), _L("Db10")); sl@0: TEST2(err, KErrBadName); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4036 sl@0: @SYMTestCaseDesc Attach secure database. The client cannot pass the security checks. sl@0: Attempt to attach a secure database. The client cannot pass the security checks. sl@0: The 'attach database' operation is expected to fail with KErrPermissionDenied error. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Attach secure database. The client cannot pass the security checks. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5794 sl@0: */ sl@0: void AttachSecureDbTest() sl@0: { sl@0: TInt err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Attach(KSecureTestDb1, _L("Db10")); sl@0: TEST2(err, KErrPermissionDenied); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4032 sl@0: @SYMTestCaseDesc Test for defect INC091579 - SQL Panic 7 when streaming BLOB fields. sl@0: The test creates a database with a table with a BLOB column. Then inserts sl@0: a record. Then the test makes an attempt to read the BLOB column using a stream - sl@0: RSqlColumnReadStream. If the defect is not fixed, the code will panic. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for defect INC091579 - SQL Panic 7 when streaming BLOB fields. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF INC091579 sl@0: */ sl@0: void INC091579L() sl@0: { sl@0: //Create test database sl@0: TInt err = TheDb.Create(KTestDatabase3); sl@0: TEST2(err, KErrNone); sl@0: _LIT8(KCreateStmt, "CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB)"); sl@0: err = TheDb.Exec(KCreateStmt); sl@0: TEST(err >= 0); sl@0: //Insert 1 row, using a binary stream sl@0: _LIT8(KInsertStmt, "INSERT INTO A(Fld1,Fld2) VALUES(:p1,:p2)"); sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, KInsertStmt); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.BindInt(0, 1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: RSqlParamWriteStream out; sl@0: err = out.BindBinary(stmt, 1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: const TInt KDataSize = 100; sl@0: TUint16 columnData[KDataSize]; sl@0: for(TInt i=0;i= 0); sl@0: sl@0: _LIT8(KInsertStmt,"INSERT INTO A(Fld1,Fld2,Fld3) VALUES(1,:p1,:p2)"); sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, KInsertStmt); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.BindText(0, _L("AAA"));// "AAA" assigned to p1 parameter sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = stmt.BindText(1,_L("123456789ABCD"));//"123456789ABCD" assigned to p2 parameter (Fld2 column) sl@0: TEST2(err, KErrNone); sl@0: err = stmt.BindText(1, _L("123456789ABCDE"));//"123456789ABCDE" assigned to p2 parameter (Fld3 column) sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Exec(); sl@0: TEST(err >= 0); sl@0: sl@0: stmt.Close(); sl@0: sl@0: _LIT8(KSelectStmt,"SELECT * FROM A WHERE Fld1=1"); sl@0: err = stmt.Prepare(TheDb, KSelectStmt); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: sl@0: TPtrC fld2 = stmt.ColumnTextL(1); // returns bad value if the defect is not fixed sl@0: TPtrC fld3 = stmt.ColumnTextL(2); sl@0: sl@0: TEST(fld2 == _L("AAA")); sl@0: TEST(fld3 == _L("123456789ABCDE")); sl@0: sl@0: //Cleanup sl@0: stmt.Close(); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1815 sl@0: @SYMTestCaseDesc KSqlErrFull test. sl@0: Create a test database with a table, which first column is declared as sl@0: "INTEGER PRIMARY KEY AUTOINCREMENT". sl@0: Insert one record into the table, initializing the ROWID with 0x7FFFFFFFFFFFFFFF sl@0: (KMaxTInt64). Try to insert one more record into the table. The operation must sl@0: fails with KSqlErrDiskFull. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Verifying that SQL server returns KSqlErrFull when there are no more available row ids. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void SqlErrFullTest() sl@0: { sl@0: TInt err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L8("CREATE TABLE A(Id INTEGER PRIMARY KEY AUTOINCREMENT, T TEXT)")); sl@0: TEST(err >= 0); sl@0: sl@0: TBuf8<100> sql; sl@0: sl@0: sql.Copy(_L8("INSERT INTO A(ROWID,T) VALUES(")); sl@0: sql.AppendNum(KMaxTInt64); sl@0: sql.Append(_L8(", 'TTT')")); sl@0: err = TheDb.Exec(sql); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L8("INSERT INTO A(T) VALUES('UUU')")); sl@0: TEST2(err, KSqlErrFull); sl@0: sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, _L8("SELECT ROWID FROM A")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: TInt64 val = stmt.ColumnInt64(0); sl@0: TEST(val == KMaxTInt64); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1816-0001 sl@0: @SYMTestCaseDesc Test for defect INC094870 - Database became corrupted and cannot be opened. sl@0: Case 1: Create a test database and set the database encoding to be UTF-8. Create a table. sl@0: Close and open again the database. "Database open" operation should not panic. sl@0: Case 2: Create a test database and set the database encoding to be UTF-8. Open two sl@0: connections to the database and check the encoding. It should be UTF-8. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for defect INC094870 - Database became corrupted and cannot be opened. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF INC094870 sl@0: */ sl@0: void INC094870L() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: //Test 1 - with a single database sl@0: TInt err = TheDb.Create(KTestDatabase3); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L8("PRAGMA cache_size=1000")); sl@0: TEST(err >= 0); sl@0: err = TheDb.SetIsolationLevel(RSqlDatabase::EReadUncommitted); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L8("PRAGMA encoding = \"UTF-8\";")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L8("PRAGMA case_sensitive_like = 0")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L8("CREATE TABLE RDFS_Namespace(NamespaceId INTEGER NOT NULL,Uri TEXT NOT NULL,ReadOnly INTEGER NOT NULL,VID INTEGER NOT NULL,PRIMARY KEY(NamespaceId),UNIQUE(Uri));")); sl@0: TEST(err >= 0); sl@0: //Close and reopen the database. The Open() call should not fail. sl@0: TheDb.Close(); sl@0: err = TheDb.Open(KTestDatabase3); // This call fails if the defect is not fixed sl@0: TEST2(err, KErrNone); sl@0: TheDb.Close(); sl@0: //Test 2 - with two database connections sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: _LIT8(KEncoding, "encoding=UTF-8"); sl@0: _LIT(KUtf8, "UTF-8"); sl@0: RSqlDatabase db1, db2; sl@0: //Connection 1: Create a database with default encoding UTF-8. sl@0: err = db1.Create(KTestDatabase3, &KEncoding); sl@0: TEST2(err, KErrNone); sl@0: TBuf<100> buf; sl@0: //Connection 1: Check the database encoding sl@0: TSqlScalarFullSelectQuery query(db1); sl@0: err = query.SelectTextL(_L8("PRAGMA encoding"), buf); sl@0: TEST2(err, KErrNone); sl@0: TEST(buf.Find(KUtf8) >= 0); sl@0: //Connection 1: Create a table sl@0: err = db1.Exec(_L8("CREATE TABLE Tbl(Id INTEGER, T BLOB)")); sl@0: TEST(err >= 0); sl@0: //Connection 1: Check the database encoding sl@0: err = query.SelectTextL(_L8("PRAGMA encoding"), buf); sl@0: TEST2(err, KErrNone); sl@0: TEST(buf.Find(KUtf8) >= 0); sl@0: //Connection 2: open the same database sl@0: err = db2.Open(KTestDatabase3); sl@0: TEST2(err, KErrNone); sl@0: //Connection 1: Check the database encoding sl@0: err = query.SelectTextL(_L8("PRAGMA encoding"), buf); sl@0: TEST2(err, KErrNone); sl@0: TEST(buf.Find(KUtf8) >= 0); sl@0: //Connection 2: Check the database encoding sl@0: query.SetDatabase(db2); sl@0: err = query.SelectTextL(_L8("PRAGMA encoding"), buf); sl@0: TEST2(err, KErrNone); sl@0: TEST(buf.Find(KUtf8) >= 0); sl@0: //Cleanup sl@0: db2.Close(); sl@0: db1.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1817-0001 sl@0: @SYMTestCaseDesc Test for defect INC095412 - Retrieving query results may corrupt heap. sl@0: Open t_inc095412.db test database and prepare SQL query (the SQL statement is in the test code). sl@0: Execute RSqlStatement::Next() and then try to retrieve the text value of column number 1. sl@0: If the defect is not fixed RSqlStatement::ColumnText() will panic. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for defect INC095412 - Retrieving query results may corrupt heap. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF INC095412 sl@0: */ sl@0: void INC095412() sl@0: { sl@0: TInt err = TheDb.Open(KTestDatabase4); sl@0: TEST2(err, KErrNone); sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, _L("SELECT ObjId, Uri, InstanceOf, Flags, p1.PropertyId, p1.PropertyTypeId, p1.Value, p1.Source, p1.Confidence FROM Objects JOIN Properties p1 ON ObjId = p1.HostObjId WHERE ( ( (NOT Flags%3) = ? AND (NOT Flags%11) = ? AND InstanceOf IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ) OR ( (NOT Flags%3) = ? AND (NOT Flags%11) = ? AND InstanceOf IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ) OR ( (NOT Flags%3) = ? AND (NOT Flags%11) = ? AND InstanceOf IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ) OR ( (NOT Flags%3) = ? AND (NOT Flags%11) = ? AND InstanceOf IN ( ? , ? , ? , ? ) ) );")); sl@0: TEST2(err, KErrNone); sl@0: const TInt KPrmValues[] = {0, 0, 33, 40, 47, 45, 43, 42, 50, 39, 51, 44, 41, 46, 38, 48, 49, 0, 0, 26, 40, 53, 54, 57, 52, 39, 58, 56, 41, 38, 55, 0, 0, 26, 40, 53, 54, 57, 52, 39, 58, 56, 41, 38, 55, 0, 0, 38, 40, 39, 41}; sl@0: for(TInt i=0;i= 0); sl@0: //Cleanup sl@0: TheDb.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-3430 sl@0: @SYMTestCaseDesc Test for DEF104437 - RSqlStatement::Next() panics the SQL server with KERN-EXEC 3. sl@0: The test attempts to execute 2 SELECT queries ("IN" and "IN + JOIN"). The table, on sl@0: which queries operate, has multi-column primary key. The right-hand side of the sl@0: "IN" operator contains NULL. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF104437 - RSqlStatement::Next() panics the SQL server with KERN-EXEC 3. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF104437 sl@0: */ sl@0: void DEF104437() sl@0: { sl@0: //Test case 1 - "IN" + "JOIN" sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: TInt err = TheDb.Create(KTestDatabase5); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L("CREATE TABLE inmk(cls TEXT,sec INTEGER,inst INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L("INSERT INTO inmk VALUES ('ORD', 2751, 2750)")); sl@0: TEST2(err, 1); sl@0: err = TheDb.Exec(_L("CREATE TABLE clss(hrar TEXT,cls TEXT,PRIMARY KEY (hrar, cls))")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L("CREATE TABLE rels(prnt_inst INTEGER,chld_inst INTEGER)")); sl@0: TEST(err >= 0); sl@0: RSqlStatement stmt; sl@0: _LIT(KSelectSql, sl@0: "SELECT I.sec\ sl@0: FROM inmk I\ sl@0: LEFT JOIN\ sl@0: rels R ON R.prnt_inst = I.inst\ sl@0: LEFT JOIN\ sl@0: inmk UI ON UI.inst = R.chld_inst\ sl@0: LEFT JOIN\ sl@0: clss C1U ON C1U.cls = UI.cls AND C1U.hrar = 'STH'\ sl@0: LEFT JOIN\ sl@0: clss C10U ON C10U.hrar = c1u.hrar AND C10U.cls IN (C1U.cls)\ sl@0: WHERE I.sec = 2751;"); sl@0: err = stmt.Prepare(TheDb, KSelectSql); sl@0: TEST2(err, KErrNone); sl@0: while((err = stmt.Next()) == KSqlAtRow) sl@0: { sl@0: TInt val = stmt.ColumnInt(0); sl@0: TEST2(val, 2751); sl@0: TheTest.Printf(_L("column value=%d\r\n"), val); sl@0: } sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: TheDb.Close(); sl@0: ////////////////////////////////////////////////////////////// sl@0: //Test case 2 - "IN" sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: err = TheDb.Create(KTestDatabase5); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L("CREATE TABLE b(y,z,PRIMARY KEY(y, z))")); sl@0: TEST(err >= 0); sl@0: err = stmt.Prepare(TheDb, _L("SELECT * FROM b WHERE y = NULL AND z IN ('hello')")); sl@0: TEST2(err, KErrNone); sl@0: while((err = stmt.Next()) == KSqlAtRow) sl@0: { sl@0: } sl@0: TEST2(err, KSqlAtEnd); sl@0: stmt.Close(); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-3442 sl@0: @SYMTestCaseDesc Test for DEF105259 - SQL, RSqlColumnReadStream's internal buffer may become invalid. sl@0: The test does the following steps: sl@0: 1) Create a table: CREATE TABLE A(Name TEXT, Data BLOB); sl@0: 2) Insert only one record in A, such that, the "Name" column length is less than sl@0: 8 characters, the "Data" column length is 1K bytes. sl@0: 3) Create RSqlStatement object with the following SQL statement: SELECT * FROM A sl@0: 4) Call RSqlStatement::Next() to get the record sl@0: 5) Create RSqlColumnReadStream for column 0 (the "Name" column) sl@0: 6) Try to access the "Data" column value, without using a stream sl@0: 7) Try to read the "Name" column using the stream sl@0: 8) Compare the read "Name" column value vs. the original column value (at the moment sl@0: when the table record was stored) sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF105259 - SQL, RSqlColumnReadStream's internal buffer may become invalid. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF105259 sl@0: */ sl@0: void DEF105259L() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: TInt err = TheDb.Create(KTestDatabase3); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE A(Name TEXT, Data BLOB)")); sl@0: TEST(err >= 0); sl@0: sl@0: const TInt KBlobDataSize = 1024; sl@0: HBufC* recBuf = HBufC::New(KBlobDataSize * 2 + 100); sl@0: TEST(recBuf != NULL); sl@0: TPtr sql = recBuf->Des(); sl@0: sql.Copy(_L("INSERT INTO A(Name,Data) VALUES('A12',x'")); sl@0: for(TInt i=0;i tmp; sl@0: tmp.AppendFormat(_L("%02X"), i % 256); sl@0: sql.Append(tmp); sl@0: } sl@0: sql.Append(_L("')")); sl@0: sl@0: err = TheDb.Exec(sql); sl@0: TEST2(err, 1); sl@0: sl@0: delete recBuf; sl@0: sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, _L("SELECT * FROM A")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: sl@0: RSqlColumnReadStream strm; sl@0: err = strm.ColumnText(stmt, 0); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TPtrC8 data; sl@0: err = stmt.ColumnBinary(1, data); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TBuf<10> name; sl@0: strm.ReadL(name, 3); sl@0: TEST(name == _L("A12")); sl@0: sl@0: strm.Close(); sl@0: stmt.Close(); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-3470 sl@0: @SYMTestCaseDesc Test for DEF105681 - SQL, HReadOnlyBuf::ConstructL() sets a pointer to a local TPtr8 variable. sl@0: The test creates a database with a table: A(Name TEXT, Data BLOB). One record is inserted sl@0: in the table. Then the test creates a statement object with "SELECT * FROM A" sql statement. sl@0: The test moves the statement cursor on the record and attempts to access the BLOB column sl@0: using a stream. When the stream object is created, the test attempts to create an embedded sl@0: store object from the stream, using CEmbeddedStore::FromLC(strm) call. If the defect sl@0: is not fixed, the call will panic. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF105681 - SQL, HReadOnlyBuf::ConstructL() sets a pointer to a local TPtr8 variable. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF105681 sl@0: */ sl@0: void DEF105681L() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: TInt err = TheDb.Create(KTestDatabase3); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE A(Name TEXT, Data BLOB)")); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L("INSERT INTO A(Name,Data) VALUES('A12',x'0400000000')")); sl@0: TEST2(err, 1); sl@0: sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, _L("SELECT * FROM A")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: sl@0: RSqlColumnReadStream strm; sl@0: err = strm.ColumnBinary(stmt, 1); sl@0: TEST2(err, KErrNone); sl@0: CEmbeddedStore* store = CEmbeddedStore::FromLC(strm); sl@0: CleanupStack::PopAndDestroy(store); sl@0: sl@0: strm.Close(); sl@0: stmt.Close(); sl@0: sl@0: //Testing with a NULL binary column value sl@0: err = TheDb.Exec(_L("INSERT INTO A(Name,Data) VALUES('BBB',NULL)")); sl@0: TEST2(err, 1); sl@0: sl@0: err = stmt.Prepare(TheDb, _L("SELECT * FROM A WHERE Name='BBB'")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: sl@0: err = strm.ColumnBinary(stmt, 1); sl@0: TEST2(err, KErrNone); sl@0: store = NULL; sl@0: TRAP(err, store = CEmbeddedStore::FromL(strm)); sl@0: TEST2(err, KErrEof); sl@0: delete store; sl@0: sl@0: strm.Close(); sl@0: stmt.Close(); sl@0: sl@0: sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-3476 sl@0: @SYMTestCaseDesc Test for DEF106391 - SQL server does not deallocate the already allocated memory. sl@0: The test is executed only on the Emulator, because its execution depends on the amount sl@0: of the available memory and the amount of free disk space - factors which cannot be easily sl@0: resolved on target hardware. sl@0: The test creates a database with a table: T(Id INTEGER, Data BLOB). sl@0: One record with a BLOB (either 0.79Mb or 0.9Mb) is inserted using RSqlDatabase::Exec(). sl@0: Another record with a BLOB (either 1.58 or 1.8Mb) is inserted using RSqlStatement and BLOB parameter. sl@0: If the defect is not fixed, after the first INSERT the SQL server will not free occupied by sl@0: the statement memory. The available heap memory won't be enough for the execution of the second INSERT statement. sl@0: The second INSERT will fail with KErrNoMemory. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF106391 - SQL server does not deallocate the already allocated memory. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF106391 sl@0: */ sl@0: void DEF106391() sl@0: { sl@0: #if defined __WINS__ || defined __WINSCW__ sl@0: #ifndef SYMBIAN_USE_SQLITE_VERSION_3_6_4 sl@0: const TInt KBlobSize = 900 * 1024; sl@0: #else sl@0: const TInt KBlobSize = 790 * 1024; sl@0: #endif sl@0: sl@0: _LIT8(KConfigStr, "encoding=UTF-8"); sl@0: sl@0: HBufC8* sqlBuf = HBufC8::New(KBlobSize * 2 + 200);//"+ 200" - for the SQL INSERT statement sl@0: TEST(sqlBuf != NULL); sl@0: sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: sl@0: //Step 1: insert a record with a very large BLOB column (using RSqlDatabase::Exec()) sl@0: // (the operation is rolled back because there may not be enough disk space) sl@0: TVolumeInfo volInfo; sl@0: TInt err = TheFs.Volume(volInfo); sl@0: TEST2(err, KErrNone); sl@0: TheTest.Printf(_L("INSERT#1, Volume size: %ldK Free space: %ldK\r\n"), volInfo.iSize / 1024, volInfo.iFree / 1024); sl@0: TheTest.Printf(_L("Test BLOB size: %dK\r\n"), KBlobSize / 1024); sl@0: sl@0: err = TheDb.Create(KTestDatabase5, &KConfigStr); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TSqlResourceProfiler profiler(TheDb); sl@0: (void)profiler.Start(TSqlResourceProfiler::ESqlCounterMaxAlloc); sl@0: sl@0: err = TheDb.Exec(_L8("CREATE TABLE T(Id INTEGER, Data BLOB)")); sl@0: TEST(err >= 0); sl@0: TPtr8 sql = sqlBuf->Des(); sl@0: sql.Copy(_L8("BEGIN TRANSACTION;INSERT INTO T(Id,Data) VALUES(1, x'")); sl@0: for(TInt i=0;i= 0); sl@0: TBuf8<32> profilerRes8; sl@0: TBuf<32> profilerRes; sl@0: if(profiler.Query(TSqlResourceProfiler::ESqlCounterMaxAlloc, profilerRes8) == KErrNone) sl@0: { sl@0: profilerRes.Copy(profilerRes8); sl@0: TheTest.Printf(_L("RSqlDatabase::Exec(): ;=%S\r\n"), &profilerRes); sl@0: } sl@0: sl@0: //Step 2: insert a record with a very large BLOB column (using RSqlStatement::Exec()) sl@0: // (the operation is rolled back because there may not be enough disk space) sl@0: err = TheFs.Volume(volInfo); sl@0: TEST2(err, KErrNone); sl@0: TheTest.Printf(_L("INSERT#2, Volume size: %ldK Free space: %ldK\r\n"), volInfo.iSize / 1024, volInfo.iFree / 1024); sl@0: TheTest.Printf(_L("Test BLOB size: %dK\r\n"), sql.Length() / 1024); sl@0: sl@0: (void)profiler.Reset(TSqlResourceProfiler::ESqlCounterMaxAlloc); sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, _L("INSERT INTO T(Id, Data) VALUES(2, :V)")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.BindBinary(0, sql); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L("BEGIN TRANSACTION")); sl@0: TEST(err >= 0); sl@0: err = stmt.Exec(); sl@0: TEST2(err, 1); sl@0: err = TheDb.Exec(_L("ROLLBACK TRANSACTION")); sl@0: TEST(err >= 0); sl@0: stmt.Close(); sl@0: if(profiler.Query(TSqlResourceProfiler::ESqlCounterMaxAlloc, profilerRes8) == KErrNone) sl@0: { sl@0: profilerRes.Copy(profilerRes8); sl@0: TheTest.Printf(_L("RSqlStatement::Bind/Exec(): ;=%S\r\n"), &profilerRes); sl@0: } sl@0: sl@0: delete sqlBuf; sl@0: sl@0: (void)profiler.Stop(TSqlResourceProfiler::ESqlCounterMaxAlloc); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: #endif// defined __WINS__ || defined __WINSCW__ sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-3501 sl@0: @SYMTestCaseDesc Test for DEF109025 - SQL, dangling long binary/text column value pointer sl@0: The test does the following steps: sl@0: 1) Create a table: CREATE TABLE A(Name TEXT, Data BLOB); sl@0: 2) Insert only one record in A, such that, the "Name" column length is less than sl@0: 8 characters, the "Data" column length is 1K bytes. sl@0: 3) Create RSqlStatement object with the following SQL statement: SELECT * FROM A sl@0: 4) Call RSqlStatement::Next() to get the record sl@0: 5) Allocate a 1024 bytes buffer (so, when the row buffer has to be reallocated, the system will be forced to sl@0: search another block of memory, because the current one is capped by the allocated 1024 bytes) sl@0: 6) Get a pointer to the "name" column value sl@0: 7) Get a pointer to the "data" column value sl@0: 8) Check the "name" column value. If the defect still exists, the "name" pointer will point to a deleted sl@0: block of memory. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF109025 - SQL, dangling long binary/text column value pointer. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF109025 sl@0: */ sl@0: void DEF109025() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: TInt err = TheDb.Create(KTestDatabase3); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE A(Name TEXT, Data BLOB)")); sl@0: TEST(err >= 0); sl@0: sl@0: const TInt KBlobDataSize = 1024; sl@0: HBufC* recBuf = HBufC::New(KBlobDataSize * 2 + 100); sl@0: TEST(recBuf != NULL); sl@0: TPtr sql = recBuf->Des(); sl@0: sql.Copy(_L("INSERT INTO A(Name,Data) VALUES('A12',x'")); sl@0: for(TInt i=0;i tmp; sl@0: tmp.AppendFormat(_L("%02X"), i % 256); sl@0: sql.Append(tmp); sl@0: } sl@0: sql.Append(_L("')")); sl@0: sl@0: err = TheDb.Exec(sql); sl@0: TEST2(err, 1); sl@0: sl@0: delete recBuf; sl@0: sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, _L("SELECT * FROM A")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: sl@0: TUint8* mem = new TUint8[1024]; //This memory block will be allocated right after the row buffer, sl@0: TEST(mem != NULL); //so the ColumnBinary() call will reallocate the row buffer somewhere else, not at the same address. sl@0: sl@0: TPtrC name; sl@0: err = stmt.ColumnText(0, name); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TPtrC8 data; sl@0: err = stmt.ColumnBinary(1, data); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TEST(name == _L("A12")); sl@0: sl@0: delete [] mem; sl@0: stmt.Close(); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-3546 sl@0: @SYMTestCaseDesc Test for DEF109843 - SQL, RSQLStatement::BindBinary() is causing panic if empty descriptor is passed. sl@0: The test does the following steps: sl@0: 1) Create a table: CREATE TABLE A(Id INTEGER, Data BLOB); sl@0: 2) Create a RSqlStatement object stmt; sl@0: 3) Prepare stmt with the following SQL statement: sl@0: INSERT INTO A(Id,Data) VALUES(:Val1,:Val2); sl@0: 4) Set the Val2 field with an empty descriptor("") by using RSqlStatement::BindBinary(); sl@0: 5) Execute the statement; sl@0: 6) If the defect still exist, stmt.BindBinary() will cause a panic; sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF109843 - SQL, RSQLStatement::BindBinary() is causing panic if empty descriptor is passed. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF109843 sl@0: */ sl@0: void DEF109843() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: TInt err = TheDb.Create(KTestDatabase5); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER, Data BLOB)")); sl@0: TEST(err >= 0); sl@0: sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, _L("INSERT INTO A(Id,Data) VALUES(:Val1,:Val2)")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TInt paramIndex; sl@0: paramIndex = stmt.ParameterIndex(_L(":Val1")); sl@0: TEST(paramIndex >= 0); sl@0: sl@0: err = stmt.BindInt(paramIndex, 1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = stmt.ParameterIndex(_L(":Val2")); sl@0: TEST(paramIndex >= 0); sl@0: sl@0: TPtrC8 emptyEntry (_L8("")); sl@0: err = stmt.BindBinary(paramIndex, emptyEntry); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = stmt.Exec(); sl@0: TEST(err >= 0); sl@0: sl@0: stmt.Close(); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4005 sl@0: @SYMTestCaseDesc Test for DEF114698 - SqlSrv.EXE::!SQL Server Insert/Update Error. sl@0: The test does the following steps: sl@0: 1) DB3: sl@0: CREATE TABLE A(Id INTEGER, Id1 INTEGER) sl@0: INSERT INTO A(Id,Id1) VALUES(2,3) sl@0: 2) DB2: sl@0: CREATE TABLE B(Id INTEGER, Id1 INTEGER) sl@0: INSERT INTO B(Id,Id1) VALUES(2,3) sl@0: 3) DB: sl@0: CREATE TABLE MAIN(Id INTEGER, Id1 INTEGER) sl@0: INSERT INTO MAIN(Id,Id1) VALUES(2,3) sl@0: 4) Attach DB2 and DB3 to DB. sl@0: 5) Execute: sl@0: INSERT INTO B SELECT * FROM B UNION ALL SELECT * FROM MAIN WHERE exists (select * FROM B WHERE B.Id = MAIN.Id); sl@0: UPDATE A SET Id= (SELECT Id1 FROM B WHERE Id=1) WHERE EXISTS ( SELECT MAIN.Id1 FROM MAIN WHERE MAIN.Id = A.Id1); sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF114698 - SqlSrv.EXE::!SQL Server Insert/Update Error. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF114698 sl@0: */ sl@0: void DEF114698() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: (void)RSqlDatabase::Delete(KTestDatabase2); sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: sl@0: TInt err = TheDb.Create(KTestDatabase5); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER, Id1 INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L("INSERT INTO A(Id,Id1) VALUES(2,3)")); sl@0: TEST2(err, 1); sl@0: TheDb.Close(); sl@0: sl@0: err = TheDb.Create(KTestDatabase2); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L("CREATE TABLE B(Id INTEGER, Id1 INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L("INSERT INTO B(Id,Id1) VALUES(2,3)")); sl@0: TEST2(err, 1); sl@0: TheDb.Close(); sl@0: sl@0: err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L("CREATE TABLE MAIN(Id INTEGER, Id1 INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L("INSERT INTO MAIN(Id,Id1) VALUES(2,3)")); sl@0: TEST2(err, 1); sl@0: sl@0: err = TheDb.Attach(KTestDatabase2, _L("db2")); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Attach(KTestDatabase5, _L("db3")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = TheDb.Exec(_L("INSERT INTO B SELECT * FROM B UNION ALL SELECT * FROM MAIN WHERE exists (select * FROM B WHERE B.Id = MAIN.Id)")); sl@0: TEST2(err, 2); sl@0: err = TheDb.Exec(_L("UPDATE A SET Id= (SELECT Id1 FROM B WHERE Id=1) WHERE EXISTS ( SELECT MAIN.Id1 FROM MAIN WHERE MAIN.Id = A.Id1)")); sl@0: TEST2(err, 0); sl@0: sl@0: err = TheDb.Detach(_L("db3")); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Detach(_L("db2")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase5); sl@0: (void)RSqlDatabase::Delete(KTestDatabase2); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4009-0001 sl@0: @SYMTestCaseDesc Test for DEF115556 SqlSrv.EXE::!SQL Server when preparing complex sql query. sl@0: The test does the following steps: sl@0: 1) Create a database with two tables sl@0: CREATE TABLE A(Id INTEGER, Id1 INTEGER, F2 BLOB) sl@0: CREATE TABLE B(Id INTEGER, Id1 INTEGER, F2 BLOB) sl@0: 2) Prepare the following statement sl@0: DELETE FROM A WHERE Id1 IN (SELECT Id1 FROM B WHERE Id IN (1,11) UNION SELECT * FROM B WHERE Id1=2 ORDER BY Id ASC LIMIT 1) sl@0: If the defect is not fixed, step (2) asserts in SQLITE. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF115556 SqlSrv.EXE::!SQL Server when preparing complex sql query. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF115556 sl@0: */ sl@0: void DEF115556() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: TInt err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER, Id1 INTEGER, F2 BLOB)")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L("CREATE TABLE B(Id INTEGER, Id1 INTEGER, F2 BLOB)")); sl@0: TEST(err >= 0); sl@0: sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, _L("DELETE FROM A WHERE Id1 IN (SELECT Id1 FROM B WHERE Id IN (1,11) UNION SELECT * FROM B WHERE Id1=2 ORDER BY Id ASC LIMIT 1)")); sl@0: TEST(err != KErrDied); sl@0: TPtrC errDescr = TheDb.LastErrorMessage(); sl@0: RDebug::Print(_L("\"Stmt prepare\" %d error. Message:\"%S\"\r\n"), err, &errDescr); sl@0: stmt.Close(); sl@0: sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4012 sl@0: @SYMTestCaseDesc Test for DEF115954: CSession Code = 2 executing SQL stmt in OOM loop. sl@0: It is an OOM test. In the loop, the test does the following steps: sl@0: 1) Create a database. sl@0: 2) Set heap failure. sl@0: 3) Open the database sl@0: 4) Execute the statement which caused the panic before this defect is fixed. sl@0: 5) Close the database. sl@0: sl@0: If the defect is not fixed, step (5) will panic with CSession Code = 2. sl@0: sl@0: Note: It's possible for database operations to be performed even after memory sl@0: allocation has failed. This is because SQLITE reuses some pages of the page sl@0: cache which have been allocated but are curently not in use. This means it is sl@0: necessary to undo any operations on the database and continue checking for sl@0: memory and resource leaks even after an operation has been completed successfully sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF115954: CSession Code = 2 executing SQL stmt in OOM loop. sl@0: @SYMTestExpectedResults Test program must not panic. sl@0: @SYMDEF DEF115954 sl@0: */ sl@0: void DEF115954() sl@0: { sl@0: TInt err = KErrNone; sl@0: TInt failingAllocationNo = 0; sl@0: TInt allocationNo = 0; sl@0: TheTest.Printf(_L("\r\n")); sl@0: while(allocationNo < KDEF115954MaxAllocLimit) sl@0: { sl@0: TheTest.Printf(_L("%d \r"), allocationNo); sl@0: RSqlDatabase::Delete(KTestDatabase1); sl@0: err = TheDb.Create(KTestDatabase1); sl@0: TEST(err == KErrNone); sl@0: TheDb.Close(); sl@0: sl@0: const TInt KDelayedDbHeapFailureMask = 0x1000; sl@0: TSqlResourceTester::SetDbHeapFailure(KDelayedDbHeapFailureMask, ++allocationNo); sl@0: sl@0: err = TheDb.Open(KTestDatabase1); sl@0: TEST(err == KErrNone); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE node(id INTEGER PRIMARY KEY,name TEXT);CREATE INDEX node_idx ON node(name);CREATE TABLE edge(orig INTEGER REFERENCES node,dest INTEGER REFERENCES node,PRIMARY KEY(orig, dest));CREATE INDEX edge_idx ON edge(dest,orig)")); sl@0: TheDb.Close(); sl@0: if(err != KErrNoMemory) sl@0: { sl@0: TEST2(err, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: failingAllocationNo = allocationNo; sl@0: } sl@0: sl@0: TSqlResourceTester::SetDbHeapFailure(RHeap::ENone, 0); sl@0: } sl@0: TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo); sl@0: TEST(err == KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4008 sl@0: @SYMTestCaseDesc Test for DEF115567 - Critical SQLite defect that can cause database corruption during UPDATE/DELETE. sl@0: The test creates 2 tables with couple of records and a "BEFORE DELETE" trigger on the first table. sl@0: Then the test deletes 1 record from the first table and checks the record count in both tables. sl@0: In both cases the record count should not be 0. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Test for DEF115567 - Critical SQLite defect that can cause database corruption during UPDATE/DELETE. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF115567 sl@0: */ sl@0: void DEF115567L() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: TInt err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L("CREATE TABLE t3(a INTEGER, b INTEGER);CREATE TABLE t4(a INTEGER, b INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L("CREATE TRIGGER t3_t BEFORE DELETE ON t3 BEGIN DELETE FROM t4 WHERE t4.a = old.a;DELETE FROM t3 WHERE a = 2;END")); sl@0: TEST(err >= 0); sl@0: err = TheDb.Exec(_L("INSERT INTO t3 VALUES(1,1)")); sl@0: TEST2(err, 1); sl@0: err = TheDb.Exec(_L("INSERT INTO t3 VALUES(2,2)")); sl@0: TEST2(err, 1); sl@0: err = TheDb.Exec(_L("INSERT INTO t3 VALUES(3,3)")); sl@0: TEST2(err, 1); sl@0: err = TheDb.Exec(_L("INSERT INTO t4 VALUES(1,1)")); sl@0: TEST2(err, 1); sl@0: err = TheDb.Exec(_L("INSERT INTO t4 VALUES(3,3)")); sl@0: TEST2(err, 1); sl@0: err = TheDb.Exec(_L("DELETE FROM t3 WHERE a=1 OR a=2")); sl@0: TEST2(err, 1); sl@0: TSqlScalarFullSelectQuery query(TheDb); sl@0: TInt rowcnt = query.SelectIntL(_L("SELECT COUNT(*) FROM t3")); sl@0: TEST2(rowcnt, 1); sl@0: rowcnt = query.SelectIntL(_L("SELECT COUNT(*) FROM t4")); sl@0: TEST2(rowcnt, 1); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-4019 sl@0: @SYMTestCaseDesc Test for DEF116397 Attaching a non-db file should return KSqlErrNotDb rather than KErrEof sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Test for DEF116397 - SQL, Attaching database returns KErrEof(-25). sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF116397 sl@0: */ sl@0: void DEF116397() sl@0: { sl@0: //Test error code opening a corrupt db file sl@0: TInt err = TheDb.Open(KCorruptDb); sl@0: TEST2(err, KSqlErrNotDb); sl@0: TheDb.Close(); sl@0: sl@0: //create a sql db file sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: err = TheDb.Exec(_L("CREATE TABLE t3(a INTEGER, b INTEGER);CREATE TABLE t4(a INTEGER, b INTEGER)")); sl@0: TEST(err >= 0); sl@0: TheDb.Close(); sl@0: sl@0: //open the db file sl@0: err=TheDb.Open(KTestDatabase1); sl@0: TEST2(err,KErrNone); sl@0: sl@0: //try to attach a non db file sl@0: err=TheDb.Attach(KCorruptDb,_L("db2")); sl@0: TEST2(err,KSqlErrNotDb); sl@0: sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4029 sl@0: @SYMTestCaseDesc Test for DEF119403 - creates a databse, retrieves its Collation Dll Name and makes sl@0: sure the Collation Dll Name doesn't contain the path sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Test for DEF119403 Database re-index unnecessarily during open operation sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF119403 sl@0: */ sl@0: void DEF119403L() sl@0: { sl@0: //create a sql db file sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: TInt err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TFileName buf; sl@0: TSqlScalarFullSelectQuery query(TheDb); sl@0: //Get Collation Dll Name from SYMBIAN_SETTINGS sl@0: err = query.SelectTextL(_L8("SELECT CollationDllName FROM SYMBIAN_SETTINGS"), buf); sl@0: TEST2(err, KErrNone); sl@0: TParse parse; sl@0: parse.Set(buf, NULL, NULL); sl@0: sl@0: //Check that the Collation Dll Name doesn't include the path sl@0: TEST(!parse.PathPresent()); sl@0: sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: sl@0: } sl@0: sl@0: // Helper function for DEF120237L() sl@0: TInt ExecuteSelect(RSqlDatabase& aDatabase, const TDesC8& aSelectStatement) sl@0: { sl@0: RSqlStatement statement; sl@0: sl@0: TInt err = statement.Prepare(aDatabase, aSelectStatement); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TInt ret; sl@0: TInt count = 0; sl@0: TheTest.Printf(_L("Results:\n")); sl@0: while((ret = statement.Next()) == KSqlAtRow) sl@0: { sl@0: TPtrC coltext; sl@0: err = statement.ColumnText(0, coltext); sl@0: TEST2(err, KErrNone); sl@0: sl@0: RDebug::RawPrint(coltext); sl@0: TheTest.Printf(_L("\n")); sl@0: count++; sl@0: } sl@0: TEST2(ret, KSqlAtEnd); sl@0: sl@0: statement.Close(); sl@0: return count; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-4031 sl@0: @SYMTestCaseDesc Test for DEF120237 - Checks that When using SELECT together with sl@0: the LIKE operator the right number of results are returned. sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions 1) Create a database and fill it with test data. sl@0: 2) Execute a SELECT statement with the LIKE operator and the % wildcard sl@0: 3) Check that the expected number of results are returned. sl@0: @SYMTestExpectedResults The SELECT statements should return the expected number of results. sl@0: @SYMDEF DEF120237 sl@0: */ sl@0: void DEF120237L() sl@0: { sl@0: const TInt KSelectTest1ExpectedResults = 3; sl@0: const TInt KSelectTest2ExpectedResults = 3; sl@0: sl@0: _LIT8(KCfgStr, "encoding=UTF-8"); sl@0: _LIT8(KCreate, "CREATE TABLE A(Id INTEGER,Name TEXT collate nocase)"); //Adding "collate nocase" allows us to see defect sl@0: _LIT8(KIndex, "CREATE INDEX name_index on A (name)"); //Adding index allows us to see defect sl@0: sl@0: _LIT8(KRecord1, "INSERT INTO A VALUES(1, '\"AAA')"); sl@0: _LIT8(KRecord2, "INSERT INTO A VALUES(2, '\"AAB')"); sl@0: _LIT8(KRecord3, "INSERT INTO A VALUES(3, '\"AAC')"); sl@0: _LIT8(KRecord4, "INSERT INTO A VALUES(4, '&BAA')"); sl@0: _LIT8(KRecord5, "INSERT INTO A VALUES(5, '%BAA')"); sl@0: _LIT8(KRecord6, "INSERT INTO A VALUES(6, '''BAA')"); sl@0: _LIT8(KRecord7, "INSERT INTO A VALUES(7, '''BAB')"); sl@0: _LIT8(KRecord8, "INSERT INTO A VALUES(8, '''BAC')"); sl@0: sl@0: //Create database sl@0: RSqlDatabase database; sl@0: CleanupClosePushL(database); sl@0: sl@0: (void*)database.Delete(KTestDatabase6); sl@0: User::LeaveIfError(database.Create(KTestDatabase6, &KCfgStr)); sl@0: TInt err = database.Exec(KCreate); sl@0: TEST(err >= KErrNone); sl@0: sl@0: err = database.Exec(KIndex); sl@0: TEST(err >= KErrNone); sl@0: sl@0: //Insert Neccessary Data sl@0: err = database.Exec(KRecord1); sl@0: TEST2(err, 1); sl@0: err = database.Exec(KRecord2); sl@0: TEST2(err, 1); sl@0: err = database.Exec(KRecord3); sl@0: TEST2(err, 1); sl@0: err = database.Exec(KRecord4); sl@0: TEST2(err, 1); sl@0: err = database.Exec(KRecord5); sl@0: TEST2(err, 1); sl@0: err = database.Exec(KRecord6); sl@0: TEST2(err, 1); sl@0: err = database.Exec(KRecord7); sl@0: TEST2(err, 1); sl@0: err = database.Exec(KRecord8); sl@0: TEST2(err, 1); sl@0: sl@0: //Case 1 when search criteria is " sl@0: //Defect: Select does not return result sl@0: _LIT8(KSelectTest1, "select name from A where name like '\"%'"); sl@0: TInt numResults = ExecuteSelect(database, KSelectTest1); sl@0: TheTest.Printf(_L("Case 1 Results: %d\n"), numResults); sl@0: TEST2(numResults, KSelectTest1ExpectedResults); sl@0: sl@0: //Case 2 when search criteria is ' sl@0: //Defect: Select returns data beginning with & and % as well sl@0: _LIT8(KSelectTest2,"select name from A where name like '''%'"); sl@0: numResults = ExecuteSelect(database, KSelectTest2); sl@0: TheTest.Printf(_L("Case 2 Results: %d\n"), numResults); sl@0: TEST2(numResults, KSelectTest2ExpectedResults); sl@0: sl@0: CleanupStack::PopAndDestroy(1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-CT-4120 sl@0: @SYMTestCaseDesc Test for DEF125881 - Checks that when a INSERT statement is executed sl@0: under a I/O failure simulation, the correct error code will be returned sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions 1) Create a database and fill it with test data. sl@0: 2) Execute a INSERT statement under a I/O failure simulation sl@0: 3) Check that the expected return error code is retruned sl@0: @SYMTestExpectedResults The INSERT statement should return the correct error code under I/O failure sl@0: @SYMDEF DEF125881 sl@0: */ sl@0: void DEF125881L() sl@0: { sl@0: _LIT(KDbPath, "c:\\t_sqldefect-def125881.db"); sl@0: _LIT(KSchema, "CREATE TABLE test(t TEXT);"); sl@0: _LIT(KInsert, "INSERT INTO test (t) VALUES (\'mkldfmklmklmkldfmkldfmklm\ sl@0: klcdmklmkldsdklfjwoierthj\ sl@0: iofnkjwefniwenfwenfjiowen\ sl@0: mkldfmklmklmkldfmkldfmklm\ sl@0: klcdmklmkldsdklfjwoierthj\ sl@0: mkldfmklmklmkldfmkldfmklm\ sl@0: klcdmklmkldsdklfjwoierthj\ sl@0: iofnkjwefniwenfwenfjiowen\ sl@0: mkldfmklmklmkldfmkldfmklm\ sl@0: klcdmklmkldsdklfjwoierthj\ sl@0: iofnkjwefniwenfwenfjiowen\ sl@0: mkldfmklmklmkldfmkldfmklm\ sl@0: klcdmklmkldsdklfjwoierthj\ sl@0: iofnkjwefniwenfwenfjiowen\ sl@0: iofnkjwefniwenfwenfjiowen\ sl@0: fiwenfwejnfwinsdf2sdf4sdf\');"); sl@0: sl@0: _LIT(KLogFormat, "After %d operations: %d returned\n"); sl@0: sl@0: // Create file server session sl@0: RFs fsSession; sl@0: CleanupClosePushL(fsSession); sl@0: User::LeaveIfError(fsSession.Connect()); sl@0: sl@0: // Open a SQL DB, setup basic schema sl@0: RSqlDatabase sqlDb; sl@0: CleanupClosePushL(sqlDb); sl@0: sl@0: TRAPD(createErr, sqlDb.OpenL(KDbPath)); sl@0: if (createErr != KErrNone) sl@0: { sl@0: sqlDb.CreateL(KDbPath); sl@0: User::LeaveIfError(sqlDb.Exec(KSchema)); sl@0: } sl@0: sl@0: // Create a SQL statement sl@0: RSqlStatement stmnt; sl@0: TInt err = stmnt.Prepare(sqlDb, KInsert); sl@0: TEST2(err,KErrNone); sl@0: sl@0: // Begin test sl@0: TInt fsError = KErrGeneral; sl@0: TInt count = 0; sl@0: sl@0: const TInt KMaxOps = 300; sl@0: sl@0: TSqlResourceProfiler pr(sqlDb); sl@0: pr.Start(TSqlResourceProfiler::ESqlCounterOsCallDetails); sl@0: pr.Reset(TSqlResourceProfiler::ESqlCounterOsCallDetails); sl@0: sl@0: while (fsError != 1 && count <= KMaxOps) sl@0: { sl@0: // Setup for KErrGeneral failure sl@0: fsSession.SetErrorCondition(KErrGeneral, count); sl@0: sl@0: // Database operation sl@0: fsError = stmnt.Exec(); sl@0: stmnt.Reset(); sl@0: sl@0: // Test for KErrGeneral sl@0: TheTest.Printf(KLogFormat, count, fsError); sl@0: TEST( (fsError == KErrGeneral) || (fsError == 1) || (fsError == KSqlErrIO)); sl@0: sl@0: // Increment fail-after count sl@0: ++count; sl@0: } sl@0: fsSession.SetErrorCondition(KErrNone); sl@0: pr.Stop(TSqlResourceProfiler::ESqlCounterOsCallDetails); sl@0: stmnt.Close(); sl@0: CleanupStack::PopAndDestroy(2); // fsSession, sqlDb sl@0: (void)RSqlDatabase::Delete(KDbPath); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-CT-4128 sl@0: @SYMTestCaseDesc Test for DEF129581: All Pragmas are allowed to be executed on non-secure SQL databases. sl@0: When executing a pragma which deosn't return any results (e.g performing "PRAGMA index_list" sl@0: on a table with no index. The client panics when RSqlStatement::Next() is called. sl@0: This test checks the client does not panic in this case sl@0: @SYMTestPriority High sl@0: @SYMTestActions DEF129581: All Pragmas are allowed to be executed on non-secure SQL databases sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF129581 sl@0: */ sl@0: void DEF129581() sl@0: { sl@0: _LIT8(KPragma, "Pragma index_list(T)"); sl@0: _LIT8(KCreateTable, "CREATE TABLE T (A INTEGER)"); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: sl@0: //create a sql db file and make sure no index is added to it sl@0: TInt err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //create a table sl@0: err = TheDb.Exec(KCreateTable); sl@0: TEST(err >= KErrNone); sl@0: sl@0: RSqlStatement stmt; sl@0: sl@0: //Executes a "Pragam index_list.." statement sl@0: err = stmt.Prepare(TheDb, KPragma); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //Calls RSqlStatement::Next() to make sure the client does not panic. sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtEnd); sl@0: sl@0: stmt.Close(); sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-CT-4153 sl@0: @SYMTestCaseDesc Test for DEF143047: SQL, default "max parameter count" value, compatibility problem. sl@0: This test case proves that an SQL statement with more than 1000 parameters can be prepared sl@0: successfully. The default value of the SQLITE_MAX_VARIABLE_NUMBER macro is 999. sl@0: Changed to 32767 with this defect fix. sl@0: @SYMTestPriority High sl@0: @SYMTestActions DEF143047: SQL, default "max parameter count" value, compatibility problem sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF143047 sl@0: */ sl@0: void DEF143047() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase1); sl@0: sl@0: TInt err = TheDb.Create(KTestDatabase1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: _LIT8(KCreateTable, "CREATE TABLE T(A INTEGER)"); sl@0: err = TheDb.Exec(KCreateTable); sl@0: TEST(err >= KErrNone); sl@0: sl@0: const TInt KPrmCount = 1200; sl@0: HBufC8* buf = HBufC8::New(KPrmCount * 2 + 200); sl@0: TEST(buf != NULL); sl@0: TPtr8 sql = buf->Des(); sl@0: sql.Copy(_L8("SELECT * FROM T WHERE A IN(?")); sl@0: for(TInt i=0;i 20 characters) column type sl@0: names results in a USER 11 panic. sl@0: This test should pass because these are valid SQL column types sl@0: */ sl@0: void LongColumnTypeTest() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: TInt err = TheDb.Create(KTestDatabase3); sl@0: TEST2(err, KErrNone); sl@0: sl@0: _LIT8(KCreateStmt, "CREATE TABLE t(a CHARACTER VARYING(100000), b NCHAR VARYING(100000), c NATIONAL CHARACTER(100000), d NATIONAL CHARACTER VARYING(100000))"); sl@0: err = TheDb.Exec(KCreateStmt); sl@0: TEST(err >= 0); sl@0: sl@0: //Select all columns (SELECT *) sl@0: _LIT(KSelectStmt, "SELECT * FROM t"); sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, KSelectStmt); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TSqlColumnType colType; sl@0: err = stmt.DeclaredColumnType(0, colType); sl@0: TEST2(err,KErrNone); sl@0: TEST2(colType, ESqlText); sl@0: sl@0: err = stmt.DeclaredColumnType(1, colType); sl@0: TEST2(err,KErrNone); sl@0: TEST2(colType, ESqlText); sl@0: sl@0: err = stmt.DeclaredColumnType(2, colType); sl@0: TEST2(err,KErrNone); sl@0: TEST2(colType, ESqlText); sl@0: sl@0: err = stmt.DeclaredColumnType(3, colType); sl@0: TEST2(err,KErrNone); sl@0: TEST2(colType, ESqlText); sl@0: sl@0: stmt.Close(); sl@0: sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDatabase3); sl@0: } sl@0: sl@0: void DoTestsL() sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1763 \"SQL against a detached db\" test ")); sl@0: SqlDetachedDbTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4034 Corrupted db file (file length too short)")); sl@0: CorruptDbFileTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4035 Attempt to attach a file which name cannot be parsed")); sl@0: AttachBadDbFileNameTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4036 Attempt to attach a secure database. The client cannot pass the security checks")); sl@0: AttachSecureDbTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4032 INC091579 - SQL Panic 7 when streaming BLOB fields")); sl@0: INC091579L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4033 INC091580 - SQL returns bogus pointer when too much text in field...")); sl@0: INC091580L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1815 Testing KSqlErrFull error code ")); sl@0: SqlErrFullTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1816-0001 INC094870 - [SQL] Database became corrupted and cannot be opened ")); sl@0: INC094870L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1817-0001 INC095412: [SQL] Retrieving query results may corrupt heap ")); sl@0: INC095412(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3427 DEF104242 - The SQL server fails to open database with default security policy only ")); sl@0: DEF104242(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3430 DEF104437 - RSqlStatement::Next() panics the SQL server with KERN-EXEC 3 ")); sl@0: DEF104437(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3442 DEF105259 - SQL, RSqlColumnReadStream's internal buffer may become invalid ")); sl@0: DEF105259L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3470 DEF105681 - SQL, HReadOnlyBuf::ConstructL() sets a pointer to a local TPtr8 variable ")); sl@0: DEF105681L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3476 DEF106391 SQL server does not deallocate the already allocated memory ")); sl@0: DEF106391(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3501 DEF109025 SQL, dangling long binary/text column value pointer ")); sl@0: DEF109025(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3546 DEF109843 SQL, RSQLStatement::BindBinary() is causing panic if empty descriptor is passed ")); sl@0: DEF109843(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4005 DEF114698: SqlSrv.EXE::!SQL Server Insert/Update Error ")); sl@0: DEF114698(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4008 DEF115567 Critical SQLite defect that can cause database corruption during UPDATE/DELETE ")); sl@0: DEF115567L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4009-0001 DEF115556: SqlSrv.EXE::!SQL Server when preparing complex sql query ")); sl@0: DEF115556(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4012 DEF115954: CSession Code = 2 executing SQL stmt in OOM loop ")); sl@0: DEF115954(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4019 DEF116397: SQL, Attaching database returns KErrEof(-25) ")); sl@0: DEF116397(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4029 DEF119403: Database re-index unnecessarily during open operation")); sl@0: DEF119403L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4031 DEF120237: SQL, SQLITE3.3.17, \"collate nocase\", wrong results.")); sl@0: DEF120237L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4120 DEF125881: RSqlDatabase::Exec() returns KErrAlreadyExists in I/O failure use cases.")); sl@0: DEF125881L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4128 DEF129581: All Pragmas are allowed to be executed on non-secure SQL databases.")); sl@0: DEF129581(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4153 DEF143047: SQL, default \"max parameter count\" value, compatibility problem.")); sl@0: DEF143047(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4157 PDEF143461 : CSqlSrvDatabase::LastErrorMessage() alignment problem")); sl@0: PDEF143461L(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4166 DEF144027: SQL Open returns error if the reported and actual file size are different")); sl@0: DEF144027(); sl@0: sl@0: TheTest.Next(_L("RSQLStatement::DeclaredColumnType() causes USER 11 panic when table contains long column type strings")); sl@0: LongColumnTypeTest(); sl@0: 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: CreateTestEnv(); sl@0: DeleteTestFiles(); sl@0: TInt err = RSqlDatabase::Copy(KCorruptDbZ, KCorruptDb); sl@0: TEST2(err, KErrNone); sl@0: TRAP(err, DoTestsL()); sl@0: DeleteTestFiles(); sl@0: TheFs.SetErrorCondition(KErrNone); sl@0: TheFs.Close(); 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: }