persistentstorage/sql/TEST/t_sqldbconfigfile.cpp
branchRCL_3
changeset 10 31a8f755b7fe
parent 9 667e88a979d7
child 12 6b6fd149daa2
--- a/persistentstorage/sql/TEST/t_sqldbconfigfile.cpp	Mon Mar 15 12:46:30 2010 +0200
+++ b/persistentstorage/sql/TEST/t_sqldbconfigfile.cpp	Thu Apr 01 00:19:42 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -45,13 +45,6 @@
 RSqlDatabase TheDb;
 sqlite3 *TheDbHandle = NULL;
 
-_LIT(KTestDir, "c:\\test\\");
-_LIT(KSqlSrvName, "sqlsrv.exe");
-
-enum TConfigParamType {EPrmCacheSize, EPrmPageSize, EPrmDbEncoding};
-
-TInt KillProcess(const TDesC& aProcessName);
-
 _LIT(KCfgDb1, "c:[1111C1C1]a.db"); // shared, secure db
 _LIT(KCfgDb2, "c:[1111C1C1]b.db"); // shared, secure db (no config file for it)
 _LIT(KCfgDb3, "c:\\private\\1111C1C1\\c.db"); // private, secure db
@@ -64,14 +57,6 @@
 _LIT(KCfgDb5ConfigFileV01Path, "c:\\private\\10281e17\\cfg[1111C1C1]e.db.01"); // config file v01 for e.db
 _LIT(KCfgDb1CorruptConfigFilePath, "c:\\private\\10281e17\\cfg[1111C1C1]a.db.invalidextension"); // invalid config file name syntax
 
-// config file v01 contents for db1 (also tests that upper and lower case statements are both supported)
-_LIT8(KCfgDb1ConfigFile01Stmts, "CREATE INDEX idx ON table1(i1);CREATE INDEX idx2 ON table1(i2);INSERT INTO table1 (i1,i2,i3) values(5,8,9);DELETE FROM table1;create index multiidx ON TABLE1(i2,i3)");
-// config file v01 contents for db3 (will not be processed as db3 is not a shared, secure db)
-_LIT8(KCfgDb3ConfigFile01Stmts, "CREATE INDEX idx ON table3(i1)");
-// config file v01 contents for db4 (will not be processed as db4 is not a shared, secure db)
-_LIT8(KCfgDb4ConfigFile01Stmts, "CREATE INDEX idx ON table4(i1)");
-// config file v01 contents for db5 (will eventually be processed after db5 itself is created)
-_LIT8(KCfgDb5ConfigFile01Stmts, "CREATE INDEX idx ON table5(i1);\r\n");
 // config file valid contents (used for v02 and others)
 _LIT8(KCfgConfigFileValidStmt, "CREATE INDEX newIdx ON table1(i3)  ;"); 
 // config file v03 empty contents
@@ -104,29 +89,21 @@
 _LIT(KLongCfgName1, "c:\\private\\10281e17\\cfg[1111C1C1]a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a1234.db.01");
 
 _LIT(KSqlSrvPrivatePath, "\\private\\10281e17\\");
-_LIT(KGetSettingsSql, "SELECT * FROM symbian_settings WHERE Reserved==%d");
 _LIT(KResetCollationDllSql, "UPDATE symbian_settings SET CollationDllName='hjagafsff'");
-_LIT(KGetCollationDllSql, "SELECT CollationDllName FROM symbian_settings");
 
 _LIT(KAttachDb1, "Db1");
 _LIT(KAttachDb2, "Db2");
 _LIT(KAttachDb5, "Db5");
 
-_LIT(KDb1CheckNumRecords, "SELECT * FROM table1");
-_LIT(KDb2CheckNumRecords, "SELECT * FROM table2");
-_LIT(KDb3CheckNumRecords, "SELECT * FROM table3");
-_LIT(KDb4CheckNumRecords, "SELECT * FROM table4");
-_LIT(KDb5CheckNumRecords, "SELECT * FROM table5");
-_LIT(KDbCheckNumIndices, "SELECT name FROM sqlite_master WHERE type = 'index'");
-
 ///////////////////////////////////////////////////////////////////////////////////////
 // Destroy functions
 
-TInt KillProcess(const TDesC& aProcessName)
+void KillSqlServer()
 	{
+	_LIT(KSqlSrvName, "sqlsrv.exe");
 	TFullName name;
 	//RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName);
-	TBuf<64> pattern(aProcessName);
+	TBuf<64> pattern(KSqlSrvName);
 	TInt length = pattern.Length();
 	pattern += _L("*");
 	TFindProcess procFinder(pattern);
@@ -154,7 +131,6 @@
 			}
 		proc.Close();
 		}
-	return KErrNone;
 	}
 
 void DeleteCfgFilesAndDbs()
@@ -186,7 +162,7 @@
 		TheDbHandle = NULL;
 		}
 	TheDb.Close();
-	(void)KillProcess(KSqlSrvName);
+	KillSqlServer();
 	DeleteCfgFilesAndDbs();
 	TheFs.Close();
 	}
@@ -232,8 +208,8 @@
 
 	RThread().HandleCount(endHandleCount1, endHandleCount2);
 
-	TEST(TheHandleCount1 == endHandleCount1);
-	TEST(TheHandleCount2 == endHandleCount2);
+	TEST2(TheHandleCount1, endHandleCount1);
+	TEST2(TheHandleCount2, endHandleCount2);
 	}
 
 void MarkAllocatedCells()
@@ -244,120 +220,87 @@
 void CheckAllocatedCells()
 	{
 	TInt allocatedCellsCount = User::CountAllocCells();
-	TEST(allocatedCellsCount == TheAllocatedCellsCount);
+	TEST2(allocatedCellsCount, TheAllocatedCellsCount);
 	}
 
 ///////////////////////////////////////////////////////////////////////////////////////
 // Set up functions
 
-TInt DoCreateSecurityPolicy(RSqlSecurityPolicy& securityPolicy)
+RSqlSecurityPolicy CreateSecurityPolicy()
 	{
 	const TSecurityPolicy KDefaultPolicy(TSecurityPolicy::EAlwaysPass);
-	if((KErrNone != securityPolicy.Create(KDefaultPolicy))
-	   ||
-	   (KErrNone != securityPolicy.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, KDefaultPolicy))
-	   ||
-	   (KErrNone != securityPolicy.SetDbPolicy(RSqlSecurityPolicy::EWritePolicy, KDefaultPolicy))
-	   ||
-	   (KErrNone != securityPolicy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, KDefaultPolicy)))
-		{
-		return KErrGeneral;
-		}
-		
-	return KErrNone;
+	RSqlSecurityPolicy policy;
+	TInt err = policy.Create(KDefaultPolicy);
+	TEST2(err, KErrNone);
+	err = policy.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, KDefaultPolicy);
+    TEST2(err, KErrNone);
+    err = policy.SetDbPolicy(RSqlSecurityPolicy::EWritePolicy, KDefaultPolicy);
+    TEST2(err, KErrNone);
+    err = policy.SetDbPolicy(RSqlSecurityPolicy::EReadPolicy, KDefaultPolicy);
+    TEST2(err, KErrNone);
+    return policy;
 	}
 	
+void DoCreateCfgFile(const TDesC& aFileName, const TDesC8& aData)
+    {
+    RFile file;
+    TInt err = file.Create(TheFs, aFileName, EFileRead | EFileWrite);
+    TEST2(err, KErrNone);
+    err = file.Write(aData); 
+    file.Close();   
+    TEST2(err, KErrNone);
+    }
+
+// Create v01 of the test config files
 void CreateCfgFiles()
 	{
- 	// Create v01 of the test config files
- 	
- 	RFile file;
 	TFileName fileName;
 	TInt v1 = 1;
-	fileName.Format(KCfgDb1ConfigFilePath(), v1);
-	TInt err = file.Create(TheFs, fileName, EFileRead | EFileWrite);
-	TEST2(err, KErrNone);
-	TPtrC8 pDb1((const TUint8*)KCfgDb1ConfigFile01Stmts().Ptr(), KCfgDb1ConfigFile01Stmts().Length());
-	err = file.Write(pDb1);	
-	file.Close();	
-	TEST2(err, KErrNone);
-	
-	fileName.Copy(KCfgDb3ConfigFileV01Path);
-	err = file.Create(TheFs, fileName, EFileRead | EFileWrite);
-	TEST2(err, KErrNone);
-	TPtrC8 pDb3((const TUint8*)KCfgDb3ConfigFile01Stmts().Ptr(), KCfgDb3ConfigFile01Stmts().Length());
-	err = file.Write(pDb3);	
-	file.Close();	
-	TEST2(err, KErrNone);	
-	
-	fileName.Copy(KCfgDb4ConfigFileV01Path);
-	err = file.Create(TheFs, fileName, EFileRead | EFileWrite);
-	TEST2(err, KErrNone);
-	TPtrC8 pDb4((const TUint8*)KCfgDb4ConfigFile01Stmts().Ptr(), KCfgDb4ConfigFile01Stmts().Length());
-	err = file.Write(pDb4);	
-	file.Close();	
-	TEST2(err, KErrNone);
-	
-	fileName.Copy(KCfgDb5ConfigFileV01Path); // create the config file for Db5 before the database has been created
-	err = file.Create(TheFs, fileName, EFileRead | EFileWrite);
-	TEST2(err, KErrNone);
-	TPtrC8 pDb5((const TUint8*)KCfgDb5ConfigFile01Stmts().Ptr(), KCfgDb5ConfigFile01Stmts().Length());
-	err = file.Write(pDb5);	
-	file.Close();	
-	TEST2(err, KErrNone);	
+	fileName.Format(KCfgDb1ConfigFilePath, v1);
+
+	// config file v01 contents for db1 (also tests that upper and lower case statements are both supported)
+	_LIT8(KCfgDb1ConfigFile01Stmts, "CREATE INDEX idx ON table1(i1);CREATE INDEX idx2 ON table1(i2);INSERT INTO table1 (i1,i2,i3) values(5,8,9);DELETE FROM table1;create index multiidx ON TABLE1(i2,i3)");
+    DoCreateCfgFile(fileName, KCfgDb1ConfigFile01Stmts);
+    
+    // config file v01 contents for db3 (will not be processed as db3 is not a shared, secure db)
+    _LIT8(KCfgDb3ConfigFile01Stmts, "CREATE INDEX idx ON table3(i1)");
+    DoCreateCfgFile(KCfgDb3ConfigFileV01Path, KCfgDb3ConfigFile01Stmts);
+    
+    // config file v01 contents for db4 (will not be processed as db4 is not a shared, secure db)
+    _LIT8(KCfgDb4ConfigFile01Stmts, "CREATE INDEX idx ON table4(i1)");
+    DoCreateCfgFile(KCfgDb4ConfigFileV01Path, KCfgDb4ConfigFile01Stmts);
+    
+    // create the config file for Db5 before the database has been created
+    // config file v01 contents for db5 (will eventually be processed after db5 itself is created)
+    _LIT8(KCfgDb5ConfigFile01Stmts, "CREATE INDEX idx ON table5(i1);\r\n");
+    DoCreateCfgFile(KCfgDb5ConfigFileV01Path, KCfgDb5ConfigFile01Stmts);
 	}
 
+void DoCreateCfgDb(const TDesC& aFileName, const TDesC& aCreateTblSql, const TDesC& aInsertSql, 
+                   RSqlSecurityPolicy* aPolicy = NULL)
+    {
+    TInt err = aPolicy ? TheDb.Create(aFileName, *aPolicy) : TheDb.Create(aFileName);
+    TEST2(err, KErrNone);
+    err = TheDb.Exec(aCreateTblSql);
+    TEST(err >= 0);
+    err = TheDb.Exec(aInsertSql);
+    TEST(err == 1);
+    TheDb.Close();
+    }
+
+// Create the test databases
 void CreateCfgDbs()
 	{
-	// Create the test databases
-	
- 	TBuf<100> sql;
- 		
- 	RSqlSecurityPolicy securityPolicy;
- 	TInt err = DoCreateSecurityPolicy(securityPolicy);
- 	TEST2(err, KErrNone);
- 	
- 	err = TheDb.Create(KCfgDb1, securityPolicy);
- 	TEST2(err, KErrNone);
- 	sql.Copy(_L("CREATE TABLE table1(i1 INTEGER, i2 INTEGER, i3 INTEGER)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err >= 0);
- 	sql.Copy(_L("INSERT INTO table1 (i1,i2,i3) values(1,2,3)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err == 1);
- 	TheDb.Close();
- 	
- 	err = TheDb.Create(KCfgDb2, securityPolicy);
- 	TEST2(err, KErrNone);
- 	sql.Copy(_L("CREATE TABLE table2(i1 INTEGER, i2 INTEGER, i3 INTEGER)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err >= 0);
- 	sql.Copy(_L("INSERT INTO table2 (i1,i2,i3) values(4,5,6)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err == 1);
- 	TheDb.Close();
- 	
- 	securityPolicy.Close();
- 
- 	err = TheDb.Create(KCfgDb3);
- 	TEST2(err, KErrNone);
- 	sql.Copy(_L("CREATE TABLE table3(i1 INTEGER, i2 INTEGER)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err >= 0);
- 	sql.Copy(_L("INSERT INTO table3 (i1,i2) values(7,8)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err == 1);
- 	TheDb.Close();	
- 
- 	err = TheDb.Create(KCfgDb4);
- 	TEST2(err, KErrNone);
- 	sql.Copy(_L("CREATE TABLE table4(i1 INTEGER, i2 INTEGER, i3 INTEGER)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err >= 0);
- 	sql.Copy(_L("INSERT INTO table4 (i1,i2,i3) values(9,10,11)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err == 1);
- 	TheDb.Close();
+    RSqlSecurityPolicy securityPolicy = CreateSecurityPolicy();
+    DoCreateCfgDb(KCfgDb1, _L("CREATE TABLE table1(i1 INTEGER, i2 INTEGER, i3 INTEGER)"),
+                           _L("INSERT INTO table1 (i1,i2,i3) values(1,2,3)"), &securityPolicy);
+    DoCreateCfgDb(KCfgDb2, _L("CREATE TABLE table2(i1 INTEGER, i2 INTEGER, i3 INTEGER)"),
+                           _L("INSERT INTO table2 (i1,i2,i3) values(4,5,6)"), &securityPolicy);
+    securityPolicy.Close();
+    DoCreateCfgDb(KCfgDb3, _L("CREATE TABLE table3(i1 INTEGER, i2 INTEGER)"),
+                           _L("INSERT INTO table3 (i1,i2) values(7,8)"));
+    DoCreateCfgDb(KCfgDb4, _L("CREATE TABLE table4(i1 INTEGER, i2 INTEGER, i3 INTEGER)"),
+                           _L("INSERT INTO table4 (i1,i2,i3) values(9,10,11)"));
  	}
 
 void CreateCfgFilesAndDbs()
@@ -367,29 +310,15 @@
 	
 	// Must now kill the SQL Server so that the config files 
 	// created above are found and processed when it restarts
-	(void)KillProcess(KSqlSrvName);
+	KillSqlServer();
  	}
  	
+// Create the Db5 test database (a config file for it already exists)
  void CreateDb5()
 	{
-	// Create the Db5 test database (a config file for it already exists)
-	
- 	TBuf<100> sql;
- 		
- 	RSqlSecurityPolicy securityPolicy;
- 	TInt err = DoCreateSecurityPolicy(securityPolicy);
- 	TEST2(err, KErrNone);
- 	
- 	err = TheDb.Create(KCfgDb5, securityPolicy);
- 	TEST2(err, KErrNone);
- 	sql.Copy(_L("CREATE TABLE table5(i1 INTEGER, i2 INTEGER, i3 INTEGER)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err >= 0);
- 	sql.Copy(_L("INSERT INTO table5 (i1,i2,i3) values(1,2,3)"));
- 	err = TheDb.Exec(sql);
- 	TEST(err == 1);
- 	
- 	TheDb.Close();
+ 	RSqlSecurityPolicy securityPolicy = CreateSecurityPolicy();
+    DoCreateCfgDb(KCfgDb5, _L("CREATE TABLE table5(i1 INTEGER, i2 INTEGER, i3 INTEGER)"),
+                           _L("INSERT INTO table5 (i1,i2,i3) values(1,2,3)"), &securityPolicy);
  	securityPolicy.Close();
 	}
 
@@ -398,6 +327,7 @@
 	TInt err = TheFs.Connect();
 	TEST2(err, KErrNone);
 
+	_LIT(KTestDir, "c:\\test\\");
 	err = TheFs.MkDir(KTestDir);
 	TEST(err == KErrNone || err == KErrAlreadyExists);
 
@@ -431,421 +361,218 @@
 ///////////////////////////////////////////////////////////////////////////////////////
 // Config file replacement functions
 
-void UpgradeDbConfigFile(const TInt aCurrentVersion)
+void UpgradeDbConfigFile(TInt aCurrentVersion)
 	{
-	(void)KillProcess(KSqlSrvName);
-	TFileName oldFile;
-	oldFile.Format(KCfgDb1ConfigFilePath(), aCurrentVersion);
-	TInt err = TheFs.Delete(oldFile);
-	TEST2(err, KErrNone);
-	RFile file;
-	TFileName newFile;
-	TInt newVersion = aCurrentVersion+1;
-	newFile.Format(KCfgDb1ConfigFilePath(), newVersion);
-	err = file.Create(TheFs, newFile, EFileRead | EFileWrite);
+    TInt newVersion = aCurrentVersion + 1;
+    TEST(newVersion != 0 && newVersion != 1 && newVersion != 10 && newVersion != 11 && newVersion < 15);
+	
+    KillSqlServer();
+		
+	TFileName fname;
+	fname.Format(KCfgDb1ConfigFilePath, aCurrentVersion);
+	TInt err = TheFs.Delete(fname);
 	TEST2(err, KErrNone);
 	
-	switch(newVersion)
-		{
-			case 2:
-				{
-				TPtrC8 p((const TUint8*)KCfgConfigFileValidStmt().Ptr(), KCfgConfigFileValidStmt().Length());
-				err = file.Write(p);
-				break;
-				}
-			case 3:
-				{
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV03EmptyStmt().Ptr(), KCfgDb1ConfigFileV03EmptyStmt().Length());
-				err = file.Write(p);
-				break;
-				}
-			case 4:
-				{
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV04UnsupportedStmt().Ptr(), KCfgDb1ConfigFileV04UnsupportedStmt().Length());
-				err = file.Write(p);
-				break;	
-				}
-			case 5:
-				{
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV05OnlyWhitespaceStmt().Ptr(), KCfgDb1ConfigFileV05OnlyWhitespaceStmt().Length());
-				err = file.Write(p);
-				break;
-				}	
-			case 6:
-				{
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV06InvalidSchemaStmt().Ptr(), KCfgDb1ConfigFileV06InvalidSchemaStmt().Length());
-				err = file.Write(p);
-				break;
-				}
-			case 7:
-				{
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV07InvalidCommentedStmt().Ptr(), KCfgDb1ConfigFileV07InvalidCommentedStmt().Length());
-				err = file.Write(p);	
-				break;
-				}
-			case 8:
-				{
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV08SeqStmt().Ptr(), KCfgDb1ConfigFileV08SeqStmt().Length());
-				err = file.Write(p);	
-				break;
-				}
-			case 9:
-				{
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV09WhitespacePreAndPostStmt().Ptr(), KCfgDb1ConfigFileV09WhitespacePreAndPostStmt().Length());
-				err = file.Write(p);	
-				break;
-				}
-			case 12:
-				{
-				// also delete version 10 of file
-				oldFile.Format(KCfgDb1ConfigFilePath(), 10);
-				err = TheFs.Delete(oldFile);
-				TEST2(err, KErrNone);	
-				
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV12InvalidPlusValidStmt().Ptr(), KCfgDb1ConfigFileV12InvalidPlusValidStmt().Length());
-				err = file.Write(p);
-				break;
-				}
-			case 13:
-				{
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV13SQLCommentStmt().Ptr(), KCfgDb1ConfigFileV13SQLCommentStmt().Length());
-				err = file.Write(p);	
-				break;
-				}
-			case 14:
-				{
-				TPtrC8 p((const TUint8*)KCfgDb1ConfigFileV14CCommentStmt().Ptr(), KCfgDb1ConfigFileV14CCommentStmt().Length());
-				err = file.Write(p);	
-				break;
-				}
-			default:
-				{
-				err = KErrArgument;
-				break;
-				}		
-		}
-	file.Close();
-	TEST2(err, KErrNone);
+	if(newVersion == 12)
+	    {
+        // also delete version 10 of file
+	    fname.Format(KCfgDb1ConfigFilePath, 10);
+        err = TheFs.Delete(fname);
+        TEST2(err, KErrNone);   
+	    }
+
+	const TPtrC8 stmts[] = {KNullDesC8(), KNullDesC8(), 
+	        KCfgConfigFileValidStmt(), 
+	        KCfgDb1ConfigFileV03EmptyStmt(),
+	        KCfgDb1ConfigFileV04UnsupportedStmt(),
+	        KCfgDb1ConfigFileV05OnlyWhitespaceStmt(),
+	        KCfgDb1ConfigFileV06InvalidSchemaStmt(),
+	        KCfgDb1ConfigFileV07InvalidCommentedStmt(),
+	        KCfgDb1ConfigFileV08SeqStmt(),
+	        KCfgDb1ConfigFileV09WhitespacePreAndPostStmt(),
+	        KNullDesC8(), KNullDesC8(),
+	        KCfgDb1ConfigFileV12InvalidPlusValidStmt(),
+	        KCfgDb1ConfigFileV13SQLCommentStmt(),
+	        KCfgDb1ConfigFileV14CCommentStmt()};
+
+    fname.Format(KCfgDb1ConfigFilePath, newVersion);
+	DoCreateCfgFile(fname, stmts[newVersion]);
 	}	
 	
-void DowngradeDbConfigFile(const TInt aCurrentVersion)
+void DowngradeDbConfigFile(TInt aCurrentVersion)
 	{
-	(void)KillProcess(KSqlSrvName);
-	TFileName oldFile;
-	oldFile.Format(KCfgDb1ConfigFilePath(), aCurrentVersion);
-	TInt err = TheFs.Delete(oldFile);
+	TEST(aCurrentVersion > 1);
+	
+	KillSqlServer();
+	
+	TFileName fname;
+	fname.Format(KCfgDb1ConfigFilePath, aCurrentVersion);
+	TInt err = TheFs.Delete(fname);
 	TEST2(err, KErrNone);
-	RFile file;
-	TFileName newFile;
-	TInt previousVersion = aCurrentVersion-1;
-	TEST(previousVersion > 0);
-	newFile.Format(KCfgDb1ConfigFilePath(), previousVersion);
-	err = file.Create(TheFs, newFile, EFileRead | EFileWrite);
-	TEST2(err, KErrNone);
-	TPtrC8 p((const TUint8*)KCfgConfigFileValidStmt().Ptr(), KCfgConfigFileValidStmt().Length());
-	err = file.Write(p);
-	file.Close();
-	TEST2(err, KErrNone);
+	
+    fname.Format(KCfgDb1ConfigFilePath, aCurrentVersion - 1);
+    DoCreateCfgFile(fname, KCfgConfigFileValidStmt);
 	}
 	
-void CreateCorruptDbConfigFile(const TInt aCurrentVersion)
+void CreateCorruptDbConfigFile(TInt aCurrentVersion)
 	{
-	(void)KillProcess(KSqlSrvName);
-	TFileName oldFile;
-	oldFile.Format(KCfgDb1ConfigFilePath(), aCurrentVersion);
-	TInt err = TheFs.Delete(oldFile);
+	KillSqlServer();
+	
+	TFileName fname;
+	fname.Format(KCfgDb1ConfigFilePath, aCurrentVersion);
+	TInt err = TheFs.Delete(fname);
 	TEST2(err, KErrNone);
-	RFile file;
-	err = file.Create(TheFs, KCfgDb1CorruptConfigFilePath(), EFileRead | EFileWrite);
-	TEST2(err, KErrNone);
-	TPtrC8 p((const TUint8*)KCfgConfigFileValidStmt().Ptr(), KCfgConfigFileValidStmt().Length());
-	err = file.Write(p);
-	file.Close();
-	TEST2(err, KErrNone);
+
+    DoCreateCfgFile(KCfgDb1CorruptConfigFilePath, KCfgConfigFileValidStmt);
 	}	
 	
 void CreateTwoVersionsOfConfigFile()
 	{
-	(void)KillProcess(KSqlSrvName);
+	KillSqlServer();
+	
 	TInt err = TheFs.Delete(KCfgDb1CorruptConfigFilePath);
 	TEST2(err, KErrNone);
-	RFile file;
-	TFileName newFile;
-	TInt nextVersion = 10;
-	newFile.Format(KCfgDb1ConfigFilePath(), nextVersion);
-	err = file.Create(TheFs, newFile, EFileRead | EFileWrite);
-	TEST2(err, KErrNone);
-	TPtrC8 p10((const TUint8*)KCfgDb1ConfigFileV10ValidStmt().Ptr(), KCfgDb1ConfigFileV10ValidStmt().Length());
-	err = file.Write(p10);
-	file.Close();
-	TEST2(err, KErrNone);
+
+    TInt nextVersion = 10;
+    TFileName fname;
+    fname.Format(KCfgDb1ConfigFilePath, nextVersion);
+    DoCreateCfgFile(fname, KCfgDb1ConfigFileV10ValidStmt);
+	
 	++nextVersion;
-	newFile.Format(KCfgDb1ConfigFilePath(), nextVersion);
-	err = file.Create(TheFs, newFile, EFileRead | EFileWrite);
-	TEST2(err, KErrNone);
-	TPtrC8 p11((const TUint8*)KCfgDb1ConfigFileV11ValidStmt().Ptr(), KCfgDb1ConfigFileV11ValidStmt().Length());
-	err = file.Write(p11);
-	file.Close();
-	TEST2(err, KErrNone);	
+    fname.Format(KCfgDb1ConfigFilePath, nextVersion);
+    DoCreateCfgFile(fname, KCfgDb1ConfigFileV11ValidStmt);
 	}
  
 ///////////////////////////////////////////////////////////////////////////////////////
 // DoDbCfgTests() functions
 
+TInt GetDbCfgVersion(const TDesC& aDbName)
+    {
+    // Note: We have to use SQLite directly to access the settings
+    // table as the SQL Server denies permission to access this table
+    // as it is in a shared, secure database
+    
+    TParse parse;
+    TInt err = parse.Set(aDbName, &KSqlSrvPrivatePath, 0);
+    TEST2(err, KErrNone);
+    
+    TBuf8<KMaxFileName + 1> dbFileName;
+    dbFileName.Copy(parse.FullName());
+    
+    sqlite3 *dbHandle = NULL;
+    TInt rc = sqlite3_open((const char*)dbFileName.PtrZ(), &dbHandle);
+    TEST2(rc, SQLITE_OK);
+    
+    _LIT(KGetDbCfgVersionSql, "SELECT Reserved AS DbCfgVersion FROM symbian_settings");
+    TBuf<100> queryBuf;
+    queryBuf.Copy(KGetDbCfgVersionSql);
+    
+    sqlite3_stmt* stmtHandle = NULL;
+    const void* stmtTailZ = NULL;
+    rc = sqlite3_prepare16_v2(dbHandle, queryBuf.PtrZ(), -1, &stmtHandle, &stmtTailZ);
+    TEST2(rc, SQLITE_OK);
+    
+    rc = sqlite3_step(stmtHandle);
+    TEST2(rc, SQLITE_ROW);
+    
+    TInt version = sqlite3_column_int(stmtHandle, 0);
+    
+    rc = sqlite3_step(stmtHandle);
+    TEST2(rc, SQLITE_DONE);
+    
+    sqlite3_finalize(stmtHandle);
+    sqlite3_close(dbHandle);
+    
+    return version;
+    }
+
 TBool GuessSystemSettingsTable(const TDesC& aDbName, TInt aVersion)
 	{
-	// Note: We have to use SQLite directly to access the settings
-	// table as the SQL Server denies permission to access this table
-	// as it is in a shared, secure database
-	
-	TBool guessIsCorrect = EFalse;
-	
-	TParse parse;
-	parse.Set(aDbName, &KSqlSrvPrivatePath, 0);
-	
-	TBuf8<KMaxFileName + 1> dbFileName;
-	dbFileName.Copy(parse.FullName());
-	
-	TheDbHandle = NULL;
-	TInt rc = sqlite3_open((const char*)dbFileName.PtrZ(), &TheDbHandle);
-	TEST2(rc, SQLITE_OK);
-	
-	TBuf<100> queryBuf;
-	queryBuf.Format(KGetSettingsSql(), aVersion);	
-	
-	sqlite3_stmt* stmtHandle = NULL;
-	const void* stmtTailZ = NULL;
-	rc = sqlite3_prepare16_v2(TheDbHandle, queryBuf.PtrZ(), -1, &stmtHandle, &stmtTailZ);
-	TEST2(rc, SQLITE_OK);
-	
-	rc = sqlite3_step(stmtHandle);
-	if(SQLITE_ROW == rc)
-		{
-		guessIsCorrect = ETrue;
-		rc = sqlite3_step(stmtHandle);
-		TEST2(rc, SQLITE_DONE);
-		}
-	
-	sqlite3_finalize(stmtHandle);
-	sqlite3_close(TheDbHandle);
-	TheDbHandle = NULL;
-	
-	return guessIsCorrect;
+	TInt dbCfgVersion = GetDbCfgVersion(aDbName);
+	return dbCfgVersion == aVersion; 
 	}
 
 void CheckSystemSettingsTable(const TDesC& aDbName, TInt aVersion)
 	{
-	// Note: We have to use SQLite directly to access the settings
-	// table as the SQL Server denies permission to access this table
-	// as it is in a shared, secure database
-	
-	TParse parse;
-	parse.Set(aDbName, &KSqlSrvPrivatePath, 0);
-	
-	TBuf8<KMaxFileName + 1> dbFileName;
-	dbFileName.Copy(parse.FullName());
-	
-	sqlite3 *dbHandle = NULL;
-	TInt rc = sqlite3_open((const char*)dbFileName.PtrZ(), &dbHandle);
-	TEST2(rc, SQLITE_OK);
-	
-	TBuf<100> queryBuf;
-	queryBuf.Format(KGetSettingsSql(), aVersion);	
-	
-	sqlite3_stmt* stmtHandle = NULL;
-	const void* stmtTailZ = NULL;
-	rc = sqlite3_prepare16_v2(dbHandle, queryBuf.PtrZ(), -1, &stmtHandle, &stmtTailZ);
-	TEST2(rc, SQLITE_OK);
-	
-	rc = sqlite3_step(stmtHandle);
-	TEST2(rc, SQLITE_ROW);
-	
-	rc = sqlite3_step(stmtHandle);
-	TEST2(rc, SQLITE_DONE);
-	
-	sqlite3_finalize(stmtHandle);
-	sqlite3_close(dbHandle);
+    TInt dbCfgVersion = GetDbCfgVersion(aDbName);
+    TEST2(dbCfgVersion, aVersion); 
 	}
 
-void CheckNumberRecordsL(const TDesC& aStmt)
+void CheckRecordCount(const TDesC& aTable)
 	{
 	// There should always be only 1 record in the table
 	// in each database as INSERT and DELETE statements are
 	// not supported in the config files
-	
-	// Prepare stmt
-	RSqlStatement stmt;
-	stmt.PrepareL(TheDb, aStmt);
-	
-	// Get each row
-	TUint numRows = 0;
-	TInt err = stmt.Next();
-	while(KSqlAtRow == err)
-		{
-		numRows++;
-		err = stmt.Next();
-		}
-
-	if (KSqlAtEnd != err)
-		{
-		User::Leave(KErrCorrupt);
-		}
-		
-	if (numRows != 1)
-		{
-		User::Leave(KErrArgument);
-		}
-
-	// Close stmt
-	stmt.Close();	
+	TBuf<50> sql;
+	sql.Format(_L("SELECT COUNT(*) FROM %S"), &aTable);
+	TSqlScalarFullSelectQuery q(TheDb);
+	TInt count = 0;
+    TRAPD(err, count = q.SelectIntL(sql));
+    TEST2(err, KErrNone);
+    TEST2(count, 1);
 	}
 	
-TInt NumberIndicesExpectedInDb1(const TInt aExpectedStoredVersion)
+TInt ExpectedDb1IndexCount(TInt aExpectedStoredVersion)
 	{
-	TInt numIndices = -1;
-	
-	switch(aExpectedStoredVersion)
-		{
-     	// Only files 01 - 04, 09 and 11 will be successfully processed and so stored in the settings table
-		case 1:
-			{
-			numIndices = 3; // 3 indices should be added to db1 based on config file 01
-			break;
-			}
-		case 2:
-			{
-			numIndices = 4; // 1 more index should be added to db1 based on config file 02
-			break;
-			}
-		case 3:
-		case 4:
-		case 5:
-		case 6:
-		case 7:
-			{
-			numIndices = 4; // no more indices should be added to db1 based on config file 03 - 07
-			break;
-			}
-		case 8:
-			{
-			numIndices = 6; // 2 more indices should be added to db1 based on config file 08
-			break;
-			}
-		case 9:
-			{
-			numIndices = 7; // 1 more index should be added to db1 based on config file 09
-			break;
-			}
-		case 11:
-			{
-			numIndices = 9; // 2 more indices should be added to db1 based on config file 11
-			break;
-			}	
-		case 12:
-			{
-			numIndices = 10; // 1 more index should be added to db1 based on config file 12
-			break;
-			}
-		case 13:
-			{
-			numIndices = 11; // 1 more index should be added to db1 based on config file 13
-			break;
-			}	
-		case 14:
-			{
-			numIndices = 12; // 1 more index should be added to db1 based on config file 14
-			break;
-			}		
-		}
-		
-	return numIndices;	
+	TEST(aExpectedStoredVersion >= 0 && aExpectedStoredVersion < 15);
+	const TInt KIdxCnt[] = {
+	       -1, 
+	        3,             // Only files 01 - 04, 09 and 11 will be successfully processed and so stored in the settings table
+	        4,             // 1 more index should be added to db1 based on config file 02
+	        4, 4, 4, 4, 4, // no more indices should be added to db1 based on config file 03 - 07 
+	        6,             // 2 more indices should be added to db1 based on config file 08 
+	        7,             // 1 more index should be added to db1 based on config file 09 
+	        -1, 
+	        9,             // 2 more indices should be added to db1 based on config file 11 
+	        10,            // 1 more index should be added to db1 based on config file 12
+	        11,            // 1 more index should be added to db1 based on config file 13
+	        12};           // 1 more index should be added to db1 based on config file 14
+	return KIdxCnt[aExpectedStoredVersion];
 	}
 
-void CheckNumberIndicesL(const TInt aNumIndicesExpected)
+void CheckIndexCount(TInt aExpectedIndexCount)
 	{
-	// Prepare stmt
-	RSqlStatement stmt;
-	stmt.PrepareL(TheDb, KDbCheckNumIndices);
-	
-	// Get each entry of type 'index' in the 'sqlite_master' table
-	TUint numEntries = 0;
-	TInt err = stmt.Next();
-	while(KSqlAtRow == err)
-		{
-		numEntries++;
-		err = stmt.Next();
-		}
-
-	if (KSqlAtEnd != err)
-		{
-		User::Leave(KErrCorrupt);
-		}
-		
-	if (numEntries != aNumIndicesExpected)
-		{
-		User::Leave(KErrArgument);
-		}
-
-	// Close stmt
-	stmt.Close();	
+	_LIT(KDbCheckNumIndices, "SELECT COUNT(*) FROM sqlite_master WHERE type = 'index'");
+    TSqlScalarFullSelectQuery q(TheDb);
+    TInt count = 0;
+    TRAPD(err, count = q.SelectIntL(KDbCheckNumIndices));
+    TEST2(err, KErrNone);
+    TEST2(count, aExpectedIndexCount);
 	}
 
-void DoCfgOpenTests(TInt aExpectedStoredVersion = 1)
+void DoCfgOpenTest(TInt aExpectedStoredVersion, const TDesC& aDbFileName, const TDesC& aTblName, TInt aExpectedIndexCnt)
+    {
+    TInt err = TheDb.Open(aDbFileName);
+    TEST2(err, KErrNone);
+    CheckRecordCount(aTblName);
+    CheckIndexCount(aExpectedIndexCnt);
+    TheDb.Close();
+    // Check that the ops in the specified config file have been applied.
+    CheckSystemSettingsTable(aDbFileName, aExpectedStoredVersion);
+    }
+
+void DoCfgOpenTests(TInt aExpectedStoredVersion)
 	{	
-	// Open a shared, secure database - config ops should be applied on it
+	// Open a shared, secure database - config ops should be applied on it.
+    // There should still be only 1 record and 3 indices in the table.
 	TheTest.Printf(_L("===CfgOpen: Open shared, secure database\r\n"));
-	TInt err = TheDb.Open(KCfgDb1);
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords)); // there should still be only 1 record in the table
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(NumberIndicesExpectedInDb1(aExpectedStoredVersion))); // there should now be 3 indices in the table
-	TEST2(err, KErrNone);
-	TheDb.Close();
-	CheckSystemSettingsTable(KCfgDb1, aExpectedStoredVersion); // check that the ops in the specified config file have been applied
+	DoCfgOpenTest(aExpectedStoredVersion, KCfgDb1, _L("table1"), ExpectedDb1IndexCount(aExpectedStoredVersion));
 		
-	// Open again the same shared, secure database - no config should occur (it has already been done)
+	// Open again the same shared, secure database - no config should occur (it has already been done).
 	TheTest.Printf(_L("===CfgOpen: Open shared, secure database again\r\n"));
-	err = TheDb.Open(KCfgDb1);
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords)); 
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(NumberIndicesExpectedInDb1(aExpectedStoredVersion)));
-	TEST2(err, KErrNone);
-	TheDb.Close();
-	CheckSystemSettingsTable(KCfgDb1, aExpectedStoredVersion);
+    DoCfgOpenTest(aExpectedStoredVersion, KCfgDb1, _L("table1"), ExpectedDb1IndexCount(aExpectedStoredVersion));
 	
 	// Open a shared, secure database - no config should occur (there is no config file for this database)
 	TheTest.Printf(_L("===CfgOpen: Open shared, secure database (that has no config file)\r\n"));
-	err = TheDb.Open(KCfgDb2);
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb2CheckNumRecords));
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(0)); 
-	TEST2(err, KErrNone);
-	TheDb.Close();
-	CheckSystemSettingsTable(KCfgDb2, 0);
+    DoCfgOpenTest(0, KCfgDb2, _L("table2"), 0);
 	
 	// Open a private, secure database - no config should occur
 	TheTest.Printf(_L("===CfgOpen: Open private, secure database\r\n"));
-	err = TheDb.Open(KCfgDb3);
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb3CheckNumRecords));
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(0)); 
-	TEST2(err, KErrNone);
-	TheDb.Close();
-	CheckSystemSettingsTable(KCfgDb3, 0);
+    DoCfgOpenTest(0, KCfgDb3, _L("table3"), 0);
 	
 	// Open a public database - no config should occur
 	TheTest.Printf(_L("===CfgOpen: Open public database\r\n"));
-	err = TheDb.Open(KCfgDb4);
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb4CheckNumRecords));
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(0)); 
-	TEST2(err, KErrNone);
-	TheDb.Close();
-	CheckSystemSettingsTable(KCfgDb4, 0);
+    DoCfgOpenTest(0, KCfgDb4, _L("table4"), 0);
 	}
 	
 void DoUpgradedCfgOpenTest()
@@ -915,27 +642,14 @@
 	// Create Db5 - a config file already exists for this database
 	CreateDb5();
 	
-	// Open the shared, secure database Db5 - config ops should be applied on it
+	// Open the shared, secure database Db5 - config ops should be applied on it.
+	// There should now be 1 index in the table.
 	TheTest.Printf(_L("===NewDbCfg: Open shared, secure database\r\n"));
-	TInt err = TheDb.Open(KCfgDb5);
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb5CheckNumRecords)); // there should still be only 1 record in the table
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(1)); // there should now be 1 index in the table
-	TEST2(err, KErrNone);
-	TheDb.Close();
-	CheckSystemSettingsTable(KCfgDb5, 1); // check that the ops in the specified config file have been applied
+    DoCfgOpenTest(1, KCfgDb5, _L("table5"), 1);
 		
 	// Open again the same shared, secure database - no config should occur (it has already been done)
 	TheTest.Printf(_L("===NewDbCfg: Open shared, secure database again\r\n"));
-	err = TheDb.Open(KCfgDb5);
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb5CheckNumRecords)); 
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(1));
-	TEST2(err, KErrNone);
-	TheDb.Close();
-	CheckSystemSettingsTable(KCfgDb5, 1);
+    DoCfgOpenTest(1, KCfgDb5, _L("table5"), 1);
 	}
 	
 void DoCfgAttachTests(TInt aExpectedStoredVersion = 0)
@@ -1036,19 +750,15 @@
 	TheTest.Printf(_L("===NewDbCfgAttach: Open private, secure database\r\n"));
 	TInt err = TheDb.Open(KCfgDb3);
 	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb3CheckNumRecords));
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(0)); 
-	TEST2(err, KErrNone);
+    CheckRecordCount(_L("table3"));
+    CheckIndexCount(0); 
 	
 	// Attach a shared, secure database - the db5 config file should not be processed
 	TheTest.Printf(_L("===NewDbCfgAttach: Attach shared, secure database\r\n"));
 	err = TheDb.Attach(KCfgDb5, KAttachDb5);
 	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb5CheckNumRecords)); // there should still be only 1 record in the table
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(0)); // there should still be no indices in the table
-	TEST2(err, KErrNone);
+    CheckRecordCount(_L("table5"));
+    CheckIndexCount(0); // there should still be no indices in the table
 	TheDb.Close();
 	CheckSystemSettingsTable(KCfgDb5, 1); // check that the config file has been processed for db1
 	CheckSystemSettingsTable(KCfgDb3, 0);
@@ -1101,7 +811,8 @@
 	TInt rc = sqlite3_open((const char*)dbFileName.PtrZ(), &dbHandle);
 	TEST2(rc, SQLITE_OK);
 	
-	TBuf<100> queryBuf;
+	_LIT(KGetCollationDllSql, "SELECT CollationDllName FROM symbian_settings");
+    TBuf<100> queryBuf;
 	queryBuf.Append(KGetCollationDllSql());	
 	
 	sqlite3_stmt* stmtHandle = NULL;
@@ -1146,10 +857,8 @@
 */
 void DoDbCfgTests()
 	{
-	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4010 DoDbCfgTests "));
-		
 	// Do 'open' tests for new db config file feature
-	DoCfgOpenTests();         // open the test databases
+	DoCfgOpenTests(1);         // open the test databases
  	DoUpgradedCfgOpenTest();  // upgrade the config file for db1 and reopen the test databases
  	DoBadCfgOpenTests();      // corrupt the config file for db1 (in a variety of ways) and reopen the test databases
  	DoNewDbCfgOpenTest();		  // create a db for which a config file already exists and then open the db
@@ -1170,7 +879,7 @@
  	
  	// Do the test that causes both reindexing and db configuration to occur when db1 is opened
 	ResetStoredCollationDll();
-	DoCfgOpenTests();
+	DoCfgOpenTests(1);
 	CheckCollationDllUpdated();
 	
 	// Recreate the original dbs and config files
@@ -1200,8 +909,6 @@
 */
 void DoDbCfgOOMTests()
 	{
-	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4013 DoDbCfgOOMTests "));
-
 	// Recreate the original dbs and config files
 	DeleteCfgFilesAndDbs();
 	CreateCfgFilesAndDbs();
@@ -1277,8 +984,6 @@
 */
 void DoDbCfgFileIOFailuresTests()
 	{
-	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4014 DoDbCfgFileIOFailuresTests "));
-
 	// Recreate the original dbs and config files
 	DeleteCfgFilesAndDbs();
 	CreateCfgFilesAndDbs();
@@ -1355,12 +1060,10 @@
 */
 void DoDbCfgPerfTests()
 	{
-	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4015 DoDbCfgPerfTests "));
-
 	// Recreate the original dbs
 	DeleteCfgFilesAndDbs();
 	CreateCfgDbs(); 
-	(void)KillProcess(KSqlSrvName); // stop the server
+	KillSqlServer();
 
 	// Measure the start up time of the server when
 	// there are no database configuration files to be cached.
@@ -1371,10 +1074,8 @@
 	TInt err = TheDb.Open(KCfgDb4);
 	TUint32 end = User::FastCounter();
 	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb4CheckNumRecords));
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(0));
-	TEST2(err, KErrNone);
+    CheckRecordCount(_L("table4"));
+    CheckIndexCount(0);
 	TheDb.Close();
 	CheckSystemSettingsTable(KCfgDb4, 0);
 	TInt ms = CalcTimeMs(start, end);
@@ -1389,10 +1090,8 @@
 	err = TheDb.Open(KCfgDb1);
 	end = User::FastCounter();
 	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords));
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(0));
-	TEST2(err, KErrNone);
+    CheckRecordCount(_L("table1"));
+    CheckIndexCount(0);
 	TheDb.Close();
 	CheckSystemSettingsTable(KCfgDb1, 0);
 	ms = CalcTimeMs(start, end);
@@ -1416,7 +1115,7 @@
 	
 	// Create the 4 version 01 config files now
 	CreateCfgFiles(); 
-	(void)KillProcess(KSqlSrvName); // stop the server so that the files are found when it is restarted
+	KillSqlServer(); // stop the server so that the files are found when it is restarted
 	
 	// Measure the start up time of the server when
 	// there are 4 database configuration files to be cached.
@@ -1427,10 +1126,8 @@
 	err = TheDb.Open(KCfgDb4);
 	end = User::FastCounter();
 	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb4CheckNumRecords));
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(0));
-	TEST2(err, KErrNone);
+    CheckRecordCount(_L("table4"));
+    CheckIndexCount(0);
 	TheDb.Close();
 	CheckSystemSettingsTable(KCfgDb4, 0);
 	ms = CalcTimeMs(start, end);
@@ -1445,10 +1142,8 @@
 	err = TheDb.Open(KCfgDb1);
 	end = User::FastCounter();
 	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords));
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(3));
-	TEST2(err, KErrNone);
+    CheckRecordCount(_L("table1"));
+    CheckIndexCount(3);
 	TheDb.Close();
 	CheckSystemSettingsTable(KCfgDb1, 1);
 	ms = CalcTimeMs(start, end);
@@ -1463,10 +1158,8 @@
 	err = TheDb.Open(KCfgDb1);
 	end = User::FastCounter();
 	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords));
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(3));
-	TEST2(err, KErrNone);
+    CheckRecordCount(_L("table1"));
+    CheckIndexCount(3);
 	TheDb.Close();
 	CheckSystemSettingsTable(KCfgDb1, 1);
 	ms = CalcTimeMs(start, end);
@@ -1489,28 +1182,21 @@
 	TheTest.Printf(_L("Execution time: Attach shared, secure Db1 - database config is not considered: %d ms\r\n"), ms);
 	}
 
-void TestStatementsL()
+void TestStatements()
 	{
-	_LIT(KDbName,					"attachDb");
-	_LIT(KCreateIndex,				"CREATE INDEX idx ON tbl(ColA)");
-	_LIT(KCreateIndexIfNotExists,   "CREATE INDEX IF NOT EXISTS idx ON tbl(ColA)");
-	_LIT(KCreateUniqueIndex,		"CREATE UNIQUE INDEX idx ON tbl(ColA)");
-	_LIT(KNonSupported,				"CREATE idx ON tbl(ColA)");
+	_LIT(KDbName, "attachDb");
 	TBuf<200> buf;
 
 	// supported statements
-	
-	TBool rc = IsStatementSupported(KCreateIndex, KDbName, buf); 
+	TBool rc = IsStatementSupported(_L("CREATE INDEX idx ON tbl(ColA)"), KDbName, buf); 
 	TEST(rc);
-	
-	rc = IsStatementSupported(KCreateIndexIfNotExists, KDbName, buf); 
+	rc = IsStatementSupported(_L("CREATE INDEX IF NOT EXISTS idx ON tbl(ColA)"), KDbName, buf); 
 	TEST(rc);
 
 	// unsupported statements
-	rc = IsStatementSupported(KCreateUniqueIndex, KDbName, buf); 
+	rc = IsStatementSupported(_L("CREATE UNIQUE INDEX idx ON tbl(ColA)"), KDbName, buf); 
 	TEST(!rc);
-
-	rc = IsStatementSupported(KNonSupported, KDbName, buf); 
+	rc = IsStatementSupported(_L("CREATE idx ON tbl(ColA)"), KDbName, buf); 
 	TEST(!rc);
 	}
 
@@ -1527,20 +1213,15 @@
 */
 void DoIsStatementSupportedTests()
 	{
-	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4030 DoIsStatementSupportedTests "));
-	TInt err = KErrNone;
-	TRAP(err, TestStatementsL());
-	TEST2(err, KErrNone);
+	TestStatements();
 	}
 
 void DoLongDbNameTest()
 	{
-	TheTest.Next(_L("'Long database name' tests"));
 	//Create the database	
- 	RSqlSecurityPolicy securityPolicy;
- 	TInt err = DoCreateSecurityPolicy(securityPolicy);
- 	TEST2(err, KErrNone);
- 	err = TheDb.Create(KLongDbName1, securityPolicy);
+ 	RSqlSecurityPolicy securityPolicy = CreateSecurityPolicy();
+ 	
+ 	TInt err = TheDb.Create(KLongDbName1, securityPolicy);
  	TEST2(err, KErrNone);
  	err = TheDb.Exec(_L("CREATE TABLE table1(i1 INTEGER, i2 INTEGER, i3 INTEGER)"));
  	TEST(err >= 0);
@@ -1548,7 +1229,7 @@
  	TEST(err == 1);
  	TheDb.Close();
  	//Kill the server (to reload config file names at the server startup)
-	(void)KillProcess(KSqlSrvName);
+ 	KillSqlServer();
 	///////////////////////////////////////////////////////////////////////
 	TheTest.Printf(_L("Open a database with a long name\r\n"));
 	//Create cfg file
@@ -1563,10 +1244,8 @@
 	//Open the database
 	err = TheDb.Open(KLongDbName1);
 	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberRecordsL(KDb1CheckNumRecords)); // there should still be only 1 record in the table
-	TEST2(err, KErrNone);
-	TRAP(err, CheckNumberIndicesL(1)); // there should now be 1 index in the table
-	TEST2(err, KErrNone);
+    CheckRecordCount(_L("table1"));
+    CheckIndexCount(1); // there should now be 1 index in the table
 	TheDb.Close();
 	const TInt KVersion = 1;
 	CheckSystemSettingsTable(KLongDbName1, KVersion); // check that the ops in the specified config file have been applied
@@ -1583,7 +1262,7 @@
  	TEST(err == 1);
  	TheDb.Close();
  	//Kill the server (to reload config file names at the server startup)
-	(void)KillProcess(KSqlSrvName);
+ 	KillSqlServer();
 	//Open the main database
  	err = TheDb.Open(KCfgDb1);
  	securityPolicy.Close();
@@ -1602,6 +1281,27 @@
  	(void)RSqlDatabase::Delete(KLongDbName1);
 	}
 
+void DoTests()
+    {
+    TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4010 Database config files test"));
+    DoDbCfgTests();
+    
+    TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4013 Database config files OOM test"));
+    DoDbCfgOOMTests();
+    
+    TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4014 Database config files file I/O error simulation test"));
+    DoDbCfgFileIOFailuresTests();
+    
+    TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4015 Database config files performance test"));
+    DoDbCfgPerfTests();
+
+    TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4030 Database config files - supported SQl statements test"));
+    DoIsStatementSupportedTests();
+
+    TheTest.Next(_L("'Long database name' tests"));
+    DoLongDbNameTest();
+    }
+
 #endif	//SYSLIBS_TEST
 
 TInt E32Main()
@@ -1614,36 +1314,13 @@
 	__UHEAP_MARK;
 
 #ifdef SYSLIBS_TEST	
-	TheTest.Start(_L("t_sqldbconfigfile tests"));
-
-	// Set up the test environment
+	TheTest.Start(_L("Setting up the test environment"));
 	SetupTestEnv();
-	//Init sqlite library
 	sqlite3SymbianLibInit();
-
-	// Do tests for database config files
-	DoDbCfgTests();
-	
-	// Do OOM tests for database config files
-	DoDbCfgOOMTests();
-	
-	// Do file I/O failure tests for database config files
-	DoDbCfgFileIOFailuresTests();
-
-	// Do performance tests for database config files
-	DoDbCfgPerfTests();
-
-	// Test IsStatementSupportedLC function
-	DoIsStatementSupportedTests();
-
-	//Test with a very long database file (and config file) name
-	DoLongDbNameTest();
- 
-  	// Destroy the test environment
+	DoTests();
  	DestroyTestEnv();
 	sqlite3SymbianLibFinalize();
 	CloseSTDLIB();
-	
 	TheTest.End();
 #else
  	TheTest.Start(_L("This test works only if the whole SQL component is built with SYSLIBS_TEST macro defined!"));