os/persistentdata/persistentstorage/sql/SRC/Server/SqlSrvConfig.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sql/SRC/Server/SqlSrvConfig.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,168 @@
     1.4 +// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __SQLSRVCONFIG_H__
    1.20 +#define __SQLSRVCONFIG_H__
    1.21 +
    1.22 +#include <e32std.h>
    1.23 +#include <f32file.h> 
    1.24 +#include "SqlAssert.h"
    1.25 +#include "SqlUtil.h"
    1.26 +
    1.27 +//Forward declarations
    1.28 +class RFs;
    1.29 +
    1.30 +/**
    1.31 +TSqlSrvConfigParams structure represents a set of configurable SQLITE parameters.
    1.32 +These are:
    1.33 +@code
    1.34 + - iCacheSize  - page cache size in pages;
    1.35 + - iPageSize   - page size in bytes;
    1.36 + - iDbEncoding - database encoding - 16-bit or 8-bit;
    1.37 + - iSoftHeapLimitKb - soft heap limit in Kb;
    1.38 + - iCompactMode - manual, background, automatic;
    1.39 + - iFreePageThresholdKb - free page threshold (in Kb) is used by the background compaction framework;
    1.40 +@endcode
    1.41 +
    1.42 +There is only one way a valid TSqlSrvConfigParams object to be created - using TSqlSrvConfig::GetConfigParamsL().
    1.43 +GetConfigParamsL() uses an algorithm, described in TSqlSrvConfig class' comments, to decide which parameter value,
    1.44 +shall be used: build time, config file or the client defined one.
    1.45 +
    1.46 +@see TSqlSrvConfig
    1.47 +@see TSqlSrvConfig::GetConfigParamsL()
    1.48 +@internalComponent
    1.49 +*/
    1.50 +NONSHARABLE_STRUCT(TSqlSrvConfigParams)
    1.51 +	{
    1.52 +	enum {KConfigPrmValueNotSet = -1};//iCacheSize, iPageSize, iSoftHeapLimitKb are initialized by default with KConfigPrmValueNotSet
    1.53 +	enum TDbEncoding {EEncNotSet, EEncUtf8, EEncUtf16};//Database encoding: the default value for iDbEncoding is EEncNotSet
    1.54 +	enum 
    1.55 +		{
    1.56 +#ifdef __WINSCW__
    1.57 +		KDefaultSoftHeapLimitKb = 1024,
    1.58 +#else
    1.59 +		KDefaultSoftHeapLimitKb = 8192,
    1.60 +#endif	
    1.61 +#ifdef SYSLIBS_TEST	
    1.62 +		KMinSoftHeapLimitKb = 8, 
    1.63 +#else
    1.64 +		KMinSoftHeapLimitKb = 512,
    1.65 +#endif
    1.66 +		KMaxSoftHeapLimitKb = KMaxTInt / 1024
    1.67 +		};
    1.68 +	
    1.69 +	TSqlSrvConfigParams();	
    1.70 +		
    1.71 +	TInt				iCacheSize;
    1.72 +	TInt				iPageSize;
    1.73 +	TDbEncoding			iDbEncoding;
    1.74 +	TInt				iSoftHeapLimitKb;
    1.75 +	TSqlCompactionMode	iCompactionMode;
    1.76 +	TInt				iFreePageThresholdKb;
    1.77 +	};
    1.78 +	
    1.79 +/**
    1.80 +TSqlSrvConfig class is used for:
    1.81 +@code 
    1.82 + - keeping the SQL server configuration file parameter values;
    1.83 + - producing a TSqlSrvConfigParams object with correct SQLITE parameter values when requested (TSqlSrvConfig::GetConfigParamsL());
    1.84 +@endcode
    1.85 +
    1.86 +If SQL server config file exists at the moment of the SQL server startup, the SQL server will keep 
    1.87 +a copy of the config file parameter values in a TSqlSrvConfig object.
    1.88 +
    1.89 +The SQL server will use the following rules, which config parameter should be used:
    1.90 +@code
    1.91 +----------------------------------------------------------------------------------------------
    1.92 +Server config file parameter | Client config string parameter | What parameter is used
    1.93 +----------------------------------------------------------------------------------------------
    1.94 +.No..........................|.No.............................|.Build-time config parameter
    1.95 +.No..........................|.Yes............................|.Client config string parameter
    1.96 +.Yes.........................|.No.............................|.Server config file parameter
    1.97 +.Yes.........................|.Yes............................|.Client config string parameter
    1.98 +----------------------------------------------------------------------------------------------
    1.99 +@endcode
   1.100 +
   1.101 +TSqlSrvConfig::InitL() should be used once for loading the config parameter values from the SQL server comfiguration file.
   1.102 +
   1.103 +TSqlSrvConfig::GetConfigParamsL() can be used for retrieving correctly initialized TSqlSrvConfigParams object.
   1.104 +The rules described in the table above will be used for producing correct set of config parameter values in
   1.105 +the created TSqlSrvConfigParams object.
   1.106 +
   1.107 +There are exceptions from the rules and these are:
   1.108 + - the "soft heap limit" parameter, which cannot be set using a configuration string, 
   1.109 +   it is a config file only parameter;
   1.110 + - the "free page threshold" parameter, which cannot be set using a configuration string, 
   1.111 +   it is a config file only parameter;
   1.112 +
   1.113 +The configuration string format is: "PARAM1=VALUE1;PARAM2=VALUE2;...."
   1.114 +
   1.115 +@see TSqlSrvConfigParams
   1.116 +@internalComponent
   1.117 +*/
   1.118 +NONSHARABLE_CLASS(TSqlSrvConfig)
   1.119 +	{	
   1.120 +public:
   1.121 +	void InitL(RFs& aFs, const TDesC& aFileName);
   1.122 +	void GetConfigParamsL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams) const;
   1.123 +	
   1.124 +private:
   1.125 +	static void GetConfigStringFromFileL(RFs& aFs, const TDesC& aFileName, TDes8& aConfigStr);
   1.126 +	static void ExtractConfigParamsFromStringL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams);
   1.127 +	static TBool ExtractParamValuePairL(TPtrC8& aConfigStr, TPtrC8& aParamName, TPtrC8& aParamValue);
   1.128 +	static void ExtractParamValueL(const TDesC8& aParamName, const TDesC8& aParamValue, TSqlSrvConfigParams& aConfigParams);
   1.129 +	static TInt GetCacheSizeL(const TDesC8& aParamValue);
   1.130 +	static TInt GetPageSizeL(const TDesC8& aParamValue);
   1.131 +	static TSqlSrvConfigParams::TDbEncoding GetEncoding(const TDesC8& aParamValue);
   1.132 +	static TInt GetSoftHeapLimitL(const TDesC8& aParamValue);
   1.133 +	static TSqlCompactionMode GetCompactionModeL(const TDesC8& aParamValue);
   1.134 +	static TPtrC8 TrimAndConstructPtr(const TUint8* aStr, TInt aLength);
   1.135 +	static TInt GetFreePageThresholdL(const TDesC8& aParamValue);
   1.136 +	
   1.137 +private:
   1.138 +	TSqlSrvConfigParams	iConfigFileParams;
   1.139 +		
   1.140 +	};
   1.141 +
   1.142 +/**
   1.143 +CDbConfigFiles class is used to store the name of each database configuration 
   1.144 +file that exists on the device. Database configuration files are currently 
   1.145 +supported only for shared, secure databases and the name of a configuration 
   1.146 +file is the name of the database itself prefixed with the string ‘cfg’ and 
   1.147 +suffixed with the extension ‘.N’, where N is the version of the configuration 
   1.148 +file. For example, for the database [12345678]a.db a valid configuration 
   1.149 +filename is cfg[12345678]a.db.01. All database configuration files must 
   1.150 +be located in the SQL Server’s private data cage on the Z: drive - 
   1.151 +namely, Z:\private\10281E17\. 
   1.152 +
   1.153 +@internalComponent
   1.154 +*/
   1.155 +NONSHARABLE_CLASS(CDbConfigFiles) : public CBase
   1.156 +{
   1.157 +public:		
   1.158 +   	static CDbConfigFiles* NewL(const CDir& aDirEntries);
   1.159 +	~CDbConfigFiles();
   1.160 +	HBufC* FindConfigFile(const TDesC& aDbFilename) const;
   1.161 +	
   1.162 +private:
   1.163 +	CDbConfigFiles();
   1.164 +	void ConstructL(const CDir& aDirEntries);
   1.165 +	void StoreFileNamesL(const CDir& aDirEntries);
   1.166 +		
   1.167 +private:
   1.168 +	RPointerArray<HBufC> iConfigFileNames;
   1.169 +};
   1.170 +
   1.171 +#endif//__SQLSRVCONFIG_H__