persistentstorage/sql/TEST/t_sqlite.cpp
changeset 55 44f437012c90
parent 0 08ec8eefde2f
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
   103 static void Check(TInt aValue, TInt aLine)
   103 static void Check(TInt aValue, TInt aLine)
   104 	{
   104 	{
   105 	if(!aValue)
   105 	if(!aValue)
   106 		{
   106 		{
   107 		DeleteTestFiles();
   107 		DeleteTestFiles();
       
   108 		TheTest.Printf(_L("*** Expresssion evaluated to false\r\n"));
   108 		TheTest(EFalse, aLine);
   109 		TheTest(EFalse, aLine);
   109 		}
   110 		}
   110 	}
   111 	}
   111 static void Check(TInt aValue, TInt aExpected, TInt aLine)
   112 static void Check(TInt aValue, TInt aExpected, TInt aLine)
   112 	{
   113 	{
   113 	if(aValue != aExpected)
   114 	if(aValue != aExpected)
   114 		{
   115 		{
   115 		DeleteTestFiles();
   116 		DeleteTestFiles();
   116 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   117 		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   117 		TheTest(EFalse, aLine);
   118 		TheTest(EFalse, aLine);
   118 		}
   119 		}
   119 	}
   120 	}
   120 #define TEST(arg) ::Check((arg), __LINE__)
   121 #define TEST(arg) ::Check((arg), __LINE__)
   121 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   122 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   135 
   136 
   136 ///////////////////////////////////////////////////////////////////////////////////////
   137 ///////////////////////////////////////////////////////////////////////////////////////
   137 
   138 
   138 static void PrintConfig(const TDesC& aDbFilePath)
   139 static void PrintConfig(const TDesC& aDbFilePath)
   139 	{
   140 	{
   140 	RDebug::Print(_L("================= Configuration ================\r\n"));	
   141 	TheTest.Printf(_L("================= Configuration ================\r\n"));	
   141 	RDebug::Print(_L("Cache page size %dK, pages %d, total %dK\r\n"), SQLITE_DEFAULT_PAGE_SIZE/1024, SQLITE_DEFAULT_CACHE_SIZE, SQLITE_DEFAULT_PAGE_SIZE * SQLITE_DEFAULT_CACHE_SIZE/1024);	
   142 	TheTest.Printf(_L("Cache page size %dK, pages %d, total %dK\r\n"), SQLITE_DEFAULT_PAGE_SIZE/1024, SQLITE_DEFAULT_CACHE_SIZE, SQLITE_DEFAULT_PAGE_SIZE * SQLITE_DEFAULT_CACHE_SIZE/1024);	
   142 	RDebug::Print(_L("Temp cache page size %dK, pages %d, total %dK\r\n"), SQLITE_DEFAULT_PAGE_SIZE/1024, SQLITE_DEFAULT_TEMP_CACHE_SIZE, SQLITE_DEFAULT_PAGE_SIZE * SQLITE_DEFAULT_TEMP_CACHE_SIZE/1024);	
   143 	TheTest.Printf(_L("Temp cache page size %dK, pages %d, total %dK\r\n"), SQLITE_DEFAULT_PAGE_SIZE/1024, SQLITE_DEFAULT_TEMP_CACHE_SIZE, SQLITE_DEFAULT_PAGE_SIZE * SQLITE_DEFAULT_TEMP_CACHE_SIZE/1024);	
   143 	_LIT(K1, "On");
   144 	_LIT(K1, "On");
   144 	_LIT(K2, "Off");
   145 	_LIT(K2, "Off");
   145 	RDebug::Print(_L("Autovacuum: %S\r\n"), SQLITE_DEFAULT_AUTOVACUUM ? &K1 : &K2);	
   146 	TheTest.Printf(_L("Autovacuum: %S\r\n"), SQLITE_DEFAULT_AUTOVACUUM ? &K1 : &K2);	
   146 	#ifdef SQLITE_DEBUG
   147 	#ifdef SQLITE_DEBUG
   147 		RDebug::Print(_L("Debug: On\r\n"));	
   148 	TheTest.Printf(_L("Debug: On\r\n"));	
   148 	#else
   149 	#else
   149 		RDebug::Print(_L("Debug: Off\r\n"));	
   150 	TheTest.Printf(_L("Debug: Off\r\n"));	
   150 	#endif
   151 	#endif
   151 	RDebug::Print(_L("Db file: %S\r\n"), &aDbFilePath);
   152 	TheTest.Printf(_L("Db file: %S\r\n"), &aDbFilePath);
   152 	RDebug::Print(_L("================================================\r\n"));	
   153 	TheTest.Printf(_L("================================================\r\n"));	
   153 	}
   154 	}
   154 	
   155 	
   155 ///////////////////////////////////////////////////////////////////////////////////////
   156 ///////////////////////////////////////////////////////////////////////////////////////
   156 
   157 
   157 static TInt callback(void */*NotUsed*/, TInt argc, char **argv, char **azColName)
   158 static TInt callback(void */*NotUsed*/, TInt argc, char **argv, char **azColName)
   163 		TPtrC8 colVal((const TUint8*)(argv[i] ? argv[i] : "NULL"));
   164 		TPtrC8 colVal((const TUint8*)(argv[i] ? argv[i] : "NULL"));
   164 		TheBuf2.Copy(colName);
   165 		TheBuf2.Copy(colName);
   165 		TheBuf2.Append(_L(" = "));
   166 		TheBuf2.Append(_L(" = "));
   166 		TheBuf1.Copy(colVal);
   167 		TheBuf1.Copy(colVal);
   167 		TheBuf2.Append(TheBuf1);
   168 		TheBuf2.Append(TheBuf1);
   168     	RDebug::Print(_L("%S\r\n"), &TheBuf2);
   169 		TheTest.Printf(_L("%S\r\n"), &TheBuf2);
   169 		}
   170 		}
   170   	RDebug::Print(_L("\n"));
   171 	TheTest.Printf(_L("\r\n"));
   171   	return 0;
   172   	return 0;
   172 	}
   173 	}
   173 
   174 
   174 static TInt Compare(void*, TInt size1, const void* p1, TInt size2, const void* p2)
   175 static TInt Compare(void*, TInt size1, const void* p1, TInt size2, const void* p2)
   175 	{
   176 	{
   211 
   212 
   212 	rc = sqlite3_open(KDbName1, &TheDb1);
   213 	rc = sqlite3_open(KDbName1, &TheDb1);
   213   	if(rc)
   214   	if(rc)
   214   		{
   215   		{
   215   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   216   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   216   		RDebug::Print(_L("Can't open database, err %d, msg: %S\n"), rc, &p);
   217   		TheTest.Printf(_L("Can't open database, err %d, msg: %S\r\n"), rc, &p);
   217     	TEST(0);
   218     	TEST(0);
   218   		}
   219   		}
   219 
   220 
   220 	rc = sqlite3_create_collation(TheDb1, "Clt1", SQLITE_UTF8, NULL, &Compare);
   221 	rc = sqlite3_create_collation(TheDb1, "Clt1", SQLITE_UTF8, NULL, &Compare);
   221   	if(rc)
   222   	if(rc)
   222   		{
   223   		{
   223   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   224   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   224   		RDebug::Print(_L("Can't create collation, err %d, msg: %S\n"), rc, &p);
   225   		TheTest.Printf(_L("Can't create collation, err %d, msg: %S\r\n"), rc, &p);
   225     	TEST(0);
   226     	TEST(0);
   226   		}
   227   		}
   227 
   228 
   228 	rc = sqlite3_create_collation(TheDb1, "Clt2", SQLITE_UTF8, NULL, &Compare2);
   229 	rc = sqlite3_create_collation(TheDb1, "Clt2", SQLITE_UTF8, NULL, &Compare2);
   229   	if(rc)
   230   	if(rc)
   230   		{
   231   		{
   231   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   232   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   232   		RDebug::Print(_L("Can't create collation, err %d, msg: %S\n"), rc, &p);
   233   		TheTest.Printf(_L("Can't create collation, err %d, msg: %S\r\n"), rc, &p);
   233     	TEST(0);
   234     	TEST(0);
   234   		}
   235   		}
   235 
   236 
   236 	rc = sqlite3_create_function(TheDb1, "Func", 2, SQLITE_UTF8, NULL, Func, NULL, NULL);
   237 	rc = sqlite3_create_function(TheDb1, "Func", 2, SQLITE_UTF8, NULL, Func, NULL, NULL);
   237   	if(rc)
   238   	if(rc)
   238   		{
   239   		{
   239   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   240   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   240   		RDebug::Print(_L("Can't create UDF, err %d, msg: %S\n"), rc, &p);
   241   		TheTest.Printf(_L("Can't create UDF, err %d, msg: %S\r\n"), rc, &p);
   241     	TEST(0);
   242     	TEST(0);
   242   		}
   243   		}
   243 
   244 
   244 	rc = sqlite3_exec(TheDb1, "\
   245 	rc = sqlite3_exec(TheDb1, "\
   245 	             BEGIN TRANSACTION;\
   246 	             BEGIN TRANSACTION;\
   270 	             COMMIT TRANSACTION;", callback, 0, &zErrMsg);
   271 	             COMMIT TRANSACTION;", callback, 0, &zErrMsg);
   271 	             
   272 	             
   272 	if(rc != SQLITE_OK)
   273 	if(rc != SQLITE_OK)
   273 		{
   274 		{
   274   		TPtrC p = ConvertToUtf16(zErrMsg);
   275   		TPtrC p = ConvertToUtf16(zErrMsg);
   275   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   276   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   276     	sqlite3_free(zErrMsg);
   277     	sqlite3_free(zErrMsg);
   277     	TEST(0);
   278     	TEST(0);
   278 		}
   279 		}
   279 
   280 
   280 	rc = sqlite3_exec(TheDb1, 
   281 	rc = sqlite3_exec(TheDb1, 
   296 	 INSERT INTO Sales(ShopId, M, D, D1, T1) VALUES(3, 200.0, '2005-01-03', '2005-01-29', '12:34:23');\
   297 	 INSERT INTO Sales(ShopId, M, D, D1, T1) VALUES(3, 200.0, '2005-01-03', '2005-01-29', '12:34:23');\
   297 	 COMMIT TRANSACTION;", callback, 0, &zErrMsg);
   298 	 COMMIT TRANSACTION;", callback, 0, &zErrMsg);
   298 	if(rc != SQLITE_OK)
   299 	if(rc != SQLITE_OK)
   299 		{
   300 		{
   300   		TPtrC p = ConvertToUtf16(zErrMsg);
   301   		TPtrC p = ConvertToUtf16(zErrMsg);
   301   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   302   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   302     	sqlite3_free(zErrMsg);
   303     	sqlite3_free(zErrMsg);
   303     	TEST(0);
   304     	TEST(0);
   304 		}
   305 		}
   305 
   306 
   306 	rc = sqlite3_exec(TheDb1, "SELECT COUNT(*) FROM Shop", callback, 0, &zErrMsg);
   307 	rc = sqlite3_exec(TheDb1, "SELECT COUNT(*) FROM Shop", callback, 0, &zErrMsg);
   307 	if(rc != SQLITE_OK)
   308 	if(rc != SQLITE_OK)
   308 		{
   309 		{
   309   		TPtrC p = ConvertToUtf16(zErrMsg);
   310   		TPtrC p = ConvertToUtf16(zErrMsg);
   310   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   311   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   311     	sqlite3_free(zErrMsg);
   312     	sqlite3_free(zErrMsg);
   312     	TEST(0);
   313     	TEST(0);
   313 		}
   314 		}
   314 
   315 
   315 	for(TInt i=0;i<500;++i)
   316 	for(TInt i=0;i<500;++i)
   318 		TheBuf3.Format(KSqlStmt, i+1, i+1);
   319 		TheBuf3.Format(KSqlStmt, i+1, i+1);
   319 		rc = sqlite3_exec(TheDb1, (const char*)TheBuf3.Ptr(), callback, 0, &zErrMsg);
   320 		rc = sqlite3_exec(TheDb1, (const char*)TheBuf3.Ptr(), callback, 0, &zErrMsg);
   320 		if(rc != SQLITE_OK)
   321 		if(rc != SQLITE_OK)
   321 			{
   322 			{
   322 	  		TPtrC p = ConvertToUtf16(zErrMsg);
   323 	  		TPtrC p = ConvertToUtf16(zErrMsg);
   323 	  		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   324 	  		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   324 	    	sqlite3_free(zErrMsg);
   325 	    	sqlite3_free(zErrMsg);
   325     		TEST(0);
   326     		TEST(0);
   326 			}
   327 			}
   327 		}
   328 		}
   328 
   329 
   329 	_LIT8(KSqlStmt2, "DELETE FROM Shop WHERE Id > 400\x0");
   330 	_LIT8(KSqlStmt2, "DELETE FROM Shop WHERE Id > 400\x0");
   330 	rc = sqlite3_exec(TheDb1, (const char*)KSqlStmt2().Ptr(), callback, 0, &zErrMsg);
   331 	rc = sqlite3_exec(TheDb1, (const char*)KSqlStmt2().Ptr(), callback, 0, &zErrMsg);
   331 	if(rc != SQLITE_OK)
   332 	if(rc != SQLITE_OK)
   332 		{
   333 		{
   333   		TPtrC p = ConvertToUtf16(zErrMsg);
   334   		TPtrC p = ConvertToUtf16(zErrMsg);
   334   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   335   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   335     	sqlite3_free(zErrMsg);
   336     	sqlite3_free(zErrMsg);
   336    		TEST(0);
   337    		TEST(0);
   337 		}
   338 		}
   338 
   339 
   339 	_LIT8(KSqlStmt3, "SELECT COUNT(*) FROM Shop\x0");
   340 	_LIT8(KSqlStmt3, "SELECT COUNT(*) FROM Shop\x0");
   340 	rc = sqlite3_exec(TheDb1, (const char*)KSqlStmt3().Ptr(), callback, 0, &zErrMsg);
   341 	rc = sqlite3_exec(TheDb1, (const char*)KSqlStmt3().Ptr(), callback, 0, &zErrMsg);
   341 	if(rc != SQLITE_OK)
   342 	if(rc != SQLITE_OK)
   342 		{
   343 		{
   343   		TPtrC p = ConvertToUtf16(zErrMsg);
   344   		TPtrC p = ConvertToUtf16(zErrMsg);
   344   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   345   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   345     	sqlite3_free(zErrMsg);
   346     	sqlite3_free(zErrMsg);
   346    		TEST(0);
   347    		TEST(0);
   347 		}
   348 		}
   348 
   349 
   349 	rc = sqlite3_exec(TheDb1, "SELECT Pn.Surname, Addr.Location, City.Name FROM Pn \
   350 	rc = sqlite3_exec(TheDb1, "SELECT Pn.Surname, Addr.Location, City.Name FROM Pn \
   351 	      INNER JOIN City ON Addr.CityId = City.Id \
   352 	      INNER JOIN City ON Addr.CityId = City.Id \
   352 	      ORDER BY Surname COLLATE Clt2", callback, 0, &zErrMsg);
   353 	      ORDER BY Surname COLLATE Clt2", callback, 0, &zErrMsg);
   353 	if(rc != SQLITE_OK)
   354 	if(rc != SQLITE_OK)
   354 		{
   355 		{
   355   		TPtrC p = ConvertToUtf16(zErrMsg);
   356   		TPtrC p = ConvertToUtf16(zErrMsg);
   356   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   357   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   357     	sqlite3_free(zErrMsg);
   358     	sqlite3_free(zErrMsg);
   358    		TEST(0);
   359    		TEST(0);
   359 		}
   360 		}
   360 	      
   361 	      
   361 	rc = sqlite3_exec(TheDb1, "SELECT * FROM Addr", callback, 0, &zErrMsg);
   362 	rc = sqlite3_exec(TheDb1, "SELECT * FROM Addr", callback, 0, &zErrMsg);
   362 	if(rc != SQLITE_OK)
   363 	if(rc != SQLITE_OK)
   363 		{
   364 		{
   364   		TPtrC p = ConvertToUtf16(zErrMsg);
   365   		TPtrC p = ConvertToUtf16(zErrMsg);
   365   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   366   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   366     	sqlite3_free(zErrMsg);
   367     	sqlite3_free(zErrMsg);
   367    		TEST(0);
   368    		TEST(0);
   368 		}
   369 		}
   369 	
   370 	
   370 	rc = sqlite3_exec(TheDb1, "SELECT * FROM Sales WHERE D1 > '2005-08-27'", callback, 0, &zErrMsg);
   371 	rc = sqlite3_exec(TheDb1, "SELECT * FROM Sales WHERE D1 > '2005-08-27'", callback, 0, &zErrMsg);
   371 	if(rc != SQLITE_OK)
   372 	if(rc != SQLITE_OK)
   372 		{
   373 		{
   373   		TPtrC p = ConvertToUtf16(zErrMsg);
   374   		TPtrC p = ConvertToUtf16(zErrMsg);
   374   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   375   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   375     	sqlite3_free(zErrMsg);
   376     	sqlite3_free(zErrMsg);
   376    		TEST(0);
   377    		TEST(0);
   377 		}
   378 		}
   378 	
   379 	
   379 	rc = sqlite3_exec(TheDb1, "SELECT V1.* FROM V1 EXCEPT SELECT V1.* FROM V1 WHERE V1.Id = 2", callback, 0, &zErrMsg);
   380 	rc = sqlite3_exec(TheDb1, "SELECT V1.* FROM V1 EXCEPT SELECT V1.* FROM V1 WHERE V1.Id = 2", callback, 0, &zErrMsg);
   380 	if(rc != SQLITE_OK)
   381 	if(rc != SQLITE_OK)
   381 		{
   382 		{
   382   		TPtrC p = ConvertToUtf16(zErrMsg);
   383   		TPtrC p = ConvertToUtf16(zErrMsg);
   383   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   384   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   384     	sqlite3_free(zErrMsg);
   385     	sqlite3_free(zErrMsg);
   385    		TEST(0);
   386    		TEST(0);
   386 		}
   387 		}
   387 
   388 
   388 	rc = sqlite3_exec(TheDb1, "SELECT V3.D, SUM(V3.M) FROM V3 GROUP BY V3.D HAVING SUM(V3.M) > 210.0", callback, 0, &zErrMsg);
   389 	rc = sqlite3_exec(TheDb1, "SELECT V3.D, SUM(V3.M) FROM V3 GROUP BY V3.D HAVING SUM(V3.M) > 210.0", callback, 0, &zErrMsg);
   389 	if(rc != SQLITE_OK)
   390 	if(rc != SQLITE_OK)
   390 		{
   391 		{
   391   		TPtrC p = ConvertToUtf16(zErrMsg);
   392   		TPtrC p = ConvertToUtf16(zErrMsg);
   392   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   393   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   393     	sqlite3_free(zErrMsg);
   394     	sqlite3_free(zErrMsg);
   394    		TEST(0);
   395    		TEST(0);
   395 		}
   396 		}
   396 	
   397 	
   397 	rc = sqlite3_exec(TheDb1, "SELECT V4.Name, SUM(V3.M) FROM V4, V3 WHERE V4.Id = V3.ShopId GROUP BY V4.Id", callback, 0, &zErrMsg);
   398 	rc = sqlite3_exec(TheDb1, "SELECT V4.Name, SUM(V3.M) FROM V4, V3 WHERE V4.Id = V3.ShopId GROUP BY V4.Id", callback, 0, &zErrMsg);
   398 	if(rc != SQLITE_OK)
   399 	if(rc != SQLITE_OK)
   399 		{
   400 		{
   400   		TPtrC p = ConvertToUtf16(zErrMsg);
   401   		TPtrC p = ConvertToUtf16(zErrMsg);
   401   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   402   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   402     	sqlite3_free(zErrMsg);
   403     	sqlite3_free(zErrMsg);
   403    		TEST(0);
   404    		TEST(0);
   404 		}
   405 		}
   405 
   406 
   406 	sqlite3_close(TheDb1);
   407 	sqlite3_close(TheDb1);
   417 
   418 
   418 	rc = sqlite3_open(KDbName1, &TheDb1);
   419 	rc = sqlite3_open(KDbName1, &TheDb1);
   419   	if(rc != SQLITE_OK)
   420   	if(rc != SQLITE_OK)
   420   		{
   421   		{
   421   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   422   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   422   		RDebug::Print(_L("Can't open database, err %d, msg: %S\n"), rc, &p);
   423   		TheTest.Printf(_L("Can't open database, err %d, msg: %S\r\n"), rc, &p);
   423     	TEST(0);
   424     	TEST(0);
   424   		}
   425   		}
   425   		
   426   		
   426 	rc = sqlite3_exec(TheDb1, "PRAGMA auto_vacuum = 1", callback, 0, &zErrMsg);
   427 	rc = sqlite3_exec(TheDb1, "PRAGMA auto_vacuum = 1", callback, 0, &zErrMsg);
   427 	if(rc != SQLITE_OK)
   428 	if(rc != SQLITE_OK)
   428 		{
   429 		{
   429   		TPtrC p = ConvertToUtf16(zErrMsg);
   430   		TPtrC p = ConvertToUtf16(zErrMsg);
   430   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   431   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   431     	sqlite3_free(zErrMsg);
   432     	sqlite3_free(zErrMsg);
   432    		TEST(0);
   433    		TEST(0);
   433 		}
   434 		}
   434 	
   435 	
   435 	rc = sqlite3_exec(TheDb1, "\
   436 	rc = sqlite3_exec(TheDb1, "\
   438 	             CREATE INDEX ShopName ON Shop(Name);\
   439 	             CREATE INDEX ShopName ON Shop(Name);\
   439 	             COMMIT TRANSACTION;", callback, 0, &zErrMsg);
   440 	             COMMIT TRANSACTION;", callback, 0, &zErrMsg);
   440 	if(rc != SQLITE_OK)
   441 	if(rc != SQLITE_OK)
   441 		{
   442 		{
   442   		TPtrC p = ConvertToUtf16(zErrMsg);
   443   		TPtrC p = ConvertToUtf16(zErrMsg);
   443   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   444   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   444     	sqlite3_free(zErrMsg);
   445     	sqlite3_free(zErrMsg);
   445    		TEST(0);
   446    		TEST(0);
   446 		}
   447 		}
   447 		
   448 		
   448 	rc = sqlite3_exec(TheDb1, "BEGIN TRANSACTION", callback, 0, &zErrMsg);
   449 	rc = sqlite3_exec(TheDb1, "BEGIN TRANSACTION", callback, 0, &zErrMsg);
   449 	if(rc != SQLITE_OK)
   450 	if(rc != SQLITE_OK)
   450 		{
   451 		{
   451   		TPtrC p = ConvertToUtf16(zErrMsg);
   452   		TPtrC p = ConvertToUtf16(zErrMsg);
   452   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   453   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   453     	sqlite3_free(zErrMsg);
   454     	sqlite3_free(zErrMsg);
   454    		TEST(0);
   455    		TEST(0);
   455 		}
   456 		}
   456 	
   457 	
   457 	for(TInt i=0;i<1000;++i)
   458 	for(TInt i=0;i<1000;++i)
   460 		TheBuf3.Format(KSqlStmt, i, i);
   461 		TheBuf3.Format(KSqlStmt, i, i);
   461 		rc = sqlite3_exec(TheDb1, (const char*)TheBuf3.Ptr(), callback, 0, &zErrMsg);
   462 		rc = sqlite3_exec(TheDb1, (const char*)TheBuf3.Ptr(), callback, 0, &zErrMsg);
   462 		if(rc != SQLITE_OK)
   463 		if(rc != SQLITE_OK)
   463 			{
   464 			{
   464 	  		TPtrC p = ConvertToUtf16(zErrMsg);
   465 	  		TPtrC p = ConvertToUtf16(zErrMsg);
   465 	  		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   466 	  		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   466 	    	sqlite3_free(zErrMsg);
   467 	    	sqlite3_free(zErrMsg);
   467 	   		TEST(0);
   468 	   		TEST(0);
   468 			}
   469 			}
   469 		}
   470 		}
   470 		
   471 		
   471 	rc = sqlite3_exec(TheDb1, "COMMIT TRANSACTION", callback, 0, &zErrMsg);
   472 	rc = sqlite3_exec(TheDb1, "COMMIT TRANSACTION", callback, 0, &zErrMsg);
   472 	if(rc != SQLITE_OK)
   473 	if(rc != SQLITE_OK)
   473 		{
   474 		{
   474   		TPtrC p = ConvertToUtf16(zErrMsg);
   475   		TPtrC p = ConvertToUtf16(zErrMsg);
   475   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   476   		TheTest.Printf(_L("SQL error %d, msg: %S\n"), rc, &p);
   476     	sqlite3_free(zErrMsg);
   477     	sqlite3_free(zErrMsg);
   477    		TEST(0);
   478    		TEST(0);
   478 		}
   479 		}
   479 
   480 
   480 	rc = sqlite3_exec(TheDb1, "SELECT COUNT(*) FROM Shop", callback, 0, &zErrMsg);
   481 	rc = sqlite3_exec(TheDb1, "SELECT COUNT(*) FROM Shop", callback, 0, &zErrMsg);
   481 	if(rc != SQLITE_OK)
   482 	if(rc != SQLITE_OK)
   482 		{
   483 		{
   483   		TPtrC p = ConvertToUtf16(zErrMsg);
   484   		TPtrC p = ConvertToUtf16(zErrMsg);
   484   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   485   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   485     	sqlite3_free(zErrMsg);
   486     	sqlite3_free(zErrMsg);
   486    		TEST(0);
   487    		TEST(0);
   487 		}
   488 		}
   488 
   489 
   489 	rc = sqlite3_exec(TheDb1, "BEGIN TRANSACTION", callback, 0, &zErrMsg);
   490 	rc = sqlite3_exec(TheDb1, "BEGIN TRANSACTION", callback, 0, &zErrMsg);
   490 	if(rc != SQLITE_OK)
   491 	if(rc != SQLITE_OK)
   491 		{
   492 		{
   492   		TPtrC p = ConvertToUtf16(zErrMsg);
   493   		TPtrC p = ConvertToUtf16(zErrMsg);
   493   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   494   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   494     	sqlite3_free(zErrMsg);
   495     	sqlite3_free(zErrMsg);
   495    		TEST(0);
   496    		TEST(0);
   496 		}
   497 		}
   497 	
   498 	
   498 	rc = sqlite3_exec(TheDb1, "DELETE FROM Shop WHERE Id > 100", callback, 0, &zErrMsg);
   499 	rc = sqlite3_exec(TheDb1, "DELETE FROM Shop WHERE Id > 100", callback, 0, &zErrMsg);
   499 	if(rc != SQLITE_OK)
   500 	if(rc != SQLITE_OK)
   500 		{
   501 		{
   501   		TPtrC p = ConvertToUtf16(zErrMsg);
   502   		TPtrC p = ConvertToUtf16(zErrMsg);
   502   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   503   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   503     	sqlite3_free(zErrMsg);
   504     	sqlite3_free(zErrMsg);
   504    		TEST(0);
   505    		TEST(0);
   505 		}
   506 		}
   506 		
   507 		
   507 	rc = sqlite3_exec(TheDb1, "COMMIT TRANSACTION", callback, 0, &zErrMsg);
   508 	rc = sqlite3_exec(TheDb1, "COMMIT TRANSACTION", callback, 0, &zErrMsg);
   508 	if(rc != SQLITE_OK)
   509 	if(rc != SQLITE_OK)
   509 		{
   510 		{
   510   		TPtrC p = ConvertToUtf16(zErrMsg);
   511   		TPtrC p = ConvertToUtf16(zErrMsg);
   511   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   512   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   512     	sqlite3_free(zErrMsg);
   513     	sqlite3_free(zErrMsg);
   513    		TEST(0);
   514    		TEST(0);
   514 		}
   515 		}
   515 
   516 
   516 	rc = sqlite3_exec(TheDb1, "SELECT COUNT(*) FROM Shop", callback, 0, &zErrMsg);
   517 	rc = sqlite3_exec(TheDb1, "SELECT COUNT(*) FROM Shop", callback, 0, &zErrMsg);
   517 	if(rc != SQLITE_OK)
   518 	if(rc != SQLITE_OK)
   518 		{
   519 		{
   519   		TPtrC p = ConvertToUtf16(zErrMsg);
   520   		TPtrC p = ConvertToUtf16(zErrMsg);
   520   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
   521   		TheTest.Printf(_L("SQL error %d, msg: %S\r\n"), rc, &p);
   521     	sqlite3_free(zErrMsg);
   522     	sqlite3_free(zErrMsg);
   522    		TEST(0);
   523    		TEST(0);
   523 		}
   524 		}
   524 
   525 
   525 	sqlite3_close(TheDb1);
   526 	sqlite3_close(TheDb1);
   537 	fname.Copy(tmp);
   538 	fname.Copy(tmp);
   538 	TInt rc = sqlite3_open16(fname.PtrZ(), &TheDb1);//!!!!16-bit encoding!!!!!
   539 	TInt rc = sqlite3_open16(fname.PtrZ(), &TheDb1);//!!!!16-bit encoding!!!!!
   539   	if(rc != SQLITE_OK)
   540   	if(rc != SQLITE_OK)
   540   		{
   541   		{
   541   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   542   		TPtrC p = ConvertToUtf16(sqlite3_errmsg(TheDb1));
   542   		RDebug::Print(_L("Can't open database, err %d, msg: %S\n"), rc, &p);
   543   		TheTest.Printf(_L("Can't open database, err %d, msg: %S\r\n"), rc, &p);
   543     	TEST(0);
   544     	TEST(0);
   544   		}
   545   		}
   545 	
   546 	
   546 	//Create table
   547 	//Create table
   547 	_LIT(KSqlStrZ, "CREATE TABLE abc(col_\u00C4 integer, col_A text)\0");
   548 	_LIT(KSqlStrZ, "CREATE TABLE abc(col_\u00C4 integer, col_A text)\0");
   553 	rc = sqlite3_prepare16_v2(TheDb1, KSqlStrZ().Ptr(), -1, &stmtHandle, &stmtTailZ);
   554 	rc = sqlite3_prepare16_v2(TheDb1, KSqlStrZ().Ptr(), -1, &stmtHandle, &stmtTailZ);
   554 	if(rc != SQLITE_OK)
   555 	if(rc != SQLITE_OK)
   555 		{
   556 		{
   556 		const void* errMsgZ = sqlite3_errmsg16(TheDb1);
   557 		const void* errMsgZ = sqlite3_errmsg16(TheDb1);
   557 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   558 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   558 		RDebug::Print(_L("'sqlite3_prepare16_v2()' failed, err %d, error msg: \"%S\"\r\n"), rc, &msg);
   559 		TheTest.Printf(_L("'sqlite3_prepare16_v2()' failed, err %d, error msg: \"%S\"\r\n"), rc, &msg);
   559     	TEST(0);
   560     	TEST(0);
   560 		}
   561 		}
   561 	rc = sqlite3_step(stmtHandle);
   562 	rc = sqlite3_step(stmtHandle);
   562 	TEST(rc == SQLITE_DONE);
   563 	TEST(rc == SQLITE_DONE);
   563 
   564 
   569 	rc = sqlite3_prepare16_v2(TheDb1, KSqlStrZ2().Ptr(), -1, &stmtHandle, &stmtTailZ);
   570 	rc = sqlite3_prepare16_v2(TheDb1, KSqlStrZ2().Ptr(), -1, &stmtHandle, &stmtTailZ);
   570 	if(rc != SQLITE_OK)
   571 	if(rc != SQLITE_OK)
   571 		{
   572 		{
   572 		const void* errMsgZ = sqlite3_errmsg16(TheDb1);
   573 		const void* errMsgZ = sqlite3_errmsg16(TheDb1);
   573 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   574 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   574 		RDebug::Print(_L("'sqlite3_prepare16_v2()' failed, err %d, error msg: \"%S\"\r\n"), rc, &msg);
   575 		TheTest.Printf(_L("'sqlite3_prepare16_v2()' failed, err %d, error msg: \"%S\"\r\n"), rc, &msg);
   575     	TEST(0);
   576     	TEST(0);
   576 		}
   577 		}
   577 
   578 
   578 	//parameter checks
   579 	//parameter checks
   579 	TBuf<16> prmNames[5];
   580 	TBuf<16> prmNames[5];
   696 	RFile file;
   697 	RFile file;
   697 	TEST2(file.Open(TheFs, aPath, EFileRead), KErrNone);
   698 	TEST2(file.Open(TheFs, aPath, EFileRead), KErrNone);
   698 	TInt size = 0;
   699 	TInt size = 0;
   699 	TEST2(file.Size(size), KErrNone);
   700 	TEST2(file.Size(size), KErrNone);
   700 	file.Close();
   701 	file.Close();
   701 	RDebug::Print(_L("File \"%S\", size: %d\r\n"), &aPath, size);
   702 	TheTest.Printf(_L("File \"%S\", size: %d\r\n"), &aPath, size);
   702 	}
   703 	}
   703 
   704 
   704 //Executes 8-bit SQL statement	
   705 //Executes 8-bit SQL statement	
   705 static void ExecSql(sqlite3* aDbHandle, const char* aSqlStmt, const TDesC& aMsg)
   706 static void ExecSql(sqlite3* aDbHandle, const char* aSqlStmt, const TDesC& aMsg)
   706 	{
   707 	{
   713 	TInt rc = sqlite3_exec(aDbHandle, aSqlStmt, callback, 0, &errMsg);
   714 	TInt rc = sqlite3_exec(aDbHandle, aSqlStmt, callback, 0, &errMsg);
   714 	if(rc != SQLITE_OK)
   715 	if(rc != SQLITE_OK)
   715 		{
   716 		{
   716 		TPtrC8 ptr8((const TUint8*)errMsg, strlen(errMsg));
   717 		TPtrC8 ptr8((const TUint8*)errMsg, strlen(errMsg));
   717 		TheBuf1.Copy(ptr8);
   718 		TheBuf1.Copy(ptr8);
   718 		RDebug::Print(_L("'sqlite3_exec()' failed, err %d, error msg: \"%S\"\t\n"), rc, &TheBuf1);
   719 		TheTest.Printf(_L("'sqlite3_exec()' failed, err %d, error msg: \"%S\"\t\n"), rc, &TheBuf1);
   719 		TEST(0);
   720 		TEST(0);
   720 		}
   721 		}
   721 	TTime t2;
   722 	TTime t2;
   722 	t2.UniversalTime();
   723 	t2.UniversalTime();
   723 	TTimeIntervalMicroSeconds diffTime = t2.MicroSecondsFrom(t1); 
   724 	TTimeIntervalMicroSeconds diffTime = t2.MicroSecondsFrom(t1); 
   724 	diffTime = diffTime.Int64() / 1000;
   725 	diffTime = diffTime.Int64() / 1000;
   725 	RDebug::Print(_L("%S, time: %d ms\r\n"), &aMsg, (TInt)diffTime.Int64());
   726 	TheTest.Printf(_L("%S, time: %d ms\r\n"), &aMsg, (TInt)diffTime.Int64());
   726 	}
   727 	}
   727 
   728 
   728 //This function searches aString argument for ';' occurences.
   729 //This function searches aString argument for ';' occurences.
   729 //Every time when it finds a ';' character, the function places a 0 right after the ';' and
   730 //Every time when it finds a ';' character, the function places a 0 right after the ';' and
   730 //tests the just created, zero-terminated substring if it is a comlpete SQL statement.
   731 //tests the just created, zero-terminated substring if it is a comlpete SQL statement.
   794 			}
   795 			}
   795 		if(err != SQLITE_DONE && err != SQLITE_OK)
   796 		if(err != SQLITE_DONE && err != SQLITE_OK)
   796 			{
   797 			{
   797 			const void* errMsgZ = sqlite3_errmsg16(aDbHandle);
   798 			const void* errMsgZ = sqlite3_errmsg16(aDbHandle);
   798 			TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   799 			TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   799 			RDebug::Print(_L("'sqlite3_exec16()' failed, err %d, error msg: \"%S\"\t\n"), err, &msg);
   800 			TheTest.Printf(_L("'sqlite3_exec16()' failed, err %d, error msg: \"%S\"\t\n"), err, &msg);
   800 			TEST(0);
   801 			TEST(0);
   801 			}
   802 			}
   802 		}
   803 		}
   803 	TTime t2;
   804 	TTime t2;
   804 	t2.UniversalTime();
   805 	t2.UniversalTime();
   805 	TTimeIntervalMicroSeconds diffTime = t2.MicroSecondsFrom(t1); 
   806 	TTimeIntervalMicroSeconds diffTime = t2.MicroSecondsFrom(t1); 
   806 	diffTime = diffTime.Int64() / 1000;
   807 	diffTime = diffTime.Int64() / 1000;
   807 	RDebug::Print(_L("%S, time: %d ms\r\n"), &aMsg, (TInt)diffTime.Int64());
   808 	TheTest.Printf(_L("%S, time: %d ms\r\n"), &aMsg, (TInt)diffTime.Int64());
   808 	}
   809 	}
   809 
   810 
   810 //////////////////////////////////////////////////////////////////////////////////////////////////
   811 //////////////////////////////////////////////////////////////////////////////////////////////////
   811 //////////////////////////////////////////////////////////////////////////////////////////////////
   812 //////////////////////////////////////////////////////////////////////////////////////////////////
   812 //////////////////////////////////////////////////////////////////////////////////////////////////
   813 //////////////////////////////////////////////////////////////////////////////////////////////////
   960 	TheFs.Delete(aDbFilePath);
   961 	TheFs.Delete(aDbFilePath);
   961 	
   962 	
   962 	TBuf<KMaxFileName + 1> fname;
   963 	TBuf<KMaxFileName + 1> fname;
   963 	fname.Copy(aDbFilePath);
   964 	fname.Copy(aDbFilePath);
   964 	//Open database
   965 	//Open database
   965 	RDebug::Print(_L("Open database\r\n"));
   966 	TheTest.Printf(_L("Open database\r\n"));
   966 	sqlite3 *dbHandle = NULL;
   967 	sqlite3 *dbHandle = NULL;
   967 	TInt rc = sqlite3_open16(fname.PtrZ(), &dbHandle);//!!!!16-bit encoding!!!!!
   968 	TInt rc = sqlite3_open16(fname.PtrZ(), &dbHandle);//!!!!16-bit encoding!!!!!
   968 	if(rc != SQLITE_OK)
   969 	if(rc != SQLITE_OK)
   969 		{
   970 		{
   970 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
   971 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
   971 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   972 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   972 		RDebug::Print(_L("'sqlite3_open()' failed, file %S, err %d, error msg: \"%S\"\t\n"), &aDbFilePath, rc, &msg);
   973 		TheTest.Printf(_L("'sqlite3_open()' failed, file %S, err %d, error msg: \"%S\"\t\n"), &aDbFilePath, rc, &msg);
   973 		TEST(0);
   974 		TEST(0);
   974 		}
   975 		}
   975 	TEST(dbHandle != NULL);
   976 	TEST(dbHandle != NULL);
   976 	//Create "CompareF" collation	
   977 	//Create "CompareF" collation	
   977 	RDebug::Print(_L("Create \"CompareF\" collation\r\n"));
   978 	TheTest.Printf(_L("Create \"CompareF\" collation\r\n"));
   978 	_LIT(KCmpF, "CmpF16\x0");
   979 	_LIT(KCmpF, "CmpF16\x0");
   979 	rc = sqlite3_create_collation16(dbHandle, (const char*)(KCmpF().Ptr()), SQLITE_UTF16 | SQLITE_UTF16_ALIGNED, NULL, &CmpF16);
   980 	rc = sqlite3_create_collation16(dbHandle, (const char*)(KCmpF().Ptr()), SQLITE_UTF16 | SQLITE_UTF16_ALIGNED, NULL, &CmpF16);
   980   	if(rc)
   981   	if(rc)
   981   		{
   982   		{
   982 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
   983 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
   983 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   984 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   984 		RDebug::Print(_L("Err=%S\r\n"), &msg);
   985 		TheTest.Printf(_L("Err=%S\r\n"), &msg);
   985 		TEST(0);
   986 		TEST(0);
   986   		}
   987   		}
   987 	//Create "CompareC" collation	
   988 	//Create "CompareC" collation	
   988 	RDebug::Print(_L("Create \"CompareC\" collation\r\n"));
   989   	TheTest.Printf(_L("Create \"CompareC\" collation\r\n"));
   989 	_LIT(KCmpC, "CmpC16\x0");
   990 	_LIT(KCmpC, "CmpC16\x0");
   990 	rc = sqlite3_create_collation16(dbHandle, (const char*)(KCmpC().Ptr()), SQLITE_UTF16 | SQLITE_UTF16_ALIGNED, NULL, &CmpC16);
   991 	rc = sqlite3_create_collation16(dbHandle, (const char*)(KCmpC().Ptr()), SQLITE_UTF16 | SQLITE_UTF16_ALIGNED, NULL, &CmpC16);
   991   	if(rc)
   992   	if(rc)
   992   		{
   993   		{
   993 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
   994 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
   994 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   995 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
   995 		RDebug::Print(_L("Err=%S\r\n"), &msg);
   996 		TheTest.Printf(_L("Err=%S\r\n"), &msg);
   996 		TEST(0);
   997 		TEST(0);
   997   		}
   998   		}
   998 	//Create database schema
   999 	//Create database schema
   999 	TheCmpFCallCnt = TheCmpCCallCnt = 0;
  1000 	TheCmpFCallCnt = TheCmpCCallCnt = 0;
  1000 	RDebug::Print(_L("Create database schema\r\n"));
  1001 	TheTest.Printf(_L("Create database schema\r\n"));
  1001 	HBufC16* createSqlZ = ReadSQL16(_L("z:\\test\\contacts_schema_to_vendors.sql"));
  1002 	HBufC16* createSqlZ = ReadSQL16(_L("z:\\test\\contacts_schema_to_vendors.sql"));
  1002 	TPtr sql = createSqlZ->Des();
  1003 	TPtr sql = createSqlZ->Des();
  1003 	ExecSql16(dbHandle, sql, _L("Create schema"));
  1004 	ExecSql16(dbHandle, sql, _L("Create schema"));
  1004 	delete createSqlZ;
  1005 	delete createSqlZ;
  1005 	RDebug::Print(_L("CmpF() call cnt %d, CmpC() call cnt %d\r\n"), TheCmpFCallCnt, TheCmpCCallCnt);
  1006 	TheTest.Printf(_L("CmpF() call cnt %d, CmpC() call cnt %d\r\n"), TheCmpFCallCnt, TheCmpCCallCnt);
  1006 	//Add 1001 "simple" contacts
  1007 	//Add 1001 "simple" contacts
  1007 	TheCmpFCallCnt = TheCmpCCallCnt = 0;
  1008 	TheCmpFCallCnt = TheCmpCCallCnt = 0;
  1008 	RDebug::Print(_L("Add 1001 \"simple\" contacts\r\n"));
  1009 	TheTest.Printf(_L("Add 1001 \"simple\" contacts\r\n"));
  1009 	HBufC16* addSqlZ = ReadSQL16(KSimpleContactsSqlFile);
  1010 	HBufC16* addSqlZ = ReadSQL16(KSimpleContactsSqlFile);
  1010 	RDebug::Print(_L("--\r\n"));
  1011 	TheTest.Printf(_L("--\r\n"));
  1011 	sql.Set(addSqlZ->Des());
  1012 	sql.Set(addSqlZ->Des());
  1012 	ExecSql16(dbHandle, sql, _L("Add simple contacts"));
  1013 	ExecSql16(dbHandle, sql, _L("Add simple contacts"));
  1013 	delete addSqlZ;
  1014 	delete addSqlZ;
  1014 	RDebug::Print(_L("CmpF() call cnt %d, CmpC() call cnt %d\r\n"), TheCmpFCallCnt, TheCmpCCallCnt);
  1015 	TheTest.Printf(_L("CmpF() call cnt %d, CmpC() call cnt %d\r\n"), TheCmpFCallCnt, TheCmpCCallCnt);
  1015 	//Print the number of records
  1016 	//Print the number of records
  1016 	RDebug::Print(_L("Print the number of records\r\n"));
  1017 	TheTest.Printf(_L("Print the number of records\r\n"));
  1017 	TBuf<40> testSql(_L("SELECT COUNT(*) FROM CONTACTS"));
  1018 	TBuf<40> testSql(_L("SELECT COUNT(*) FROM CONTACTS"));
  1018 	testSql.Append(TChar(0));
  1019 	testSql.Append(TChar(0));
  1019 	ExecSql16(dbHandle, testSql, _L("--"));
  1020 	ExecSql16(dbHandle, testSql, _L("--"));
  1020 	
  1021 	
  1021 	//Create index: "First name, Last name"
  1022 	//Create index: "First name, Last name"
  1022 	TheCmpFCallCnt = TheCmpCCallCnt = 0;
  1023 	TheCmpFCallCnt = TheCmpCCallCnt = 0;
  1023 	RDebug::Print(_L("Create index: \"First name, Last name\"\r\n"));
  1024 	TheTest.Printf(_L("Create index: \"First name, Last name\"\r\n"));
  1024 	TBuf<100> createIndexStmt(_L("CREATE INDEX Idx1 ON identitytable(cm_firstname COLLATE CmpC16, cm_lastname COLLATE CmpC16)"));
  1025 	TBuf<100> createIndexStmt(_L("CREATE INDEX Idx1 ON identitytable(cm_firstname COLLATE CmpC16, cm_lastname COLLATE CmpC16)"));
  1025 	createIndexStmt.Append(TChar(0));
  1026 	createIndexStmt.Append(TChar(0));
  1026 	ExecSql16(dbHandle, createIndexStmt, _L("Create index"));
  1027 	ExecSql16(dbHandle, createIndexStmt, _L("Create index"));
  1027 	RDebug::Print(_L("CmpF() call cnt %d, CmpC() call cnt %d\r\n"), TheCmpFCallCnt, TheCmpCCallCnt);
  1028 	TheTest.Printf(_L("CmpF() call cnt %d, CmpC() call cnt %d\r\n"), TheCmpFCallCnt, TheCmpCCallCnt);
  1028 
  1029 
  1029 	RDebug::Print(_L("Close database\r\n"));
  1030 	TheTest.Printf(_L("Close database\r\n"));
  1030    	sqlite3_close(dbHandle);
  1031    	sqlite3_close(dbHandle);
  1031 
  1032 
  1032 	PrintFileSize(aDbFilePath);
  1033 	PrintFileSize(aDbFilePath);
  1033 	}
  1034 	}
  1034 
  1035 
  1059 	TheFs.Delete(aDbFilePath);
  1060 	TheFs.Delete(aDbFilePath);
  1060 	
  1061 	
  1061 	TBuf8<KMaxFileName + 1> fname;
  1062 	TBuf8<KMaxFileName + 1> fname;
  1062 	fname.Copy(aDbFilePath);
  1063 	fname.Copy(aDbFilePath);
  1063 	
  1064 	
  1064 	RDebug::Print(_L("%S\r\n"), &aMsg);
  1065 	TheTest.Printf(_L("%S\r\n"), &aMsg);
  1065 	RDebug::Print(_L("Open database\r\n"));
  1066 	TheTest.Printf(_L("Open database\r\n"));
  1066 	sqlite3 *dbHandle = NULL;
  1067 	sqlite3 *dbHandle = NULL;
  1067 	TInt rc = sqlite3_open((const char*)fname.PtrZ(), &dbHandle);
  1068 	TInt rc = sqlite3_open((const char*)fname.PtrZ(), &dbHandle);
  1068 	if(rc != SQLITE_OK)
  1069 	if(rc != SQLITE_OK)
  1069 		{
  1070 		{
  1070 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
  1071 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
  1071 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
  1072 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
  1072 		RDebug::Print(_L("'sqlite3_open()' failed, file %S, err %d, error msg: \"%S\"\r\n"), &aDbFilePath, rc, &msg);
  1073 		TheTest.Printf(_L("'sqlite3_open()' failed, file %S, err %d, error msg: \"%S\"\r\n"), &aDbFilePath, rc, &msg);
  1073 		TEST(0);
  1074 		TEST(0);
  1074 		}
  1075 		}
  1075 	TEST(dbHandle != NULL);
  1076 	TEST(dbHandle != NULL);
  1076 	
  1077 	
  1077 	RDebug::Print(_L("Create 'CompareF' collation\r\n"));
  1078 	TheTest.Printf(_L("Create 'CompareF' collation\r\n"));
  1078 	_LIT8(KCmpF, "CmpF8\x0");
  1079 	_LIT8(KCmpF, "CmpF8\x0");
  1079 	rc = sqlite3_create_collation(dbHandle, (const char*)(KCmpF().Ptr()), SQLITE_UTF8, NULL, &CmpF8);
  1080 	rc = sqlite3_create_collation(dbHandle, (const char*)(KCmpF().Ptr()), SQLITE_UTF8, NULL, &CmpF8);
  1080   	if(rc)
  1081   	if(rc)
  1081   		{
  1082   		{
  1082 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
  1083 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
  1083 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
  1084 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
  1084 		RDebug::Print(_L("'sqlite3_create_collation()' failed, file %S, err %d, error msg: \"%S\"\r\n"), &aDbFilePath, rc, &msg);
  1085 		TheTest.Printf(_L("'sqlite3_create_collation()' failed, file %S, err %d, error msg: \"%S\"\r\n"), &aDbFilePath, rc, &msg);
  1085 		TEST(0);
  1086 		TEST(0);
  1086   		}
  1087   		}
  1087 
  1088 
  1088 	RDebug::Print(_L("Create 'CompareC' collation\r\n"));
  1089   	TheTest.Printf(_L("Create 'CompareC' collation\r\n"));
  1089 	_LIT8(KCmpC, "CmpC8\x0");
  1090 	_LIT8(KCmpC, "CmpC8\x0");
  1090 	rc = sqlite3_create_collation(dbHandle, (const char*)(KCmpC().Ptr()), SQLITE_UTF8, NULL, &CmpC8);
  1091 	rc = sqlite3_create_collation(dbHandle, (const char*)(KCmpC().Ptr()), SQLITE_UTF8, NULL, &CmpC8);
  1091   	if(rc)
  1092   	if(rc)
  1092   		{
  1093   		{
  1093 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
  1094 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
  1094 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
  1095 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
  1095 		RDebug::Print(_L("'sqlite3_create_collation()' failed, file %S, err %d, error msg: \"%S\"\r\n"), &aDbFilePath, rc, &msg);
  1096 		TheTest.Printf(_L("'sqlite3_create_collation()' failed, file %S, err %d, error msg: \"%S\"\r\n"), &aDbFilePath, rc, &msg);
  1096 		TEST(0);
  1097 		TEST(0);
  1097   		}
  1098   		}
  1098 
  1099 
  1099 	RDebug::Print(_L("Create database schema\r\n"));
  1100   	TheTest.Printf(_L("Create database schema\r\n"));
  1100 	char* createSqlZ = ReadSQL2(_L("z:\\test\\contacts_schema_to_vendors.sql"));
  1101 	char* createSqlZ = ReadSQL2(_L("z:\\test\\contacts_schema_to_vendors.sql"));
  1101 	ExecSql(dbHandle, createSqlZ, _L("Create schema"));
  1102 	ExecSql(dbHandle, createSqlZ, _L("Create schema"));
  1102 	delete [] createSqlZ;
  1103 	delete [] createSqlZ;
  1103 
  1104 
  1104 	RDebug::Print(_L("Add 1001 contacts\r\n"));
  1105 	TheTest.Printf(_L("Add 1001 contacts\r\n"));
  1105 	char* addSqlZ = ReadSQL2(aAddContactsFile);
  1106 	char* addSqlZ = ReadSQL2(aAddContactsFile);
  1106 	ExecSql(dbHandle, addSqlZ, _L("Add contacts"));
  1107 	ExecSql(dbHandle, addSqlZ, _L("Add contacts"));
  1107 	delete [] addSqlZ;
  1108 	delete [] addSqlZ;
  1108 
  1109 
  1109 	RDebug::Print(_L("Print the number of records\r\n"));
  1110 	TheTest.Printf(_L("Print the number of records\r\n"));
  1110 	const char testSql[] = {"SELECT COUNT(*) FROM CONTACTS"};
  1111 	const char testSql[] = {"SELECT COUNT(*) FROM CONTACTS"};
  1111 	ExecSql(dbHandle, testSql, _L("SELECT COUNT(*)"));
  1112 	ExecSql(dbHandle, testSql, _L("SELECT COUNT(*)"));
  1112 	
  1113 	
  1113 	RDebug::Print(_L("Create index (using 'CompareF' collation): 'FirstName, Surname'\r\n"));
  1114 	TheTest.Printf(_L("Create index (using 'CompareF' collation): 'FirstName, Surname'\r\n"));
  1114 	_LIT8(KCreateIndexStmt, "CREATE INDEX Idx1 ON identitytable(cm_firstname COLLATE CmpF8, cm_lastname COLLATE CmpF8)\x0");
  1115 	_LIT8(KCreateIndexStmt, "CREATE INDEX Idx1 ON identitytable(cm_firstname COLLATE CmpF8, cm_lastname COLLATE CmpF8)\x0");
  1115 	ExecSql(dbHandle, (const char*)(KCreateIndexStmt().Ptr()), _L("Create index"));
  1116 	ExecSql(dbHandle, (const char*)(KCreateIndexStmt().Ptr()), _L("Create index"));
  1116 	RDebug::Print(_L("CompareF() called %d times\r\n"), TheCmpFCallCnt);
  1117 	TheTest.Printf(_L("CompareF() called %d times\r\n"), TheCmpFCallCnt);
  1117 
  1118 
  1118 /* BEGIN OF - TEST CASE 1 "Select all contacts which first name begins with 'a' " */	
  1119 /* BEGIN OF - TEST CASE 1 "Select all contacts which first name begins with 'a' " */	
  1119 
  1120 
  1120 	RDebug::Print(_L("Prepare 'Select all contacts where the first name begins with 'A'' SQL string\r\n"));
  1121 	TheTest.Printf(_L("Prepare 'Select all contacts where the first name begins with 'A'' SQL string\r\n"));
  1121 	_LIT8(KSearchStmt, "SELECT cm_firstname, cm_lastname FROM identitytable WHERE cm_firstname LIKE 'A%'\x0");
  1122 	_LIT8(KSearchStmt, "SELECT cm_firstname, cm_lastname FROM identitytable WHERE cm_firstname LIKE 'A%'\x0");
  1122 	sqlite3_stmt* stmtHandle = NULL;
  1123 	sqlite3_stmt* stmtHandle = NULL;
  1123 	const char* stmtTailZ = NULL;
  1124 	const char* stmtTailZ = NULL;
  1124 	TTime t1;
  1125 	TTime t1;
  1125 	t1.UniversalTime();
  1126 	t1.UniversalTime();
  1130 	TTime t2;
  1131 	TTime t2;
  1131 	t2.UniversalTime();
  1132 	t2.UniversalTime();
  1132 	TTimeIntervalMicroSeconds diffTime = t2.MicroSecondsFrom(t1); 
  1133 	TTimeIntervalMicroSeconds diffTime = t2.MicroSecondsFrom(t1); 
  1133 	diffTime = diffTime.Int64() / 1000;
  1134 	diffTime = diffTime.Int64() / 1000;
  1134 	TInt t = (TInt)diffTime.Int64();
  1135 	TInt t = (TInt)diffTime.Int64();
  1135 	RDebug::Print(_L("'Prepare SQL statement' time: %d ms\r\n"), t);
  1136 	TheTest.Printf(_L("'Prepare SQL statement' time: %d ms\r\n"), t);
  1136 
  1137 
  1137 	RDebug::Print(_L("Step the prepared SQL statement\r\n"));
  1138 	TheTest.Printf(_L("Step the prepared SQL statement\r\n"));
  1138 	TInt totalCmpFCnt = 0;
  1139 	TInt totalCmpFCnt = 0;
  1139 	t1.UniversalTime();
  1140 	t1.UniversalTime();
  1140 	TheCmpFCallCnt = 0;
  1141 	TheCmpFCallCnt = 0;
  1141 	TInt recordCnt = 0;
  1142 	TInt recordCnt = 0;
  1142 	while((rc = sqlite3_step(stmtHandle)) == SQLITE_ROW)
  1143 	while((rc = sqlite3_step(stmtHandle)) == SQLITE_ROW)
  1145 		//TPtrC8 p(firstName, strlen((const char*)firstName));
  1146 		//TPtrC8 p(firstName, strlen((const char*)firstName));
  1146 		//TBuf<100> p1; p1.Copy(p);
  1147 		//TBuf<100> p1; p1.Copy(p);
  1147 		//const TUint8* surname = sqlite3_column_text(stmtHandle, 1);
  1148 		//const TUint8* surname = sqlite3_column_text(stmtHandle, 1);
  1148 		//p.Set(surname, strlen((const char*)surname));
  1149 		//p.Set(surname, strlen((const char*)surname));
  1149 		//TBuf<100> p2; p2.Copy(p);
  1150 		//TBuf<100> p2; p2.Copy(p);
  1150 		//RDebug::Print(_L("Found rec: %S, %S\r\n"), &p1, &p2);
  1151 		//TheTest.Printf(_L("Found rec: %S, %S\r\n"), &p1, &p2);
  1151 		++recordCnt;
  1152 		++recordCnt;
  1152 		}
  1153 		}
  1153 	totalCmpFCnt += TheCmpFCallCnt;
  1154 	totalCmpFCnt += TheCmpFCallCnt;
  1154 	TEST(rc == SQLITE_OK || rc == SQLITE_DONE);
  1155 	TEST(rc == SQLITE_OK || rc == SQLITE_DONE);
  1155 	t2.UniversalTime();
  1156 	t2.UniversalTime();
  1156 	diffTime = t2.MicroSecondsFrom(t1); 
  1157 	diffTime = t2.MicroSecondsFrom(t1); 
  1157 	diffTime = diffTime.Int64() / 1000;
  1158 	diffTime = diffTime.Int64() / 1000;
  1158 	t = (TInt)diffTime.Int64();
  1159 	t = (TInt)diffTime.Int64();
  1159 	RDebug::Print(_L("'Stepping' time: %d ms, found records: %d\r\n"), t, recordCnt);
  1160 	TheTest.Printf(_L("'Stepping' time: %d ms, found records: %d\r\n"), t, recordCnt);
  1160 	RDebug::Print(_L("Total 'search' ('CompareF' used) operations=%d\r\n"), totalCmpFCnt);
  1161 	TheTest.Printf(_L("Total 'search' ('CompareF' used) operations=%d\r\n"), totalCmpFCnt);
  1161 
  1162 
  1162 	sqlite3_finalize(stmtHandle);
  1163 	sqlite3_finalize(stmtHandle);
  1163 	stmtHandle = NULL;
  1164 	stmtHandle = NULL;
  1164 
  1165 
  1165 /* END OF - TEST CASE 1 "Select all contacts which first name begins with 'a' " */	
  1166 /* END OF - TEST CASE 1 "Select all contacts which first name begins with 'a' " */	
  1166 
  1167 
  1167 /*	BEGIN OF - TEST CASE 2 "Do 100 searches in 1001 contacts" */
  1168 /*	BEGIN OF - TEST CASE 2 "Do 100 searches in 1001 contacts" */
  1168 
  1169 
  1169 	RDebug::Print(_L("Prepare 'SELECT FirstName, Surname...' SQL string\r\n"));
  1170 	TheTest.Printf(_L("Prepare 'SELECT FirstName, Surname...' SQL string\r\n"));
  1170 	_LIT8(KSearchStmt2, "SELECT cm_firstname, cm_lastname FROM identitytable WHERE cm_firstname = :Prm1 AND cm_lastname = :Prm2\x0");
  1171 	_LIT8(KSearchStmt2, "SELECT cm_firstname, cm_lastname FROM identitytable WHERE cm_firstname = :Prm1 AND cm_lastname = :Prm2\x0");
  1171 	stmtHandle = NULL;
  1172 	stmtHandle = NULL;
  1172 	stmtTailZ = NULL;
  1173 	stmtTailZ = NULL;
  1173 	t1.UniversalTime();
  1174 	t1.UniversalTime();
  1174 	rc = sqlite3_prepare_v2(dbHandle, (const char*)(KSearchStmt2().Ptr()), -1, &stmtHandle, &stmtTailZ);
  1175 	rc = sqlite3_prepare_v2(dbHandle, (const char*)(KSearchStmt2().Ptr()), -1, &stmtHandle, &stmtTailZ);
  1177 	TEST(!stmtTailZ || strlen(stmtTailZ) == 0);
  1178 	TEST(!stmtTailZ || strlen(stmtTailZ) == 0);
  1178 	t2.UniversalTime();
  1179 	t2.UniversalTime();
  1179 	diffTime = t2.MicroSecondsFrom(t1); 
  1180 	diffTime = t2.MicroSecondsFrom(t1); 
  1180 	diffTime = diffTime.Int64() / 1000;
  1181 	diffTime = diffTime.Int64() / 1000;
  1181 	t = (TInt)diffTime.Int64();
  1182 	t = (TInt)diffTime.Int64();
  1182 	RDebug::Print(_L("'Prepare SQL statement' time: %d ms\r\n"), t);
  1183 	TheTest.Printf(_L("'Prepare SQL statement' time: %d ms\r\n"), t);
  1183 	
  1184 	
  1184 	TInt idxPrm1 = sqlite3_bind_parameter_index(stmtHandle, ":Prm1");
  1185 	TInt idxPrm1 = sqlite3_bind_parameter_index(stmtHandle, ":Prm1");
  1185 	TEST(idxPrm1 > 0);
  1186 	TEST(idxPrm1 > 0);
  1186 	TInt idxPrm2 = sqlite3_bind_parameter_index(stmtHandle, ":Prm2");
  1187 	TInt idxPrm2 = sqlite3_bind_parameter_index(stmtHandle, ":Prm2");
  1187 	TEST(idxPrm2 > 0);
  1188 	TEST(idxPrm2 > 0);
  1188 	
  1189 	
  1189 	RDebug::Print(_L("Do %d searches using the prepared SQL statement\r\n"), KNamesCnt);
  1190 	TheTest.Printf(_L("Do %d searches using the prepared SQL statement\r\n"), KNamesCnt);
  1190 	totalCmpFCnt = 0;
  1191 	totalCmpFCnt = 0;
  1191 	t1.UniversalTime();
  1192 	t1.UniversalTime();
  1192 	for(TInt i=0;i<KNamesCnt;++i)
  1193 	for(TInt i=0;i<KNamesCnt;++i)
  1193 		{
  1194 		{
  1194 		const TDesC8& firstName = KNames[i].iFirstName;
  1195 		const TDesC8& firstName = KNames[i].iFirstName;
  1212 		}
  1213 		}
  1213 	t2.UniversalTime();
  1214 	t2.UniversalTime();
  1214 	diffTime = t2.MicroSecondsFrom(t1); 
  1215 	diffTime = t2.MicroSecondsFrom(t1); 
  1215 	diffTime = diffTime.Int64() / 1000;
  1216 	diffTime = diffTime.Int64() / 1000;
  1216 	t = (TInt)diffTime.Int64();
  1217 	t = (TInt)diffTime.Int64();
  1217 	RDebug::Print(_L("'Search' time: %d ms\r\n"), t);
  1218 	TheTest.Printf(_L("'Search' time: %d ms\r\n"), t);
  1218 	RDebug::Print(_L("Total 'search' ('CompareF' used) operations=%d, average_per_iter=%d\r\n"), totalCmpFCnt, totalCmpFCnt/KNamesCnt);
  1219 	TheTest.Printf(_L("Total 'search' ('CompareF' used) operations=%d, average_per_iter=%d\r\n"), totalCmpFCnt, totalCmpFCnt/KNamesCnt);
  1219 
  1220 
  1220 	sqlite3_finalize(stmtHandle);
  1221 	sqlite3_finalize(stmtHandle);
  1221 	stmtHandle = NULL;
  1222 	stmtHandle = NULL;
  1222 	
  1223 	
  1223 /* END OF - TEST CASE 2 "Do 100 searches in 1001 contacts" */	
  1224 /* END OF - TEST CASE 2 "Do 100 searches in 1001 contacts" */	
  1226 	sqlite3_finalize(stmtHandle);
  1227 	sqlite3_finalize(stmtHandle);
  1227 	t2.UniversalTime();
  1228 	t2.UniversalTime();
  1228 	diffTime = t2.MicroSecondsFrom(t1); 
  1229 	diffTime = t2.MicroSecondsFrom(t1); 
  1229 	diffTime = diffTime.Int64() / 1000;
  1230 	diffTime = diffTime.Int64() / 1000;
  1230 	t = (TInt)diffTime.Int64();
  1231 	t = (TInt)diffTime.Int64();
  1231 	RDebug::Print(_L("'Finalize SQL statement' time: %d ms\r\n"), t);
  1232 	TheTest.Printf(_L("'Finalize SQL statement' time: %d ms\r\n"), t);
  1232 
  1233 
  1233    	sqlite3_close(dbHandle);
  1234    	sqlite3_close(dbHandle);
  1234 	PrintFileSize(aDbFilePath);
  1235 	PrintFileSize(aDbFilePath);
  1235 	}
  1236 	}
  1236 
  1237 
  1320 	TInt rc = sqlite3_open(KDbName1, &dbHandle);
  1321 	TInt rc = sqlite3_open(KDbName1, &dbHandle);
  1321 	if(rc != SQLITE_OK)
  1322 	if(rc != SQLITE_OK)
  1322 		{
  1323 		{
  1323 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
  1324 		const void* errMsgZ = sqlite3_errmsg16(dbHandle);
  1324 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
  1325 		TPtrC msg(reinterpret_cast <const TText16*> (errMsgZ), wcslen(reinterpret_cast <const wchar_t*> (errMsgZ)));
  1325 		RDebug::Print(_L("'sqlite3_open()' failed, err %d, error msg: \"%S\"\r\n"), rc, &msg);
  1326 		TheTest.Printf(_L("'sqlite3_open()' failed, err %d, error msg: \"%S\"\r\n"), rc, &msg);
  1326 		TEST(0);
  1327 		TEST(0);
  1327 		}
  1328 		}
  1328 	TEST(dbHandle != NULL);
  1329 	TEST(dbHandle != NULL);
  1329 
  1330 
  1330 	char *zErrMsg = 0;
  1331 	char *zErrMsg = 0;
  1332 	_LIT8(KSql1, "CREATE TEMP TABLE A(F1 INTEGER)\x0");
  1333 	_LIT8(KSql1, "CREATE TEMP TABLE A(F1 INTEGER)\x0");
  1333 	rc = sqlite3_exec(dbHandle, reinterpret_cast <const char*> (KSql1().Ptr()), callback, 0, &zErrMsg);
  1334 	rc = sqlite3_exec(dbHandle, reinterpret_cast <const char*> (KSql1().Ptr()), callback, 0, &zErrMsg);
  1334 	if(rc != SQLITE_OK)
  1335 	if(rc != SQLITE_OK)
  1335 		{
  1336 		{
  1336   		TPtrC p = ConvertToUtf16(zErrMsg);
  1337   		TPtrC p = ConvertToUtf16(zErrMsg);
  1337   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
  1338   		TheTest.Printf(_L("SQL error %d, msg: %S\n"), rc, &p);
  1338     	sqlite3_free(zErrMsg);
  1339     	sqlite3_free(zErrMsg);
  1339     	TEST(0);
  1340     	TEST(0);
  1340 		}
  1341 		}
  1341 
  1342 
  1342 	_LIT8(KSql2, "INSERT INTO A(F1) VALUES(2)\x0");
  1343 	_LIT8(KSql2, "INSERT INTO A(F1) VALUES(2)\x0");
  1343 	rc = sqlite3_exec(dbHandle, reinterpret_cast <const char*> (KSql2().Ptr()), callback, 0, &zErrMsg);
  1344 	rc = sqlite3_exec(dbHandle, reinterpret_cast <const char*> (KSql2().Ptr()), callback, 0, &zErrMsg);
  1344 	if(rc != SQLITE_OK)
  1345 	if(rc != SQLITE_OK)
  1345 		{
  1346 		{
  1346   		TPtrC p = ConvertToUtf16(zErrMsg);
  1347   		TPtrC p = ConvertToUtf16(zErrMsg);
  1347   		RDebug::Print(_L("SQL error %d, msg: %S\n"), rc, &p);
  1348   		TheTest.Printf(_L("SQL error %d, msg: %S\n"), rc, &p);
  1348     	sqlite3_free(zErrMsg);
  1349     	sqlite3_free(zErrMsg);
  1349     	TEST(0);
  1350     	TEST(0);
  1350 		}
  1351 		}
  1351 
  1352 
  1352    	sqlite3_close(dbHandle);
  1353    	sqlite3_close(dbHandle);