diff -r a12246c97fcc -r cb96c29156b2 mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbcommon/src/mpxdbmanager.cpp --- a/mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbcommon/src/mpxdbmanager.cpp Wed Jun 09 09:38:28 2010 +0300 +++ b/mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbcommon/src/mpxdbmanager.cpp Mon Jun 21 15:37:19 2010 +0300 @@ -269,16 +269,20 @@ } TInt count(iDatabaseHandles.Count()); - TBool ret = EFalse; for ( TInt i = 0; i < count ; ++i ) { + if ( ! iDatabaseHandles[i].iOpen ) + { + MPX_DEBUG1("CMPXDbManager::CopyDBsToRamL DB not open (assuming drive is not present)"); + continue; + } if ( iDatabaseHandles[i].iUseRAMdb ) { // already used MPX_DEBUG1("CMPXDbManager::CopyDBsToRamL iUseRAMdb already ETrue"); continue; } - CloseDatabaseAtIndexL( i ); // let leave: not much we can't do if we can't close the original DB + CloseDatabaseAtIndexL( i ); // let leave: not much we can do if we can't close the original DB DoCopyDBToRam( i, aIsMTPInUse ); // copies if it can TRAPD( err, OpenDatabaseAtIndexL( i ) ); if ( err != KErrNone ) @@ -861,30 +865,27 @@ { MPX_FUNC("CMPXDbManager::CloseAllDatabases"); - if (iInitialized) - { - // Close all prepared statements if a db is closed - // - ResetPreparedQueries(); + // Close all prepared statements if a db is closed + // + ResetPreparedQueries(); - TInt count(iDatabaseHandles.Count()); - for (TInt i = 0; i < count; ++i) - { - delete iDatabaseHandles[i].iAliasname; - iDatabaseHandles[i].iAliasname = 0; + TInt count(iDatabaseHandles.Count()); + for (TInt i = 0; i < count; ++i) + { + delete iDatabaseHandles[i].iAliasname; + iDatabaseHandles[i].iAliasname = 0; #ifdef __RAMDISK_PERF_ENABLE - RemoveDummyFile(i); - delete iDatabaseHandles[i].iOrigFullFilePath; - iDatabaseHandles[i].iOrigFullFilePath = 0; - delete iDatabaseHandles[i].iTargetFullFilePath; - iDatabaseHandles[i].iTargetFullFilePath = 0; + RemoveDummyFile(i); + delete iDatabaseHandles[i].iOrigFullFilePath; + iDatabaseHandles[i].iOrigFullFilePath = 0; + delete iDatabaseHandles[i].iTargetFullFilePath; + iDatabaseHandles[i].iTargetFullFilePath = 0; #endif //__RAMDISK_PERF_ENABLE - } + } - iDatabaseHandles.Reset(); - iDatabase.Close(); - iInitialized = EFalse; - } + iDatabaseHandles.Reset(); + iDatabase.Close(); + iInitialized = EFalse; } // ---------------------------------------------------------------------------- @@ -1726,6 +1727,16 @@ } // ---------------------------------------------------------------------------- +// CleanupTransaction: close transaction when creating DB +// ---------------------------------------------------------------------------- +// +static void CleanupTransaction(TAny * aDatabase) + { + TInt err = ((RSqlDatabase*)aDatabase)->Exec(KRollbackTransaction); + MPX_DEBUG2("CMPXDbManager CleanupTransaction rollback, error %d", err); + } + +// ---------------------------------------------------------------------------- // CMPXDbManager::CreateTablesL // ---------------------------------------------------------------------------- // @@ -1733,11 +1744,26 @@ RSqlDatabase& aDatabase, TBool aCorrupt) { + MPX_FUNC("CMPXDbManager::CreateTablesL"); + TInt err = aDatabase.Exec(KBeginTransaction); + if (err < 0) + { + MPX_DEBUG2("SQL BEGIN TRANSACTION error %d", err); + User::Leave (err); + } + CleanupStack::PushL(TCleanupItem(&CleanupTransaction, &aDatabase)); TInt count(iTables.Count()); for (TInt i = 0; i < count; ++i) { iTables[i]->CreateTableL(aDatabase, aCorrupt); } + err = aDatabase.Exec(KCommitTransaction); + if (err < 0) + { + MPX_DEBUG2("SQL COMMIT TRANSACTION error %d", err); + User::Leave (err); + } + CleanupStack::Pop(); } // ---------------------------------------------------------------------------- @@ -2017,12 +2043,7 @@ User::Leave(KErrNotReady); } -#ifndef __RAMDISK_PERF_ENABLE - EnsureDiskSpaceL(aDrive); - -#endif //__RAMDISK_PERF_ENABLE - } // ---------------------------------------------------------------------------- @@ -2862,19 +2883,24 @@ TInt count(iDatabaseHandles.Count()); for (TInt i = 0; i < count; ++i) { + DatabaseHandle& database = iDatabaseHandles[i]; if (((KDbManagerAllDrives == aDrive) || - (aDrive == iDatabaseHandles[i].iDrive)) && - iDatabaseHandles[i].iOpen) + (aDrive == database.iDrive)) && + database.iOpen +#ifdef __RAMDISK_PERF_ENABLE + && !database.iUseRAMdb +#endif + ) { if (SysUtil::DiskSpaceBelowCriticalLevelL(&iFs, 0, - iDatabaseHandles[i].iDrive)) + database.iDrive)) { MPX_DEBUG1("CMPXDbManager::EnsureDiskSpaceL Error diskspace full"); User::Leave(KErrDiskFull); } } - if (aDrive == iDatabaseHandles[i].iDrive) + if (aDrive == database.iDrive) { // exit if just one drive to check break;