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