1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sql/SRC/Server/SqlSrvConfig.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,494 @@
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 +#include <f32file.h>
1.19 +#include <f32file64.h>
1.20 +#include "SqlSrvConfig.h"
1.21 +#include "SqlSrvUtil.h"
1.22 +#include "OstTraceDefinitions.h"
1.23 +#ifdef OST_TRACE_COMPILER_IN_USE
1.24 +#include "SqlSrvConfigTraces.h"
1.25 +#endif
1.26 +#include "SqlTraceDef.h"
1.27 +
1.28 +/**
1.29 +Initializes TSqlSrvConfigParams data members with their default values.
1.30 +*/
1.31 +TSqlSrvConfigParams::TSqlSrvConfigParams() :
1.32 + iCacheSize(TSqlSrvConfigParams::KConfigPrmValueNotSet),
1.33 + iPageSize(TSqlSrvConfigParams::KConfigPrmValueNotSet),
1.34 + iDbEncoding(TSqlSrvConfigParams::EEncNotSet),
1.35 + iSoftHeapLimitKb(TSqlSrvConfigParams::KConfigPrmValueNotSet),
1.36 + iCompactionMode(ESqlCompactionNotSet),
1.37 + iFreePageThresholdKb(TSqlSrvConfigParams::KConfigPrmValueNotSet)
1.38 + {
1.39 + }
1.40 +
1.41 +/**
1.42 +"Object initialization" method.
1.43 +Opens and reads the SQL server configuration file (if it exists).
1.44 +Initializes TSqlSrvConfig data members using the data from the config file.
1.45 +If the configuration file does not exist, TSqlSrvConfig data members stay unchanged,
1.46 +except:
1.47 + - the soft heap limit, which default value is TSqlSrvConfigParams::KDefaultSoftHeapLimit;
1.48 + - the free pages threshold, which default value is KSqlCompactFreePageThreshold;
1.49 +
1.50 +@param aFs File session
1.51 +@param aFileName Config file name
1.52 +@leave KErrEof No valid config string found in the configuration file;
1.53 + Note that the function may also leave with some other system-wide error codes.
1.54 +*/
1.55 +void TSqlSrvConfig::InitL(RFs& aFs, const TDesC& aFileName)
1.56 + {
1.57 + SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL_ENTRY, "Entry;0;TSqlSrvConfig::InitL;aFs.Handle()=0x%X;aFileName=%S", (TUint)aFs.Handle(), __SQLPRNSTR(aFileName)));
1.58 + if(::FileExists(aFs, aFileName))
1.59 + {
1.60 + SQL_TRACE_INTERNALS(OstTrace0(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL1, "0;TSqlSrvConfig::InitL;Config file found"));
1.61 + TBuf8<KSqlSrvMaxConfigStrLen> configFileStr;
1.62 + //Step 1: get the config string from the config file and store the string in configFileStr
1.63 + TSqlSrvConfig::GetConfigStringFromFileL(aFs, aFileName, configFileStr);
1.64 + __SQLTRACE_INTERNALSVAR(TBuf<100> des16prnbuf);
1.65 + SQL_TRACE_INTERNALS(OstTraceExt1(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL2, "0;TSqlSrvConfig::InitL;Config file string=%s", __SQLPRNSTR8(configFileStr, des16prnbuf)));
1.66 + //Step 2: extract config file parameters from the string (configFileStr) and store them in iConfigFileParams
1.67 + TSqlSrvConfig::ExtractConfigParamsFromStringL(configFileStr, iConfigFileParams);
1.68 + }
1.69 + //If the soft heap limit is not set from the file or the file does not exist - then set the soft heap limit with the default value
1.70 + if(iConfigFileParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet)
1.71 + {
1.72 + iConfigFileParams.iSoftHeapLimitKb = TSqlSrvConfigParams::KDefaultSoftHeapLimitKb;
1.73 + }
1.74 + //If the free page threshold is not set from the file or the file does not exist - then set the free page threshold with the default value
1.75 + if(iConfigFileParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet)
1.76 + {
1.77 + iConfigFileParams.iFreePageThresholdKb = KSqlCompactFreePageThresholdKb;
1.78 + }
1.79 +
1.80 +#ifdef _SQL_RDEBUG_PRINT
1.81 + SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL_EXIT1, "Exit;0;TSqlSrvConfig::InitL;iCacheSize=%d;iPageSize=%d;iDbEncoding=%d;iSoftHeapLimit=%d", iConfigFileParams.iCacheSize, iConfigFileParams.iPageSize, iConfigFileParams.iDbEncoding, iConfigFileParams.iSoftHeapLimitKb));
1.82 +#else
1.83 + SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL_EXIT2, "Exit;0;TSqlSrvConfig::InitL;iCacheSize=%d;iPageSize=%d;iDbEncoding=%{TSqlSrvConfig_TDbEncoding};iSoftHeapLimit=%d", iConfigFileParams.iCacheSize, iConfigFileParams.iPageSize, iConfigFileParams.iDbEncoding, iConfigFileParams.iSoftHeapLimitKb));
1.84 +#endif
1.85 + SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL_EXIT3, "Exit;0;TSqlSrvConfig::InitL;iCompactionMode=%d;iFreePageThresholdKb=%d", iConfigFileParams.iCompactionMode, iConfigFileParams.iFreePageThresholdKb));
1.86 + }
1.87 +
1.88 +/**
1.89 +Parses the config string parameter (aConfigStr), extracts configuration parameters values and
1.90 +and initialises with them aConfigParams data members.
1.91 +The config string format is: "PARAM1=VALUE1;PARAM2=VALUE2;..."
1.92 +If there is unknown parameter "name=value" pair in the config string, it will be skipped - not reported as an error.
1.93 +In a case of a leave, the old content of aConfigStr is preserved.
1.94 +The rules for TSqlSrvConfigParams data members initialization are described in TSqlSrvConfig class' comments.
1.95 +
1.96 +@see TSqlSrvConfig
1.97 +@param aConfigStr the config descriptor
1.98 +@param aConfigParams Output argument, config parameters will be stored there.
1.99 +@leave KErrArgument if the config is not good or the config string contains "soft heap limit" parameter/value pair.
1.100 +@leave KErrArgument if the config is not good or the config string contains "free page threshold" parameter/value pair.
1.101 +*/
1.102 +void TSqlSrvConfig::GetConfigParamsL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams) const
1.103 + {
1.104 + __SQLTRACE_INTERNALSVAR(TBuf<100> des16prnbuf);
1.105 + SQL_TRACE_INTERNALS(OstTraceExt1(TRACE_INTERNALS, TSQLSRVCONFIGFILE_GETCONFIGPARAMSL_ENTRY, "Entry;0;TSqlSrvConfig::GetConfigParamsL;aConfigStr=%s", __SQLPRNSTR8(aConfigStr, des16prnbuf)));
1.106 + TSqlSrvConfigParams tmpConfigParams;
1.107 + //Step 1: extract configuration parameters from aConfigStr, store them in tmpConfigParams.
1.108 + TSqlSrvConfig::ExtractConfigParamsFromStringL(aConfigStr, tmpConfigParams);
1.109 + if(tmpConfigParams.iSoftHeapLimitKb != TSqlSrvConfigParams::KConfigPrmValueNotSet ||
1.110 + tmpConfigParams.iFreePageThresholdKb != TSqlSrvConfigParams::KConfigPrmValueNotSet)
1.111 + {//It is not allowed the soft heap limit to be set from a config string, only from the SQL server config file.
1.112 + //It is not allowed the free page threshold to be set from a config string, only from the SQL server config file.
1.113 + __SQLLEAVE(KErrArgument);
1.114 + }
1.115 + //Step 2: store tmpConfigParams in aConfigParams.
1.116 + aConfigParams = tmpConfigParams;
1.117 + //Step 3: replace each "not set" parameter in aConfigParams with the related parameter value from iConfigFileParams (the config file).
1.118 + if(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet)
1.119 + {
1.120 + aConfigParams.iPageSize = iConfigFileParams.iPageSize;
1.121 + }
1.122 + if(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet)
1.123 + {
1.124 + aConfigParams.iDbEncoding = iConfigFileParams.iDbEncoding;
1.125 + }
1.126 + if(aConfigParams.iCompactionMode == ESqlCompactionNotSet)
1.127 + {
1.128 + aConfigParams.iCompactionMode = iConfigFileParams.iCompactionMode;
1.129 + }
1.130 + //Step 4: set the soft heap limit.
1.131 + aConfigParams.iSoftHeapLimitKb = iConfigFileParams.iSoftHeapLimitKb;
1.132 + //Step 5: set the free page threshold.
1.133 + aConfigParams.iFreePageThresholdKb = iConfigFileParams.iFreePageThresholdKb;
1.134 + //Step 6: assert the parameter values.
1.135 + __ASSERT_DEBUG(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, __SQLPANIC(ESqlPanicInternalError));
1.136 + __ASSERT_DEBUG(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, __SQLPANIC(ESqlPanicInternalError));
1.137 + __ASSERT_DEBUG(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet ||
1.138 + aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf8 ||
1.139 + aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf16, __SQLPANIC(ESqlPanicInternalError));
1.140 + __ASSERT_DEBUG(aConfigParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet ||
1.141 + (aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb &&
1.142 + aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb), __SQLPANIC(ESqlPanicInternalError));
1.143 + __ASSERT_DEBUG(aConfigParams.iCompactionMode == ESqlCompactionNotSet || aConfigParams.iCompactionMode == ESqlCompactionManual ||
1.144 + aConfigParams.iCompactionMode == ESqlCompactionBackground || aConfigParams.iCompactionMode == ESqlCompactionAuto, __SQLPANIC(ESqlPanicInternalError));
1.145 + __ASSERT_DEBUG(aConfigParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet ||
1.146 + aConfigParams.iFreePageThresholdKb >= 0, __SQLPANIC(ESqlPanicInternalError));
1.147 +#ifdef _SQL_RDEBUG_PRINT
1.148 + SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, TSQLSRVCONFIGFILE_GETCONFIGPARAMSL_EXIT1, "Exit;0;TSqlSrvConfig::GetConfigParamsL;cacheSize=%d;pageSize=%d;dbEncoding=%d;softHeapLimit=%d", aConfigParams.iCacheSize, aConfigParams.iPageSize, aConfigParams.iDbEncoding, aConfigParams.iSoftHeapLimitKb));
1.149 +#else
1.150 + SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, TSQLSRVCONFIGFILE_GETCONFIGPARAMSL_EXIT2, "Exit;0;TSqlSrvConfig::GetConfigParamsL;cacheSize=%d;pageSize=%d;dbEncoding=%{TSqlSrvConfig_TDbEncoding};softHeapLimit=%d", aConfigParams.iCacheSize, aConfigParams.iPageSize, aConfigParams.iDbEncoding, aConfigParams.iSoftHeapLimitKb));
1.151 +#endif
1.152 + SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLSRVCONFIGFILE_GETCONFIGPARAMSL_EXIT3, "Exit;0;TSqlSrvConfig::GetConfigParamsL;compactionMode=%d;freePageThresholdKb=%d", aConfigParams.iCompactionMode, aConfigParams.iFreePageThresholdKb));
1.153 + }
1.154 +
1.155 +//The function opeans the aFileName config file and reads the config string, storring it in aConfigStr argument.
1.156 +//Preconditions:
1.157 +// - The config file does exist;
1.158 +// - It is a file, containing 16-bit strings;
1.159 +// - aConfigStr max size is at least KSqlSrvMaxConfigStrLen bytes;
1.160 +//The function may leave if some of the file I/O operations (open file, read file) fails.
1.161 +void TSqlSrvConfig::GetConfigStringFromFileL(RFs& aFs, const TDesC& aFileName, TDes8& aConfigStr)
1.162 + {
1.163 + __ASSERT_DEBUG(aConfigStr.MaxLength() >= KSqlSrvMaxConfigStrLen, __SQLPANIC2(ESqlPanicBadArgument));
1.164 + RFile64 cfgFile;
1.165 + CleanupClosePushL(cfgFile);
1.166 + __SQLLEAVE_IF_ERROR2(cfgFile.Open(aFs, aFileName, EFileRead));
1.167 + TFileText cfgFileReader;
1.168 + cfgFileReader.Set(cfgFile);
1.169 + TBuf<KSqlSrvMaxConfigStrLen> buf;
1.170 + TBool cfgLineFound = EFalse;
1.171 + TInt err = KErrNone;
1.172 + //Read the configuration file line by line until get the first "non-comment" line.
1.173 + while((err = cfgFileReader.Read(buf)) == KErrNone)
1.174 + {
1.175 + buf.TrimAll();
1.176 + if(buf.Length() == 0 || buf.Locate('#') == 0) //'#' means - this line is a comment
1.177 + {
1.178 + continue;
1.179 + }
1.180 + cfgLineFound = ETrue;
1.181 + break;
1.182 + }
1.183 + CleanupStack::PopAndDestroy(&cfgFile);
1.184 + if(err != KErrEof)
1.185 + {//The "read configuration file" operation has failed with "err" (if err != KErrNone)
1.186 + __SQLLEAVE_IF_ERROR2(err);
1.187 + }
1.188 + if(!cfgLineFound)
1.189 + {//End of config file reached - no valid configuration line found.
1.190 + __SQLLEAVE2(KErrEof);
1.191 + }
1.192 + __ASSERT_DEBUG(err == KErrNone || err == KErrEof, __SQLPANIC2(ESqlPanicInternalError));
1.193 + aConfigStr.Copy(buf);
1.194 + }
1.195 +
1.196 +//Parses the config string parameter (aConfigStr) and stores the extracted configuration parameter values in the aConfigParams argument.
1.197 +//The config string format is: "PARAM1=VALUE1;PARAM2=VALUE2;..."
1.198 +//If there is unknown parameter name in the config string, it will be skipped - not reported as an error.
1.199 +//The function will leave with KErrArgument in a case of a bad config string (bad parameter values).
1.200 +void TSqlSrvConfig::ExtractConfigParamsFromStringL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams)
1.201 + {
1.202 + //Search iteratively the config string for "PARAM=VALUE;" pairs. If such pair is found, extract the parameter name and
1.203 + //parameter value. Adjust the string start ptr to point to the rest of the string.
1.204 + for(TPtrC8 ptr(aConfigStr);ptr.Length()>0;)
1.205 + {
1.206 + TPtrC8 prmName(KNullDesC8);
1.207 + TPtrC8 prmValue(KNullDesC8);
1.208 + if(TSqlSrvConfig::ExtractParamValuePairL(ptr, prmName, prmValue))
1.209 + {
1.210 + TSqlSrvConfig::ExtractParamValueL(prmName, prmValue, aConfigParams);
1.211 + }
1.212 + }
1.213 + //Assert the extracted parameter values.
1.214 + __ASSERT_DEBUG(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, __SQLPANIC2(ESqlPanicInternalError));
1.215 + __ASSERT_DEBUG(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, __SQLPANIC2(ESqlPanicInternalError));
1.216 + __ASSERT_DEBUG(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet ||
1.217 + aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf8 ||
1.218 + aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf16, __SQLPANIC2(ESqlPanicInternalError));
1.219 + __ASSERT_DEBUG(aConfigParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet ||
1.220 + (aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb &&
1.221 + aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb), __SQLPANIC2(ESqlPanicInternalError));
1.222 + __ASSERT_DEBUG(aConfigParams.iCompactionMode == ESqlCompactionNotSet || aConfigParams.iCompactionMode == ESqlCompactionManual ||
1.223 + aConfigParams.iCompactionMode == ESqlCompactionBackground || aConfigParams.iCompactionMode == ESqlCompactionAuto, __SQLPANIC2(ESqlPanicInternalError));
1.224 + __ASSERT_DEBUG(aConfigParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet ||
1.225 + aConfigParams.iFreePageThresholdKb >= 0, __SQLPANIC2(ESqlPanicInternalError));
1.226 + }
1.227 +
1.228 +//The function searches aConfigStr arguments for "PARAM=VALUE;" pair. If such pair is found, then
1.229 +//aParamName is set to point to the parameter name, aParamValue is set to point to the parameter value,
1.230 +//aConfigStr is set to point to the rest of the config string (skipping the just found "param=value;" pair).
1.231 +//The function leaves with KErrArgument in case of a bad config string.
1.232 +//The function returns false if a ";" string is found instead of a "param=value;" pair.
1.233 +//When the function returns true, it means that aParamName and aParamValue arguments are set to point to the
1.234 +//parameter name and parameter value.
1.235 +TBool TSqlSrvConfig::ExtractParamValuePairL(TPtrC8& aConfigStr, TPtrC8& aParamName, TPtrC8& aParamValue)
1.236 + {
1.237 + const TChar KSemiColon(';');
1.238 + const TChar KAssignment('=');
1.239 + TInt pos = aConfigStr.Locate(KSemiColon);
1.240 + TPtrC8 prmText(KNullDesC8);
1.241 + if(pos < 0)
1.242 + {
1.243 + pos = aConfigStr.Length() - 1;
1.244 + prmText.Set(TSqlSrvConfig::TrimAndConstructPtr(aConfigStr.Ptr(), aConfigStr.Length()));
1.245 + }
1.246 + else
1.247 + {
1.248 + prmText.Set(TSqlSrvConfig::TrimAndConstructPtr(aConfigStr.Ptr(), pos));
1.249 + }
1.250 + //Set aConfigStr to the "point" right after the last found ';'
1.251 + if(pos == aConfigStr.Length() - 1)
1.252 + {
1.253 + aConfigStr.Set(NULL, 0);
1.254 + }
1.255 + else
1.256 + {
1.257 + aConfigStr.Set(aConfigStr.Ptr() + pos + 1, aConfigStr.Length() - (pos + 1));
1.258 + }
1.259 + if(prmText.Length() == 0)
1.260 + {//Empty ";"
1.261 + return EFalse;
1.262 + }
1.263 + //Find the parameter name and parameter value
1.264 + pos = prmText.Locate(KAssignment);
1.265 + if(pos < 0 || pos >= (prmText.Length() - 1))
1.266 + {
1.267 + __SQLLEAVE2(KErrArgument);
1.268 + }
1.269 + //we've got now prmText pointing to a " PARAM = VALUE " string.
1.270 + aParamName.Set(TSqlSrvConfig::TrimAndConstructPtr(prmText.Ptr(), pos));
1.271 + aParamValue.Set(TSqlSrvConfig::TrimAndConstructPtr(prmText.Ptr() + pos + 1, prmText.Length() - (pos + 1)));
1.272 + return ETrue;
1.273 + }
1.274 +
1.275 +//The function compares aParamName argument against a set of predefined parameter names and if one of them is matched,
1.276 +//then the function converts aParamValue argument to a numerical value and assigns it to the corresponding aConfigParams data member.
1.277 +//The function may leave with KErrArgument, if the parameter value is invalid.
1.278 +void TSqlSrvConfig::ExtractParamValueL(const TDesC8& aParamName, const TDesC8& aParamValue, TSqlSrvConfigParams& aConfigParams)
1.279 + {
1.280 + if(aParamName.CompareF(KCacheSize) == 0)
1.281 + {
1.282 + aConfigParams.iCacheSize = TSqlSrvConfig::GetCacheSizeL(aParamValue);
1.283 + }
1.284 + else if(aParamName.CompareF(KPageSize) == 0)
1.285 + {
1.286 + aConfigParams.iPageSize = TSqlSrvConfig::GetPageSizeL(aParamValue);
1.287 + }
1.288 + else if(aParamName.CompareF(KEncoding) == 0)
1.289 + {
1.290 + aConfigParams.iDbEncoding = TSqlSrvConfig::GetEncoding(aParamValue);
1.291 + }
1.292 + else if(aParamName.CompareF(KSoftHeapLimitKb) == 0)
1.293 + {
1.294 + aConfigParams.iSoftHeapLimitKb = TSqlSrvConfig::GetSoftHeapLimitL(aParamValue);
1.295 + }
1.296 + else if(aParamName.CompareF(KCompactionMode) == 0)
1.297 + {
1.298 + aConfigParams.iCompactionMode = TSqlSrvConfig::GetCompactionModeL(aParamValue);
1.299 + }
1.300 + else if(aParamName.CompareF(KFreePageThresholdKb) == 0)
1.301 + {
1.302 + aConfigParams.iFreePageThresholdKb = TSqlSrvConfig::GetFreePageThresholdL(aParamValue);
1.303 + }
1.304 + //else
1.305 + // {
1.306 + // Unrecognized parameter/value pair - no problem, skip it.
1.307 + // }
1.308 + }
1.309 +
1.310 +//The function converts aParamValue to a numerical value (the cache size in pages) and returns it.
1.311 +//If the converted numerical value is less than 0, the function leaves with KErrArgument.
1.312 +TInt TSqlSrvConfig::GetCacheSizeL(const TDesC8& aParamValue)
1.313 + {
1.314 + TLex8 lex(aParamValue);
1.315 + TInt cacheSize = TSqlSrvConfigParams::KConfigPrmValueNotSet;
1.316 + TInt err = lex.Val(cacheSize);
1.317 + if(err != KErrNone || cacheSize < 0) //The correct check is for "<=0", but it has to be backward
1.318 + { //compatible with the previous implementation
1.319 + __SQLLEAVE2(KErrArgument);
1.320 + }
1.321 + return cacheSize;
1.322 + }
1.323 +
1.324 +//The function converts aParamValue to a numerical value (the page size in bytes) and returns it.
1.325 +//If the converted numerical value is less than 0, the function leaves with KErrArgument.
1.326 +TInt TSqlSrvConfig::GetPageSizeL(const TDesC8& aParamValue)
1.327 + {
1.328 + TLex8 lex(aParamValue);
1.329 + TInt pageSize = TSqlSrvConfigParams::KConfigPrmValueNotSet;
1.330 + TInt err = lex.Val(pageSize);
1.331 + if(err != KErrNone || pageSize < 0) //The correct check is for "<0", "power of 2", "between 512 and 32768",
1.332 + { //but it has to be backward compatible with the previous implementation
1.333 + __SQLLEAVE2(KErrArgument);
1.334 + }
1.335 + return pageSize;
1.336 + }
1.337 +
1.338 +//The function converts aParamValue to a numerical value (the database encoding) and returns it.
1.339 +TSqlSrvConfigParams::TDbEncoding TSqlSrvConfig::GetEncoding(const TDesC8& aParamValue)
1.340 + {
1.341 + TSqlSrvConfigParams::TDbEncoding encoding = TSqlSrvConfigParams::EEncNotSet;
1.342 + if(aParamValue.CompareF(KUTF8) == 0 || aParamValue.CompareF(KUTF8Q) == 0)
1.343 + {
1.344 + encoding = TSqlSrvConfigParams::EEncUtf8;
1.345 + }
1.346 + else if(aParamValue.CompareF(KUTF16) == 0 || aParamValue.CompareF(KUTF16Q) == 0)
1.347 + {
1.348 + encoding = TSqlSrvConfigParams::EEncUtf16;
1.349 + }
1.350 + //else
1.351 + // {
1.352 + // Invalid encoding - bypass it in order to be compatible with the previous implementation
1.353 + // }
1.354 + return encoding;
1.355 + }
1.356 +
1.357 +//The function converts aParamValue to a numerical value (the soft heap limit in Kb) and returns it.
1.358 +TInt TSqlSrvConfig::GetSoftHeapLimitL(const TDesC8& aParamValue)
1.359 + {
1.360 + TLex8 lex(aParamValue);
1.361 + TInt softHeapLimitKb = TSqlSrvConfigParams::KConfigPrmValueNotSet;
1.362 + TInt err = lex.Val(softHeapLimitKb);
1.363 + if(err != KErrNone || softHeapLimitKb < 0 ||
1.364 + (softHeapLimitKb < TSqlSrvConfigParams::KMinSoftHeapLimitKb || softHeapLimitKb > TSqlSrvConfigParams::KMaxSoftHeapLimitKb))
1.365 + {
1.366 + __SQLLEAVE2(KErrArgument);
1.367 + }
1.368 + return softHeapLimitKb;
1.369 + }
1.370 +
1.371 +//The function converts aParamValue to a numerical value (the database compaction mode) and returns it.
1.372 +TSqlCompactionMode TSqlSrvConfig::GetCompactionModeL(const TDesC8& aParamValue)
1.373 + {
1.374 + TSqlCompactionMode compactionMode = ESqlCompactionNotSet;
1.375 + if(aParamValue.CompareF(KManual) == 0)
1.376 + {
1.377 + compactionMode = ESqlCompactionManual;
1.378 + }
1.379 + else if(aParamValue.CompareF(KBackground) == 0)
1.380 + {
1.381 + compactionMode = ESqlCompactionBackground;
1.382 + }
1.383 + else if(aParamValue.CompareF(KAuto) == 0 || aParamValue.CompareF(KSynchronous) == 0)
1.384 + {
1.385 + compactionMode = ESqlCompactionAuto;
1.386 + }
1.387 + //else
1.388 + // {
1.389 + // Invalid compaction mode
1.390 + // }
1.391 + return compactionMode;
1.392 + }
1.393 +
1.394 +//The function converts aParamValue to a numerical value (the free page threshold in pages) and returns it.
1.395 +TInt TSqlSrvConfig::GetFreePageThresholdL(const TDesC8& aParamValue)
1.396 + {
1.397 + TLex8 lex(aParamValue);
1.398 + TInt freePageThreshold = 0;
1.399 + TInt err = lex.Val(freePageThreshold);
1.400 + if(err != KErrNone || freePageThreshold < 0)
1.401 + {
1.402 + __SQLLEAVE2(KErrArgument);
1.403 + }
1.404 + return freePageThreshold;
1.405 + }
1.406 +
1.407 +
1.408 +//The function searches aStr for leading and trailing whitespace
1.409 +//characters, then creates and returns TPtrC object which points to the
1.410 +//aStr content without leading and trailing whitespace characters.
1.411 +TPtrC8 TSqlSrvConfig::TrimAndConstructPtr(const TUint8* aStr, TInt aLength)
1.412 + {
1.413 + __ASSERT_DEBUG(aStr != NULL, __SQLPANIC2(ESqlPanicBadArgument));
1.414 + __ASSERT_DEBUG(aLength >= 0, __SQLPANIC2(ESqlPanicBadArgument));
1.415 + //Trim left
1.416 + for(;aLength>0;--aLength,++aStr)
1.417 + {
1.418 + if(!TChar(*aStr).IsSpace())
1.419 + {
1.420 + break;
1.421 + }
1.422 + }
1.423 + //Trim right
1.424 + for(const TUint8* p=aStr+aLength-1;aLength>0;--aLength,--p)
1.425 + {
1.426 + if(!TChar(*p).IsSpace())
1.427 + {
1.428 + break;
1.429 + }
1.430 + }
1.431 + return TPtrC8(aStr, aLength);
1.432 + }
1.433 +
1.434 +//////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.435 +
1.436 +CDbConfigFiles* CDbConfigFiles::NewL(const CDir& aDirEntries)
1.437 + {
1.438 + CDbConfigFiles* self = new(ELeave) CDbConfigFiles();
1.439 + CleanupStack::PushL(self);
1.440 + self->ConstructL(aDirEntries);
1.441 + CleanupStack::Pop();
1.442 + return self;
1.443 + }
1.444 +
1.445 +CDbConfigFiles::CDbConfigFiles()
1.446 + {
1.447 + }
1.448 +
1.449 +void CDbConfigFiles::ConstructL(const CDir& aDirEntries)
1.450 + {
1.451 + StoreFileNamesL(aDirEntries);
1.452 + }
1.453 +
1.454 +CDbConfigFiles::~CDbConfigFiles()
1.455 + {
1.456 + iConfigFileNames.ResetAndDestroy();
1.457 + }
1.458 +
1.459 +//Stores the names of the given database configuration files.
1.460 +//These files were found in the server's private data cage on
1.461 +//the Z: drive and begin with the prefix 'cfg'
1.462 +void CDbConfigFiles::StoreFileNamesL(const CDir& aDirEntries)
1.463 + {
1.464 + //Store the file names in reverse alphabetical order so that
1.465 + //in FindConfigFile() if there is more than one version of the same
1.466 + //config file (which there shouldn't be) then the highest version
1.467 + //will be returned
1.468 + for(TInt i = aDirEntries.Count() - 1; i >= 0; --i)
1.469 + {
1.470 + const TEntry& entry = aDirEntries[i];
1.471 + if(!entry.IsDir())
1.472 + {
1.473 + HBufC* filename = entry.iName.AllocLC();
1.474 + iConfigFileNames.AppendL(filename);
1.475 + CleanupStack::Pop(); // filename
1.476 + }
1.477 + }
1.478 + }
1.479 +
1.480 +//Finds the configuration file corresponding to the given database, if one exists.
1.481 +//The database filename including the extension is passed as a parameter - for example,
1.482 +//[12345678]a.db. Note that if more than one version of a configuration file exists
1.483 +//for the given database (which shouldn't happen) - for example, cfg[12345678]a.db.01
1.484 +//and cfg[12345678]a.db.02 - then the highest version will be returned
1.485 +HBufC* CDbConfigFiles::FindConfigFile(const TDesC& aDbFilename) const
1.486 + {
1.487 + TInt count = iConfigFileNames.Count();
1.488 + for(TInt i = 0; i < count; ++i)
1.489 + {
1.490 + TInt offset = iConfigFileNames[i]->Des().FindF(aDbFilename);
1.491 + if(KErrNotFound != offset)
1.492 + {
1.493 + return iConfigFileNames[i];
1.494 + }
1.495 + }
1.496 + return NULL;
1.497 + }