1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
335 |
335 |
336 @leave KErrGeneral, either unable to retrieve the data from the settings table or the |
336 @leave KErrGeneral, either unable to retrieve the data from the settings table or the |
337 stored table version or config file version is invalid or the stored compaction mode is invalid. |
337 stored table version or config file version is invalid or the stored compaction mode is invalid. |
338 KErrOverflow, aCollationDllName is not large enough to store the name of the |
338 KErrOverflow, aCollationDllName is not large enough to store the name of the |
339 collation dll that is stored in the settings table. |
339 collation dll that is stored in the settings table. |
|
340 KErrNoMemory, an out of memory condition has occurred. |
340 Note that the function may also leave with other system-wide error codes or SQL |
341 Note that the function may also leave with other system-wide error codes or SQL |
341 errors of ESqlDbError type |
342 errors of ESqlDbError type |
342 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object). |
343 @panic SqlDb 2 In _DEBUG mode if iDbHandle is NULL (uninitialized TSqlDbSysSettings object). |
343 */ |
344 */ |
344 void TSqlDbSysSettings::GetSettingsL(const TDesC& aDbName, TDes& aCollationDllName, TInt& aDbConfigFileVersion, |
345 void TSqlDbSysSettings::GetSettingsL(const TDesC& aDbName, TDes& aCollationDllName, TInt& aDbConfigFileVersion, |
354 sqlite3_stmt* stmtHandle = ::StmtPrepare16L(iDbHandle, sql); |
355 sqlite3_stmt* stmtHandle = ::StmtPrepare16L(iDbHandle, sql); |
355 CleanupStack::PushL(TCleanupItem(&FinalizeStatementHandle, stmtHandle)); |
356 CleanupStack::PushL(TCleanupItem(&FinalizeStatementHandle, stmtHandle)); |
356 //Move to the first record |
357 //Move to the first record |
357 TInt err = ::StmtNext(stmtHandle); |
358 TInt err = ::StmtNext(stmtHandle); |
358 __SQLLEAVE_IF_ERROR(err); |
359 __SQLLEAVE_IF_ERROR(err); |
359 //Check that it is a valid row |
360 //Check that it is a valid row. The error is checked on the previous line. |
|
361 //The "if" bellow will check whether there is a valid record or not. |
360 if(err != KSqlAtRow) |
362 if(err != KSqlAtRow) |
361 { |
363 { |
362 __SQLLEAVE(KErrGeneral); |
364 __SQLLEAVE(KErrGeneral); |
363 } |
365 } |
364 //Get the system settings version |
366 //Get the system settings version |
376 if(aDbConfigFileVersion < KSqlNullDbConfigFileVersion) |
378 if(aDbConfigFileVersion < KSqlNullDbConfigFileVersion) |
377 { |
379 { |
378 __SQLLEAVE(KErrGeneral); |
380 __SQLLEAVE(KErrGeneral); |
379 } |
381 } |
380 |
382 |
381 //The "CollationDllName" column exists and its value can be read |
383 //The "CollationDllName" column exists and its value can be read. |
|
384 //The column type might be different than SQLITE_TEXT - malformed database. |
|
385 if(sqlite3_column_type(stmtHandle, KCollationDllNameColIdx) != SQLITE_TEXT) |
|
386 { |
|
387 __SQLLEAVE(KErrGeneral); |
|
388 } |
382 const void* ptr = sqlite3_column_text16(stmtHandle, KCollationDllNameColIdx); |
389 const void* ptr = sqlite3_column_text16(stmtHandle, KCollationDllNameColIdx); |
383 if(ptr) |
390 //Null column value - this might be an indication of an "out of memory" problem, if the column text |
384 { |
391 //is in UTF8 format. (sqlite3_column_text16() may allocate memory for UTF8->UTF16 conversion) |
385 TPtrC16 src(reinterpret_cast <const TUint16*> (ptr)); |
392 __SQLLEAVE_IF_NULL(ptr); |
386 if(src.Length() > aCollationDllName.MaxLength()) |
393 TPtrC16 src(reinterpret_cast <const TUint16*> (ptr)); |
387 { |
394 if(src.Length() > aCollationDllName.MaxLength()) |
388 __SQLLEAVE(KErrOverflow); |
395 { |
389 } |
396 __SQLLEAVE(KErrOverflow); |
390 aCollationDllName.Copy(src); |
397 } |
391 } |
398 aCollationDllName.Copy(src); |
392 else |
|
393 { |
|
394 __SQLLEAVE(KErrGeneral); |
|
395 } |
|
396 } |
399 } |
397 if(aSettingsVersion > ESqlSystemVersion3) |
400 if(aSettingsVersion > ESqlSystemVersion3) |
398 { |
401 { |
399 aCompactionMode = static_cast <TSqlCompactionMode> (sqlite3_column_int(stmtHandle, KCompactionModeColIdx)); |
402 aCompactionMode = static_cast <TSqlCompactionMode> (sqlite3_column_int(stmtHandle, KCompactionModeColIdx)); |
400 if(aCompactionMode != ESqlCompactionManual && aCompactionMode != ESqlCompactionBackground && aCompactionMode != ESqlCompactionAuto) |
403 if(aCompactionMode != ESqlCompactionManual && aCompactionMode != ESqlCompactionBackground && aCompactionMode != ESqlCompactionAuto) |
851 TSecurityPolicy TSqlDbSysSettings::ReadCurrSecurityPolicyL(sqlite3_stmt* aStmtHandle, TInt& aObjType, |
854 TSecurityPolicy TSqlDbSysSettings::ReadCurrSecurityPolicyL(sqlite3_stmt* aStmtHandle, TInt& aObjType, |
852 TPtrC& aObjName, TInt& aPolicyType) |
855 TPtrC& aObjName, TInt& aPolicyType) |
853 { |
856 { |
854 __SQLASSERT(aStmtHandle != NULL, ESqlPanicBadArgument); |
857 __SQLASSERT(aStmtHandle != NULL, ESqlPanicBadArgument); |
855 aObjType = sqlite3_column_int(aStmtHandle, KObjTypeColIdx); |
858 aObjType = sqlite3_column_int(aStmtHandle, KObjTypeColIdx); |
|
859 //The "ObjectName" column type might be different than SQLITE_TEXT - malformed database. |
|
860 if(sqlite3_column_type(aStmtHandle, KObjNameColIdx) != SQLITE_TEXT) |
|
861 { |
|
862 __SQLLEAVE(KErrGeneral); |
|
863 } |
|
864 const void* text = sqlite3_column_text16(aStmtHandle, KObjNameColIdx); |
|
865 //Null column value - this might be an indication of an "out of memory" problem, if the column text |
|
866 //is in UTF8 format. (sqlite3_column_text16() may allocate memory for UTF8->UTF16 conversion) |
|
867 __SQLLEAVE_IF_NULL(text); |
856 TInt len = (TUint)sqlite3_column_bytes16(aStmtHandle, KObjNameColIdx) / sizeof(TUint16); |
868 TInt len = (TUint)sqlite3_column_bytes16(aStmtHandle, KObjNameColIdx) / sizeof(TUint16); |
857 const void* text = sqlite3_column_text16(aStmtHandle, KObjNameColIdx); |
|
858 aObjName.Set(reinterpret_cast <const TUint16*> (text), len); |
869 aObjName.Set(reinterpret_cast <const TUint16*> (text), len); |
859 aPolicyType = sqlite3_column_int(aStmtHandle, KObjPolicyTypeColIdx); |
870 aPolicyType = sqlite3_column_int(aStmtHandle, KObjPolicyTypeColIdx); |
860 len = sqlite3_column_bytes(aStmtHandle, KObjPolicyDataColIdx); |
871 len = sqlite3_column_bytes(aStmtHandle, KObjPolicyDataColIdx); |
861 if(len != sizeof(TSecurityPolicy)) |
872 if(len != sizeof(TSecurityPolicy)) |
862 { |
873 { |