sl@0: // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __SQLSRVCONFIG_H__ sl@0: #define __SQLSRVCONFIG_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include "SqlAssert.h" sl@0: #include "SqlUtil.h" sl@0: sl@0: //Forward declarations sl@0: class RFs; sl@0: sl@0: /** sl@0: TSqlSrvConfigParams structure represents a set of configurable SQLITE parameters. sl@0: These are: sl@0: @code sl@0: - iCacheSize - page cache size in pages; sl@0: - iPageSize - page size in bytes; sl@0: - iDbEncoding - database encoding - 16-bit or 8-bit; sl@0: - iSoftHeapLimitKb - soft heap limit in Kb; sl@0: - iCompactMode - manual, background, automatic; sl@0: - iFreePageThresholdKb - free page threshold (in Kb) is used by the background compaction framework; sl@0: @endcode sl@0: sl@0: There is only one way a valid TSqlSrvConfigParams object to be created - using TSqlSrvConfig::GetConfigParamsL(). sl@0: GetConfigParamsL() uses an algorithm, described in TSqlSrvConfig class' comments, to decide which parameter value, sl@0: shall be used: build time, config file or the client defined one. sl@0: sl@0: @see TSqlSrvConfig sl@0: @see TSqlSrvConfig::GetConfigParamsL() sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_STRUCT(TSqlSrvConfigParams) sl@0: { sl@0: enum {KConfigPrmValueNotSet = -1};//iCacheSize, iPageSize, iSoftHeapLimitKb are initialized by default with KConfigPrmValueNotSet sl@0: enum TDbEncoding {EEncNotSet, EEncUtf8, EEncUtf16};//Database encoding: the default value for iDbEncoding is EEncNotSet sl@0: enum sl@0: { sl@0: #ifdef __WINSCW__ sl@0: KDefaultSoftHeapLimitKb = 1024, sl@0: #else sl@0: KDefaultSoftHeapLimitKb = 8192, sl@0: #endif sl@0: #ifdef SYSLIBS_TEST sl@0: KMinSoftHeapLimitKb = 8, sl@0: #else sl@0: KMinSoftHeapLimitKb = 512, sl@0: #endif sl@0: KMaxSoftHeapLimitKb = KMaxTInt / 1024 sl@0: }; sl@0: sl@0: TSqlSrvConfigParams(); sl@0: sl@0: TInt iCacheSize; sl@0: TInt iPageSize; sl@0: TDbEncoding iDbEncoding; sl@0: TInt iSoftHeapLimitKb; sl@0: TSqlCompactionMode iCompactionMode; sl@0: TInt iFreePageThresholdKb; sl@0: }; sl@0: sl@0: /** sl@0: TSqlSrvConfig class is used for: sl@0: @code sl@0: - keeping the SQL server configuration file parameter values; sl@0: - producing a TSqlSrvConfigParams object with correct SQLITE parameter values when requested (TSqlSrvConfig::GetConfigParamsL()); sl@0: @endcode sl@0: sl@0: If SQL server config file exists at the moment of the SQL server startup, the SQL server will keep sl@0: a copy of the config file parameter values in a TSqlSrvConfig object. sl@0: sl@0: The SQL server will use the following rules, which config parameter should be used: sl@0: @code sl@0: ---------------------------------------------------------------------------------------------- sl@0: Server config file parameter | Client config string parameter | What parameter is used sl@0: ---------------------------------------------------------------------------------------------- sl@0: .No..........................|.No.............................|.Build-time config parameter sl@0: .No..........................|.Yes............................|.Client config string parameter sl@0: .Yes.........................|.No.............................|.Server config file parameter sl@0: .Yes.........................|.Yes............................|.Client config string parameter sl@0: ---------------------------------------------------------------------------------------------- sl@0: @endcode sl@0: sl@0: TSqlSrvConfig::InitL() should be used once for loading the config parameter values from the SQL server comfiguration file. sl@0: sl@0: TSqlSrvConfig::GetConfigParamsL() can be used for retrieving correctly initialized TSqlSrvConfigParams object. sl@0: The rules described in the table above will be used for producing correct set of config parameter values in sl@0: the created TSqlSrvConfigParams object. sl@0: sl@0: There are exceptions from the rules and these are: sl@0: - the "soft heap limit" parameter, which cannot be set using a configuration string, sl@0: it is a config file only parameter; sl@0: - the "free page threshold" parameter, which cannot be set using a configuration string, sl@0: it is a config file only parameter; sl@0: sl@0: The configuration string format is: "PARAM1=VALUE1;PARAM2=VALUE2;...." sl@0: sl@0: @see TSqlSrvConfigParams sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(TSqlSrvConfig) sl@0: { sl@0: public: sl@0: void InitL(RFs& aFs, const TDesC& aFileName); sl@0: void GetConfigParamsL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams) const; sl@0: sl@0: private: sl@0: static void GetConfigStringFromFileL(RFs& aFs, const TDesC& aFileName, TDes8& aConfigStr); sl@0: static void ExtractConfigParamsFromStringL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams); sl@0: static TBool ExtractParamValuePairL(TPtrC8& aConfigStr, TPtrC8& aParamName, TPtrC8& aParamValue); sl@0: static void ExtractParamValueL(const TDesC8& aParamName, const TDesC8& aParamValue, TSqlSrvConfigParams& aConfigParams); sl@0: static TInt GetCacheSizeL(const TDesC8& aParamValue); sl@0: static TInt GetPageSizeL(const TDesC8& aParamValue); sl@0: static TSqlSrvConfigParams::TDbEncoding GetEncoding(const TDesC8& aParamValue); sl@0: static TInt GetSoftHeapLimitL(const TDesC8& aParamValue); sl@0: static TSqlCompactionMode GetCompactionModeL(const TDesC8& aParamValue); sl@0: static TPtrC8 TrimAndConstructPtr(const TUint8* aStr, TInt aLength); sl@0: static TInt GetFreePageThresholdL(const TDesC8& aParamValue); sl@0: sl@0: private: sl@0: TSqlSrvConfigParams iConfigFileParams; sl@0: sl@0: }; sl@0: sl@0: /** sl@0: CDbConfigFiles class is used to store the name of each database configuration sl@0: file that exists on the device. Database configuration files are currently sl@0: supported only for shared, secure databases and the name of a configuration sl@0: file is the name of the database itself prefixed with the string ‘cfg’ and sl@0: suffixed with the extension ‘.N’, where N is the version of the configuration sl@0: file. For example, for the database [12345678]a.db a valid configuration sl@0: filename is cfg[12345678]a.db.01. All database configuration files must sl@0: be located in the SQL Server’s private data cage on the Z: drive - sl@0: namely, Z:\private\10281E17\. sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(CDbConfigFiles) : public CBase sl@0: { sl@0: public: sl@0: static CDbConfigFiles* NewL(const CDir& aDirEntries); sl@0: ~CDbConfigFiles(); sl@0: HBufC* FindConfigFile(const TDesC& aDbFilename) const; sl@0: sl@0: private: sl@0: CDbConfigFiles(); sl@0: void ConstructL(const CDir& aDirEntries); sl@0: void StoreFileNamesL(const CDir& aDirEntries); sl@0: sl@0: private: sl@0: RPointerArray iConfigFileNames; sl@0: }; sl@0: sl@0: #endif//__SQLSRVCONFIG_H__