sl@0: // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include //MStreamBuf sl@0: #include sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: RTest TheTest(_L("t_sqlapi test")); sl@0: _LIT(KTestDir, "c:\\test\\"); sl@0: _LIT(KTestDbName1, "c:\\test\\t_sqlapi1.db"); sl@0: _LIT(KTestDbName2, "c:[1111CCCC]t_sqlapi2.db"); sl@0: _LIT(KTestDbName3, "C:\\TEST\\t_sqlapi3.db"); sl@0: _LIT(KTestDbName4, "C:[1111CCCC]D012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.db"); sl@0: _LIT(KTestDbName5, "C:\\TEST\\D012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.db"); sl@0: _LIT(KTestDbName6, "C:[1111CCCC]t_sqlapi6.db"); sl@0: _LIT(KTestDbName7, "C:[1111CCCC]t_sqlapi7.db"); sl@0: _LIT(KTestDbName8, "c:\\test\\t_sqlapi8.db"); sl@0: _LIT(KTestDbName9, "c:\\private\\1111CCCC\\t_sqlapi9.db"); sl@0: _LIT(KTestCfgDbName, "c:\\test\\t_sqlapi_cfg.db"); sl@0: _LIT(KTestCfgDbName2, "c:[1111CCCC]t_sqlapi_cfg.db"); sl@0: _LIT(KServerPrivateDir, "\\private\\10281e17\\"); sl@0: sl@0: _LIT(KDbName7, "C:\\TEST\\t_sqlapi7_2.db"); sl@0: sl@0: // used for the config test sl@0: _LIT8(KServerConfigString1, " ; cache_size = 1024 ; page_size =1024 ;encoding = \"UTF-8\" "); sl@0: _LIT8(KServerConfigString2, " badconfigstring "); sl@0: _LIT8(KServerConfigString3, " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); sl@0: _LIT8(KServerConfigString4, ""); sl@0: _LIT8(KServerConfigString5, "dfgdfrgdkfjgjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj43w3wk4jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"); sl@0: sl@0: const TUid KSecureUid = {0x1111CCCC};//The same as the UID in the MMP file sl@0: sl@0: _LIT(KCreateDbScript, "z:\\test\\contacts_schema_to_vendors.sql"); sl@0: _LIT(KFillDbScript, "z:\\test\\add_simple_contacts.sql"); sl@0: _LIT8(KCommitStr8, "COMMIT;"); sl@0: _LIT16(KCommitStr16, "COMMIT;"); sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void DeleteTestFiles() sl@0: { sl@0: RSqlDatabase::Delete(KTestDbName1); sl@0: RSqlDatabase::Delete(KTestDbName2); sl@0: RSqlDatabase::Delete(KTestDbName3); sl@0: RSqlDatabase::Delete(KTestDbName4); sl@0: RSqlDatabase::Delete(KTestDbName5); sl@0: RSqlDatabase::Delete(KTestDbName6); sl@0: RSqlDatabase::Delete(KTestDbName7); sl@0: RSqlDatabase::Delete(KTestDbName8); sl@0: RSqlDatabase::Delete(KTestDbName9); sl@0: RSqlDatabase::Delete(KTestCfgDbName); sl@0: RSqlDatabase::Delete(KTestCfgDbName2); sl@0: RSqlDatabase::Delete(KDbName7); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macros and functions sl@0: void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: DeleteTestFiles(); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: DeleteTestFiles(); sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void CreateTestDir() sl@0: { sl@0: RFs fs; sl@0: TInt err = fs.Connect(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = fs.MkDir(KTestDir); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: sl@0: err = fs.CreatePrivatePath(EDriveC); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: sl@0: fs.Close(); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: template void ExecSqlStmtOnDb(RSqlDatabase& aDb, const TDesC8& aSqlString, sl@0: TInt aExpectedError) sl@0: { sl@0: BUF sqlBuf; sl@0: sqlBuf.Copy(aSqlString); sl@0: sl@0: TInt rc = aDb.Exec(sqlBuf); sl@0: if(rc < 0 && SqlRetCodeClass(rc) == ESqlDbError) sl@0: { sl@0: TPtrC msg = aDb.LastErrorMessage(); sl@0: RDebug::Print(_L("Execute SQL error - '%S'\r\n"), &msg); sl@0: } sl@0: if(aExpectedError < 0) sl@0: { sl@0: TEST2(rc, aExpectedError); sl@0: } sl@0: else sl@0: { sl@0: TEST(rc >= 0); sl@0: } sl@0: } sl@0: sl@0: template RSqlStatement PrepareSqlStmt(RSqlDatabase& aDb, const TDesC8& aSqlString, sl@0: TInt aExpectedError) sl@0: { sl@0: BUF sqlBuf; sl@0: sqlBuf.Copy(aSqlString); sl@0: sl@0: RSqlStatement stmt; sl@0: TInt rc = stmt.Prepare(aDb, sqlBuf); sl@0: if(rc != KErrNone && SqlRetCodeClass(rc) == ESqlDbError) sl@0: { sl@0: TPtrC msg = aDb.LastErrorMessage(); sl@0: RDebug::Print(_L("Execute SQL error - '%S'\r\n"), &msg); sl@0: } sl@0: TEST2(rc, aExpectedError); sl@0: return stmt; sl@0: } sl@0: sl@0: void ExecSqlStmt(RSqlDatabase& aDb, RSqlStatement& aStmt, TInt aExpectedError) sl@0: { sl@0: TInt rc = aStmt.Exec(); sl@0: if(rc < 0 && SqlRetCodeClass(rc) == ESqlDbError) sl@0: { sl@0: TPtrC msg = aDb.LastErrorMessage(); sl@0: RDebug::Print(_L("Execute SQL error - '%S'\r\n"), &msg); sl@0: } sl@0: if(aExpectedError < 0) sl@0: { sl@0: TEST2(rc, aExpectedError); sl@0: } sl@0: else sl@0: { sl@0: TEST(rc >= 0); sl@0: } sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1601 sl@0: @SYMTestCaseDesc Create/Open/Close database tests. Invalid database names, very long database names, sl@0: private databases, public databases, open twice database, create already sl@0: existing database, open non-exisitng database, open corrupted database. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for RSqlDatabase::Create(), RSqlDatabase::Open() methods. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void OpenCloseDatabaseTest() sl@0: { sl@0: RSqlDatabase db; sl@0: TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass); sl@0: RSqlSecurityPolicy securityPolicy; sl@0: TInt rc = securityPolicy.Create(defaultPolicy); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Secure shared database file on a non-existing drive (A:) sl@0: _LIT(KDbPath1, "A:[1111CCCC]db1.db"); sl@0: rc = db.Create(KDbPath1, securityPolicy); sl@0: TEST2(rc, KErrNotReady); sl@0: db.Close(); sl@0: sl@0: //Attempt to open a non-existing file. sl@0: _LIT(KDbFName, "c:\\test\\nofile.db"); sl@0: rc = db.Open(KDbFName); sl@0: TEST2(rc, KErrNotFound); sl@0: sl@0: //Zero length database file name. sl@0: rc = db.Create(_L("")); sl@0: TEST2(rc, KErrBadName); sl@0: db.Close(); sl@0: sl@0: //Database file name containing only the drive name sl@0: rc = db.Create(_L("C:")); sl@0: TEST2(rc, KErrBadName); sl@0: db.Close(); sl@0: sl@0: //Database file name containing only the path, without the file name sl@0: rc = db.Create(_L("C:\\TEST\\")); sl@0: TEST2(rc, KErrBadName); sl@0: db.Close(); sl@0: sl@0: //Public shared database file on a non-existing drive (A:) sl@0: _LIT(KDbPath2, "A:\\test\\db1.db"); sl@0: rc = db.Create(KDbPath2); sl@0: TEST2(rc, KErrNotReady); sl@0: db.Close(); sl@0: sl@0: // create database with good config specified sl@0: rc = db.Create(KTestCfgDbName,&KServerConfigString1); sl@0: TEST2(rc, KErrNone); sl@0: db.Close(); sl@0: TInt rc2 = RSqlDatabase::Delete(KTestCfgDbName); sl@0: TEST2(rc2, KErrNone); sl@0: sl@0: // create database with bad config specified sl@0: rc = db.Create(KTestCfgDbName,&KServerConfigString2); sl@0: TEST2(rc, KErrArgument); sl@0: db.Close(); sl@0: sl@0: // create database with long config specified sl@0: rc = db.Create(KTestCfgDbName,&KServerConfigString3); sl@0: TEST2(rc, KErrArgument); sl@0: db.Close(); sl@0: sl@0: // create database with empty config specified - not an error sl@0: rc = db.Create(KTestCfgDbName,&KServerConfigString4); sl@0: TEST2(rc, KErrNone); sl@0: db.Close(); sl@0: rc2 = RSqlDatabase::Delete(KTestCfgDbName); sl@0: TEST2(rc2, KErrNone); sl@0: sl@0: // create database with very long config specified sl@0: rc = db.Create(KTestCfgDbName, &KServerConfigString5); sl@0: TEST2(rc, KErrArgument); sl@0: db.Close(); sl@0: sl@0: //Secure shared database file on an existing drive (C:). sl@0: //Very long database file name (> 90 characters) but still a valid name. sl@0: rc = db.Create(KTestDbName4, securityPolicy); sl@0: db.Close(); sl@0: rc2 = RSqlDatabase::Delete(KTestDbName4); sl@0: TEST2(rc, KErrNone); sl@0: TEST2(rc2, KErrNone); sl@0: sl@0: //Secure shared database file on an existing drive (C:). sl@0: //Very long database file name (> 90 characters) but still a valid name. sl@0: //With config sl@0: rc = db.Create(KTestCfgDbName2, securityPolicy, &KServerConfigString1); sl@0: db.Close(); sl@0: rc2 = RSqlDatabase::Delete(KTestCfgDbName2); sl@0: TEST2(rc, KErrNone); sl@0: TEST2(rc2, KErrNone); sl@0: sl@0: //Public shared database file on an existing drive (C:). sl@0: //Very long database file name (> 90 characters) but still a valid name. sl@0: rc = db.Create(KTestDbName5); sl@0: db.Close(); sl@0: rc2 = RSqlDatabase::Delete(KTestDbName5); sl@0: TEST2(rc, KErrNone); sl@0: TEST2(rc2, KErrNone); sl@0: sl@0: RFs fs; sl@0: TEST2(fs.Connect(), KErrNone); sl@0: TFileName privatePath; sl@0: TEST2(fs.PrivatePath(privatePath), KErrNone); sl@0: sl@0: //Private shared database file on an existing drive (C:). sl@0: //Very long database file name. sl@0: TBuf<50>filesysname; sl@0: fs.FileSystemName(filesysname,(TInt) EDriveC); sl@0: fs.Close(); sl@0: sl@0: RDebug::Print(_L("file system name = %S"), &filesysname); sl@0: TInt maxFileName = KMaxFileName -40;//"-40" because the SQLITE engine creates a journal file if begins sl@0: //a transaction. The name of the journal file is sl@0: //"-journal.". It is obvious that if the sl@0: //database file name is too long but still valid and its creation sl@0: //succeeds, the journal file creation may fail because the journal sl@0: //file name becomes too long sl@0: sl@0: if(filesysname.CompareF(_L("HVFS")) == 0) sl@0: { sl@0: 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. sl@0: } sl@0: HBufC* dbPath = HBufC::New(maxFileName); sl@0: TEST(dbPath != NULL); sl@0: TPtr dbPathPtr = dbPath->Des(); sl@0: _LIT(KExt, ".DB"); sl@0: dbPathPtr.Copy(_L("C:")); sl@0: dbPathPtr.Append(KSecureUid.Name()); sl@0: TInt len = maxFileName + 1 - (dbPathPtr.Length() + KExt().Length() + privatePath.Length()); sl@0: sl@0: while(--len) sl@0: { sl@0: dbPathPtr.Append(TChar('A')); sl@0: } sl@0: dbPathPtr.Append(KExt); sl@0: TEST(dbPathPtr.Length() == (maxFileName - privatePath.Length())); sl@0: rc = db.Create(dbPathPtr, securityPolicy); sl@0: TEST2(rc, KErrNone); sl@0: db.Close(); sl@0: rc2 = RSqlDatabase::Delete(dbPathPtr); sl@0: TEST2(rc2, KErrNone); sl@0: sl@0: // Private database with config sl@0: TBuf cfgPath; sl@0: cfgPath.Copy(_L("C:")); sl@0: cfgPath.Append(KSecureUid.Name()); sl@0: cfgPath.Append(KExt); sl@0: rc = db.Create(cfgPath,securityPolicy,&KServerConfigString1); sl@0: db.Close(); sl@0: rc2 = RSqlDatabase::Delete(cfgPath); sl@0: TEST2(rc, KErrNone); sl@0: TEST2(rc2, KErrNone); sl@0: sl@0: //Public shared database file on an existing drive (C:). sl@0: //Very long database file name. sl@0: dbPathPtr.Copy(_L("C:\\TEST\\D")); sl@0: len = maxFileName + 1 - (dbPathPtr.Length() + KExt().Length()); sl@0: while(--len) sl@0: { sl@0: dbPathPtr.Append(TChar('A')); sl@0: } sl@0: dbPathPtr.Append(KExt); sl@0: TEST(dbPathPtr.Length() == maxFileName); sl@0: rc = db.Create(dbPathPtr); sl@0: db.Close(); sl@0: rc2 = RSqlDatabase::Delete(dbPathPtr); sl@0: sl@0: delete dbPath; sl@0: sl@0: TEST2(rc, KErrNone); sl@0: TEST2(rc2, KErrNone); sl@0: sl@0: //Create/Close/Open/Close secure shared database test sl@0: rc = db.Create(KTestDbName6, securityPolicy); sl@0: db.Close(); sl@0: rc2 = db.Open(KTestDbName6); sl@0: db.Close(); sl@0: TInt rc3 = RSqlDatabase::Delete(KTestDbName6); sl@0: TEST2(rc, KErrNone); sl@0: TEST2(rc2, KErrNone); sl@0: TEST2(rc3, KErrNone); sl@0: sl@0: //An attempt to create already existing secure shared file. sl@0: rc = db.Create(KTestDbName6, securityPolicy); sl@0: db.Close(); sl@0: rc2 = db.Create(KTestDbName6, securityPolicy); sl@0: db.Close(); sl@0: rc3 = RSqlDatabase::Delete(KTestDbName6); sl@0: TEST2(rc, KErrNone); sl@0: TEST2(rc2, KErrAlreadyExists); sl@0: TEST2(rc3, KErrNone); sl@0: sl@0: //An attempt to open twice the same database file using different RSqlDatabase objects sl@0: rc = db.Create(KTestDbName6, securityPolicy); sl@0: RSqlDatabase db2; sl@0: rc2 = db2.Open(KTestDbName6); sl@0: db2.Close(); sl@0: db.Close(); sl@0: rc3 = RSqlDatabase::Delete(KTestDbName6); sl@0: TEST2(rc, KErrNone); sl@0: TEST2(rc2, KErrNone);//-- KErrInUse -- in case EFileRead | EFileWrite file open mode! sl@0: TEST2(rc3, KErrNone); sl@0: sl@0: //An attempt to create secure shared database file on a read-only drive (Z:) sl@0: _LIT(KDbPath8, "Z:[1111CCCC]db1.db"); sl@0: rc = db.Create(KDbPath8, securityPolicy); sl@0: TEST2(rc, KErrAccessDenied); sl@0: db.Close(); sl@0: sl@0: //An attempt to create non-secure shared database file on a read-only drive (Z:) sl@0: _LIT(KDbPath8a, "Z:\\db1.db"); sl@0: rc = db.Create(KDbPath8a); sl@0: TEST2(rc, KErrAccessDenied); sl@0: db.Close(); sl@0: sl@0: //An attempt to open non-existing secure shared database file on a read-only drive (Z:) sl@0: rc = db.Open(KDbPath8); sl@0: TEST(rc == KErrNotFound || rc == KErrPathNotFound); sl@0: db.Close(); sl@0: sl@0: //An attempt to open existing public shared database file on a read-only drive (Z:) sl@0: _LIT(KDbPath9, "Z:\\TEST\\TestDb1.db"); sl@0: rc = db.Open(KDbPath9); sl@0: TEST2(rc, KErrNone); sl@0: db.Close(); sl@0: sl@0: //An attempt to open corrupted public shared database file on a read-only drive (Z:) sl@0: _LIT(KDbPath10, "Z:\\TEST\\CorruptDb.db"); sl@0: rc = db.Open(KDbPath10); sl@0: // it will be KErrNotDb if SqlServer.cfg exists, else KErrNone if it doesn't sl@0: // this is because we can detect a corrupt database when we attempt to sl@0: // set the configuration. If there is no cfg file, then there will be no sl@0: // attempt to set the pragmas and so the corrupt file is undetected sl@0: TEST(rc==KSqlErrNotDb || rc==KErrNone); sl@0: db.Close(); sl@0: sl@0: //An attempt to open database with name containing non-convertible characters. sl@0: TBuf<6> invName; sl@0: invName.SetLength(6); sl@0: invName[0] = TChar('c'); sl@0: invName[1] = TChar(':'); sl@0: invName[2] = TChar('\\'); sl@0: invName[3] = TChar(0xD800); sl@0: invName[4] = TChar(0xFC00); sl@0: invName[5] = TChar(0x0000); sl@0: rc = db.Open(invName); sl@0: db.Close(); sl@0: TEST(rc != KErrNone); sl@0: sl@0: //Copy the corrupted database file on drive C: sl@0: TEST2(fs.Connect(), KErrNone); sl@0: rc = BaflUtils::CopyFile(fs, KDbPath10, KTestDbName3); sl@0: TEST2(rc, KErrNone); sl@0: (void)fs.SetAtt(KTestDbName3, 0, KEntryAttReadOnly); sl@0: fs.Close(); sl@0: sl@0: //An attempt to open corrupted public shared database file on a drive (C:) sl@0: rc = db.Open(KTestDbName3); sl@0: TEST(rc == KSqlErrNotDb || rc == KErrNone);//Note: but it may be a different error code as well sl@0: db.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDbName3); sl@0: sl@0: //Create, Close, Open, Close and again Open database test sl@0: rc = db.Create(KTestDbName2, securityPolicy); sl@0: TEST2(rc, KErrNone); sl@0: db.Close(); sl@0: rc = db.Open(KTestDbName2); sl@0: TEST2(rc, KErrNone); sl@0: db.Close(); sl@0: rc = db.Open(KTestDbName2); sl@0: TEST2(rc, KErrNone); sl@0: db.Close(); sl@0: sl@0: //Open two connections to the same database. sl@0: rc = db.Open(KTestDbName2); sl@0: TEST2(rc, KErrNone); sl@0: rc = db2.Open(KTestDbName2); sl@0: TEST2(rc, KErrNone); sl@0: db2.Close(); sl@0: db.Close(); sl@0: sl@0: rc = RSqlDatabase::Delete(KTestDbName2); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: securityPolicy.Close(); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1602 sl@0: @SYMTestCaseDesc Setting database isolation level tests. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for RSqlDatabase::SetIsolationLevel() method. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void SetIsolationLevelTest() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: sl@0: RSqlDatabase db; sl@0: TInt err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = db.SetIsolationLevel(RSqlDatabase::EReadCommitted); sl@0: TEST2(err, KErrNotSupported); sl@0: sl@0: err = db.SetIsolationLevel(RSqlDatabase::ERepeatableRead); sl@0: TEST2(err, KErrNotSupported); sl@0: sl@0: err = db.SetIsolationLevel(RSqlDatabase::EReadUncommitted); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = db.SetIsolationLevel(RSqlDatabase::ESerializable); sl@0: TEST2(err, KErrNone); sl@0: sl@0: db.Close(); sl@0: sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1603 sl@0: @SYMTestCaseDesc Deleting database tests. Deleting non-existing database, opened database, sl@0: database on non-existing drive, zero-length database name, only path (no file name), sl@0: rom drive based database. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for RSqlDatabase::Delete() method. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void DeleteDatabaseTest() sl@0: { sl@0: //An attempt to delete non-existing secure shared database sl@0: _LIT(KDbName1, "C:[1111CCCC]EE__900000.adb"); sl@0: TInt err = RSqlDatabase::Delete(KDbName1); sl@0: TEST2(err, KErrNotFound); sl@0: sl@0: //An attempt to delete non-existing public database sl@0: _LIT(KDbName2, "C:\\TEST\\__900000.adb"); sl@0: err = RSqlDatabase::Delete(KDbName2); sl@0: TEST2(err, KErrNotFound); sl@0: sl@0: //Zero length database file name. sl@0: _LIT(KDbName3, ""); sl@0: err = RSqlDatabase::Delete(KDbName3); sl@0: TEST2(err, KErrBadName); sl@0: sl@0: //Database file name containing only the drive name sl@0: _LIT(KDbName4, "C:"); sl@0: err = RSqlDatabase::Delete(KDbName4); sl@0: TEST2(err, KErrBadName); sl@0: sl@0: //Database file name containing only the path, without the file name sl@0: _LIT(KDbName5, "C:"); sl@0: err = RSqlDatabase::Delete(KDbName5); sl@0: TEST2(err, KErrBadName); sl@0: sl@0: //Public shared database file on a non-existing drive (A:) sl@0: _LIT(KDbName6, "A:\\test\\db1.db"); sl@0: err = RSqlDatabase::Delete(KDbName6); sl@0: TEST2(err, KErrNotReady); sl@0: sl@0: //An attempt to delete opened database. sl@0: RSqlDatabase db; sl@0: err = db.Create(KDbName7); sl@0: TEST2(err, KErrNone); sl@0: err = RSqlDatabase::Delete(KDbName7); sl@0: TEST2(err, KErrInUse); sl@0: db.Close(); sl@0: err = RSqlDatabase::Delete(KDbName7); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //An attempt to delete existing public shared database file on a read-only drive (Z:) sl@0: _LIT(KDbName8, "Z:\\TEST\\TestDb1.db"); sl@0: err = RSqlDatabase::Delete(KDbName8); sl@0: TEST2(err, KErrAccessDenied); sl@0: sl@0: //Create secure database sl@0: TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass); sl@0: RSqlSecurityPolicy securityPolicy; sl@0: err = securityPolicy.Create(defaultPolicy); sl@0: TEST2(err, KErrNone); sl@0: err = db.Create(KTestDbName7, securityPolicy); sl@0: TEST2(err, KErrNone); sl@0: db.Close(); sl@0: securityPolicy.Close(); sl@0: sl@0: //Attempt to delete a secure public database. sl@0: //The calling application has no rights to delete a file with that name from the server's sl@0: //private data cage. sl@0: err = RSqlDatabase::Delete(_L("C:[45454545]qq.db")); sl@0: TEST2(err, KErrPermissionDenied); sl@0: sl@0: //Attempt to delete a secure public database. No drive specified. sl@0: //The calling application has no rights to delete a file with that name from the server's sl@0: //private data cage. sl@0: err = RSqlDatabase::Delete(_L("[45454545]qq.db")); sl@0: TEST2(err, KErrPermissionDenied); sl@0: sl@0: //Attempt to delete secure database specifying the full database path sl@0: TParse parse; sl@0: parse.Set(KTestDbName7, &KServerPrivateDir(), 0); sl@0: err = RSqlDatabase::Delete(parse.FullName()); sl@0: TEST2(err, KErrArgument); sl@0: sl@0: //Attempt to delete secure database specifying only the database name sl@0: err = RSqlDatabase::Delete(parse.NameAndExt()); sl@0: //If C: is the system drive then the operation must pass. sl@0: TEST2(err, KErrNone); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1640 sl@0: @SYMTestCaseDesc Copying database tests. Copying: sl@0: - non-secure to non-secure database; sl@0: - non-secure to secure database; sl@0: - secure to non-secure database; sl@0: - secure to secure database; sl@0: - secure database, when the application is not the database creator (owner); sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for RSqlDatabase::Copy() method. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void CopyDatabaseTest() sl@0: { sl@0: RSqlDatabase db; sl@0: sl@0: //Create secure database sl@0: TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass); sl@0: RSqlSecurityPolicy securityPolicy; sl@0: TInt err = securityPolicy.Create(defaultPolicy); sl@0: TEST2(err, KErrNone); sl@0: err = db.Create(KTestDbName7, securityPolicy); sl@0: TEST2(err, KErrNone); sl@0: db.Close(); sl@0: securityPolicy.Close(); sl@0: sl@0: //Create non-secure database sl@0: err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: db.Close(); sl@0: sl@0: //Copy non-secure to non-secure database sl@0: err = RSqlDatabase::Copy(KTestDbName1, KTestDbName8); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //Attempt to copy non-secure to secure database sl@0: err = RSqlDatabase::Copy(KTestDbName1, _L("C:[99999999]pkk.db")); sl@0: TEST2(err, KErrPermissionDenied); sl@0: sl@0: //Attempt to copy secure to non-secure database sl@0: err = RSqlDatabase::Copy(KTestDbName7, _L("C:\\test\\asdf.db")); sl@0: TEST2(err, KErrPermissionDenied); sl@0: sl@0: //Copy secure to secure database. The test application is the database owner. sl@0: err = RSqlDatabase::Copy(KTestDbName7, KTestDbName4); sl@0: TEST2(err, KErrNone); sl@0: err = RSqlDatabase::Delete(KTestDbName4); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //Attempt to copy secure to secure database. The test application is not the database owner. sl@0: err = RSqlDatabase::Copy(KTestDbName7, _L("C:[11111111]ff.db")); sl@0: TEST2(err, KErrPermissionDenied); sl@0: err = RSqlDatabase::Copy(_L("C:[11111111]ff.db"), _L("C:[22222222]ff.db")); sl@0: TEST2(err, KErrPermissionDenied); sl@0: err = RSqlDatabase::Copy(_L("C:[11111111]ff.db"), KTestDbName7); sl@0: TEST2(err, KErrPermissionDenied); sl@0: sl@0: (void)RSqlDatabase::Delete(KTestDbName8); sl@0: (void)RSqlDatabase::Delete(KTestDbName7); sl@0: (void)RSqlDatabase::Delete(KTestDbName4); sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1604 sl@0: @SYMTestCaseDesc Create a table with two integer columns. The second column has a default value NULL. sl@0: Check what will be the result of "column1 + column2" operation, if "column2" sl@0: value is NULL. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests mathematical operations with ESqlNull column values. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void NullColumnValues() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: sl@0: RSqlDatabase db; sl@0: TInt err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = db.Exec(_L8("CREATE TABLE test(int_fld integer, null_int_fld integer default null)")); sl@0: TEST(err >= 0); sl@0: sl@0: err = db.Exec(_L8("INSERT INTO test(int_fld) values(200)")); sl@0: TEST2(err, 1); sl@0: sl@0: RSqlStatement stmt; sl@0: sl@0: err = stmt.Prepare(db, _L8("SELECT * from test")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: sl@0: TSqlColumnType colType = stmt.ColumnType(0); sl@0: TEST(colType == ESqlInt); sl@0: sl@0: colType = stmt.ColumnType(1); sl@0: TEST(colType == ESqlNull); sl@0: sl@0: TInt val = stmt.ColumnInt(0); sl@0: TEST(val == 200); sl@0: sl@0: val = stmt.ColumnInt(1); sl@0: TEST(val == 0); sl@0: sl@0: stmt.Close(); sl@0: sl@0: err = stmt.Prepare(db, _L8("SELECT (int_fld + null_int_fld) as res from test")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: sl@0: colType = stmt.ColumnType(0); sl@0: TEST(colType == ESqlNull); sl@0: sl@0: val = stmt.ColumnInt(0); sl@0: TEST(val == 0); sl@0: sl@0: stmt.Close(); sl@0: db.Close(); sl@0: sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: _LIT8(KStmt1, "CREATE TABLE A1(Fld1 INTEGER, Fld2 DOUBLE);\ sl@0: CREATE TABLE A2(Fld1 INTEGER, Fld2 DOUBLE);\ sl@0: CREATE TRIGGER TrgA1Ins BEFORE Insert ON A1\ sl@0: BEGIN\ sl@0: INSERT INTO A2(Fld1, Fld2) VALUES(new.Fld1, new.Fld2);\ sl@0: END;"); sl@0: _LIT8(KStmt2, "INSERT INTO A1(Fld1, Fld2) VALUES(1, 2.0)"); sl@0: _LIT8(KStmt3, "SELECT * FROM A2"); sl@0: _LIT8(KStmt4, "INSERT INTO A1(Fld1, Fld2) VALUES(2, 4.0); UPDATE A2 SET Fld2 = 11.3 WHERE Fld1 = 2"); sl@0: _LIT8(KStmt5, ""); sl@0: _LIT8(KStmt6, "INSERT INTO A1(Fld1, Fld2) VALUESa(6, 234.0);"); sl@0: _LIT8(KStmt7, ""); sl@0: _LIT8(KStmt8, ";;;;;"); sl@0: _LIT8(KStmt9, "INSERT INTO A1(Fld1, Fld2) VALUES(:v1, :v2)"); sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1605 sl@0: @SYMTestCaseDesc SQL statements execution. Valid SQL statements. Empty SQL statement. sl@0: More than one SQL statements, separated with ";". SQL statement which syntax is sl@0: incorrect. SQL statement with parameters. INSERT/SELECT/CREATE TABLE SQL statements. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlDatabase::Exec() tests, 16-bit and 8-bit SQL statements sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: template void ExecOnDbTest() sl@0: { sl@0: RSqlDatabase db; sl@0: TInt rc = db.Create(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Create two tables and a trigger sl@0: ExecSqlStmtOnDb(db, KStmt1, KErrNone); sl@0: sl@0: //INSERT sql statement execution sl@0: ExecSqlStmtOnDb(db, KStmt2, KErrNone); sl@0: sl@0: //SELECT sql statement execution sl@0: ExecSqlStmtOnDb(db, KStmt3, KErrNone); sl@0: sl@0: //Executing more than one SQL statement in a single Exec() call. sl@0: ExecSqlStmtOnDb(db, KStmt4, KErrNone); sl@0: sl@0: //Executing zero length SQL statement. sl@0: ExecSqlStmtOnDb(db, KStmt5, KErrNone); sl@0: sl@0: //Executing a SQL statement with syntax errors. sl@0: ExecSqlStmtOnDb(db, KStmt6, KSqlErrGeneral); sl@0: sl@0: //Executing an empty SQL statement. sl@0: ExecSqlStmtOnDb(db, KStmt7, KErrNone); sl@0: sl@0: //Executing a SQL string, which does not have any SQL statements inside, but has valid syntax. sl@0: ExecSqlStmtOnDb(db, KStmt8, KErrNone); sl@0: sl@0: //Executing SQL statement with parameters. They will be set with NULL values, if not set explicitly. sl@0: ExecSqlStmtOnDb(db, KStmt9, KErrNone); sl@0: sl@0: db.Close(); sl@0: sl@0: rc = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: sl@0: _LIT8(KStmt10, ""); sl@0: _LIT8(KStmt11, "; ; ;;;"); sl@0: _LIT8(KStmt12, "CREATE TABLE AAA(Fld1 INTEGER, Fld2 VARCHAR(100))"); sl@0: _LIT8(KStmt13, "INSERT INTO AAA(Fld1, Fld2) VALUES(5, 'FldVal1-1234567890')"); sl@0: _LIT8(KStmt14, "SELECT fld1, fld2 FROM AAA"); sl@0: _LIT8(KStmt15, "SELECT fld2, fld1 FROM AAA"); sl@0: _LIT8(KStmt16, "SELECT fld2, fld1 FROM AAA WHERE Fld1 > :Prm1 AND fld2 = :PRM2"); sl@0: _LIT8(KStmt17, "INSERT INTO AAA(Fld1, Fld2) VALUES(:b, :a);"); sl@0: _LIT8(KStmt18, "CREATE TABLE BBB(Fld1 INTEGER, Fld2 BIGINT, Fld3 DOUBLE, \ sl@0: Fld4 TEXT, Fld5 LONGBLOB, Fld6 TEXT NULL)"); sl@0: _LIT8(KStmt19, "INSERT INTO BBB(Fld1, Fld2, Fld3, Fld4, Fld5, Fld6)\ sl@0: VALUES(:V1, :V2, :V3, :V4, :V5, :V6)"); sl@0: _LIT8(KStmt20, "SELECT * FROM BBB"); sl@0: _LIT8(KStmt21, "SELECT fld1, fld2 FROM AAA;SELECT fld1, fld2 FROM AAA"); sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1606 sl@0: @SYMTestCaseDesc Preparing SQL statements. Moving to the next record. Retrieving and verifying sl@0: the column types and values. Binding parameter values. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlStatement::Prepare(), RSqlStatement::Next() tests, 16-bit and 8-bit SQL statements. sl@0: RSqlStatement::ColumnIndex(), RSqlStatement::Column(), RSqlStatement::Bind(), sl@0: RSqlStatement::Column(). sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: template void StatementTest() sl@0: { sl@0: RSqlDatabase db; sl@0: TInt rc = db.Create(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Executing an empty SQL statement. sl@0: RSqlStatement stmt = PrepareSqlStmt(db, KStmt10, KErrArgument); sl@0: stmt.Close(); sl@0: sl@0: //Executing a SQL string, which does not have any SQL statements inside, but has valid syntax. sl@0: stmt = PrepareSqlStmt(db, KStmt11, KErrArgument); sl@0: stmt.Close(); sl@0: sl@0: //SQL statement without parameters. Create a table. sl@0: stmt = PrepareSqlStmt(db, KStmt12, KErrNone); sl@0: ExecSqlStmt(db, stmt, KErrNone); sl@0: stmt.Close(); sl@0: sl@0: //String containg more than one SQL statement. sl@0: stmt = PrepareSqlStmt(db, KStmt21, KErrArgument); sl@0: stmt.Close(); sl@0: sl@0: //SQL statement without parameters. Insert a record into the table. sl@0: stmt = PrepareSqlStmt(db, KStmt13, KErrNone); sl@0: ExecSqlStmt(db, stmt, KErrNone); sl@0: stmt.Close(); sl@0: sl@0: //Test RSqlStatement::ColumnIndex(). sl@0: stmt = PrepareSqlStmt(db, KStmt14, KErrNone); sl@0: TInt idx1 = stmt.ColumnIndex(_L("FLD1")); sl@0: TEST(idx1 == 0); sl@0: TInt idx2 = stmt.ColumnIndex(_L("FlD2")); sl@0: TEST(idx2 == 1); sl@0: TInt idx3 = stmt.ColumnIndex(_L("fld3")); sl@0: TEST(idx3 < 0); sl@0: stmt.Close(); sl@0: sl@0: stmt = PrepareSqlStmt(db, KStmt15, KErrNone); sl@0: idx1 = stmt.ColumnIndex(_L("FLD1")); sl@0: TEST(idx1 == 1); sl@0: idx2 = stmt.ColumnIndex(_L("FlD2")); sl@0: TEST(idx2 == 0); sl@0: idx3 = stmt.ColumnIndex(_L("fld3")); sl@0: TEST(idx3 < 0); sl@0: sl@0: //Test RSqlStatement::Column() methods. sl@0: TInt recCnt = 0; sl@0: while((rc = stmt.Next()) == KSqlAtRow) sl@0: { sl@0: ++recCnt; sl@0: sl@0: TInt intVal = stmt.ColumnInt(idx1); sl@0: TEST(intVal == 5); sl@0: sl@0: //Integer column value retrieved as a text. sl@0: TPtrC strVal1; sl@0: TInt err = stmt.ColumnText(idx1, strVal1); sl@0: TEST2(err, KErrNone); sl@0: TEST(strVal1 == KNullDesC); sl@0: sl@0: //Text column value retrieved as a binary sl@0: TBuf8<50> strVal3; sl@0: err = stmt.ColumnBinary(idx2, strVal3); sl@0: TEST2(err, KErrNone); sl@0: TEST(strVal3 == KNullDesC8); sl@0: sl@0: TPtrC strVal2; sl@0: err = stmt.ColumnText(idx2, strVal2); sl@0: TEST2(err, KErrNone); sl@0: TEST(strVal2 == _L("FldVal1-1234567890")); sl@0: sl@0: //Invalid column index. Panic: "SqlDb 5" sl@0: //intVal = stmt.ColumnInt(1002); sl@0: //intVal = stmt.ColumnInt(-24); sl@0: } sl@0: stmt.Close(); sl@0: TEST2(rc, KSqlAtEnd); sl@0: TEST2(SqlRetCodeClass(rc), ESqlInformation); sl@0: TEST(recCnt == 1); sl@0: sl@0: //Test RSqlStatement::Bind() methods. sl@0: stmt = PrepareSqlStmt(db, KStmt16, KErrNone); sl@0: idx1 = stmt.ColumnIndex(_L("FLD1")); sl@0: TEST(idx1 == 1); sl@0: idx2 = stmt.ColumnIndex(_L("FlD2")); sl@0: TEST(idx2 == 0); sl@0: TInt prmIdx1 = stmt.ParameterIndex(_L(":prm1")); sl@0: TEST(prmIdx1 == 0); sl@0: TInt prmIdx2 = stmt.ParameterIndex(_L(":prm2")); sl@0: TEST(prmIdx2 == 1); sl@0: rc = stmt.BindInt(prmIdx1, -4); sl@0: //No problem to bind whatever value type we like sl@0: //rc = stmt.BindBinary(prmIdx1, KSqlStmt4()); sl@0: TEST2(rc, KErrNone); sl@0: rc = stmt.BindText(prmIdx2, _L("FldVal1-1234567890")); sl@0: TEST2(rc, KErrNone); sl@0: //Test RSqlStatement::Column() methods. sl@0: recCnt = 0; sl@0: while((rc = stmt.Next()) == KSqlAtRow) sl@0: { sl@0: ++recCnt; sl@0: TInt intVal = stmt.ColumnInt(idx1); sl@0: TEST(intVal == 5); sl@0: TPtrC strVal; sl@0: TInt err = stmt.ColumnText(idx2, strVal); sl@0: TEST2(err, KErrNone); sl@0: TEST(strVal == _L("FldVal1-1234567890")); sl@0: } sl@0: stmt.Close(); sl@0: TEST2(rc, KSqlAtEnd); sl@0: TEST2(SqlRetCodeClass(rc), ESqlInformation); sl@0: TEST(recCnt == 1); sl@0: sl@0: //Test an INSERT SQL - prepare, bind, exec. sl@0: stmt = PrepareSqlStmt(db, KStmt17, KErrNone); sl@0: prmIdx1 = stmt.ParameterIndex(_L(":A")); sl@0: TEST(prmIdx1 == 1); sl@0: prmIdx2 = stmt.ParameterIndex(_L(":B")); sl@0: TEST(prmIdx2 == 0); sl@0: rc = stmt.BindInt(prmIdx1, 20); sl@0: TEST2(rc, KErrNone); sl@0: rc = stmt.BindText(prmIdx2, _L("FldVal2")); sl@0: TEST2(rc, KErrNone); sl@0: rc = stmt.Exec(); sl@0: TEST2(rc, 1); sl@0: sl@0: stmt.Close(); sl@0: sl@0: //Create a table with INTEGER, INT64, REAL, TEXT, BINARY, NULL, field types sl@0: stmt = PrepareSqlStmt(db, KStmt18, KErrNone); sl@0: ExecSqlStmt(db, stmt, KErrNone); sl@0: stmt.Close(); sl@0: sl@0: enum {KLow = 1, KHigh = 2}; sl@0: //Insert (KHigh - KLow + 1) records sl@0: stmt = PrepareSqlStmt(db, KStmt19, KErrNone); sl@0: TInt v32 = 1024; sl@0: TInt64 v64 = MAKE_TINT64(0x00FF00FF, 0x12345678); sl@0: TReal vReal = 234.75; sl@0: TBuf<10> vText; sl@0: TBuf8<10> vBinary; sl@0: for(TInt i=KLow;i<=KHigh;++i) sl@0: { sl@0: rc = stmt.BindInt(0, v32 * i); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: rc = stmt.BindInt64(1, v64 * i); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: rc = stmt.BindReal(2, vReal * i); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: vText.Copy(_L("TEXT")); sl@0: vText.Append(TChar(i + '0')); sl@0: rc = stmt.BindText(3, vText); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: vBinary.Copy(_L("BINARY")); sl@0: vBinary.Append(TChar(i + '0')); sl@0: rc = stmt.BindBinary(4, vBinary); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: rc = stmt.BindNull(5); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: rc = stmt.Exec(); sl@0: TEST2(rc, 1); sl@0: sl@0: rc = stmt.Reset(); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: stmt.Close(); sl@0: sl@0: //Read and test (KHigh - KLow + 1) records sl@0: stmt = PrepareSqlStmt(db, KStmt20, KErrNone); sl@0: recCnt = 0; sl@0: while((rc = stmt.Next()) == KSqlAtRow) sl@0: { sl@0: ++recCnt; sl@0: TInt v1 = stmt.ColumnInt(0); sl@0: TEST(v1 == v32 * recCnt); sl@0: sl@0: TInt64 v2 = stmt.ColumnInt64(1); sl@0: TEST(v2 == v64 * recCnt); sl@0: sl@0: TReal v3 = stmt.ColumnReal(2); sl@0: TEST(Abs(v3 - vReal * recCnt) < 0.000001); sl@0: sl@0: vText.Copy(_L("TEXT")); sl@0: vText.Append(TChar(recCnt + '0')); sl@0: TPtrC v4; sl@0: TInt err = stmt.ColumnText(3, v4); sl@0: TEST2(err, KErrNone); sl@0: TEST(v4 == vText); sl@0: sl@0: vBinary.Copy(_L("BINARY")); sl@0: vBinary.Append(TChar(recCnt + '0')); sl@0: TPtrC8 v5; sl@0: err = stmt.ColumnBinary(4, v5); sl@0: TEST2(err, KErrNone); sl@0: TEST(v5 == vBinary); sl@0: sl@0: TBool b = stmt.IsNull(5); sl@0: TEST(b != 0); sl@0: } sl@0: stmt.Close(); sl@0: TEST2(rc, KSqlAtEnd); sl@0: TEST2(SqlRetCodeClass(rc), ESqlInformation); sl@0: TEST(recCnt == (KHigh - KLow + 1)); sl@0: sl@0: db.Close(); sl@0: sl@0: rc = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1607 sl@0: @SYMTestCaseDesc Retrieving long text column values test. sl@0: Retrieving long column values using RSqlStatement::ColumnText() when the recipient buffer sl@0: is not big enough. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlColumnReadStream::ColumnText() test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void ColumnTextStreamTest() sl@0: { sl@0: RSqlDatabase db; sl@0: TInt rc = db.Create(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: enum {KSqlBufSize = 64}; sl@0: sl@0: //Create a table sl@0: _LIT8(KSqlStmt1, "CREATE TABLE A(Fld1 INTEGER, Fld2 TEXT);"); sl@0: ExecSqlStmtOnDb >(db, KSqlStmt1(), KErrNone); sl@0: sl@0: const TInt KTextLen = 3101; sl@0: sl@0: _LIT(KSqlStmt2, "INSERT INTO A(Fld1, Fld2) VALUES("); sl@0: sl@0: //Allocate a buffer for the SQL statement. sl@0: HBufC* buf = HBufC::New(KSqlStmt2().Length() + KTextLen + 10); sl@0: TEST(buf != NULL); sl@0: sl@0: TPtr sql = buf->Des(); sl@0: sl@0: //Insert row 1 sl@0: sl@0: const TChar KChar1('A'); sl@0: sql.Copy(KSqlStmt2); sl@0: sql.Append(_L("1, '")); sl@0: TInt i; sl@0: for(i=0;i >(db, KSqlStmt3, KErrNone); sl@0: sl@0: //Move on row 1 sl@0: rc = stmt.Next(); sl@0: TEST2(rc, KSqlAtRow); sl@0: sl@0: //An attempt to read integer column using binary stream sl@0: RSqlColumnReadStream strm2; sl@0: rc = strm2.ColumnBinary(stmt, 0); sl@0: strm2.Close(); sl@0: TEST2(rc, KErrArgument); sl@0: sl@0: //An attempt to read integer column using text stream sl@0: rc = strm2.ColumnText(stmt, 0); sl@0: strm2.Close(); sl@0: TEST2(rc, KErrArgument); sl@0: sl@0: //Read the long text column using a stream sl@0: RSqlColumnReadStream columnStream; sl@0: rc = columnStream.ColumnText(stmt, 1); sl@0: columnStream.Close(); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //...and the leaving version of ColumnText() sl@0: TRAP(rc, columnStream.ColumnTextL(stmt, 1)); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: TInt size = stmt.ColumnSize(1); sl@0: TPtr colData = buf->Des(); sl@0: TRAP(rc, columnStream.ReadL(colData, size)); sl@0: columnStream.Close(); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Check the column value sl@0: for(i=0;i buf1; sl@0: rc = stmt.ColumnText(1, buf1); sl@0: TEST2(rc, KErrOverflow); sl@0: sl@0: //Check the column value sl@0: for(i=0;i colBuf; sl@0: rc = stmt.ColumnText(1, colBuf); sl@0: TEST2(rc, KErrOverflow); sl@0: //Check the column value sl@0: for(i=0;i >(db, KSqlStmt1(), KErrNone); sl@0: sl@0: const TInt KDataLen = 3311; sl@0: sl@0: _LIT8(KSqlStmt2, "INSERT INTO A(Fld1, Fld2) VALUES("); sl@0: sl@0: //Allocate a buffer for the SQL statement. sl@0: HBufC8* buf = HBufC8::New(KSqlStmt2().Length() + KDataLen * 2 + 10);//"* 2" - SQL statement with HEX values sl@0: TEST(buf != NULL); sl@0: sl@0: TPtr8 sql = buf->Des(); sl@0: sl@0: //Insert row 1 sl@0: sl@0: const TUint8 KHexVal1 = 0x7E; sl@0: _LIT8(KHexValStr1, "7E"); sl@0: sql.Copy(KSqlStmt2); sl@0: sql.Append(_L8("1, x'")); sl@0: TInt i; sl@0: for(i=0;i >(db, KSqlStmt3, KErrNone); sl@0: sl@0: //Move on row 1 sl@0: rc = stmt.Next(); sl@0: TEST2(rc, KSqlAtRow); sl@0: sl@0: //Read the long binary column using a stream sl@0: RSqlColumnReadStream columnStream; sl@0: rc = columnStream.ColumnBinary(stmt, 1); sl@0: columnStream.Close(); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //...and the leaving version of ColumnBinary() sl@0: TRAP(rc, columnStream.ColumnBinaryL(stmt, 1)); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: TInt size = stmt.ColumnSize(1); sl@0: TPtr8 colData = buf->Des(); sl@0: TRAP(rc, columnStream.ReadL(colData, size)); sl@0: columnStream.Close(); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Check the column value sl@0: for(i=0;i colBuf; sl@0: rc = stmt.ColumnBinary(1, colBuf); sl@0: TEST2(rc, KErrOverflow); sl@0: //Check the column value sl@0: for(i=0;i buf1; sl@0: rc = stmt.ColumnBinary(1, buf1); sl@0: TEST2(rc, KErrNone); sl@0: TEST2(buf1.Length(), 2); sl@0: TBuf8<1> buf2; sl@0: rc = stmt.ColumnBinary(1, buf2); sl@0: TEST2(rc, KErrOverflow); sl@0: sl@0: stmt.Close(); sl@0: sl@0: //Deallocate buf sl@0: delete buf; sl@0: buf = NULL; sl@0: sl@0: db.Close(); sl@0: sl@0: rc = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-CT-4191 sl@0: @SYMTestCaseDesc The test creates a test database and inserts one record using a stream. sl@0: MStreamBuf::SeekL() is used to modify the parameter data at specific positions. sl@0: Then the test executes a SELECT statement to read the just written record. sl@0: MStreamBuf::SeekL() is used to read the column content at specific positions sl@0: (the same positions used during the record write operation). The read byte values must sl@0: match the written byte values. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlColumnReadStream::ColumnBinary() and RSqlParamWriteStream::BindBinary() - MStreamBuf::SeekL() test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF145125 sl@0: */ sl@0: void StreamSeekTestL() sl@0: { sl@0: RSqlDatabase db; sl@0: CleanupClosePushL(db); sl@0: TInt rc = db.Create(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: rc = db.Exec(_L("CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB)")); sl@0: TEST(rc >= 0); sl@0: //Write a record to the database using a stream. MStreamBuf::SeekL() is used to modify the content at a specific position. sl@0: RSqlStatement stmt; sl@0: CleanupClosePushL(stmt); sl@0: rc = stmt.Prepare(db, _L("INSERT INTO A(Fld1, Fld2) VALUES(1, ?)")); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: RSqlParamWriteStream strm1; sl@0: CleanupClosePushL(strm1); sl@0: rc = strm1.BindBinary(stmt, 0); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: for(TInt i=0;i<256;++i) sl@0: { sl@0: strm1 << (TUint8)i; sl@0: } sl@0: sl@0: const TInt KStreamOffset = 10; sl@0: const TUint8 KByte = 'z'; sl@0: _LIT8(KData, "QWERTYUIOPASDFG"); sl@0: sl@0: MStreamBuf* strm1buf = strm1.Sink(); sl@0: TEST(strm1buf != NULL); sl@0: sl@0: strm1buf->SeekL(MStreamBuf::EWrite, EStreamBeginning, 0); sl@0: strm1buf->WriteL(&KByte, 1); sl@0: sl@0: strm1buf->SeekL(MStreamBuf::EWrite, EStreamMark, KStreamOffset); sl@0: strm1buf->WriteL(&KByte, 1); sl@0: sl@0: strm1buf->SeekL(MStreamBuf::EWrite, EStreamEnd, 0); sl@0: strm1buf->WriteL(KData().Ptr(), KData().Length()); sl@0: sl@0: strm1buf->SeekL(MStreamBuf::EWrite, EStreamEnd, -4 * KStreamOffset); sl@0: strm1buf->WriteL(&KByte, 1); sl@0: sl@0: strm1.CommitL(); sl@0: CleanupStack::PopAndDestroy(&strm1); sl@0: sl@0: rc = stmt.Exec(); sl@0: TEST2(rc, 1); sl@0: CleanupStack::PopAndDestroy(&stmt); sl@0: sl@0: //Read the record using a stream. MStreamBuf::SeekL() is used to read the content at a specific position. sl@0: CleanupClosePushL(stmt); sl@0: rc = stmt.Prepare(db, _L("SELECT Fld2 FROM A WHERE Fld1 = 1")); sl@0: TEST2(rc, KErrNone); sl@0: rc = stmt.Next(); sl@0: TEST2(rc, KSqlAtRow); sl@0: sl@0: RSqlColumnReadStream strm2; sl@0: CleanupClosePushL(strm2); sl@0: rc = strm2.ColumnBinary(stmt, 0); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: TUint8 byte = 0; sl@0: MStreamBuf* strm2buf = strm2.Source(); sl@0: TEST(strm1buf != NULL); sl@0: sl@0: strm2buf->SeekL(MStreamBuf::ERead, EStreamBeginning, 0); sl@0: rc = strm2buf->ReadL(&byte, 1); sl@0: TEST2(rc, 1); sl@0: TEST2(byte, KByte); sl@0: sl@0: strm2buf->SeekL(MStreamBuf::ERead, EStreamMark, KStreamOffset); sl@0: rc = strm2buf->ReadL(&byte, 1); sl@0: TEST2(rc, 1); sl@0: TEST2(byte, KByte); sl@0: sl@0: strm2buf->SeekL(MStreamBuf::ERead, EStreamEnd, -KData().Length()); sl@0: TUint8 buf[20]; sl@0: rc = strm2buf->ReadL(buf, KData().Length()); sl@0: TEST2(rc, KData().Length()); sl@0: TPtrC8 bufptr(buf, rc); sl@0: TEST(bufptr == KData); sl@0: sl@0: strm2buf->SeekL(MStreamBuf::ERead, EStreamEnd, -4 * KStreamOffset); sl@0: rc = strm2buf->ReadL(&byte, 1); sl@0: TEST2(rc, 1); sl@0: TEST2(byte, KByte); sl@0: sl@0: CleanupStack::PopAndDestroy(&strm2); sl@0: CleanupStack::PopAndDestroy(&stmt); sl@0: sl@0: CleanupStack::PopAndDestroy(&db); sl@0: rc = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-CT-4174 sl@0: @SYMTestCaseDesc Test for DEF144937: SQL, SQL server, the code coverage can be improved in some areas. sl@0: @SYMTestPriority High sl@0: @SYMTestActions The test creates a test database with a table with 3 records. sl@0: The first record has a BLOB column with 0 length. sl@0: The second record has a BLOB column with length less than KSqlMaxDesLen sl@0: (in debug mode) in which case no IPC call is needed to be made in order sl@0: to access the column value via stream. sl@0: The third record has a BLOB column with length exactly KSqlMaxDesLen sl@0: in which case an IPC call will be made in order to retrieve the column value, sl@0: but the column value will be copied directly to the client - no stream object is created. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF144937 sl@0: */ sl@0: void ColumnBinaryStreamTest2() sl@0: { sl@0: RSqlDatabase db; sl@0: TInt rc = db.Create(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: enum {KSqlBufSize = 128}; sl@0: sl@0: //Create a table sl@0: _LIT8(KSqlStmt1, "CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB);"); sl@0: ExecSqlStmtOnDb >(db, KSqlStmt1(), KErrNone); sl@0: sl@0: //Insert one record where the BLOB length is 0. sl@0: //Insert second record where the BLOB length is smaller than the max inline column length - KSqlMaxDesLen. sl@0: //Insert third record where the BLOB length is exactly the max inline column length - KSqlMaxDesLen. sl@0: _LIT8(KSqlStmt2, "INSERT INTO A VALUES(1, '');INSERT INTO A VALUES(2, x'0102030405');INSERT INTO A VALUES(3, x'0102030405060708');"); sl@0: ExecSqlStmtOnDb >(db, KSqlStmt2(), KErrNone); sl@0: sl@0: RSqlStatement stmt; sl@0: rc = stmt.Prepare(db, _L("SELECT Fld2 FROM A")); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: TBuf8<16> databuf; sl@0: sl@0: rc = stmt.Next(); sl@0: TEST2(rc, KSqlAtRow); sl@0: //ColumnBinary() does not make an IPC call because the BLOB length is 0. sl@0: RSqlColumnReadStream strm; sl@0: rc = strm.ColumnBinary(stmt, 0); sl@0: TEST2(rc, KErrNone); sl@0: TRAP(rc, strm.ReadL(databuf, stmt.ColumnSize(0))); sl@0: strm.Close(); sl@0: TEST2(rc, KErrNone); sl@0: TEST2(databuf.Length(), 0); sl@0: sl@0: rc = stmt.Next(); sl@0: TEST2(rc, KSqlAtRow); sl@0: //ColumnBinary() does not make an IPC call because the BLOB length is less than the max inline sl@0: //column length - KSqlMaxDesLen. sl@0: rc = strm.ColumnBinary(stmt, 0); sl@0: TEST2(rc, KErrNone); sl@0: TRAP(rc, strm.ReadL(databuf, stmt.ColumnSize(0))); sl@0: strm.Close(); sl@0: TEST2(rc, KErrNone); sl@0: TEST(databuf == _L8("\x1\x2\x3\x4\x5")); sl@0: sl@0: rc = stmt.Next(); sl@0: TEST2(rc, KSqlAtRow); sl@0: //ColumnBinary() makes an IPC call (in _DEBUG mode) because: sl@0: // - the column length is exactly KSqlMaxDesLen. sl@0: // - but at the same time the column length is equal to KIpcBufSize (in debug mode). sl@0: rc = strm.ColumnBinary(stmt, 0); sl@0: TEST2(rc, KErrNone); sl@0: TRAP(rc, strm.ReadL(databuf, stmt.ColumnSize(0))); sl@0: strm.Close(); sl@0: TEST2(rc, KErrNone); sl@0: TEST(databuf == _L8("\x1\x2\x3\x4\x5\x6\x7\x8")); sl@0: sl@0: stmt.Close(); sl@0: db.Close(); sl@0: sl@0: rc = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1608 sl@0: @SYMTestCaseDesc Setting long text parameter values test. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlParamWriteStream::BindText() test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void TextParameterStreamTest() sl@0: { sl@0: RSqlDatabase db; sl@0: TInt rc = db.Create(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: enum {KSqlBufSize = 64}; sl@0: sl@0: //Create a table sl@0: _LIT8(KSqlStmt1, "CREATE TABLE A(Fld1 INTEGER, Fld2 TEXT);"); sl@0: ExecSqlStmtOnDb >(db, KSqlStmt1(), KErrNone); sl@0: sl@0: const TInt KTextLen = 3001; sl@0: sl@0: _LIT(KSqlStmt2, "INSERT INTO A(Fld1, Fld2) VALUES("); sl@0: sl@0: //Allocate a buffer for the SQL statement. sl@0: HBufC* buf = HBufC::New(KSqlStmt2().Length() + KTextLen + 10); sl@0: TEST(buf != NULL); sl@0: sl@0: TPtr sql = buf->Des(); sl@0: sl@0: //Insert a row sl@0: sl@0: const TChar KChar('g'); sl@0: sql.Copy(KSqlStmt2); sl@0: sql.Append(_L("1, '")); sl@0: TInt i; sl@0: for(i=0;i >(db, KSqlStmt3, KErrNone); sl@0: sl@0: //Open the parameter stream sl@0: RSqlParamWriteStream paramStream; sl@0: rc = paramStream.BindText(stmt, 0); sl@0: paramStream.Close(); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //...and the leaving version of BindText() sl@0: TRAP(rc, paramStream.BindTextL(stmt, 0)); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Prepare and set the parameter value sl@0: TPtr val = buf->Des(); sl@0: val.Zero(); sl@0: for(i=0;i >(db, KSqlStmt4(), KErrNone); sl@0: sl@0: //Prepare INSERT SQL statement. sl@0: _LIT8(KSqlStmt5, "INSERT INTO A(Fld1, Fld2) VALUES(1, :Val)"); sl@0: stmt = PrepareSqlStmt >(db, KSqlStmt5, KErrNone); sl@0: sl@0: //Open the parameter stream sl@0: rc = paramStream.BindText(stmt, 0); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Prepare and set the parameter value sl@0: TRAP(rc, (paramStream.WriteL(KTextVal), paramStream.CommitL())); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Execute the prepared SQL statement sl@0: rc = stmt.Exec(); sl@0: TEST2(rc, 1); sl@0: sl@0: paramStream.Close(); sl@0: stmt.Close(); sl@0: sl@0: //Prepare SELECT SQL statement sl@0: _LIT8(KSqlStmt6, "SELECT * FROM A WHERE Fld1 = 1"); sl@0: stmt = PrepareSqlStmt >(db, KSqlStmt6, KErrNone); sl@0: sl@0: //Move on row 1 sl@0: rc = stmt.Next(); sl@0: TEST2(rc, KSqlAtRow); sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////////////// sl@0: //Open a stream for a "short" text column. The streaming API should work with "short" text columns too. sl@0: sl@0: TBuf<20> columnVal; sl@0: RSqlColumnReadStream columnStream; sl@0: rc = columnStream.ColumnText(stmt, 1); sl@0: TEST2(rc, KErrNone); sl@0: TInt size = stmt.ColumnSize(1); sl@0: TRAP(rc, columnStream.ReadL(columnVal, size)); sl@0: columnStream.Close(); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Check the column value sl@0: TEST(columnVal == KTextVal); sl@0: sl@0: stmt.Close(); sl@0: sl@0: db.Close(); sl@0: sl@0: rc = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1622 sl@0: @SYMTestCaseDesc Setting long binary parameter values test. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlParamWriteStream::BindBinary() test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void BinaryParameterStreamTest() sl@0: { sl@0: //Create a test database sl@0: RSqlDatabase db; sl@0: TInt rc = db.Create(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: enum {KSqlBufSize = 64}; sl@0: sl@0: //Create a table sl@0: _LIT8(KSqlStmt1, "CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB);"); sl@0: ExecSqlStmtOnDb >(db, KSqlStmt1(), KErrNone); sl@0: sl@0: const TInt KDataLen = 3731; sl@0: sl@0: _LIT8(KSqlStmt2, "INSERT INTO A(Fld1, Fld2) VALUES("); sl@0: sl@0: //Allocate a buffer for the SQL statement. sl@0: HBufC8* buf = HBufC8::New(KSqlStmt2().Length() + KDataLen * 2 + 10);//"* 2" - SQL statement with HEX values sl@0: TEST(buf != NULL); sl@0: sl@0: TPtr8 sql = buf->Des(); sl@0: sl@0: //Insert a row sl@0: sl@0: const TUint8 KHexVal = 0xD3; sl@0: _LIT8(KHexValStr, "D3"); sl@0: sql.Copy(KSqlStmt2); sl@0: sql.Append(_L8("1, x'")); sl@0: TInt i; sl@0: for(i=0;i >(db, KSqlStmt3, KErrNone); sl@0: sl@0: //Open the parameter stream sl@0: RSqlParamWriteStream paramStream; sl@0: rc = paramStream.BindBinary(stmt, 0); sl@0: TEST2(rc, KErrNone); sl@0: paramStream.Close(); sl@0: //Open the parameter stream with BindBinaryL() sl@0: TRAP(rc, paramStream.BindBinaryL(stmt, 0)); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Prepare and set the parameter value (NULL parameter value) sl@0: TPtr8 prmVal = buf->Des(); sl@0: prmVal.SetLength(0); sl@0: sl@0: TRAP(rc, (paramStream.WriteL(prmVal), paramStream.CommitL())); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: rc = stmt.Next(); sl@0: TEST2(rc, KSqlAtEnd); sl@0: sl@0: paramStream.Close(); sl@0: stmt.Reset(); sl@0: sl@0: //Prepare and set the parameter value (non-NULL binary value) sl@0: rc = paramStream.BindBinary(stmt, 0); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: prmVal.SetLength(KDataLen); sl@0: for(i=0;i >(db, KSqlStmt4(), KErrNone); sl@0: sl@0: //Prepare INSERT SQL statement. sl@0: _LIT8(KSqlStmt5, "INSERT INTO A(Fld1, Fld2) VALUES(1, :Val)"); sl@0: stmt = PrepareSqlStmt >(db, KSqlStmt5, KErrNone); sl@0: sl@0: //Open the parameter stream sl@0: rc = paramStream.BindBinary(stmt, 0); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Prepare and set the parameter value sl@0: TRAP(rc, (paramStream.WriteL(KBinVal), paramStream.CommitL())); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Execute the prepared SQL statement sl@0: rc = stmt.Exec(); sl@0: TEST2(rc, 1); sl@0: sl@0: paramStream.Close(); sl@0: stmt.Close(); sl@0: sl@0: //Prepare SELECT SQL statement sl@0: _LIT8(KSqlStmt6, "SELECT * FROM A WHERE Fld1 = 1"); sl@0: stmt = PrepareSqlStmt >(db, KSqlStmt6, KErrNone); sl@0: sl@0: //Move on row 1 sl@0: rc = stmt.Next(); sl@0: TEST2(rc, KSqlAtRow); sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////////////// sl@0: //Open a stream for a "short" binary column. The streaming API should work with "short" binary columns too. sl@0: sl@0: TBuf8<20> columnVal; sl@0: RSqlColumnReadStream columnStream; sl@0: rc = columnStream.ColumnBinary(stmt, 1); sl@0: TEST2(rc, KErrNone); sl@0: TInt size = stmt.ColumnSize(1); sl@0: TRAP(rc, columnStream.ReadL(columnVal, size)); sl@0: columnStream.Close(); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: //Check the column value sl@0: TEST(columnVal == KBinVal); sl@0: sl@0: stmt.Close(); sl@0: sl@0: db.Close(); sl@0: sl@0: rc = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1634 sl@0: @SYMTestCaseDesc RSqlStatement test - nameless parameter. sl@0: Tests RSqlStatement behaviour if the prepared statement has nameless parameters. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlStatement test - nameless parameter. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void NamelessParameterTest() sl@0: { sl@0: //Create a test database sl@0: RSqlDatabase db; sl@0: TInt rc = db.Create(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: rc = db.Exec(_L("CREATE TABLE A(F1 INTEGER, F2 INTEGER, F3 INTEGER)")); sl@0: TEST(rc >= 0); sl@0: sl@0: RSqlStatement stmt; sl@0: rc = stmt.Prepare(db, _L("SELECT * FROM A WHERE F1 = ? AND F2 = ? AND F3 = :Val")); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: TEST(stmt.ParameterIndex(_L("?0")) == 0); sl@0: TEST(stmt.ParameterIndex(_L("?1")) == 1); sl@0: TEST(stmt.ParameterIndex(_L(":VAL")) == 2); sl@0: sl@0: stmt.Close(); sl@0: sl@0: db.Close(); sl@0: rc = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: sl@0: //Reads a SQL file and returns the file content as HBUFC string. sl@0: //The caller is responsible for destroying the returned HBUFC object. sl@0: template HBUFC* ReadSqlScript(const TDesC& aSqlFileName) sl@0: { sl@0: RFs fs; sl@0: TEST2(fs.Connect(), KErrNone); sl@0: sl@0: RFile file; sl@0: TEST2(file.Open(fs, aSqlFileName, EFileRead), KErrNone); sl@0: sl@0: TInt size = 0; sl@0: TEST2(file.Size(size), KErrNone); sl@0: sl@0: HBufC8* sql = HBufC8::New(size); sl@0: TEST(sql != NULL); sl@0: sl@0: TPtr8 ptr = sql->Des(); sl@0: TEST2(file.Read(ptr, size), KErrNone); sl@0: sl@0: file.Close(); sl@0: fs.Close(); sl@0: sl@0: HBUFC* sql2 = HBUFC::New(size); sl@0: TEST(sql2 != NULL); sl@0: sql2->Des().Copy(sql->Des()); sl@0: delete sql; sl@0: sl@0: return sql2; sl@0: } sl@0: //Explicit ReadSqlScript() template instantiations. sl@0: template HBufC8* ReadSqlScript(const TDesC&); sl@0: template HBufC16* ReadSqlScript(const TDesC&); sl@0: sl@0: //Searches for the next aCommitStr appearance in aSqlScript string and returns a PTRC object holding sl@0: //the SQL strings from the beginning of aSqlScript till the aCommitStr (including it). sl@0: template PTRC GetNextTrans(PTRC& aSqlScript, const DESC& aCommitStr) sl@0: { sl@0: PTRC res(NULL, 0); sl@0: TInt pos = aSqlScript.FindF(aCommitStr); sl@0: if(pos >= 0) sl@0: { sl@0: pos += aCommitStr.Length(); sl@0: res.Set(aSqlScript.Left(pos)); sl@0: aSqlScript.Set(aSqlScript.Mid(pos)); sl@0: } sl@0: return res; sl@0: } sl@0: //Explicit GetNextTrans() template instantiations. sl@0: template TPtrC8 GetNextTrans(TPtrC8&, const TDesC8&); sl@0: template TPtrC16 GetNextTrans(TPtrC16&, const TDesC16&); sl@0: sl@0: //Creates aDb database schema. sl@0: void CreateDbSchema(RSqlDatabase& aDb) sl@0: { sl@0: HBufC8* createDbScript = ReadSqlScript(KCreateDbScript()); sl@0: TInt err = aDb.Exec(createDbScript->Des()); sl@0: TEST(err >= 0); sl@0: delete createDbScript; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1768 sl@0: @SYMTestCaseDesc The test creates a database. sl@0: Then the test executes 8-bit and 16-bit sql statements asynchronously sl@0: (using asynchronous versions of RSqlDatabase::Exec() and RSqlStatement::Exec()) sl@0: @SYMTestPriority High sl@0: @SYMTestActions SQL, Asynchronous sql statements execution. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ5792 sl@0: REQ5793 sl@0: */ sl@0: void AsyncTest() sl@0: { sl@0: ////////////////////////////////////////////////////////////////////////// sl@0: //Asynchronous execution, 8-bit sql statements sl@0: //Create the database sl@0: RSqlDatabase db; sl@0: TInt err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: CreateDbSchema(db); sl@0: //Read the sql script file and execute the statements sl@0: HBufC8* fillDbScript1 = ReadSqlScript(KFillDbScript()); sl@0: TPtrC8 ptr1(fillDbScript1->Des()); sl@0: TPtrC8 sql1(GetNextTrans(ptr1, KCommitStr8())); sl@0: TRequestStatus status; sl@0: db.Exec(sql1, status); sl@0: TEST2(status.Int(), KRequestPending); sl@0: User::WaitForRequest(status); sl@0: TEST(status.Int() >= 0); sl@0: delete fillDbScript1; sl@0: ////////////////////////////////////////////////////////////////////////// sl@0: //Asynchronous execution, RSqlStatement::Exec(). sl@0: RSqlStatement stmt; sl@0: sl@0: err = stmt.Prepare(db, _L("UPDATE IDENTITYTABLE SET CM_FIRSTNAME=:V1")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.BindText(0, _L("+++first+++")); sl@0: TEST2(err, KErrNone); sl@0: stmt.Exec(status); sl@0: TEST2(status.Int(), KRequestPending); sl@0: User::WaitForRequest(status); sl@0: TEST(status.Int() >= 0); sl@0: stmt.Close(); sl@0: sl@0: err = stmt.Prepare(db, _L("UPDATE IDENTITYTABLE SET CM_FIRSTNAME='+++first+++'")); sl@0: TEST2(err, KErrNone); sl@0: stmt.Exec(status); sl@0: TEST2(status.Int(), KRequestPending); sl@0: User::WaitForRequest(status); sl@0: TEST(status.Int() >= 0); sl@0: stmt.Close(); sl@0: sl@0: //Verify the UPDATE operation sl@0: err = stmt.Prepare(db, _L("SELECT COUNT(*) FROM identitytable WHERE cm_firstname = '+++first+++'")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Next(); sl@0: TEST2(err, KSqlAtRow); sl@0: TInt cnt = stmt.ColumnInt(0); sl@0: TEST2(cnt, 64); sl@0: stmt.Close(); sl@0: //Close and delete the database sl@0: db.Close(); sl@0: err = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: ////////////////////////////////////////////////////////////////////////// sl@0: //Asynchronous execution, 16-bit sql statements sl@0: //Create the database sl@0: err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: CreateDbSchema(db); sl@0: //Read the sql script file and execute the statements sl@0: HBufC16* fillDbScript2 = ReadSqlScript(KFillDbScript()); sl@0: TPtrC16 ptr2(fillDbScript2->Des()); sl@0: TPtrC16 sql2(GetNextTrans(ptr2, KCommitStr16())); sl@0: db.Exec(sql2, status); sl@0: TEST2(status.Int(), KRequestPending); sl@0: User::WaitForRequest(status); sl@0: TEST(status.Int() >= 0); sl@0: delete fillDbScript2; sl@0: //Close and delete the database sl@0: db.Close(); sl@0: err = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1816 sl@0: @SYMTestCaseDesc RSqlDatabase::Size() test. sl@0: Call RSqlDatabase::Size() in various situations and check that the call does not fail. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Call RSqlDatabase::Size() in various situations and check that the call does not fail. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ7141 sl@0: */ sl@0: void SizeTest() sl@0: { sl@0: const TInt KTestDbCnt = 3; sl@0: TPtrC dbNames[KTestDbCnt]; sl@0: dbNames[0].Set(KTestDbName1); //Non-secure shared database sl@0: dbNames[1].Set(KTestDbName9); //Private database sl@0: dbNames[2].Set(KTestDbName7); //Secure shared database sl@0: sl@0: TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass); sl@0: RSqlSecurityPolicy securityPolicy; sl@0: TInt rc = securityPolicy.Create(defaultPolicy); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: for(TInt i=0;i= 0); sl@0: //Insert some data and check the size again sl@0: rc = db.Exec(_L("CREATE TABLE A(Id INTEGER, T TEXT)")); sl@0: TEST(rc >= 0); sl@0: rc = db.Exec(_L("INSERT INTO A VALUES(1, '1111111')")); sl@0: TEST(rc >= 0); sl@0: rc = db.Exec(_L("INSERT INTO A VALUES(2, '22222222222222')")); sl@0: TEST(rc >= 0); sl@0: TInt size2 = db.Size(); sl@0: TEST(size2 > size1); sl@0: //Check the database size in a transaction sl@0: rc = db.Exec(_L("BEGIN")); sl@0: TEST(rc >= 0); sl@0: TInt size3 = db.Size(); sl@0: TEST(size3 == size2); sl@0: rc = db.Exec(_L("INSERT INTO A VALUES(3, '3333333333333333333333333333333333333333333333333333333333333')")); sl@0: TEST(rc >= 0); sl@0: rc = db.Exec(_L("INSERT INTO A VALUES(4, '4444444444444444444444444444444444444444444444444444444444444')")); sl@0: TEST(rc >= 0); sl@0: rc = db.Exec(_L("INSERT INTO A VALUES(5, '5555555555555555555555555555555555555555555555555555555555555')")); sl@0: TEST(rc >= 0); sl@0: TInt size4 = db.Size(); sl@0: TEST(size4 == size2); sl@0: rc = db.Exec(_L("COMMIT")); sl@0: TEST(rc >= 0); sl@0: TInt size5 = db.Size(); sl@0: TEST(size5 == size2); sl@0: //Cleanup sl@0: db.Close(); sl@0: rc = RSqlDatabase::Delete(dbNames[i]); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: securityPolicy.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-CT-1817 sl@0: @SYMTestCaseDesc RSqlDatabase::InTransaction() test. sl@0: Call RSqlDatabase::InTransaction() in various situations and check that the method reports sl@0: database's transaction state correctly. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Call RSqlDatabase::InTransaction() in various situations and check that the method reports sl@0: database's transaction state correctly. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ7141 sl@0: */ sl@0: void InTransactionTest() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: RSqlDatabase db; sl@0: TInt rc = db.Create(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: // sl@0: TBool state = db.InTransaction(); sl@0: TEST(!state); sl@0: rc = db.Exec(_L("BEGIN")); sl@0: TEST(rc >= 0); sl@0: state = db.InTransaction(); sl@0: TEST(!!state); sl@0: rc = db.Exec(_L("ROLLBACK")); sl@0: TEST(rc >= 0); sl@0: state = db.InTransaction(); sl@0: TEST(!state); sl@0: //Cleanup sl@0: db.Close(); sl@0: rc = RSqlDatabase::Delete(KTestDbName1); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4039 sl@0: @SYMTestCaseDesc RSqlDatabase::Size(TSize&) functional test. sl@0: The test creates a non-secure shared database, private database, secure shared database sl@0: and tests that the new RSqlDatabase::Size(TSize&) can be used on the created databases. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlDatabase::Size(TSize&) functional test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ10407 sl@0: */ sl@0: void SizeTest2() sl@0: { sl@0: const TInt KTestDbCnt = 3; sl@0: TPtrC dbNames[KTestDbCnt]; sl@0: dbNames[0].Set(KTestDbName1); //Non-secure shared database sl@0: dbNames[1].Set(KTestDbName9); //Private database sl@0: dbNames[2].Set(KTestDbName7); //Secure shared database sl@0: sl@0: TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass); sl@0: RSqlSecurityPolicy securityPolicy; sl@0: TInt rc = securityPolicy.Create(defaultPolicy); sl@0: TEST2(rc, KErrNone); sl@0: sl@0: _LIT8(KConfig, "compaction=background"); sl@0: sl@0: for(TInt i=0;i 0); sl@0: TEST2(size.iFree, 0); sl@0: //Insert some data and check the size again sl@0: rc = db.Exec(_L("CREATE TABLE A(Id INTEGER, T TEXT)")); sl@0: TEST(rc >= 0); sl@0: const TInt KTestRecCnt = 50; sl@0: rc = db.Exec(_L("BEGIN")); sl@0: TEST(rc >= 0); sl@0: for(TInt k=0;k sql; sl@0: sql.Format(_L("INSERT INTO A VALUES(%d, 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')"), k + 1); sl@0: rc = db.Exec(sql); sl@0: TEST2(rc, 1); sl@0: } sl@0: rc = db.Exec(_L("COMMIT")); sl@0: TEST(rc >= 0); sl@0: rc = db.Size(size); sl@0: TEST2(rc, KErrNone); sl@0: TEST(size.iSize > 0); sl@0: TEST2(size.iFree, 0); sl@0: //Delete the records and check the size again. sl@0: rc = db.Exec(_L("DELETE FROM A")); sl@0: rc = db.Size(size); sl@0: TEST2(rc, KErrNone); sl@0: TEST(size.iSize > 0); sl@0: TEST(size.iFree > 0); sl@0: //Cleanup sl@0: db.Close(); sl@0: rc = RSqlDatabase::Delete(dbNames[i]); sl@0: TEST2(rc, KErrNone); sl@0: } sl@0: securityPolicy.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4040 sl@0: @SYMTestCaseDesc RSqlDatabase::Size(TSize&) on an attached database - functional test. sl@0: The test creates a database and attaches another database. Then the test sl@0: verifies that the new RSqlDatabase::Size(TSize&) method can be used on the attached sl@0: database. The test also calls the new method with an invalid attached database sl@0: name and check that an appropriate error is reported. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlDatabase::Size(TSize&) on an attached database - functional test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ10407 sl@0: */ sl@0: void AttachedSizeTest2() sl@0: { sl@0: RSqlDatabase db; sl@0: sl@0: TInt err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: err = db.Exec(_L("CREATE TABLE A(I INTEGER)")); sl@0: TEST(err >= 0); sl@0: db.Close(); sl@0: err = db.Create(KTestDbName8); sl@0: TEST2(err, KErrNone); sl@0: err = db.Exec(_L("CREATE TABLE B(J INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = db.Exec(_L("BEGIN")); sl@0: TEST(err >= 0); sl@0: for(TInt i=0;i<1000;++i) sl@0: { sl@0: err = db.Exec(_L("INSERT INTO B(J) VALUES(1)")); sl@0: TEST2(err, 1); sl@0: } sl@0: err = db.Exec(_L("COMMIT")); sl@0: TEST(err >= 0); sl@0: db.Close(); sl@0: sl@0: err = db.Open(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: _LIT(KAttachDbName, "B"); sl@0: err = db.Attach(KTestDbName8, KAttachDbName); sl@0: TEST2(err, KErrNone); sl@0: sl@0: //Size(TSize&) - main and the attached databse sl@0: RSqlDatabase::TSize size1; sl@0: err = db.Size(size1); sl@0: TEST2(err, KErrNone); sl@0: TEST(size1.iSize > 0); sl@0: TEST(size1.iFree >= 0); sl@0: RSqlDatabase::TSize size2; sl@0: err = db.Size(size2, KAttachDbName); sl@0: TEST2(err, KErrNone); sl@0: TEST(size2.iSize > 0); sl@0: TEST(size2.iFree >= 0); sl@0: TEST(size2.iSize > size1.iSize); sl@0: sl@0: //Very long attached database name sl@0: TBuf longDbName; sl@0: longDbName.SetLength(longDbName.MaxLength()); sl@0: err = db.Size(size1, longDbName); sl@0: TEST2(err, KErrBadName); sl@0: sl@0: //An attempt to get the size of a non-existing attached database sl@0: err = db.Size(size1, _L("TheDbDoesNotExist")); sl@0: TEST2(err, KSqlErrGeneral); sl@0: TPtrC msg = db.LastErrorMessage(); sl@0: TheTest.Printf(_L("Non-existing attached database, error message: %S\r\n"), &msg); sl@0: sl@0: //An attempt to get the size when the attached database name contains "bad" unicode characters (cannot be converted to UTF8) sl@0: TBuf<2> dbName3; sl@0: dbName3.SetLength(2); sl@0: dbName3[0] = TChar(0xD800); sl@0: dbName3[1] = TChar(0xFC00); sl@0: err = db.Size(size1, dbName3); sl@0: TEST2(err, KErrGeneral); sl@0: sl@0: err = db.Detach(KAttachDbName); sl@0: TEST2(err, KErrNone); sl@0: db.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDbName8); sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQL-UT-4041 sl@0: @SYMTestCaseDesc RSqlDatabase::Size(TSize&) and different compaction modes - functional test. sl@0: The test creates databases using all possible compaction modes and sl@0: verifies that the new RSqlDatabase::Size(TSize&) method can be used on these sl@0: databases without any problems. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RSqlDatabase::Size(TSize&) and different compaction modes - functional test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ10407 sl@0: */ sl@0: void DiffCompactModeSize2Test() sl@0: { sl@0: _LIT8(KAutoCompaction, "compaction = auto"); sl@0: RSqlDatabase db; sl@0: TInt err = db.Create(KTestDbName1, &KAutoCompaction); sl@0: TEST2(err, KErrNone); sl@0: err = db.Exec(_L("CREATE TABLE A(I INTEGER)")); sl@0: TEST(err >= 0); sl@0: RSqlDatabase::TSize size; sl@0: err = db.Size(size); sl@0: TEST2(err, KErrNone); sl@0: TEST(size.iSize > 0); sl@0: TEST(size.iFree >= 0); sl@0: db.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: sl@0: _LIT8(KManualCompaction, "compaction = manual"); sl@0: err = db.Create(KTestDbName1, &KManualCompaction); sl@0: TEST2(err, KErrNone); sl@0: err = db.Exec(_L("CREATE TABLE A(I INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = db.Size(size); sl@0: TEST2(err, KErrNone); sl@0: TEST(size.iSize > 0); sl@0: TEST(size.iFree >= 0); sl@0: db.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: sl@0: _LIT8(KBackgroundCompaction, "compaction = background"); sl@0: err = db.Create(KTestDbName1, &KBackgroundCompaction); sl@0: TEST2(err, KErrNone); sl@0: err = db.Exec(_L("CREATE TABLE A(I INTEGER)")); sl@0: TEST(err >= 0); sl@0: err = db.Size(size); sl@0: TEST2(err, KErrNone); sl@0: TEST(size.iSize > 0); sl@0: TEST(size.iFree >= 0); sl@0: db.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-CT-4205 sl@0: @SYMTestCaseDesc "PRAGMA count_changes" test. sl@0: When "count_changes" pragma is ON, sqlite3_step() is called two times by the sl@0: SQL server, before getting the SQLITE_DONE return code. sl@0: Everything else is the same (statement processing, etc.). sl@0: @SYMTestPriority High sl@0: @SYMTestActions "PRAGMA count_changes" test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: */ sl@0: void CountChangesTest() sl@0: { sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: RSqlDatabase db; sl@0: TInt err = db.Create(KTestDbName1); sl@0: TEST2(err, KErrNone); sl@0: err = db.Exec(_L("CREATE TABLE A(I INTEGER)")); sl@0: TEST(err >= 0); sl@0: sl@0: err = db.Exec(_L("PRAGMA count_changes=ON")); sl@0: TEST(err >= 0); sl@0: sl@0: err = db.Exec(_L("INSERT INTO A VALUES(1)")); sl@0: TEST2(err, 1); sl@0: sl@0: err = db.Exec(_L8("INSERT INTO A VALUES(2)")); sl@0: TEST2(err, 1); sl@0: sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(db, _L("DELETE FROM A WHERE I>=1 AND I<=2")); sl@0: TEST2(err, KErrNone); sl@0: err = stmt.Exec(); sl@0: TEST2(err, 2); sl@0: stmt.Close(); sl@0: sl@0: err = db.Exec(_L("PRAGMA count_changes=OFF")); sl@0: TEST(err >= 0); sl@0: sl@0: db.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDbName1); sl@0: } sl@0: sl@0: void DoTestsL() sl@0: { sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1601 Create/Open/Close database tests ")); sl@0: OpenCloseDatabaseTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1602 SetIsolationLevel() database tests ")); sl@0: SetIsolationLevelTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1603 Delete database tests ")); sl@0: DeleteDatabaseTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1640 Copy database tests ")); sl@0: CopyDatabaseTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1604 Operations with NULL column values ")); sl@0: NullColumnValues(); sl@0: sl@0: enum {KSqlBufSize = 1024}; sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1605 RSqlDatabase::Exec() test. 16-bit SQL strings. ")); sl@0: ExecOnDbTest >(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1605 RSqlDatabase::Exec() test. 8-bit SQL strings. ")); sl@0: ExecOnDbTest >(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1606 RSqlStatement test. 16-bit SQL strings. ")); sl@0: StatementTest >(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1606 RSqlStatement test. 8-bit SQL strings. ")); sl@0: StatementTest >(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1607 RSqlColumnReadStream test. Long text column ")); sl@0: ColumnTextStreamTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1621 RSqlColumnReadStream test. Long binary column ")); sl@0: ColumnBinaryStreamTest(); sl@0: sl@0: TheTest.Next (_L(" @SYMTestCaseID:PDS-SQL-CT-4174 CSqlSrvSession::NewOutputStreamL() coverage test")); sl@0: ColumnBinaryStreamTest2(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1608 RSqlParamWriteStream test. Long text parameter ")); sl@0: TextParameterStreamTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1622 RSqlParamWriteStream test. Long binary parameter ")); sl@0: BinaryParameterStreamTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4191 MStreamBuf::SeekL() test")); sl@0: StreamSeekTestL(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1634 RSqlStatement test. Nameless parameter ")); sl@0: NamelessParameterTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1768 Asynchronous execution tests ")); sl@0: AsyncTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1816 RSqlDatabase::Size() tests ")); sl@0: SizeTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1817 RSqlDatabase::InTransaction() tests ")); sl@0: InTransactionTest(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4039 RSqlDatabase::Size(RSqlDatabase::TSize&) tests")); sl@0: SizeTest2(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4040 RSqlDatabase::Size(RSqlDatabase::TSize&) - attached database tests")); sl@0: AttachedSizeTest2(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4041 RSqlDatabase::Size(RSqlDatabase::TSize&) - different compaction modes tests")); sl@0: DiffCompactModeSize2Test(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4205 PRAGMA \"count_changes\" test")); sl@0: CountChangesTest(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: TheTest.Title(); sl@0: sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: CreateTestDir(); sl@0: DeleteTestFiles(); sl@0: TRAPD(err, DoTestsL()); sl@0: DeleteTestFiles(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: delete tc; sl@0: sl@0: User::Heap().Check(); sl@0: return KErrNone; sl@0: }