mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbcommon/src/mpxdbmanager.cpp
branchRCL_3
changeset 21 cb96c29156b2
parent 18 56b11cf8addb
equal deleted inserted replaced
19:a12246c97fcc 21:cb96c29156b2
   267             iTransactionCount = 0;
   267             iTransactionCount = 0;
   268             DoCommitL();
   268             DoCommitL();
   269             }
   269             }
   270 
   270 
   271         TInt count(iDatabaseHandles.Count());
   271         TInt count(iDatabaseHandles.Count());
   272         TBool ret = EFalse;
       
   273         for ( TInt i = 0; i < count ; ++i )
   272         for ( TInt i = 0; i < count ; ++i )
   274             {
   273             {
       
   274             if ( ! iDatabaseHandles[i].iOpen )
       
   275                 {
       
   276                 MPX_DEBUG1("CMPXDbManager::CopyDBsToRamL DB not open (assuming drive is not present)");
       
   277                 continue;
       
   278                 }
   275             if ( iDatabaseHandles[i].iUseRAMdb )
   279             if ( iDatabaseHandles[i].iUseRAMdb )
   276                 {
   280                 {
   277                 // already used
   281                 // already used
   278                 MPX_DEBUG1("CMPXDbManager::CopyDBsToRamL iUseRAMdb already ETrue");
   282                 MPX_DEBUG1("CMPXDbManager::CopyDBsToRamL iUseRAMdb already ETrue");
   279                 continue;
   283                 continue;
   280                 }
   284                 }
   281             CloseDatabaseAtIndexL( i ); // let leave: not much we can't do if we can't close the original DB
   285             CloseDatabaseAtIndexL( i ); // let leave: not much we can do if we can't close the original DB
   282             DoCopyDBToRam( i, aIsMTPInUse ); // copies if it can
   286             DoCopyDBToRam( i, aIsMTPInUse ); // copies if it can
   283             TRAPD( err, OpenDatabaseAtIndexL( i ) );
   287             TRAPD( err, OpenDatabaseAtIndexL( i ) );
   284             if ( err != KErrNone )
   288             if ( err != KErrNone )
   285                 {
   289                 {
   286                 MPX_DEBUG2("CMPXDbManager::CopyDBsToRamL OpenDatabaseAtIndexL leave=%d", err);
   290                 MPX_DEBUG2("CMPXDbManager::CopyDBsToRamL OpenDatabaseAtIndexL leave=%d", err);
   859 //
   863 //
   860 EXPORT_C void CMPXDbManager::CloseAllDatabases()
   864 EXPORT_C void CMPXDbManager::CloseAllDatabases()
   861     {
   865     {
   862     MPX_FUNC("CMPXDbManager::CloseAllDatabases");
   866     MPX_FUNC("CMPXDbManager::CloseAllDatabases");
   863 
   867 
   864     if (iInitialized)
   868     // Close all prepared statements if a db is closed
   865         {
   869     //
   866         // Close all prepared statements if a db is closed
   870     ResetPreparedQueries();
   867         //
   871 
   868         ResetPreparedQueries();
   872     TInt count(iDatabaseHandles.Count());
   869 
   873     for (TInt i = 0; i < count; ++i)
   870         TInt count(iDatabaseHandles.Count());
   874         {
   871         for (TInt i = 0; i < count; ++i)
   875         delete iDatabaseHandles[i].iAliasname;
   872             {
   876         iDatabaseHandles[i].iAliasname = 0;
   873             delete iDatabaseHandles[i].iAliasname;
       
   874             iDatabaseHandles[i].iAliasname = 0;
       
   875 #ifdef __RAMDISK_PERF_ENABLE 
   877 #ifdef __RAMDISK_PERF_ENABLE 
   876             RemoveDummyFile(i);            	
   878         RemoveDummyFile(i);            	
   877             delete iDatabaseHandles[i].iOrigFullFilePath;
   879         delete iDatabaseHandles[i].iOrigFullFilePath;
   878 			iDatabaseHandles[i].iOrigFullFilePath = 0;
   880         iDatabaseHandles[i].iOrigFullFilePath = 0;
   879             delete iDatabaseHandles[i].iTargetFullFilePath;
   881         delete iDatabaseHandles[i].iTargetFullFilePath;
   880 			iDatabaseHandles[i].iTargetFullFilePath = 0;
   882         iDatabaseHandles[i].iTargetFullFilePath = 0;
   881 #endif //__RAMDISK_PERF_ENABLE 
   883 #endif //__RAMDISK_PERF_ENABLE 
   882             }
   884         }
   883 
   885 
   884         iDatabaseHandles.Reset();
   886     iDatabaseHandles.Reset();
   885         iDatabase.Close();
   887     iDatabase.Close();
   886         iInitialized = EFalse;
   888     iInitialized = EFalse;
   887         }
       
   888     }
   889     }
   889 
   890 
   890 // ----------------------------------------------------------------------------
   891 // ----------------------------------------------------------------------------
   891 // Open all databases.
   892 // Open all databases.
   892 // ----------------------------------------------------------------------------
   893 // ----------------------------------------------------------------------------
  1724 
  1725 
  1725 	CreateTablesL(aDatabase, EFalse);
  1726 	CreateTablesL(aDatabase, EFalse);
  1726     }
  1727     }
  1727 
  1728 
  1728 // ----------------------------------------------------------------------------
  1729 // ----------------------------------------------------------------------------
       
  1730 // CleanupTransaction: close transaction when creating DB
       
  1731 // ----------------------------------------------------------------------------
       
  1732 //
       
  1733 static void CleanupTransaction(TAny * aDatabase)
       
  1734     {
       
  1735     TInt err = ((RSqlDatabase*)aDatabase)->Exec(KRollbackTransaction);
       
  1736     MPX_DEBUG2("CMPXDbManager CleanupTransaction rollback, error %d", err);
       
  1737     }
       
  1738     
       
  1739 // ----------------------------------------------------------------------------
  1729 // CMPXDbManager::CreateTablesL
  1740 // CMPXDbManager::CreateTablesL
  1730 // ----------------------------------------------------------------------------
  1741 // ----------------------------------------------------------------------------
  1731 //
  1742 //
  1732 void CMPXDbManager::CreateTablesL(
  1743 void CMPXDbManager::CreateTablesL(
  1733 	RSqlDatabase& aDatabase,
  1744 	RSqlDatabase& aDatabase,
  1734 	TBool aCorrupt)
  1745 	TBool aCorrupt)
  1735 	{
  1746 	{
       
  1747 	MPX_FUNC("CMPXDbManager::CreateTablesL");
       
  1748     TInt err = aDatabase.Exec(KBeginTransaction);
       
  1749     if (err < 0)
       
  1750        {
       
  1751        MPX_DEBUG2("SQL BEGIN TRANSACTION error %d", err);
       
  1752        User::Leave (err);
       
  1753        }
       
  1754     CleanupStack::PushL(TCleanupItem(&CleanupTransaction, &aDatabase));
  1736     TInt count(iTables.Count());
  1755     TInt count(iTables.Count());
  1737     for (TInt i = 0; i < count; ++i)
  1756     for (TInt i = 0; i < count; ++i)
  1738         {
  1757         {
  1739         iTables[i]->CreateTableL(aDatabase, aCorrupt);
  1758         iTables[i]->CreateTableL(aDatabase, aCorrupt);
  1740         }
  1759         }
       
  1760     err = aDatabase.Exec(KCommitTransaction);
       
  1761     if (err < 0)
       
  1762         {
       
  1763         MPX_DEBUG2("SQL COMMIT TRANSACTION error %d", err);
       
  1764         User::Leave (err);
       
  1765         }
       
  1766     CleanupStack::Pop();
  1741 	}
  1767 	}
  1742 
  1768 
  1743 // ----------------------------------------------------------------------------
  1769 // ----------------------------------------------------------------------------
  1744 // Opens root database on C-drive
  1770 // Opens root database on C-drive
  1745 // ----------------------------------------------------------------------------
  1771 // ----------------------------------------------------------------------------
  2015         {
  2041         {
  2016         MPX_DEBUG1("invalid driveId, leave with KErrNotReady");
  2042         MPX_DEBUG1("invalid driveId, leave with KErrNotReady");
  2017         User::Leave(KErrNotReady);
  2043         User::Leave(KErrNotReady);
  2018         }
  2044         }
  2019     
  2045     
  2020 #ifndef __RAMDISK_PERF_ENABLE 
       
  2021     
       
  2022     EnsureDiskSpaceL(aDrive);
  2046     EnsureDiskSpaceL(aDrive);
  2023     
       
  2024 #endif //__RAMDISK_PERF_ENABLE
       
  2025 
       
  2026     }
  2047     }
  2027     
  2048     
  2028 // ----------------------------------------------------------------------------
  2049 // ----------------------------------------------------------------------------
  2029 // Regenerate all databases.
  2050 // Regenerate all databases.
  2030 // ----------------------------------------------------------------------------
  2051 // ----------------------------------------------------------------------------
  2860 
  2881 
  2861     // handle other drives (eg. removable EDriveE)
  2882     // handle other drives (eg. removable EDriveE)
  2862     TInt count(iDatabaseHandles.Count());
  2883     TInt count(iDatabaseHandles.Count());
  2863     for (TInt i = 0; i < count; ++i)
  2884     for (TInt i = 0; i < count; ++i)
  2864         {
  2885         {
       
  2886         DatabaseHandle& database = iDatabaseHandles[i];
  2865         if (((KDbManagerAllDrives == aDrive) ||
  2887         if (((KDbManagerAllDrives == aDrive) ||
  2866             (aDrive == iDatabaseHandles[i].iDrive)) &&
  2888             (aDrive == database.iDrive)) &&
  2867             iDatabaseHandles[i].iOpen)
  2889             database.iOpen
       
  2890 #ifdef __RAMDISK_PERF_ENABLE
       
  2891             && !database.iUseRAMdb
       
  2892 #endif
       
  2893             )
  2868             {
  2894             {
  2869             if (SysUtil::DiskSpaceBelowCriticalLevelL(&iFs, 0,
  2895             if (SysUtil::DiskSpaceBelowCriticalLevelL(&iFs, 0,
  2870                 iDatabaseHandles[i].iDrive))
  2896                 database.iDrive))
  2871                 {
  2897                 {
  2872                 MPX_DEBUG1("CMPXDbManager::EnsureDiskSpaceL Error diskspace full");
  2898                 MPX_DEBUG1("CMPXDbManager::EnsureDiskSpaceL Error diskspace full");
  2873                 User::Leave(KErrDiskFull);
  2899                 User::Leave(KErrDiskFull);
  2874                 }
  2900                 }
  2875             }
  2901             }
  2876 
  2902 
  2877         if (aDrive == iDatabaseHandles[i].iDrive)
  2903         if (aDrive == database.iDrive)
  2878             {
  2904             {
  2879             // exit if just one drive to check
  2905             // exit if just one drive to check
  2880             break;
  2906             break;
  2881             }
  2907             }
  2882         }
  2908         }