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