297 |
297 |
298 if(filesysname.CompareF(_L("HVFS")) == 0) |
298 if(filesysname.CompareF(_L("HVFS")) == 0) |
299 { |
299 { |
300 maxFileName = KMaxFileName -150;//The test will panic in PlatSim when the file name is too long. This line should be removed when platsim team fixes the file system defect. |
300 maxFileName = KMaxFileName -150;//The test will panic in PlatSim when the file name is too long. This line should be removed when platsim team fixes the file system defect. |
301 } |
301 } |
302 HBufC* dbPath = HBufC::NewLC(maxFileName); |
302 HBufC* dbPath = HBufC::New(maxFileName); |
|
303 TEST(dbPath != NULL); |
|
304 TPtr dbPathPtr = dbPath->Des(); |
303 _LIT(KExt, ".DB"); |
305 _LIT(KExt, ".DB"); |
304 dbPath->Des().Copy(_L("C:")); |
306 dbPathPtr.Copy(_L("C:")); |
305 dbPath->Des().Append(KSecureUid.Name()); |
307 dbPathPtr.Append(KSecureUid.Name()); |
306 TInt len = maxFileName + 1 - (dbPath->Length() + KExt().Length() + privatePath.Length()); |
308 TInt len = maxFileName + 1 - (dbPathPtr.Length() + KExt().Length() + privatePath.Length()); |
307 |
309 |
308 while(--len) |
310 while(--len) |
309 { |
311 { |
310 dbPath->Des().Append(TChar('A')); |
312 dbPathPtr.Append(TChar('A')); |
311 } |
313 } |
312 dbPath->Des().Append(KExt); |
314 dbPathPtr.Append(KExt); |
313 TEST(dbPath->Length() == (maxFileName - privatePath.Length())); |
315 TEST(dbPathPtr.Length() == (maxFileName - privatePath.Length())); |
314 rc = db.Create(dbPath->Des(), securityPolicy); |
316 rc = db.Create(dbPathPtr, securityPolicy); |
315 TEST2(rc, KErrNone); |
317 TEST2(rc, KErrNone); |
316 db.Close(); |
318 db.Close(); |
317 rc2 = RSqlDatabase::Delete(dbPath->Des()); |
319 rc2 = RSqlDatabase::Delete(dbPathPtr); |
318 TEST2(rc2, KErrNone); |
320 TEST2(rc2, KErrNone); |
319 |
321 |
320 // Private database with config |
322 // Private database with config |
321 TBuf<KMaxFileName> cfgPath; |
323 TBuf<KMaxFileName> cfgPath; |
322 cfgPath.Copy(_L("C:")); |
324 cfgPath.Copy(_L("C:")); |
328 TEST2(rc, KErrNone); |
330 TEST2(rc, KErrNone); |
329 TEST2(rc2, KErrNone); |
331 TEST2(rc2, KErrNone); |
330 |
332 |
331 //Public shared database file on an existing drive (C:). |
333 //Public shared database file on an existing drive (C:). |
332 //Very long database file name. |
334 //Very long database file name. |
333 dbPath->Des().Copy(_L("C:\\TEST\\D")); |
335 dbPathPtr.Copy(_L("C:\\TEST\\D")); |
334 len = maxFileName + 1 - (dbPath->Length() + KExt().Length()); |
336 len = maxFileName + 1 - (dbPathPtr.Length() + KExt().Length()); |
335 while(--len) |
337 while(--len) |
336 { |
338 { |
337 dbPath->Des().Append(TChar('A')); |
339 dbPathPtr.Append(TChar('A')); |
338 } |
340 } |
339 dbPath->Des().Append(KExt); |
341 dbPathPtr.Append(KExt); |
340 TEST(dbPath->Length() == maxFileName); |
342 TEST(dbPathPtr.Length() == maxFileName); |
341 rc = db.Create(dbPath->Des()); |
343 rc = db.Create(dbPathPtr); |
342 db.Close(); |
344 db.Close(); |
343 rc2 = RSqlDatabase::Delete(dbPath->Des()); |
345 rc2 = RSqlDatabase::Delete(dbPathPtr); |
344 |
346 |
345 CleanupStack::PopAndDestroy(dbPath); |
347 delete dbPath; |
|
348 |
346 TEST2(rc, KErrNone); |
349 TEST2(rc, KErrNone); |
347 TEST2(rc2, KErrNone); |
350 TEST2(rc2, KErrNone); |
348 |
351 |
349 //Create/Close/Open/Close secure shared database test |
352 //Create/Close/Open/Close secure shared database test |
350 rc = db.Create(KTestDbName6, securityPolicy); |
353 rc = db.Create(KTestDbName6, securityPolicy); |
407 // this is because we can detect a corrupt database when we attempt to |
410 // this is because we can detect a corrupt database when we attempt to |
408 // set the configuration. If there is no cfg file, then there will be no |
411 // set the configuration. If there is no cfg file, then there will be no |
409 // attempt to set the pragmas and so the corrupt file is undetected |
412 // attempt to set the pragmas and so the corrupt file is undetected |
410 TEST(rc==KSqlErrNotDb || rc==KErrNone); |
413 TEST(rc==KSqlErrNotDb || rc==KErrNone); |
411 db.Close(); |
414 db.Close(); |
|
415 |
|
416 //An attempt to open database with name containing non-convertible characters. |
|
417 TBuf<6> invName; |
|
418 invName.SetLength(6); |
|
419 invName[0] = TChar('c'); |
|
420 invName[1] = TChar(':'); |
|
421 invName[2] = TChar('\\'); |
|
422 invName[3] = TChar(0xD800); |
|
423 invName[4] = TChar(0xFC00); |
|
424 invName[5] = TChar(0x0000); |
|
425 rc = db.Open(invName); |
|
426 db.Close(); |
|
427 TEST(rc != KErrNone); |
412 |
428 |
413 //Copy the corrupted database file on drive C: |
429 //Copy the corrupted database file on drive C: |
414 TEST2(fs.Connect(), KErrNone); |
430 TEST2(fs.Connect(), KErrNone); |
415 rc = BaflUtils::CopyFile(fs, KDbPath10, KTestDbName3); |
431 rc = BaflUtils::CopyFile(fs, KDbPath10, KTestDbName3); |
416 TEST2(rc, KErrNone); |
432 TEST2(rc, KErrNone); |
790 _LIT8(KStmt18, "CREATE TABLE BBB(Fld1 INTEGER, Fld2 BIGINT, Fld3 DOUBLE, \ |
806 _LIT8(KStmt18, "CREATE TABLE BBB(Fld1 INTEGER, Fld2 BIGINT, Fld3 DOUBLE, \ |
791 Fld4 TEXT, Fld5 LONGBLOB, Fld6 TEXT NULL)"); |
807 Fld4 TEXT, Fld5 LONGBLOB, Fld6 TEXT NULL)"); |
792 _LIT8(KStmt19, "INSERT INTO BBB(Fld1, Fld2, Fld3, Fld4, Fld5, Fld6)\ |
808 _LIT8(KStmt19, "INSERT INTO BBB(Fld1, Fld2, Fld3, Fld4, Fld5, Fld6)\ |
793 VALUES(:V1, :V2, :V3, :V4, :V5, :V6)"); |
809 VALUES(:V1, :V2, :V3, :V4, :V5, :V6)"); |
794 _LIT8(KStmt20, "SELECT * FROM BBB"); |
810 _LIT8(KStmt20, "SELECT * FROM BBB"); |
|
811 _LIT8(KStmt21, "SELECT fld1, fld2 FROM AAA;SELECT fld1, fld2 FROM AAA"); |
795 |
812 |
796 /** |
813 /** |
797 @SYMTestCaseID SYSLIB-SQL-CT-1606 |
814 @SYMTestCaseID SYSLIB-SQL-CT-1606 |
798 @SYMTestCaseDesc Preparing SQL statements. Moving to the next record. Retrieving and verifying |
815 @SYMTestCaseDesc Preparing SQL statements. Moving to the next record. Retrieving and verifying |
799 the column types and values. Binding parameter values. |
816 the column types and values. Binding parameter values. |
822 //SQL statement without parameters. Create a table. |
839 //SQL statement without parameters. Create a table. |
823 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt12, KErrNone); |
840 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt12, KErrNone); |
824 ExecSqlStmt(db, stmt, KErrNone); |
841 ExecSqlStmt(db, stmt, KErrNone); |
825 stmt.Close(); |
842 stmt.Close(); |
826 |
843 |
|
844 //String containg more than one SQL statement. |
|
845 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt21, KErrArgument); |
|
846 stmt.Close(); |
|
847 |
827 //SQL statement without parameters. Insert a record into the table. |
848 //SQL statement without parameters. Insert a record into the table. |
828 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt13, KErrNone); |
849 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt13, KErrNone); |
829 ExecSqlStmt(db, stmt, KErrNone); |
850 ExecSqlStmt(db, stmt, KErrNone); |
830 stmt.Close(); |
851 stmt.Close(); |
831 |
852 |
1086 |
1107 |
1087 //Move on row 1 |
1108 //Move on row 1 |
1088 rc = stmt.Next(); |
1109 rc = stmt.Next(); |
1089 TEST2(rc, KSqlAtRow); |
1110 TEST2(rc, KSqlAtRow); |
1090 |
1111 |
|
1112 //An attempt to read integer column using binary stream |
|
1113 RSqlColumnReadStream strm2; |
|
1114 rc = strm2.ColumnBinary(stmt, 0); |
|
1115 strm2.Close(); |
|
1116 TEST2(rc, KErrArgument); |
|
1117 |
|
1118 //An attempt to read integer column using text stream |
|
1119 rc = strm2.ColumnText(stmt, 0); |
|
1120 strm2.Close(); |
|
1121 TEST2(rc, KErrArgument); |
|
1122 |
1091 //Read the long text column using a stream |
1123 //Read the long text column using a stream |
1092 RSqlColumnReadStream columnStream; |
1124 RSqlColumnReadStream columnStream; |
1093 rc = columnStream.ColumnText(stmt, 1); |
1125 rc = columnStream.ColumnText(stmt, 1); |
1094 columnStream.Close(); |
1126 columnStream.Close(); |
1095 TEST2(rc, KErrNone); |
1127 TEST2(rc, KErrNone); |
2356 TEST(size.iFree >= 0); |
2388 TEST(size.iFree >= 0); |
2357 db.Close(); |
2389 db.Close(); |
2358 (void)RSqlDatabase::Delete(KTestDbName1); |
2390 (void)RSqlDatabase::Delete(KTestDbName1); |
2359 } |
2391 } |
2360 |
2392 |
|
2393 /** |
|
2394 @SYMTestCaseID PDS-SQL-CT-4205 |
|
2395 @SYMTestCaseDesc "PRAGMA count_changes" test. |
|
2396 When "count_changes" pragma is ON, sqlite3_step() is called two times by the |
|
2397 SQL server, before getting the SQLITE_DONE return code. |
|
2398 Everything else is the same (statement processing, etc.). |
|
2399 @SYMTestPriority High |
|
2400 @SYMTestActions "PRAGMA count_changes" test. |
|
2401 @SYMTestExpectedResults Test must not fail |
|
2402 */ |
|
2403 void CountChangesTest() |
|
2404 { |
|
2405 (void)RSqlDatabase::Delete(KTestDbName1); |
|
2406 RSqlDatabase db; |
|
2407 TInt err = db.Create(KTestDbName1); |
|
2408 TEST2(err, KErrNone); |
|
2409 err = db.Exec(_L("CREATE TABLE A(I INTEGER)")); |
|
2410 TEST(err >= 0); |
|
2411 |
|
2412 err = db.Exec(_L("PRAGMA count_changes=ON")); |
|
2413 TEST(err >= 0); |
|
2414 |
|
2415 err = db.Exec(_L("INSERT INTO A VALUES(1)")); |
|
2416 TEST2(err, 1); |
|
2417 |
|
2418 err = db.Exec(_L8("INSERT INTO A VALUES(2)")); |
|
2419 TEST2(err, 1); |
|
2420 |
|
2421 RSqlStatement stmt; |
|
2422 err = stmt.Prepare(db, _L("DELETE FROM A WHERE I>=1 AND I<=2")); |
|
2423 TEST2(err, KErrNone); |
|
2424 err = stmt.Exec(); |
|
2425 TEST2(err, 2); |
|
2426 stmt.Close(); |
|
2427 |
|
2428 err = db.Exec(_L("PRAGMA count_changes=OFF")); |
|
2429 TEST(err >= 0); |
|
2430 |
|
2431 db.Close(); |
|
2432 (void)RSqlDatabase::Delete(KTestDbName1); |
|
2433 } |
|
2434 |
2361 void DoTestsL() |
2435 void DoTestsL() |
2362 { |
2436 { |
2363 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1601 Create/Open/Close database tests ")); |
2437 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1601 Create/Open/Close database tests ")); |
2364 OpenCloseDatabaseTest(); |
2438 OpenCloseDatabaseTest(); |
2365 |
2439 |
2425 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4040 RSqlDatabase::Size(RSqlDatabase::TSize&) - attached database tests")); |
2499 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4040 RSqlDatabase::Size(RSqlDatabase::TSize&) - attached database tests")); |
2426 AttachedSizeTest2(); |
2500 AttachedSizeTest2(); |
2427 |
2501 |
2428 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4041 RSqlDatabase::Size(RSqlDatabase::TSize&) - different compaction modes tests")); |
2502 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4041 RSqlDatabase::Size(RSqlDatabase::TSize&) - different compaction modes tests")); |
2429 DiffCompactModeSize2Test(); |
2503 DiffCompactModeSize2Test(); |
|
2504 |
|
2505 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4205 PRAGMA \"count_changes\" test")); |
|
2506 CountChangesTest(); |
2430 } |
2507 } |
2431 |
2508 |
2432 TInt E32Main() |
2509 TInt E32Main() |
2433 { |
2510 { |
2434 TheTest.Title(); |
2511 TheTest.Title(); |