mtpfws/mtpfw/src/cmtppkgidstore.cpp
changeset 49 c20dd21d1eb4
parent 0 d0791faffa3f
equal deleted inserted replaced
41:2c19c7cf5550 49:c20dd21d1eb4
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 #include "cmtppkgidstore.h"
    16 #include "cmtppkgidstore.h"
    17 #include "dbutility.h"
    17 #include "dbutility.h"
       
    18 #include "mtpdebug.h"
       
    19 #include "OstTraceDefinitions.h"
       
    20 #ifdef OST_TRACE_COMPILER_IN_USE
       
    21 #include "cmtppkgidstoreTraces.h"
       
    22 #endif
       
    23 
    18 
    24 
    19 /**
    25 /**
    20 Two-phase construction
    26 Two-phase construction
    21 @param aDatabase    The reference to the database object
    27 @param aDatabase    The reference to the database object
    22 @return pointer to the created <pkgid, dpid> map instance
    28 @return pointer to the created <pkgid, dpid> map instance
    56     _LIT(KSQLPkgIDTableName, "PkgIDStore");
    62     _LIT(KSQLPkgIDTableName, "PkgIDStore");
    57     if (!DBUtility::IsTableExistsL(iDatabase, KSQLPkgIDTableName))
    63     if (!DBUtility::IsTableExistsL(iDatabase, KSQLPkgIDTableName))
    58         {
    64         {
    59         _LIT(KSQLCreatePkgIDTableText,
    65         _LIT(KSQLCreatePkgIDTableText,
    60             "CREATE TABLE PkgIDStore (DataProviderId UNSIGNED INTEGER, PkgId UNSIGNED INTEGER)");
    66             "CREATE TABLE PkgIDStore (DataProviderId UNSIGNED INTEGER, PkgId UNSIGNED INTEGER)");
    61         User::LeaveIfError(iDatabase.Execute(KSQLCreatePkgIDTableText));            
    67         LEAVEIFERROR(iDatabase.Execute(KSQLCreatePkgIDTableText),
       
    68                 OstTrace0( TRACE_ERROR, CMTPPKGIDSTORE_CREATEPKGIDSTORETABLEL, "TABLE PkgIDStore create failed!"));
    62         }
    69         }
    63     _LIT(KSQLGetPKGID, "SELECT * FROM PkgIDStore");
    70     _LIT(KSQLGetPKGID, "SELECT * FROM PkgIDStore");
    64     iSqlStatement.Format(KSQLGetPKGID);    
    71     iSqlStatement.Format(KSQLGetPKGID);    
    65     RDbView view;
    72     RDbView view;
    66     CleanupClosePushL(view);
    73     CleanupClosePushL(view);
    67     User::LeaveIfError(view.Prepare(iDatabase, TDbQuery(iSqlStatement)));
    74     LEAVEIFERROR(view.Prepare(iDatabase, TDbQuery(iSqlStatement)),
    68     User::LeaveIfError(view.Evaluate());
    75             OstTrace0( TRACE_ERROR, DUP1_CMTPPKGIDSTORE_CREATEPKGIDSTORETABLEL, "view for PkgIDStore prepare failed!" ));   
       
    76     LEAVEIFERROR(view.Evaluate(),
       
    77             OstTrace0( TRACE_ERROR, DUP2_CMTPPKGIDSTORE_CREATEPKGIDSTORETABLEL, "view evaluate failed!"));   
    69     while (view.NextL())
    78     while (view.NextL())
    70         {
    79         {
    71         view.GetL();
    80         view.GetL();
    72         iDPIDs.AppendL(view.ColInt64(EPkgIDStoreDataProviderId));
    81         iDPIDs.AppendL(view.ColInt64(EPkgIDStoreDataProviderId));
    73         iPkgIDs.AppendL(view.ColInt64(EPkgIDStorePKGID));
    82         iPkgIDs.AppendL(view.ColInt64(EPkgIDStorePKGID));
    91     TRAPD(err, index = iDPIDs.FindL(aDPId));
   100     TRAPD(err, index = iDPIDs.FindL(aDPId));
    92     if(KErrNotFound == err)
   101     if(KErrNotFound == err)
    93         {
   102         {
    94         _LIT(KSQLInsertPkgIDObjectText, "INSERT INTO PkgIDStore (DataProviderId, PkgId) VALUES (%u, %u)");
   103         _LIT(KSQLInsertPkgIDObjectText, "INSERT INTO PkgIDStore (DataProviderId, PkgId) VALUES (%u, %u)");
    95         iSqlStatement.Format(KSQLInsertPkgIDObjectText, aDPId, aPkgId);
   104         iSqlStatement.Format(KSQLInsertPkgIDObjectText, aDPId, aPkgId);
    96         User::LeaveIfError(iDatabase.Execute(iSqlStatement));
   105         LEAVEIFERROR(iDatabase.Execute(iSqlStatement),
       
   106                 OstTrace0( TRACE_ERROR, CMTPPKGIDSTORE_INSERTPKGIDL, "INSERT INTO PkgIDStore failed!" ));
    97         iDPIDs.AppendL(aDPId);
   107         iDPIDs.AppendL(aDPId);
    98         iPkgIDs.AppendL(aPkgId);
   108         iPkgIDs.AppendL(aPkgId);
    99         }
   109         }
   100     else
   110     else
   101         {
   111         {
   102         if(aPkgId != iPkgIDs[index])
   112         if(aPkgId != iPkgIDs[index])
   103             {
   113             {
   104             _LIT(KSQLSetPkgIDObjectText, "UPDATE PkgIDStore SET PkgId = %u WHERE DataProviderId = %u");
   114             _LIT(KSQLSetPkgIDObjectText, "UPDATE PkgIDStore SET PkgId = %u WHERE DataProviderId = %u");
   105             iSqlStatement.Format(KSQLSetPkgIDObjectText, aPkgId,aDPId);
   115             iSqlStatement.Format(KSQLSetPkgIDObjectText, aPkgId,aDPId);
   106             User::LeaveIfError(iDatabase.Execute(iSqlStatement));
   116             LEAVEIFERROR(iDatabase.Execute(iSqlStatement),
       
   117                     OstTrace0( TRACE_ERROR, DUP1_CMTPPKGIDSTORE_INSERTPKGIDL, "UPDATE PkgIDStore SET PkgId failed!" ));    
   107             iPkgIDs[index] = aPkgId;
   118             iPkgIDs[index] = aPkgId;
   108             }
   119             }
   109         }
   120         }
   110     }
   121     }
   111 
   122 
   128         {
   139         {
   129         iDPIDs.Remove(index);
   140         iDPIDs.Remove(index);
   130         iPkgIDs.Remove(index);
   141         iPkgIDs.Remove(index);
   131         _LIT(KSQLDeleteObjectText, "DELETE FROM PkgIDStore WHERE DataProviderId = %u");
   142         _LIT(KSQLDeleteObjectText, "DELETE FROM PkgIDStore WHERE DataProviderId = %u");
   132         iSqlStatement.Format(KSQLDeleteObjectText, aDpId);
   143         iSqlStatement.Format(KSQLDeleteObjectText, aDpId);
   133         User::LeaveIfError(iDatabase.Execute(iSqlStatement));
   144         LEAVEIFERROR(iDatabase.Execute(iSqlStatement),
       
   145                 OstTrace0( TRACE_ERROR, CMTPPKGIDSTORE_REMOVEL, "DELETE FROM PkgIDStore failed!" ));
   134         }
   146         }
   135     return index;
   147     return index;
   136     }
   148     }