Ejemplo n.º 1
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-3509
@SYMTestCaseDesc		Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
						The test has 5 sub-cases, where the test attempts to open
						a secure shared database with:
						- no settings table;
						- empty settings table;
						- invalid version number of the settings;
						- NULL collation dll name, stored in the settings;
						- too long collation dll name, stored in the settings;
@SYMTestPriority		High
@SYMTestActions			Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
@SYMTestExpectedResults Test must not fail
@SYMDEF					DEF109100
*/
void LoadSysSettingsTest()
{
    //Case 1: no "symbian_settings" table. No error returned, because the table is recreated.
    RSqlDatabase db;
    TInt err = db.Open(KDb1);
    TEST2(err, KErrNone);
    db.Close();

    //Case 2: "symbian_settings" table is empty.
    err = db.Open(KDb2);
    TEST2(err, KErrGeneral);
    db.Close();

    //Case 3: Invalid version number in "symbian_settings" table.
    err = db.Open(KDb3);
    TEST2(err, KErrGeneral);
    db.Close();

    //Case 4: NULL collation dll name in "symbian_settings" table.
    err = db.Open(KDb4);
    TEST2(err, KErrGeneral);
    db.Close();

    //Case 5: Too long collation dll name in "symbian_settings" table.
    err = db.Open(KDb5);
    TEST2(err, KErrOverflow);
    db.Close();
}
Ejemplo n.º 2
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-4058
@SYMTestCaseDesc		Background compaction - configuration test.
						The test creates a database with a background compaction mode.
						The test reopens the database and verifies that the compaction mode is persistent and is still background.
						Then the test reopens the database using different compaction mode in the configuration string and 
						verifies that the original (background) compaction mode cannot be changed when the database is opened.
@SYMTestPriority		Medium
@SYMTestActions			Background compaction - configuration test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ10274
*/
void CompactConfigTest3L()
	{
	//Create a test database with "background" compaction mode
	_LIT8(KConfigStr1, "encoding=utf-8;compaction=background");
	TInt err = TheDb.Create(KTestDbName1, &KConfigStr1);
	TEST2(err, KErrNone);
	//Check the vacuum mode. The SQLite vacuum mode should be "incremental"
	TSqlScalarFullSelectQuery scalarQuery(TheDb);
	TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KIncrementalVacuum);
	TheDb.Close();
	//Close and open the database again. The SQLite vacuum mode should be "incremental".
	err = TheDb.Open(KTestDbName1);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KIncrementalVacuum);
	TheDb.Close();
	//Close and open the database again with a config string with "manual" compaction mode. 
	//The SQLite vacuum mode should stay unchanged.
	_LIT8(KConfigStr2, "compaction=manual");
	err = TheDb.Open(KTestDbName1, &KConfigStr2);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KIncrementalVacuum);
	TheDb.Close();
	//Delete database
	err = RSqlDatabase::Delete(KTestDbName1);
	TEST2(err, KErrNone);
	}
Ejemplo n.º 3
0
/**
@SYMTestCaseID          PDS-SQL-UT-4152
@SYMTestCaseDesc		Test for DEF142305 - RSqlDatabase::Attach does not use cache_size configuration parameters.
						The test verifies that when a database is attached, the attached database cache size will be set
						based on the page size, soft heap limit and default cache size.
@SYMTestPriority        High
@SYMTestActions			Test for DEF142305 - RSqlDatabase::Attach does not use cache_size configuration parameters.
@SYMTestExpectedResults The test must not fail.
@SYMDEF INC106788
*/
void DEF142305()
	{
	_LIT8(KConfig, "cache_size=500");
	
	//Create main db
	TInt err = TheDb.Create(KTestDbName, &KConfig);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 500, KDefaultPageSize, KDefaultEncoding);
	TheDb.Close();
	
	//Create non-secure db that will be attached 
	err = TheDb.Create(KTestDbName2, &KConfig);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 500, KDefaultPageSize, KDefaultEncoding);
	TheDb.Close();

	//Create private db that will be attached 
	_LIT8(KConfig2, "page_size=2048");
	err = TheDb.Create(KTestDbName4, &KConfig2);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 2048, 2048, KDefaultEncoding);//2048? - see KConfig2 string
	TheDb.Close();

	_LIT(KAttachDbName, "Attached");
	
	//Attach non-secure db
	err = TheDb.Open(KTestDbName, &KConfig);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 500, KDefaultPageSize, KDefaultEncoding);
	err = TheDb.Attach(KTestDbName2, KAttachDbName);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding, KAttachDbName);
	err = TheDb.Detach(KAttachDbName);
	TEST2(err, KErrNone);
	TheDb.Close();
	
	//Attach private db
	err = TheDb.Open(KTestDbName, &KConfig);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 500, KDefaultPageSize, KDefaultEncoding);
	err = TheDb.Attach(KTestDbName4, KAttachDbName);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 2048, 2048, KDefaultEncoding, KAttachDbName);//2048? - see KConfig2 string
	err = TheDb.Detach(KAttachDbName);
	TEST2(err, KErrNone);
	TheDb.Close();
	
	(void)RSqlDatabase::Delete(KTestDbName4);
	(void)RSqlDatabase::Delete(KTestDbName2);
	(void)RSqlDatabase::Delete(KTestDbName);
	}
Ejemplo n.º 4
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-4061
@SYMTestCaseDesc		Secure shared database and compaction configuration test.
						The test verifies that a secure shared database can be created using auto, background or 
						manual compaction mode and that the compaction mode does not chage after reopening 
						the database.
@SYMTestPriority		Medium
@SYMTestActions			Secure shared database and compaction configuration test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ10273
                        REQ10274
                        REQ10400
                        REQ10402
*/
void CompactConfigTest6L()
	{
	//Create a secure test database with "auto" compaction mode.
	RSqlSecurityPolicy securityPolicy = CreateTestSecurityPolicy();
	_LIT8(KConfigStr1, "encoding=utf-8;compaction=auto");
	TInt err = TheDb.Create(KTestSecureDbName, securityPolicy, &KConfigStr1);
	TEST2(err, KErrNone);
	securityPolicy.Close();
	TheDb.Close();
	//Check the vacuum mode. The SQLite vacuum mode should be "auto"
	TestCompactMode(KAutoVacuum);
	//Close and open the database again. The SQLite vacuum mode should be "auto".
	err = TheDb.Open(KTestSecureDbName);
	TEST2(err, KErrNone);
	TheDb.Close();
	TestCompactMode(KAutoVacuum);
	//Close and open the database again with a config string with "background" compaction mode. 
	//The SQLite vacuum mode should stay unchanged.
	_LIT8(KConfigStr2, "compaction=background");
	err = TheDb.Open(KTestSecureDbName, &KConfigStr2);
	TEST2(err, KErrNone);
	TheDb.Close();
	TestCompactMode(KAutoVacuum);
	//Delete database
	err = RSqlDatabase::Delete(KTestSecureDbName);
	TEST2(err, KErrNone);
	//Create a private test database - no config string
	securityPolicy = CreateTestSecurityPolicy();
	err = TheDb.Create(KTestSecureDbName, securityPolicy);
	TEST2(err, KErrNone);
	securityPolicy.Close();
	TheDb.Close();
	//Check the vacuum mode. The SQLite vacuum mode should be KSqlDefaultVacuum.
	TestCompactMode(KSqlDefaultVacuum);
	//Close and open the database again. The SQLite vacuum mode should be KSqlDefaultVacuum.
	err = TheDb.Open(KTestSecureDbName);
	TEST2(err, KErrNone);
	TheDb.Close();
	TestCompactMode(KSqlDefaultVacuum);
	//Close and open the database again with a config string with "auto" compaction mode. 
	//The SQLite vacuum mode should stay unchanged.
	err = TheDb.Open(KTestSecureDbName, &KConfigStr1);
	TEST2(err, KErrNone);
	TheDb.Close();
	TestCompactMode(KSqlDefaultVacuum);
	//Delete database
	err = RSqlDatabase::Delete(KTestSecureDbName);
	TEST2(err, KErrNone);
	}
/**
@SYMTestCaseID			PDS-SQLITE3SEC-UT-4034
@SYMTestCaseDesc		SQL server multi-insert performance test.
						The test inserts 1000 records in a single transaction and stores
						the execution time for later use (comparison and printing).
@SYMTestPriority		High
@SYMTestActions			SQL server multi-insert performance test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ11320
*/
static void SqlServerMultiInsertTest(const char aInsertSql[], TInt aInsertRecCnt)
	{
	TheTest.Next( _L("@SYMTestCaseID:PDS-SQLITE3SEC-UT-4034"));
	(void)KillProcess(KSqlSrvName);

	TInt err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);

	RSqlStatement stmt;
	err = stmt.Prepare(TheDb, TPtrC8((const TUint8*)aInsertSql));
	TEST2(err, KErrNone);

	TUint32 fc = FastCounterValue();
	err = TheDb.Exec(_L8("BEGIN"));
	TEST(err >= 0);

	for(TInt i=0;i<aInsertRecCnt;++i)
		{
		err = stmt.BindInt(0, i + 1);
		TEST2(err, KErrNone);
		err = stmt.Exec();
		TEST2(err, 1);
		err = stmt.Reset();
		TEST2(err, KErrNone);
		}

	err = TheDb.Exec(_L8("COMMIT"));
	TEST(err >= 0);
	StorePerfTestResult(EPerfTestSqlMode, EPerfTestMultiInsert, FastCounterValue() - fc);

	stmt.Close();
	TheDb.Close();
	}
Ejemplo n.º 6
0
TInt ThreadFunc(void* aData)
	{
	__UHEAP_MARK;
	
	CTrapCleanup* tc = CTrapCleanup::New();
	TTEST(tc != NULL);

	TThreadData* data = static_cast<TThreadData*> (aData);
	TTEST(data != NULL);

	RSqlDatabase db;
	TInt err = db.Open(KTestDbName1);
	TTEST2(err, KErrNone);
	
	err = db.SetIsolationLevel(data->iIsolationLevel);
	TTEST2(err, KErrNone);
		
	if(data->iTransType == 1)
		{
		_LIT8(KBeginTrans, "BEGIN");
		err = db.Exec(KBeginTrans);
		TTEST(err >= 0);
		}

	_LIT8(KInsertSql, "INSERT INTO A(Id) VALUES(");	
	for(TInt id=data->iLowRecNo;id<=data->iHighRecNo;++id)
		{
		TBuf8<128> sql(KInsertSql);
		sql.AppendNum((TInt64)id);
		sql.Append(_L(")"));
		err = KSqlErrBusy;
		const TInt KAttempts = 20;
		for(TInt i=0;i<KAttempts&&err==KSqlErrBusy;++i)
			{
			err = db.Exec(sql);
			if(err == KSqlErrBusy)
				{
				RThread th;
				TName name = th.Name();
				RDebug::Print(_L("!!!Database locked, Thread: %S, Attempt %d, column value %d\r\n"), &name, i + 1, id);
				User::After(1000000);
				}
			}
		TTEST2(err, 1);
		}

	if(data->iTransType == 1)
		{
		_LIT8(KCommitTrans, "COMMIT");
		err = db.Exec(KCommitTrans);
		TTEST(err >= 0);
		}

	db.Close();		
	delete tc;
	
	__UHEAP_MARKEND;
	
	return KErrNone;		
	}
Ejemplo n.º 7
0
/**
@SYMTestCaseID			SYSLIB-SQL-CT-1645
@SYMTestCaseDesc		Testing database operations on a secure database.
						The test application's capabilities allow write-only access to the test secure database.
						Verify that any other kind of a database operation will fail with KErrPermissionDenied error.
@SYMTestPriority		High
@SYMTestActions			Testing database operations on a secure database.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ5792
                        REQ5793
*/	
void WriteOnlyDatabaseTest()
	{
	TInt err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);
	
	//Attempt to modify the database schema
	err = TheDb.Exec(_L("CREATE TABLE C(FFF TEXT)"));
	TEST2(err, KErrPermissionDenied);
    err = TheDb.Exec(_L("CREATE TRIGGER upd_a_b1 UPDATE OF B1 ON A BEGIN UPDATE B SET F3 = 'AAAA' WHERE F2 = A.F1; END;"));
    TEST2(err, KErrPermissionDenied);
    err = TheDb.Exec(_L("CREATE TEMP TRIGGER upd_a_b1 UPDATE OF B1 ON A BEGIN UPDATE B SET F3 = 'AAAA' WHERE F2 = A.F1; END;"));
    TEST2(err, KErrPermissionDenied);//Temp trigger which attempts to update one of the tables.
    err = TheDb.Exec(_L("CREATE VIEW V1 AS SELECT * FROM A"));
    TEST2(err, KErrPermissionDenied);
    err = TheDb.Exec(_L("CREATE TEMP VIEW V1 AS SELECT * FROM A"));
    TEST(err >= 0);
    err = TheDb.Exec(_L("DROP VIEW V1"));
    TEST(err >= 0);
	//Attempt to update the user data (but it includes a READ operation)
	err = TheDb.Exec(_L("UPDATE A SET F1 = 11 WHERE F1 = 1"));
	TEST2(err, KErrPermissionDenied);
	//Attempt to update the user data (unconditional UPDATE, no READ operations)
	err = TheDb.Exec(_L("UPDATE A SET F1 = 11"));
	TEST(err >= 0);	
	//Attempt to delete the user data (but it includes a READ operation)
	err = TheDb.Exec(_L("DELETE FROM B WHERE F2 = 2"));
	TEST2(err, KErrPermissionDenied);
	//Attempt to delete the user data (unconditional DELETE, no READ operations)
	err = TheDb.Exec(_L("DELETE FROM A"));
	TEST(err >= 0);	
	//Restore the deleted table A
	err = TheDb.Exec(_L("INSERT INTO A(F1,B1) VALUES(1,x'41414141414141414141');INSERT INTO A(F1,B1) VALUES(2,x'42424242424242424242');INSERT INTO A(F1,B1) VALUES(3,x'43434343434343434343');INSERT INTO A(F1,B1) VALUES(4,x'44444444444444444444');"));
	TEST(err >= 0);	
	//Attempt to insert new user data
	err = TheDb.Exec(_L("INSERT INTO B(F2, F3, B2) VALUES(22, 'AAA', x'47474747474747474747')"));
	TEST2(err, 1);
	//Attempt to change the isolation level.
	err = TheDb.SetIsolationLevel(RSqlDatabase::ESerializable);	
	TEST2(err, KErrNone);
	err = TheDb.SetIsolationLevel(RSqlDatabase::EReadUncommitted);	
	TEST2(err, KErrNone);
	//Attempt to read the user data
	RSqlStatement stmt;
	err = stmt.Prepare(TheDb, _L("SELECT A.F1 FROM B,A WHERE A.F1 = B.F2"));
	TEST2(err, KErrPermissionDenied);	
	//Attempt to read the system data
	err = stmt.Prepare(TheDb, _L("SELECT * FROM SQLITE_MASTER"));
	TEST2(err, KErrNone);
	err = stmt.Next();
	TEST2(err, KSqlAtRow);
	TPtrC p;
	err = stmt.ColumnText(0, p);
	TEST2(err, KErrNone);
	RDebug::Print(_L("Value=%S\r\n"), &p);
	stmt.Close();
	
	TheDb.Close();
	}
Ejemplo n.º 8
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-3510
@SYMTestCaseDesc		Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
						The test has 3 sub-cases, where the test attempts to open
						a secure shared database with:
						- missing default policy in the security policy table;
						- invalid database object type in the security policy table;
						- 2 default policies in the security policy table;
@SYMTestPriority		High
@SYMTestActions			Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
@SYMTestExpectedResults Test must not fail
@SYMDEF					DEF109100
*/
void LoadSecurityPolicyTest()
{
    //Case 1: missing default policy.
    RSqlDatabase db;
    TInt err = db.Open(KDb6);
    TEST2(err, KErrGeneral);
    db.Close();

    //Case 2: invalid database object type.
    err = db.Open(KDb7);
    TEST2(err, KErrGeneral);
    db.Close();

    //Case 3: 2 default policies.
    err = db.Open(KDb8);
    TEST2(err, KErrGeneral);
    db.Close();
}
Ejemplo n.º 9
0
/**
@SYMTestCaseID			SYSLIB-SQL-CT-1643
@SYMTestCaseDesc		SQL server private path in database file name test.
						Verify that SQL API returns appropriate error, if an attempt is made to create, open
						or delete a secure database, with the full path specified in the database file name.
@SYMTestPriority		High
@SYMTestActions			SQL server private path in database file name test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ5792
                        REQ5793
*/
void PrivatePathTest()
{
    RSqlSecurityPolicy securityPolicy;
    CreateTestSecurityPolicy(securityPolicy);

    RSqlDatabase db;

    TInt err = db.Create(_L("C:\\PrIVATE\\10281E17\\[98765432]A.DB"), securityPolicy);
    TEST2(err, KErrArgument);
    err = db.Create(_L("C:\\PRIVATE\\10281E17\\[98765432]A.DB"));
    TEST2(err, KErrArgument);
    err = db.Open(_L("C:\\PRIVATE\\10281E17\\[98765432]A.DB"));
    TEST2(err, KErrArgument);
    err = db.Open(_L("C:\\PRIvaTe\\10281E17\\[98765432]A.DB"));
    TEST2(err, KErrArgument);

    err = db.Create(KTestDbName2);
    TEST2(err, KErrNone);
    err = db.Attach(_L("C:\\PRIVATe\\10281E17\\[98765432]A.DB"), _L("Db"));
    TEST2(err, KErrArgument);
    err = db.Attach(_L("C:\\PRIVAtE\\10281E17\\[98765432]A.DB"), _L("Db"));
    TEST2(err, KErrArgument);
    //This is an attempt to attach a database from the application's private data cage
    err = db.Attach(KTestDbName4, _L("Db"));
    TEST2(err, KErrNotFound);//There is no "Db" database file in the application's private data cage
    db.Close();

    err = RSqlDatabase::Delete(_L("C:\\pRIVATE\\10281E17\\[98765432]A.DB"));
    TEST2(err, KErrArgument);
    err = RSqlDatabase::Delete(_L("C:\\PRIvATE\\10281E17\\[98765432]A.DB"));
    TEST2(err, KErrArgument);

    //This is an attempt to create a database in the application's private data cage
    err = db.Create(KTestDbName4);
    TEST2(err, KErrNone);
    db.Close();
    err = RSqlDatabase::Delete(KTestDbName4);
    TEST2(err, KErrNone);

    err = db.Create(KTestDbName5);
    TEST2(err, KErrArgument);

    securityPolicy.Close();
}
Ejemplo n.º 10
0
/**
 * Method to change a plugin id in plugin Id table
 * @param aNewPluginID The ID of the new plugin
 * @param aFlag The flag that indicates the plugin id is enables or disabled
 * @param aOldPluginID The ID of the plugin to be replaced
 * @return Returns KErrNone if success. Refer ESqlDbError and system-wide
 * error codes for detailed error description.
 */
TInt CSmfCredMgrDbUser::updatePlugin(const TDesC& aPluginID,
                                     const TBool& aFlag, const TDesC& aOldPluginID)
{
    TInt err(KErrNone);
    RSqlStatement sqlStatement;
    TInt paramIndex(KErrNone);
    TBuf<KMaxBufSize> newPluginBuf(aPluginID);
    TBuf<KMaxBufSize> OldPluginBuf(aOldPluginID);
    RSqlDatabase db;

    err = db.Open(iDbFilePathName);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());

    err = sqlStatement.Prepare(db, KUpdatePluginID);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());

    paramIndex = sqlStatement.ParameterIndex(_L(":iText"));
    err = sqlStatement.BindText(paramIndex, newPluginBuf);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());

    paramIndex = sqlStatement.ParameterIndex(_L(":iFlag"));
    err = sqlStatement.BindInt(paramIndex, aFlag);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());

    paramIndex = sqlStatement.ParameterIndex(_L(":iID"));
    err = sqlStatement.BindText(paramIndex, OldPluginBuf);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());

    err = db.Exec(KBegin);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
    err = sqlStatement.Exec();
    if (KSqlErrConstraint == err)
    {
        //
    }
    else if (err < KErrNone)
    {
        __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
    }

    err = db.Exec(KCommit);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());

    //if commit fails we have to roll back
    if (err < KErrNone)
    {
        err = db.Exec(KRollback);
    }
    sqlStatement.Close();
    db.Close();
    if (err >= 0)
    {
        return KErrNone;
    }
    return err;
}
Ejemplo n.º 11
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-4049
@SYMTestCaseDesc		Database configuration string - injection test.
						The test attempts to create a database using a configuration string
						and passing a DELETE SQL statement as a compaction mode name.
						The database should be created successfully, the invalid compaction mode - ignored,
						the database system tables content shoud not be corrupted by the call.
@SYMTestPriority		High
@SYMTestActions			Database configuration string - injection test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ10405
*/
void InjectionTest()
	{
	(void)RSqlDatabase::Delete(KTestDbName);
	TInt err = TheDb.Create(KTestDbName);
	TEST2(err, KErrNone);
	err = TheDb.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1);"));
	TEST(err > 0);
	TheDb.Close();
	
	_LIT8(KConfig1, "cache_size=128;DELETE FROM A");
	err = TheDb.Open(KTestDbName, &KConfig1);
	TEST2(err, KErrArgument);
	err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);
	TSqlScalarFullSelectQuery query(TheDb);
	TInt recCount = 0;
	TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM A")));
	TEST2(err, KErrNone);
	TEST2(recCount, 1);
	TheDb.Close();

	_LIT8(KConfig2, "cache_size=256;compaction=DELETE FROM A;");
	err = TheDb.Open(KTestDbName, &KConfig2);
	TEST2(err, KErrNone);
	query.SetDatabase(TheDb);
	recCount = 0;
	TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM A")));
	TEST2(err, KErrNone);
	TEST2(recCount, 1);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);

	_LIT8(KConfig3, "cache_size=256;compaction=DELETE FROM symbian_settings;");
	err = TheDb.Create(KTestDbName, &KConfig3);
	TEST2(err, KErrNone);
	query.SetDatabase(TheDb);
	recCount = 0;
	TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM symbian_settings")));
	TEST2(err, KErrNone);
	TEST2(recCount, 1);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	}
Ejemplo n.º 12
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-3439
@SYMTestCaseDesc		Test for DEF105928 "SQL server ignores config string parameters".
						The test creates two databases using configuration strings and checks that database 1
						configuration has no impact on database 2 configuration.
@SYMTestPriority		High
@SYMTestActions			Test for DEF105928 "SQL server ignores config string parameters".
@SYMTestExpectedResults The test must not fail
@SYMDEF					DEF105928
*/
void CfgCrossConnectionTest()
	{
	//Create database 1 with cache size = 40, page size = 2048.
	_LIT8(KCfgStr1, "cache_size = 40; page_size = 2048");
	TInt err = TheDb.Create(KTestDbName, &KCfgStr1);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 40, 2048, KDefaultEncoding);
	//Without closing database 1, create database 2 without a configuration string.
	//Check that database 2 uses the default configuration parameters
	err = TheDb2.Create(KTestDbName2);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb2, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
	//Close database 2. Check the configuration parameters of database 1
	TheDb2.Close();
	AssertConfigPrmValues(TheDb, 40, 2048, KDefaultEncoding);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName2);
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create 2 databases with different configuration parameters
	_LIT8(KCfgStr2_1, "cache_size = 50; page_size = 512; encoding = \"UTF-16\"");
	_LIT8(KCfgStr2_2, "cache_size = 80; page_size = 4096; encoding = \"UTF-8\"");
	err = TheDb.Create(KTestDbName, &KCfgStr2_1);
	TEST2(err, KErrNone);
	err = TheDb2.Create(KTestDbName2, &KCfgStr2_2);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 50, 512, TSqlSrvConfigParams::EEncUtf16);
	AssertConfigPrmValues(TheDb2, 80, 4096, TSqlSrvConfigParams::EEncUtf8);
	TheDb2.Close();
	TheDb.Close();
	//Reopen the databases and check the configuration parameters
	err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);
	err = TheDb2.Open(KTestDbName2);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 512, 512, TSqlSrvConfigParams::EEncUtf16);
	AssertConfigPrmValues(TheDb2, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 4096, 4096, TSqlSrvConfigParams::EEncUtf8);
	TheDb2.Close();
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName2);
	(void)RSqlDatabase::Delete(KTestDbName);
	}
Ejemplo n.º 13
0
/**
 * Method to insert AuthParamsTable
 * @param aAuthAppId The ID of the Authentication app
 * @param aKey The Key
 * @param aSecret The Secret
 * @return Returns KErrNone if success. Refer ESqlDbError and system-wide
 * error codes for detailed error description.
 */
TInt CSmfCredMgrDbUser::AuthParamsTableInsert(const TDesC& aAuthAppId,
        const TDesC& aKey, const TDesC& aSecret)
{
    TInt err(KErrNone);
    RSqlStatement sqlStatement;
    RSqlDatabase db;

    TBuf<KMaxBufSize> keyBuf(aKey);
    TBuf<KMaxBufSize> secretBuf(aSecret);

    err = db.Open(iDbFilePathName);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());

    err = sqlStatement.Prepare(db, KSmfAuthParamsTableInsert);
    TInt paramIndex(KErrNone);

    paramIndex = sqlStatement.ParameterIndex(_L(":Val1"));
    err = sqlStatement.BindText(paramIndex, aAuthAppId);

    paramIndex = sqlStatement.ParameterIndex(_L(":Val2"));
    err = sqlStatement.BindText(paramIndex, keyBuf);

    paramIndex = sqlStatement.ParameterIndex(_L(":Val3"));
    err = sqlStatement.BindText(paramIndex, secretBuf);

    err = db.Exec(KBegin);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
    err = sqlStatement.Exec();
    if (KSqlErrConstraint == err)
    {
        //Table already present.
    }
    else if (err < KErrNone)
    {
        __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
    }

    err = db.Exec(KCommit);
    __ASSERT_DEBUG( (err >= KErrNone), User::Invariant());

    //if commit fails we have to roll back
    if (err < KErrNone)
    {
        err = db.Exec(KRollback);
    }
    sqlStatement.Close();
    db.Close();
    if (err >= 0)
    {
        return KErrNone;
    }
    return err;
}
Ejemplo n.º 14
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-3441
@SYMTestCaseDesc		Test for DEF105928 "SQL server ignores config string parameters".
						The test creates a private database with a configuration string. The test must not fail.
@SYMTestPriority		High
@SYMTestActions			Test for DEF105928 "SQL server ignores config string parameters".
@SYMTestExpectedResults The test must not fail
@SYMDEF					DEF105928
*/
void CfgPrivateDbTest()
	{
	//Create
	_LIT8(KCfgStr1, "cache_size = 80; page_size = 4096; encoding = UTF-8");
	TInt err = TheDb.Create(KTestDbName4, &KCfgStr1);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 80, 4096, TSqlSrvConfigParams::EEncUtf8);
	TheDb.Close();	
	//Open-1. The cache size can be changed.
	_LIT8(KCfgStr2, "cache_size = 100");
	err = TheDb.Open(KTestDbName4, &KCfgStr2);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 100, 4096, TSqlSrvConfigParams::EEncUtf8);
	TheDb.Close();	
	//Open-2. The page size cannot be changed if the database does exist already.
	_LIT8(KCfgStr3, "page_size = 512");
	err = TheDb.Open(KTestDbName4, &KCfgStr3);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 4096, 4096, TSqlSrvConfigParams::EEncUtf8);
	TheDb.Close();	
	(void)RSqlDatabase::Delete(KTestDbName4);
	}
Ejemplo n.º 15
0
///////////////////////////////////////////////////////////////////////////////////////
//Restore original test database function
void RestoreOriginalDb()
	{
	TheDb.Close();
	TheDb.Open(KTestDbName);
	
	// Delete and restore the content of table A (unconditional DELETE, no READ operations)
	TheDb.Exec(_L("DELETE FROM A"));
	TheDb.Exec(_L("INSERT INTO A(F1,B1) VALUES(1,x'41414141414141414141');INSERT INTO A(F1,B1) VALUES(2,x'42424242424242424242');INSERT INTO A(F1,B1) VALUES(3,x'43434343434343434343');INSERT INTO A(F1,B1) VALUES(4,x'44444444444444444444');"));

	// Delete and restore the content of table B (unconditional DELETE, no READ operations)
	TheDb.Exec(_L("DELETE FROM B"));
	TheDb.Exec(_L("INSERT INTO B(F2,F3,B2) VALUES(2, 'ABC',x'45454545454545454545');INSERT INTO B(F2,F3,B2) VALUES(4,'DEF',x'46464646464646464646');"));

	TheDb.Close();	
	}
Ejemplo n.º 16
0
TInt UpdateThreadFunc(void*)
	{
	__UHEAP_MARK;
	
	CTrapCleanup* tc = CTrapCleanup::New();
	TTEST(tc != NULL);

	RSqlDatabase db;
	TInt err = db.Open(KTestDbName1);
	TTEST2(err, KErrNone);

	RDebug::Print(_L("---:UpdThread: Set the isolation level to \"Read uncommitted\"\r\n"));
	err = db.SetIsolationLevel(RSqlDatabase::EReadUncommitted);
	TTEST2(err, KErrNone);

	RDebug::Print(_L("---:UpdThread: Begin a write transaction\r\n"));
	_LIT8(KBeginTransSql, "BEGIN IMMEDIATE TRANSACTION");
	err = db.Exec(KBeginTransSql);
	TTEST(err >= 0);

	RDebug::Print(_L("---:UpdThread: Update the record\r\n"));
	_LIT8(KUpdateSql, "UPDATE A SET Id = ");
	TBuf8<64> sql(KUpdateSql);
	sql.AppendNum((TInt64)KUpdatedValue);
	err = db.Exec(sql);
	TTEST(err >= 0);

	RDebug::Print(_L("---:UpdThread: Notify the main thread about the update\r\n"));
	MainThreadCrS.Signal();
	
	RDebug::Print(_L("---:UpdThread: Wait for permisson to continue...\r\n"));
	UpdateThreadCrS.Wait();

	RDebug::Print(_L("---:UpdThread: Rollback the update\r\n"));
	_LIT8(KRollBackTransSql, "ROLLBACK TRANSACTION");
	err = db.Exec(KRollBackTransSql);
	TTEST(err >= 0);

	RDebug::Print(_L("---:UpdThread: Notify the main thread about the rollback\r\n"));
	MainThreadCrS.Signal();
	
	db.Close();
	delete tc;
	
	__UHEAP_MARKEND;
	
	return KErrNone;		
	}
Ejemplo n.º 17
0
/**
@SYMTestCaseID			PDS-SQLITE3SEC-UT-4038
@SYMTestCaseDesc		SQL server single-insert performance test.
						The test inserts one record and stores
						the execution time for later use (comparison and printing).
@SYMTestPriority		High
@SYMTestActions			SQL server single-insert performance test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ11320
*/
static void SqlServerSingleInsertTest(const char aSingleInsertSql[], TInt aInsertRecId)
	{
	TheTest.Next( _L("@SYMTestCaseID:PDS-SQLITE3SEC-UT-4038"));
	(void)KillProcess(KSqlSrvName);

	TInt err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);

	TheSqlBuf.Format(TPtrC8((const TUint8*)aSingleInsertSql), aInsertRecId);
	TUint32 fc = FastCounterValue();
	err = TheDb.Exec(TheSqlBuf);
	StorePerfTestResult(EPerfTestSqlMode, EPerfTestSingleInsert, FastCounterValue() - fc);
	TEST2(err, 1);

	TheDb.Close();
	}
Ejemplo n.º 18
0
/**
@SYMTestCaseID			PDS-SQLITE3SEC-UT-4036
@SYMTestCaseDesc		SQL server multi-delete performance test.
						The test deletes 100 randomly chosen records and stores
						the execution time for later use (comparison and printing).
@SYMTestPriority		High
@SYMTestActions			SQL server multi-delete performance test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ11320
*/
static void SqlServerMultiDeleteTest(const char aDeleteSql[], TInt aDeleteRecIds[], TInt aDeleteRecCnt)
	{
	TheTest.Next( _L("@SYMTestCaseID:PDS-SQLITE3SEC-UT-4036"));
	(void)KillProcess(KSqlSrvName);

	TInt err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);

	FormatSqlStmt(TheSqlBuf, aDeleteSql, aDeleteRecIds, aDeleteRecCnt);

	TUint32 fc = FastCounterValue();
	err = TheDb.Exec(TheSqlBuf);
	StorePerfTestResult(EPerfTestSqlMode, EPerfTestMultiDelete, FastCounterValue() - fc);
	TEST2(err, aDeleteRecCnt);

	TheDb.Close();
	}
Ejemplo n.º 19
0
/**
@SYMTestCaseID			SYSLIB-SQL-CT-1637
@SYMTestCaseDesc		RSqlDatabase::Create() test.
						Tests RSqlDatabase::Create() call when the request is for creation of a secure database.
@SYMTestPriority		High
@SYMTestActions			RSqlDatabase::Create() test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ5792
                        REQ5793
*/
void CreateSecureDatabaseTest()
{
    RSqlSecurityPolicy securityPolicy;

    //Create and initialize RSqlSecurityPolicy object.
    CreateTestSecurityPolicy(securityPolicy);

    //Create secure database using the data from securityPolicy object.
    RSqlDatabase db;
    TInt err = db.Create(KTestDbName, securityPolicy);
    TEST2(err, KErrNone);
    securityPolicy.Close();

    //Check that the database security policy matches the policy used when the database was created.
    err = db.GetSecurityPolicy(securityPolicy);
    TEST2(err, KErrNone);
    CheckTestSecurityPolicy(securityPolicy);
    securityPolicy.Close();

    db.Close();

    //Reopen the database and check the security policies
    err = db.Open(KTestDbName);
    TEST2(err, KErrNone);

    //Check that the database security policy matches the policy used when the database was created.
    err = db.GetSecurityPolicy(securityPolicy);
    TEST2(err, KErrNone);
    CheckTestSecurityPolicy(securityPolicy);
    securityPolicy.Close();

    db.Close();

    err = RSqlDatabase::Delete(KTestDbName);
    TEST2(err, KErrNone);

    //An attempt to create a secure database specifying the full database path
    CreateTestSecurityPolicy(securityPolicy);
    err = db.Create(KTestDbName2, securityPolicy);
    securityPolicy.Close();
    TEST2(err, KErrArgument);

    //An attempt to create a non-secure database formatting the database file name as <drive:><dbFileName>
    err = db.Create(KTestDbName);
    TEST2(err, KErrArgument);
}
Ejemplo n.º 20
0
/**
@SYMTestCaseID			PDS-SQLITE3SEC-UT-4040
@SYMTestCaseDesc		SQL server single-delete performance test.
						The test deletes one randomly chosen record and stores
						the execution time for later use (comparison and printing).
@SYMTestPriority		High
@SYMTestActions			SQL server single-delete performance test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ11320
*/
static void SqlServerSingleDeleteTest(const char aSingleDeleteSql[], TInt aDeleteRecId)
	{
	TheTest.Next( _L("@SYMTestCaseID:PDS-SQLITE3SEC-UT-4040"));
	(void)KillProcess(KSqlSrvName);

	TInt err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);

	TheSqlBuf.Copy(TPtrC8((const TUint8*)aSingleDeleteSql));
	TheSqlBuf.AppendNum((TInt64)aDeleteRecId);
	TUint32 fc = FastCounterValue();
	err = TheDb.Exec(TheSqlBuf);
	StorePerfTestResult(EPerfTestSqlMode, EPerfTestSingleDelete, FastCounterValue() - fc);
	TEST2(err, 1);

	TheDb.Close();
	}
Ejemplo n.º 21
0
void getcontentstatus ( TPtrC aContent , TInt& aBLstatus ,TInt& aINstatus)
    {
    RSqlDatabase sqlDB;
    RFs fssession;    
    User::LeaveIfError( fssession.Connect() );
    TFileName privatePath;
    TFileName datafile;    
    fssession.CreatePrivatePath(EDriveC);
    fssession.PrivatePath(privatePath);//data caged path of loading process 
    fssession.Close();
    datafile.Copy(KDriveC);
    datafile.Append(privatePath);    
    datafile.Append( KContentInfoFileName );
    TInt err = sqlDB.Open( datafile );
    
    if ( err  ==KErrNone )
        {
        TSqlScalarFullSelectQuery fullSelectQuery(sqlDB);

        TBuf<100> sql;        
        // Query with INS column 
        _LIT(KgetINstatusSqlFormat, "SELECT INS FROM table1 WHERE NAME = '");
        _LIT(Kendtag, "'");
        sql.Copy( KgetINstatusSqlFormat);
        sql.Append( aContent);
        sql.Append( Kendtag );
        //sql.Format( KgetINstatusSqlFormat , aContent );
        // Read INS as integer.
        aINstatus = fullSelectQuery.SelectIntL(sql);
        
        _LIT(KgetBLstatusSqlFormat, "SELECT BLS FROM table1 WHERE NAME = '");
        sql.FillZ();
        sql.Copy( KgetBLstatusSqlFormat);
        sql.Append( aContent);
        sql.Append( Kendtag );
        //sql.Format( KgetBLstatusSqlFormat , aContent );
        // Read BLS as integer.
        aBLstatus = fullSelectQuery.SelectIntL(sql);
        }
    sqlDB.Close();
    }
Ejemplo n.º 22
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-3440
@SYMTestCaseDesc		Test for DEF105928 "SQL server ignores config string parameters".
						The test creates a secure database with a configuration string. The test must not fail.
@SYMTestPriority		High
@SYMTestActions			Test for DEF105928 "SQL server ignores config string parameters".
@SYMTestExpectedResults The test must not fail
@SYMDEF					DEF105928
*/
void CfgSecureDbTest()
	{
	//Create
	TSecurityPolicy policy(TSecurityPolicy::EAlwaysPass);
	RSqlSecurityPolicy dbPolicy;
	TInt err = dbPolicy.Create(policy);
	TEST2(err, KErrNone);
	_LIT8(KCfgStr1, "cache_size = 80; page_size = 4096; encoding = UTF-8");
	err = TheDb.Create(KTestDbName3, dbPolicy, &KCfgStr1);
	TEST2(err, KErrNone);
	//Since it is a secure database, PRAGMAs cannot be executed (in order to assert the parameter values)
	//AssertConfigPrmValues(TheDb, 80, 4096, TSqlSrvConfig::EEncUtf8);
	TheDb.Close();	
	dbPolicy.Close();
	//Open
	_LIT8(KCfgStr2, "cache_size = 100");
	err = TheDb.Open(KTestDbName3, &KCfgStr2);
	TEST2(err, KErrNone);
	TheDb.Close();	
	(void)RSqlDatabase::Delete(KTestDbName3);
	}
Ejemplo n.º 23
0
/**
@SYMTestCaseID			PDS-SQLITE3SEC-UT-4041
@SYMTestCaseDesc		SQL server single-select performance test.
						The test selects one randomly chosen record and stores
						the execution time for later use (comparison and printing).
@SYMTestPriority		High
@SYMTestActions			SQL server single-select performance test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ11320
*/
static void SqlServerSingleSelectTest(const char aSingleSelectSql[], TInt aSelectRecId)
	{
	TheTest.Next( _L("@SYMTestCaseID:PDS-SQLITE3SEC-UT-4041"));
	(void)KillProcess(KSqlSrvName);

	TInt err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);

	TheSqlBuf.Copy(TPtrC8((const TUint8*)aSingleSelectSql));
	TheSqlBuf.AppendNum((TInt64)aSelectRecId);

	RSqlStatement stmt;
	err = stmt.Prepare(TheDb, TheSqlBuf);
	TEST2(err, KErrNone);
	TInt recCnt = 0;
	TUint32 fc = FastCounterValue();
	while((err = stmt.Next()) == KSqlAtRow)
		{
		TInt64 i64 = stmt.ColumnInt64(0);
		UNUSED_VAR(i64);
		TReal d = stmt.ColumnReal(1);
		UNUSED_VAR(d);
		TPtrC t;
		err = stmt.ColumnText(2, t);
		TEST2(err, KErrNone);
		UNUSED_PTR(t);
		TPtrC8 b;
		err = stmt.ColumnBinary(3, b);
		TEST2(err, KErrNone);
		UNUSED_PTR(b);
		++recCnt;
		}
	StorePerfTestResult(EPerfTestSqlMode, EPerfTestSingleSelect, FastCounterValue() - fc);
	TEST2(err, KSqlAtEnd);
	TEST2(recCnt, 1);

	stmt.Close();
	TheDb.Close();
	}
Ejemplo n.º 24
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-3436
@SYMTestCaseDesc		Test for DEF105928 "SQL server ignores config string parameters".
						The test attempts to create/open a database using different cache size/page size/
						database encoding configurations and then checks that the configuration parameters
						have been set properly and have the expected values.
@SYMTestPriority		High
@SYMTestActions			Test for DEF105928 "SQL server ignores config string parameters".
@SYMTestExpectedResults The test must not fail
@SYMDEF					DEF105928
*/
void CfgFunctionalTest()
	{
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create a database. No config string. The default config parameters will be used.
	TInt err = TheDb.Create(KTestDbName);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create a database. Cache size set.
	_LIT8(KCfgStr1, "cache_size=32");
	err = TheDb.Create(KTestDbName, &KCfgStr1);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 32, KDefaultPageSize, KDefaultEncoding);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create a database. Page size set.
	_LIT8(KCfgStr2, "page_size=2048");
	err = TheDb.Create(KTestDbName, &KCfgStr2);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, (TSqlSrvConfigParams::KDefaultSoftHeapLimitKb * 1024) / 2048, 2048, KDefaultEncoding);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create a database. Cache & Page size set.
	_LIT8(KCfgStr3, "cache_size=256;page_size=4096");
	err = TheDb.Create(KTestDbName, &KCfgStr3);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 256, 4096, KDefaultEncoding);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create a database. Cache size & Page size & db encoding set.
	_LIT8(KCfgStr4, "cache_size=512;page_size=512;encoding=UTF-8");
	err = TheDb.Create(KTestDbName, &KCfgStr4);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 512, 512, TSqlSrvConfigParams::EEncUtf8);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create a database. Cache size & Page size & db encoding set.
	_LIT8(KCfgStr5, "cache_size=16;page_size=1024;encoding=UTF-16");
	err = TheDb.Create(KTestDbName, &KCfgStr5);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 16, 1024, TSqlSrvConfigParams::EEncUtf16);
	TheDb.Close();
	//Open the database. Cache size set. The rest of parameter values must be the same as for KCfgStr5.
	_LIT8(KCfgStr6, "cache_size=80");
	err = TheDb.Open(KTestDbName, &KCfgStr6);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, 80, 1024, TSqlSrvConfigParams::EEncUtf16);
	TheDb.Close();
	//Open the database. Attempt to set the page size (impossible when opening a database).
	_LIT8(KCfgStr7, "page_size=2048");
	err = TheDb.Open(KTestDbName, &KCfgStr7);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, KDefaultCacheSize, 1024, TSqlSrvConfigParams::EEncUtf16);
	TheDb.Close();
	//Open the database. Attempt to set the encoding (impossible when opening a database).
	_LIT8(KCfgStr8, "encoding=UTF-8");
	err = TheDb.Open(KTestDbName, &KCfgStr8);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, KDefaultCacheSize, 1024, TSqlSrvConfigParams::EEncUtf16);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create a database. Empty config string - 1
	_LIT8(KCfgStr9, "");
	err = TheDb.Create(KTestDbName, &KCfgStr9);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create a database. Empty config string - 2
	_LIT8(KCfgStr10, "       ");
	err = TheDb.Create(KTestDbName, &KCfgStr10);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	//Create a database. Empty config string - 3
	_LIT8(KCfgStr11, " ; ;   ;;   ");
	err = TheDb.Create(KTestDbName, &KCfgStr11);
	TEST2(err, KErrNone);
	AssertConfigPrmValues(TheDb, KDefaultCacheSize, KDefaultPageSize, KDefaultEncoding);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestDbName);
	}
Ejemplo n.º 25
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-4060
@SYMTestCaseDesc		Private database and compaction configuration test.
						The test verifies that a private database can be created using auto, background or 
						manual compaction mode and that the compaction mode does not chage after reopening 
						the database.
						The test also verifies that if the database is legacy, read-only, then the compaction
						mode is auto.
						The test also verifies that if the database is legacy, r/w, then the compaction
						mode will be changed from auto to background.
@SYMTestPriority		Medium
@SYMTestActions			Private database and compaction configuration test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ10273
                        REQ10274
                        REQ10400
                        REQ10402
*/
void CompactConfigTest5L()
	{
	//Create a private test database with "auto" compaction mode
	_LIT8(KConfigStr1, "encoding=utf-8;compaction=auto");
	TInt err = TheDb.Create(KTestPrivDbName, &KConfigStr1);
	TEST2(err, KErrNone);
	//Check the vacuum mode. The SQLite vacuum mode should be "auto"
	TSqlScalarFullSelectQuery scalarQuery(TheDb);
	TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KAutoVacuum);
	TheDb.Close();
	//Close and open the database again. The SQLite vacuum mode should be "auto".
	err = TheDb.Open(KTestPrivDbName);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KAutoVacuum);
	TheDb.Close();
	//Close and open the database again with a config string with "background" compaction mode. 
	//The SQLite vacuum mode should stay unchanged.
	_LIT8(KConfigStr2, "compaction=background");
	err = TheDb.Open(KTestPrivDbName, &KConfigStr2);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KAutoVacuum);
	TheDb.Close();
	//Delete database
	err = RSqlDatabase::Delete(KTestPrivDbName);
	TEST2(err, KErrNone);
	//Create a private test database - no config string
	err = TheDb.Create(KTestPrivDbName);
	TEST2(err, KErrNone);
	//Check the vacuum mode. The SQLite vacuum mode should be KSqlDefaultVacuum
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KSqlDefaultVacuum);
	TheDb.Close();
	//Close and open the database again. The SQLite vacuum mode should be KSqlDefaultVacuum.
	err = TheDb.Open(KTestPrivDbName);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KSqlDefaultVacuum);
	TheDb.Close();
	//Close and open the database again with a config string with "auto" compaction mode. 
	//The SQLite vacuum mode should stay unchanged.
	err = TheDb.Open(KTestPrivDbName, &KConfigStr1);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KSqlDefaultVacuum);
	TheDb.Close();
	//Delete database
	err = RSqlDatabase::Delete(KTestPrivDbName);
	TEST2(err, KErrNone);
	//Open an existing private database that is read-only (on drive Z:)
	err = TheDb.Open(KTestPrivDbNameZ, &KConfigStr1);
	TEST2(err, KErrNone);
	//Check the vacuum mode. The SQLite compact mode should be "auto" (this is an old database (pre-"background compact" era))
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KAutoVacuum);
	TheDb.Close();
	//Open the same database after copying it to drive C: (r/w private database). The compaction mode should change from auto to background.
	RFs fs;
	err = fs.Connect();
	TEST2(err, KErrNone);
	CFileMan* fm = CFileMan::NewL(fs);
	TEST(fm != NULL);
	err = fm->Copy(KTestPrivDbNameZ, KTestPrivDbNameC);
	TEST2(err, KErrNone);
	//"Copy" operation executed without errors. Now it is a time to turn off the read-only
	//flag of the target file (which may be on if the source file is on a read-only drive)
	err = fs.SetAtt(KTestPrivDbNameC, 0, KEntryAttReadOnly);
	TEST2(err, KErrNone);
	delete fm;
	fs.Close();
	err = TheDb.Open(KTestPrivDbNameC);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KSqlDefaultVacuum);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestPrivDbNameC);
	}
Ejemplo n.º 26
0
/**
@SYMTestCaseID			PDS-SQL-UT-4151
@SYMTestCaseDesc		Measures the performance of inserting multiple records
						into the Music Player MPX database.  This test is based on 
						a real Music Player Harvesting use case
@SYMTestPriority		Medium
@SYMTestActions			Reads SQL transactions from a file and executes them.  
						Records the time for executing each statement
@SYMTestExpectedResults All statements should be executed without error and 
						performance measurements logged
@SYMDEF					DEF142306
*/
void RunTest()
	{
	//Open the file with the sql statements 
	_LIT(KSqlFileName,"z:\\test\\t_sqlperformance4.sql");
	RFile sqlFile;
	TInt err = sqlFile.Open(TheFs, KSqlFileName, EFileRead); 
	TEST2(err, KErrNone);
	
	TInt fileLen = 0;
	err = sqlFile.Size(fileLen); 
	TEST2(err, KErrNone);
	
	HBufC8* sqlBuf = HBufC8::New(fileLen); 
	TEST(sqlBuf != NULL);
	TPtr8 sql = sqlBuf->Des();
	err = sqlFile.Read(sql);
	
	sqlFile.Close();
	TEST2(err, KErrNone);
	TEST2(sql.Length(), fileLen);
	
	//Open main database
	err = TheDbC.Open(TheDbFileName, &TheSqlConfigString);
	TEST2(err, KErrNone);
	
	TheTest.Printf(_L("Beginning INSERTS...\n"));
	
	const TInt KRecordCount = 6544;
	TInt recordCount = 0;
	TInt insertCnt = 0;
	TInt updateCnt = 0;
	TInt selectCnt = 0;
	TInt trnCnt = 0;
	TInt totalTime = 0;

	TInt insertTrnCnt = 0;
	TInt updateTrnCnt = 0;
	TInt selectTrnCnt = 0;
	
	for(;sql.Length()>0;)
		{
		TInt eolPos = sql.Locate(TChar('\n'));
		if(eolPos < 0)
			{
			break;//No more SQL statements
			}
		TInt stmtLength = eolPos;
		while (stmtLength > 0 && (sql[stmtLength-1] == '\r'))
			{
			--stmtLength; //Reduce length to remove carriage return characters from the end of the statement string
			}
		TPtrC8 sqlStmt8(sql.Ptr(), stmtLength);
		TPtrC8 ptr = sql.Mid(eolPos + 1);//"eolPos + 1" - first character after '\n'
		sql.Set(const_cast <TUint8*> (ptr.Ptr()), ptr.Length(), ptr.Length());
		++recordCount;
		
		//Convert to 16 bit query string
		TBuf<1024> query;
		query.Copy(sqlStmt8);
		
		//Execute the statement
		TInt start = User::FastCounter();
		err = TheDbC.Exec(query);
		TInt end = User::FastCounter();
		
		TEST(err >= 0);
		
		//Get the execution time for that statement
		TInt duration = GetDuration(start, end);
		totalTime += duration;
		
		if(query == KBeginTransaction)
			{		
			TheTest.Printf(_L("Execute Statement - BEGIN: %d us\n"), duration);
			}
		
		else if(query == KCommitTransaction)
			{
			++trnCnt;
			TheTest.Printf(_L("Execute Statement - COMMIT: %d us, Trn#%d, \"INSERT\" count: %d, \"UPDATE\" count: %d, \"SELECT\" count: %d\n"), 
					duration, trnCnt, insertTrnCnt, updateTrnCnt, selectTrnCnt);
			insertTrnCnt = updateTrnCnt = selectTrnCnt = 0;
			}

		else
			{	
			TPtrC queryType(query.Ptr(), 6);
			TheTest.Printf(_L("Execute Statement - %S: %d us\n"),&queryType, duration);
			if(queryType.FindF(_L("INSERT")) >= 0)
				{
				++insertCnt;
				++insertTrnCnt;
				}
			else if(queryType.FindF(_L("UPDATE")) >= 0)
				{
				++updateCnt;
				++updateTrnCnt;
				}
			else if(queryType.FindF(_L("SELECT")) >= 0)
				{
				++selectCnt;
				++selectTrnCnt;
				}
			}
		}
	delete sqlBuf;
	
	TheDbC.Close();
	
	TheTest.Printf(_L("Total time to process Songs: %d us\n"), totalTime);
	TheTest.Printf(_L("Transactions count: %d, \"INSERT\" count: %d, \"UPDATE\" count: %d, \"SELECT\" count: %d\n"), 
			               trnCnt, insertCnt, updateCnt, selectCnt);
	TEST2(recordCount, KRecordCount);
	}
Ejemplo n.º 27
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-4096
@SYMTestCaseDesc		Testing incremental blob writes on a secure database.
						The test application's capabilities allow write-only access to the blobs.
						Verify that any attempt to read a blob will fail with KErrPermissionDenied.
@SYMTestPriority		High
@SYMTestActions			Testing incremental blob writes on a secure database.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ5794
*/	
void WriteOnlyBlobTestL()
	{
	TInt err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);
			
	// Attempt to write the blobs in tables A and B
	RSqlBlobWriteStream wrStrm;
	CleanupClosePushL(wrStrm);
	TRAP(err, wrStrm.OpenL(TheDb, _L("A"), _L("B1"), 2));
	TEST2(err, KErrNone);
	TRAP(err, wrStrm.WriteL(_L8("YYYYYYY")));
	TEST2(err, KErrNone);
	wrStrm.Close();
	TRAP(err, wrStrm.OpenL(TheDb, _L("B"), _L("B2"), 1));
	TEST2(err, KErrNone);
	TRAP(err, wrStrm.WriteL(_L8("XXXXXXXXX")));
	TEST2(err, KErrNone);
	CleanupStack::PopAndDestroy(&wrStrm);	

	TRAP(err, TSqlBlob::SetL(TheDb, _L("A"), _L("B1"), _L8("UUUUUUUU"), 4));
	TEST2(err, KErrNone);
	TRAP(err, TSqlBlob::SetL(TheDb, _L("B"), _L("B2"), _L8("SSS"), 2));
	TEST2(err, KErrNone);
	
	// Attempt to read from the blobs in tables A and B
	RSqlBlobReadStream rdStrm;
	CleanupClosePushL(rdStrm);
	TRAP(err, rdStrm.OpenL(TheDb, _L("A"), _L("B1"), 1));
	TEST2(err, KErrPermissionDenied);
	rdStrm.Close();
	TRAP(err, rdStrm.OpenL(TheDb, _L("B"), _L("B2"), 1));
	TEST2(err, KErrPermissionDenied);
	CleanupStack::PopAndDestroy(&rdStrm);	

	HBufC8* wholeBuf = NULL;
	TRAP(err, wholeBuf = TSqlBlob::GetLC(TheDb, _L("A"), _L("B1"), 1));
	TEST2(err, KErrPermissionDenied);
	TRAP(err, wholeBuf = TSqlBlob::GetLC(TheDb, _L("B"), _L("B2"), 1));
	TEST2(err, KErrPermissionDenied);

	HBufC8* buf = HBufC8::NewLC(10);	
	TPtr8 bufPtr(buf->Des());	  
	err = TSqlBlob::Get(TheDb, _L("A"), _L("B1"), bufPtr, 2);
	TEST2(err, KErrPermissionDenied); 
	err = TSqlBlob::Get(TheDb, _L("B"), _L("B2"), bufPtr, 1);
	TEST2(err, KErrPermissionDenied); 
	CleanupStack::PopAndDestroy(buf); 
	
	// SQLite and system tables
	
	// Attempt to read from and write to the SQLite master table -
	// reads should be permitted because write capability is enough for this, 
	// writes should not be permitted because schema capability is required for this
	CleanupClosePushL(rdStrm);
	TRAP(err, rdStrm.OpenL(TheDb, _L("sqlite_master"), _L("tbl_name"), 1)); // TEXT column
	TEST2(err, KErrNone);
	TBuf8<20> data;
	TRAP(err, rdStrm.ReadL(data, 1));
	TEST2(err, KErrNone);
	CleanupStack::PopAndDestroy(&rdStrm);	

	wholeBuf = TSqlBlob::GetLC(TheDb, _L("sqlite_master"), _L("tbl_name"), 1);
	TEST(wholeBuf->Length() > 0);	
	CleanupStack::PopAndDestroy(wholeBuf); 	

	buf = HBufC8::NewLC(100);
	bufPtr.Set(buf->Des());	 	  
	err = TSqlBlob::Get(TheDb, _L("sqlite_master"), _L("tbl_name"), bufPtr, 1);
	TEST2(err, KErrNone); 
	TEST(bufPtr.Length() > 0);	
	CleanupStack::PopAndDestroy(buf); 
	
	CleanupClosePushL(wrStrm);
	TRAP(err, wrStrm.OpenL(TheDb, _L("sqlite_master"), _L("tbl_name"), 1));
	TEST2(err, KErrPermissionDenied);
	CleanupStack::PopAndDestroy(&wrStrm);	

	TRAP(err, TSqlBlob::SetL(TheDb, _L("sqlite_master"), _L("tbl_name"), _L8("VVVV"), 1));
	TEST2(err, KErrPermissionDenied);

	// Attempt to read from and write to the system tables - neither reads nor writes should be permitted
	CleanupClosePushL(rdStrm);
	TRAP(err, rdStrm.OpenL(TheDb, _L("symbian_security"), _L("PolicyData"), 1)); // BLOB column
	TEST2(err, KErrPermissionDenied);
	CleanupStack::PopAndDestroy(&rdStrm);	

	TRAP(err, wholeBuf = TSqlBlob::GetLC(TheDb, _L("symbian_security"), _L("PolicyData"), 1));
	TEST2(err, KErrPermissionDenied);

	buf = HBufC8::NewLC(100);	
	bufPtr.Set(buf->Des());	  
	err = TSqlBlob::Get(TheDb, _L("symbian_security"), _L("PolicyData"), bufPtr, 1);
	TEST2(err, KErrPermissionDenied); 
	CleanupStack::PopAndDestroy(buf); 
	
	CleanupClosePushL(wrStrm);
	TRAP(err, wrStrm.OpenL(TheDb, _L("symbian_security"), _L("PolicyData"), 1));
	TEST2(err, KErrPermissionDenied);
	CleanupStack::PopAndDestroy(&wrStrm);	

	TRAP(err, TSqlBlob::SetL(TheDb, _L("symbian_security"), _L("PolicyData"), _L8("VVVV"), 1));
	TEST2(err, KErrPermissionDenied);
	
	TheDb.Close();
	}
Ejemplo n.º 28
0
/**
@SYMTestCaseID			SYSLIB-SQL-CT-1646
@SYMTestCaseDesc		Testing database operations on a secure database.
						The test application's capabilities allow read/write access to the test secure database.
						Verify that any other kind of a database operation will fail with KErrPermissionDenied error.
@SYMTestPriority		High
@SYMTestActions			Testing database operations on a secure database.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ5792
                        REQ5793
*/	
void ReadWriteDatabaseTest()
	{
	RSqlDatabase db;
	TInt err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);
	
	//Attempt to modify the database schema
	err = TheDb.Exec(_L("CREATE TABLE C(FFF TEXT)"));
	TEST2(err, KErrPermissionDenied);
    err = TheDb.Exec(_L("CREATE TEMP TABLE TBL1(COL1 INTEGER, COL2 INTEGER)"));
    TEST(err >= 0);
    err = TheDb.Exec(_L("CREATE TEMP TRIGGER del1 AFTER DELETE ON TBL1 BEGIN DELETE FROM A; END;"));
    TEST(err >= 0);
    err = TheDb.Exec(_L("DROP TRIGGER del1"));
    TEST(err >= 0);
    err = TheDb.Exec(_L("CREATE TEMP VIEW V1 AS SELECT * FROM TBL1"));
    TEST(err >= 0);
    err = TheDb.Exec(_L("DROP VIEW V1"));
    TEST(err >= 0);
    err = TheDb.Exec(_L("CREATE INDEX I1 ON TBL1(COL2)"));
    TEST(err >= 0);
    err = TheDb.Exec(_L("DROP INDEX I1"));
    TEST(err >= 0);
    err = TheDb.Exec(_L("DROP TABLE TBL1"));
    TEST(err >= 0);
    err = TheDb.Exec(_L("ANALYZE A"));
    TEST2(err, KErrPermissionDenied);
    err = TheDb.Exec(_L("CREATE VIEW V2 AS SELECT * FROM A"));
    TEST2(err, KErrPermissionDenied);
	//Attempt to update the user data (but it includes a READ operation)
	err = TheDb.Exec(_L("UPDATE A SET F1 = 11 WHERE F1 = 1"));
	TEST(err >= 0);	
	//Attempt to update the user data (unconditional UPDATE, no READ operations)
	err = TheDb.Exec(_L("UPDATE A SET F1 = 11"));
	TEST(err >= 0);	
	//Attempt to delete the user data (but it includes a READ operation)
	err = TheDb.Exec(_L("DELETE FROM B WHERE F2 = 2"));
	TEST(err >= 0);	
	//Attempt to delete the user data (unconditional DELETE, no READ operations)
	err = TheDb.Exec(_L("DELETE FROM A"));
	TEST(err >= 0);	
	//Restore the deleted table A
	err = TheDb.Exec(_L("INSERT INTO A(F1,B1) VALUES(1,x'41414141414141414141');INSERT INTO A(F1,B1) VALUES(2,x'42424242424242424242');INSERT INTO A(F1,B1) VALUES(3,x'43434343434343434343');INSERT INTO A(F1,B1) VALUES(4,x'44444444444444444444');"));
	TEST(err >= 0);	
	//Restore the deleted record in table B
	err = TheDb.Exec(_L("INSERT INTO B(F2, F3, B2) VALUES(2, 'ABC', x'45454545454545454545');"));
	TEST2(err, 1);
	//Attempt to insert new user data
	err = TheDb.Exec(_L("INSERT INTO B(F2, F3, B2) VALUES(6, 'GHI', x'47474747474747474747');"));
	TEST2(err, 1);
	//Attempt to read the user data
	RSqlStatement stmt;
	err = stmt.Prepare(TheDb, _L("SELECT A.F1 FROM B,A WHERE A.F1 = B.F2"));
	TEST2(err, KErrNone);
	//ColumnCount() has no capabilities assigned
	TInt colCnt = stmt.ColumnCount();
	TEST2(colCnt, 1);
	//DeclaredColumnType() has no capabilities assigned
	TSqlColumnType colType;
	err = stmt.DeclaredColumnType(0, colType);
	TEST2(err, KErrNone);
	TEST2(colType, ESqlInt);
	err = stmt.Next();
	TEST2(err, KSqlAtRow);
	RDebug::Print(_L("Value=%d\r\n"), stmt.ColumnInt(0));
	err = stmt.Next();
	TEST2(err, KSqlAtRow);
	RDebug::Print(_L("Value=%d\r\n"), stmt.ColumnInt(0));
	stmt.Close();
	//Attempt to read the system data
	err = stmt.Prepare(TheDb, _L("SELECT * FROM SQLITE_MASTER"));
	TEST2(err, KErrNone);
	err = stmt.Next();
	TEST2(err, KSqlAtRow);
	TPtrC p;
	err = stmt.ColumnText(0, p);
	TEST2(err, KErrNone);
	RDebug::Print(_L("Value=%S\r\n"), &p);
	stmt.Close();
	
	NonSecureDbTest();
	
	TheDb.Close();
	}
Ejemplo n.º 29
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-4097
@SYMTestCaseDesc		Testing incremental blob reads and writes on a secure database.
						The test application's capabilities allow read and write access to the blobs.
						Verify that both reads and writes are allowed.
@SYMTestPriority		Medium
@SYMTestActions			Testing incremental blob reads and writes on a secure database.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ5794
*/	
void ReadWriteBlobTestL()
	{
	// Current database data:
	// TABLE A: {1, x'41414141414141414141'}, {2, x'42424242424242424242'}, {3, x'43434343434343434343'}, {4, x'44444444444444444444'}
	// TABLE B: {4, "DEF", x'46464646464646464646'} <- ROWID = 2, {2, "ABC", x'45454545454545454545'} <- ROWID = 3, {6, "GHI", x'47474747474747474747'} <- ROWID = 4

	RSqlDatabase db;
	TInt err = TheDb.Open(KTestDbName);
	TEST2(err, KErrNone);
			
	// Attempt to read the blobs in tables A and B
	RSqlBlobReadStream rdStrm;
	CleanupClosePushL(rdStrm);
	TBuf8<20> data;
	TRAP(err, rdStrm.OpenL(TheDb, _L("A"), _L("B1"), 1));
	TEST2(err, KErrNone);
	TRAP(err, rdStrm.ReadL(data, 3));
	TEST2(err, KErrNone);
	TEST(data.Compare(_L8("AAA")) == 0);
	rdStrm.Close();
	TRAP(err, rdStrm.OpenL(TheDb, _L("B"), _L("B2"), 3));
	TEST2(err, KErrNone);
	TRAP(err, rdStrm.ReadL(data, 10));
	TEST2(err, KErrNone);
	TEST(data.Compare(_L8("EEEEEEEEEE")) == 0);
	CleanupStack::PopAndDestroy(&rdStrm);	

	HBufC8* wholeBuf = TSqlBlob::GetLC(TheDb, _L("A"), _L("B1"), 4);
	TEST(wholeBuf->Des().Compare(_L8("DDDDDDDDDD")) == 0);	
	CleanupStack::PopAndDestroy(wholeBuf);
	wholeBuf = TSqlBlob::GetLC(TheDb, _L("B"), _L("B2"), 2);
	TEST(wholeBuf->Des().Compare(_L8("FFFFFFFFFF")) == 0);	
	CleanupStack::PopAndDestroy(wholeBuf);

	HBufC8* buf = HBufC8::NewLC(10);	
	TPtr8 bufPtr(buf->Des());	  
	err = TSqlBlob::Get(TheDb, _L("A"), _L("B1"), bufPtr, 2);
	TEST2(err, KErrNone); 
	TEST(bufPtr.Compare(_L8("BBBBBBBBBB")) == 0);	
	err = TSqlBlob::Get(TheDb, _L("B"), _L("B2"), bufPtr, 4);
	TEST2(err, KErrNone); 
	TEST(bufPtr.Compare(_L8("GGGGGGGGGG")) == 0);
	CleanupStack::PopAndDestroy(buf); 
	
	// Attempt to write the blobs in tables A and B
	RSqlBlobWriteStream wrStrm;
	CleanupClosePushL(wrStrm);
	TRAP(err, wrStrm.OpenL(TheDb, _L("A"), _L("B1"), 1));
	TEST2(err, KErrNone);
	TRAP(err, wrStrm.WriteL(_L8("ZZZ")));
	TEST2(err, KErrNone);
	wrStrm.Close();
	TRAP(err, wrStrm.OpenL(TheDb, _L("B"), _L("B2"), 2));
	TEST2(err, KErrNone);
	TRAP(err, wrStrm.WriteL(_L8("XXXXXXXXX")));
	TEST2(err, KErrNone);
	CleanupStack::PopAndDestroy(&wrStrm);	

	TRAP(err, TSqlBlob::SetL(TheDb, _L("A"), _L("B1"), _L8("UUUUUUUU"), 4));
	TEST2(err, KErrNone);
	TRAP(err, TSqlBlob::SetL(TheDb, _L("B"), _L("B2"), _L8("TT"), 2));
	TEST2(err, KErrNone);
	
	// SQLite and system tables
	
	// Attempt to read from and write to the SQLite master table -
	// reads should be permitted because read capability is enough for this, 
	// writes should not be permitted because schema capability is required for this
	CleanupClosePushL(rdStrm);
	TRAP(err, rdStrm.OpenL(TheDb, _L("sqlite_master"), _L("tbl_name"), 1)); // TEXT column
	TEST2(err, KErrNone);
	TRAP(err, rdStrm.ReadL(data, 1));
	TEST2(err, KErrNone);
	CleanupStack::PopAndDestroy(&rdStrm); 	

	wholeBuf = TSqlBlob::GetLC(TheDb, _L("sqlite_master"), _L("tbl_name"), 1);
	TEST(wholeBuf->Length() > 0);	
	CleanupStack::PopAndDestroy(wholeBuf);  	

	buf = HBufC8::NewLC(100);
	bufPtr.Set(buf->Des());	 	  
	err = TSqlBlob::Get(TheDb, _L("sqlite_master"), _L("tbl_name"), bufPtr, 1);
	TEST2(err, KErrNone); 
	TEST(bufPtr.Length() > 0);	
	CleanupStack::PopAndDestroy(buf); 
	
	CleanupClosePushL(wrStrm);
	TRAP(err, wrStrm.OpenL(TheDb, _L("sqlite_master"), _L("tbl_name"), 1));
	TEST2(err, KErrPermissionDenied);
	CleanupStack::PopAndDestroy(&wrStrm);	

	TRAP(err, TSqlBlob::SetL(TheDb, _L("sqlite_master"), _L("tbl_name"), _L8("VVVV"), 1));
	TEST2(err, KErrPermissionDenied);

	// Attempt to read from and write to the system tables - neither reads nor writes should be permitted
	CleanupClosePushL(rdStrm);
	TRAP(err, rdStrm.OpenL(TheDb, _L("symbian_security"), _L("PolicyData"), 1)); // BLOB column
	TEST2(err, KErrPermissionDenied);
	CleanupStack::PopAndDestroy(&rdStrm);	

	TRAP(err, wholeBuf = TSqlBlob::GetLC(TheDb, _L("symbian_security"), _L("PolicyData"), 1));
	TEST2(err, KErrPermissionDenied);

	buf = HBufC8::NewLC(100);	
	bufPtr.Set(buf->Des());	  
	err = TSqlBlob::Get(TheDb, _L("symbian_security"), _L("PolicyData"), bufPtr, 1);
	TEST2(err, KErrPermissionDenied); 
	CleanupStack::PopAndDestroy(buf); 
	
	CleanupClosePushL(wrStrm);
	TRAP(err, wrStrm.OpenL(TheDb, _L("symbian_security"), _L("PolicyData"), 1));
	TEST2(err, KErrPermissionDenied);
	CleanupStack::PopAndDestroy(&wrStrm);	

	TRAP(err, TSqlBlob::SetL(TheDb, _L("symbian_security"), _L("PolicyData"), _L8("VVVV"), 1));
	TEST2(err, KErrPermissionDenied);
	
	TheDb.Close();
	}