20 #include "SqlSrvStatement.h" |
20 #include "SqlSrvStatement.h" |
21 #include "SqlUtil.h" //Panic codes, Sql2OsErrCode() |
21 #include "SqlUtil.h" //Panic codes, Sql2OsErrCode() |
22 #include "SqlSrvUtil.h" //Global server functions |
22 #include "SqlSrvUtil.h" //Global server functions |
23 #include "SqlCompact.h" |
23 #include "SqlCompact.h" |
24 #include "SqlSrvResourceProfiler.h" |
24 #include "SqlSrvResourceProfiler.h" |
|
25 #include "OstTraceDefinitions.h" |
|
26 #ifdef OST_TRACE_COMPILER_IN_USE |
|
27 #include "SqlSrvDatabaseTraces.h" |
|
28 #endif |
|
29 #include "SqlTraceDef.h" |
25 |
30 |
26 // |
31 // |
27 // The following macro disables the creation/loading of the settings table. |
32 // The following macro disables the creation/loading of the settings table. |
28 // It is for internal testing purposes only! |
33 // It is for internal testing purposes only! |
29 // |
34 // |
64 _LIT(KCacheSizePragma, "PRAGMA \"%S\".cache_size=%d\x0"); |
69 _LIT(KCacheSizePragma, "PRAGMA \"%S\".cache_size=%d\x0"); |
65 _LIT(KPageSizePragma, "PRAGMA \"%S\".page_size=%d\x0"); |
70 _LIT(KPageSizePragma, "PRAGMA \"%S\".page_size=%d\x0"); |
66 _LIT(KAutoVacuumPragma, "PRAGMA \"%S\".auto_vacuum=%d\x0"); |
71 _LIT(KAutoVacuumPragma, "PRAGMA \"%S\".auto_vacuum=%d\x0"); |
67 //_LIT(KPersist, "persist"); |
72 //_LIT(KPersist, "persist"); |
68 //_LIT(KPersistentJournalPragma, "PRAGMA \"%S\".journal_mode=%S\x0"); |
73 //_LIT(KPersistentJournalPragma, "PRAGMA \"%S\".journal_mode=%S\x0"); |
|
74 _LIT(KJournalSizeLimitPragma, "PRAGMA \"%S\".journal_size_limit=%d\x0"); |
69 //////////////////////////////////////////////////////// |
75 //////////////////////////////////////////////////////// |
70 //"LIKE" - user defined function name |
76 //"LIKE" - user defined function name |
71 _LIT8(KStrLikeFuncName, "LIKE\x0"); |
77 _LIT8(KStrLikeFuncName, "LIKE\x0"); |
72 |
78 |
73 /////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
79 /////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
83 // |
89 // |
84 //The function will panic with panic code 7 in _DEBUG mode if iKey member of aLeft or |
90 //The function will panic with panic code 7 in _DEBUG mode if iKey member of aLeft or |
85 //aRight argument is NULL. |
91 //aRight argument is NULL. |
86 static TInt Compare(const TSqlAttachDbPair& aLeft, const TSqlAttachDbPair& aRight) |
92 static TInt Compare(const TSqlAttachDbPair& aLeft, const TSqlAttachDbPair& aRight) |
87 { |
93 { |
88 __SQLASSERT(aLeft.iKey != NULL && aRight.iKey != NULL, ESqlPanicInternalError); |
94 __ASSERT_DEBUG(aLeft.iKey != NULL && aRight.iKey != NULL, __SQLPANIC2(ESqlPanicInternalError)); |
89 return ::CompareNoCase8(TPtrC8(aLeft.iKey), TPtrC8(aRight.iKey)); |
95 return ::CompareNoCase8(TPtrC8(aLeft.iKey), TPtrC8(aRight.iKey)); |
90 } |
96 } |
91 |
97 |
92 //Local function, used for comparing TSqlCompactDbPair objects. |
98 //Local function, used for comparing TSqlCompactDbPair objects. |
93 //(TSqlCompactDbPair structure represents type of the objects, members |
99 //(TSqlCompactDbPair structure represents type of the objects, members |
98 // |
104 // |
99 //The function will panic with panic code 7 in _DEBUG mode if iKey member of aLeft or |
105 //The function will panic with panic code 7 in _DEBUG mode if iKey member of aLeft or |
100 //aRight argument is NULL. |
106 //aRight argument is NULL. |
101 static TInt Compare2(const TSqlCompactDbPair& aLeft, const TSqlCompactDbPair& aRight) |
107 static TInt Compare2(const TSqlCompactDbPair& aLeft, const TSqlCompactDbPair& aRight) |
102 { |
108 { |
103 __SQLASSERT(aLeft.iKey != NULL && aRight.iKey != NULL, ESqlPanicInternalError); |
109 __ASSERT_DEBUG(aLeft.iKey != NULL && aRight.iKey != NULL, __SQLPANIC2(ESqlPanicInternalError)); |
104 return ::CompareNoCase(*aLeft.iKey, *aRight.iKey); |
110 return ::CompareNoCase(*aLeft.iKey, *aRight.iKey); |
105 } |
111 } |
106 |
112 |
107 //Creates/opens database file (database file name in aFileData parameter) and initializes aDbHandle parameter. |
113 //Creates/opens database file (database file name in aFileData parameter) and initializes aDbHandle parameter. |
108 //The database will be created either with UTF-16 or UTF-8 encoding, depending on the |
114 //The database will be created either with UTF-16 or UTF-8 encoding, depending on the |
112 if(aFileData.ConfigParams().iDbEncoding == TSqlSrvConfigParams::EEncUtf8) |
118 if(aFileData.ConfigParams().iDbEncoding == TSqlSrvConfigParams::EEncUtf8) |
113 { |
119 { |
114 TBuf8<KMaxFileName + 1> fileNameZ; |
120 TBuf8<KMaxFileName + 1> fileNameZ; |
115 if(!::UTF16ZToUTF8Z(aFileData.FileNameZ(), fileNameZ)) |
121 if(!::UTF16ZToUTF8Z(aFileData.FileNameZ(), fileNameZ)) |
116 { |
122 { |
117 __SQLLEAVE(KErrGeneral); |
123 __SQLLEAVE2(KErrGeneral); |
118 } |
124 } |
119 __SQLLEAVE_IF_ERROR(::CreateDbHandle8(fileNameZ, aDbHandle)); |
125 __SQLLEAVE_IF_ERROR2(::CreateDbHandle8(fileNameZ, aDbHandle)); |
120 } |
126 } |
121 else |
127 else |
122 { |
128 { |
123 __SQLLEAVE_IF_ERROR(::CreateDbHandle16(aFileData.FileNameZ(), aDbHandle)); |
129 __SQLLEAVE_IF_ERROR2(::CreateDbHandle16(aFileData.FileNameZ(), aDbHandle)); |
124 } |
130 } |
125 } |
131 } |
126 |
132 |
127 //LoadAttachedDbSecurityPolicyLC() creates a new CSqlSecurityPolicy object and initializes it with the |
133 //LoadAttachedDbSecurityPolicyLC() creates a new CSqlSecurityPolicy object and initializes it with the |
128 //security policies read from the attached database file, which name is in aFileData parameter. |
134 //security policies read from the attached database file, which name is in aFileData parameter. |
150 //The created database security policy object is placed in the cleanup stack. |
156 //The created database security policy object is placed in the cleanup stack. |
151 //The caller is responsible for destroying the returned database security policy object. |
157 //The caller is responsible for destroying the returned database security policy object. |
152 //The function is used to read the security policy of the main database. |
158 //The function is used to read the security policy of the main database. |
153 static CSqlSecurityPolicy* LoadDbSecurityPolicyLC(sqlite3* aDbHandle) |
159 static CSqlSecurityPolicy* LoadDbSecurityPolicyLC(sqlite3* aDbHandle) |
154 { |
160 { |
155 __SQLASSERT(aDbHandle != NULL, ESqlPanicBadArgument); |
161 __ASSERT_DEBUG(aDbHandle != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
156 //Create new database security policy object and initialize it with a default security policy |
162 //Create new database security policy object and initialize it with a default security policy |
157 TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysFail); |
163 TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysFail); |
158 CSqlSecurityPolicy* dbPolicy = CSqlSecurityPolicy::NewLC(defaultPolicy); |
164 CSqlSecurityPolicy* dbPolicy = CSqlSecurityPolicy::NewLC(defaultPolicy); |
159 //Read the security policies. |
165 //Read the security policies. |
160 TSqlDbSysSettings dbSysSettings(aDbHandle); |
166 TSqlDbSysSettings dbSysSettings(aDbHandle); |
165 //CreateStrCopyLC() makes a copy of aSrc string and places it in the cleanup stack. |
171 //CreateStrCopyLC() makes a copy of aSrc string and places it in the cleanup stack. |
166 //aSrc is expected to be UTF8 encoded, zero terminated string. |
172 //aSrc is expected to be UTF8 encoded, zero terminated string. |
167 //The function panics in _DEBUG mode if aSrc is NULL. |
173 //The function panics in _DEBUG mode if aSrc is NULL. |
168 static TUint8* CreateStrCopyLC(const TUint8* aSrc) |
174 static TUint8* CreateStrCopyLC(const TUint8* aSrc) |
169 { |
175 { |
170 __SQLASSERT(aSrc != NULL, ESqlPanicBadArgument); |
176 __ASSERT_DEBUG(aSrc != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
171 TInt len = User::StringLength(aSrc) + 1; |
177 TInt len = User::StringLength(aSrc) + 1; |
172 TUint8* copy = new (ELeave) TUint8[len]; |
178 TUint8* copy = new (ELeave) TUint8[len]; |
173 Mem::Copy(copy, aSrc, len); |
179 Mem::Copy(copy, aSrc, len); |
174 CleanupStack::PushL(copy); |
180 CleanupStack::PushL(copy); |
175 return copy; |
181 return copy; |
177 |
183 |
178 //EnableAuthorizer() function is used to reenable the authorizer callback |
184 //EnableAuthorizer() function is used to reenable the authorizer callback |
179 //during the stack cleanup. |
185 //during the stack cleanup. |
180 static void EnableAuthorizer(void* aAuthorizerDisabled) |
186 static void EnableAuthorizer(void* aAuthorizerDisabled) |
181 { |
187 { |
182 __SQLASSERT(aAuthorizerDisabled != NULL, ESqlPanicBadArgument); |
188 __ASSERT_DEBUG(aAuthorizerDisabled != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
183 TBool* authorizerDisabled = static_cast <TBool*> (aAuthorizerDisabled); |
189 TBool* authorizerDisabled = static_cast <TBool*> (aAuthorizerDisabled); |
184 *authorizerDisabled = EFalse; |
190 *authorizerDisabled = EFalse; |
185 } |
191 } |
186 |
192 |
187 //Used by DbFileCleanup() |
193 //Used by DbFileCleanup() |
206 |
212 |
207 //DbFileCleanup() is used to close and delete the database file during the stack cleanup, if |
213 //DbFileCleanup() is used to close and delete the database file during the stack cleanup, if |
208 //CSqlSrvDatabase's ConstructL() method(s) leave (when creating a new database file). |
214 //CSqlSrvDatabase's ConstructL() method(s) leave (when creating a new database file). |
209 static void DbFileCleanup(void* aDbFileCleanup) |
215 static void DbFileCleanup(void* aDbFileCleanup) |
210 { |
216 { |
211 __SQLASSERT(aDbFileCleanup != NULL, ESqlPanicBadArgument); |
217 __ASSERT_DEBUG(aDbFileCleanup != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
212 TDbFileCleanup* dbFileCleanup = static_cast <TDbFileCleanup*> (aDbFileCleanup); |
218 TDbFileCleanup* dbFileCleanup = static_cast <TDbFileCleanup*> (aDbFileCleanup); |
213 dbFileCleanup->Cleanup(); |
219 dbFileCleanup->Cleanup(); |
214 } |
220 } |
215 |
221 |
216 //Executes "PRAGMA" SQL statement + INTEGER value. |
222 //Executes "PRAGMA" SQL statement + INTEGER value. |
220 // aDbName - "main" or the attached database name |
226 // aDbName - "main" or the attached database name |
221 //This function is used for setting "cache_size", "page_size", "auto_vacuum" pragmas. |
227 //This function is used for setting "cache_size", "page_size", "auto_vacuum" pragmas. |
222 //During the call the authorizer will be disabled. |
228 //During the call the authorizer will be disabled. |
223 static TInt ExecPragma(sqlite3* aDbHandle, TBool& aAuthorizerDisabled, const TDesC& aPragma, TInt aValue, const TDesC& aDbName = KMainDb16) |
229 static TInt ExecPragma(sqlite3* aDbHandle, TBool& aAuthorizerDisabled, const TDesC& aPragma, TInt aValue, const TDesC& aDbName = KMainDb16) |
224 { |
230 { |
225 __SQLASSERT(aDbHandle != NULL, ESqlPanicBadArgument); |
231 __SQLTRACE_INTERNALSEXPR(TPtrC pragmaprnptr(aPragma.Left(aPragma.Length() - 1))); |
|
232 SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, EXECPRAGMA_ENTRY, "Entry;0;ExecPragma;sqlite3*=0x%X;aPragma=%S;aValue=%d;aDbName=%S", (TUint)aDbHandle, __SQLPRNSTR(pragmaprnptr), aValue, __SQLPRNSTR(aDbName))); |
|
233 __ASSERT_DEBUG(aDbHandle != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
226 TBuf<KMaxFileName + 64> pragmaSql;//(KMaxFileName + 64) characters buffer length is enough for the longest possible PRAGMA statement |
234 TBuf<KMaxFileName + 64> pragmaSql;//(KMaxFileName + 64) characters buffer length is enough for the longest possible PRAGMA statement |
227 pragmaSql.Format(aPragma, &aDbName, aValue); |
235 pragmaSql.Format(aPragma, &aDbName, aValue); |
228 TBool authorizerDisabledState = aAuthorizerDisabled; |
236 TBool authorizerDisabledState = aAuthorizerDisabled; |
229 aAuthorizerDisabled = ETrue; |
237 aAuthorizerDisabled = ETrue; |
230 TInt err = DbExecStmt16(aDbHandle, pragmaSql); |
238 TInt err = DbExecStmt16(aDbHandle, pragmaSql); |
231 aAuthorizerDisabled = authorizerDisabledState; |
239 aAuthorizerDisabled = authorizerDisabledState; |
|
240 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, EXECPRAGMA_EXIT, "Exit;0;ExecPragma;sqlite3*=0x%X;err=%d", (TUint)aDbHandle, err)); |
232 return err; |
241 return err; |
|
242 } |
|
243 |
|
244 //The journal size limit is set to be at lest 16 pages and no less than 64 Kb. |
|
245 static void SetJournalSizeLimitL(sqlite3* aDbHandle, TBool& aAuthorizerDisabled, TInt aPageSize, const TDesC& aDbName = KMainDb16) |
|
246 { |
|
247 __ASSERT_DEBUG(aDbHandle != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
|
248 if(aPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
|
249 { |
|
250 __SQLLEAVE_IF_ERROR2(DbPageSize(aDbHandle, aDbName, aPageSize)); |
|
251 } |
|
252 const TInt KPageMultiplier = 16; |
|
253 const TInt KDefaultJournalSizeLimit = 64 * 1024; |
|
254 const TInt KMaxJournalSizeLimit = 512 * 1024; |
|
255 const TInt KJournalSizeLimit = Min((aPageSize * KPageMultiplier), KMaxJournalSizeLimit); |
|
256 if(KJournalSizeLimit > KDefaultJournalSizeLimit) |
|
257 { |
|
258 __SQLLEAVE_IF_ERROR2(::ExecPragma(aDbHandle, aAuthorizerDisabled, KJournalSizeLimitPragma, KJournalSizeLimit)); |
|
259 } |
233 } |
260 } |
234 |
261 |
235 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
262 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
236 ///////////////////////////// CSqlSrvDatabase class ///////////////////////////////////////////// |
263 ///////////////////////////// CSqlSrvDatabase class ///////////////////////////////////////////// |
237 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
264 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
272 @panic SqlDb 4 In _DEBUG mode if aFileData does not refer to a secure database file name. |
299 @panic SqlDb 4 In _DEBUG mode if aFileData does not refer to a secure database file name. |
273 @panic SqlDb 4 In _DEBUG mode if aSecurityPolicy is NULL. |
300 @panic SqlDb 4 In _DEBUG mode if aSecurityPolicy is NULL. |
274 */ |
301 */ |
275 CSqlSrvDatabase* CSqlSrvDatabase::CreateSecureL(const TSqlSrvFileData& aFileData, CSqlSecurityPolicy* aSecurityPolicy) |
302 CSqlSrvDatabase* CSqlSrvDatabase::CreateSecureL(const TSqlSrvFileData& aFileData, CSqlSecurityPolicy* aSecurityPolicy) |
276 { |
303 { |
277 __SQLASSERT(aFileData.IsSecureFileNameFmt(), ESqlPanicBadArgument); |
304 SQL_TRACE_INTERNALS(OstTrace0(TRACE_INTERNALS, CSQLSRVDATABASE_CREATESECUREL_ENTRY, "Entry;0;CSqlSrvDatabase::CreateSecureL")); |
278 __SQLASSERT(aSecurityPolicy != NULL, ESqlPanicBadArgument); |
305 __ASSERT_DEBUG(aFileData.IsSecureFileNameFmt(), __SQLPANIC2(ESqlPanicBadArgument)); |
|
306 __ASSERT_DEBUG(aSecurityPolicy != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
279 if(!::SqlServer().SecurityInspector().Check(aSecurityPolicy->DbPolicy(RSqlSecurityPolicy::ESchemaPolicy))) |
307 if(!::SqlServer().SecurityInspector().Check(aSecurityPolicy->DbPolicy(RSqlSecurityPolicy::ESchemaPolicy))) |
280 { |
308 { |
281 //The caller has no "SCHEMA" policy. Then the client is not given a permission to create the database. |
309 //The caller has no "SCHEMA" policy. Then the client is not given a permission to create the database. |
282 //Delete aSecurityPolicy since no database object is going to be created and the security policy object |
310 //Delete aSecurityPolicy since no database object is going to be created and the security policy object |
283 //won't be put in the security policies map. |
311 //won't be put in the security policies map. |
284 delete aSecurityPolicy; |
312 delete aSecurityPolicy; |
285 __SQLLEAVE(KErrPermissionDenied); |
313 __SQLLEAVE2(KErrPermissionDenied); |
286 } |
314 } |
287 //What does happen with aSecurityPolicy instance? |
315 //What does happen with aSecurityPolicy instance? |
288 // If the database is created successfully, then a lookup will be made in the security policies map. |
316 // If the database is created successfully, then a lookup will be made in the security policies map. |
289 // (the security policies map contains reference counted security policies) |
317 // (the security policies map contains reference counted security policies) |
290 // If the same security policy already exists in the map, then aSecurityPolicy will be deleted. |
318 // If the same security policy already exists in the map, then aSecurityPolicy will be deleted. |
303 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
331 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
304 CleanupStack::Pop(aSecurityPolicy); |
332 CleanupStack::Pop(aSecurityPolicy); |
305 CleanupStack::PushL(self); |
333 CleanupStack::PushL(self); |
306 self->ConstructCreateSecureL(aFileData, aSecurityPolicy); |
334 self->ConstructCreateSecureL(aFileData, aSecurityPolicy); |
307 CleanupStack::Pop(self); |
335 CleanupStack::Pop(self); |
|
336 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_CREATESECUREL_EXIT, "Exit;0x%X;CSqlSrvDatabase::CreateSecureL;sqlite3*=0x%X", (TUint)self, (TUint)self->iDbHandle)); |
308 return self; |
337 return self; |
309 } |
338 } |
310 |
339 |
311 /** |
340 /** |
312 Creates new CSqlSrvDatabase instance which creates and manages new SQL database. |
341 Creates new CSqlSrvDatabase instance which creates and manages new SQL database. |
333 |
362 |
334 @panic SqlDb 4 In _DEBUG mode if aFileData refers to a secure database file name. |
363 @panic SqlDb 4 In _DEBUG mode if aFileData refers to a secure database file name. |
335 */ |
364 */ |
336 CSqlSrvDatabase* CSqlSrvDatabase::CreateL(const TSqlSrvFileData& aFileData) |
365 CSqlSrvDatabase* CSqlSrvDatabase::CreateL(const TSqlSrvFileData& aFileData) |
337 { |
366 { |
338 __SQLASSERT(!aFileData.IsSecureFileNameFmt(), ESqlPanicBadArgument); |
367 SQL_TRACE_INTERNALS(OstTrace0(TRACE_INTERNALS, CSQLSRVDATABASE_CREATEL_ENTRY, "Entry;0;CSqlSrvDatabase::CreateL")); |
|
368 __ASSERT_DEBUG(!aFileData.IsSecureFileNameFmt(), __SQLPANIC2(ESqlPanicBadArgument)); |
339 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
369 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
340 CleanupStack::PushL(self); |
370 CleanupStack::PushL(self); |
341 self->ConstructCreateL(aFileData); |
371 self->ConstructCreateL(aFileData); |
342 CleanupStack::Pop(self); |
372 CleanupStack::Pop(self); |
|
373 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_CREATEL_EXIT, "Exit;0x%X;CSqlSrvDatabase::CreateL;sqlite3*=0x%X", (TUint)self, (TUint)self->iDbHandle)); |
343 return self; |
374 return self; |
344 } |
375 } |
345 |
376 |
346 /** |
377 /** |
347 Creates new CSqlSrvDatabase instance which opens and manages an existing SQL database. |
378 Creates new CSqlSrvDatabase instance which opens and manages an existing SQL database. |
372 @see CSqlSecurityPolicy |
403 @see CSqlSecurityPolicy |
373 @see TSqlSrvFileData::SetFromHandleL() |
404 @see TSqlSrvFileData::SetFromHandleL() |
374 */ |
405 */ |
375 CSqlSrvDatabase* CSqlSrvDatabase::OpenL(const TSqlSrvFileData& aFileData) |
406 CSqlSrvDatabase* CSqlSrvDatabase::OpenL(const TSqlSrvFileData& aFileData) |
376 { |
407 { |
|
408 SQL_TRACE_INTERNALS(OstTrace0(TRACE_INTERNALS, CSQLSRVDATABASE_OPENL_ENTRY, "Entry;0;CSqlSrvDatabase::OpenL")); |
377 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
409 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
378 CleanupStack::PushL(self); |
410 CleanupStack::PushL(self); |
379 aFileData.IsSecureFileNameFmt() ? self->ConstructOpenSecureL(aFileData) : self->ConstructOpenL(aFileData); |
411 aFileData.IsSecureFileNameFmt() ? self->ConstructOpenSecureL(aFileData) : self->ConstructOpenL(aFileData); |
380 CleanupStack::Pop(self); |
412 CleanupStack::Pop(self); |
|
413 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_OPENL_EXIT, "Exit;0x%X;CSqlSrvDatabase::OpenL;sqlite3*=0x%X", (TUint)self, (TUint)self->iDbHandle)); |
381 return self; |
414 return self; |
382 } |
415 } |
383 |
416 |
384 /** |
417 /** |
385 Cleans up the allocated for the database connection memory and other resources. |
418 Cleans up the allocated for the database connection memory and other resources. |
386 */ |
419 */ |
387 CSqlSrvDatabase::~CSqlSrvDatabase() |
420 CSqlSrvDatabase::~CSqlSrvDatabase() |
388 { |
421 { |
389 SQLPROFILER_DB_CLOSE((TUint)iDbHandle); |
422 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_CSQLSRVDATABASE2_ENTRY, "Entry;0x%X;CSqlSrvDatabase::~CSqlSrvDatabase;sqlite3*=0x%X", (TUint)this, (TUint)iDbHandle)); |
390 TSqlCompactDbMapIterator compactDbIt(iCompactDbMap); |
423 TSqlCompactDbMapIterator compactDbIt(iCompactDbMap); |
391 TSqlCompactDbPair compactDbPair; |
424 TSqlCompactDbPair compactDbPair; |
392 while(compactDbIt.Next(compactDbPair)) |
425 while(compactDbIt.Next(compactDbPair)) |
393 { |
426 { |
394 __SQLASSERT(compactDbPair.iData, ESqlPanicInvalidObj); |
427 __ASSERT_DEBUG(compactDbPair.iData, __SQLPANIC2(ESqlPanicInvalidObj)); |
395 ::SqlServer().Compactor().ReleaseEntry(*compactDbPair.iData); |
428 ::SqlServer().Compactor().ReleaseEntry(*compactDbPair.iData); |
396 } |
429 } |
397 iCompactDbMap.Close(); |
430 iCompactDbMap.Close(); |
398 //If iSecureDbName is not NULL, the current CSqlSrvDatabase object operates on a secure database. |
431 //If iSecureDbName is not NULL, the current CSqlSrvDatabase object operates on a secure database. |
399 //The database security policy has to be removed from the security policy map. |
432 //The database security policy has to be removed from the security policy map. |
432 // the code there "expects" that is the first time when a "c:[11111111]b.db" entry is added to iSecurityMap. |
465 // the code there "expects" that is the first time when a "c:[11111111]b.db" entry is added to iSecurityMap. |
433 TSqlAttachDbMapIterator it(iAttachDbMap); |
466 TSqlAttachDbMapIterator it(iAttachDbMap); |
434 TSqlAttachDbPair attachDbPair; |
467 TSqlAttachDbPair attachDbPair; |
435 while(it.Next(attachDbPair)) |
468 while(it.Next(attachDbPair)) |
436 { |
469 { |
437 __SQLASSERT(attachDbPair.iData, ESqlPanicInvalidObj); |
470 __ASSERT_DEBUG(attachDbPair.iData, __SQLPANIC2(ESqlPanicInvalidObj)); |
438 ::SqlServer().SecurityMap().Remove(attachDbPair.iData); |
471 ::SqlServer().SecurityMap().Remove(attachDbPair.iData); |
439 } |
472 } |
440 iAttachDbMap.Close(); |
473 iAttachDbMap.Close(); |
441 ::CloseDbHandle(iDbHandle); |
474 ::CloseDbHandle(iDbHandle); |
|
475 SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSRVDATABASE_CSQLSRVDATABASE2_EXIT, "Exit;0x%X;CSqlSrvDatabase::~CSqlSrvDatabase", (TUint)this)); |
442 } |
476 } |
443 |
477 |
444 /** |
478 /** |
445 Initializes CSqlSrvDatabase data memebers with their default values. |
479 Initializes CSqlSrvDatabase data memebers with their default values. |
446 |
480 |
474 Note that the function may also leave with some other database specific |
508 Note that the function may also leave with some other database specific |
475 errors categorised as ESqlDbError, and other system-wide error codes. |
509 errors categorised as ESqlDbError, and other system-wide error codes. |
476 */ |
510 */ |
477 void CSqlSrvDatabase::CreateNewDbFileL(const TSqlSrvFileData& aFileData) |
511 void CSqlSrvDatabase::CreateNewDbFileL(const TSqlSrvFileData& aFileData) |
478 { |
512 { |
|
513 __SQLTRACE_INTERNALSVAR(TPtrC fname = aFileData.FileName()); |
|
514 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_CREATENEWDBFILEL, "0x%x;CSqlSrvDatabase::CreateNewDbFileL;fname=%S", (TUint)this, __SQLPRNSTR(fname))); |
479 if(::FileExists(aFileData.Fs(), aFileData.FileName())) |
515 if(::FileExists(aFileData.Fs(), aFileData.FileName())) |
480 { |
516 { |
481 __SQLLEAVE(KErrAlreadyExists); |
517 __SQLLEAVE(KErrAlreadyExists); |
482 } |
518 } |
483 TDbFileCleanup dbFileCleanup(aFileData, iDbHandle); |
519 TDbFileCleanup dbFileCleanup(aFileData, iDbHandle); |
509 @see TSqlSrvFileData |
545 @see TSqlSrvFileData |
510 @see TSqlSrvFileData::SetFromHandleL() |
546 @see TSqlSrvFileData::SetFromHandleL() |
511 */ |
547 */ |
512 void CSqlSrvDatabase::OpenExistingDbFileL(const TSqlSrvFileData& aFileData) |
548 void CSqlSrvDatabase::OpenExistingDbFileL(const TSqlSrvFileData& aFileData) |
513 { |
549 { |
|
550 __SQLTRACE_INTERNALSVAR(TPtrC fname = aFileData.FileName()); |
|
551 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_OPENEXISTINGDBFILEL, "0x%x;CSqlSrvDatabase::OpenExistingDbFileL;fname=%S", (TUint)this, __SQLPRNSTR(fname))); |
514 if(!aFileData.ContainHandles()) |
552 if(!aFileData.ContainHandles()) |
515 {//This check is valid only if the database is outside application's private data cage |
553 {//This check is valid only if the database is outside application's private data cage |
516 if(!::FileExists(aFileData.Fs(), aFileData.FileName())) |
554 if(!::FileExists(aFileData.Fs(), aFileData.FileName())) |
517 { |
555 { |
518 __SQLLEAVE(KErrNotFound); |
556 __SQLLEAVE(KErrNotFound); |
633 |
671 |
634 @see TSqlSrvFileData |
672 @see TSqlSrvFileData |
635 */ |
673 */ |
636 void CSqlSrvDatabase::AttachDbL(const TSqlSrvFileData& aFileData, const TDesC& aDbName) |
674 void CSqlSrvDatabase::AttachDbL(const TSqlSrvFileData& aFileData, const TDesC& aDbName) |
637 { |
675 { |
|
676 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_ATTACHDBL_ENTRY, "Entry;0x%X;CSqlSrvDatabase::AttachDbL;aDbName=%S", (TUint)this, __SQLPRNSTR(aDbName))); |
638 if(!aFileData.ContainHandles()) |
677 if(!aFileData.ContainHandles()) |
639 {//This check is valid only if the database is outside application's private data cage |
678 {//This check is valid only if the database is outside application's private data cage |
640 if(!::FileExists(aFileData.Fs(), aFileData.FileName())) |
679 if(!::FileExists(aFileData.Fs(), aFileData.FileName())) |
641 { |
680 { |
642 __SQLLEAVE(KErrNotFound); |
681 __SQLLEAVE(KErrNotFound); |
785 { |
827 { |
786 iAuthorizerDisabled = ETrue; |
828 iAuthorizerDisabled = ETrue; |
787 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
829 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
788 TInt pageCount = 0; |
830 TInt pageCount = 0; |
789 __SQLLEAVE_IF_ERROR(::DbPageCount(iDbHandle, aDbName, pageCount)); |
831 __SQLLEAVE_IF_ERROR(::DbPageCount(iDbHandle, aDbName, pageCount)); |
790 __SQLASSERT(pageCount >= 0, ESqlPanicInternalError); |
832 __ASSERT_DEBUG(pageCount >= 0, __SQLPANIC(ESqlPanicInternalError)); |
791 CleanupStack::PopAndDestroy(); |
833 CleanupStack::PopAndDestroy(); |
792 return (TInt64)pageCount * PageSizeL(aDbName); |
834 return (TInt64)pageCount * PageSizeL(aDbName); |
793 } |
835 } |
794 |
836 |
795 /** |
837 /** |
807 iAuthorizerDisabled = ETrue; |
849 iAuthorizerDisabled = ETrue; |
808 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
850 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
809 TInt freePageCount = 0; |
851 TInt freePageCount = 0; |
810 __SQLLEAVE_IF_ERROR(::DbFreePageCount(iDbHandle, aDbName, freePageCount)); |
852 __SQLLEAVE_IF_ERROR(::DbFreePageCount(iDbHandle, aDbName, freePageCount)); |
811 CleanupStack::PopAndDestroy(); |
853 CleanupStack::PopAndDestroy(); |
812 __SQLASSERT(freePageCount >= 0, ESqlPanicInternalError); |
854 __ASSERT_DEBUG(freePageCount >= 0, __SQLPANIC(ESqlPanicInternalError)); |
813 return (TInt64)freePageCount * PageSizeL(aDbName); |
855 return (TInt64)freePageCount * PageSizeL(aDbName); |
814 } |
856 } |
815 |
857 |
816 /** |
858 /** |
817 Collects information regarding the current cache size, page, size, encoding, etc. and puts the values |
859 Collects information regarding the current cache size, page, size, encoding, etc. and puts the values |
871 @leave The function may leave with some database specific errors categorised as ESqlDbError, |
913 @leave The function may leave with some database specific errors categorised as ESqlDbError, |
872 and other system-wide error codes. |
914 and other system-wide error codes. |
873 */ |
915 */ |
874 TInt CSqlSrvDatabase::CompactL(TInt aSize, const TDesC& aDbName) |
916 TInt CSqlSrvDatabase::CompactL(TInt aSize, const TDesC& aDbName) |
875 { |
917 { |
876 __SQLASSERT(aSize > 0 || aSize == RSqlDatabase::EMaxCompaction, ESqlPanicBadArgument); |
918 SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSRVDATABASE_COMPACTL_ENTRY, "Entry;0x%X;CSqlSrvDatabase::CompactL;aSize=%d;aDbName=%S", (TUint)this, aSize, __SQLPRNSTR(aDbName))); |
|
919 __ASSERT_DEBUG(aSize > 0 || aSize == RSqlDatabase::EMaxCompaction, __SQLPANIC(ESqlPanicBadArgument)); |
877 TInt pageSize = PageSizeL(aDbName);//PageSizeL() will disable/enable the authorizer |
920 TInt pageSize = PageSizeL(aDbName);//PageSizeL() will disable/enable the authorizer |
878 TInt pageCount = KMaxTInt; |
921 TInt pageCount = KMaxTInt; |
879 if(aSize > 0) |
922 if(aSize > 0) |
880 {//64-bit calculations to avoid the overflow in case if (aSize + pageSize) >= KMaxTInt. |
923 {//64-bit calculations to avoid the overflow in case if (aSize + pageSize) >= KMaxTInt. |
881 pageCount = (TInt64)((TInt64)aSize + pageSize - 1) / pageSize; |
924 pageCount = (TInt64)((TInt64)aSize + pageSize - 1) / pageSize; |
885 iAuthorizerDisabled = ETrue; |
928 iAuthorizerDisabled = ETrue; |
886 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
929 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
887 __SQLLEAVE_IF_ERROR(::DbCompact(iDbHandle, aDbName, pageCount, pageCount)); |
930 __SQLLEAVE_IF_ERROR(::DbCompact(iDbHandle, aDbName, pageCount, pageCount)); |
888 CleanupStack::PopAndDestroy(); |
931 CleanupStack::PopAndDestroy(); |
889 } |
932 } |
|
933 SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSRVDATABASE_COMPACTL_EXIT, "Exit;0x%X;CSqlSrvDatabase::CompactL;pageCount=%d;pageSize=%d", (TUint)this, pageCount, pageSize)); |
890 return pageCount * pageSize; |
934 return pageCount * pageSize; |
891 } |
935 } |
892 |
936 |
893 /** |
937 /** |
894 This structure is used in case if the InitAttachedDbL() execution fails and the |
938 This structure is used in case if the InitAttachedDbL() execution fails and the |
1057 } |
1101 } |
1058 else |
1102 else |
1059 { |
1103 { |
1060 //No, it is not in the map. Read the security policies from the security policies tables and |
1104 //No, it is not in the map. Read the security policies from the security policies tables and |
1061 //insert a new item in the map. |
1105 //insert a new item in the map. |
1062 __SQLASSERT(aMapKey != NULL, ESqlPanicInternalError); |
1106 __ASSERT_DEBUG(aMapKey != NULL, __SQLPANIC(ESqlPanicInternalError)); |
1063 aMapKey = ::CreateStrCopyLC(aMapKey); |
1107 aMapKey = ::CreateStrCopyLC(aMapKey); |
1064 CSqlSecurityPolicy* securityPolicy = aAttachedDb ? ::LoadAttachedDbSecurityPolicyLC(aFileData) : |
1108 CSqlSecurityPolicy* securityPolicy = aAttachedDb ? ::LoadAttachedDbSecurityPolicyLC(aFileData) : |
1065 ::LoadDbSecurityPolicyLC(iDbHandle); |
1109 ::LoadDbSecurityPolicyLC(iDbHandle); |
1066 __SQLASSERT(!::SqlServer().SecurityMap().Entry(aMapKey), ESqlPanicObjExists); |
1110 __ASSERT_DEBUG(!::SqlServer().SecurityMap().Entry(aMapKey), __SQLPANIC2(ESqlPanicObjExists)); |
1067 __SQLLEAVE_IF_ERROR(::SqlServer().SecurityMap().Insert(aMapKey, securityPolicy)); |
1111 __SQLLEAVE_IF_ERROR(::SqlServer().SecurityMap().Insert(aMapKey, securityPolicy)); |
1068 CleanupStack::Pop(2);//iSecurityMap owns aMapKey and securityPolicy objects |
1112 CleanupStack::Pop(2);//iSecurityMap owns aMapKey and securityPolicy objects |
1069 aSecurityPolicy = securityPolicy; |
1113 aSecurityPolicy = securityPolicy; |
1070 } |
1114 } |
1071 __SQLASSERT(aMapKey != NULL, ESqlPanicInternalError); |
1115 __ASSERT_DEBUG(aMapKey != NULL, __SQLPANIC(ESqlPanicInternalError)); |
1072 __SQLASSERT(aSecurityPolicy != NULL, ESqlPanicInternalError); |
1116 __ASSERT_DEBUG(aSecurityPolicy != NULL, __SQLPANIC(ESqlPanicInternalError)); |
1073 } |
1117 } |
1074 |
1118 |
1075 /** |
1119 /** |
1076 Removes attached secure database entries from the maps. |
1120 Removes attached secure database entries from the maps. |
1077 |
1121 |
1096 @see CSqlServer |
1140 @see CSqlServer |
1097 @see CSqlSrvDatabase |
1141 @see CSqlSrvDatabase |
1098 */ |
1142 */ |
1099 void CSqlSrvDatabase::RemoveFromMapsL(const TDesC& aDbName) |
1143 void CSqlSrvDatabase::RemoveFromMapsL(const TDesC& aDbName) |
1100 { |
1144 { |
|
1145 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_REMOVEFROMMAPSL, "0x%X;CSqlSrvDatabase::RemoveFromMapsL;aDbName=%S", (TUint)this, __SQLPRNSTR(aDbName))); |
1101 TPtr8 ptr(iFileNameBuf, sizeof(iFileNameBuf)); |
1146 TPtr8 ptr(iFileNameBuf, sizeof(iFileNameBuf)); |
1102 if(!::UTF16ToUTF8Z(aDbName, ptr)) |
1147 if(!::UTF16ToUTF8Z(aDbName, ptr)) |
1103 { |
1148 { |
1104 __SQLLEAVE(KErrGeneral); |
1149 __SQLLEAVE(KErrGeneral); |
1105 } |
1150 } |
1126 @see RSqlAttachDbMap |
1171 @see RSqlAttachDbMap |
1127 @see CSqlSrvDatabase |
1172 @see CSqlSrvDatabase |
1128 */ |
1173 */ |
1129 void CSqlSrvDatabase::InsertInAttachDbMapL(const TDesC& aDbFileName, const TDesC& aDbName) |
1174 void CSqlSrvDatabase::InsertInAttachDbMapL(const TDesC& aDbFileName, const TDesC& aDbName) |
1130 { |
1175 { |
|
1176 SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSRVDATABASE_INSERTINATTACHDBMAPL, "0x%X;CSqlSrvDatabase::InsertInAttachDbMapL;aDbFileName=%S;aDbName=%S", (TUint)this, __SQLPRNSTR(aDbFileName), __SQLPRNSTR(aDbName))); |
1131 //Convert aDbName to UTF8, zero-terminated name |
1177 //Convert aDbName to UTF8, zero-terminated name |
1132 TPtr8 ptr(iFileNameBuf, sizeof(iFileNameBuf)); |
1178 TPtr8 ptr(iFileNameBuf, sizeof(iFileNameBuf)); |
1133 if(!::UTF16ToUTF8Z(aDbName, ptr)) |
1179 if(!::UTF16ToUTF8Z(aDbName, ptr)) |
1134 { |
1180 { |
1135 __SQLLEAVE(KErrGeneral); |
1181 __SQLLEAVE(KErrGeneral); |
1136 } |
1182 } |
1137 const TUint8* mapKey = ::CreateStrCopyLC(iFileNameBuf); |
1183 const TUint8* mapKey = ::CreateStrCopyLC(iFileNameBuf); |
1138 const TUint8* mapData = SecurityMapKeyL(aDbFileName); |
1184 const TUint8* mapData = SecurityMapKeyL(aDbFileName); |
1139 mapData = ::CreateStrCopyLC(mapData); |
1185 mapData = ::CreateStrCopyLC(mapData); |
1140 __SQLASSERT(!iAttachDbMap.Entry(mapKey), ESqlPanicObjExists); |
1186 __ASSERT_DEBUG(!iAttachDbMap.Entry(mapKey), __SQLPANIC(ESqlPanicObjExists)); |
1141 __SQLLEAVE_IF_ERROR(iAttachDbMap.Insert(mapKey, mapData)); |
1187 __SQLLEAVE_IF_ERROR(iAttachDbMap.Insert(mapKey, mapData)); |
1142 CleanupStack::Pop(2);//iAttachDbMap owns mapKey amd mapData. |
1188 CleanupStack::Pop(2);//iAttachDbMap owns mapKey amd mapData. |
1143 } |
1189 } |
1144 |
1190 |
1145 /** |
1191 /** |
1157 |
1203 |
1158 @panic SqlDb 7 In _DEBUG mode if aFileData does not refer to a r/w database file. |
1204 @panic SqlDb 7 In _DEBUG mode if aFileData does not refer to a r/w database file. |
1159 */ |
1205 */ |
1160 void CSqlSrvDatabase::ProcessSettingsL(const TSqlSrvFileData& aFileData, const TDesC& aDbName) |
1206 void CSqlSrvDatabase::ProcessSettingsL(const TSqlSrvFileData& aFileData, const TDesC& aDbName) |
1161 { |
1207 { |
1162 __SQLASSERT(!aFileData.IsReadOnly(), ESqlPanicInternalError); |
1208 __ASSERT_DEBUG(!aFileData.IsReadOnly(), __SQLPANIC(ESqlPanicInternalError)); |
1163 #if !defined(__SQL_DISABLE_SYMBIAN_SETTINGS_TABLE__) |
1209 #if !defined(__SQL_DISABLE_SYMBIAN_SETTINGS_TABLE__) |
1164 //Make the journal file persistent - done by SQLite automatically because the locking mode is EXCLUSIVE |
1210 //Make the journal file persistent - done by SQLite automatically because the locking mode is EXCLUSIVE |
1165 //__SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KPersistentJournalPragma, KPersist, aDbName)); |
1211 //__SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KPersistentJournalPragma, KPersist, aDbName)); |
1166 //Load the current settings |
1212 //Load the current settings |
1167 TFileName storedCollationDllName; |
1213 TFileName storedCollationDllName; |
1170 __SQLLEAVE_IF_ERROR(::DbVacuumMode(iDbHandle, aDbName, currVacuumMode)); |
1216 __SQLLEAVE_IF_ERROR(::DbVacuumMode(iDbHandle, aDbName, currVacuumMode)); |
1171 //currVacuumMode == ESqliteVacuumOff ==> This is a database created not by the SQL server |
1217 //currVacuumMode == ESqliteVacuumOff ==> This is a database created not by the SQL server |
1172 TSqlCompactionMode compactionMode = currVacuumMode == ESqliteVacuumOff ? ESqlCompactionManual : ESqlCompactionNotSet; |
1218 TSqlCompactionMode compactionMode = currVacuumMode == ESqliteVacuumOff ? ESqlCompactionManual : ESqlCompactionNotSet; |
1173 TSqlDbSysSettings dbSettings(iDbHandle); |
1219 TSqlDbSysSettings dbSettings(iDbHandle); |
1174 dbSettings.LoadSettingsL(aDbName, storedCollationDllName, storedDbConfigFileVer, compactionMode); |
1220 dbSettings.LoadSettingsL(aDbName, storedCollationDllName, storedDbConfigFileVer, compactionMode); |
1175 __SQLASSERT(currVacuumMode == ESqliteVacuumOff ? compactionMode == ESqlCompactionManual : 1, ESqlPanicInternalError); |
1221 __ASSERT_DEBUG(currVacuumMode == ESqliteVacuumOff ? compactionMode == ESqlCompactionManual : 1, __SQLPANIC(ESqlPanicInternalError)); |
1176 if(aFileData.ContainHandles() && aFileData.IsCreated()) |
1222 if(aFileData.ContainHandles() && aFileData.IsCreated()) |
1177 { |
1223 { |
1178 compactionMode = aFileData.ConfigParams().iCompactionMode; |
1224 compactionMode = aFileData.ConfigParams().iCompactionMode; |
1179 if(compactionMode == ESqlCompactionNotSet) |
1225 if(compactionMode == ESqlCompactionNotSet) |
1180 { |
1226 { |
1214 { |
1260 { |
1215 TSqlDbSysSettings dbSettings(iDbHandle); |
1261 TSqlDbSysSettings dbSettings(iDbHandle); |
1216 //Check whether reindexing is necessary |
1262 //Check whether reindexing is necessary |
1217 if(::SqlServer().CollationDllName().CompareF(aStoredCollationDllName) != 0) |
1263 if(::SqlServer().CollationDllName().CompareF(aStoredCollationDllName) != 0) |
1218 { |
1264 { |
|
1265 SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSRVDATABASE_APPLYCONFIGUPDATES2L, "0x%X;CSqlSrvDatabase::ApplyConfigUpdatesL;Reindex db;aStoredCollationDllName=%S;aDbName=%S", (TUint)this, __SQLPRNSTR(aStoredCollationDllName), __SQLPRNSTR(aDbName))); |
1219 dbSettings.ReindexDatabaseL(aDbName, ::SqlServer().CollationDllName()); |
1266 dbSettings.ReindexDatabaseL(aDbName, ::SqlServer().CollationDllName()); |
1220 } |
1267 } |
1221 |
1268 |
1222 //Perform any necessary configuration file updates to the database. |
1269 //Perform any necessary configuration file updates to the database. |
1223 //We do not want failures here to cause the database to fail |
1270 //We do not want failures here to cause the database to fail |
1224 //to be opened and so any leave error is TRAPed and ignored |
1271 //to be opened and so any leave error is TRAPed and ignored |
1225 //(the error is logged in _DEBUG mode) |
1272 //(the error is logged in _DEBUG mode) |
1226 TRAPD(err, dbSettings.ConfigureDatabaseL(aStoredDbConfigFileVersion, aFileData, aDbName)); |
1273 TRAPD(err, dbSettings.ConfigureDatabaseL(aStoredDbConfigFileVersion, aFileData, aDbName)); |
1227 if(KErrNone != err) |
1274 if(KErrNone != err) |
1228 { |
1275 { |
1229 __SQLLOG_ERR(_L("SQLLOG: CSqlSrvDatabase::ApplyConfigUpdatesL() - ConfigureDatabaseL() failed with error code %d"), err); |
1276 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_APPLYCONFIGUPDATESL, "0x%X;CSqlSrvDatabase::ApplyConfigUpdatesL;ConfigureDatabaseL() failed with error code %d", (TUint)this, err)); |
1230 } |
1277 } |
1231 } |
1278 } |
1232 |
1279 |
1233 /** |
1280 /** |
1234 Sets the "cache size" and "page size" parameter values, if their values are valid. |
1281 Sets the "cache size" and "page size" parameter values, if their values are valid. |
1241 @param aLogicalDbName Parameter with default value of KNullDesC. If aLogicalDbName length is not 0, then the |
1288 @param aLogicalDbName Parameter with default value of KNullDesC. If aLogicalDbName length is not 0, then the |
1242 "cache_size" pragma will be executed on the attached database with aLogicalDbName name. |
1289 "cache_size" pragma will be executed on the attached database with aLogicalDbName name. |
1243 */ |
1290 */ |
1244 void CSqlSrvDatabase::SetConfigL(const TSqlSrvConfigParams& aConfigParams, TBool aSetPageSize, const TDesC& aLogicalDbName) |
1291 void CSqlSrvDatabase::SetConfigL(const TSqlSrvConfigParams& aConfigParams, TBool aSetPageSize, const TDesC& aLogicalDbName) |
1245 { |
1292 { |
1246 __SQLASSERT(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, ESqlPanicBadArgument); |
1293 __ASSERT_DEBUG(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, __SQLPANIC(ESqlPanicBadArgument)); |
1247 __SQLASSERT(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, ESqlPanicBadArgument); |
1294 __ASSERT_DEBUG(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, __SQLPANIC(ESqlPanicBadArgument)); |
1248 if(aSetPageSize && aConfigParams.iPageSize != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1295 if(aSetPageSize && aConfigParams.iPageSize != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1249 { |
1296 { |
1250 __SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KPageSizePragma, aConfigParams.iPageSize)); |
1297 __SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KPageSizePragma, aConfigParams.iPageSize)); |
1251 } |
1298 } |
1252 |
1299 |
1253 const TDesC& logicalDbName = aLogicalDbName.Length() > 0 ? aLogicalDbName : KMainDb16; |
1300 const TDesC& logicalDbName = aLogicalDbName.Length() > 0 ? aLogicalDbName : KMainDb16; |
1254 |
1301 |
|
1302 ::SetJournalSizeLimitL(iDbHandle, iAuthorizerDisabled, aConfigParams.iPageSize, logicalDbName); |
|
1303 |
1255 //Setting the cache size. |
1304 //Setting the cache size. |
1256 //Step 1: Check if aConfigParams.iCacheSize value is set. If it is set, then use it. |
1305 //Step 1: Check if aConfigParams.iCacheSize value is set. If it is set, then use it. |
1257 if(aConfigParams.iCacheSize != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1306 if(aConfigParams.iCacheSize != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1258 { |
1307 { |
1259 __SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KCacheSizePragma, aConfigParams.iCacheSize, logicalDbName)); |
1308 __SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KCacheSizePragma, aConfigParams.iCacheSize, logicalDbName)); |
1261 else |
1310 else |
1262 { |
1311 { |
1263 //Step 2: aConfigParams.iCacheSize value is not set. Then check if aConfigParams.iSoftHeapLimitKb value is set. |
1312 //Step 2: aConfigParams.iCacheSize value is not set. Then check if aConfigParams.iSoftHeapLimitKb value is set. |
1264 if(aConfigParams.iSoftHeapLimitKb != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1313 if(aConfigParams.iSoftHeapLimitKb != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1265 { |
1314 { |
1266 __SQLASSERT(aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
1315 __ASSERT_DEBUG(aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
1267 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb, ESqlPanicInternalError); |
1316 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb, __SQLPANIC(ESqlPanicInternalError)); |
1268 //Step 3: aConfigParams.iSoftHeapLimitKb value is set. Then use it to calculate the cache size. But we need the page size first. |
1317 //Step 3: aConfigParams.iSoftHeapLimitKb value is set. Then use it to calculate the cache size. But we need the page size first. |
1269 // aLogicalDbName is used instead of logicalDbName because PageSizeL() if called with non-zero length name, |
1318 // aLogicalDbName is used instead of logicalDbName because PageSizeL() if called with non-zero length name, |
1270 // "thinks" it is the main database name. KMainDb16 will be interpreted as an attached database name. |
1319 // "thinks" it is the main database name. KMainDb16 will be interpreted as an attached database name. |
1271 TInt pageSize = PageSizeL(aLogicalDbName); |
1320 TInt pageSize = PageSizeL(aLogicalDbName); |
1272 //Step 4: Calculate the cache size. |
1321 //Step 4: Calculate the cache size. |
1303 @panic SqlDb 4 In _DEBUG mode if aCompactionMode parameter value is invalid. |
1352 @panic SqlDb 4 In _DEBUG mode if aCompactionMode parameter value is invalid. |
1304 */ |
1353 */ |
1305 void CSqlSrvDatabase::InitCompactionL(TSqlCompactionMode aCompactionMode, TInt aFreePageThresholdKb, |
1354 void CSqlSrvDatabase::InitCompactionL(TSqlCompactionMode aCompactionMode, TInt aFreePageThresholdKb, |
1306 const TDesC& aDbFileName, TSqliteVacuumMode aCurrentVacuumMode, const TDesC& aDbName) |
1355 const TDesC& aDbFileName, TSqliteVacuumMode aCurrentVacuumMode, const TDesC& aDbName) |
1307 { |
1356 { |
1308 __SQLASSERT(aCompactionMode == ESqlCompactionManual || aCompactionMode == ESqlCompactionBackground || aCompactionMode == ESqlCompactionAuto, ESqlPanicBadArgument); |
1357 __ASSERT_DEBUG(aCompactionMode == ESqlCompactionManual || aCompactionMode == ESqlCompactionBackground || aCompactionMode == ESqlCompactionAuto, __SQLPANIC(ESqlPanicBadArgument)); |
1309 __SQLASSERT(aCurrentVacuumMode == ESqliteVacuumOff || aCurrentVacuumMode == ESqliteVacuumAuto || |
1358 __ASSERT_DEBUG(aCurrentVacuumMode == ESqliteVacuumOff || aCurrentVacuumMode == ESqliteVacuumAuto || |
1310 aCurrentVacuumMode == ESqliteVacuumIncremental, ESqlPanicBadArgument); |
1359 aCurrentVacuumMode == ESqliteVacuumIncremental, __SQLPANIC(ESqlPanicBadArgument)); |
1311 __SQLASSERT(aFreePageThresholdKb >= 0, ESqlPanicBadArgument); |
1360 __ASSERT_DEBUG(aFreePageThresholdKb >= 0, __SQLPANIC(ESqlPanicBadArgument)); |
1312 TSqliteVacuumMode newSqliteVacuumMode = aCompactionMode == ESqlCompactionAuto ? ESqliteVacuumAuto : ESqliteVacuumIncremental; |
1361 TSqliteVacuumMode newSqliteVacuumMode = aCompactionMode == ESqlCompactionAuto ? ESqliteVacuumAuto : ESqliteVacuumIncremental; |
1313 if(aCurrentVacuumMode == ESqliteVacuumOff) |
1362 if(aCurrentVacuumMode == ESqliteVacuumOff) |
1314 { |
1363 { |
1315 newSqliteVacuumMode = ESqliteVacuumOff; |
1364 newSqliteVacuumMode = ESqliteVacuumOff; |
1316 } |
1365 } |
1339 @see CSqlCompactor |
1388 @see CSqlCompactor |
1340 @see RSqlCompactDbMap |
1389 @see RSqlCompactDbMap |
1341 */ |
1390 */ |
1342 void CSqlSrvDatabase::NewCompactEntryL(TInt aFreePageThresholdKb, const TDesC& aDbFileName, const TDesC& aDbName) |
1391 void CSqlSrvDatabase::NewCompactEntryL(TInt aFreePageThresholdKb, const TDesC& aDbFileName, const TDesC& aDbName) |
1343 { |
1392 { |
|
1393 SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, CSQLSRVDATABASE_NEWCOMPACTENTRYL_ENTRY, "Entry;0x%X;CSqlSrvDatabase::NewCompactEntryL;aFreePageThresholdKb=%d;aDbFileName=%S;aDbName=%S", (TUint)this, aFreePageThresholdKb, __SQLPRNSTR(aDbFileName), __SQLPRNSTR(aDbName))); |
1344 TSqlCompactSettings settings; |
1394 TSqlCompactSettings settings; |
1345 settings.iFreePageThresholdKb = aFreePageThresholdKb; |
1395 settings.iFreePageThresholdKb = aFreePageThresholdKb; |
1346 ::SqlServer().Compactor().AddEntryL(aDbFileName, settings); |
1396 ::SqlServer().Compactor().AddEntryL(aDbFileName, settings); |
1347 TInt err = KErrNoMemory; |
1397 TInt err = KErrNoMemory; |
1348 HBufC* key = aDbName.Alloc(); |
1398 HBufC* key = aDbName.Alloc(); |
1349 HBufC* data = aDbFileName.Alloc(); |
1399 HBufC* data = aDbFileName.Alloc(); |
1350 if(key && data) |
1400 if(key && data) |
1351 { |
1401 { |
1352 __SQLASSERT(!iCompactDbMap.Entry(key), ESqlPanicObjExists); |
1402 __ASSERT_DEBUG(!iCompactDbMap.Entry(key), __SQLPANIC(ESqlPanicObjExists)); |
1353 err = iCompactDbMap.Insert(key, data);//returns the index of the new entry |
1403 err = iCompactDbMap.Insert(key, data);//returns the index of the new entry |
1354 } |
1404 } |
1355 if(err < 0) //If either "key" or "data" or both is NULL, then "err" is KErrNoMemory and the next "if" will be executed. |
1405 if(err < 0) //If either "key" or "data" or both is NULL, then "err" is KErrNoMemory and the next "if" will be executed. |
1356 { |
1406 { |
1357 delete data; |
1407 delete data; |
1358 delete key; |
1408 delete key; |
1359 ::SqlServer().Compactor().ReleaseEntry(aDbFileName); |
1409 ::SqlServer().Compactor().ReleaseEntry(aDbFileName); |
1360 } |
1410 } |
|
1411 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_NEWCOMPACTENTRYL_EXIT, "Exit;0x%X;CSqlSrvDatabase::NewCompactEntryL;err=%d", (TUint)this, err)); |
1361 __SQLLEAVE_IF_ERROR(err); |
1412 __SQLLEAVE_IF_ERROR(err); |
1362 } |
1413 } |
1363 |
1414 |
1364 /** |
1415 /** |
1365 Removes database (identified by its logical name) from the compactor. |
1416 Removes database (identified by its logical name) from the compactor. |
1424 iAuthorizerDisabled = ETrue; |
1476 iAuthorizerDisabled = ETrue; |
1425 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
1477 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
1426 TInt pageSize = 0; |
1478 TInt pageSize = 0; |
1427 __SQLLEAVE_IF_ERROR(::DbPageSize(iDbHandle, aDbName, pageSize)); |
1479 __SQLLEAVE_IF_ERROR(::DbPageSize(iDbHandle, aDbName, pageSize)); |
1428 CleanupStack::PopAndDestroy(); |
1480 CleanupStack::PopAndDestroy(); |
1429 __SQLASSERT(pageSize > 0, ESqlPanicInternalError); |
1481 __ASSERT_DEBUG(pageSize > 0, __SQLPANIC(ESqlPanicInternalError)); |
1430 if(aDbName == KNullDesC) |
1482 if(aDbName == KNullDesC) |
1431 { |
1483 { |
1432 iPageSize = pageSize; |
1484 iPageSize = pageSize; |
1433 } |
1485 } |
1434 return pageSize; |
1486 return pageSize; |
1452 |
1504 |
1453 @panic SqlDb 4 In _DEBUG mode if aSecurityPolicy is NULL. |
1505 @panic SqlDb 4 In _DEBUG mode if aSecurityPolicy is NULL. |
1454 */ |
1506 */ |
1455 void CSqlSrvDatabase::ConstructCreateSecureL(const TSqlSrvFileData& aFileData, CSqlSecurityPolicy* aSecurityPolicy) |
1507 void CSqlSrvDatabase::ConstructCreateSecureL(const TSqlSrvFileData& aFileData, CSqlSecurityPolicy* aSecurityPolicy) |
1456 { |
1508 { |
1457 __SQLASSERT(aSecurityPolicy != NULL, ESqlPanicBadArgument); |
1509 __ASSERT_DEBUG(aSecurityPolicy != NULL, __SQLPANIC(ESqlPanicBadArgument)); |
1458 //Insert a new item in the security policies map. |
1510 //Insert a new item in the security policies map. |
1459 CleanupStack::PushL(aSecurityPolicy); |
1511 CleanupStack::PushL(aSecurityPolicy); |
1460 const TUint8* mapKey = SecurityMapKeyL(aFileData.FileName()); |
1512 const TUint8* mapKey = SecurityMapKeyL(aFileData.FileName()); |
1461 mapKey = ::CreateStrCopyLC(mapKey); |
1513 mapKey = ::CreateStrCopyLC(mapKey); |
1462 __SQLASSERT(!::SqlServer().SecurityMap().Entry(mapKey), ESqlPanicObjExists); |
1514 __ASSERT_DEBUG(!::SqlServer().SecurityMap().Entry(mapKey), __SQLPANIC(ESqlPanicObjExists)); |
1463 __SQLLEAVE_IF_ERROR(::SqlServer().SecurityMap().Insert(mapKey, aSecurityPolicy)); |
1515 __SQLLEAVE_IF_ERROR(::SqlServer().SecurityMap().Insert(mapKey, aSecurityPolicy)); |
1464 CleanupStack::Pop(2);//iSecurityMap owns mapKey and aSecurityPolicy. |
1516 CleanupStack::Pop(2);//iSecurityMap owns mapKey and aSecurityPolicy. |
1465 iSecureDbName = mapKey; |
1517 iSecureDbName = mapKey; |
1466 iSecurityPolicy = aSecurityPolicy; |
1518 iSecurityPolicy = aSecurityPolicy; |
1467 // |
1519 // |
1468 DoCommonConstructCreateL(aFileData, ETrue); |
1520 DoCommonConstructCreateL(aFileData, ETrue); |
1495 // - installs the user-defined functions |
1547 // - installs the user-defined functions |
1496 // - installs collations |
1548 // - installs collations |
1497 //If the method fails and the error is not KErrAlreadyExists, the database file will be closed and deleted. |
1549 //If the method fails and the error is not KErrAlreadyExists, the database file will be closed and deleted. |
1498 void CSqlSrvDatabase::DoCommonConstructCreateL(const TSqlSrvFileData& aFileData, TBool aSecureDb) |
1550 void CSqlSrvDatabase::DoCommonConstructCreateL(const TSqlSrvFileData& aFileData, TBool aSecureDb) |
1499 { |
1551 { |
1500 __SQLASSERT(!iDbHandle, ESqlPanicInternalError); |
1552 __ASSERT_DEBUG(!iDbHandle, __SQLPANIC(ESqlPanicInternalError)); |
1501 __SQLASSERT(aSecureDb ? iSecurityPolicy != NULL : ETrue, ESqlPanicInternalError); |
1553 __ASSERT_DEBUG(aSecureDb ? iSecurityPolicy != NULL : ETrue, __SQLPANIC(ESqlPanicInternalError)); |
1502 CreateNewDbFileL(aFileData); |
1554 CreateNewDbFileL(aFileData); |
1503 TDbFileCleanup dbFileCleanup(aFileData, iDbHandle); |
1555 TDbFileCleanup dbFileCleanup(aFileData, iDbHandle); |
1504 CleanupStack::PushL(TCleanupItem(&DbFileCleanup, &dbFileCleanup)); |
1556 CleanupStack::PushL(TCleanupItem(&DbFileCleanup, &dbFileCleanup)); |
1505 //Make the journal file persistent - done by SQLite automatically because the locking mode is EXCLUSIVE |
1557 //Make the journal file persistent - done by SQLite automatically because the locking mode is EXCLUSIVE |
1506 //::ExecPragma(iDbHandle, iAuthorizerDisabled, KPersistentJournalPragma, KPersist); |
1558 //::ExecPragma(iDbHandle, iAuthorizerDisabled, KPersistentJournalPragma, KPersist); |