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) |
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;\ |
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); |
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); |
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(); |
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); |
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); |