diff -r 0d6db0a14001 -r 3256212fc81f persistentstorage/sql/SRC/Server/SqlSrvMain.cpp --- a/persistentstorage/sql/SRC/Server/SqlSrvMain.cpp Tue Jul 06 16:18:30 2010 +0300 +++ b/persistentstorage/sql/SRC/Server/SqlSrvMain.cpp Wed Aug 18 11:30:17 2010 +0300 @@ -25,10 +25,14 @@ #include "SqlCompact.h" #include "SqlCompactConn.h" #include "SqlSrvResourceProfiler.h" -#include "UTraceSql.h" #ifdef _DEBUG #include #endif +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "SqlSrvMainTraces.h" +#endif +#include "SqlTraceDef.h" #ifndef SQLSRV_STARTUP_TEST static @@ -66,7 +70,7 @@ //aRight argument is NULL. static TInt Compare(const TSqlSecurityPair& aLeft, const TSqlSecurityPair& aRight) { - __SQLASSERT(aLeft.iKey != NULL && aRight.iKey != NULL, ESqlPanicInternalError); + __ASSERT_DEBUG(aLeft.iKey != NULL && aRight.iKey != NULL, __SQLPANIC2(ESqlPanicInternalError)); return ::CompareNoCase8(TPtrC8(aLeft.iKey), TPtrC8(aRight.iKey)); } @@ -81,7 +85,7 @@ */ CSqlServer& SqlServer(void) { - __SQLASSERT_ALWAYS(TheServer != NULL, ESqlPanicInvalidObj); + __ASSERT_ALWAYS(TheServer != NULL, __SQLPANIC2(ESqlPanicInvalidObj)); return *TheServer; } @@ -95,9 +99,11 @@ */ CSqlServer* CSqlServer::NewLC() { + SQL_TRACE_INTERNALS(OstTrace0(TRACE_INTERNALS, CSQLSERVER_NEWLC_ENTRY, "Entry;0;CSqlServer::NewLC")); CSqlServer* self = new (ELeave) CSqlServer; CleanupStack::PushL(self); self->ConstructL(); + SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSERVER_NEWLC_EXIT, "Exit;0x%X;CSqlServer::NewLC", (TUint)self)); return self; } @@ -106,6 +112,7 @@ */ CSqlServer::~CSqlServer() { + SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSERVER_CSQLSERVER2_ENTRY, "Entry;0x%x;CSqlServer::~CSqlServer", (TUint)this)); delete iCompactor; delete iBackupClient; iDriveSpaceCol.ResetAndDestroy(); @@ -117,8 +124,7 @@ delete iDbConfigFiles; sqlite3SymbianLibFinalize(); TheServer = NULL; - SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KSqlSrvClose)); - SQLPROFILER_SERVER_STOP(); + SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSERVER_CSQLSERVER2_EXIT, "Exit;0x%x;CSqlServer::~CSqlServer", (TUint)this)); } /** @@ -128,7 +134,7 @@ */ RSqlBufFlat& CSqlServer::GetFlatBufL(TInt aMinLen) { - __SQLASSERT(aMinLen >= 0, ESqlPanicBadArgument); + __ASSERT_DEBUG(aMinLen >= 0, __SQLPANIC(ESqlPanicBadArgument)); __SQLLEAVE_IF_ERROR(iFlatBuf.ReAlloc(aMinLen)); SQLPROFILER_REPORT_ALLOC(iFlatBuf.MaxSize()); return iFlatBuf; @@ -144,10 +150,10 @@ */ TDes8& CSqlServer::GetBuf8L(TInt aMinLen) { - __SQLASSERT(aMinLen >= 0, ESqlPanicBadArgument); + __ASSERT_DEBUG(aMinLen >= 0, __SQLPANIC(ESqlPanicBadArgument)); #ifdef _DEBUG -TInt maxBufLen = iBufPtr8.MaxLength(); -maxBufLen = maxBufLen; + TInt maxBufLen = iBufPtr8.MaxLength(); + maxBufLen = maxBufLen; #endif if(iBufPtr8.MaxLength() < aMinLen) { @@ -167,10 +173,10 @@ */ TDes16& CSqlServer::GetBuf16L(TInt aMinLen) { - __SQLASSERT(aMinLen >= 0, ESqlPanicBadArgument); + __ASSERT_DEBUG(aMinLen >= 0, __SQLPANIC(ESqlPanicBadArgument)); #ifdef _DEBUG -TInt maxBufLen = iBufPtr16.MaxLength(); -maxBufLen = maxBufLen; + TInt maxBufLen = iBufPtr16.MaxLength(); + maxBufLen = maxBufLen; #endif if(iBufPtr16.MaxLength() < aMinLen) { @@ -196,7 +202,7 @@ if(iBufPtr8.MaxSize() > KBufLimit) { (void)ReAllocBuf(KBufLimit); - __SQLASSERT(oldBuf == iBuf, ESqlPanicInternalError); + __ASSERT_DEBUG(oldBuf == iBuf, __SQLPANIC(ESqlPanicInternalError)); } } @@ -211,7 +217,7 @@ */ TInt CSqlServer::ReAllocBuf(TInt aNewBufSize) { - __SQLASSERT(aNewBufSize >= 0, ESqlPanicBadArgument); + __ASSERT_DEBUG(aNewBufSize >= 0, __SQLPANIC(ESqlPanicBadArgument)); #ifdef _DEBUG const TInt KMinBufSize = 8; #else @@ -301,7 +307,8 @@ #endif SQLPROFILER_SERVER_START(); //Configure the SQLite library - __SQLLEAVE_IF_ERROR(sqlite3_config(SQLITE_CONFIG_LOOKASIDE, KSqliteLookAsideCellSize, KSqliteLookAsideCellCount)); + TInt sqliteErr = sqlite3_config(SQLITE_CONFIG_LOOKASIDE, KSqliteLookAsideCellSize, KSqliteLookAsideCellCount); + __SQLLEAVE_IF_ERROR(::Sql2OsErrCode(sqliteErr, KErrArgument)); //Open SQLITE library - this must be the first call after StartL() (os_symbian.cpp, "TheAllocator" initialization rellated). __SQLLEAVE_IF_ERROR(sqlite3SymbianLibInit()); //Create buffers @@ -314,6 +321,7 @@ RFs& fs = sqlite3SymbianFs(); TFileName serverPrivatePath; __SQLLEAVE_IF_ERROR(fs.PrivatePath(serverPrivatePath)); + DeleteTempFilesL(sysDrive, serverPrivatePath); //Load config file parameter values (if config file exists) and initialize iFileData. TParse parse; __SQLLEAVE_IF_ERROR(parse.Set(KSqlSrvDefaultConfigFile, &serverPrivatePath, NULL)); @@ -326,8 +334,8 @@ const TSqlSrvConfigParams& configParams = iFileData.ConfigParams(); if(configParams.iSoftHeapLimitKb > 0) { - __SQLASSERT(configParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && - configParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb, ESqlPanicInternalError); + __ASSERT_DEBUG(configParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && + configParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb, __SQLPANIC(ESqlPanicInternalError)); sqlite3_soft_heap_limit(configParams.iSoftHeapLimitKb * 1024); } //Enable shared cache @@ -362,6 +370,39 @@ } /** +Delete any temp files left the "temp" subdirectory in server's private directory. + +The SQLite is configured to use shared page cache. When the shared page cache is enabled, +those temp files created by SQLite are deleted only when the database gets closed. However, +if during power down event the client application does not close the database, +the temp files will never get deleted. +This is why the SQL server should deletes all temp files during its start-up. + +Note that all errors exept KErrNoMemory are ignored in the function body, becasuse +the temp files deletion is not a critical operation to prevent the server start up. + +@param aDriveNumber A drive number. +@param aServerPath A server's private path. + +*/ +void CSqlServer::DeleteTempFilesL(TInt aDriveNumber, const TDesC& aServerPath)const + { + _LIT(KTempFileDir, "temp"); + _LIT(KWildCard, "*.*"); + TDriveUnit drive(aDriveNumber); + TDriveName driveName = drive.Name(); + TParse parse; + (void)parse.Set(aServerPath, &driveName, 0);//this call can't fail + (void)parse.AddDir(KTempFileDir);//this call can't fail + TFileName tempfileDir(parse.FullName()); + (void)parse.Set(KWildCard, &tempfileDir, 0);//this call can't fail + RFs& fs = sqlite3SymbianFs(); + CFileMan* fm = CFileMan::NewL(fs); + (void)fm->Delete(parse.FullName()); + delete fm; + } + +/** Retrieves in iCollationDllName current(default) collation dll name. see TExtendedLocale */ @@ -380,6 +421,7 @@ fileName.Set(fname, NULL, NULL); iCollationDllName = fileName.NameAndExt(); } + SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSERVER_GETCOLLATIONDLLNAMEL, "0x%x;CSqlServer::GetCollationDllNameL;iCollationDllName=%S;err=%d", (TUint)this, __SQLPRNSTR(iCollationDllName), err)); } /** Finds and caches the name of each database configuration file @@ -403,7 +445,7 @@ } else { - __SQLLOG_ERR(_L("SQLLOG: CSqlServer::CacheDbConfigFileNamesL() - GetDir() failed with error code %d"), err); + SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_CACHEDDBCONFIGFILENAMESL, "0x%X;CSqlServer::CacheDbConfigFileNamesL;GetDir() failed with error code %d", (TUint)this, err)); } CleanupStack::PopAndDestroy(); // entryList } @@ -459,6 +501,7 @@ */ void CSqlServer::GetBackUpListL(TSecureId aUid, RArray& aFileList) { + SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL_ENTRY, "Entry;0x%x;CSqlServer::GetBackUpListL;aUid=0x%X", (TUint)this, (TUint)aUid.iId)); aFileList.Reset(); TFindFile findFile(iFileData.Fs()); CDir* fileNameCol = NULL; @@ -472,14 +515,14 @@ //The first set of files, which name is matching "[aUid]*" pattern, is ready. do { - __SQLASSERT(fileNameCol != NULL, ESqlPanicInternalError); + __ASSERT_DEBUG(fileNameCol != NULL, __SQLPANIC(ESqlPanicInternalError)); CleanupStack::PushL(fileNameCol); const TDesC& file = findFile.File();//"file" variable contains the drive and the path. the file name in "file" is invalid in this case. //Check that the drive, where the database files are, is not ROM drive TParse parse; (void)parse.Set(file, NULL, NULL);//this call can't file, the file name comes from findFile call. TPtrC driveName = parse.Drive(); - __SQLASSERT(driveName.Length() > 0, ESqlPanicInternalError); + __ASSERT_DEBUG(driveName.Length() > 0, __SQLPANIC(ESqlPanicInternalError)); TInt driveNumber = -1; __SQLLEAVE_IF_ERROR(RFs::CharToDrive(driveName[0], driveNumber)); TDriveInfo driveInfo; @@ -495,6 +538,8 @@ if(!entry.IsDir()) { (void)parse.Set(entry.iName, &file, NULL);//"parse" variable now contains the full file path + __SQLTRACE_INTERNALSVAR(TPtrC fname = parse.FullName()); + SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL, "0x%x;CSqlServer::GetBackUpListL;fname=%S", (TUint)this, __SQLPRNSTR(fname))); __SQLLEAVE_IF_ERROR(aFileList.Append(parse)); } } @@ -503,11 +548,12 @@ fileNameCol = NULL; } while((err = findFile.FindWild(fileNameCol)) == KErrNone);//Get the next set of files }//end of "if(err == KErrNone)" - __SQLASSERT(!fileNameCol, ESqlPanicInternalError); + __ASSERT_DEBUG(!fileNameCol, __SQLPANIC(ESqlPanicInternalError)); if(err != KErrNotFound && err != KErrNone) { __SQLLEAVE(err); } + SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL_EXIT, "Exit;0x%x;CSqlServer::GetBackUpListL;file count=%d;err=%d", (TUint)this, aFileList.Count(), err)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -526,7 +572,6 @@ CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; CleanupStack::PushL(scheduler); CActiveScheduler::Install(scheduler); - SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KSqlSrvStart)); TheServer = CSqlServer::NewLC(); RProcess::Rendezvous(KErrNone); CActiveScheduler::Start();