mpxplugins/serviceplugins/collectionplugins/mpxsqlitepodcastdbplugin/src/mpxdbauxiliary.cpp
changeset 0 ff3acec5bc43
child 27 2cbbefa9af78
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Responsible for interaction with the Auxiliary table.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <sqldb.h>
       
    21 #include <mpxlog.h>
       
    22 
       
    23 #include "mpxdbcommonutil.h"
       
    24 #include "mpxdbmanager.h"
       
    25 
       
    26 #include "mpxpodcastdbpluginqueries.h"
       
    27 #include "mpxpodcastcollectiondbdef.h"
       
    28 #include "mpxdbutil.h"
       
    29 #include "mpxdbauxiliary.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ==============================
       
    32 
       
    33 // ----------------------------------------------------------------------------
       
    34 // Two-phased constructor.
       
    35 // ----------------------------------------------------------------------------
       
    36 //
       
    37 CMPXDbAuxiliary* CMPXDbAuxiliary::NewL(
       
    38     CMPXDbManager& aDbManager)
       
    39     {
       
    40     MPX_FUNC("CMPXDbAuxiliary::NewL");
       
    41 
       
    42     CMPXDbAuxiliary* self = CMPXDbAuxiliary::NewLC(aDbManager);
       
    43     CleanupStack::Pop(self);
       
    44     return self;
       
    45     }
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // Two-phased constructor.
       
    49 // ----------------------------------------------------------------------------
       
    50 //
       
    51 CMPXDbAuxiliary* CMPXDbAuxiliary::NewLC(
       
    52     CMPXDbManager& aDbManager)
       
    53     {
       
    54     MPX_FUNC("CMPXDbAuxiliary::NewLC");
       
    55 
       
    56     CMPXDbAuxiliary* self = new (ELeave) CMPXDbAuxiliary(aDbManager);
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL();
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // Destructor
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 CMPXDbAuxiliary::~CMPXDbAuxiliary()
       
    67     {
       
    68     MPX_FUNC("CMPXDbAuxiliary::~CMPXDbAuxiliary");
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // Constructor
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 CMPXDbAuxiliary::CMPXDbAuxiliary(
       
    76     CMPXDbManager& aDbManager) :
       
    77     CMPXDbTable(aDbManager)
       
    78     {
       
    79     MPX_FUNC("CMPXDbAuxiliary::CMPXDbAuxiliary");
       
    80     }
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // Second phase constructor.
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 void CMPXDbAuxiliary::ConstructL()
       
    87     {
       
    88     MPX_FUNC("CMPXDbAuxiliary::ConstructL");
       
    89     BaseConstructL();
       
    90     }
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // CMPXDbAuxiliary::SetLastRefreshedTimeL
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 void CMPXDbAuxiliary::SetLastRefreshedTimeL(
       
    97     TTime aTime)
       
    98     {
       
    99     MPX_FUNC("CMPXDbAuxiliary::SetLastRefreshedTimeL");
       
   100 
       
   101     // update all databases
       
   102     HBufC* time = MPXDbCommonUtil::TTimeToDesLC(aTime);
       
   103     iDbManager.ExecuteQueryL(KDbManagerAllDrives, KQueryAuxiliarySetTime, time);
       
   104     CleanupStack::PopAndDestroy(time);
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // CMPXDbAuxiliary::LastRefreshedTimeL
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 TTime CMPXDbAuxiliary::LastRefreshedTimeL()
       
   112     {
       
   113     MPX_FUNC("CMPXDbAuxiliary::LastRefreshedTimeL");
       
   114 
       
   115     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryAuxiliaryGetTime));
       
   116     CleanupClosePushL(recordset);
       
   117 
       
   118     if (recordset.Next() != KSqlAtRow)
       
   119         {
       
   120         User::Leave(KErrCorrupt);
       
   121         }
       
   122 
       
   123     // read the time string and convert it to TTime
       
   124     TTime time(MPXDbCommonUtil::DesToTTimeL(
       
   125     	MPXDbCommonUtil::GetColumnTextL(recordset, KMPXTableDefaultIndex)));
       
   126     CleanupStack::PopAndDestroy(&recordset);
       
   127 
       
   128     return time;
       
   129     }
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // CMPXDbAuxiliary::SetDBCorruptedL
       
   133 // ----------------------------------------------------------------------------
       
   134 //
       
   135 void CMPXDbAuxiliary::SetDBCorruptedL(
       
   136     TBool aCorrupt)
       
   137     {
       
   138     MPX_FUNC("CMPXDbAuxiliary::SetDBCorruptedL");
       
   139 
       
   140     // update all databases
       
   141     iDbManager.ExecuteQueryL(KDbManagerAllDrives, KQueryAuxiliarySetCorrupt,
       
   142         aCorrupt);
       
   143     }
       
   144 
       
   145 // ----------------------------------------------------------------------------
       
   146 // CMPXDbAuxiliary::DBCorruptedL
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 TBool CMPXDbAuxiliary::DBCorruptedL()
       
   150     {
       
   151     MPX_FUNC("CMPXDbAuxiliary::DBCorruptedL");
       
   152     return (ExecuteSumQueryL(KQueryAuxiliaryGetCorrupt) > 0);
       
   153     }
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CMPXDbAuxiliary::SetSaveDeletedRecordCountL
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 void CMPXDbAuxiliary::SetSaveDeletedRecordCountL(TInt aDrive,
       
   160     TUint32 aValue)
       
   161     {
       
   162     MPX_FUNC("CMPXDbAuxiliary::SetSaveDeletedRecordCountL");
       
   163 
       
   164     // update all databases
       
   165     iDbManager.ExecuteQueryL(aDrive, KQueryAuxiliarySetCount, aValue);
       
   166     }
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CMPXDbAuxiliary::SaveDeletedRecordCountL
       
   170 // ----------------------------------------------------------------------------
       
   171 //
       
   172 TUint32 CMPXDbAuxiliary::SaveDeletedRecordCountL()
       
   173     {
       
   174     MPX_FUNC("CMPXDbAuxiliary::SaveDeletedRecordCountL");
       
   175     return ExecuteSumQueryL(KQueryAuxiliaryGetCount);
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 // CMPXDbAuxiliary::SaveDeletedRecordCountL
       
   180 // ----------------------------------------------------------------------------
       
   181 //
       
   182 TUint32 CMPXDbAuxiliary::SaveDeletedRecordCountL(TInt aDrive)
       
   183     {
       
   184     MPX_FUNC("CMPXDbAuxiliary::SaveDeletedRecordCountL ");
       
   185     return ExecuteIntQueryL(aDrive, KQueryAuxiliaryGetCount);
       
   186     }
       
   187 
       
   188 // ----------------------------------------------------------------------------
       
   189 // CMPXDbAuxiliary::IsRefreshedL
       
   190 // ----------------------------------------------------------------------------
       
   191 //
       
   192 TBool CMPXDbAuxiliary::IsRefreshedL()
       
   193     {
       
   194     MPX_FUNC("CMPXDbAuxiliary::IsRefreshedL");
       
   195 
       
   196     TBool refreshed(ETrue);
       
   197 
       
   198     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryAuxiliaryGetTime));
       
   199     CleanupClosePushL(recordset);
       
   200 
       
   201     TInt count(0);
       
   202     while (recordset.Next() == KSqlAtRow)
       
   203         {
       
   204         count++;
       
   205 
       
   206         // read the time string and convert it to TTime
       
   207         if (Time::NullTTime() == MPXDbCommonUtil::DesToTTimeL(
       
   208         	MPXDbCommonUtil::GetColumnTextL(recordset, KMPXTableDefaultIndex)))
       
   209             {
       
   210             refreshed = EFalse;
       
   211             break;
       
   212             }
       
   213         }
       
   214 
       
   215     CleanupStack::PopAndDestroy(&recordset);
       
   216     return refreshed && (count > 0);
       
   217     }
       
   218 
       
   219 // ----------------------------------------------------------------------------
       
   220 // CMPXDbAuxiliary::IdL
       
   221 // ----------------------------------------------------------------------------
       
   222 //
       
   223 TInt CMPXDbAuxiliary::IdL( TInt aDrive )
       
   224     {
       
   225     MPX_DEBUG1("CMPXDbAuxiliary::IdL <--");
       
   226     TInt id(0);
       
   227     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDrive, KQueryAuxiliaryGetId));
       
   228     CleanupClosePushL( recordset );
       
   229 
       
   230     while(recordset.Next() == KSqlAtRow )
       
   231         {
       
   232         id = recordset.ColumnInt(KMPXTableDefaultIndex);
       
   233         }
       
   234 
       
   235     CleanupStack::PopAndDestroy( &recordset );
       
   236     MPX_DEBUG1("CMPXDbAuxiliary::IdL -->");
       
   237     return id;
       
   238     }
       
   239 
       
   240 // ----------------------------------------------------------------------------
       
   241 // CMPXDbAuxiliary::SetIdL
       
   242 // ----------------------------------------------------------------------------
       
   243 //
       
   244 void CMPXDbAuxiliary::SetIdL( TInt aDrive, TInt aId )
       
   245     {
       
   246     MPX_DEBUG1("CMPXDbAuxiliary::SetIdL <--");
       
   247     iDbManager.ExecuteQueryL(aDrive,KQueryAuxiliarySetId, aId);
       
   248     MPX_DEBUG1("CMPXDbAuxiliary::SetIdL -->");
       
   249     }
       
   250 
       
   251 // ----------------------------------------------------------------------------
       
   252 // CMPXDbAuxiliary::CreateTableL
       
   253 // ----------------------------------------------------------------------------
       
   254 //
       
   255 void CMPXDbAuxiliary::CreateTableL(
       
   256     RSqlDatabase& aDatabase,
       
   257     TBool aCorruptTable)
       
   258     {
       
   259     MPX_FUNC("CMPXDbAuxiliary::CreateTableL");
       
   260 
       
   261     // create the table
       
   262     User::LeaveIfError(aDatabase.Exec(KAuxiliaryCreateTable));
       
   263 
       
   264     // insert the default record
       
   265     // use the same length as '%u' is longer than '0' or '1'
       
   266     HBufC* query = KQueryAuxiliaryInsert().AllocLC();
       
   267     query->Des().Format(KQueryAuxiliaryInsert, aCorruptTable);
       
   268     User::LeaveIfError(aDatabase.Exec(*query));
       
   269     CleanupStack::PopAndDestroy(query);
       
   270     }
       
   271 
       
   272 // ----------------------------------------------------------------------------
       
   273 // CMPXDbAuxiliary::DropTableL
       
   274 // ----------------------------------------------------------------------------
       
   275 //
       
   276 void CMPXDbAuxiliary::DropTableL(
       
   277     RSqlDatabase& aDatabase)
       
   278     {
       
   279     MPX_FUNC("CMPXDbAuxiliary::DropTableL");
       
   280     User::LeaveIfError(aDatabase.Exec(KAuxiliaryDropTable));
       
   281     }
       
   282 
       
   283 // ----------------------------------------------------------------------------
       
   284 // CMPXDbAuxiliary::CheckTableL
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 TBool CMPXDbAuxiliary::CheckTableL(
       
   288     RSqlDatabase& aDatabase)
       
   289     {
       
   290     MPX_FUNC("CMPXDbAuxiliary::CheckTableL");
       
   291     return DoCheckTable(aDatabase, KAuxiliaryCheckTable);
       
   292     }
       
   293 
       
   294 // End of File