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 // |
84 // |
89 // |
85 //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 |
86 //aRight argument is NULL. |
91 //aRight argument is NULL. |
87 static TInt Compare(const TSqlAttachDbPair& aLeft, const TSqlAttachDbPair& aRight) |
92 static TInt Compare(const TSqlAttachDbPair& aLeft, const TSqlAttachDbPair& aRight) |
88 { |
93 { |
89 __SQLASSERT(aLeft.iKey != NULL && aRight.iKey != NULL, ESqlPanicInternalError); |
94 __ASSERT_DEBUG(aLeft.iKey != NULL && aRight.iKey != NULL, __SQLPANIC2(ESqlPanicInternalError)); |
90 return ::CompareNoCase8(TPtrC8(aLeft.iKey), TPtrC8(aRight.iKey)); |
95 return ::CompareNoCase8(TPtrC8(aLeft.iKey), TPtrC8(aRight.iKey)); |
91 } |
96 } |
92 |
97 |
93 //Local function, used for comparing TSqlCompactDbPair objects. |
98 //Local function, used for comparing TSqlCompactDbPair objects. |
94 //(TSqlCompactDbPair structure represents type of the objects, members |
99 //(TSqlCompactDbPair structure represents type of the objects, members |
99 // |
104 // |
100 //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 |
101 //aRight argument is NULL. |
106 //aRight argument is NULL. |
102 static TInt Compare2(const TSqlCompactDbPair& aLeft, const TSqlCompactDbPair& aRight) |
107 static TInt Compare2(const TSqlCompactDbPair& aLeft, const TSqlCompactDbPair& aRight) |
103 { |
108 { |
104 __SQLASSERT(aLeft.iKey != NULL && aRight.iKey != NULL, ESqlPanicInternalError); |
109 __ASSERT_DEBUG(aLeft.iKey != NULL && aRight.iKey != NULL, __SQLPANIC2(ESqlPanicInternalError)); |
105 return ::CompareNoCase(*aLeft.iKey, *aRight.iKey); |
110 return ::CompareNoCase(*aLeft.iKey, *aRight.iKey); |
106 } |
111 } |
107 |
112 |
108 //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. |
109 //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 |
113 if(aFileData.ConfigParams().iDbEncoding == TSqlSrvConfigParams::EEncUtf8) |
118 if(aFileData.ConfigParams().iDbEncoding == TSqlSrvConfigParams::EEncUtf8) |
114 { |
119 { |
115 TBuf8<KMaxFileName + 1> fileNameZ; |
120 TBuf8<KMaxFileName + 1> fileNameZ; |
116 if(!::UTF16ZToUTF8Z(aFileData.FileNameZ(), fileNameZ)) |
121 if(!::UTF16ZToUTF8Z(aFileData.FileNameZ(), fileNameZ)) |
117 { |
122 { |
118 __SQLLEAVE(KErrGeneral); |
123 __SQLLEAVE2(KErrGeneral); |
119 } |
124 } |
120 __SQLLEAVE_IF_ERROR(::CreateDbHandle8(fileNameZ, aDbHandle)); |
125 __SQLLEAVE_IF_ERROR2(::CreateDbHandle8(fileNameZ, aDbHandle)); |
121 } |
126 } |
122 else |
127 else |
123 { |
128 { |
124 __SQLLEAVE_IF_ERROR(::CreateDbHandle16(aFileData.FileNameZ(), aDbHandle)); |
129 __SQLLEAVE_IF_ERROR2(::CreateDbHandle16(aFileData.FileNameZ(), aDbHandle)); |
125 } |
130 } |
126 } |
131 } |
127 |
132 |
128 //LoadAttachedDbSecurityPolicyLC() creates a new CSqlSecurityPolicy object and initializes it with the |
133 //LoadAttachedDbSecurityPolicyLC() creates a new CSqlSecurityPolicy object and initializes it with the |
129 //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. |
151 //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. |
152 //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. |
153 //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. |
154 static CSqlSecurityPolicy* LoadDbSecurityPolicyLC(sqlite3* aDbHandle) |
159 static CSqlSecurityPolicy* LoadDbSecurityPolicyLC(sqlite3* aDbHandle) |
155 { |
160 { |
156 __SQLASSERT(aDbHandle != NULL, ESqlPanicBadArgument); |
161 __ASSERT_DEBUG(aDbHandle != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
157 //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 |
158 TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysFail); |
163 TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysFail); |
159 CSqlSecurityPolicy* dbPolicy = CSqlSecurityPolicy::NewLC(defaultPolicy); |
164 CSqlSecurityPolicy* dbPolicy = CSqlSecurityPolicy::NewLC(defaultPolicy); |
160 //Read the security policies. |
165 //Read the security policies. |
161 TSqlDbSysSettings dbSysSettings(aDbHandle); |
166 TSqlDbSysSettings dbSysSettings(aDbHandle); |
166 //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. |
167 //aSrc is expected to be UTF8 encoded, zero terminated string. |
172 //aSrc is expected to be UTF8 encoded, zero terminated string. |
168 //The function panics in _DEBUG mode if aSrc is NULL. |
173 //The function panics in _DEBUG mode if aSrc is NULL. |
169 static TUint8* CreateStrCopyLC(const TUint8* aSrc) |
174 static TUint8* CreateStrCopyLC(const TUint8* aSrc) |
170 { |
175 { |
171 __SQLASSERT(aSrc != NULL, ESqlPanicBadArgument); |
176 __ASSERT_DEBUG(aSrc != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
172 TInt len = User::StringLength(aSrc) + 1; |
177 TInt len = User::StringLength(aSrc) + 1; |
173 TUint8* copy = new (ELeave) TUint8[len]; |
178 TUint8* copy = new (ELeave) TUint8[len]; |
174 Mem::Copy(copy, aSrc, len); |
179 Mem::Copy(copy, aSrc, len); |
175 CleanupStack::PushL(copy); |
180 CleanupStack::PushL(copy); |
176 return copy; |
181 return copy; |
207 |
212 |
208 //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 |
209 //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). |
210 static void DbFileCleanup(void* aDbFileCleanup) |
215 static void DbFileCleanup(void* aDbFileCleanup) |
211 { |
216 { |
212 __SQLASSERT(aDbFileCleanup != NULL, ESqlPanicBadArgument); |
217 __ASSERT_DEBUG(aDbFileCleanup != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
213 TDbFileCleanup* dbFileCleanup = static_cast <TDbFileCleanup*> (aDbFileCleanup); |
218 TDbFileCleanup* dbFileCleanup = static_cast <TDbFileCleanup*> (aDbFileCleanup); |
214 dbFileCleanup->Cleanup(); |
219 dbFileCleanup->Cleanup(); |
215 } |
220 } |
216 |
221 |
217 //Executes "PRAGMA" SQL statement + INTEGER value. |
222 //Executes "PRAGMA" SQL statement + INTEGER value. |
221 // aDbName - "main" or the attached database name |
226 // aDbName - "main" or the attached database name |
222 //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. |
223 //During the call the authorizer will be disabled. |
228 //During the call the authorizer will be disabled. |
224 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) |
225 { |
230 { |
226 __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)); |
227 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 |
228 pragmaSql.Format(aPragma, &aDbName, aValue); |
235 pragmaSql.Format(aPragma, &aDbName, aValue); |
229 TBool authorizerDisabledState = aAuthorizerDisabled; |
236 TBool authorizerDisabledState = aAuthorizerDisabled; |
230 aAuthorizerDisabled = ETrue; |
237 aAuthorizerDisabled = ETrue; |
231 TInt err = DbExecStmt16(aDbHandle, pragmaSql); |
238 TInt err = DbExecStmt16(aDbHandle, pragmaSql); |
232 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)); |
233 return err; |
241 return err; |
234 } |
242 } |
235 |
243 |
236 //The journal size limit is set to be at lest 16 pages and no less than 64 Kb. |
244 //The journal size limit is set to be at lest 16 pages and no less than 64 Kb. |
237 static void SetJournalSizeLimitL(sqlite3* aDbHandle, TBool& aAuthorizerDisabled, TInt aPageSize, const TDesC& aDbName = KMainDb16) |
245 static void SetJournalSizeLimitL(sqlite3* aDbHandle, TBool& aAuthorizerDisabled, TInt aPageSize, const TDesC& aDbName = KMainDb16) |
238 { |
246 { |
239 __SQLASSERT(aDbHandle != NULL, ESqlPanicBadArgument); |
247 __ASSERT_DEBUG(aDbHandle != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
240 if(aPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
248 if(aPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
241 { |
249 { |
242 __SQLLEAVE_IF_ERROR(DbPageSize(aDbHandle, aDbName, aPageSize)); |
250 __SQLLEAVE_IF_ERROR2(DbPageSize(aDbHandle, aDbName, aPageSize)); |
243 } |
251 } |
244 const TInt KPageMultiplier = 16; |
252 const TInt KPageMultiplier = 16; |
245 const TInt KDefaultJournalSizeLimit = 64 * 1024; |
253 const TInt KDefaultJournalSizeLimit = 64 * 1024; |
246 const TInt KMaxJournalSizeLimit = 512 * 1024; |
254 const TInt KMaxJournalSizeLimit = 512 * 1024; |
247 const TInt KJournalSizeLimit = Min((aPageSize * KPageMultiplier), KMaxJournalSizeLimit); |
255 const TInt KJournalSizeLimit = Min((aPageSize * KPageMultiplier), KMaxJournalSizeLimit); |
248 if(KJournalSizeLimit > KDefaultJournalSizeLimit) |
256 if(KJournalSizeLimit > KDefaultJournalSizeLimit) |
249 { |
257 { |
250 __SQLLEAVE_IF_ERROR(::ExecPragma(aDbHandle, aAuthorizerDisabled, KJournalSizeLimitPragma, KJournalSizeLimit)); |
258 __SQLLEAVE_IF_ERROR2(::ExecPragma(aDbHandle, aAuthorizerDisabled, KJournalSizeLimitPragma, KJournalSizeLimit)); |
251 } |
259 } |
252 } |
260 } |
253 |
261 |
254 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
262 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
255 ///////////////////////////// CSqlSrvDatabase class ///////////////////////////////////////////// |
263 ///////////////////////////// CSqlSrvDatabase class ///////////////////////////////////////////// |
291 @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. |
292 @panic SqlDb 4 In _DEBUG mode if aSecurityPolicy is NULL. |
300 @panic SqlDb 4 In _DEBUG mode if aSecurityPolicy is NULL. |
293 */ |
301 */ |
294 CSqlSrvDatabase* CSqlSrvDatabase::CreateSecureL(const TSqlSrvFileData& aFileData, CSqlSecurityPolicy* aSecurityPolicy) |
302 CSqlSrvDatabase* CSqlSrvDatabase::CreateSecureL(const TSqlSrvFileData& aFileData, CSqlSecurityPolicy* aSecurityPolicy) |
295 { |
303 { |
296 __SQLASSERT(aFileData.IsSecureFileNameFmt(), ESqlPanicBadArgument); |
304 SQL_TRACE_INTERNALS(OstTrace0(TRACE_INTERNALS, CSQLSRVDATABASE_CREATESECUREL_ENTRY, "Entry;0;CSqlSrvDatabase::CreateSecureL")); |
297 __SQLASSERT(aSecurityPolicy != NULL, ESqlPanicBadArgument); |
305 __ASSERT_DEBUG(aFileData.IsSecureFileNameFmt(), __SQLPANIC2(ESqlPanicBadArgument)); |
|
306 __ASSERT_DEBUG(aSecurityPolicy != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
298 if(!::SqlServer().SecurityInspector().Check(aSecurityPolicy->DbPolicy(RSqlSecurityPolicy::ESchemaPolicy))) |
307 if(!::SqlServer().SecurityInspector().Check(aSecurityPolicy->DbPolicy(RSqlSecurityPolicy::ESchemaPolicy))) |
299 { |
308 { |
300 //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. |
301 //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 |
302 //won't be put in the security policies map. |
311 //won't be put in the security policies map. |
303 delete aSecurityPolicy; |
312 delete aSecurityPolicy; |
304 __SQLLEAVE(KErrPermissionDenied); |
313 __SQLLEAVE2(KErrPermissionDenied); |
305 } |
314 } |
306 //What does happen with aSecurityPolicy instance? |
315 //What does happen with aSecurityPolicy instance? |
307 // 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. |
308 // (the security policies map contains reference counted security policies) |
317 // (the security policies map contains reference counted security policies) |
309 // 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. |
322 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
331 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
323 CleanupStack::Pop(aSecurityPolicy); |
332 CleanupStack::Pop(aSecurityPolicy); |
324 CleanupStack::PushL(self); |
333 CleanupStack::PushL(self); |
325 self->ConstructCreateSecureL(aFileData, aSecurityPolicy); |
334 self->ConstructCreateSecureL(aFileData, aSecurityPolicy); |
326 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)); |
327 return self; |
337 return self; |
328 } |
338 } |
329 |
339 |
330 /** |
340 /** |
331 Creates new CSqlSrvDatabase instance which creates and manages new SQL database. |
341 Creates new CSqlSrvDatabase instance which creates and manages new SQL database. |
352 |
362 |
353 @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. |
354 */ |
364 */ |
355 CSqlSrvDatabase* CSqlSrvDatabase::CreateL(const TSqlSrvFileData& aFileData) |
365 CSqlSrvDatabase* CSqlSrvDatabase::CreateL(const TSqlSrvFileData& aFileData) |
356 { |
366 { |
357 __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)); |
358 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
369 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
359 CleanupStack::PushL(self); |
370 CleanupStack::PushL(self); |
360 self->ConstructCreateL(aFileData); |
371 self->ConstructCreateL(aFileData); |
361 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)); |
362 return self; |
374 return self; |
363 } |
375 } |
364 |
376 |
365 /** |
377 /** |
366 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. |
391 @see CSqlSecurityPolicy |
403 @see CSqlSecurityPolicy |
392 @see TSqlSrvFileData::SetFromHandleL() |
404 @see TSqlSrvFileData::SetFromHandleL() |
393 */ |
405 */ |
394 CSqlSrvDatabase* CSqlSrvDatabase::OpenL(const TSqlSrvFileData& aFileData) |
406 CSqlSrvDatabase* CSqlSrvDatabase::OpenL(const TSqlSrvFileData& aFileData) |
395 { |
407 { |
|
408 SQL_TRACE_INTERNALS(OstTrace0(TRACE_INTERNALS, CSQLSRVDATABASE_OPENL_ENTRY, "Entry;0;CSqlSrvDatabase::OpenL")); |
396 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
409 CSqlSrvDatabase* self = new (ELeave) CSqlSrvDatabase(); |
397 CleanupStack::PushL(self); |
410 CleanupStack::PushL(self); |
398 aFileData.IsSecureFileNameFmt() ? self->ConstructOpenSecureL(aFileData) : self->ConstructOpenL(aFileData); |
411 aFileData.IsSecureFileNameFmt() ? self->ConstructOpenSecureL(aFileData) : self->ConstructOpenL(aFileData); |
399 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)); |
400 return self; |
414 return self; |
401 } |
415 } |
402 |
416 |
403 /** |
417 /** |
404 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. |
405 */ |
419 */ |
406 CSqlSrvDatabase::~CSqlSrvDatabase() |
420 CSqlSrvDatabase::~CSqlSrvDatabase() |
407 { |
421 { |
408 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)); |
409 TSqlCompactDbMapIterator compactDbIt(iCompactDbMap); |
423 TSqlCompactDbMapIterator compactDbIt(iCompactDbMap); |
410 TSqlCompactDbPair compactDbPair; |
424 TSqlCompactDbPair compactDbPair; |
411 while(compactDbIt.Next(compactDbPair)) |
425 while(compactDbIt.Next(compactDbPair)) |
412 { |
426 { |
413 __SQLASSERT(compactDbPair.iData, ESqlPanicInvalidObj); |
427 __ASSERT_DEBUG(compactDbPair.iData, __SQLPANIC2(ESqlPanicInvalidObj)); |
414 ::SqlServer().Compactor().ReleaseEntry(*compactDbPair.iData); |
428 ::SqlServer().Compactor().ReleaseEntry(*compactDbPair.iData); |
415 } |
429 } |
416 iCompactDbMap.Close(); |
430 iCompactDbMap.Close(); |
417 //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. |
418 //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. |
451 // 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. |
452 TSqlAttachDbMapIterator it(iAttachDbMap); |
466 TSqlAttachDbMapIterator it(iAttachDbMap); |
453 TSqlAttachDbPair attachDbPair; |
467 TSqlAttachDbPair attachDbPair; |
454 while(it.Next(attachDbPair)) |
468 while(it.Next(attachDbPair)) |
455 { |
469 { |
456 __SQLASSERT(attachDbPair.iData, ESqlPanicInvalidObj); |
470 __ASSERT_DEBUG(attachDbPair.iData, __SQLPANIC2(ESqlPanicInvalidObj)); |
457 ::SqlServer().SecurityMap().Remove(attachDbPair.iData); |
471 ::SqlServer().SecurityMap().Remove(attachDbPair.iData); |
458 } |
472 } |
459 iAttachDbMap.Close(); |
473 iAttachDbMap.Close(); |
460 ::CloseDbHandle(iDbHandle); |
474 ::CloseDbHandle(iDbHandle); |
|
475 SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSRVDATABASE_CSQLSRVDATABASE2_EXIT, "Exit;0x%X;CSqlSrvDatabase::~CSqlSrvDatabase", (TUint)this)); |
461 } |
476 } |
462 |
477 |
463 /** |
478 /** |
464 Initializes CSqlSrvDatabase data memebers with their default values. |
479 Initializes CSqlSrvDatabase data memebers with their default values. |
465 |
480 |
493 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 |
494 errors categorised as ESqlDbError, and other system-wide error codes. |
509 errors categorised as ESqlDbError, and other system-wide error codes. |
495 */ |
510 */ |
496 void CSqlSrvDatabase::CreateNewDbFileL(const TSqlSrvFileData& aFileData) |
511 void CSqlSrvDatabase::CreateNewDbFileL(const TSqlSrvFileData& aFileData) |
497 { |
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))); |
498 if(::FileExists(aFileData.Fs(), aFileData.FileName())) |
515 if(::FileExists(aFileData.Fs(), aFileData.FileName())) |
499 { |
516 { |
500 __SQLLEAVE(KErrAlreadyExists); |
517 __SQLLEAVE(KErrAlreadyExists); |
501 } |
518 } |
502 TDbFileCleanup dbFileCleanup(aFileData, iDbHandle); |
519 TDbFileCleanup dbFileCleanup(aFileData, iDbHandle); |
528 @see TSqlSrvFileData |
545 @see TSqlSrvFileData |
529 @see TSqlSrvFileData::SetFromHandleL() |
546 @see TSqlSrvFileData::SetFromHandleL() |
530 */ |
547 */ |
531 void CSqlSrvDatabase::OpenExistingDbFileL(const TSqlSrvFileData& aFileData) |
548 void CSqlSrvDatabase::OpenExistingDbFileL(const TSqlSrvFileData& aFileData) |
532 { |
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))); |
533 if(!aFileData.ContainHandles()) |
552 if(!aFileData.ContainHandles()) |
534 {//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 |
535 if(!::FileExists(aFileData.Fs(), aFileData.FileName())) |
554 if(!::FileExists(aFileData.Fs(), aFileData.FileName())) |
536 { |
555 { |
537 __SQLLEAVE(KErrNotFound); |
556 __SQLLEAVE(KErrNotFound); |
826 iAuthorizerDisabled = ETrue; |
849 iAuthorizerDisabled = ETrue; |
827 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
850 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
828 TInt freePageCount = 0; |
851 TInt freePageCount = 0; |
829 __SQLLEAVE_IF_ERROR(::DbFreePageCount(iDbHandle, aDbName, freePageCount)); |
852 __SQLLEAVE_IF_ERROR(::DbFreePageCount(iDbHandle, aDbName, freePageCount)); |
830 CleanupStack::PopAndDestroy(); |
853 CleanupStack::PopAndDestroy(); |
831 __SQLASSERT(freePageCount >= 0, ESqlPanicInternalError); |
854 __ASSERT_DEBUG(freePageCount >= 0, __SQLPANIC(ESqlPanicInternalError)); |
832 return (TInt64)freePageCount * PageSizeL(aDbName); |
855 return (TInt64)freePageCount * PageSizeL(aDbName); |
833 } |
856 } |
834 |
857 |
835 /** |
858 /** |
836 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 |
890 @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, |
891 and other system-wide error codes. |
914 and other system-wide error codes. |
892 */ |
915 */ |
893 TInt CSqlSrvDatabase::CompactL(TInt aSize, const TDesC& aDbName) |
916 TInt CSqlSrvDatabase::CompactL(TInt aSize, const TDesC& aDbName) |
894 { |
917 { |
895 __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)); |
896 TInt pageSize = PageSizeL(aDbName);//PageSizeL() will disable/enable the authorizer |
920 TInt pageSize = PageSizeL(aDbName);//PageSizeL() will disable/enable the authorizer |
897 TInt pageCount = KMaxTInt; |
921 TInt pageCount = KMaxTInt; |
898 if(aSize > 0) |
922 if(aSize > 0) |
899 {//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. |
900 pageCount = (TInt64)((TInt64)aSize + pageSize - 1) / pageSize; |
924 pageCount = (TInt64)((TInt64)aSize + pageSize - 1) / pageSize; |
904 iAuthorizerDisabled = ETrue; |
928 iAuthorizerDisabled = ETrue; |
905 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
929 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
906 __SQLLEAVE_IF_ERROR(::DbCompact(iDbHandle, aDbName, pageCount, pageCount)); |
930 __SQLLEAVE_IF_ERROR(::DbCompact(iDbHandle, aDbName, pageCount, pageCount)); |
907 CleanupStack::PopAndDestroy(); |
931 CleanupStack::PopAndDestroy(); |
908 } |
932 } |
|
933 SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSRVDATABASE_COMPACTL_EXIT, "Exit;0x%X;CSqlSrvDatabase::CompactL;pageCount=%d;pageSize=%d", (TUint)this, pageCount, pageSize)); |
909 return pageCount * pageSize; |
934 return pageCount * pageSize; |
910 } |
935 } |
911 |
936 |
912 /** |
937 /** |
913 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 |
1076 } |
1101 } |
1077 else |
1102 else |
1078 { |
1103 { |
1079 //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 |
1080 //insert a new item in the map. |
1105 //insert a new item in the map. |
1081 __SQLASSERT(aMapKey != NULL, ESqlPanicInternalError); |
1106 __ASSERT_DEBUG(aMapKey != NULL, __SQLPANIC(ESqlPanicInternalError)); |
1082 aMapKey = ::CreateStrCopyLC(aMapKey); |
1107 aMapKey = ::CreateStrCopyLC(aMapKey); |
1083 CSqlSecurityPolicy* securityPolicy = aAttachedDb ? ::LoadAttachedDbSecurityPolicyLC(aFileData) : |
1108 CSqlSecurityPolicy* securityPolicy = aAttachedDb ? ::LoadAttachedDbSecurityPolicyLC(aFileData) : |
1084 ::LoadDbSecurityPolicyLC(iDbHandle); |
1109 ::LoadDbSecurityPolicyLC(iDbHandle); |
1085 __SQLASSERT(!::SqlServer().SecurityMap().Entry(aMapKey), ESqlPanicObjExists); |
1110 __ASSERT_DEBUG(!::SqlServer().SecurityMap().Entry(aMapKey), __SQLPANIC2(ESqlPanicObjExists)); |
1086 __SQLLEAVE_IF_ERROR(::SqlServer().SecurityMap().Insert(aMapKey, securityPolicy)); |
1111 __SQLLEAVE_IF_ERROR(::SqlServer().SecurityMap().Insert(aMapKey, securityPolicy)); |
1087 CleanupStack::Pop(2);//iSecurityMap owns aMapKey and securityPolicy objects |
1112 CleanupStack::Pop(2);//iSecurityMap owns aMapKey and securityPolicy objects |
1088 aSecurityPolicy = securityPolicy; |
1113 aSecurityPolicy = securityPolicy; |
1089 } |
1114 } |
1090 __SQLASSERT(aMapKey != NULL, ESqlPanicInternalError); |
1115 __ASSERT_DEBUG(aMapKey != NULL, __SQLPANIC(ESqlPanicInternalError)); |
1091 __SQLASSERT(aSecurityPolicy != NULL, ESqlPanicInternalError); |
1116 __ASSERT_DEBUG(aSecurityPolicy != NULL, __SQLPANIC(ESqlPanicInternalError)); |
1092 } |
1117 } |
1093 |
1118 |
1094 /** |
1119 /** |
1095 Removes attached secure database entries from the maps. |
1120 Removes attached secure database entries from the maps. |
1096 |
1121 |
1145 @see RSqlAttachDbMap |
1171 @see RSqlAttachDbMap |
1146 @see CSqlSrvDatabase |
1172 @see CSqlSrvDatabase |
1147 */ |
1173 */ |
1148 void CSqlSrvDatabase::InsertInAttachDbMapL(const TDesC& aDbFileName, const TDesC& aDbName) |
1174 void CSqlSrvDatabase::InsertInAttachDbMapL(const TDesC& aDbFileName, const TDesC& aDbName) |
1149 { |
1175 { |
|
1176 SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSRVDATABASE_INSERTINATTACHDBMAPL, "0x%X;CSqlSrvDatabase::InsertInAttachDbMapL;aDbFileName=%S;aDbName=%S", (TUint)this, __SQLPRNSTR(aDbFileName), __SQLPRNSTR(aDbName))); |
1150 //Convert aDbName to UTF8, zero-terminated name |
1177 //Convert aDbName to UTF8, zero-terminated name |
1151 TPtr8 ptr(iFileNameBuf, sizeof(iFileNameBuf)); |
1178 TPtr8 ptr(iFileNameBuf, sizeof(iFileNameBuf)); |
1152 if(!::UTF16ToUTF8Z(aDbName, ptr)) |
1179 if(!::UTF16ToUTF8Z(aDbName, ptr)) |
1153 { |
1180 { |
1154 __SQLLEAVE(KErrGeneral); |
1181 __SQLLEAVE(KErrGeneral); |
1155 } |
1182 } |
1156 const TUint8* mapKey = ::CreateStrCopyLC(iFileNameBuf); |
1183 const TUint8* mapKey = ::CreateStrCopyLC(iFileNameBuf); |
1157 const TUint8* mapData = SecurityMapKeyL(aDbFileName); |
1184 const TUint8* mapData = SecurityMapKeyL(aDbFileName); |
1158 mapData = ::CreateStrCopyLC(mapData); |
1185 mapData = ::CreateStrCopyLC(mapData); |
1159 __SQLASSERT(!iAttachDbMap.Entry(mapKey), ESqlPanicObjExists); |
1186 __ASSERT_DEBUG(!iAttachDbMap.Entry(mapKey), __SQLPANIC(ESqlPanicObjExists)); |
1160 __SQLLEAVE_IF_ERROR(iAttachDbMap.Insert(mapKey, mapData)); |
1187 __SQLLEAVE_IF_ERROR(iAttachDbMap.Insert(mapKey, mapData)); |
1161 CleanupStack::Pop(2);//iAttachDbMap owns mapKey amd mapData. |
1188 CleanupStack::Pop(2);//iAttachDbMap owns mapKey amd mapData. |
1162 } |
1189 } |
1163 |
1190 |
1164 /** |
1191 /** |
1176 |
1203 |
1177 @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. |
1178 */ |
1205 */ |
1179 void CSqlSrvDatabase::ProcessSettingsL(const TSqlSrvFileData& aFileData, const TDesC& aDbName) |
1206 void CSqlSrvDatabase::ProcessSettingsL(const TSqlSrvFileData& aFileData, const TDesC& aDbName) |
1180 { |
1207 { |
1181 __SQLASSERT(!aFileData.IsReadOnly(), ESqlPanicInternalError); |
1208 __ASSERT_DEBUG(!aFileData.IsReadOnly(), __SQLPANIC(ESqlPanicInternalError)); |
1182 #if !defined(__SQL_DISABLE_SYMBIAN_SETTINGS_TABLE__) |
1209 #if !defined(__SQL_DISABLE_SYMBIAN_SETTINGS_TABLE__) |
1183 //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 |
1184 //__SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KPersistentJournalPragma, KPersist, aDbName)); |
1211 //__SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KPersistentJournalPragma, KPersist, aDbName)); |
1185 //Load the current settings |
1212 //Load the current settings |
1186 TFileName storedCollationDllName; |
1213 TFileName storedCollationDllName; |
1189 __SQLLEAVE_IF_ERROR(::DbVacuumMode(iDbHandle, aDbName, currVacuumMode)); |
1216 __SQLLEAVE_IF_ERROR(::DbVacuumMode(iDbHandle, aDbName, currVacuumMode)); |
1190 //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 |
1191 TSqlCompactionMode compactionMode = currVacuumMode == ESqliteVacuumOff ? ESqlCompactionManual : ESqlCompactionNotSet; |
1218 TSqlCompactionMode compactionMode = currVacuumMode == ESqliteVacuumOff ? ESqlCompactionManual : ESqlCompactionNotSet; |
1192 TSqlDbSysSettings dbSettings(iDbHandle); |
1219 TSqlDbSysSettings dbSettings(iDbHandle); |
1193 dbSettings.LoadSettingsL(aDbName, storedCollationDllName, storedDbConfigFileVer, compactionMode); |
1220 dbSettings.LoadSettingsL(aDbName, storedCollationDllName, storedDbConfigFileVer, compactionMode); |
1194 __SQLASSERT(currVacuumMode == ESqliteVacuumOff ? compactionMode == ESqlCompactionManual : 1, ESqlPanicInternalError); |
1221 __ASSERT_DEBUG(currVacuumMode == ESqliteVacuumOff ? compactionMode == ESqlCompactionManual : 1, __SQLPANIC(ESqlPanicInternalError)); |
1195 if(aFileData.ContainHandles() && aFileData.IsCreated()) |
1222 if(aFileData.ContainHandles() && aFileData.IsCreated()) |
1196 { |
1223 { |
1197 compactionMode = aFileData.ConfigParams().iCompactionMode; |
1224 compactionMode = aFileData.ConfigParams().iCompactionMode; |
1198 if(compactionMode == ESqlCompactionNotSet) |
1225 if(compactionMode == ESqlCompactionNotSet) |
1199 { |
1226 { |
1233 { |
1260 { |
1234 TSqlDbSysSettings dbSettings(iDbHandle); |
1261 TSqlDbSysSettings dbSettings(iDbHandle); |
1235 //Check whether reindexing is necessary |
1262 //Check whether reindexing is necessary |
1236 if(::SqlServer().CollationDllName().CompareF(aStoredCollationDllName) != 0) |
1263 if(::SqlServer().CollationDllName().CompareF(aStoredCollationDllName) != 0) |
1237 { |
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))); |
1238 dbSettings.ReindexDatabaseL(aDbName, ::SqlServer().CollationDllName()); |
1266 dbSettings.ReindexDatabaseL(aDbName, ::SqlServer().CollationDllName()); |
1239 } |
1267 } |
1240 |
1268 |
1241 //Perform any necessary configuration file updates to the database. |
1269 //Perform any necessary configuration file updates to the database. |
1242 //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 |
1243 //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 |
1244 //(the error is logged in _DEBUG mode) |
1272 //(the error is logged in _DEBUG mode) |
1245 TRAPD(err, dbSettings.ConfigureDatabaseL(aStoredDbConfigFileVersion, aFileData, aDbName)); |
1273 TRAPD(err, dbSettings.ConfigureDatabaseL(aStoredDbConfigFileVersion, aFileData, aDbName)); |
1246 if(KErrNone != err) |
1274 if(KErrNone != err) |
1247 { |
1275 { |
1248 __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)); |
1249 } |
1277 } |
1250 } |
1278 } |
1251 |
1279 |
1252 /** |
1280 /** |
1253 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. |
1260 @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 |
1261 "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. |
1262 */ |
1290 */ |
1263 void CSqlSrvDatabase::SetConfigL(const TSqlSrvConfigParams& aConfigParams, TBool aSetPageSize, const TDesC& aLogicalDbName) |
1291 void CSqlSrvDatabase::SetConfigL(const TSqlSrvConfigParams& aConfigParams, TBool aSetPageSize, const TDesC& aLogicalDbName) |
1264 { |
1292 { |
1265 __SQLASSERT(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, ESqlPanicBadArgument); |
1293 __ASSERT_DEBUG(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, __SQLPANIC(ESqlPanicBadArgument)); |
1266 __SQLASSERT(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, ESqlPanicBadArgument); |
1294 __ASSERT_DEBUG(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, __SQLPANIC(ESqlPanicBadArgument)); |
1267 if(aSetPageSize && aConfigParams.iPageSize != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1295 if(aSetPageSize && aConfigParams.iPageSize != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1268 { |
1296 { |
1269 __SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KPageSizePragma, aConfigParams.iPageSize)); |
1297 __SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KPageSizePragma, aConfigParams.iPageSize)); |
1270 } |
1298 } |
1271 |
1299 |
1272 const TDesC& logicalDbName = aLogicalDbName.Length() > 0 ? aLogicalDbName : KMainDb16; |
1300 const TDesC& logicalDbName = aLogicalDbName.Length() > 0 ? aLogicalDbName : KMainDb16; |
1273 |
1301 |
1274 ::SetJournalSizeLimitL(iDbHandle, iAuthorizerDisabled, aConfigParams.iPageSize, logicalDbName); |
1302 ::SetJournalSizeLimitL(iDbHandle, iAuthorizerDisabled, aConfigParams.iPageSize, logicalDbName); |
1275 |
1303 |
1276 //Setting the cache size. |
1304 //Setting the cache size. |
1277 //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. |
1278 if(aConfigParams.iCacheSize != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1306 if(aConfigParams.iCacheSize != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1279 { |
1307 { |
1280 __SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KCacheSizePragma, aConfigParams.iCacheSize, logicalDbName)); |
1308 __SQLLEAVE_IF_ERROR(::ExecPragma(iDbHandle, iAuthorizerDisabled, KCacheSizePragma, aConfigParams.iCacheSize, logicalDbName)); |
1282 else |
1310 else |
1283 { |
1311 { |
1284 //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. |
1285 if(aConfigParams.iSoftHeapLimitKb != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1313 if(aConfigParams.iSoftHeapLimitKb != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
1286 { |
1314 { |
1287 __SQLASSERT(aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
1315 __ASSERT_DEBUG(aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
1288 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb, ESqlPanicInternalError); |
1316 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb, __SQLPANIC(ESqlPanicInternalError)); |
1289 //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. |
1290 // 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, |
1291 // "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. |
1292 TInt pageSize = PageSizeL(aLogicalDbName); |
1320 TInt pageSize = PageSizeL(aLogicalDbName); |
1293 //Step 4: Calculate the cache size. |
1321 //Step 4: Calculate the cache size. |
1324 @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. |
1325 */ |
1353 */ |
1326 void CSqlSrvDatabase::InitCompactionL(TSqlCompactionMode aCompactionMode, TInt aFreePageThresholdKb, |
1354 void CSqlSrvDatabase::InitCompactionL(TSqlCompactionMode aCompactionMode, TInt aFreePageThresholdKb, |
1327 const TDesC& aDbFileName, TSqliteVacuumMode aCurrentVacuumMode, const TDesC& aDbName) |
1355 const TDesC& aDbFileName, TSqliteVacuumMode aCurrentVacuumMode, const TDesC& aDbName) |
1328 { |
1356 { |
1329 __SQLASSERT(aCompactionMode == ESqlCompactionManual || aCompactionMode == ESqlCompactionBackground || aCompactionMode == ESqlCompactionAuto, ESqlPanicBadArgument); |
1357 __ASSERT_DEBUG(aCompactionMode == ESqlCompactionManual || aCompactionMode == ESqlCompactionBackground || aCompactionMode == ESqlCompactionAuto, __SQLPANIC(ESqlPanicBadArgument)); |
1330 __SQLASSERT(aCurrentVacuumMode == ESqliteVacuumOff || aCurrentVacuumMode == ESqliteVacuumAuto || |
1358 __ASSERT_DEBUG(aCurrentVacuumMode == ESqliteVacuumOff || aCurrentVacuumMode == ESqliteVacuumAuto || |
1331 aCurrentVacuumMode == ESqliteVacuumIncremental, ESqlPanicBadArgument); |
1359 aCurrentVacuumMode == ESqliteVacuumIncremental, __SQLPANIC(ESqlPanicBadArgument)); |
1332 __SQLASSERT(aFreePageThresholdKb >= 0, ESqlPanicBadArgument); |
1360 __ASSERT_DEBUG(aFreePageThresholdKb >= 0, __SQLPANIC(ESqlPanicBadArgument)); |
1333 TSqliteVacuumMode newSqliteVacuumMode = aCompactionMode == ESqlCompactionAuto ? ESqliteVacuumAuto : ESqliteVacuumIncremental; |
1361 TSqliteVacuumMode newSqliteVacuumMode = aCompactionMode == ESqlCompactionAuto ? ESqliteVacuumAuto : ESqliteVacuumIncremental; |
1334 if(aCurrentVacuumMode == ESqliteVacuumOff) |
1362 if(aCurrentVacuumMode == ESqliteVacuumOff) |
1335 { |
1363 { |
1336 newSqliteVacuumMode = ESqliteVacuumOff; |
1364 newSqliteVacuumMode = ESqliteVacuumOff; |
1337 } |
1365 } |
1360 @see CSqlCompactor |
1388 @see CSqlCompactor |
1361 @see RSqlCompactDbMap |
1389 @see RSqlCompactDbMap |
1362 */ |
1390 */ |
1363 void CSqlSrvDatabase::NewCompactEntryL(TInt aFreePageThresholdKb, const TDesC& aDbFileName, const TDesC& aDbName) |
1391 void CSqlSrvDatabase::NewCompactEntryL(TInt aFreePageThresholdKb, const TDesC& aDbFileName, const TDesC& aDbName) |
1364 { |
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))); |
1365 TSqlCompactSettings settings; |
1394 TSqlCompactSettings settings; |
1366 settings.iFreePageThresholdKb = aFreePageThresholdKb; |
1395 settings.iFreePageThresholdKb = aFreePageThresholdKb; |
1367 ::SqlServer().Compactor().AddEntryL(aDbFileName, settings); |
1396 ::SqlServer().Compactor().AddEntryL(aDbFileName, settings); |
1368 TInt err = KErrNoMemory; |
1397 TInt err = KErrNoMemory; |
1369 HBufC* key = aDbName.Alloc(); |
1398 HBufC* key = aDbName.Alloc(); |
1370 HBufC* data = aDbFileName.Alloc(); |
1399 HBufC* data = aDbFileName.Alloc(); |
1371 if(key && data) |
1400 if(key && data) |
1372 { |
1401 { |
1373 __SQLASSERT(!iCompactDbMap.Entry(key), ESqlPanicObjExists); |
1402 __ASSERT_DEBUG(!iCompactDbMap.Entry(key), __SQLPANIC(ESqlPanicObjExists)); |
1374 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 |
1375 } |
1404 } |
1376 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. |
1377 { |
1406 { |
1378 delete data; |
1407 delete data; |
1379 delete key; |
1408 delete key; |
1380 ::SqlServer().Compactor().ReleaseEntry(aDbFileName); |
1409 ::SqlServer().Compactor().ReleaseEntry(aDbFileName); |
1381 } |
1410 } |
|
1411 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVDATABASE_NEWCOMPACTENTRYL_EXIT, "Exit;0x%X;CSqlSrvDatabase::NewCompactEntryL;err=%d", (TUint)this, err)); |
1382 __SQLLEAVE_IF_ERROR(err); |
1412 __SQLLEAVE_IF_ERROR(err); |
1383 } |
1413 } |
1384 |
1414 |
1385 /** |
1415 /** |
1386 Removes database (identified by its logical name) from the compactor. |
1416 Removes database (identified by its logical name) from the compactor. |
1445 iAuthorizerDisabled = ETrue; |
1476 iAuthorizerDisabled = ETrue; |
1446 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
1477 CleanupStack::PushL(TCleanupItem(&EnableAuthorizer, &iAuthorizerDisabled)); |
1447 TInt pageSize = 0; |
1478 TInt pageSize = 0; |
1448 __SQLLEAVE_IF_ERROR(::DbPageSize(iDbHandle, aDbName, pageSize)); |
1479 __SQLLEAVE_IF_ERROR(::DbPageSize(iDbHandle, aDbName, pageSize)); |
1449 CleanupStack::PopAndDestroy(); |
1480 CleanupStack::PopAndDestroy(); |
1450 __SQLASSERT(pageSize > 0, ESqlPanicInternalError); |
1481 __ASSERT_DEBUG(pageSize > 0, __SQLPANIC(ESqlPanicInternalError)); |
1451 if(aDbName == KNullDesC) |
1482 if(aDbName == KNullDesC) |
1452 { |
1483 { |
1453 iPageSize = pageSize; |
1484 iPageSize = pageSize; |
1454 } |
1485 } |
1455 return pageSize; |
1486 return pageSize; |
1473 |
1504 |
1474 @panic SqlDb 4 In _DEBUG mode if aSecurityPolicy is NULL. |
1505 @panic SqlDb 4 In _DEBUG mode if aSecurityPolicy is NULL. |
1475 */ |
1506 */ |
1476 void CSqlSrvDatabase::ConstructCreateSecureL(const TSqlSrvFileData& aFileData, CSqlSecurityPolicy* aSecurityPolicy) |
1507 void CSqlSrvDatabase::ConstructCreateSecureL(const TSqlSrvFileData& aFileData, CSqlSecurityPolicy* aSecurityPolicy) |
1477 { |
1508 { |
1478 __SQLASSERT(aSecurityPolicy != NULL, ESqlPanicBadArgument); |
1509 __ASSERT_DEBUG(aSecurityPolicy != NULL, __SQLPANIC(ESqlPanicBadArgument)); |
1479 //Insert a new item in the security policies map. |
1510 //Insert a new item in the security policies map. |
1480 CleanupStack::PushL(aSecurityPolicy); |
1511 CleanupStack::PushL(aSecurityPolicy); |
1481 const TUint8* mapKey = SecurityMapKeyL(aFileData.FileName()); |
1512 const TUint8* mapKey = SecurityMapKeyL(aFileData.FileName()); |
1482 mapKey = ::CreateStrCopyLC(mapKey); |
1513 mapKey = ::CreateStrCopyLC(mapKey); |
1483 __SQLASSERT(!::SqlServer().SecurityMap().Entry(mapKey), ESqlPanicObjExists); |
1514 __ASSERT_DEBUG(!::SqlServer().SecurityMap().Entry(mapKey), __SQLPANIC(ESqlPanicObjExists)); |
1484 __SQLLEAVE_IF_ERROR(::SqlServer().SecurityMap().Insert(mapKey, aSecurityPolicy)); |
1515 __SQLLEAVE_IF_ERROR(::SqlServer().SecurityMap().Insert(mapKey, aSecurityPolicy)); |
1485 CleanupStack::Pop(2);//iSecurityMap owns mapKey and aSecurityPolicy. |
1516 CleanupStack::Pop(2);//iSecurityMap owns mapKey and aSecurityPolicy. |
1486 iSecureDbName = mapKey; |
1517 iSecureDbName = mapKey; |
1487 iSecurityPolicy = aSecurityPolicy; |
1518 iSecurityPolicy = aSecurityPolicy; |
1488 // |
1519 // |
1489 DoCommonConstructCreateL(aFileData, ETrue); |
1520 DoCommonConstructCreateL(aFileData, ETrue); |
1516 // - installs the user-defined functions |
1547 // - installs the user-defined functions |
1517 // - installs collations |
1548 // - installs collations |
1518 //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. |
1519 void CSqlSrvDatabase::DoCommonConstructCreateL(const TSqlSrvFileData& aFileData, TBool aSecureDb) |
1550 void CSqlSrvDatabase::DoCommonConstructCreateL(const TSqlSrvFileData& aFileData, TBool aSecureDb) |
1520 { |
1551 { |
1521 __SQLASSERT(!iDbHandle, ESqlPanicInternalError); |
1552 __ASSERT_DEBUG(!iDbHandle, __SQLPANIC(ESqlPanicInternalError)); |
1522 __SQLASSERT(aSecureDb ? iSecurityPolicy != NULL : ETrue, ESqlPanicInternalError); |
1553 __ASSERT_DEBUG(aSecureDb ? iSecurityPolicy != NULL : ETrue, __SQLPANIC(ESqlPanicInternalError)); |
1523 CreateNewDbFileL(aFileData); |
1554 CreateNewDbFileL(aFileData); |
1524 TDbFileCleanup dbFileCleanup(aFileData, iDbHandle); |
1555 TDbFileCleanup dbFileCleanup(aFileData, iDbHandle); |
1525 CleanupStack::PushL(TCleanupItem(&DbFileCleanup, &dbFileCleanup)); |
1556 CleanupStack::PushL(TCleanupItem(&DbFileCleanup, &dbFileCleanup)); |
1526 //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 |
1527 //::ExecPragma(iDbHandle, iAuthorizerDisabled, KPersistentJournalPragma, KPersist); |
1558 //::ExecPragma(iDbHandle, iAuthorizerDisabled, KPersistentJournalPragma, KPersist); |