persistentstorage/sql/SRC/Server/SqlSrvDbSysSettings.cpp
branchRCL_3
changeset 23 26645d81f48d
parent 15 fcc16690f446
child 24 cc28652e0254
equal deleted inserted replaced
21:28839de615b4 23:26645d81f48d
    27 #include "SqlSrvStatementUtil.h"//Global SQL execution functions
    27 #include "SqlSrvStatementUtil.h"//Global SQL execution functions
    28 #include "SqlSrvCollation.h"	//TSqlCollate
    28 #include "SqlSrvCollation.h"	//TSqlCollate
    29 #include "SqlSrvStrings.h"		//System table names
    29 #include "SqlSrvStrings.h"		//System table names
    30 #include "SqlSrvUtil.h"			//Global functions
    30 #include "SqlSrvUtil.h"			//Global functions
    31 #include "SqlSrvFileData.h"		//TSqlSrvFileData
    31 #include "SqlSrvFileData.h"		//TSqlSrvFileData
       
    32 #include "OstTraceDefinitions.h"
       
    33 #ifdef OST_TRACE_COMPILER_IN_USE
       
    34 #include "SqlSrvDbSysSettingsTraces.h"
       
    35 #endif
       
    36 #include "SqlTraceDef.h"
    32 
    37 
    33 extern TBool IsStatementSupported(const TDesC& aStatementIn, const TDesC& aDbName, TDes& aStatementOut);
    38 extern TBool IsStatementSupported(const TDesC& aStatementIn, const TDesC& aDbName, TDes& aStatementOut);
    34 
    39 
    35 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    40 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    36 /////////////////////////////        Local const data   ///////////////////////////////////////////////////////
    41 /////////////////////////////        Local const data   ///////////////////////////////////////////////////////
   103 
   108 
   104 //Finalzes the statement handle (aHandle argument). Used in stack cleanup operations.
   109 //Finalzes the statement handle (aHandle argument). Used in stack cleanup operations.
   105 //Panic SqlDb 4 In _DEBUG mode if aHandle argument is NULL.
   110 //Panic SqlDb 4 In _DEBUG mode if aHandle argument is NULL.
   106 static void FinalizeStatementHandle(void* aHandle)
   111 static void FinalizeStatementHandle(void* aHandle)
   107 	{
   112 	{
   108 	__SQLASSERT(aHandle != NULL, ESqlPanicBadArgument);
   113 	__ASSERT_DEBUG(aHandle != NULL, __SQLPANIC2(ESqlPanicBadArgument));
   109 	sqlite3_stmt* stmtHandle = static_cast <sqlite3_stmt*> (aHandle);
   114 	sqlite3_stmt* stmtHandle = static_cast <sqlite3_stmt*> (aHandle);
   110 	(void)sqlite3_finalize(stmtHandle);
   115 	(void)sqlite3_finalize(stmtHandle);
   111 	}
   116 	}
   112 
   117 
   113 //Transaction rollback. Used in stack cleanup operations.
   118 //Transaction rollback. Used in stack cleanup operations.
   114 //Panic SqlDb 4 In _DEBUG mode if aDbHandle argument is NULL.
   119 //Panic SqlDb 4 In _DEBUG mode if aDbHandle argument is NULL.
   115 static void RollbackTransaction(void* aDbHandle)
   120 static void RollbackTransaction(void* aDbHandle)
   116 	{
   121 	{
   117 	__SQLASSERT(aDbHandle != NULL, ESqlPanicBadArgument);
   122 	__ASSERT_DEBUG(aDbHandle != NULL, __SQLPANIC2(ESqlPanicBadArgument));
   118 	(void)::DbExecStmt8(reinterpret_cast <sqlite3*> (aDbHandle), KRollbackTransactionSql);
   123 	(void)::DbExecStmt8(reinterpret_cast <sqlite3*> (aDbHandle), KRollbackTransactionSql);
   119 	}
   124 	}
   120 
   125 
   121 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
   126 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
   122 /////////////////////////////      TSqlDbSysSettings   ////////////////////////////////////////////////////////
   127 /////////////////////////////      TSqlDbSysSettings   ////////////////////////////////////////////////////////
   130 @panic SqlDb 4 In _DEBUG mode if aDbHandle argument is NULL.
   135 @panic SqlDb 4 In _DEBUG mode if aDbHandle argument is NULL.
   131 */
   136 */
   132 TSqlDbSysSettings::TSqlDbSysSettings(sqlite3* aDbHandle) :
   137 TSqlDbSysSettings::TSqlDbSysSettings(sqlite3* aDbHandle) :
   133 	iDbHandle(aDbHandle)
   138 	iDbHandle(aDbHandle)
   134 	{
   139 	{
   135 	__SQLASSERT(iDbHandle != NULL, ESqlPanicBadArgument);
   140 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicBadArgument));
   136 	}
   141 	}
   137 
   142 
   138 /**
   143 /**
   139 Creates the database security policy table and stores the security policy in the table.
   144 Creates the database security policy table and stores the security policy in the table.
   140 
   145 
   145                   errors categorised as ESqlDbError, and other system-wide error codes.
   150                   errors categorised as ESqlDbError, and other system-wide error codes.
   146 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   151 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   147 */
   152 */
   148 void TSqlDbSysSettings::StoreSecurityPolicyL(const CSqlSecurityPolicy& aSecurityPolicyCon)
   153 void TSqlDbSysSettings::StoreSecurityPolicyL(const CSqlSecurityPolicy& aSecurityPolicyCon)
   149 	{
   154 	{
   150 	__SQLASSERT(iDbHandle != NULL, ESqlPanicInvalidObj);
   155 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   151 	__SQLLEAVE_IF_ERROR(::DbExecStmt8(iDbHandle, KBeginTransactionSql()));
   156 	__SQLLEAVE_IF_ERROR(::DbExecStmt8(iDbHandle, KBeginTransactionSql()));
   152 	CleanupStack::PushL(TCleanupItem(&RollbackTransaction, iDbHandle));
   157 	CleanupStack::PushL(TCleanupItem(&RollbackTransaction, iDbHandle));
   153 	__SQLLEAVE_IF_ERROR(::DbExecStmt8(iDbHandle, KCreateSecuritySql()));
   158 	__SQLLEAVE_IF_ERROR(::DbExecStmt8(iDbHandle, KCreateSecuritySql()));
   154 	StoreSecurityPoliciesL(aSecurityPolicyCon);
   159 	StoreSecurityPoliciesL(aSecurityPolicyCon);
   155 	__SQLLEAVE_IF_ERROR(::DbExecStmt8(iDbHandle, KCommitTransactionSql()));
   160 	__SQLLEAVE_IF_ERROR(::DbExecStmt8(iDbHandle, KCommitTransactionSql()));
   174 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   179 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   175 @panic SqlDb 4 In _DEBUG mode if aCompactionMode parameter value is invalid.
   180 @panic SqlDb 4 In _DEBUG mode if aCompactionMode parameter value is invalid.
   176 */
   181 */
   177 void TSqlDbSysSettings::StoreSettingsL(const TDesC& aDbName, const TDesC& aCollationDllName, TInt aDbConfigFileVersion, TSqlCompactionMode aCompactionMode)
   182 void TSqlDbSysSettings::StoreSettingsL(const TDesC& aDbName, const TDesC& aCollationDllName, TInt aDbConfigFileVersion, TSqlCompactionMode aCompactionMode)
   178 	{
   183 	{
   179 	__SQLASSERT(aCompactionMode == ESqlCompactionManual || aCompactionMode == ESqlCompactionBackground || aCompactionMode == ESqlCompactionAuto, ESqlPanicBadArgument);
   184 	__ASSERT_DEBUG(aCompactionMode == ESqlCompactionManual || aCompactionMode == ESqlCompactionBackground || aCompactionMode == ESqlCompactionAuto, __SQLPANIC(ESqlPanicBadArgument));
   180 	__SQLASSERT(iDbHandle != NULL, ESqlPanicInvalidObj);
   185 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   181 	HBufC* buf = HBufC::NewLC(Max((TInt)sizeof(KDropSettingsSql), 
   186 	HBufC* buf = HBufC::NewLC(Max((TInt)sizeof(KDropSettingsSql), 
   182 							  Max((TInt)sizeof(KCreateSettingsSql), (TInt)sizeof(KInsertSettingsSql))) + 
   187 							  Max((TInt)sizeof(KCreateSettingsSql), (TInt)sizeof(KInsertSettingsSql))) + 
   183 							  aDbName.Length() + aCollationDllName.Length() + 10);
   188 							  aDbName.Length() + aCollationDllName.Length() + 10);
   184 	TPtr sql = buf->Des();
   189 	TPtr sql = buf->Des();
   185 	//Begin transaction
   190 	//Begin transaction
   214                   errors categorised as ESqlDbError, and other system-wide error codes.
   219                   errors categorised as ESqlDbError, and other system-wide error codes.
   215 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   220 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   216 */
   221 */
   217 void TSqlDbSysSettings::LoadSecurityPolicyL(CSqlSecurityPolicy& aSecurityPolicyCon)
   222 void TSqlDbSysSettings::LoadSecurityPolicyL(CSqlSecurityPolicy& aSecurityPolicyCon)
   218 	{
   223 	{
   219 	__SQLASSERT(iDbHandle != NULL, ESqlPanicInvalidObj);
   224 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   220 	//Even if the version of the system settings is bigger than the current one (KSqlSystemVersion constant),
   225 	//Even if the version of the system settings is bigger than the current one (KSqlSystemVersion constant),
   221 	//I think that all future modifications of the system tables shall not affect the already existing
   226 	//I think that all future modifications of the system tables shall not affect the already existing
   222 	//fields. So it is correct to think that all information available in version 1 should be available 
   227 	//fields. So it is correct to think that all information available in version 1 should be available 
   223 	//(and accessible) in all future versions of the system settings.
   228 	//(and accessible) in all future versions of the system settings.
   224 	//Note: no attempt shall be made here to modify the system tables structure! There may be more than one 
   229 	//Note: no attempt shall be made here to modify the system tables structure! There may be more than one 
   287 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   292 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   288 @panic SqlDb 7 In _DEBUG mode if the stored compaction mode is invalid.
   293 @panic SqlDb 7 In _DEBUG mode if the stored compaction mode is invalid.
   289 */	
   294 */	
   290 void TSqlDbSysSettings::LoadSettingsL(const TDesC& aDbName, TDes& aCollationDllName, TInt& aDbConfigFileVersion, TSqlCompactionMode& aCompactionMode)
   295 void TSqlDbSysSettings::LoadSettingsL(const TDesC& aDbName, TDes& aCollationDllName, TInt& aDbConfigFileVersion, TSqlCompactionMode& aCompactionMode)
   291 	{
   296 	{
   292 	__SQLASSERT(iDbHandle != NULL, ESqlPanicInvalidObj);
   297 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   293 
   298 
   294 	aCollationDllName.Zero();
   299 	aCollationDllName.Zero();
   295 	aDbConfigFileVersion = KSqlNullDbConfigFileVersion;	
   300 	aDbConfigFileVersion = KSqlNullDbConfigFileVersion;	
   296 	if(aCompactionMode == ESqlCompactionNotSet)
   301 	if(aCompactionMode == ESqlCompactionNotSet)
   297 		{
   302 		{
   317 			{
   322 			{
   318 			//Recreate the settings table using the last version number format (this is what the old code did during reindexing)
   323 			//Recreate the settings table using the last version number format (this is what the old code did during reindexing)
   319 			StoreSettingsL(aDbName, aCollationDllName, aDbConfigFileVersion, aCompactionMode); // store empty collation dll name, then reindexing will occur
   324 			StoreSettingsL(aDbName, aCollationDllName, aDbConfigFileVersion, aCompactionMode); // store empty collation dll name, then reindexing will occur
   320 			}
   325 			}
   321 		}
   326 		}
   322 	__SQLASSERT(aCompactionMode == ESqlCompactionManual || aCompactionMode == ESqlCompactionBackground || aCompactionMode == ESqlCompactionAuto, ESqlPanicInternalError);
   327 	__ASSERT_DEBUG(aCompactionMode == ESqlCompactionManual || aCompactionMode == ESqlCompactionBackground || aCompactionMode == ESqlCompactionAuto, __SQLPANIC(ESqlPanicInternalError));
   323 	}
   328 	}
   324 	
   329 	
   325 /**
   330 /**
   326 Retrieves the database system settings from the settings table.
   331 Retrieves the database system settings from the settings table.
   327 
   332 
   343 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   348 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   344 */
   349 */
   345 void TSqlDbSysSettings::GetSettingsL(const TDesC& aDbName, TDes& aCollationDllName, TInt& aDbConfigFileVersion, 
   350 void TSqlDbSysSettings::GetSettingsL(const TDesC& aDbName, TDes& aCollationDllName, TInt& aDbConfigFileVersion, 
   346 									 TInt& aSettingsVersion, TSqlCompactionMode& aCompactionMode)
   351 									 TInt& aSettingsVersion, TSqlCompactionMode& aCompactionMode)
   347 	{
   352 	{
   348 	__SQLASSERT(iDbHandle != NULL, ESqlPanicInvalidObj);
   353 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   349 
   354 
   350 	HBufC* buf = HBufC::NewLC(sizeof(KGetSettingsSql) + aDbName.Length());
   355 	HBufC* buf = HBufC::NewLC(sizeof(KGetSettingsSql) + aDbName.Length());
   351 	TPtr sql = buf->Des();
   356 	TPtr sql = buf->Des();
   352 			
   357 			
   353 	//Prepare statement handle
   358 	//Prepare statement handle
   387             __SQLLEAVE(KErrGeneral);   
   392             __SQLLEAVE(KErrGeneral);   
   388             }
   393             }
   389 		const void* ptr = sqlite3_column_text16(stmtHandle, KCollationDllNameColIdx);
   394 		const void* ptr = sqlite3_column_text16(stmtHandle, KCollationDllNameColIdx);
   390         //Null column value - this might be an indication of an "out of memory" problem, if the column text  
   395         //Null column value - this might be an indication of an "out of memory" problem, if the column text  
   391         //is in UTF8 format. (sqlite3_column_text16() may allocate memory for UTF8->UTF16 conversion)
   396         //is in UTF8 format. (sqlite3_column_text16() may allocate memory for UTF8->UTF16 conversion)
   392 		__SQLLEAVE_IF_NULL(ptr);
   397 		__SQLLEAVE_IF_NULL(const_cast<void*>(ptr));
   393         TPtrC16 src(reinterpret_cast <const TUint16*> (ptr));
   398         TPtrC16 src(reinterpret_cast <const TUint16*> (ptr));
   394         if(src.Length() > aCollationDllName.MaxLength())
   399         if(src.Length() > aCollationDllName.MaxLength())
   395             {
   400             {
   396             __SQLLEAVE(KErrOverflow);	
   401             __SQLLEAVE(KErrOverflow);	
   397             }
   402             }
   421 
   426 
   422 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   427 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   423 */
   428 */
   424 void TSqlDbSysSettings::ReindexDatabaseL(const TDesC& aDbName, const TDesC& aCurrentCollationDllName)
   429 void TSqlDbSysSettings::ReindexDatabaseL(const TDesC& aDbName, const TDesC& aCurrentCollationDllName)
   425 	{	
   430 	{	
   426 	__SQLASSERT(iDbHandle != NULL, ESqlPanicInvalidObj);
   431 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   427 
   432 
   428 	//Allocate memory for the SQL statements
   433 	//Allocate memory for the SQL statements
   429 	HBufC* buf = HBufC::NewLC(Max((TInt)sizeof(KUpdateCollationSettingsSql), (TInt)sizeof(KReindexSql)) + 
   434 	HBufC* buf = HBufC::NewLC(Max((TInt)sizeof(KUpdateCollationSettingsSql), (TInt)sizeof(KReindexSql)) + 
   430 							  aDbName.Length() + aCurrentCollationDllName.Length());
   435 							  aDbName.Length() + aCurrentCollationDllName.Length());
   431 	TPtr sql = buf->Des();
   436 	TPtr sql = buf->Des();
   473 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object)
   478 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object)
   474 */
   479 */
   475 void TSqlDbSysSettings::ConfigureDatabaseL(TInt aStoredDbConfigFileVersion, const TSqlSrvFileData& aFileData, 
   480 void TSqlDbSysSettings::ConfigureDatabaseL(TInt aStoredDbConfigFileVersion, const TSqlSrvFileData& aFileData, 
   476 										   const TDesC& aDbName)
   481 										   const TDesC& aDbName)
   477 	{	
   482 	{	
   478 	__SQLASSERT(iDbHandle != NULL, ESqlPanicInvalidObj);
   483 	SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, TSQLDBSYSSETTINGS_CONFIGUREDATABASEL_ENTRY, "Entry;0x%X;TSqlDbSysSettings::ConfigureDatabaseL", (TUint)this));    
       
   484 	
       
   485 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   479 
   486 
   480 	if(!aFileData.IsSecureFileNameFmt())
   487 	if(!aFileData.IsSecureFileNameFmt())
   481 		{
   488 		{
   482 		//As a first implementation, config files will only be supported for 
   489 		//As a first implementation, config files will only be supported for 
   483 		//shared, secure databases - not for private, secure databases or public databases
   490 		//shared, secure databases - not for private, secure databases or public databases
       
   491 		SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, TSQLDBSYSSETTINGS_CONFIGUREDATABASEL_EXIT1, "Exit;0x%X;TSqlDbSysSettings::ConfigureDatabaseL;Not a secure db", (TUint)this));    
   484 		return;	
   492 		return;	
   485 		}
   493 		}
   486 		
   494 		
   487 	//Determine whether there is a configuration file 
   495 	//Determine whether there is a configuration file 
   488 	//for this database that has not yet been processed
   496 	//for this database that has not yet been processed
   512 				if(KErrNone == lex.Val(fileVersion))
   520 				if(KErrNone == lex.Val(fileVersion))
   513 					{
   521 					{
   514 					if(fileVersion > aStoredDbConfigFileVersion)
   522 					if(fileVersion > aStoredDbConfigFileVersion)
   515 						{
   523 						{
   516 						//The latest version of the configuration file has not yet been processed, so do it now
   524 						//The latest version of the configuration file has not yet been processed, so do it now
   517 						__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::ConfigureDatabaseL() - Processing config file %S"), configFileName);	
   525 						SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLDBSYSSETTINGS_CONFIGUREDATABASEL1, "0x%X;TSqlDbSysSettings::ConfigureDatabaseL;Config file '%S'", (TUint)this, __SQLPRNSTR(configFileName)));	
   518 						ExecuteConfigurationUpdateL(aFileData, configFileName, fileVersion, aDbName);
   526 						ExecuteConfigurationUpdateL(aFileData, configFileName, fileVersion, aDbName);
   519 						__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::ConfigureDatabaseL() - SUCCESS! Config file %S was processed"), configFileName);	
   527 						SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLDBSYSSETTINGS_CONFIGUREDATABASEL2, "0x%X;TSqlDbSysSettings::ConfigureDatabaseL;Config file '%S' was processed, no errors", (TUint)this, __SQLPRNSTR(configFileName)));	
   520 						}
   528 						}
   521 					else
   529 					else
   522 						{
   530 						{
   523 						__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::ConfigureDatabaseL() - Not processing config file %S as this or a later version has already been processed"), configFileName);	
   531 						SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLDBSYSSETTINGS_CONFIGUREDATABASEL3, "0x%X;TSqlDbSysSettings::ConfigureDatabaseL;Config file '%S' as this or a later version has already been processed", (TUint)this, __SQLPRNSTR(configFileName)));	
   524 						}
   532 						}
   525 					}
   533 					}
   526 				else
   534 				else
   527 					{
   535 					{
   528 					//Invalid config file name extension - it cannot be converted to an integer
   536 					//Invalid config file name extension - it cannot be converted to an integer
   535 				__SQLLEAVE(KErrCorrupt);
   543 				__SQLLEAVE(KErrCorrupt);
   536 				}
   544 				}
   537 			}
   545 			}
   538 		else
   546 		else
   539 			{
   547 			{
   540 			__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::ConfigureDatabaseL() - No config file found for database %S"), dbFileNameAndExt);	
   548 			SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLDBSYSSETTINGS_CONFIGUREDATABASEL4, "0x%X;TSqlDbSysSettings::ConfigureDatabaseL;No config file found for database '%S'", (TUint)this, __SQLPRNSTR(dbFileNameAndExt)));	
   541 			}
   549 			}
   542 		}		
   550 		}		
       
   551 	SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, TSQLDBSYSSETTINGS_CONFIGUREDATABASEL_EXIT2, "Exit;0x%X;TSqlDbSysSettings::ConfigureDatabaseL", (TUint)this));    
   543 	}
   552 	}
   544 	
   553 	
   545 /**
   554 /**
   546 Executes the supported operations specified in the given database 
   555 Executes the supported operations specified in the given database 
   547 configuration file and updates the settings table to store the 
   556 configuration file and updates the settings table to store the 
   563 void TSqlDbSysSettings::ExecuteConfigurationUpdateL(const TSqlSrvFileData& aFileData, 
   572 void TSqlDbSysSettings::ExecuteConfigurationUpdateL(const TSqlSrvFileData& aFileData, 
   564 													const TDesC& aMatchingConfigFile,
   573 													const TDesC& aMatchingConfigFile,
   565 													TInt aDbConfigFileVersion,
   574 													TInt aDbConfigFileVersion,
   566 													const TDesC& aDbName)
   575 													const TDesC& aDbName)
   567 	{
   576 	{
   568 	__SQLASSERT(iDbHandle != NULL, ESqlPanicInvalidObj);
   577 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   569 														
   578 														
   570 	//Execute the specified database config file operations that are supported
   579 	//Execute the specified database config file operations that are supported
   571 #ifdef SYSLIBS_TEST
   580 #ifdef SYSLIBS_TEST
   572 	TDriveUnit drive = EDriveC;
   581 	TDriveUnit drive = EDriveC;
   573 #else
   582 #else
   607 
   616 
   608 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   617 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object).
   609 */
   618 */
   610 void TSqlDbSysSettings::DoExecuteDbConfigFileOpsL(RFs& aFs, const TDesC& aConfigFilePath, const TDesC& aDbName)
   619 void TSqlDbSysSettings::DoExecuteDbConfigFileOpsL(RFs& aFs, const TDesC& aConfigFilePath, const TDesC& aDbName)
   611 	{
   620 	{
   612 	__SQLASSERT(iDbHandle != NULL, ESqlPanicInvalidObj);
   621 	__ASSERT_DEBUG(iDbHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   613 	
   622 	
   614 	//Open the config file and read it into a buffer
   623 	//Open the config file and read it into a buffer
   615 	RFile64 file;
   624 	RFile64 file;
   616 	__SQLLEAVE_IF_ERROR(file.Open(aFs, aConfigFilePath, EFileRead)); 
   625 	__SQLLEAVE_IF_ERROR(file.Open(aFs, aConfigFilePath, EFileRead)); 
   617 	CleanupClosePushL(file);
   626 	CleanupClosePushL(file);
   618 	TInt64 size = 0;
   627 	TInt64 size = 0;
   619 	__SQLLEAVE_IF_ERROR(file.Size(size));
   628 	__SQLLEAVE_IF_ERROR(file.Size(size));
   620 	if(size == 0)
   629 	if(size == 0)
   621 		{
   630 		{
   622 		//Config file is empty so just return
   631 		//Config file is empty so just return
   623 		__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::DoExecuteDbConfigFileOpsL() - Config file %S is empty"), aConfigFilePath);	
   632 		SQL_TRACE_INTERNALS(OstTraceExt1(TRACE_INTERNALS, TSQLDBSYSSETTINGS_DOEXECUTEDBCONFIGFILEOPSL, "0;TSqlDbSysSettings::DoExecuteDbConfigFileOpsL();Config file %S is empty", __SQLPRNSTR(aConfigFilePath)));	
   624 		CleanupStack::PopAndDestroy(); // file
   633 		CleanupStack::PopAndDestroy(); // file
   625 		return;
   634 		return;
   626 		}
   635 		}
   627 	HBufC8* buffer = HBufC8::NewLC(size);
   636 	HBufC8* buffer = HBufC8::NewLC(size);
   628 	TPtr8 bufPtr = buffer->Des();
   637 	TPtr8 bufPtr = buffer->Des();
   689 
   698 
   690 @leave KErrNoMemory, if an out of memory condition occurs
   699 @leave KErrNoMemory, if an out of memory condition occurs
   691 */
   700 */
   692 void TSqlDbSysSettings::ProcessStatementL(const TDesC& aStmt, const TDesC& aDbName)
   701 void TSqlDbSysSettings::ProcessStatementL(const TDesC& aStmt, const TDesC& aDbName)
   693 	{	
   702 	{	
   694 	__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::ProcessStatementL() - Processing statement '%S'"), aStmt);	
   703 	SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLDBSYSSETTINGS_PROCESSSTATEMENTL_ENTRY, "Entry;0x%X;TSqlDbSysSettings::ProcessStatementL;Processing statement '%S'", (TUint)this, __SQLPRNSTR(aStmt)));	
   695 	
   704 	
   696 	//If the statement only contained whitespace then just return
   705 	//If the statement only contained whitespace then just return
   697 	if(aStmt.Length() == 0)
   706 	if(aStmt.Length() == 0)
   698 		{
   707 		{
   699 		__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::ProcessStatementL() - Statement '%S' only contains whitespace - statement will be ignored"), aStmt);	
   708 		SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, TSQLDBSYSSETTINGS_PROCESSSTATEMENTL_EXIT1, "Exit;0x%X;TSqlDbSysSettings::ProcessStatementL;The statement ignored because contains only whitespace", (TUint)this));	
   700 		return;	
   709 		return;	
   701 		}
   710 		}
   702 		
   711 		
   703 	//Check that the statement does not contain an unsupported comment style
   712 	//Check that the statement does not contain an unsupported comment style
   704 	if(KErrNotFound != aStmt.Find(_L("//")))
   713 	if(KErrNotFound != aStmt.Find(_L("//")))
   705 		{
   714 		{
   706 		//The statement contains '//' which is an unsupported comment style, but rather
   715 		//The statement contains '//' which is an unsupported comment style, but rather
   707 		//than leave here and cause the full file to fail, we just ignore this statement
   716 		//than leave here and cause the full file to fail, we just ignore this statement
   708 		__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::ProcessStatementL() - Statement '%S' contains invalid comment style - statement will be ignored"), aStmt);	
   717 		SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, TSQLDBSYSSETTINGS_PROCESSSTATEMENTL_EXIT2, "Exit;0x%X;TSqlDbSysSettings::ProcessStatementL;The statement ignored because contains invalid comment style", (TUint)this));	
   709 		return;
   718 		return;
   710 		}
   719 		}
   711 		
   720 		
   712 	HBufC* stmtBuf = HBufC::NewLC(aStmt.Length() + 1 + aDbName.Length() + 1);
   721 	HBufC* stmtBuf = HBufC::NewLC(aStmt.Length() + 1 + aDbName.Length() + 1);
   713 	TPtr stmtPtr = stmtBuf->Des();
   722 	TPtr stmtPtr = stmtBuf->Des();
   715 	if(::IsStatementSupported(aStmt, aDbName, stmtPtr))
   724 	if(::IsStatementSupported(aStmt, aDbName, stmtPtr))
   716 		{
   725 		{
   717 		TInt err = ::DbExecStmt16(iDbHandle, stmtPtr);
   726 		TInt err = ::DbExecStmt16(iDbHandle, stmtPtr);
   718 		if(KErrNone == err)
   727 		if(KErrNone == err)
   719 			{
   728 			{
   720 			__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::ProcessStatementL() - Successfully executed statement '%S'"), aStmt);		
   729 			SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, TSQLDBSYSSETTINGS_PROCESSSTATEMENTL1, "0x%X;TSqlDbSysSettings::ProcessStatementL;Successfully executed statement", (TUint)this));		
   721 			}
   730 			}
   722 		else
   731 		else
   723 			{
   732 			{
   724 			__SQLLOG_ERR(_L("SQLLOG: TSqlDbSysSettings::ProcessStatementL() - Failed to execute the statement, err=%d"), err);		
   733 			SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLDBSYSSETTINGS_PROCESSSTATEMENTL2, "0x%X;TSqlDbSysSettings::ProcessStatementL;Failed to execute the statement;err=%d", (TUint)this, err));		
   725 			if(err == KErrNoMemory)
   734 			if(err == KErrNoMemory)
   726 				{
   735 				{
   727 				__SQLLEAVE(err);	
   736 				__SQLLEAVE(err);	
   728 				}
   737 				}
   729 			}
   738 			}
   730 		}
   739 		}
   731 	else
   740 	else
   732 		{
   741 		{
   733 		__SQLLOG_STRING(_L("SQLLOG: TSqlDbSysSettings::ProcessStatementL() - Non-supported statement, will be ignored - '%S'"), aStmt);		
   742 		SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, TSQLDBSYSSETTINGS_PROCESSSTATEMENTL3, "0x%X;TSqlDbSysSettings::ProcessStatementL;Non-supported statement, will be ignored", (TUint)this));		
   734 		}
   743 		}
   735 	CleanupStack::PopAndDestroy(); // stmtBuf
   744 	CleanupStack::PopAndDestroy(); // stmtBuf
       
   745 	SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, TSQLDBSYSSETTINGS_PROCESSSTATEMENTL_EXIT3, "Exit;0x%X;TSqlDbSysSettings::ProcessStatementL", (TUint)this));  
   736 	}
   746 	}
   737 
   747 
   738 
   748 
   739 /**
   749 /**
   740 Stores the security policies into the security policies table.
   750 Stores the security policies into the security policies table.
   793 @panic SqlDb 4 In _DEBUG mode if aHandle argument is NULL.
   803 @panic SqlDb 4 In _DEBUG mode if aHandle argument is NULL.
   794 */
   804 */
   795 void TSqlDbSysSettings::StoreSecurityPolicyL(sqlite3_stmt* aStmtHandle, TInt aObjType, const TDesC& aObjName, 
   805 void TSqlDbSysSettings::StoreSecurityPolicyL(sqlite3_stmt* aStmtHandle, TInt aObjType, const TDesC& aObjName, 
   796 											 TInt aPolicyType, const TSecurityPolicy& aPolicy)
   806 											 TInt aPolicyType, const TSecurityPolicy& aPolicy)
   797 	{
   807 	{
   798 	__SQLASSERT(aStmtHandle != NULL, ESqlPanicBadArgument);
   808 	__ASSERT_DEBUG(aStmtHandle != NULL, __SQLPANIC(ESqlPanicBadArgument));
   799 	__SQLLEAVE_IF_ERROR(::StmtReset(aStmtHandle));
   809 	__SQLLEAVE_IF_ERROR(::StmtReset(aStmtHandle));
   800 	__SQLLEAVE_IF_ERROR(BindSecurityPolicyPrm(aStmtHandle, aObjType, aObjName, aPolicyType, aPolicy));
   810 	__SQLLEAVE_IF_ERROR(BindSecurityPolicyPrm(aStmtHandle, aObjType, aObjName, aPolicyType, aPolicy));
   801 	__SQLLEAVE_IF_ERROR(::StmtExec(aStmtHandle));
   811 	__SQLLEAVE_IF_ERROR(::StmtExec(aStmtHandle));
   802 	}
   812 	}
   803 
   813 
   852 	   KErrNoMemory, Out of memory.
   862 	   KErrNoMemory, Out of memory.
   853 */
   863 */
   854 TSecurityPolicy TSqlDbSysSettings::ReadCurrSecurityPolicyL(sqlite3_stmt* aStmtHandle, TInt& aObjType, 
   864 TSecurityPolicy TSqlDbSysSettings::ReadCurrSecurityPolicyL(sqlite3_stmt* aStmtHandle, TInt& aObjType, 
   855 														   TPtrC& aObjName, TInt& aPolicyType)
   865 														   TPtrC& aObjName, TInt& aPolicyType)
   856 	{
   866 	{
   857 	__SQLASSERT(aStmtHandle != NULL, ESqlPanicBadArgument);
   867 	__ASSERT_DEBUG(aStmtHandle != NULL, __SQLPANIC(ESqlPanicBadArgument));
   858 	aObjType = sqlite3_column_int(aStmtHandle, KObjTypeColIdx);
   868 	aObjType = sqlite3_column_int(aStmtHandle, KObjTypeColIdx);
   859     //The "ObjectName" column type might be different than SQLITE_TEXT - malformed database.
   869     //The "ObjectName" column type might be different than SQLITE_TEXT - malformed database.
   860     if(sqlite3_column_type(aStmtHandle, KObjNameColIdx) != SQLITE_TEXT)
   870     if(sqlite3_column_type(aStmtHandle, KObjNameColIdx) != SQLITE_TEXT)
   861         {
   871         {
   862         __SQLLEAVE(KErrGeneral);   
   872         __SQLLEAVE(KErrGeneral);   
   863         }
   873         }
   864     const void* text = sqlite3_column_text16(aStmtHandle, KObjNameColIdx);
   874     const void* text = sqlite3_column_text16(aStmtHandle, KObjNameColIdx);
   865     //Null column value - this might be an indication of an "out of memory" problem, if the column text  
   875     //Null column value - this might be an indication of an "out of memory" problem, if the column text  
   866     //is in UTF8 format. (sqlite3_column_text16() may allocate memory for UTF8->UTF16 conversion)
   876     //is in UTF8 format. (sqlite3_column_text16() may allocate memory for UTF8->UTF16 conversion)
   867     __SQLLEAVE_IF_NULL(text);
   877     __SQLLEAVE_IF_NULL(const_cast<void*>(text));
   868 	TInt len = (TUint)sqlite3_column_bytes16(aStmtHandle, KObjNameColIdx) / sizeof(TUint16);
   878 	TInt len = (TUint)sqlite3_column_bytes16(aStmtHandle, KObjNameColIdx) / sizeof(TUint16);
   869 	aObjName.Set(reinterpret_cast <const TUint16*> (text), len);
   879 	aObjName.Set(reinterpret_cast <const TUint16*> (text), len);
   870 	aPolicyType = sqlite3_column_int(aStmtHandle, KObjPolicyTypeColIdx);
   880 	aPolicyType = sqlite3_column_int(aStmtHandle, KObjPolicyTypeColIdx);
   871 	len = sqlite3_column_bytes(aStmtHandle, KObjPolicyDataColIdx);
   881 	len = sqlite3_column_bytes(aStmtHandle, KObjPolicyDataColIdx);
   872 	if(len != sizeof(TSecurityPolicy))
   882 	if(len != sizeof(TSecurityPolicy))