os/persistentdata/persistentstorage/sql/TEST/t_sqldefect.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sql/TEST/t_sqldefect.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1798 @@
     1.4 +// Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +// NTT DOCOMO, INC - Fix for Bug 1915 "SQL server panics when using long column type strings"
    1.16 +//
    1.17 +// Description:
    1.18 +//
    1.19 +
    1.20 +#include <e32test.h>
    1.21 +#include <bautils.h>
    1.22 +#include <s32stor.h>
    1.23 +#include <sqldb.h>
    1.24 +#include "SqlResourceProfiler.h"
    1.25 +#include "SqlResourceTester.h"
    1.26 +
    1.27 +///////////////////////////////////////////////////////////////////////////////////////
    1.28 +
    1.29 +static RFs TheFs;
    1.30 +RTest TheTest(_L("t_sqldefect test"));
    1.31 +RSqlDatabase TheDb;
    1.32 +
    1.33 +_LIT(KTestDir, "c:\\test\\");
    1.34 +_LIT(KTestDatabase1, "c:\\test\\t_sqldefect_1.db");
    1.35 +_LIT(KTestDatabase2, "c:\\test\\t_sqldefect_2.db");
    1.36 +_LIT(KCorruptDb, "c:\\test\\t_SqlShortNonDb.db");
    1.37 +_LIT(KCorruptDbZ, "z:\\test\\t_SqlShortNonDb.db");	//Created outside this test app
    1.38 +_LIT(KSecureTestDb1, "c:[21212122]BBDb2.db");		//Created outside this test app
    1.39 +_LIT(KTestDatabase3, "c:\\test\\t_sqldefect_3.db");
    1.40 +_LIT(KTestDatabase4, "z:\\test\\t_inc095412.db");	//Created outside this test app
    1.41 +_LIT(KTestDatabase5, "c:\\test\\t_sqldefect_5.db");
    1.42 +_LIT(KTestDatabase6, "c:\\test\\t_def120237.db");
    1.43 +_LIT(KTestDatabase7, "c:\\test\\t_def144027.db");
    1.44 +_LIT(KTestDatabase7Journal, "c:\\test\\t_def144027.db-journal");
    1.45 +
    1.46 +// This value has been found by performing the OOM test
    1.47 +// with an allocation limit of 2000 and then taking a value
    1.48 +// which is just above the allocation failure rate.
    1.49 +const TInt KDEF115954MaxAllocLimit = 1300;
    1.50 +
    1.51 +///////////////////////////////////////////////////////////////////////////////////////
    1.52 +
    1.53 +//Deletes all created test files.
    1.54 +void DeleteTestFiles()
    1.55 +	{
    1.56 +	TheDb.Close();
    1.57 +	(void)TheFs.Delete(KTestDatabase7Journal);
    1.58 +	(void)RSqlDatabase::Delete(KTestDatabase7);
    1.59 +	(void)RSqlDatabase::Delete(KTestDatabase6);
    1.60 +	(void)RSqlDatabase::Delete(KTestDatabase5);
    1.61 +	(void)RSqlDatabase::Delete(KTestDatabase3);
    1.62 +	(void)RSqlDatabase::Delete(KTestDatabase2);
    1.63 +	(void)RSqlDatabase::Delete(KTestDatabase1);
    1.64 +	(void)RSqlDatabase::Delete(KCorruptDb);
    1.65 +	}
    1.66 +
    1.67 +///////////////////////////////////////////////////////////////////////////////////////
    1.68 +///////////////////////////////////////////////////////////////////////////////////////
    1.69 +//Test macros and functions
    1.70 +void Check1(TInt aValue, TInt aLine)
    1.71 +	{
    1.72 +	if(!aValue)
    1.73 +		{
    1.74 +		DeleteTestFiles();
    1.75 +		RDebug::Print(_L("*** Line %d\r\n"), aLine);
    1.76 +		TheTest(EFalse, aLine);
    1.77 +		}
    1.78 +	}
    1.79 +void Check2(TInt aValue, TInt aExpected, TInt aLine)
    1.80 +	{
    1.81 +	if(aValue != aExpected)
    1.82 +		{
    1.83 +		DeleteTestFiles();
    1.84 +		RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
    1.85 +		TheTest(EFalse, aLine);
    1.86 +		}
    1.87 +	}
    1.88 +#define TEST(arg) ::Check1((arg), __LINE__)
    1.89 +#define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
    1.90 +
    1.91 +///////////////////////////////////////////////////////////////////////////////////////
    1.92 +
    1.93 +//Creates file session instance and the test directory
    1.94 +void CreateTestEnv()
    1.95 +    {
    1.96 +	TInt err = TheFs.Connect();
    1.97 +	TEST2(err, KErrNone);
    1.98 +
    1.99 +	err = TheFs.MkDir(KTestDir);
   1.100 +	TEST(err == KErrNone || err == KErrAlreadyExists);
   1.101 +	}
   1.102 +
   1.103 +/**
   1.104 +@SYMTestCaseID			SYSLIB-SQL-CT-1763
   1.105 +@SYMTestCaseDesc		The test creates database 1 and attaches database 2.
   1.106 +					    Then the test prepares a SELECT sql statement which is supposed to
   1.107 +					    retrieve records from the attached database 2. Then the test tries to detach
   1.108 +					    database 2. The expectation is that the detaching operation must fail.
   1.109 +					    The database can be detached only when there are no alive sql statements prepared on it.
   1.110 +@SYMTestPriority		High
   1.111 +@SYMTestActions			SQL, "Detach database" test.
   1.112 +@SYMTestExpectedResults Test must not fail
   1.113 +@SYMREQ					REQ5792
   1.114 +                        REQ5793
   1.115 +*/	
   1.116 +void SqlDetachedDbTest()
   1.117 +	{
   1.118 +	TInt err = TheDb.Create(KTestDatabase1);
   1.119 +	TEST2(err, KErrNone);
   1.120 +	err = TheDb.Exec(_L8("CREATE TABLE A(Id INTEGER)"));	
   1.121 +	TEST(err >= 0);
   1.122 +	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(1)"));	
   1.123 +	TEST2(err, 1);
   1.124 +	TheDb.Close();	
   1.125 +
   1.126 +	err = TheDb.Create(KTestDatabase2);
   1.127 +	TEST2(err, KErrNone);
   1.128 +	err = TheDb.Exec(_L8("CREATE TABLE B(N INTEGER)"));	
   1.129 +	TEST(err >= 0);
   1.130 +	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(10)"));	
   1.131 +	TEST2(err, 1);
   1.132 +	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(20)"));	
   1.133 +	TEST2(err, 1);
   1.134 +	TheDb.Close();	
   1.135 +
   1.136 +	err = TheDb.Open(KTestDatabase1);
   1.137 +	TEST2(err, KErrNone);
   1.138 +	err = TheDb.Attach(KTestDatabase2, _L("Db2"));
   1.139 +	TEST2(err, KErrNone);
   1.140 +	
   1.141 +	RSqlStatement stmt;
   1.142 +	err = stmt.Prepare(TheDb, _L8("SELECT * FROM B"));
   1.143 +	TEST2(err, KErrNone);
   1.144 +	err = stmt.Next();
   1.145 +	TEST2(err, KSqlAtRow);
   1.146 +	
   1.147 +	err = TheDb.Detach(_L("Db2"));
   1.148 +	TEST(err != KErrNone);
   1.149 +	TPtrC errMsg = TheDb.LastErrorMessage();
   1.150 +	RDebug::Print(_L("Detach err: %S\r\n"), &errMsg);
   1.151 +
   1.152 +	err = stmt.Next();
   1.153 +	TEST2(err, KSqlAtRow);
   1.154 +	stmt.Close();
   1.155 +
   1.156 +	err = TheDb.Detach(_L("Db2"));
   1.157 +	TEST2(err, KErrNone);
   1.158 +	
   1.159 +	TheDb.Close();
   1.160 +	(void)RSqlDatabase::Delete(KTestDatabase2);
   1.161 +	(void)RSqlDatabase::Delete(KTestDatabase1);
   1.162 +	}
   1.163 +
   1.164 +/**
   1.165 +@SYMTestCaseID			SYSLIB-SQL-UT-4034
   1.166 +@SYMTestCaseDesc		Corrupted database test.
   1.167 +						The test tries to open a corrupted database file which length is too short.
   1.168 +						The 'database open' operation is expected to fail with KSqlErrNotDb error.
   1.169 +@SYMTestPriority		High
   1.170 +@SYMTestActions			Corrupted database test.
   1.171 +@SYMTestExpectedResults Test must not fail
   1.172 +@SYMREQ					REQ5792
   1.173 +*/
   1.174 +void CorruptDbFileTest()
   1.175 +	{
   1.176 +	TInt err = TheDb.Open(KCorruptDb);
   1.177 +	TEST2(err, KSqlErrNotDb);
   1.178 +	}
   1.179 +
   1.180 +/**
   1.181 +@SYMTestCaseID			SYSLIB-SQL-UT-4035
   1.182 +@SYMTestCaseDesc		Attach database with bad name.
   1.183 +						Attempt to attach a file which name cannot be parsed.
   1.184 +						The 'attach database' operation is expected to fail with KErrBadName error.
   1.185 +@SYMTestPriority		High
   1.186 +@SYMTestActions			Attach database with bad name.
   1.187 +@SYMTestExpectedResults Test must not fail
   1.188 +@SYMREQ					REQ5792
   1.189 +*/
   1.190 +void AttachBadDbFileNameTest()
   1.191 +	{
   1.192 +	TInt err = TheDb.Create(KTestDatabase1);
   1.193 +	TEST2(err, KErrNone);
   1.194 +	err = TheDb.Attach(_L("\"c:\\test\\d12345678.db\""), _L("Db10"));
   1.195 +	TEST2(err, KErrBadName);
   1.196 +	TheDb.Close();
   1.197 +	(void)RSqlDatabase::Delete(KTestDatabase1);
   1.198 +	}
   1.199 +
   1.200 +/**
   1.201 +@SYMTestCaseID			SYSLIB-SQL-UT-4036
   1.202 +@SYMTestCaseDesc		Attach secure database. The client cannot pass the security checks.
   1.203 +						Attempt to attach a secure database. The client cannot pass the security checks.
   1.204 +						The 'attach database' operation is expected to fail with KErrPermissionDenied error.
   1.205 +@SYMTestPriority		High
   1.206 +@SYMTestActions			Attach secure database. The client cannot pass the security checks.
   1.207 +@SYMTestExpectedResults Test must not fail
   1.208 +@SYMREQ					REQ5794
   1.209 +*/
   1.210 +void AttachSecureDbTest()
   1.211 +	{
   1.212 +	TInt err = TheDb.Create(KTestDatabase1);
   1.213 +	TEST2(err, KErrNone);
   1.214 +	err = TheDb.Attach(KSecureTestDb1, _L("Db10"));
   1.215 +	TEST2(err, KErrPermissionDenied);
   1.216 +	TheDb.Close();
   1.217 +	(void)RSqlDatabase::Delete(KTestDatabase1);
   1.218 +	}
   1.219 +
   1.220 +/**
   1.221 +@SYMTestCaseID			SYSLIB-SQL-UT-4032
   1.222 +@SYMTestCaseDesc		Test for defect INC091579 - SQL Panic 7 when streaming BLOB fields.
   1.223 +						The test creates a database with a table with a BLOB column. Then inserts
   1.224 +						a record. Then the test makes an attempt to read the BLOB column using a stream - 
   1.225 +						RSqlColumnReadStream. If the defect is not fixed, the code will panic.
   1.226 +@SYMTestPriority		High
   1.227 +@SYMTestActions			Test for defect INC091579 - SQL Panic 7 when streaming BLOB fields.
   1.228 +@SYMTestExpectedResults Test must not fail
   1.229 +@SYMDEF					INC091579
   1.230 +*/
   1.231 +void INC091579L()
   1.232 +	{
   1.233 +	//Create test database
   1.234 +	TInt err = TheDb.Create(KTestDatabase3);
   1.235 +	TEST2(err, KErrNone);
   1.236 +	_LIT8(KCreateStmt, "CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB)"); 
   1.237 +	err = TheDb.Exec(KCreateStmt);
   1.238 +	TEST(err >= 0);
   1.239 +	//Insert 1 row, using a binary stream
   1.240 +	_LIT8(KInsertStmt, "INSERT INTO A(Fld1,Fld2) VALUES(:p1,:p2)"); 
   1.241 +	RSqlStatement stmt; 
   1.242 +	err = stmt.Prepare(TheDb, KInsertStmt);
   1.243 +	TEST2(err, KErrNone);
   1.244 +	err = stmt.BindInt(0, 1);
   1.245 +	TEST2(err, KErrNone);
   1.246 +
   1.247 +	RSqlParamWriteStream out;
   1.248 +	err = out.BindBinary(stmt, 1);
   1.249 +	TEST2(err, KErrNone);
   1.250 +	
   1.251 +	const TInt KDataSize = 100;
   1.252 +	TUint16 columnData[KDataSize];
   1.253 +	for(TInt i=0;i<KDataSize;i++)
   1.254 +		{
   1.255 +		columnData[i] = (TUint16)i;
   1.256 +		}
   1.257 +		
   1.258 +	out.WriteL(columnData, KDataSize);
   1.259 +	out.CommitL();
   1.260 +	err = stmt.Exec();
   1.261 +	TEST2(err, 1);
   1.262 +	
   1.263 +	out.Close();
   1.264 +	stmt.Close();
   1.265 +
   1.266 +	//Try to read the inserted row, using a binary stream
   1.267 +	_LIT8(KSelectStmt, "SELECT * FROM A WHERE Fld1=1"); 
   1.268 +	err = stmt.Prepare(TheDb, KSelectStmt);
   1.269 +	TEST2(err, KErrNone);
   1.270 +	err = stmt.Next();
   1.271 +	TEST2(err, KSqlAtRow);
   1.272 +
   1.273 +	RSqlColumnReadStream in;
   1.274 +	TInt idx = stmt.ColumnIndex(_L("Fld2"));
   1.275 +	TInt type = stmt.ColumnType(idx);
   1.276 +	TInt size = stmt.ColumnSize(idx);
   1.277 +	err = in.ColumnBinary(stmt,idx); // panic occurs here, if the defect is not fixed
   1.278 +	TEST2(err, KErrNone);
   1.279 +	in.Close();
   1.280 +	
   1.281 +	//Cleanup
   1.282 +	stmt.Close();
   1.283 +	TheDb.Close();
   1.284 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.285 +	}
   1.286 +
   1.287 +/**
   1.288 +@SYMTestCaseID			SYSLIB-SQL-UT-4033
   1.289 +@SYMTestCaseDesc		Test for defect INC091580 - SQL returns bogus pointer when too much text in field.
   1.290 +						The test creates a database with a table with 2 TEXT columns. Then inserts
   1.291 +						a record using a prepared statement with parameters. 
   1.292 +						The second text column value is set twice calling RSqlStatement::BindText().
   1.293 +						Then the test makes an attempt to read the TEXT columns using a SELECT statement - 
   1.294 +						RSqlStatement. If the defect is not fixed, the RSqlStatement::ColumnText() returns a 
   1.295 +						bad value for the first TEXT column.
   1.296 +@SYMTestPriority		High
   1.297 +@SYMTestActions			Test for defect INC091580 - SQL returns bogus pointer when too much text in field.
   1.298 +@SYMTestExpectedResults Test must not fail
   1.299 +@SYMDEF					INC091580
   1.300 +*/
   1.301 +void INC091580L()
   1.302 +	{
   1.303 +	_LIT8(KCreateStmt, "CREATE TABLE A(Fld1 INTEGER, Fld2 TEXT, Fld3 TEXT)"); 
   1.304 +	TInt err = TheDb.Create(KTestDatabase3); 
   1.305 +	TEST2(err, KErrNone);
   1.306 +	err = TheDb.Exec(KCreateStmt);
   1.307 +	TEST(err >= 0);
   1.308 +
   1.309 +	_LIT8(KInsertStmt,"INSERT INTO A(Fld1,Fld2,Fld3) VALUES(1,:p1,:p2)"); 
   1.310 +	RSqlStatement stmt; 
   1.311 +	err = stmt.Prepare(TheDb, KInsertStmt); 
   1.312 +	TEST2(err, KErrNone);
   1.313 +	err = stmt.BindText(0, _L("AAA"));// "AAA" assigned to p1 parameter
   1.314 +	TEST2(err, KErrNone);
   1.315 +
   1.316 +	err = stmt.BindText(1,_L("123456789ABCD"));//"123456789ABCD" assigned to p2 parameter (Fld2 column)
   1.317 +	TEST2(err, KErrNone);
   1.318 +	err = stmt.BindText(1, _L("123456789ABCDE"));//"123456789ABCDE" assigned to p2 parameter (Fld3 column)
   1.319 +	TEST2(err, KErrNone);
   1.320 +	err = stmt.Exec();
   1.321 +	TEST(err >= 0);
   1.322 +	
   1.323 +	stmt.Close();
   1.324 +
   1.325 +	_LIT8(KSelectStmt,"SELECT * FROM A WHERE Fld1=1"); 
   1.326 +	err = stmt.Prepare(TheDb, KSelectStmt); 
   1.327 +	TEST2(err, KErrNone);
   1.328 +	err = stmt.Next();
   1.329 +	TEST2(err, KSqlAtRow);
   1.330 +
   1.331 +	TPtrC fld2 = stmt.ColumnTextL(1); // returns bad value if the defect is not fixed
   1.332 +	TPtrC fld3 = stmt.ColumnTextL(2);
   1.333 +
   1.334 +	TEST(fld2 == _L("AAA"));
   1.335 +	TEST(fld3 == _L("123456789ABCDE"));
   1.336 +	
   1.337 +	//Cleanup
   1.338 +	stmt.Close();
   1.339 +	TheDb.Close();
   1.340 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.341 +	}
   1.342 +
   1.343 +/**
   1.344 +@SYMTestCaseID			SYSLIB-SQL-CT-1815
   1.345 +@SYMTestCaseDesc		KSqlErrFull test.
   1.346 +						Create a test database with a table, which first column is declared as
   1.347 +						"INTEGER PRIMARY KEY AUTOINCREMENT".
   1.348 +						Insert one record into the table, initializing the ROWID with 0x7FFFFFFFFFFFFFFF
   1.349 +						(KMaxTInt64). Try to insert one more record into the table. The operation must
   1.350 +						fails with KSqlErrDiskFull.
   1.351 +@SYMTestPriority		High
   1.352 +@SYMTestActions			Verifying that SQL server returns KSqlErrFull when there are no more available row ids.
   1.353 +@SYMTestExpectedResults Test must not fail
   1.354 +@SYMREQ					REQ5792
   1.355 +                        REQ5793
   1.356 +*/
   1.357 +void SqlErrFullTest()
   1.358 +	{
   1.359 +	TInt err = TheDb.Create(KTestDatabase1);
   1.360 +	TEST2(err, KErrNone);
   1.361 +	err = TheDb.Exec(_L8("CREATE TABLE A(Id INTEGER PRIMARY KEY AUTOINCREMENT, T TEXT)"));
   1.362 +	TEST(err >= 0);
   1.363 +	
   1.364 +	TBuf8<100> sql;
   1.365 +	
   1.366 +	sql.Copy(_L8("INSERT INTO A(ROWID,T) VALUES("));
   1.367 +	sql.AppendNum(KMaxTInt64);
   1.368 +	sql.Append(_L8(", 'TTT')"));
   1.369 +	err = TheDb.Exec(sql);
   1.370 +	TEST(err >= 0);
   1.371 +	
   1.372 +	err = TheDb.Exec(_L8("INSERT INTO A(T) VALUES('UUU')"));
   1.373 +	TEST2(err, KSqlErrFull);
   1.374 +	
   1.375 +	RSqlStatement stmt;
   1.376 +	err = stmt.Prepare(TheDb, _L8("SELECT ROWID FROM A"));
   1.377 +	TEST2(err, KErrNone);
   1.378 +	err = stmt.Next();
   1.379 +	TEST2(err, KSqlAtRow);
   1.380 +	TInt64 val = stmt.ColumnInt64(0);
   1.381 +	TEST(val == KMaxTInt64);
   1.382 +	err = stmt.Next();
   1.383 +	TEST2(err, KSqlAtEnd);
   1.384 +	stmt.Close();
   1.385 +	
   1.386 +	TheDb.Close();
   1.387 +	(void)RSqlDatabase::Delete(KTestDatabase1);
   1.388 +	}
   1.389 +
   1.390 +/**
   1.391 +@SYMTestCaseID			SYSLIB-SQL-CT-1816-0001
   1.392 +@SYMTestCaseDesc		Test for defect INC094870 - Database became corrupted and cannot be opened.
   1.393 +						Case 1: Create a test database and set the database encoding to be UTF-8. Create a table.
   1.394 +						Close and open again the database. "Database open" operation should not panic.
   1.395 +						Case 2: Create a test database and set the database encoding to be UTF-8. Open two 
   1.396 +						connections to the database and check the encoding. It should be UTF-8.
   1.397 +@SYMTestPriority		High
   1.398 +@SYMTestActions			Test for defect INC094870 - Database became corrupted and cannot be opened.
   1.399 +@SYMTestExpectedResults Test must not fail
   1.400 +@SYMDEF					INC094870
   1.401 +*/
   1.402 +void INC094870L()
   1.403 +	{
   1.404 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.405 +	//Test 1 - with a single database
   1.406 +	TInt err = TheDb.Create(KTestDatabase3);
   1.407 +	TEST2(err, KErrNone);
   1.408 +	err = TheDb.Exec(_L8("PRAGMA cache_size=1000"));
   1.409 +	TEST(err >= 0);
   1.410 +    err = TheDb.SetIsolationLevel(RSqlDatabase::EReadUncommitted);
   1.411 +	TEST(err >= 0);
   1.412 +    err = TheDb.Exec(_L8("PRAGMA encoding = \"UTF-8\";"));
   1.413 +	TEST(err >= 0);
   1.414 +    err = TheDb.Exec(_L8("PRAGMA case_sensitive_like = 0"));
   1.415 +	TEST(err >= 0);
   1.416 +    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));"));
   1.417 +	TEST(err >= 0);
   1.418 +	//Close and reopen the database. The Open() call should not fail.
   1.419 +    TheDb.Close();
   1.420 +    err  = TheDb.Open(KTestDatabase3); // This call fails if the defect is not fixed
   1.421 +	TEST2(err, KErrNone);
   1.422 +    TheDb.Close();
   1.423 +	//Test 2 - with two database connections
   1.424 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.425 +	_LIT8(KEncoding, "encoding=UTF-8");
   1.426 +	_LIT(KUtf8, "UTF-8");
   1.427 +	RSqlDatabase db1, db2;
   1.428 +	//Connection 1: Create a database with default encoding UTF-8.
   1.429 +	err = db1.Create(KTestDatabase3, &KEncoding);
   1.430 +	TEST2(err, KErrNone);
   1.431 +	TBuf<100> buf;
   1.432 +	//Connection 1: Check the database encoding
   1.433 +	TSqlScalarFullSelectQuery query(db1);
   1.434 +	err = query.SelectTextL(_L8("PRAGMA encoding"), buf);
   1.435 +	TEST2(err, KErrNone);
   1.436 +	TEST(buf.Find(KUtf8) >= 0);
   1.437 +	//Connection 1: Create a table
   1.438 +	err = db1.Exec(_L8("CREATE TABLE Tbl(Id INTEGER, T BLOB)"));
   1.439 +	TEST(err >= 0);
   1.440 +	//Connection 1: Check the database encoding
   1.441 +	err = query.SelectTextL(_L8("PRAGMA encoding"), buf);
   1.442 +	TEST2(err, KErrNone);
   1.443 +	TEST(buf.Find(KUtf8) >= 0);
   1.444 +	//Connection 2: open the same database
   1.445 +	err = db2.Open(KTestDatabase3);
   1.446 +	TEST2(err, KErrNone);
   1.447 +	//Connection 1: Check the database encoding
   1.448 +	err = query.SelectTextL(_L8("PRAGMA encoding"), buf);
   1.449 +	TEST2(err, KErrNone);
   1.450 +	TEST(buf.Find(KUtf8) >= 0);
   1.451 +	//Connection 2: Check the database encoding
   1.452 +	query.SetDatabase(db2);
   1.453 +	err = query.SelectTextL(_L8("PRAGMA encoding"), buf);
   1.454 +	TEST2(err, KErrNone);
   1.455 +	TEST(buf.Find(KUtf8) >= 0);
   1.456 +	//Cleanup
   1.457 +	db2.Close();
   1.458 +	db1.Close();
   1.459 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.460 +	}
   1.461 +
   1.462 +/**
   1.463 +@SYMTestCaseID			SYSLIB-SQL-CT-1817-0001
   1.464 +@SYMTestCaseDesc		Test for defect INC095412 - Retrieving query results may corrupt heap.
   1.465 +						Open t_inc095412.db test database and prepare SQL query (the SQL statement is in the test code). 
   1.466 +						Execute RSqlStatement::Next() and then try to retrieve the text value of column number 1.
   1.467 +						If the defect is not fixed RSqlStatement::ColumnText() will panic.
   1.468 +@SYMTestPriority		High
   1.469 +@SYMTestActions			Test for defect INC095412 - Retrieving query results may corrupt heap.
   1.470 +@SYMTestExpectedResults Test must not fail
   1.471 +@SYMDEF					INC095412
   1.472 +*/
   1.473 +void INC095412()
   1.474 +	{
   1.475 +    TInt err = TheDb.Open(KTestDatabase4);
   1.476 +    TEST2(err, KErrNone);
   1.477 +    RSqlStatement stmt;
   1.478 +    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  ( ? , ? , ? , ?  )  )  );"));
   1.479 +    TEST2(err, KErrNone);
   1.480 +    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};
   1.481 +    for(TInt i=0;i<sizeof(KPrmValues)/sizeof(KPrmValues[0]);++i)
   1.482 +    	{
   1.483 +    	err = stmt.BindInt(i, KPrmValues[i]);
   1.484 +    	TEST2(err, KErrNone);
   1.485 +    	}
   1.486 +    err = stmt.Next();
   1.487 +    TEST2(err, KSqlAtRow);
   1.488 +    TPtrC ptr;
   1.489 +    stmt.ColumnText(1, ptr); // May corrupt heap and panic the test application if the defect is not fixed!
   1.490 +    stmt.Close();
   1.491 +    TheDb.Close();
   1.492 +	}
   1.493 +	
   1.494 +/**
   1.495 +@SYMTestCaseID			SYSLIB-SQL-UT-3427
   1.496 +@SYMTestCaseDesc		Test for DEF104242 - The SQL server fails to open database with default security policy only.
   1.497 +						The test plays with C:[21212125]T_OneDefPolicy.db secure database, which was created by
   1.498 +						an external tool and the database security policy table contains just a single record
   1.499 +						with the default security policy. The default security policy is set to be 
   1.500 +						TSecurityPolicy::EAlwaysPass. The test attempts to read from the database, modify the database
   1.501 +						content, modify the database schema.
   1.502 +@SYMTestPriority		High
   1.503 +@SYMTestActions			Test for DEF104242 - The SQL server fails to open database with default security policy only.
   1.504 +@SYMTestExpectedResults Test must not fail
   1.505 +@SYMDEF					DEF104242
   1.506 +*/
   1.507 +void DEF104242()
   1.508 +	{
   1.509 +	TInt err = TheDb.Open(_L("C:[21212125]T_OneDefPolicy.db"));
   1.510 +	TEST2(err, KErrNone);
   1.511 +	//Read
   1.512 +	RSqlStatement stmt;
   1.513 +	err = stmt.Prepare(TheDb, _L("SELECT t1key, data from t1"));
   1.514 +	TEST2(err, KErrNone);
   1.515 +	while((err = stmt.Next()) == KSqlAtRow)
   1.516 +		{
   1.517 +		TheTest.Printf(_L("t1key=%d\r\n"), stmt.ColumnInt(0));
   1.518 +		}
   1.519 +	TEST2(err, KSqlAtEnd);
   1.520 +	stmt.Close();
   1.521 +	//Write
   1.522 +	err = TheDb.Exec(_L("INSERT INTO t1(t1key) VALUES(12)"));
   1.523 +	TEST2(err, 1);
   1.524 +	//Schema
   1.525 +	err = TheDb.Exec(_L("CREATE TABLE AAA(Id INTEGER)"));
   1.526 +	TEST(err >= 0);
   1.527 +	//Cleanup
   1.528 +	TheDb.Close();
   1.529 +	}
   1.530 +	
   1.531 +/**
   1.532 +@SYMTestCaseID			SYSLIB-SQL-UT-3430
   1.533 +@SYMTestCaseDesc		Test for DEF104437 - RSqlStatement::Next() panics the SQL server with KERN-EXEC 3.
   1.534 +						The test attempts to execute 2 SELECT queries ("IN" and "IN + JOIN"). The table, on
   1.535 +						which queries operate, has multi-column primary key. The right-hand side of the 
   1.536 +						"IN" operator contains NULL.
   1.537 +@SYMTestPriority		High
   1.538 +@SYMTestActions			Test for DEF104437 - RSqlStatement::Next() panics the SQL server with KERN-EXEC 3.
   1.539 +@SYMTestExpectedResults Test must not fail
   1.540 +@SYMDEF					DEF104437
   1.541 +*/
   1.542 +void DEF104437()
   1.543 +	{
   1.544 +	//Test case 1 - "IN" + "JOIN"
   1.545 +	(void)RSqlDatabase::Delete(KTestDatabase5);
   1.546 +	TInt err = TheDb.Create(KTestDatabase5);
   1.547 +	TEST2(err, KErrNone);
   1.548 +	err = TheDb.Exec(_L("CREATE TABLE inmk(cls TEXT,sec INTEGER,inst INTEGER)"));
   1.549 +	TEST(err >= 0);
   1.550 +	err = TheDb.Exec(_L("INSERT INTO inmk VALUES ('ORD', 2751, 2750)"));
   1.551 +	TEST2(err, 1);
   1.552 +	err = TheDb.Exec(_L("CREATE TABLE clss(hrar TEXT,cls TEXT,PRIMARY KEY (hrar, cls))"));
   1.553 +	TEST(err >= 0);
   1.554 +	err = TheDb.Exec(_L("CREATE TABLE rels(prnt_inst INTEGER,chld_inst INTEGER)"));
   1.555 +	TEST(err >= 0);
   1.556 +	RSqlStatement stmt;
   1.557 +	_LIT(KSelectSql,
   1.558 +	"SELECT I.sec\
   1.559 +	  FROM inmk I\
   1.560 +	   LEFT JOIN\
   1.561 +	     rels R ON R.prnt_inst = I.inst\
   1.562 +	   LEFT JOIN\
   1.563 +	      inmk UI ON UI.inst = R.chld_inst\
   1.564 +	   LEFT JOIN\
   1.565 +	     clss C1U ON C1U.cls = UI.cls AND C1U.hrar = 'STH'\
   1.566 +	   LEFT JOIN\
   1.567 +	     clss C10U ON C10U.hrar = c1u.hrar AND C10U.cls IN (C1U.cls)\
   1.568 +	  WHERE I.sec = 2751;");
   1.569 +	err = stmt.Prepare(TheDb, KSelectSql);
   1.570 +	TEST2(err, KErrNone);
   1.571 +	while((err = stmt.Next()) == KSqlAtRow)
   1.572 +		{
   1.573 +		TInt val = stmt.ColumnInt(0);
   1.574 +		TEST2(val, 2751);
   1.575 +		TheTest.Printf(_L("column value=%d\r\n"), val);
   1.576 +		}
   1.577 +	TEST2(err, KSqlAtEnd);
   1.578 +	stmt.Close();
   1.579 +	TheDb.Close();
   1.580 +	//////////////////////////////////////////////////////////////
   1.581 +	//Test case 2 - "IN"
   1.582 +	(void)RSqlDatabase::Delete(KTestDatabase5);
   1.583 +	err = TheDb.Create(KTestDatabase5);
   1.584 +	TEST2(err, KErrNone);
   1.585 +	err = TheDb.Exec(_L("CREATE TABLE b(y,z,PRIMARY KEY(y, z))"));
   1.586 +	TEST(err >= 0);
   1.587 +	err = stmt.Prepare(TheDb, _L("SELECT * FROM b WHERE y = NULL AND z IN ('hello')"));
   1.588 +	TEST2(err, KErrNone);
   1.589 +	while((err = stmt.Next()) == KSqlAtRow)
   1.590 +		{
   1.591 +		}
   1.592 +	TEST2(err, KSqlAtEnd);
   1.593 +	stmt.Close();
   1.594 +	TheDb.Close();
   1.595 +	(void)RSqlDatabase::Delete(KTestDatabase5);
   1.596 +	}
   1.597 +
   1.598 +/**
   1.599 +@SYMTestCaseID			SYSLIB-SQL-UT-3442
   1.600 +@SYMTestCaseDesc		Test for DEF105259 - SQL, RSqlColumnReadStream's internal buffer may become invalid.
   1.601 +						The test does the following steps:
   1.602 +						1) Create a table: CREATE TABLE A(Name TEXT, Data BLOB);
   1.603 +						2) Insert only one record in A, such that, the "Name" column length is less than 
   1.604 +						   8 characters, the "Data" column length is 1K bytes.
   1.605 +						3) Create RSqlStatement object with the following SQL statement: SELECT * FROM A
   1.606 +						4) Call RSqlStatement::Next() to get the record
   1.607 +						5) Create RSqlColumnReadStream for column 0 (the "Name" column)
   1.608 +						6) Try to access the "Data" column value, without using a stream
   1.609 +						7) Try to read the "Name" column using the stream
   1.610 +						8) Compare the read "Name" column value vs. the original column value (at the moment 
   1.611 +						   when the table record was stored)
   1.612 +@SYMTestPriority		High
   1.613 +@SYMTestActions			Test for DEF105259 - SQL, RSqlColumnReadStream's internal buffer may become invalid.
   1.614 +@SYMTestExpectedResults Test must not fail
   1.615 +@SYMDEF					DEF105259
   1.616 +*/
   1.617 +void DEF105259L()
   1.618 +	{
   1.619 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.620 +	TInt err = TheDb.Create(KTestDatabase3);
   1.621 +	TEST2(err, KErrNone);
   1.622 +	
   1.623 +	err = TheDb.Exec(_L("CREATE TABLE A(Name TEXT, Data BLOB)"));
   1.624 +	TEST(err >= 0);
   1.625 +	
   1.626 +	const TInt KBlobDataSize = 1024;
   1.627 +	HBufC* recBuf = HBufC::New(KBlobDataSize * 2 + 100);
   1.628 +	TEST(recBuf != NULL);
   1.629 +	TPtr sql = recBuf->Des();
   1.630 +	sql.Copy(_L("INSERT INTO A(Name,Data) VALUES('A12',x'"));
   1.631 +	for(TInt i=0;i<KBlobDataSize;++i)
   1.632 +		{
   1.633 +		TBuf<2> tmp;
   1.634 +		tmp.AppendFormat(_L("%02X"), i % 256);
   1.635 +		sql.Append(tmp);
   1.636 +		}
   1.637 +	sql.Append(_L("')"));
   1.638 +	
   1.639 +	err = TheDb.Exec(sql);
   1.640 +	TEST2(err, 1);
   1.641 +
   1.642 +	delete recBuf;
   1.643 +	
   1.644 +	RSqlStatement stmt;
   1.645 +	err = stmt.Prepare(TheDb, _L("SELECT * FROM A"));
   1.646 +	TEST2(err, KErrNone);
   1.647 +	
   1.648 +	err = stmt.Next();
   1.649 +	TEST2(err, KSqlAtRow);
   1.650 +	
   1.651 +	RSqlColumnReadStream strm;
   1.652 +	err = strm.ColumnText(stmt, 0);
   1.653 +	TEST2(err, KErrNone);
   1.654 +	
   1.655 +	TPtrC8 data;
   1.656 +	err = stmt.ColumnBinary(1, data);
   1.657 +	TEST2(err, KErrNone);
   1.658 +
   1.659 +	TBuf<10> name;
   1.660 +	strm.ReadL(name, 3);
   1.661 +	TEST(name == _L("A12"));
   1.662 +
   1.663 +	strm.Close();	
   1.664 +	stmt.Close();
   1.665 +	TheDb.Close();
   1.666 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.667 +	}
   1.668 +
   1.669 +/**
   1.670 +@SYMTestCaseID			SYSLIB-SQL-UT-3470
   1.671 +@SYMTestCaseDesc		Test for DEF105681 - SQL, HReadOnlyBuf::ConstructL() sets a pointer to a local TPtr8 variable.
   1.672 +						The test creates a database with a table: A(Name TEXT, Data BLOB). One record is inserted
   1.673 +						in the table. Then the test creates a statement object with "SELECT * FROM A" sql statement.
   1.674 +						The test moves the statement cursor on the record and attempts to access the BLOB column
   1.675 +						using a stream. When the stream object is created, the test attempts to create an embedded
   1.676 +						store object from the stream, using CEmbeddedStore::FromLC(strm) call. If the defect
   1.677 +						is not fixed, the call will panic.
   1.678 +@SYMTestPriority		High
   1.679 +@SYMTestActions			Test for DEF105681 - SQL, HReadOnlyBuf::ConstructL() sets a pointer to a local TPtr8 variable.
   1.680 +@SYMTestExpectedResults Test must not fail
   1.681 +@SYMDEF					DEF105681
   1.682 +*/
   1.683 +void DEF105681L()
   1.684 +	{	
   1.685 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.686 +	TInt err = TheDb.Create(KTestDatabase3);
   1.687 +	TEST2(err, KErrNone);
   1.688 +	
   1.689 +	err = TheDb.Exec(_L("CREATE TABLE A(Name TEXT, Data BLOB)"));
   1.690 +	TEST(err >= 0);
   1.691 +	
   1.692 +	err = TheDb.Exec(_L("INSERT INTO A(Name,Data) VALUES('A12',x'0400000000')"));
   1.693 +	TEST2(err, 1);
   1.694 +	
   1.695 +	RSqlStatement stmt;
   1.696 +	err = stmt.Prepare(TheDb, _L("SELECT * FROM A"));
   1.697 +	TEST2(err, KErrNone);
   1.698 +	
   1.699 +	err = stmt.Next();
   1.700 +	TEST2(err, KSqlAtRow);
   1.701 +
   1.702 +	RSqlColumnReadStream strm;
   1.703 +	err = strm.ColumnBinary(stmt, 1);
   1.704 +	TEST2(err, KErrNone);
   1.705 +	CEmbeddedStore* store = CEmbeddedStore::FromLC(strm);
   1.706 +	CleanupStack::PopAndDestroy(store);
   1.707 +
   1.708 +	strm.Close();	
   1.709 +	stmt.Close();
   1.710 +
   1.711 +	//Testing with a NULL binary column value
   1.712 +	err = TheDb.Exec(_L("INSERT INTO A(Name,Data) VALUES('BBB',NULL)"));
   1.713 +	TEST2(err, 1);
   1.714 +
   1.715 +	err = stmt.Prepare(TheDb, _L("SELECT * FROM A WHERE Name='BBB'"));
   1.716 +	TEST2(err, KErrNone);
   1.717 +	
   1.718 +	err = stmt.Next();
   1.719 +	TEST2(err, KSqlAtRow);
   1.720 +
   1.721 +	err = strm.ColumnBinary(stmt, 1);
   1.722 +	TEST2(err, KErrNone);
   1.723 +	store = NULL;
   1.724 +	TRAP(err, store = CEmbeddedStore::FromL(strm));
   1.725 +	TEST2(err, KErrEof);
   1.726 +	delete store;
   1.727 +
   1.728 +	strm.Close();	
   1.729 +	stmt.Close();
   1.730 +	
   1.731 +	
   1.732 +	TheDb.Close();
   1.733 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.734 +	}
   1.735 +
   1.736 +/**
   1.737 +@SYMTestCaseID			SYSLIB-SQL-UT-3476
   1.738 +@SYMTestCaseDesc		Test for DEF106391 - SQL server does not deallocate the already allocated memory.
   1.739 +						The test is executed only on the Emulator, because its execution depends on the amount
   1.740 +						of the available memory and the amount of free disk space - factors which cannot be easily 
   1.741 +						resolved on target hardware.
   1.742 +						The test creates a database with a table: T(Id INTEGER, Data BLOB). 
   1.743 +						One record with a BLOB (either 0.79Mb or 0.9Mb) is inserted using RSqlDatabase::Exec().
   1.744 +						Another record with a BLOB (either 1.58 or 1.8Mb) is inserted using RSqlStatement and BLOB parameter.
   1.745 +						If the defect is not fixed, after the first INSERT the SQL server will not free occupied by
   1.746 +						the statement memory. The available heap memory won't be enough for the execution of the second INSERT statement.
   1.747 +						The second INSERT will fail with KErrNoMemory.
   1.748 +@SYMTestPriority		High
   1.749 +@SYMTestActions			Test for DEF106391 - SQL server does not deallocate the already allocated memory.
   1.750 +@SYMTestExpectedResults Test must not fail
   1.751 +@SYMDEF					DEF106391
   1.752 +*/
   1.753 +void DEF106391()
   1.754 +	{
   1.755 +#if defined __WINS__ ||	defined __WINSCW__
   1.756 +#ifndef SYMBIAN_USE_SQLITE_VERSION_3_6_4
   1.757 +    const TInt KBlobSize = 900 * 1024;
   1.758 +#else
   1.759 +    const TInt KBlobSize = 790 * 1024;
   1.760 +#endif    
   1.761 +
   1.762 +	_LIT8(KConfigStr, "encoding=UTF-8");
   1.763 +
   1.764 +	HBufC8* sqlBuf = HBufC8::New(KBlobSize * 2 + 200);//"+ 200" - for the SQL INSERT statement
   1.765 +	TEST(sqlBuf != NULL);
   1.766 +
   1.767 +	(void)RSqlDatabase::Delete(KTestDatabase5);
   1.768 +	
   1.769 +	//Step 1: insert a record with a very large BLOB column (using RSqlDatabase::Exec())
   1.770 +	//        (the operation is rolled back because there may not be enough disk space)
   1.771 +	TVolumeInfo volInfo;
   1.772 +	TInt err = TheFs.Volume(volInfo);
   1.773 +	TEST2(err, KErrNone);
   1.774 +	TheTest.Printf(_L("INSERT#1, Volume size: %ldK  Free space: %ldK\r\n"), volInfo.iSize / 1024, volInfo.iFree / 1024);
   1.775 +	TheTest.Printf(_L("Test BLOB size: %dK\r\n"), KBlobSize / 1024);
   1.776 +	
   1.777 +	err = TheDb.Create(KTestDatabase5, &KConfigStr);
   1.778 +	TEST2(err, KErrNone);
   1.779 +	
   1.780 +	TSqlResourceProfiler profiler(TheDb);
   1.781 +	(void)profiler.Start(TSqlResourceProfiler::ESqlCounterMaxAlloc);
   1.782 +	
   1.783 +	err = TheDb.Exec(_L8("CREATE TABLE T(Id INTEGER, Data BLOB)"));
   1.784 +	TEST(err >= 0);
   1.785 +	TPtr8 sql = sqlBuf->Des();
   1.786 +	sql.Copy(_L8("BEGIN TRANSACTION;INSERT INTO T(Id,Data) VALUES(1, x'"));
   1.787 +	for(TInt i=0;i<KBlobSize;++i)
   1.788 +		{
   1.789 +		sql.Append(_L8("A5"));
   1.790 +		}
   1.791 +	sql.Append(_L8("');"));	
   1.792 +	(void)profiler.Reset(TSqlResourceProfiler::ESqlCounterMaxAlloc);
   1.793 +	err = TheDb.Exec(sql);
   1.794 +	TEST2(err, 1);
   1.795 +	err = TheDb.Exec(_L("ROLLBACK TRANSACTION"));
   1.796 +	TEST(err >= 0);
   1.797 +	TBuf8<32> profilerRes8;
   1.798 +	TBuf<32> profilerRes;
   1.799 +	if(profiler.Query(TSqlResourceProfiler::ESqlCounterMaxAlloc, profilerRes8) == KErrNone)
   1.800 +		{
   1.801 +		profilerRes.Copy(profilerRes8);
   1.802 +		TheTest.Printf(_L("RSqlDatabase::Exec(): <SQL server max alloc>;<SQLite max alloc>=%S\r\n"), &profilerRes);
   1.803 +		}
   1.804 +
   1.805 +	//Step 2: insert a record with a very large BLOB column (using RSqlStatement::Exec())
   1.806 +	//        (the operation is rolled back because there may not be enough disk space)
   1.807 +	err = TheFs.Volume(volInfo);
   1.808 +	TEST2(err, KErrNone);
   1.809 +	TheTest.Printf(_L("INSERT#2, Volume size: %ldK  Free space: %ldK\r\n"), volInfo.iSize / 1024, volInfo.iFree / 1024);
   1.810 +	TheTest.Printf(_L("Test BLOB size: %dK\r\n"), sql.Length() / 1024);
   1.811 +	
   1.812 +	(void)profiler.Reset(TSqlResourceProfiler::ESqlCounterMaxAlloc);
   1.813 +	RSqlStatement stmt;
   1.814 +	err = stmt.Prepare(TheDb, _L("INSERT INTO T(Id, Data) VALUES(2, :V)"));
   1.815 +	TEST2(err, KErrNone);
   1.816 +	err = stmt.BindBinary(0, sql);
   1.817 +	TEST2(err, KErrNone);
   1.818 +	err = TheDb.Exec(_L("BEGIN TRANSACTION"));
   1.819 +	TEST(err >= 0);
   1.820 +	err = stmt.Exec();
   1.821 +	TEST2(err, 1);
   1.822 +	err = TheDb.Exec(_L("ROLLBACK TRANSACTION"));
   1.823 +	TEST(err >= 0);
   1.824 +	stmt.Close();
   1.825 +	if(profiler.Query(TSqlResourceProfiler::ESqlCounterMaxAlloc, profilerRes8) == KErrNone)
   1.826 +		{
   1.827 +		profilerRes.Copy(profilerRes8);
   1.828 +		TheTest.Printf(_L("RSqlStatement::Bind/Exec(): <SQL server max alloc>;<SQLite max alloc>=%S\r\n"), &profilerRes);
   1.829 +		}
   1.830 +	
   1.831 +	delete sqlBuf;
   1.832 +
   1.833 +	(void)profiler.Stop(TSqlResourceProfiler::ESqlCounterMaxAlloc);
   1.834 +	TheDb.Close();
   1.835 +	(void)RSqlDatabase::Delete(KTestDatabase5);
   1.836 +#endif// defined __WINS__ || defined __WINSCW__	
   1.837 +	}
   1.838 +
   1.839 +/**
   1.840 +@SYMTestCaseID			SYSLIB-SQL-UT-3501
   1.841 +@SYMTestCaseDesc		Test for DEF109025 - SQL, dangling long binary/text column value pointer
   1.842 +						The test does the following steps:
   1.843 +						1) Create a table: CREATE TABLE A(Name TEXT, Data BLOB);
   1.844 +						2) Insert only one record in A, such that, the "Name" column length is less than 
   1.845 +						   8 characters, the "Data" column length is 1K bytes.
   1.846 +						3) Create RSqlStatement object with the following SQL statement: SELECT * FROM A
   1.847 +						4) Call RSqlStatement::Next() to get the record
   1.848 +						5) Allocate a 1024 bytes buffer (so, when the row buffer has to be reallocated, the system will be forced to 
   1.849 +						   search another block of memory, because the current one is capped by the allocated 1024 bytes)
   1.850 +						6) Get a pointer to the "name" column value
   1.851 +						7) Get a pointer to the "data" column value
   1.852 +						8) Check the "name" column value. If the defect still exists, the "name" pointer will point to a deleted 
   1.853 +						   block of memory.
   1.854 +@SYMTestPriority		High
   1.855 +@SYMTestActions			Test for DEF109025 - SQL, dangling long binary/text column value pointer.
   1.856 +@SYMTestExpectedResults Test must not fail
   1.857 +@SYMDEF					DEF109025
   1.858 +*/
   1.859 +void DEF109025()
   1.860 +	{
   1.861 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.862 +	TInt err = TheDb.Create(KTestDatabase3);
   1.863 +	TEST2(err, KErrNone);
   1.864 +	
   1.865 +	err = TheDb.Exec(_L("CREATE TABLE A(Name TEXT, Data BLOB)"));
   1.866 +	TEST(err >= 0);
   1.867 +	
   1.868 +	const TInt KBlobDataSize = 1024;
   1.869 +	HBufC* recBuf = HBufC::New(KBlobDataSize * 2 + 100);
   1.870 +	TEST(recBuf != NULL);
   1.871 +	TPtr sql = recBuf->Des();
   1.872 +	sql.Copy(_L("INSERT INTO A(Name,Data) VALUES('A12',x'"));
   1.873 +	for(TInt i=0;i<KBlobDataSize;++i)
   1.874 +		{
   1.875 +		TBuf<2> tmp;
   1.876 +		tmp.AppendFormat(_L("%02X"), i % 256);
   1.877 +		sql.Append(tmp);
   1.878 +		}
   1.879 +	sql.Append(_L("')"));
   1.880 +	
   1.881 +	err = TheDb.Exec(sql);
   1.882 +	TEST2(err, 1);
   1.883 +
   1.884 +	delete recBuf;
   1.885 +	
   1.886 +	RSqlStatement stmt;
   1.887 +	err = stmt.Prepare(TheDb, _L("SELECT * FROM A"));
   1.888 +	TEST2(err, KErrNone);
   1.889 +	
   1.890 +	err = stmt.Next();
   1.891 +	TEST2(err, KSqlAtRow);
   1.892 +
   1.893 +	TUint8* mem = new TUint8[1024];	//This memory block will be allocated right after the row buffer,
   1.894 +	TEST(mem != NULL);				//so the ColumnBinary() call will reallocate the row buffer somewhere else, not at the same address.
   1.895 +
   1.896 +	TPtrC name;
   1.897 +	err = stmt.ColumnText(0, name);
   1.898 +	TEST2(err, KErrNone);
   1.899 +	
   1.900 +	TPtrC8 data;
   1.901 +	err = stmt.ColumnBinary(1, data);
   1.902 +	TEST2(err, KErrNone);
   1.903 +
   1.904 +	TEST(name == _L("A12"));
   1.905 +
   1.906 +	delete [] mem;
   1.907 +	stmt.Close();
   1.908 +	TheDb.Close();
   1.909 +	(void)RSqlDatabase::Delete(KTestDatabase3);
   1.910 +	}
   1.911 +
   1.912 +/**
   1.913 +@SYMTestCaseID			SYSLIB-SQL-UT-3546
   1.914 +@SYMTestCaseDesc		Test for DEF109843 - SQL, RSQLStatement::BindBinary() is causing panic if empty descriptor is passed.
   1.915 +						The test does the following steps:
   1.916 +						1) Create a table: CREATE TABLE A(Id INTEGER, Data BLOB);
   1.917 +						2) Create a RSqlStatement object stmt;
   1.918 +						3) Prepare stmt with the following SQL statement:
   1.919 +						INSERT INTO A(Id,Data) VALUES(:Val1,:Val2);
   1.920 +						4) Set the Val2 field with an empty descriptor("") by using RSqlStatement::BindBinary();
   1.921 +						5) Execute the statement;
   1.922 +						6) If the defect still exist, stmt.BindBinary() will cause a panic;
   1.923 +@SYMTestPriority		High
   1.924 +@SYMTestActions			Test for DEF109843 - SQL, RSQLStatement::BindBinary() is causing panic if empty descriptor is passed.
   1.925 +@SYMTestExpectedResults Test must not fail
   1.926 +@SYMDEF					DEF109843
   1.927 +*/
   1.928 +void DEF109843()
   1.929 +	{
   1.930 +	(void)RSqlDatabase::Delete(KTestDatabase5);
   1.931 +	TInt err = TheDb.Create(KTestDatabase5);
   1.932 +	TEST2(err, KErrNone);
   1.933 +	
   1.934 +	err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER, Data BLOB)"));
   1.935 +	TEST(err >= 0);
   1.936 +
   1.937 +	RSqlStatement stmt;
   1.938 +	err = stmt.Prepare(TheDb, _L("INSERT INTO A(Id,Data) VALUES(:Val1,:Val2)"));
   1.939 +	TEST2(err, KErrNone);
   1.940 +	
   1.941 +	TInt paramIndex;
   1.942 +	paramIndex = stmt.ParameterIndex(_L(":Val1"));
   1.943 +	TEST(paramIndex >= 0);
   1.944 +	
   1.945 +	err = stmt.BindInt(paramIndex, 1);
   1.946 +	TEST2(err, KErrNone);
   1.947 +	
   1.948 +	paramIndex = stmt.ParameterIndex(_L(":Val2"));
   1.949 +	TEST(paramIndex >= 0);
   1.950 +	
   1.951 +	TPtrC8 emptyEntry (_L8(""));
   1.952 +	err = stmt.BindBinary(paramIndex, emptyEntry);
   1.953 +	TEST2(err, KErrNone);
   1.954 +	
   1.955 +	err = stmt.Exec();
   1.956 +	TEST(err >= 0);
   1.957 +	
   1.958 +	stmt.Close();
   1.959 +	TheDb.Close();
   1.960 +	(void)RSqlDatabase::Delete(KTestDatabase5);
   1.961 +	}
   1.962 +
   1.963 +/**
   1.964 +@SYMTestCaseID			SYSLIB-SQL-UT-4005
   1.965 +@SYMTestCaseDesc		Test for DEF114698 - SqlSrv.EXE::!SQL Server Insert/Update Error.
   1.966 +						The test does the following steps:
   1.967 +						1) DB3: 
   1.968 +							CREATE TABLE A(Id INTEGER, Id1 INTEGER)
   1.969 +							INSERT INTO A(Id,Id1) VALUES(2,3)
   1.970 +						2) DB2:
   1.971 +							CREATE TABLE B(Id INTEGER, Id1 INTEGER)
   1.972 +							INSERT INTO B(Id,Id1) VALUES(2,3)
   1.973 +						3) DB:
   1.974 +							CREATE TABLE MAIN(Id INTEGER, Id1 INTEGER)
   1.975 +							INSERT INTO MAIN(Id,Id1) VALUES(2,3)
   1.976 +						4) Attach DB2 and DB3 to DB.
   1.977 +						5) Execute:
   1.978 +							INSERT INTO B SELECT * FROM B UNION ALL SELECT * FROM MAIN WHERE exists (select * FROM B WHERE B.Id = MAIN.Id);
   1.979 +							UPDATE A SET Id= (SELECT Id1 FROM B WHERE Id=1) WHERE EXISTS ( SELECT MAIN.Id1 FROM MAIN WHERE MAIN.Id = A.Id1);
   1.980 +@SYMTestPriority		High
   1.981 +@SYMTestActions			Test for DEF114698 - SqlSrv.EXE::!SQL Server Insert/Update Error.
   1.982 +@SYMTestExpectedResults Test must not fail
   1.983 +@SYMDEF					DEF114698
   1.984 +*/
   1.985 +void DEF114698()
   1.986 +	{
   1.987 +	(void)RSqlDatabase::Delete(KTestDatabase1);
   1.988 +	(void)RSqlDatabase::Delete(KTestDatabase2);
   1.989 +	(void)RSqlDatabase::Delete(KTestDatabase5);
   1.990 +	
   1.991 +	TInt err = TheDb.Create(KTestDatabase5);
   1.992 +	TEST2(err, KErrNone);
   1.993 +	err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER, Id1 INTEGER)"));
   1.994 +	TEST(err >= 0);
   1.995 +	err = TheDb.Exec(_L("INSERT INTO A(Id,Id1) VALUES(2,3)"));
   1.996 +	TEST2(err, 1);
   1.997 +	TheDb.Close();
   1.998 +	
   1.999 +	err = TheDb.Create(KTestDatabase2);
  1.1000 +	TEST2(err, KErrNone);
  1.1001 +	err = TheDb.Exec(_L("CREATE TABLE B(Id INTEGER, Id1 INTEGER)"));
  1.1002 +	TEST(err >= 0);
  1.1003 +	err = TheDb.Exec(_L("INSERT INTO B(Id,Id1) VALUES(2,3)"));
  1.1004 +	TEST2(err, 1);
  1.1005 +	TheDb.Close();
  1.1006 +	
  1.1007 +	err = TheDb.Create(KTestDatabase1);
  1.1008 +	TEST2(err, KErrNone);
  1.1009 +	err = TheDb.Exec(_L("CREATE TABLE MAIN(Id INTEGER, Id1 INTEGER)"));
  1.1010 +	TEST(err >= 0);
  1.1011 +	err = TheDb.Exec(_L("INSERT INTO MAIN(Id,Id1) VALUES(2,3)"));
  1.1012 +	TEST2(err, 1);
  1.1013 +	
  1.1014 +	err = TheDb.Attach(KTestDatabase2, _L("db2"));
  1.1015 +	TEST2(err, KErrNone);
  1.1016 +	err = TheDb.Attach(KTestDatabase5, _L("db3"));
  1.1017 +	TEST2(err, KErrNone);
  1.1018 +	
  1.1019 +	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)"));
  1.1020 +	TEST2(err, 2);
  1.1021 +	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)"));
  1.1022 +	TEST2(err, 0);
  1.1023 +
  1.1024 +	err = TheDb.Detach(_L("db3"));
  1.1025 +	TEST2(err, KErrNone);
  1.1026 +	err = TheDb.Detach(_L("db2"));
  1.1027 +	TEST2(err, KErrNone);
  1.1028 +	
  1.1029 +	TheDb.Close();
  1.1030 +	(void)RSqlDatabase::Delete(KTestDatabase5);
  1.1031 +	(void)RSqlDatabase::Delete(KTestDatabase2);
  1.1032 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1033 +	}
  1.1034 +
  1.1035 +/**
  1.1036 +@SYMTestCaseID			SYSLIB-SQL-UT-4009-0001
  1.1037 +@SYMTestCaseDesc		Test for DEF115556 SqlSrv.EXE::!SQL Server when preparing complex sql query.
  1.1038 +						The test does the following steps:
  1.1039 +						1) Create a database with two tables
  1.1040 +							CREATE TABLE A(Id INTEGER, Id1 INTEGER, F2 BLOB)
  1.1041 +							CREATE TABLE B(Id INTEGER, Id1 INTEGER, F2 BLOB)
  1.1042 +						2) Prepare the following statement
  1.1043 +							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)
  1.1044 +						If the defect is not fixed, step (2) asserts in SQLITE.
  1.1045 +@SYMTestPriority		High
  1.1046 +@SYMTestActions			Test for DEF115556 SqlSrv.EXE::!SQL Server when preparing complex sql query.
  1.1047 +@SYMTestExpectedResults Test must not fail
  1.1048 +@SYMDEF					DEF115556
  1.1049 +*/
  1.1050 +void DEF115556()
  1.1051 +	{
  1.1052 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1053 +	TInt err = TheDb.Create(KTestDatabase1);
  1.1054 +	TEST2(err, KErrNone);
  1.1055 +
  1.1056 +	err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER, Id1 INTEGER, F2 BLOB)"));
  1.1057 +	TEST(err >= 0);
  1.1058 +	err = TheDb.Exec(_L("CREATE TABLE B(Id INTEGER, Id1 INTEGER, F2 BLOB)"));
  1.1059 +	TEST(err >= 0);
  1.1060 +
  1.1061 +	RSqlStatement stmt;
  1.1062 +	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)"));
  1.1063 +	TEST(err != KErrDied);
  1.1064 +	TPtrC errDescr = TheDb.LastErrorMessage();
  1.1065 +	RDebug::Print(_L("\"Stmt prepare\" %d error. Message:\"%S\"\r\n"), err, &errDescr);
  1.1066 +	stmt.Close();
  1.1067 +	
  1.1068 +	TheDb.Close();
  1.1069 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1070 +	}
  1.1071 +
  1.1072 +
  1.1073 +/**
  1.1074 +@SYMTestCaseID			SYSLIB-SQL-UT-4012
  1.1075 +@SYMTestCaseDesc		Test for DEF115954: CSession Code = 2 executing SQL stmt in OOM loop.
  1.1076 +						It is an OOM test. In the loop, the test does the following steps:
  1.1077 +						1) Create a database. 
  1.1078 +						2) Set heap failure.
  1.1079 +						3) Open the database
  1.1080 +						4) Execute the statement which caused the panic before this defect is fixed.
  1.1081 +						5) Close the database.
  1.1082 +
  1.1083 +						If the defect is not fixed, step (5) will panic with CSession Code = 2.
  1.1084 +						
  1.1085 +						Note: It's possible for database operations to be performed even after memory
  1.1086 + 						allocation has failed. This is because SQLITE reuses some pages of the page
  1.1087 + 						cache which have been allocated but are curently not in use. This means it is 
  1.1088 + 						necessary to undo any operations on the database and continue checking for
  1.1089 + 						memory and resource leaks even after an operation has been completed successfully
  1.1090 +@SYMTestPriority		High
  1.1091 +@SYMTestActions			Test for DEF115954: CSession Code = 2 executing SQL stmt in OOM loop.
  1.1092 +@SYMTestExpectedResults Test program must not panic.
  1.1093 +@SYMDEF					DEF115954
  1.1094 +*/
  1.1095 +void DEF115954()
  1.1096 +	{
  1.1097 +	TInt err = KErrNone;
  1.1098 +	TInt failingAllocationNo = 0;
  1.1099 +	TInt allocationNo = 0;
  1.1100 +	TheTest.Printf(_L("\r\n"));
  1.1101 +	while(allocationNo < KDEF115954MaxAllocLimit)
  1.1102 + 		{
  1.1103 +		TheTest.Printf(_L("%d    \r"), allocationNo);
  1.1104 +  		RSqlDatabase::Delete(KTestDatabase1);
  1.1105 +  		err = TheDb.Create(KTestDatabase1);
  1.1106 +  		TEST(err == KErrNone);
  1.1107 +  		TheDb.Close(); 
  1.1108 +  		
  1.1109 +  		const TInt KDelayedDbHeapFailureMask = 0x1000;
  1.1110 +  		TSqlResourceTester::SetDbHeapFailure(KDelayedDbHeapFailureMask, ++allocationNo);
  1.1111 +
  1.1112 +  		err = TheDb.Open(KTestDatabase1);
  1.1113 +  		TEST(err == KErrNone);
  1.1114 +
  1.1115 +  		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)"));
  1.1116 +  		TheDb.Close();
  1.1117 +  		if(err != KErrNoMemory)
  1.1118 +			{
  1.1119 +			TEST2(err, KErrNone);	
  1.1120 +			}
  1.1121 +		else
  1.1122 +			{
  1.1123 +			failingAllocationNo = allocationNo;
  1.1124 +			}
  1.1125 +  
  1.1126 +  		TSqlResourceTester::SetDbHeapFailure(RHeap::ENone, 0);
  1.1127 +  		}
  1.1128 +	TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
  1.1129 +	TEST(err == KErrNone);
  1.1130 +	}
  1.1131 +	
  1.1132 +/**
  1.1133 +@SYMTestCaseID			SYSLIB-SQL-UT-4008
  1.1134 +@SYMTestCaseDesc		Test for DEF115567 - Critical SQLite defect that can cause database corruption during UPDATE/DELETE.
  1.1135 +						The test creates 2 tables with couple of records and a "BEFORE DELETE" trigger on the first table.
  1.1136 +						Then the test deletes 1 record from the first table and checks the record count in both tables.
  1.1137 +						In both cases the record count should not be 0.
  1.1138 +@SYMTestPriority		Critical
  1.1139 +@SYMTestActions			Test for DEF115567 - Critical SQLite defect that can cause database corruption during UPDATE/DELETE.
  1.1140 +@SYMTestExpectedResults Test must not fail
  1.1141 +@SYMDEF					DEF115567
  1.1142 +*/
  1.1143 +void DEF115567L()
  1.1144 +	{
  1.1145 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1146 +	TInt err = TheDb.Create(KTestDatabase1);
  1.1147 +	TEST2(err, KErrNone);
  1.1148 +	err = TheDb.Exec(_L("CREATE TABLE t3(a INTEGER, b INTEGER);CREATE TABLE t4(a INTEGER, b INTEGER)"));
  1.1149 +	TEST(err >= 0);
  1.1150 +	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"));
  1.1151 +	TEST(err >= 0);
  1.1152 +	err = TheDb.Exec(_L("INSERT INTO t3 VALUES(1,1)"));
  1.1153 +	TEST2(err, 1);
  1.1154 +	err = TheDb.Exec(_L("INSERT INTO t3 VALUES(2,2)"));
  1.1155 +	TEST2(err, 1);
  1.1156 +	err = TheDb.Exec(_L("INSERT INTO t3 VALUES(3,3)"));
  1.1157 +	TEST2(err, 1);
  1.1158 +	err = TheDb.Exec(_L("INSERT INTO t4 VALUES(1,1)"));
  1.1159 +	TEST2(err, 1);
  1.1160 +	err = TheDb.Exec(_L("INSERT INTO t4 VALUES(3,3)"));
  1.1161 +	TEST2(err, 1);
  1.1162 +	err = TheDb.Exec(_L("DELETE FROM t3 WHERE a=1 OR a=2"));
  1.1163 +	TEST2(err, 1);
  1.1164 +	TSqlScalarFullSelectQuery query(TheDb);
  1.1165 +	TInt rowcnt = query.SelectIntL(_L("SELECT COUNT(*) FROM t3"));
  1.1166 +	TEST2(rowcnt, 1);
  1.1167 +	rowcnt = query.SelectIntL(_L("SELECT COUNT(*) FROM t4"));
  1.1168 +	TEST2(rowcnt, 1);
  1.1169 +	TheDb.Close();
  1.1170 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1171 +	}	
  1.1172 +
  1.1173 +/**
  1.1174 +@SYMTestCaseID			SYSLIB-SQL-CT-4019
  1.1175 +@SYMTestCaseDesc		Test for DEF116397 Attaching a non-db file should return KSqlErrNotDb rather than KErrEof
  1.1176 +@SYMTestPriority		Medium
  1.1177 +@SYMTestActions			Test for DEF116397 - SQL, Attaching database returns KErrEof(-25).
  1.1178 +@SYMTestExpectedResults Test must not fail
  1.1179 +@SYMDEF					DEF116397
  1.1180 +*/
  1.1181 +void DEF116397()
  1.1182 +	{
  1.1183 +	//Test error code opening a corrupt db file
  1.1184 +	TInt err = TheDb.Open(KCorruptDb);
  1.1185 +	TEST2(err, KSqlErrNotDb);
  1.1186 +	TheDb.Close();
  1.1187 +	
  1.1188 +	//create a sql db file
  1.1189 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1190 +	err = TheDb.Create(KTestDatabase1);
  1.1191 +	TEST2(err, KErrNone);
  1.1192 +	err = TheDb.Exec(_L("CREATE TABLE t3(a INTEGER, b INTEGER);CREATE TABLE t4(a INTEGER, b INTEGER)"));
  1.1193 +	TEST(err >= 0);
  1.1194 +	TheDb.Close();
  1.1195 +	
  1.1196 +	//open the db file
  1.1197 +	err=TheDb.Open(KTestDatabase1);
  1.1198 +	TEST2(err,KErrNone);
  1.1199 +	
  1.1200 +	//try to attach a non db file
  1.1201 +	err=TheDb.Attach(KCorruptDb,_L("db2"));
  1.1202 +	TEST2(err,KSqlErrNotDb);
  1.1203 +	
  1.1204 +	TheDb.Close();
  1.1205 +	(void)RSqlDatabase::Delete(KTestDatabase1);			
  1.1206 +	}
  1.1207 +
  1.1208 +/**
  1.1209 +@SYMTestCaseID			SYSLIB-SQL-UT-4029
  1.1210 +@SYMTestCaseDesc		Test for DEF119403 - creates a databse, retrieves its Collation Dll Name and makes 
  1.1211 +						sure the Collation Dll Name doesn't contain the path 
  1.1212 +@SYMTestPriority		Medium
  1.1213 +@SYMTestActions			Test for DEF119403 Database re-index unnecessarily during open operation 
  1.1214 +@SYMTestExpectedResults Test must not fail
  1.1215 +@SYMDEF					DEF119403
  1.1216 +*/
  1.1217 +void DEF119403L()
  1.1218 +	{
  1.1219 +	//create a sql db file
  1.1220 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1221 +	TInt err = TheDb.Create(KTestDatabase1);
  1.1222 +	TEST2(err, KErrNone);
  1.1223 +	
  1.1224 +	TFileName buf;
  1.1225 +	TSqlScalarFullSelectQuery query(TheDb);
  1.1226 +	//Get Collation Dll Name from SYMBIAN_SETTINGS
  1.1227 +	err = query.SelectTextL(_L8("SELECT CollationDllName FROM SYMBIAN_SETTINGS"), buf);
  1.1228 +	TEST2(err, KErrNone);
  1.1229 +	TParse parse;
  1.1230 +	parse.Set(buf, NULL, NULL);
  1.1231 +	
  1.1232 +	//Check that the Collation Dll Name doesn't include the path
  1.1233 +	TEST(!parse.PathPresent());
  1.1234 +	
  1.1235 +	TheDb.Close();
  1.1236 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1237 +
  1.1238 +	}
  1.1239 +
  1.1240 +// Helper function for DEF120237L()
  1.1241 +TInt ExecuteSelect(RSqlDatabase& aDatabase, const TDesC8& aSelectStatement)
  1.1242 +	{
  1.1243 +	RSqlStatement statement;
  1.1244 +
  1.1245 +	TInt err = statement.Prepare(aDatabase, aSelectStatement);
  1.1246 +	TEST2(err, KErrNone);
  1.1247 +	
  1.1248 +	TInt ret;
  1.1249 +	TInt count = 0;
  1.1250 +	TheTest.Printf(_L("Results:\n"));
  1.1251 +	while((ret = statement.Next()) == KSqlAtRow)
  1.1252 +	    {  
  1.1253 +	    TPtrC coltext;
  1.1254 +	    err = statement.ColumnText(0, coltext);
  1.1255 +	    TEST2(err, KErrNone);
  1.1256 +	    
  1.1257 +	    RDebug::RawPrint(coltext);
  1.1258 +	    TheTest.Printf(_L("\n"));
  1.1259 +	    count++;
  1.1260 +	    }
  1.1261 +	TEST2(ret, KSqlAtEnd);
  1.1262 +	
  1.1263 +	statement.Close();	
  1.1264 +	return count;
  1.1265 +	}
  1.1266 +
  1.1267 +/**
  1.1268 +@SYMTestCaseID			SYSLIB-SQL-CT-4031
  1.1269 +@SYMTestCaseDesc		Test for DEF120237 - Checks that When using SELECT together with 
  1.1270 +                        the LIKE operator the right number of results are returned.
  1.1271 +@SYMTestPriority		Medium
  1.1272 +@SYMTestActions			1) Create a database and fill it with test data.
  1.1273 +                        2) Execute a SELECT statement with the LIKE operator and the % wildcard
  1.1274 +                        3) Check that the expected number of results are returned.
  1.1275 +@SYMTestExpectedResults The SELECT statements should return the expected number of results.
  1.1276 +@SYMDEF					DEF120237
  1.1277 +*/
  1.1278 +void DEF120237L()
  1.1279 +	{
  1.1280 +	const TInt KSelectTest1ExpectedResults = 3;
  1.1281 +	const TInt KSelectTest2ExpectedResults = 3;
  1.1282 +	
  1.1283 +	_LIT8(KCfgStr, "encoding=UTF-8");
  1.1284 +	_LIT8(KCreate, "CREATE TABLE A(Id INTEGER,Name TEXT collate nocase)"); //Adding "collate nocase" allows us to see defect
  1.1285 +	_LIT8(KIndex, "CREATE INDEX name_index on A (name)"); //Adding index allows us to see defect
  1.1286 +
  1.1287 +	_LIT8(KRecord1, "INSERT INTO A VALUES(1, '\"AAA')");
  1.1288 +	_LIT8(KRecord2, "INSERT INTO A VALUES(2, '\"AAB')");
  1.1289 +	_LIT8(KRecord3, "INSERT INTO A VALUES(3, '\"AAC')");
  1.1290 +	_LIT8(KRecord4, "INSERT INTO A VALUES(4, '&BAA')");
  1.1291 +	_LIT8(KRecord5, "INSERT INTO A VALUES(5, '%BAA')");
  1.1292 +	_LIT8(KRecord6, "INSERT INTO A VALUES(6, '''BAA')");
  1.1293 +	_LIT8(KRecord7, "INSERT INTO A VALUES(7, '''BAB')");
  1.1294 +	_LIT8(KRecord8, "INSERT INTO A VALUES(8, '''BAC')");
  1.1295 +
  1.1296 +	//Create database
  1.1297 +	RSqlDatabase database;
  1.1298 +	CleanupClosePushL(database);
  1.1299 +	
  1.1300 +	(void*)database.Delete(KTestDatabase6);
  1.1301 +	User::LeaveIfError(database.Create(KTestDatabase6, &KCfgStr));
  1.1302 +	TInt err = database.Exec(KCreate);
  1.1303 +	TEST(err >= KErrNone);
  1.1304 +	
  1.1305 +	err = database.Exec(KIndex);
  1.1306 +	TEST(err >= KErrNone);
  1.1307 +	
  1.1308 +	//Insert Neccessary Data
  1.1309 +	err = database.Exec(KRecord1);
  1.1310 +	TEST2(err, 1);
  1.1311 +	err = database.Exec(KRecord2);
  1.1312 +	TEST2(err, 1);
  1.1313 +	err = database.Exec(KRecord3);
  1.1314 +	TEST2(err, 1);
  1.1315 +	err = database.Exec(KRecord4);
  1.1316 +	TEST2(err, 1);
  1.1317 +	err = database.Exec(KRecord5);
  1.1318 +	TEST2(err, 1);
  1.1319 +	err = database.Exec(KRecord6);
  1.1320 +	TEST2(err, 1);
  1.1321 +	err = database.Exec(KRecord7);
  1.1322 +	TEST2(err, 1);
  1.1323 +	err = database.Exec(KRecord8);
  1.1324 +	TEST2(err, 1);
  1.1325 +
  1.1326 +	//Case 1 when search criteria is "
  1.1327 +	//Defect: Select does not return result
  1.1328 +	_LIT8(KSelectTest1, "select name from A where name like '\"%'");
  1.1329 +	TInt numResults = ExecuteSelect(database, KSelectTest1);
  1.1330 +	TheTest.Printf(_L("Case 1 Results: %d\n"), numResults);
  1.1331 +	TEST2(numResults, KSelectTest1ExpectedResults);
  1.1332 +	
  1.1333 +	//Case 2 when search criteria is '
  1.1334 +	//Defect: Select returns data beginning with & and % as well
  1.1335 +	_LIT8(KSelectTest2,"select name from A where name like '''%'");
  1.1336 +	numResults = ExecuteSelect(database, KSelectTest2);
  1.1337 +	TheTest.Printf(_L("Case 2 Results: %d\n"), numResults);
  1.1338 +	TEST2(numResults, KSelectTest2ExpectedResults);
  1.1339 +
  1.1340 +	CleanupStack::PopAndDestroy(1);
  1.1341 +	}
  1.1342 +
  1.1343 +/**
  1.1344 +@SYMTestCaseID			PDS-SQL-CT-4120
  1.1345 +@SYMTestCaseDesc		Test for DEF125881 - Checks that when a INSERT statement is executed
  1.1346 +						under a I/O failure simulation, the correct error code will be returned
  1.1347 +@SYMTestPriority		Medium
  1.1348 +@SYMTestActions			1) Create a database and fill it with test data.
  1.1349 +                        2) Execute a INSERT statement under a I/O failure simulation
  1.1350 +                        3) Check that the expected return error code is retruned
  1.1351 +@SYMTestExpectedResults The INSERT statement should return the correct error code under I/O failure
  1.1352 +@SYMDEF					DEF125881
  1.1353 +*/
  1.1354 +void DEF125881L()
  1.1355 +	{
  1.1356 +	_LIT(KDbPath, "c:\\t_sqldefect-def125881.db");
  1.1357 +	_LIT(KSchema, "CREATE TABLE test(t TEXT);");
  1.1358 +	_LIT(KInsert, "INSERT INTO test (t) VALUES (\'mkldfmklmklmkldfmkldfmklm\
  1.1359 +												  klcdmklmkldsdklfjwoierthj\
  1.1360 +												  iofnkjwefniwenfwenfjiowen\
  1.1361 +												  mkldfmklmklmkldfmkldfmklm\
  1.1362 +												  klcdmklmkldsdklfjwoierthj\
  1.1363 +												  mkldfmklmklmkldfmkldfmklm\
  1.1364 +												  klcdmklmkldsdklfjwoierthj\
  1.1365 +												  iofnkjwefniwenfwenfjiowen\
  1.1366 +												  mkldfmklmklmkldfmkldfmklm\
  1.1367 +												  klcdmklmkldsdklfjwoierthj\
  1.1368 +												  iofnkjwefniwenfwenfjiowen\
  1.1369 +												  mkldfmklmklmkldfmkldfmklm\
  1.1370 +												  klcdmklmkldsdklfjwoierthj\
  1.1371 +												  iofnkjwefniwenfwenfjiowen\
  1.1372 +												  iofnkjwefniwenfwenfjiowen\
  1.1373 +												  fiwenfwejnfwinsdf2sdf4sdf\');");
  1.1374 +	
  1.1375 +	_LIT(KLogFormat, "After %d operations: %d returned\n");
  1.1376 +	
  1.1377 +	// Create file server session
  1.1378 +	RFs fsSession;
  1.1379 +	CleanupClosePushL(fsSession);
  1.1380 +	User::LeaveIfError(fsSession.Connect());
  1.1381 +	
  1.1382 +	// Open a SQL DB, setup basic schema
  1.1383 +	RSqlDatabase sqlDb;
  1.1384 +	CleanupClosePushL(sqlDb);
  1.1385 +	
  1.1386 +	TRAPD(createErr, sqlDb.OpenL(KDbPath));
  1.1387 +	if (createErr != KErrNone)
  1.1388 +		{
  1.1389 +		sqlDb.CreateL(KDbPath);
  1.1390 +		User::LeaveIfError(sqlDb.Exec(KSchema));
  1.1391 +		}	
  1.1392 +	
  1.1393 +	// Create a SQL statement
  1.1394 +	RSqlStatement stmnt;
  1.1395 +	TInt err = stmnt.Prepare(sqlDb, KInsert);
  1.1396 +	TEST2(err,KErrNone);
  1.1397 +	
  1.1398 +	// Begin test
  1.1399 +	TInt fsError = KErrGeneral;
  1.1400 +	TInt count = 0;
  1.1401 +	
  1.1402 +	const TInt KMaxOps = 300;
  1.1403 +
  1.1404 +	TSqlResourceProfiler pr(sqlDb);
  1.1405 +	pr.Start(TSqlResourceProfiler::ESqlCounterOsCallDetails);
  1.1406 +	pr.Reset(TSqlResourceProfiler::ESqlCounterOsCallDetails);
  1.1407 +	
  1.1408 +	while (fsError != 1 && count <= KMaxOps)
  1.1409 +		{
  1.1410 +		// Setup for KErrGeneral failure
  1.1411 +		fsSession.SetErrorCondition(KErrGeneral, count);
  1.1412 +		
  1.1413 +		// Database operation
  1.1414 +		fsError = stmnt.Exec();
  1.1415 +		stmnt.Reset();
  1.1416 +		
  1.1417 +		// Test for KErrGeneral
  1.1418 +		TheTest.Printf(KLogFormat, count, fsError);
  1.1419 +		TEST( (fsError == KErrGeneral) || (fsError == 1) || (fsError == KSqlErrIO));
  1.1420 +		
  1.1421 +		// Increment fail-after count
  1.1422 +		++count;
  1.1423 +		}
  1.1424 +	fsSession.SetErrorCondition(KErrNone);
  1.1425 +	pr.Stop(TSqlResourceProfiler::ESqlCounterOsCallDetails);
  1.1426 +	stmnt.Close();
  1.1427 +	CleanupStack::PopAndDestroy(2); // fsSession, sqlDb
  1.1428 +	(void)RSqlDatabase::Delete(KDbPath);
  1.1429 +	}
  1.1430 +
  1.1431 +/**
  1.1432 +@SYMTestCaseID			PDS-SQL-CT-4128
  1.1433 +@SYMTestCaseDesc		Test for DEF129581: All Pragmas are allowed to be executed on non-secure SQL databases.
  1.1434 +						When executing a pragma which deosn't return any results (e.g performing "PRAGMA index_list"
  1.1435 +						on a table with no index. The client panics when RSqlStatement::Next() is called. 
  1.1436 +						This test checks the client does not panic in this case
  1.1437 +@SYMTestPriority		High
  1.1438 +@SYMTestActions			DEF129581: All Pragmas are allowed to be executed on non-secure SQL databases
  1.1439 +@SYMTestExpectedResults Test must not fail
  1.1440 +@SYMDEF					DEF129581
  1.1441 +*/
  1.1442 +void DEF129581()
  1.1443 +	{
  1.1444 +	_LIT8(KPragma, "Pragma index_list(T)");
  1.1445 +	_LIT8(KCreateTable, "CREATE TABLE T (A INTEGER)");
  1.1446 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1447 +	
  1.1448 +	//create a sql db file and make sure no index is added to it
  1.1449 +	TInt err = TheDb.Create(KTestDatabase1);
  1.1450 +	TEST2(err, KErrNone);
  1.1451 +
  1.1452 +	//create a table
  1.1453 +	err = TheDb.Exec(KCreateTable);
  1.1454 +	TEST(err >= KErrNone);
  1.1455 +	
  1.1456 +	RSqlStatement stmt;
  1.1457 +	
  1.1458 +	//Executes a "Pragam index_list.." statement
  1.1459 +	err = stmt.Prepare(TheDb, KPragma);
  1.1460 +	TEST2(err, KErrNone);
  1.1461 +	
  1.1462 +	//Calls RSqlStatement::Next() to make sure the client does not panic.
  1.1463 +	err = stmt.Next();
  1.1464 +	TEST2(err, KSqlAtEnd);
  1.1465 +	
  1.1466 +	stmt.Close();
  1.1467 +	TheDb.Close();
  1.1468 +	(void)RSqlDatabase::Delete(KTestDatabase1);
  1.1469 +	}
  1.1470 +
  1.1471 +/**
  1.1472 +@SYMTestCaseID          PDS-SQL-CT-4153
  1.1473 +@SYMTestCaseDesc        Test for DEF143047: SQL, default "max parameter count" value, compatibility problem.
  1.1474 +                        This test case proves that an SQL statement with more than 1000 parameters can be prepared 
  1.1475 +                        successfully. The default value of the SQLITE_MAX_VARIABLE_NUMBER macro is 999. 
  1.1476 +                        Changed to 32767 with this defect fix.
  1.1477 +@SYMTestPriority        High
  1.1478 +@SYMTestActions         DEF143047: SQL, default "max parameter count" value, compatibility problem
  1.1479 +@SYMTestExpectedResults Test must not fail
  1.1480 +@SYMDEF                 DEF143047
  1.1481 +*/
  1.1482 +void DEF143047()
  1.1483 +    {
  1.1484 +    (void)RSqlDatabase::Delete(KTestDatabase1);
  1.1485 +    
  1.1486 +    TInt err = TheDb.Create(KTestDatabase1);
  1.1487 +    TEST2(err, KErrNone);
  1.1488 +
  1.1489 +    _LIT8(KCreateTable, "CREATE TABLE T(A INTEGER)");
  1.1490 +    err = TheDb.Exec(KCreateTable);
  1.1491 +    TEST(err >= KErrNone);
  1.1492 +    
  1.1493 +    const TInt KPrmCount = 1200;
  1.1494 +    HBufC8* buf = HBufC8::New(KPrmCount * 2 + 200);
  1.1495 +    TEST(buf != NULL);
  1.1496 +    TPtr8 sql = buf->Des();
  1.1497 +    sql.Copy(_L8("SELECT * FROM T WHERE A IN(?"));
  1.1498 +    for(TInt i=0;i<KPrmCount;++i)
  1.1499 +        {
  1.1500 +        sql.Append(_L8(",?"));
  1.1501 +        }
  1.1502 +    sql.Append(_L8(")"));
  1.1503 +    
  1.1504 +    RSqlStatement stmt;
  1.1505 +    err = stmt.Prepare(TheDb,sql);
  1.1506 +    if(err != KErrNone)
  1.1507 +        {
  1.1508 +        TPtrC errdes = TheDb.LastErrorMessage();
  1.1509 +        TheTest.Printf(_L("RSqlStatement::Prepare() failed. Err %d, ErrMsg: \"%S\".\r\n"), err, &errdes);
  1.1510 +        }
  1.1511 +    TEST2(err, KErrNone);
  1.1512 +    stmt.Close();
  1.1513 +    
  1.1514 +    delete buf;
  1.1515 +    TheDb.Close();
  1.1516 +    (void)RSqlDatabase::Delete(KTestDatabase1);
  1.1517 +    }
  1.1518 +
  1.1519 +/**
  1.1520 +@SYMTestCaseID          PDS-SQL-UT-4157
  1.1521 +@SYMTestCaseDesc        Test for PDEF143461  Calling CSqlSrvDatabase::LastErrorMessage() does not panic with the descriptor alignment error
  1.1522 +@SYMTestPriority        Normal
  1.1523 +@SYMTestActions         Test for PDEF143461  - CSqlSrvDatabase::LastErrorMessage() alignment problem.
  1.1524 +                        This tests the following SQLite Error messages to make sure it doesn't panic:
  1.1525 +                        1)library routine called out of sequence
  1.1526 +                        2)out of memory
  1.1527 +@SYMTestExpectedResults Test must not fail
  1.1528 +@SYMDEF                 PDEF143461 
  1.1529 +*/
  1.1530 +void PDEF143461L()
  1.1531 +    {
  1.1532 +    (void) RSqlDatabase::Delete(KTestDatabase6);
  1.1533 +    
  1.1534 +    //Create and setup the database file
  1.1535 +    RSqlDatabase db;
  1.1536 +    TInt err =0;
  1.1537 +    err = db.Create(KTestDatabase6);
  1.1538 +    TEST2(err, KErrNone);
  1.1539 +    err = db.Exec(_L("CREATE TABLE t(num INTEGER)"));
  1.1540 +    TEST2(err, 1);
  1.1541 +    err = db.Exec(_L("INSERT INTO t VALUES(1)"));
  1.1542 +    TEST2(err, 1);
  1.1543 +    err = db.Exec(_L("INSERT INTO t VALUES(2)"));
  1.1544 +    TEST2(err, 1);
  1.1545 +
  1.1546 +    
  1.1547 +    //Purposely commit an error so LastErrorMessage can be called 
  1.1548 +    RSqlStatement stmt;
  1.1549 +    err = stmt.Prepare(db, _L("DELETE FROM t WHERE ROWID=?"));
  1.1550 +    TEST2(err, KErrNone);
  1.1551 +    err = stmt.BindInt(0, 1);
  1.1552 +    TEST2(err, KErrNone);        
  1.1553 +    err = stmt.Exec();
  1.1554 +    TEST2(err, 1);
  1.1555 +    
  1.1556 +    //Should have reset stmt here
  1.1557 +    err = stmt.BindInt(0, 2);
  1.1558 +    TEST2(err, KErrNone); 
  1.1559 +    err = stmt.Exec();
  1.1560 +    TEST2(err, KSqlErrMisuse);
  1.1561 +    
  1.1562 +    //Test "library routine called out of sequence" error message 
  1.1563 +    //If the defect is not fixed then it will panic here   
  1.1564 +    TPtrC errMsg = db.LastErrorMessage();
  1.1565 +    RDebug::Print(_L("errMsg=%S\r\n"), &errMsg);
  1.1566 +
  1.1567 +    stmt.Close();
  1.1568 +    db.Close();
  1.1569 +    
  1.1570 +    TInt allocationNo = 0;
  1.1571 +    //The mask allows the out of memory simulation of the SQL Server to be delayed until the database is opened
  1.1572 +    const TInt KDelayedDbHeapFailureMask = 0x1000;
  1.1573 +    
  1.1574 +    do
  1.1575 +        {
  1.1576 +        TSqlResourceTester::SetDbHeapFailure(RHeap::EDeterministic |KDelayedDbHeapFailureMask, ++allocationNo);
  1.1577 +        err = db.Open(KTestDatabase6);
  1.1578 +        TEST2(err, KErrNone);
  1.1579 +        err = db.Exec(_L("INSERT INTO t VALUES(3)"));
  1.1580 +        TSqlResourceTester::SetDbHeapFailure(RHeap::ENone, 0);
  1.1581 +        
  1.1582 +        TheTest.Printf(_L("%d    \r"), allocationNo);
  1.1583 +        //Test "out of memory" error message, if the defect is not fixed then it will panic here   
  1.1584 +        TPtrC errMsg = db.LastErrorMessage();
  1.1585 +        RDebug::Print(_L("errMsg=%S\r\n"), &errMsg);
  1.1586 +        db.Close();
  1.1587 +        }
  1.1588 +    while (err == KErrNoMemory);
  1.1589 +    TEST2(err, 1);
  1.1590 +    }
  1.1591 +
  1.1592 +/**
  1.1593 +@SYMTestCaseID          PDS-SQL-CT-4166
  1.1594 +@SYMTestCaseDesc        Tests for DEF144027: SQL Open returns error if the reported and actual file size are different
  1.1595 +@SYMTestPriority        Medium
  1.1596 +@SYMTestActions         1) Create a simple database and close it (this will automatically delete the journal file
  1.1597 +                        2) Create a 15 bytes garbage journal file which is just less than the minimum file size allowed.
  1.1598 +                        3) Reopen the database and checks that the open operation does not fail even thou we've used a 
  1.1599 +                        garbage journal file which is too small
  1.1600 +@SYMTestExpectedResults The RSqlDatabase::Open operation should not fail
  1.1601 +@SYMDEF                 DEF144027
  1.1602 +                        DEF144238
  1.1603 +*/
  1.1604 +void DEF144027()
  1.1605 +    {
  1.1606 +    (void) RSqlDatabase::Delete(KTestDatabase7);
  1.1607 +    (void) TheFs.Delete(KTestDatabase7Journal);
  1.1608 +    
  1.1609 +    TInt err = TheDb.Create(KTestDatabase7);
  1.1610 +    TEST2(err, KErrNone);
  1.1611 +    
  1.1612 +    err = TheDb.Exec(_L("CREATE TABLE t1(NUM INTEGER)"));
  1.1613 +    TEST2(err, 1);
  1.1614 +    
  1.1615 +    err = TheDb.Exec(_L("INSERT INTO t1(NUM) VALUES (1)"));
  1.1616 +    TEST2(err, 1);
  1.1617 +    
  1.1618 +    TheDb.Close();
  1.1619 +    
  1.1620 +    //Created a garbage 15 bytes journal file 
  1.1621 +    RFile file;
  1.1622 +    err = file.Create(TheFs, KTestDatabase7Journal, EFileWrite);
  1.1623 +    TEST2(err, KErrNone);
  1.1624 +    
  1.1625 +    _LIT8(KJournalJunkData, "A123456789B1234");//15 bytes
  1.1626 +    err = file.Write(0, KJournalJunkData);
  1.1627 +    TEST2(err, KErrNone);
  1.1628 +    
  1.1629 +    file.Flush();
  1.1630 +    file.Close();
  1.1631 +    
  1.1632 +    //Here we check the open operation does not return an error, 
  1.1633 +    //even though there is a journal file less than 16 bytes
  1.1634 +    err = TheDb.Open(KTestDatabase7);
  1.1635 +    TEST2(err, KErrNone);
  1.1636 +    TheDb.Close();
  1.1637 +    }
  1.1638 +
  1.1639 +/**
  1.1640 +Test defect where calling RSQLStatement::DeclaredColumnType() on a table which contains long (> 20 characters) column type 
  1.1641 +names results in a USER 11 panic.
  1.1642 +This test should pass because these are valid SQL column types 
  1.1643 +*/
  1.1644 +void LongColumnTypeTest()
  1.1645 +	{
  1.1646 +	(void)RSqlDatabase::Delete(KTestDatabase3);
  1.1647 +	TInt err = TheDb.Create(KTestDatabase3);
  1.1648 +	TEST2(err, KErrNone);
  1.1649 +	
  1.1650 +	_LIT8(KCreateStmt, "CREATE TABLE t(a CHARACTER VARYING(100000), b NCHAR VARYING(100000), c NATIONAL CHARACTER(100000), d NATIONAL CHARACTER VARYING(100000))");
  1.1651 +	err = TheDb.Exec(KCreateStmt);
  1.1652 +	TEST(err >= 0);
  1.1653 +	
  1.1654 +	//Select all columns (SELECT *)
  1.1655 +	_LIT(KSelectStmt, "SELECT * FROM t");
  1.1656 +	RSqlStatement stmt;
  1.1657 +	err = stmt.Prepare(TheDb, KSelectStmt);
  1.1658 +	TEST2(err, KErrNone);
  1.1659 +	
  1.1660 +	TSqlColumnType colType;
  1.1661 +	err = stmt.DeclaredColumnType(0, colType);
  1.1662 +	TEST2(err,KErrNone);
  1.1663 +	TEST2(colType, ESqlText);
  1.1664 +	
  1.1665 +	err = stmt.DeclaredColumnType(1, colType);
  1.1666 +	TEST2(err,KErrNone);
  1.1667 +	TEST2(colType, ESqlText);
  1.1668 +	
  1.1669 +	err = stmt.DeclaredColumnType(2, colType);
  1.1670 +	TEST2(err,KErrNone);
  1.1671 +	TEST2(colType, ESqlText);
  1.1672 +	
  1.1673 +	err = stmt.DeclaredColumnType(3, colType);
  1.1674 +	TEST2(err,KErrNone);
  1.1675 +	TEST2(colType, ESqlText);
  1.1676 +	
  1.1677 +	stmt.Close();
  1.1678 +
  1.1679 +	TheDb.Close();
  1.1680 +	(void)RSqlDatabase::Delete(KTestDatabase3); 
  1.1681 +	}
  1.1682 +
  1.1683 +void DoTestsL()
  1.1684 +	{
  1.1685 +	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1763 \"SQL against a detached db\" test "));
  1.1686 +	SqlDetachedDbTest();	
  1.1687 +
  1.1688 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4034 Corrupted db file (file length too short)"));
  1.1689 +	CorruptDbFileTest();	
  1.1690 +	
  1.1691 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4035 Attempt to attach a file which name cannot be parsed"));
  1.1692 +	AttachBadDbFileNameTest();	
  1.1693 +
  1.1694 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4036 Attempt to attach a secure database. The client cannot pass the security checks"));
  1.1695 +	AttachSecureDbTest();	
  1.1696 +
  1.1697 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4032 INC091579 - SQL Panic 7 when streaming BLOB fields"));
  1.1698 +	INC091579L();
  1.1699 +
  1.1700 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4033 INC091580 - SQL returns bogus pointer when too much text in field..."));
  1.1701 +	INC091580L();
  1.1702 +
  1.1703 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1815 Testing KSqlErrFull error code "));
  1.1704 +	SqlErrFullTest();
  1.1705 +	
  1.1706 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1816-0001 INC094870 - [SQL] Database became corrupted and cannot be opened "));
  1.1707 +	INC094870L();
  1.1708 +
  1.1709 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1817-0001 INC095412: [SQL] Retrieving query results may corrupt heap "));
  1.1710 + 	INC095412();
  1.1711 +
  1.1712 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3427 DEF104242 - The SQL server fails to open database with default security policy only "));
  1.1713 +	DEF104242();
  1.1714 +
  1.1715 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3430 DEF104437 - RSqlStatement::Next() panics the SQL server with KERN-EXEC 3 "));
  1.1716 +	DEF104437();
  1.1717 +	
  1.1718 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3442 DEF105259 - SQL, RSqlColumnReadStream's internal buffer may become invalid "));
  1.1719 +	DEF105259L();
  1.1720 +
  1.1721 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3470 DEF105681 - SQL, HReadOnlyBuf::ConstructL() sets a pointer to a local TPtr8 variable "));
  1.1722 +	DEF105681L();
  1.1723 +
  1.1724 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3476 DEF106391 SQL server does not deallocate the already allocated memory "));
  1.1725 +	DEF106391();
  1.1726 +	
  1.1727 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3501 DEF109025 SQL, dangling long binary/text column value pointer "));
  1.1728 +	DEF109025();
  1.1729 +	
  1.1730 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3546 DEF109843 SQL, RSQLStatement::BindBinary() is causing panic if empty descriptor is passed "));
  1.1731 +	DEF109843();
  1.1732 +
  1.1733 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4005 DEF114698: SqlSrv.EXE::!SQL Server Insert/Update Error "));
  1.1734 +	DEF114698();
  1.1735 +
  1.1736 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4008 DEF115567 Critical SQLite defect that can cause database corruption during UPDATE/DELETE "));
  1.1737 +	DEF115567L();
  1.1738 +
  1.1739 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4009-0001 DEF115556: SqlSrv.EXE::!SQL Server when preparing complex sql query "));
  1.1740 +	DEF115556();
  1.1741 +	
  1.1742 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4012 DEF115954: CSession Code = 2 executing SQL stmt in OOM loop ")); 
  1.1743 +	DEF115954();
  1.1744 +
  1.1745 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4019 DEF116397: SQL, Attaching database returns KErrEof(-25) "));
  1.1746 +	DEF116397();
  1.1747 +
  1.1748 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4029 DEF119403: Database re-index unnecessarily during open operation"));
  1.1749 +	DEF119403L();
  1.1750 +	
  1.1751 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4031 DEF120237: SQL, SQLITE3.3.17, \"collate nocase\", wrong results."));
  1.1752 +	DEF120237L();
  1.1753 +	
  1.1754 +	TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4120 DEF125881: RSqlDatabase::Exec() returns KErrAlreadyExists in I/O failure use cases."));
  1.1755 +	DEF125881L();
  1.1756 +    
  1.1757 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4128 DEF129581: All Pragmas are allowed to be executed on non-secure SQL databases."));
  1.1758 +    DEF129581();
  1.1759 +    
  1.1760 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4153 DEF143047: SQL, default \"max parameter count\" value, compatibility problem."));
  1.1761 +    DEF143047();
  1.1762 +    
  1.1763 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4157 PDEF143461 : CSqlSrvDatabase::LastErrorMessage() alignment problem"));
  1.1764 +    PDEF143461L();
  1.1765 +    
  1.1766 +    TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4166 DEF144027: SQL Open returns error if the reported and actual file size are different"));
  1.1767 +    DEF144027();
  1.1768 +    
  1.1769 +    TheTest.Next(_L("RSQLStatement::DeclaredColumnType() causes USER 11 panic when table contains long column type strings"));
  1.1770 +    LongColumnTypeTest();
  1.1771 + 
  1.1772 +	}
  1.1773 +
  1.1774 +TInt E32Main()
  1.1775 +	{
  1.1776 +	TheTest.Title();
  1.1777 +	
  1.1778 +	CTrapCleanup* tc = CTrapCleanup::New();
  1.1779 +	
  1.1780 +	__UHEAP_MARK;
  1.1781 +	
  1.1782 +	CreateTestEnv();
  1.1783 +	DeleteTestFiles();
  1.1784 +	TInt err = RSqlDatabase::Copy(KCorruptDbZ, KCorruptDb);	
  1.1785 +	TEST2(err, KErrNone);
  1.1786 +	TRAP(err, DoTestsL());
  1.1787 +	DeleteTestFiles();
  1.1788 +	TheFs.SetErrorCondition(KErrNone);
  1.1789 +	TheFs.Close();
  1.1790 +	TEST2(err, KErrNone);
  1.1791 +
  1.1792 +	__UHEAP_MARKEND;
  1.1793 +	
  1.1794 +	TheTest.End();
  1.1795 +	TheTest.Close();
  1.1796 +	
  1.1797 +	delete tc;
  1.1798 +
  1.1799 +	User::Heap().Check();
  1.1800 +	return KErrNone;
  1.1801 +	}