|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __SQLSRVCONFIG_H__ |
|
17 #define __SQLSRVCONFIG_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <f32file.h> |
|
21 #include "SqlPanic.h" |
|
22 #include "SqlUtil.h" |
|
23 |
|
24 //Forward declarations |
|
25 class RFs; |
|
26 |
|
27 /** |
|
28 TSqlSrvConfigParams structure represents a set of configurable SQLITE parameters. |
|
29 These are: |
|
30 @code |
|
31 - iCacheSize - page cache size in pages; |
|
32 - iPageSize - page size in bytes; |
|
33 - iDbEncoding - database encoding - 16-bit or 8-bit; |
|
34 - iSoftHeapLimitKb - soft heap limit in Kb; |
|
35 - iCompactMode - manual, background, automatic; |
|
36 - iFreePageThresholdKb - free page threshold (in Kb) is used by the background compaction framework; |
|
37 @endcode |
|
38 |
|
39 There is only one way a valid TSqlSrvConfigParams object to be created - using TSqlSrvConfig::GetConfigParamsL(). |
|
40 GetConfigParamsL() uses an algorithm, described in TSqlSrvConfig class' comments, to decide which parameter value, |
|
41 shall be used: build time, config file or the client defined one. |
|
42 |
|
43 @see TSqlSrvConfig |
|
44 @see TSqlSrvConfig::GetConfigParamsL() |
|
45 @internalComponent |
|
46 */ |
|
47 NONSHARABLE_STRUCT(TSqlSrvConfigParams) |
|
48 { |
|
49 enum {KConfigPrmValueNotSet = -1};//iCacheSize, iPageSize, iSoftHeapLimitKb are initialized by default with KConfigPrmValueNotSet |
|
50 enum TDbEncoding {EEncNotSet, EEncUtf8, EEncUtf16};//Database encoding: the default value for iDbEncoding is EEncNotSet |
|
51 enum |
|
52 { |
|
53 KDefaultSoftHeapLimitKb = 1024, |
|
54 #ifdef SYSLIBS_TEST |
|
55 KMinSoftHeapLimitKb = 8, |
|
56 #else |
|
57 KMinSoftHeapLimitKb = 512, |
|
58 #endif |
|
59 KMaxSoftHeapLimitKb = KMaxTInt / 1024 |
|
60 }; |
|
61 |
|
62 TSqlSrvConfigParams(); |
|
63 |
|
64 TInt iCacheSize; |
|
65 TInt iPageSize; |
|
66 TDbEncoding iDbEncoding; |
|
67 TInt iSoftHeapLimitKb; |
|
68 TSqlCompactionMode iCompactionMode; |
|
69 TInt iFreePageThresholdKb; |
|
70 }; |
|
71 |
|
72 /** |
|
73 TSqlSrvConfig class is used for: |
|
74 @code |
|
75 - keeping the SQL server configuration file parameter values; |
|
76 - producing a TSqlSrvConfigParams object with correct SQLITE parameter values when requested (TSqlSrvConfig::GetConfigParamsL()); |
|
77 @endcode |
|
78 |
|
79 If SQL server config file exists at the moment of the SQL server startup, the SQL server will keep |
|
80 a copy of the config file parameter values in a TSqlSrvConfig object. |
|
81 |
|
82 The SQL server will use the following rules, which config parameter should be used: |
|
83 @code |
|
84 ---------------------------------------------------------------------------------------------- |
|
85 Server config file parameter | Client config string parameter | What parameter is used |
|
86 ---------------------------------------------------------------------------------------------- |
|
87 .No..........................|.No.............................|.Build-time config parameter |
|
88 .No..........................|.Yes............................|.Client config string parameter |
|
89 .Yes.........................|.No.............................|.Server config file parameter |
|
90 .Yes.........................|.Yes............................|.Client config string parameter |
|
91 ---------------------------------------------------------------------------------------------- |
|
92 @endcode |
|
93 |
|
94 TSqlSrvConfig::InitL() should be used once for loading the config parameter values from the SQL server comfiguration file. |
|
95 |
|
96 TSqlSrvConfig::GetConfigParamsL() can be used for retrieving correctly initialized TSqlSrvConfigParams object. |
|
97 The rules described in the tabble above will be used for producing correct set of config parameter values in |
|
98 the created TSqlSrvConfigParams object. |
|
99 |
|
100 There are exceptions from the rules and these are: |
|
101 - the "soft heap limit" parameter, which cannot be set using a configuration string, |
|
102 it is a config file only parameter; |
|
103 - the "free page threshold" parameter, which cannot be set using a configuration string, |
|
104 it is a config file only parameter; |
|
105 |
|
106 The configuration string format is: "PARAM1=VALUE1;PARAM2=VALUE2;...." |
|
107 |
|
108 @see TSqlSrvConfigParams |
|
109 @internalComponent |
|
110 */ |
|
111 NONSHARABLE_CLASS(TSqlSrvConfig) |
|
112 { |
|
113 public: |
|
114 void InitL(RFs& aFs, const TDesC& aFileName); |
|
115 void GetConfigParamsL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams) const; |
|
116 |
|
117 private: |
|
118 static void GetConfigStringFromFileL(RFs& aFs, const TDesC& aFileName, TDes8& aConfigStr); |
|
119 static void ExtractConfigParamsFromStringL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams); |
|
120 static TBool ExtractParamValuePairL(TPtrC8& aConfigStr, TPtrC8& aParamName, TPtrC8& aParamValue); |
|
121 static void ExtractParamValueL(const TDesC8& aParamName, const TDesC8& aParamValue, TSqlSrvConfigParams& aConfigParams); |
|
122 static TInt GetCacheSizeL(const TDesC8& aParamValue); |
|
123 static TInt GetPageSizeL(const TDesC8& aParamValue); |
|
124 static TSqlSrvConfigParams::TDbEncoding GetEncoding(const TDesC8& aParamValue); |
|
125 static TInt GetSoftHeapLimitL(const TDesC8& aParamValue); |
|
126 static TSqlCompactionMode GetCompactionModeL(const TDesC8& aParamValue); |
|
127 static TPtrC8 TrimAndConstructPtr(const TUint8* aStr, TInt aLength); |
|
128 static TInt GetFreePageThresholdL(const TDesC8& aParamValue); |
|
129 |
|
130 private: |
|
131 TSqlSrvConfigParams iConfigFileParams; |
|
132 |
|
133 }; |
|
134 |
|
135 /** |
|
136 CDbConfigFiles class is used to store the name of each database configuration |
|
137 file that exists on the device. Database configuration files are currently |
|
138 supported only for shared, secure databases and the name of a configuration |
|
139 file is the name of the database itself prefixed with the string ‘cfg’ and |
|
140 suffixed with the extension ‘.N’, where N is the version of the configuration |
|
141 file. For example, for the database [12345678]a.db a valid configuration |
|
142 filename is cfg[12345678]a.db.01. All database configuration files must |
|
143 be located in the SQL Server’s private data cage on the Z: drive - |
|
144 namely, Z:\private\10281E17\. |
|
145 |
|
146 @internalComponent |
|
147 */ |
|
148 NONSHARABLE_CLASS(CDbConfigFiles) : public CBase |
|
149 { |
|
150 public: |
|
151 static CDbConfigFiles* NewL(const CDir& aDirEntries); |
|
152 ~CDbConfigFiles(); |
|
153 HBufC* FindConfigFile(const TDesC& aDbFilename) const; |
|
154 |
|
155 private: |
|
156 CDbConfigFiles(); |
|
157 void ConstructL(const CDir& aDirEntries); |
|
158 void StoreFileNamesL(const CDir& aDirEntries); |
|
159 |
|
160 private: |
|
161 RPointerArray<HBufC> iConfigFileNames; |
|
162 }; |
|
163 |
|
164 #endif//__SQLSRVCONFIG_H__ |