407 // this is because we can detect a corrupt database when we attempt to |
407 // 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 |
408 // 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 |
409 // attempt to set the pragmas and so the corrupt file is undetected |
410 TEST(rc==KSqlErrNotDb || rc==KErrNone); |
410 TEST(rc==KSqlErrNotDb || rc==KErrNone); |
411 db.Close(); |
411 db.Close(); |
|
412 |
|
413 //An attempt to open database with name containing non-convertible characters. |
|
414 TBuf<6> invName; |
|
415 invName.SetLength(6); |
|
416 invName[0] = TChar('c'); |
|
417 invName[1] = TChar(':'); |
|
418 invName[2] = TChar('\\'); |
|
419 invName[3] = TChar(0xD800); |
|
420 invName[4] = TChar(0xFC00); |
|
421 invName[5] = TChar(0x0000); |
|
422 rc = db.Open(invName); |
|
423 db.Close(); |
|
424 TEST(rc != KErrNone); |
412 |
425 |
413 //Copy the corrupted database file on drive C: |
426 //Copy the corrupted database file on drive C: |
414 TEST2(fs.Connect(), KErrNone); |
427 TEST2(fs.Connect(), KErrNone); |
415 rc = BaflUtils::CopyFile(fs, KDbPath10, KTestDbName3); |
428 rc = BaflUtils::CopyFile(fs, KDbPath10, KTestDbName3); |
416 TEST2(rc, KErrNone); |
429 TEST2(rc, KErrNone); |
790 _LIT8(KStmt18, "CREATE TABLE BBB(Fld1 INTEGER, Fld2 BIGINT, Fld3 DOUBLE, \ |
803 _LIT8(KStmt18, "CREATE TABLE BBB(Fld1 INTEGER, Fld2 BIGINT, Fld3 DOUBLE, \ |
791 Fld4 TEXT, Fld5 LONGBLOB, Fld6 TEXT NULL)"); |
804 Fld4 TEXT, Fld5 LONGBLOB, Fld6 TEXT NULL)"); |
792 _LIT8(KStmt19, "INSERT INTO BBB(Fld1, Fld2, Fld3, Fld4, Fld5, Fld6)\ |
805 _LIT8(KStmt19, "INSERT INTO BBB(Fld1, Fld2, Fld3, Fld4, Fld5, Fld6)\ |
793 VALUES(:V1, :V2, :V3, :V4, :V5, :V6)"); |
806 VALUES(:V1, :V2, :V3, :V4, :V5, :V6)"); |
794 _LIT8(KStmt20, "SELECT * FROM BBB"); |
807 _LIT8(KStmt20, "SELECT * FROM BBB"); |
|
808 _LIT8(KStmt21, "SELECT fld1, fld2 FROM AAA;SELECT fld1, fld2 FROM AAA"); |
795 |
809 |
796 /** |
810 /** |
797 @SYMTestCaseID SYSLIB-SQL-CT-1606 |
811 @SYMTestCaseID SYSLIB-SQL-CT-1606 |
798 @SYMTestCaseDesc Preparing SQL statements. Moving to the next record. Retrieving and verifying |
812 @SYMTestCaseDesc Preparing SQL statements. Moving to the next record. Retrieving and verifying |
799 the column types and values. Binding parameter values. |
813 the column types and values. Binding parameter values. |
822 //SQL statement without parameters. Create a table. |
836 //SQL statement without parameters. Create a table. |
823 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt12, KErrNone); |
837 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt12, KErrNone); |
824 ExecSqlStmt(db, stmt, KErrNone); |
838 ExecSqlStmt(db, stmt, KErrNone); |
825 stmt.Close(); |
839 stmt.Close(); |
826 |
840 |
|
841 //String containg more than one SQL statement. |
|
842 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt21, KErrArgument); |
|
843 stmt.Close(); |
|
844 |
827 //SQL statement without parameters. Insert a record into the table. |
845 //SQL statement without parameters. Insert a record into the table. |
828 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt13, KErrNone); |
846 stmt = PrepareSqlStmt<DES, BUF>(db, KStmt13, KErrNone); |
829 ExecSqlStmt(db, stmt, KErrNone); |
847 ExecSqlStmt(db, stmt, KErrNone); |
830 stmt.Close(); |
848 stmt.Close(); |
831 |
849 |
1086 |
1104 |
1087 //Move on row 1 |
1105 //Move on row 1 |
1088 rc = stmt.Next(); |
1106 rc = stmt.Next(); |
1089 TEST2(rc, KSqlAtRow); |
1107 TEST2(rc, KSqlAtRow); |
1090 |
1108 |
|
1109 //An attempt to read integer column using binary stream |
|
1110 RSqlColumnReadStream strm2; |
|
1111 rc = strm2.ColumnBinary(stmt, 0); |
|
1112 strm2.Close(); |
|
1113 TEST2(rc, KErrArgument); |
|
1114 |
|
1115 //An attempt to read integer column using text stream |
|
1116 rc = strm2.ColumnText(stmt, 0); |
|
1117 strm2.Close(); |
|
1118 TEST2(rc, KErrArgument); |
|
1119 |
1091 //Read the long text column using a stream |
1120 //Read the long text column using a stream |
1092 RSqlColumnReadStream columnStream; |
1121 RSqlColumnReadStream columnStream; |
1093 rc = columnStream.ColumnText(stmt, 1); |
1122 rc = columnStream.ColumnText(stmt, 1); |
1094 columnStream.Close(); |
1123 columnStream.Close(); |
1095 TEST2(rc, KErrNone); |
1124 TEST2(rc, KErrNone); |
2356 TEST(size.iFree >= 0); |
2385 TEST(size.iFree >= 0); |
2357 db.Close(); |
2386 db.Close(); |
2358 (void)RSqlDatabase::Delete(KTestDbName1); |
2387 (void)RSqlDatabase::Delete(KTestDbName1); |
2359 } |
2388 } |
2360 |
2389 |
|
2390 /** |
|
2391 @SYMTestCaseID PDS-SQL-CT-4205 |
|
2392 @SYMTestCaseDesc "PRAGMA count_changes" test. |
|
2393 When "count_changes" pragma is ON, sqlite3_step() is called two times by the |
|
2394 SQL server, before getting the SQLITE_DONE return code. |
|
2395 Everything else is the same (statement processing, etc.). |
|
2396 @SYMTestPriority High |
|
2397 @SYMTestActions "PRAGMA count_changes" test. |
|
2398 @SYMTestExpectedResults Test must not fail |
|
2399 */ |
|
2400 void CountChangesTest() |
|
2401 { |
|
2402 (void)RSqlDatabase::Delete(KTestDbName1); |
|
2403 RSqlDatabase db; |
|
2404 TInt err = db.Create(KTestDbName1); |
|
2405 TEST2(err, KErrNone); |
|
2406 err = db.Exec(_L("CREATE TABLE A(I INTEGER)")); |
|
2407 TEST(err >= 0); |
|
2408 |
|
2409 err = db.Exec(_L("PRAGMA count_changes=ON")); |
|
2410 TEST(err >= 0); |
|
2411 |
|
2412 err = db.Exec(_L("INSERT INTO A VALUES(1)")); |
|
2413 TEST2(err, 1); |
|
2414 |
|
2415 err = db.Exec(_L8("INSERT INTO A VALUES(2)")); |
|
2416 TEST2(err, 1); |
|
2417 |
|
2418 RSqlStatement stmt; |
|
2419 err = stmt.Prepare(db, _L("DELETE FROM A WHERE I>=1 AND I<=2")); |
|
2420 TEST2(err, KErrNone); |
|
2421 err = stmt.Exec(); |
|
2422 TEST2(err, 2); |
|
2423 stmt.Close(); |
|
2424 |
|
2425 err = db.Exec(_L("PRAGMA count_changes=OFF")); |
|
2426 TEST(err >= 0); |
|
2427 |
|
2428 db.Close(); |
|
2429 (void)RSqlDatabase::Delete(KTestDbName1); |
|
2430 } |
|
2431 |
2361 void DoTestsL() |
2432 void DoTestsL() |
2362 { |
2433 { |
2363 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1601 Create/Open/Close database tests ")); |
2434 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1601 Create/Open/Close database tests ")); |
2364 OpenCloseDatabaseTest(); |
2435 OpenCloseDatabaseTest(); |
2365 |
2436 |
2425 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4040 RSqlDatabase::Size(RSqlDatabase::TSize&) - attached database tests")); |
2496 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4040 RSqlDatabase::Size(RSqlDatabase::TSize&) - attached database tests")); |
2426 AttachedSizeTest2(); |
2497 AttachedSizeTest2(); |
2427 |
2498 |
2428 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4041 RSqlDatabase::Size(RSqlDatabase::TSize&) - different compaction modes tests")); |
2499 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4041 RSqlDatabase::Size(RSqlDatabase::TSize&) - different compaction modes tests")); |
2429 DiffCompactModeSize2Test(); |
2500 DiffCompactModeSize2Test(); |
|
2501 |
|
2502 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4205 PRAGMA \"count_changes\" test")); |
|
2503 CountChangesTest(); |
2430 } |
2504 } |
2431 |
2505 |
2432 TInt E32Main() |
2506 TInt E32Main() |
2433 { |
2507 { |
2434 TheTest.Title(); |
2508 TheTest.Title(); |