sl@0: // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "LogServDatabaseMarshall.h" sl@0: #include "logservpanic.h" sl@0: #include "LogServCacheConfig.h" sl@0: #include "LogServCacheStrings.h" sl@0: #include "LogServCacheTypes.h" sl@0: #include "LogServBackupInterface.h" sl@0: #include "LogServResourceInterpreter.h" sl@0: #include "LogServDatabaseChangeInterface.h" sl@0: #include "LogServSqlStrings.h" sl@0: #include "LOGREPDEFS.H" sl@0: sl@0: sl@0: // Constants sl@0: const TInt KExpectedNumberOfTables = 4; // Should match the code in CreateTablesL sl@0: sl@0: // Literal constants sl@0: _LIT(KLogDatabaseName,"Logdbu.dat"); sl@0: sl@0: sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: // -----> CLogServDatabaseMarshall (source) sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: CLogServDatabaseMarshall::CLogServDatabaseMarshall(RFs& aFsSession, sl@0: CLogServResourceInterpreter& aResourceInterface, sl@0: MLogServBackupInterface& aBackupInterface) sl@0: : iFsSession(aFsSession), iResourceInterface(aResourceInterface), iBackupInterface(aBackupInterface) sl@0: { sl@0: } sl@0: sl@0: CLogServDatabaseMarshall::~CLogServDatabaseMarshall() sl@0: { sl@0: iBackupInterface.BIObserverRemove(*this); sl@0: // sl@0: delete iDatabaseName; sl@0: delete iCacheStrings; sl@0: delete iCacheTypes; sl@0: delete iCacheConfig; sl@0: delete iSecurity; sl@0: delete iEventType; sl@0: // sl@0: iDatabase.Close(); sl@0: iStandardTypeUids.Close(); sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::ConstructL() sl@0: { sl@0: iBackupInterface.BIObserverAddL(*this, MLogServBackupInterface::EObjectDatabaseMarshall); sl@0: // sl@0: iSecurity = CLogServSecurity::NewL(iResourceInterface); sl@0: // sl@0: iEventType = CLogEventType::NewL(); sl@0: sl@0: DatabaseLocateL(); sl@0: DatabaseOpenL(); sl@0: RestoreStandardTypesL(); sl@0: sl@0: iCacheTypes->CopyStandardTypeUidsL(iStandardTypeUids); sl@0: } sl@0: sl@0: CLogServDatabaseMarshall* CLogServDatabaseMarshall::NewL(RFs& aFsSession, sl@0: CLogServResourceInterpreter& aResourceInterface, sl@0: MLogServBackupInterface& aBackupInterface) sl@0: { sl@0: CLogServDatabaseMarshall* self = new(ELeave) CLogServDatabaseMarshall(aFsSession, aResourceInterface, aBackupInterface); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: TInt CLogServDatabaseMarshall::DTIBegin() sl@0: { sl@0: const TInt backupError = iBackupInterface.BIErrorValueForCurrentState(); sl@0: if (backupError != KErrNone) sl@0: return backupError; sl@0: sl@0: __ASSERT_DEBUG(!iDatabase.InTransaction(), Panic(ELogBeginInTransaction)); sl@0: return iDatabase.Begin(); sl@0: } sl@0: sl@0: TInt CLogServDatabaseMarshall::DTICommitAndEnd() sl@0: { sl@0: __ASSERT_DEBUG(iDatabase.InTransaction(), Panic(ELogCommitNotInTransaction)); sl@0: TInt err = iDatabase.Commit(); sl@0: if (err == KErrNone && iCacheStrings != NULL) sl@0: { sl@0: iCacheStrings->Commit(); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::DTIRollBack() sl@0: { sl@0: __ASSERT_DEBUG(iDatabase.InTransaction(), Panic(ELogRollbackNotInTransaction)); sl@0: iDatabase.Rollback(); sl@0: if (iCacheStrings != NULL) sl@0: { sl@0: iCacheStrings->Rollback(); sl@0: } sl@0: } sl@0: sl@0: TInt CLogServDatabaseMarshall::DTIExecuteSql(const TDesC& aStatement, TDbTextComparison aComparison) sl@0: { sl@0: return iDatabase.Execute(aStatement, aComparison); sl@0: } sl@0: sl@0: TBool CLogServDatabaseMarshall::DTIInTransaction() const sl@0: { sl@0: return iDatabase.InTransaction(); sl@0: } sl@0: sl@0: TBool CLogServDatabaseMarshall::DTIDatabaseIsDamaged() const sl@0: { sl@0: return iDatabase.IsDamaged(); sl@0: } sl@0: sl@0: CLogServResourceInterpreter& CLogServDatabaseMarshall::DTIResourceInterface() const sl@0: { sl@0: return iResourceInterface; sl@0: } sl@0: sl@0: MLogServDatabaseChangeInterface& CLogServDatabaseMarshall::DTIChangeInterface() const sl@0: { sl@0: __ASSERT_ALWAYS(iChangeInterface, Panic(ELogNoChangeInterfacePointer)); sl@0: return *iChangeInterface; sl@0: } sl@0: sl@0: CLogServCacheStrings& CLogServDatabaseMarshall::DTICacheStrings() const sl@0: { sl@0: __ASSERT_ALWAYS(iCacheStrings, Panic(ELogCacheAccessDuringBackupStrings)); sl@0: return *iCacheStrings; sl@0: } sl@0: sl@0: CLogServCacheTypes& CLogServDatabaseMarshall::DTICacheTypes() const sl@0: { sl@0: __ASSERT_ALWAYS(iCacheTypes, Panic(ELogCacheAccessDuringBackupTypes)); sl@0: return *iCacheTypes; sl@0: } sl@0: sl@0: CLogServCacheConfig& CLogServDatabaseMarshall::DTICacheConfig() const sl@0: { sl@0: __ASSERT_ALWAYS(iCacheConfig, Panic(ELogCacheAccessDuringBackupConfig)); sl@0: return *iCacheConfig; sl@0: } sl@0: sl@0: RDbDatabase& CLogServDatabaseMarshall::DTIDatabase() sl@0: { sl@0: return iDatabase; sl@0: } sl@0: sl@0: TBool CLogServDatabaseMarshall::DTIIsAllowed(TEventOp aEventOp, const RMessage2& aMessage, TUid aEventType, const char* aDiagnostic) const sl@0: { sl@0: return iSecurity->IsAllowed(aMessage, aEventType, aEventOp, aDiagnostic); sl@0: } sl@0: sl@0: const RArray& CLogServDatabaseMarshall::DTIUidsOfStandardTypes() sl@0: { sl@0: return iStandardTypeUids; sl@0: } sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void CLogServDatabaseMarshall::BOHandleEventL(TLogServBackupEvent aEvent) sl@0: { sl@0: switch(aEvent) sl@0: { sl@0: case EBackupStarting: sl@0: { sl@0: //Destroy config, types and strings caches sl@0: delete iCacheConfig; sl@0: iCacheConfig = NULL; sl@0: delete iCacheStrings; sl@0: iCacheStrings = NULL; sl@0: delete iCacheTypes; sl@0: iCacheTypes = NULL; sl@0: //Close the database sl@0: iDatabase.Close(); sl@0: } sl@0: break; sl@0: sl@0: case EBackupEnded: sl@0: { sl@0: // Re-open the database and create config, types and strings caches sl@0: DatabaseOpenL(); sl@0: // reset views as a different database is being restored sl@0: DTIChangeInterface().DCISubmitGlobalChangeContextL(KLogClientChangeEventRefreshView); sl@0: } sl@0: break; sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: ///////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void CLogServDatabaseMarshall::DatabaseLocateL() sl@0: { sl@0: // Get drive for database sl@0: TDriveUnit driveUnit(static_cast(RFs::GetSystemDrive())); sl@0: TDriveName name(driveUnit.Name()); sl@0: sl@0: TFileName path; sl@0: iFsSession.PrivatePath(path); sl@0: sl@0: // Ensure database path exists sl@0: TParse parse; sl@0: User::LeaveIfError(parse.Set(path, &name, NULL)); sl@0: path = parse.FullName(); sl@0: sl@0: TInt error = iFsSession.MkDirAll(path); sl@0: if (error != KErrAlreadyExists) sl@0: User::LeaveIfError(error); sl@0: sl@0: path += KLogDatabaseName; sl@0: iDatabaseName = path.AllocL(); sl@0: } sl@0: sl@0: /** sl@0: Opens the LogEng database. sl@0: @return KErrNone, If the "database open" operation completes successfully. sl@0: If the "database open" operation fails the function returns the repported error code. sl@0: KErrCorrupt, If the database is opened successfully but is damaged, then the function returns KErrCorrupt. sl@0: */ sl@0: TInt CLogServDatabaseMarshall::DoDbOpen() sl@0: { sl@0: LOGTEXT2("CLogServDatabaseMarshall::DatabaseOpenL() - attempting to open db: %S", iDatabaseName); sl@0: #ifdef LOGGING_ENABLED sl@0: TEntry entry; sl@0: if (iFsSession.Entry(*iDatabaseName, entry) == KErrNone) sl@0: { sl@0: LOGTEXT2("CLogServDatabaseMarshall::DatabaseOpenL() - Database file: %S DOES exist", iDatabaseName); sl@0: } sl@0: else sl@0: { sl@0: LOGTEXT2("CLogServDatabaseMarshall::DatabaseOpenL() - Database file: %S NOT FOUND", iDatabaseName); sl@0: } sl@0: #endif sl@0: // Open database sl@0: TInt err = iDatabase.Open(iFsSession, DatabaseName()); sl@0: LOGTEXT2("CLogServDatabaseMarshall::DatabaseOpenL() - attempting to open DMBS database resulted in error: %d", error); sl@0: // Check if the database is damaged. If it is set the error to KErrCorrupt so that it sl@0: // will be deleted. sl@0: if ((err == KErrNone) && iDatabase.IsDamaged()) sl@0: { sl@0: err = KErrCorrupt; sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: Check if the database table count is the expected one - KExpectedNumberOfTables. sl@0: @return True, The database tables count is KExpectedNumberOfTables, sl@0: False, The database tables count is not KExpectedNumberOfTables; sl@0: @leave KErrNoMemory, an out of memory condition has occurred; sl@0: Note that the function may leave with database specific errors or sl@0: other system-wide error codes. sl@0: */ sl@0: TBool CLogServDatabaseMarshall::DbTableCntCheckL() sl@0: { sl@0: CDbTableNames* tables = iDatabase.TableNamesL(); sl@0: TInt numberOfTables = tables->Count(); sl@0: delete tables; sl@0: LOGTEXT2("CLogServDatabaseMarshall::DatabaseOpenL() - Number of tables: %d", numberOfTables); sl@0: return numberOfTables == KExpectedNumberOfTables; sl@0: } sl@0: sl@0: /** sl@0: Alters the "Event" table if the number column length is not KLogMaxNumberLength. sl@0: @return KErrNone, The "alter" operation has completed successfully, system wide or database specific error code otherwise. sl@0: */ sl@0: TInt CLogServDatabaseMarshall::AlterEventTblIfOldFmt(CDbColSet& aEventTblColSet) sl@0: { sl@0: const TDbCol* numberCol = aEventTblColSet.Col(KLogFieldEventNumberString); sl@0: __ASSERT_DEBUG(numberCol != NULL, User::Invariant()); sl@0: TInt err = KErrNone; sl@0: // check the column width is correct sl@0: if(numberCol->iMaxLength != KLogMaxNumberLength) sl@0: { sl@0: //The column width is not correct, so this is an old format database. sl@0: //Modify the database so the number length is KLogMaxNumberLength. sl@0: (const_cast (numberCol))->iMaxLength = KLogMaxNumberLength; sl@0: err = iDatabase.AlterTable(KLogNameEventString, aEventTblColSet); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: sl@0: /** sl@0: Alters the "Event" table if the the table does not have "SimId" column. sl@0: @return KErrNone, The "alter" operation has completed successfully, system wide or database specific error code otherwise. sl@0: @leave KErrNoMemory, an out of memory condition has occurred; sl@0: Some other failure codes, not related to the "alter" opertaion. sl@0: */ sl@0: TInt CLogServDatabaseMarshall::AlterEventTblIfNoSimIdL(CDbColSet& aEventTblColSet) sl@0: {//Compiled only when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM macro is defined sl@0: const TDbCol* simIdCol = aEventTblColSet.Col(KLogFieldEventSimId); sl@0: TInt err = KErrNone; sl@0: if(!simIdCol) sl@0: { sl@0: TDbCol col(KLogFieldEventSimId, EDbColUint32); sl@0: aEventTblColSet.AddL(col); sl@0: err = iDatabase.AlterTable(KLogNameEventString, aEventTblColSet); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: #endif sl@0: sl@0: /** sl@0: Checks the database structure and alters the tables if that's an old format database. sl@0: @return KErrNone, The "alter" operation has completed successfully, system wide or database specific error code otherwise. sl@0: @leave KErrNoMemory, an out of memory condition has occurred; sl@0: Some other failure codes, not related to the "alter" opertaion. sl@0: */ sl@0: TInt CLogServDatabaseMarshall::AlterDbIfOldFmtL() sl@0: { sl@0: CDbColSet* tableEventCol = iDatabase.ColSetL(KLogNameEventString); sl@0: CleanupStack::PushL(tableEventCol); sl@0: //Check for old format database which had MaxNumberLength =32 sl@0: TInt err = AlterEventTblIfOldFmt(*tableEventCol); sl@0: #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM sl@0: //Check if the "SimId" column is present sl@0: if(err == KErrNone) sl@0: { sl@0: err = AlterEventTblIfNoSimIdL(*tableEventCol); sl@0: } sl@0: #endif sl@0: CleanupStack::PopAndDestroy(tableEventCol); sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: Closes and deletes the LogEng database. In _DEBUG builds the "delete file" error will be printed out. sl@0: */ sl@0: void CLogServDatabaseMarshall::DbDelete() sl@0: { sl@0: iDatabase.Close(); sl@0: #ifdef _DEBUG sl@0: //Do not remove the statement bellow. In _DEBUG builds it forms a single "TInt err2 = iFsSession.Delete(DatabaseName());" statement. sl@0: TInt err2 = sl@0: #endif sl@0: iFsSession.Delete(DatabaseName()); sl@0: #ifdef _DEBUG sl@0: if((err2 != KErrNone) && (err2 != KErrNotFound)) sl@0: { sl@0: RDebug::Print(_L("CLogServDatabaseMarshall::DatabaseOpenL() - Failed to delete file. Error = %d"), err2); sl@0: } sl@0: #endif sl@0: } sl@0: sl@0: /** sl@0: Attempts to create the LogEng database and tables. sl@0: @return KErrNoNone, The database was created successfully, system wide or database specific error otherwise. sl@0: */ sl@0: TInt CLogServDatabaseMarshall::DbCreate() sl@0: { sl@0: // Try and create the database sl@0: LOGTEXT("CLogServDatabaseMarshall::DatabaseOpenL() - trying to create database"); sl@0: TRAPD(err, DatabaseCreateL(DatabaseName())); sl@0: LOGTEXT2("CLogServDatabaseMarshall::DatabaseOpenL() - creation error was: %d", error); sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: Creates config and string LogEng caches. Finishes the initialization of the event types cache. sl@0: @leave KErrNoMemory, an out of memory condition has occurred; sl@0: Note that the function may leave with database specific errors or sl@0: other system-wide error codes. sl@0: */ sl@0: void CLogServDatabaseMarshall::CreateCachesL() sl@0: { sl@0: // Create other cache objects (these require the database to be already opened) sl@0: LOGTEXT("CLogServDatabaseMarshall::DatabaseOpenL() - creating config cache"); sl@0: iCacheConfig = CLogServCacheConfig::NewL(*this); sl@0: LOGTEXT("CLogServDatabaseMarshall::DatabaseOpenL() - creating string cache"); sl@0: iCacheStrings = CLogServCacheStrings::NewL(*this); sl@0: // Finish the type cache initialization sl@0: LOGTEXT("CLogServDatabaseMarshall::DatabaseOpenL() - initializing type cache"); sl@0: iCacheTypes->InitializeL(); sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::DatabaseOpenL() sl@0: { sl@0: // Create the cache objects - objects need to be put into the cache as sl@0: // soon as the database is open. sl@0: LOGTEXT("CLogServDatabaseMarshall::DatabaseOpenL() - creating type cache"); sl@0: iCacheTypes = CLogServCacheTypes::NewL(*this); sl@0: TInt err = DoDbOpen(); sl@0: // Check we have the expected number of tables sl@0: if(err == KErrNone && !DbTableCntCheckL()) sl@0: { sl@0: err = KErrCorrupt; sl@0: } sl@0: // Check a compaction can be performed. If it can't it indicates a serious problem? sl@0: if(err == KErrNone && (err = iDatabase.Compact()) != KErrNone) sl@0: { sl@0: err = KErrCorrupt; sl@0: } sl@0: if(err == KErrNone) sl@0: { sl@0: err = CLogServDatabaseMarshall::AlterDbIfOldFmtL(); sl@0: } sl@0: // If the database failed to open, delete and recreate. sl@0: if(err == KErrNotFound || err == KErrCorrupt || err == KErrArgument || err == KErrEof) sl@0: { sl@0: DbDelete(); sl@0: // Try and create the database sl@0: err = DbCreate(); sl@0: if(err != KErrNone) sl@0: { sl@0: DbDelete(); sl@0: } sl@0: } sl@0: User::LeaveIfError(err); sl@0: CreateCachesL(); sl@0: // At this point, its safe to tell the backup interface what file it has to watch sl@0: LOGTEXT("CLogServDatabaseMarshall::DatabaseOpenL() - registering database filename with backup interface"); sl@0: iBackupInterface.BISetDatabaseNameL(DatabaseName()); sl@0: LOGTEXT("CLogServDatabaseMarshall::DatabaseOpenL() - end"); sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::DatabaseCreateL(const TDesC& aName) sl@0: { sl@0: User::LeaveIfError(iDatabase.Replace(iFsSession, aName)); sl@0: CreateTablesL(); sl@0: } sl@0: sl@0: // Note: Number of tables HAS to match KExpectedNumberOfTables sl@0: void CLogServDatabaseMarshall::CreateTablesL() sl@0: { sl@0: DTIBeginWithRollBackProtectionLC(); sl@0: sl@0: // Create event table sl@0: TheSql.Format(KLogTableEventString, KLogMaxRemotePartyLength, KLogMaxSubjectLength, KLogMaxNumberLength); sl@0: User::LeaveIfError(iDatabase.Execute(TheSql)); sl@0: MakeColumnAutoIncremetingL(KLogNameEventString, KLogFieldIdString); sl@0: sl@0: // Create event type table sl@0: TheSql.Format(KLogTableTypeString, KLogMaxDescriptionLength); sl@0: User::LeaveIfError(iDatabase.Execute(TheSql)); sl@0: MakeColumnAutoIncremetingL(KLogNameTypeString, KLogFieldIdString); sl@0: sl@0: // Create string list table sl@0: TheSql.Format(KLogTableStringString, KLogMaxSharedStringLength); sl@0: User::LeaveIfError(iDatabase.Execute(TheSql)); sl@0: MakeColumnAutoIncremetingL(KLogNameStringString, KLogFieldIdString); sl@0: sl@0: // Create configuration table sl@0: TheSql.Copy(KLogTableConfigString); sl@0: User::LeaveIfError(iDatabase.Execute(TheSql)); sl@0: sl@0: // Create the index sl@0: CreateIndiciesL(); sl@0: sl@0: // Set the initial configuration sl@0: CreateConfigurationL(); sl@0: sl@0: // Load standard event types sl@0: CreateTypesL(); sl@0: sl@0: DTICommitAndCancelRollbackProtectionL(); sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::CreateTypesL(TBool aReadOnly) sl@0: { sl@0: // Get the array size sl@0: TResourceReader reader; sl@0: iResourceInterface.CreateResourceReaderLC(reader, R_LOG_INITIAL_EVENTS); sl@0: sl@0: // Create them sl@0: DTICacheTypes().CreateStandardTypesL(reader, aReadOnly); sl@0: sl@0: CleanupStack::PopAndDestroy(); // reader sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::CreateIndiciesL() sl@0: { sl@0: // Get the array size sl@0: TResourceReader reader; sl@0: iResourceInterface.CreateResourceReaderLC(reader, R_LOG_INDEXES); sl@0: sl@0: const TInt indexes = reader.ReadInt16(); sl@0: sl@0: // Read in the array sl@0: for(TInt c1 = 0; c1 < indexes; c1++) sl@0: { sl@0: const TPtrC name(reader.ReadTPtrC()); sl@0: const TPtrC table(reader.ReadTPtrC()); sl@0: sl@0: // Get the number of keys sl@0: const TInt keys = reader.ReadInt16(); sl@0: sl@0: CDbKey* key = CDbKey::NewLC(); sl@0: sl@0: for(TInt c2 = 0; c2 < keys; c2++) sl@0: { sl@0: TPtrC col = reader.ReadTPtrC(); sl@0: TUint order = reader.ReadUint16(); sl@0: TInt len = reader.ReadInt16(); sl@0: sl@0: // Add the key sl@0: key->AddL(TDbKeyCol(col, len, (TDbKeyCol::TOrder)order)); sl@0: } sl@0: sl@0: // Make key unique if required sl@0: if (reader.ReadInt8()) sl@0: key->MakeUnique(); sl@0: sl@0: // Set comparison sl@0: const TDbTextComparison comparison = static_cast(reader.ReadInt8()); sl@0: key->SetComparison(comparison); sl@0: sl@0: // Create the index sl@0: User::LeaveIfError(iDatabase.CreateIndex(name, table, *key)); sl@0: sl@0: CleanupStack::PopAndDestroy(key); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(); // reader sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::CreateConfigurationL() sl@0: { sl@0: // Load the resource/repository file default configuration sl@0: // The precedence is given to the reading from the repository file. sl@0: TLogConfig config; sl@0: sl@0: CRepository* repository = NULL; sl@0: TRAPD(res, repository = CRepository::NewL(KUidLogengRepository)); sl@0: if (res == KErrNone) sl@0: { sl@0: CleanupStack::PushL(repository); sl@0: ReadRepositoryFileConfigurationL(config, *repository); sl@0: CleanupStack::PopAndDestroy(repository); sl@0: } sl@0: else if (res == KErrCorrupt) sl@0: { sl@0: User::Leave(res); sl@0: } sl@0: else sl@0: { sl@0: ReadResourceFileConfigurationL(config); sl@0: } sl@0: // Insert the column sl@0: TheSql.Format(KLogSqlInsertConfigString, config.iMaxLogSize, config.iMaxRecentLogSize, config.iMaxEventAge); sl@0: User::LeaveIfError(iDatabase.Execute(TheSql)); sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::ReadRepositoryFileConfigurationL(TLogConfig& aConfig, CRepository& repository) const sl@0: { sl@0: TInt maxLogSize; sl@0: TInt maxRecentLogSize; sl@0: TInt maxEventAge; sl@0: // sl@0: User::LeaveIfError(repository.Get(KMaxLogSizeRepKey, maxLogSize)); sl@0: aConfig.iMaxLogSize = static_cast (maxLogSize); sl@0: User::LeaveIfError(repository.Get(KMaxRecentLogSizeRepKey, maxRecentLogSize)); sl@0: aConfig.iMaxRecentLogSize = static_cast (maxRecentLogSize); sl@0: User::LeaveIfError(repository.Get(KMaxEventAgeRepKey, maxEventAge)); sl@0: aConfig.iMaxEventAge = static_cast (maxEventAge); sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::ReadResourceFileConfigurationL(TLogConfig& aConfig) const sl@0: { sl@0: TResourceReader reader; sl@0: iResourceInterface.CreateResourceReaderLC(reader, R_LOG_INITIAL_CONFIG); sl@0: // sl@0: aConfig.iMaxLogSize = static_cast(reader.ReadUint16()); sl@0: aConfig.iMaxRecentLogSize = static_cast(reader.ReadUint8()); sl@0: aConfig.iMaxEventAge = static_cast(reader.ReadUint32()); sl@0: // sl@0: CleanupStack::PopAndDestroy(); // reader sl@0: } sl@0: sl@0: void CLogServDatabaseMarshall::MakeColumnAutoIncremetingL(const TDesC& aTable, const TDesC& aColumn) sl@0: { sl@0: CDbColSet* newTable = iDatabase.ColSetL(aTable); sl@0: CleanupStack::PushL(newTable); sl@0: sl@0: const TDbCol* oldCol = newTable->Col(aColumn); sl@0: __ASSERT_DEBUG(oldCol != NULL, Panic(ELogNoSuchColumn)); sl@0: sl@0: TDbCol newCol = *oldCol; sl@0: newCol.iAttributes |= TDbCol::EAutoIncrement; sl@0: sl@0: newTable->Remove(aColumn); sl@0: newTable->AddL(newCol); sl@0: sl@0: User::LeaveIfError(iDatabase.DropTable(aTable)); sl@0: User::LeaveIfError(iDatabase.CreateTable(aTable, *newTable)); sl@0: sl@0: CleanupStack::PopAndDestroy(newTable); sl@0: } sl@0: