17 #include <e32math.h> |
17 #include <e32math.h> |
18 #include <bautils.h> |
18 #include <bautils.h> |
19 #include <hal.h> |
19 #include <hal.h> |
20 #include <stdlib.h> |
20 #include <stdlib.h> |
21 #include <sqldb.h> |
21 #include <sqldb.h> |
|
22 #include "t_sqlcmdlineutil.h" |
22 #include "SqlSrvStrings.h" |
23 #include "SqlSrvStrings.h" |
23 #include "sqlite3.h" |
24 #include "sqlite3.h" |
24 #include "SqliteSymbian.h" |
25 #include "SqliteSymbian.h" |
25 |
26 |
26 /////////////////////////////////////////////////////////////////////////////////////// |
27 /////////////////////////////////////////////////////////////////////////////////////// |
27 |
28 |
28 RTest TheTest(_L("t_sqlperformance test")); |
29 RTest TheTest(_L("t_sqlperformance test")); |
29 RFs TheFs; |
30 RFs TheFs; |
30 |
|
31 TBuf<200> TheTestTitle; |
31 TBuf<200> TheTestTitle; |
32 TBuf<256> TheCmd; |
32 TCmdLineParams TheCmdLineParams; |
33 TParse TheParse; |
33 TBuf8<200> TheSqlConfigString; |
34 TBuf<8> TheDriveName; |
34 |
35 |
35 _LIT(KUtf8, "UTF8 "); |
36 _LIT8(KDbEncodingUtf8, "encoding=UTF-8"); |
36 _LIT(KUtf16, "UTF16"); |
37 _LIT(KDbEncodingUtf8text, "UTF8 encoded db"); |
|
38 _LIT(KDbEncodingUtf16text, "UTF16 encoded db"); |
|
39 |
37 |
40 TFileName TheSecureDbName; |
38 TFileName TheSecureDbName; |
41 TFileName TheNonSecureDbName; |
39 TFileName TheNonSecureDbName; |
42 TFileName TheNonSecureDbName2; |
40 TFileName TheNonSecureDbName2; |
43 TFileName TheNonSecureTmpDbName; |
41 TFileName TheNonSecureTmpDbName; |
44 TFileName TheSglRecDbFileName; |
42 TFileName TheSglRecDbFileName; |
45 |
43 |
46 enum TDbEncoding |
|
47 { |
|
48 EDbUtf8, |
|
49 EDbUtf16 |
|
50 }; |
|
51 |
|
52 TDbEncoding TheDbEncoding; |
|
53 |
|
54 _LIT(KSqlServerPrivateDir, "\\private\\10281e17\\"); |
44 _LIT(KSqlServerPrivateDir, "\\private\\10281e17\\"); |
55 |
45 |
56 _LIT(KCreateDbScript, "z:\\test\\contacts_schema_to_vendors.sql"); |
46 _LIT(KCreateDbScript, "z:\\test\\contacts_schema_to_vendors.sql"); |
57 _LIT(KFillDbScript, "z:\\test\\add_simple_contacts.sql"); |
47 _LIT(KFillDbScript, "z:\\test\\add_simple_contacts.sql"); |
58 |
48 |
1037 (void)fm->Copy(TheNonSecureTmpDbName, aDbFileName); |
1029 (void)fm->Copy(TheNonSecureTmpDbName, aDbFileName); |
1038 (void)fm->Delete(TheNonSecureTmpDbName); |
1030 (void)fm->Delete(TheNonSecureTmpDbName); |
1039 delete fm; |
1031 delete fm; |
1040 } |
1032 } |
1041 //Explicit PerformanceTest2() template instantiations. |
1033 //Explicit PerformanceTest2() template instantiations. |
1042 template void PerformanceTest2<EDbUtf8, HBufC8, TPtrC8, TDesC8>(const TDesC&, const TDesC8&, const TDesC8&, const TDesC8&, const TDesC8&); |
1034 template void PerformanceTest2<TCmdLineParams::EDbUtf8, HBufC8, TPtrC8, TDesC8>(const TDesC&, const TDesC8&, const TDesC8&, const TDesC8&, const TDesC8&); |
1043 template void PerformanceTest2<EDbUtf16, HBufC8, TPtrC8, TDesC8>(const TDesC&, const TDesC8&, const TDesC8&, const TDesC8&, const TDesC8&); |
1035 template void PerformanceTest2<TCmdLineParams::EDbUtf16, HBufC8, TPtrC8, TDesC8>(const TDesC&, const TDesC8&, const TDesC8&, const TDesC8&, const TDesC8&); |
1044 template void PerformanceTest2<EDbUtf8, HBufC16, TPtrC16, TDesC16>(const TDesC&, const TDesC16&, const TDesC16&, const TDesC16&, const TDesC16&); |
1036 template void PerformanceTest2<TCmdLineParams::EDbUtf8, HBufC16, TPtrC16, TDesC16>(const TDesC&, const TDesC16&, const TDesC16&, const TDesC16&, const TDesC16&); |
1045 template void PerformanceTest2<EDbUtf16, HBufC16, TPtrC16, TDesC16>(const TDesC&, const TDesC16&, const TDesC16&, const TDesC16&, const TDesC16&); |
1037 template void PerformanceTest2<TCmdLineParams::EDbUtf16, HBufC16, TPtrC16, TDesC16>(const TDesC&, const TDesC16&, const TDesC16&, const TDesC16&, const TDesC16&); |
1046 |
1038 |
1047 void ColumnValueAccessTest() |
1039 void ColumnValueAccessTest() |
1048 { |
1040 { |
1049 _LIT(KColName1, "Column1"); |
1041 _LIT(KColName1, "Column1"); |
1050 _LIT(KColName2, "Column2"); |
1042 _LIT(KColName2, "Column2"); |
1257 SingleInsertTest(); |
1249 SingleInsertTest(); |
1258 |
1250 |
1259 TheTest.Printf(_L("Single \"delete\" test\r\n")); |
1251 TheTest.Printf(_L("Single \"delete\" test\r\n")); |
1260 SingleDeleteTest(); |
1252 SingleDeleteTest(); |
1261 |
1253 |
1262 TheTestTitle.Copy(_L("SERVER, UTF8 SQL strings, non-secure, ")); |
1254 TheTestTitle.Format(_L("SERVER, UTF8 SQL strings, non-secure, encoding: \"%S\", page size: %d\r\n"), |
1263 TheTestTitle.Append(TheDbEncoding == EDbUtf16 ? KDbEncodingUtf16text : KDbEncodingUtf8text); |
1255 TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); |
1264 TheTestTitle.Append(_L("\r\n")); |
|
1265 TheTest.Printf(TheTestTitle); |
1256 TheTest.Printf(TheTestTitle); |
1266 PerformanceTest<HBufC8, TPtrC8, TDesC8, ENonSecureDb>(TheNonSecureDbName, KCommitStr8(), KUpdateSql8(), KSelectSql8(), KDeleteSql8()); |
1257 PerformanceTest<HBufC8, TPtrC8, TDesC8, ENonSecureDb>(TheNonSecureDbName, KCommitStr8(), KUpdateSql8(), KSelectSql8(), KDeleteSql8()); |
1267 |
1258 |
1268 TheTestTitle.Copy(_L("SERVER, UTF8 SQL strings, non-secure, ")); |
1259 TheTestTitle.Format(_L("SERVER, UTF8 SQL strings, non-secure, update test (without parameters), encoding: \"%S\", page size: %d\r\n"), |
1269 TheTestTitle.Append(TheDbEncoding == EDbUtf16 ? KDbEncodingUtf16text : KDbEncodingUtf8text); |
1260 TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); |
1270 TheTestTitle.Append(_L(", update test (without parameters)")); |
|
1271 TheTestTitle.Append(_L("\r\n")); |
|
1272 TheTest.Printf(TheTestTitle); |
1261 TheTest.Printf(TheTestTitle); |
1273 UpdateWPTest<TBuf8<200>, TDesC8, ENonSecureDb>(TheNonSecureDbName, KUpdateSql2_8()); |
1262 UpdateWPTest<TBuf8<200>, TDesC8, ENonSecureDb>(TheNonSecureDbName, KUpdateSql2_8()); |
1274 |
1263 |
1275 TheTestTitle.Copy(_L("SERVER, UTF8 SQL strings, secure, ")); |
1264 TheTestTitle.Format(_L("SERVER, UTF8 SQL strings, secure, encoding: \"%S\", page size: %d\r\n"), |
1276 TheTestTitle.Append(TheDbEncoding == EDbUtf16 ? KDbEncodingUtf16text : KDbEncodingUtf8text); |
1265 TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); |
1277 TheTestTitle.Append(_L("\r\n")); |
|
1278 TheTest.Printf(TheTestTitle); |
1266 TheTest.Printf(TheTestTitle); |
1279 PerformanceTest<HBufC8, TPtrC8, TDesC8, ESecureDb>(TheSecureDbName, KCommitStr8(), KUpdateSql8(), KSelectSql8(), KDeleteSql8()); |
1267 PerformanceTest<HBufC8, TPtrC8, TDesC8, ESecureDb>(TheSecureDbName, KCommitStr8(), KUpdateSql8(), KSelectSql8(), KDeleteSql8()); |
1280 |
1268 |
1281 TheTest.Printf(_L("SQLITE, UTF8 encoded database, UTF8 SQL strings\r\n")); |
1269 TheTest.Printf(_L("SQLITE, UTF8 encoded database, UTF8 SQL strings\r\n")); |
1282 PerformanceTest2<EDbUtf8, HBufC8, TPtrC8, TDesC8>(TheNonSecureDbName, KCommitStr8(), KUpdateSql8(), KSelectSql8(), KDeleteSql8()); |
1270 PerformanceTest2<TCmdLineParams::EDbUtf8, HBufC8, TPtrC8, TDesC8>(TheNonSecureDbName, KCommitStr8(), KUpdateSql8(), KSelectSql8(), KDeleteSql8()); |
1283 |
1271 |
1284 TheTest.Printf(_L("SQLITE, UTF8 encoded database, UTF8 SQL strings, update test (without parameters)\r\n")); |
1272 TheTest.Printf(_L("SQLITE, UTF8 encoded database, UTF8 SQL strings, update test (without parameters)\r\n")); |
1285 UpdateWPTest2<TDesC8>(TheNonSecureDbName, KUpdateSql2_8()); |
1273 UpdateWPTest2<TDesC8>(TheNonSecureDbName, KUpdateSql2_8()); |
1286 |
1274 |
1287 TheTest.Printf(_L("SQLITE, UTF16 encoded database, UTF8 SQL strings\r\n")); |
1275 TheTest.Printf(_L("SQLITE, UTF16 encoded database, UTF8 SQL strings\r\n")); |
1288 PerformanceTest2<EDbUtf16, HBufC8, TPtrC8, TDesC8>(TheNonSecureDbName, KCommitStr8(), KUpdateSql8(), KSelectSql8(), KDeleteSql8()); |
1276 PerformanceTest2<TCmdLineParams::EDbUtf16, HBufC8, TPtrC8, TDesC8>(TheNonSecureDbName, KCommitStr8(), KUpdateSql8(), KSelectSql8(), KDeleteSql8()); |
1289 |
1277 |
1290 TheTestTitle.Copy(_L("SERVER, UTF16 SQL strings, non-secure, ")); |
1278 TheTestTitle.Format(_L("SERVER, UTF16 SQL strings, non-secure, encoding: \"%S\", page size: %d\r\n"), |
1291 TheTestTitle.Append(TheDbEncoding == EDbUtf16 ? KDbEncodingUtf16text : KDbEncodingUtf8text); |
1279 TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); |
1292 TheTestTitle.Append(_L("\r\n")); |
|
1293 TheTest.Printf(TheTestTitle); |
1280 TheTest.Printf(TheTestTitle); |
1294 PerformanceTest<HBufC16, TPtrC16, TDesC16, ENonSecureDb>(TheNonSecureDbName, KCommitStr16(), KUpdateSql16(), KSelectSql16(), KDeleteSql16()); |
1281 PerformanceTest<HBufC16, TPtrC16, TDesC16, ENonSecureDb>(TheNonSecureDbName, KCommitStr16(), KUpdateSql16(), KSelectSql16(), KDeleteSql16()); |
1295 |
1282 |
1296 TheTestTitle.Copy(_L("SERVER, UTF16 SQL strings, non-secure, ")); |
1283 TheTestTitle.Format(_L("SERVER, UTF16 SQL strings, non-secure, update test (without parameters), encoding: \"%S\", page size: %d\r\n"), |
1297 TheTestTitle.Append(TheDbEncoding == EDbUtf16 ? KDbEncodingUtf16text : KDbEncodingUtf8text); |
1284 TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); |
1298 TheTestTitle.Append(_L(", update test (without parameters)\r\n")); |
|
1299 TheTest.Printf(TheTestTitle); |
1285 TheTest.Printf(TheTestTitle); |
1300 UpdateWPTest<TBuf16<200>, TDesC16, ENonSecureDb>(TheNonSecureDbName, KUpdateSql2_16()); |
1286 UpdateWPTest<TBuf16<200>, TDesC16, ENonSecureDb>(TheNonSecureDbName, KUpdateSql2_16()); |
1301 |
1287 |
1302 TheTestTitle.Copy(_L("SERVER, UTF16 SQL strings, secure, ")); |
1288 TheTestTitle.Format(_L("SERVER, UTF16 SQL strings, secure, encoding: \"%S\", page size: %d\r\n"), |
1303 TheTestTitle.Append(TheDbEncoding == EDbUtf16 ? KDbEncodingUtf16text : KDbEncodingUtf8text); |
1289 TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); |
1304 TheTestTitle.Append(_L("\r\n")); |
|
1305 TheTest.Printf(TheTestTitle); |
1290 TheTest.Printf(TheTestTitle); |
1306 PerformanceTest<HBufC16, TPtrC16, TDesC16, ESecureDb>(TheSecureDbName, KCommitStr16(), KUpdateSql16(), KSelectSql16(), KDeleteSql16()); |
1291 PerformanceTest<HBufC16, TPtrC16, TDesC16, ESecureDb>(TheSecureDbName, KCommitStr16(), KUpdateSql16(), KSelectSql16(), KDeleteSql16()); |
1307 |
1292 |
1308 TheTest.Printf(_L("SQLITE, UTF8 encoded database, UTF16 SQL strings\r\n")); |
1293 TheTest.Printf(_L("SQLITE, UTF8 encoded database, UTF16 SQL strings\r\n")); |
1309 PerformanceTest2<EDbUtf8, HBufC16, TPtrC16, TDesC16>(TheNonSecureDbName, KCommitStr16(), KUpdateSql16(), KSelectSql16(), KDeleteSql16()); |
1294 PerformanceTest2<TCmdLineParams::EDbUtf8, HBufC16, TPtrC16, TDesC16>(TheNonSecureDbName, KCommitStr16(), KUpdateSql16(), KSelectSql16(), KDeleteSql16()); |
1310 |
1295 |
1311 TheTest.Printf(_L("SQLITE, UTF16 encoded database, UTF16 SQL strings\r\n")); |
1296 TheTest.Printf(_L("SQLITE, UTF16 encoded database, UTF16 SQL strings\r\n")); |
1312 PerformanceTest2<EDbUtf16, HBufC16, TPtrC16, TDesC16>(TheNonSecureDbName, KCommitStr16(), KUpdateSql16(), KSelectSql16(), KDeleteSql16()); |
1297 PerformanceTest2<TCmdLineParams::EDbUtf16, HBufC16, TPtrC16, TDesC16>(TheNonSecureDbName, KCommitStr16(), KUpdateSql16(), KSelectSql16(), KDeleteSql16()); |
1313 |
1298 |
1314 TheTest.Printf(_L("SQLITE, UTF16 encoded database, UTF16 SQL strings, update test (without parameters)\r\n")); |
1299 TheTest.Printf(_L("SQLITE, UTF16 encoded database, UTF16 SQL strings, update test (without parameters)\r\n")); |
1315 UpdateWPTest2<TDesC16>(TheNonSecureDbName, KUpdateSql2_16()); |
1300 UpdateWPTest2<TDesC16>(TheNonSecureDbName, KUpdateSql2_16()); |
1316 |
1301 |
1317 TheTest.Printf(_L("Accessing column value by index or by name\r\n")); |
1302 TheTest.Printf(_L("Accessing column value by index or by name\r\n")); |
1320 TheTest.Printf(_L("Retrieving data from UTF8 Database using SELECT LIKE statements\r\n")); |
1305 TheTest.Printf(_L("Retrieving data from UTF8 Database using SELECT LIKE statements\r\n")); |
1321 SelectLikeQueryPerfTest(); |
1306 SelectLikeQueryPerfTest(); |
1322 |
1307 |
1323 } |
1308 } |
1324 |
1309 |
1325 //Usage: "t_sqlperformance [[-16/-8] [<drive letter>:]]" |
|
1326 |
|
1327 TInt E32Main() |
1310 TInt E32Main() |
1328 { |
1311 { |
1329 TheTest.Title(); |
1312 TheTest.Title(); |
1330 |
1313 |
1331 CTrapCleanup* tc = CTrapCleanup::New(); |
1314 CTrapCleanup* tc = CTrapCleanup::New(); |
1332 |
1315 TheTest(tc != NULL); |
1333 TheDbEncoding = EDbUtf16; |
1316 |
1334 |
1317 GetCmdLineParamsAndSqlConfigString(TheTest, _L("t_sqlperformance"), TheCmdLineParams, TheSqlConfigString); |
1335 User::CommandLine(TheCmd); |
|
1336 TheCmd.TrimAll(); |
|
1337 if(TheCmd.Length() > 0) |
|
1338 { |
|
1339 TPtrC prm1(KNullDesC); |
|
1340 TPtrC prm2(KNullDesC); |
|
1341 TInt pos = TheCmd.Locate(TChar(' ')); |
|
1342 if(pos > 0) |
|
1343 { |
|
1344 prm1.Set(TheCmd.Left(pos)); |
|
1345 prm2.Set(TheCmd.Mid(pos + 1)); |
|
1346 } |
|
1347 else |
|
1348 { |
|
1349 prm1.Set(TheCmd); |
|
1350 } |
|
1351 if(prm1.Compare(_L("-8")) == 0) |
|
1352 { |
|
1353 TheDbEncoding = EDbUtf8; |
|
1354 TheDriveName.Copy(prm2); |
|
1355 } |
|
1356 else if(prm2.Compare(_L("-8")) == 0) |
|
1357 { |
|
1358 TheDbEncoding = EDbUtf8; |
|
1359 TheDriveName.Copy(prm1); |
|
1360 } |
|
1361 else if(prm1.Compare(_L("-16")) == 0) |
|
1362 { |
|
1363 TheDbEncoding = EDbUtf16; |
|
1364 TheDriveName.Copy(prm2); |
|
1365 } |
|
1366 else if(prm2.Compare(_L("-16")) == 0) |
|
1367 { |
|
1368 TheDbEncoding = EDbUtf16; |
|
1369 TheDriveName.Copy(prm1); |
|
1370 } |
|
1371 } |
|
1372 |
|
1373 //Construct test database file names |
|
1374 _LIT(KSecureDbName, "c:[2121212A]t_perfdb.db"); |
1318 _LIT(KSecureDbName, "c:[2121212A]t_perfdb.db"); |
1375 TheParse.Set(TheDriveName, &KSecureDbName, 0); |
1319 PrepareDbName(KSecureDbName, TheCmdLineParams.iDriveName, TheSecureDbName); |
1376 const TDesC& dbFilePath1 = TheParse.FullName(); |
|
1377 TheSecureDbName.Copy(dbFilePath1); |
|
1378 |
|
1379 _LIT(KNonSecureDbName, "c:\\test\\t_perfdb.db"); |
1320 _LIT(KNonSecureDbName, "c:\\test\\t_perfdb.db"); |
1380 TheParse.Set(TheDriveName, &KNonSecureDbName, 0); |
1321 PrepareDbName(KNonSecureDbName, TheCmdLineParams.iDriveName, TheNonSecureDbName); |
1381 const TDesC& dbFilePath2 = TheParse.FullName(); |
|
1382 TheNonSecureDbName.Copy(dbFilePath2); |
|
1383 |
|
1384 _LIT(KNonSecureDbName2, "c:\\test\\t_perfdb2.db"); |
1322 _LIT(KNonSecureDbName2, "c:\\test\\t_perfdb2.db"); |
1385 TheParse.Set(TheDriveName, &KNonSecureDbName2, 0); |
1323 PrepareDbName(KNonSecureDbName2, TheCmdLineParams.iDriveName, TheNonSecureDbName2); |
1386 const TDesC& dbFilePath3 = TheParse.FullName(); |
|
1387 TheNonSecureDbName2.Copy(dbFilePath3); |
|
1388 |
|
1389 _LIT(KNonSecureTmpDbName, "c:\\test\\tmp.db"); |
1324 _LIT(KNonSecureTmpDbName, "c:\\test\\tmp.db"); |
1390 TheParse.Set(TheDriveName, &KNonSecureTmpDbName, 0); |
1325 PrepareDbName(KNonSecureTmpDbName, TheCmdLineParams.iDriveName, TheNonSecureTmpDbName); |
1391 const TDesC& dbFilePath4 = TheParse.FullName(); |
|
1392 TheNonSecureTmpDbName.Copy(dbFilePath4); |
|
1393 |
|
1394 _LIT(KSglRecDbName, "c:\\test\\default_avacon.dbSQL"); |
1326 _LIT(KSglRecDbName, "c:\\test\\default_avacon.dbSQL"); |
1395 TheParse.Set(TheDriveName, &KSglRecDbName, 0); |
1327 PrepareDbName(KSglRecDbName, TheCmdLineParams.iDriveName, TheSglRecDbFileName); |
1396 const TDesC& dbFilePath5 = TheParse.FullName(); |
1328 |
1397 TheSglRecDbFileName.Copy(dbFilePath5); |
1329 TheTest.Printf(_L("==Databases: %S, %S, %S, %S, %S\r\n"), &TheSecureDbName, &TheNonSecureDbName, |
|
1330 &TheNonSecureDbName2, &TheNonSecureTmpDbName, |
|
1331 &TheSglRecDbFileName); |
1398 |
1332 |
1399 __UHEAP_MARK; |
1333 __UHEAP_MARK; |
1400 |
1334 |
1401 TestEnvInit(); |
1335 TestEnvInit(); |
1402 TheTest.Printf(_L("==Databases: %S, %S, %S, %S, %S\r\n"), &TheSecureDbName, &TheNonSecureDbName, |
|
1403 &TheNonSecureDbName2, &TheNonSecureTmpDbName, &TheSglRecDbFileName); |
|
1404 DoTests(); |
1336 DoTests(); |
1405 TestEnvDestroy(); |
1337 TestEnvDestroy(); |
1406 |
1338 |
1407 __UHEAP_MARKEND; |
1339 __UHEAP_MARKEND; |
1408 |
1340 |