upnpharvester/common/dbmanager/src/cmdmsqliteconnection.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2008 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:      SQLite Connection class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include "cmdmsqliteconnection.h"
       
    24 #include "cmdmsqlclausedef.h"
       
    25 #include "cmfillrule.h"
       
    26 #include "cmfillrulecontainer.h"
       
    27 #include "cmmediaserverfull.h"
       
    28 #include "cmstorerule.h"
       
    29 #include "cmfilllistitem.h"
       
    30 #include "cmstorelistitem.h"
       
    31 #include "cmdriveinfo.h"
       
    32 #include "cmsearchresponsehash.h"
       
    33 #include "msdebug.h"
       
    34 
       
    35 // Constants
       
    36 _LIT8( KCmDbPragmaCacheSize, "PRAGMA cache_size=4096;PRAGMA page_size=4096;");
       
    37 const TUint8 KAmountOfIDs = 10;
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CCmDmSQLiteConnection::NewL
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CCmDmSQLiteConnection* CCmDmSQLiteConnection::NewL()
       
    44     {
       
    45     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::NewL()"));
       
    46     
       
    47     CCmDmSQLiteConnection* self = CCmDmSQLiteConnection::NewLC();
       
    48     CleanupStack::Pop( self );
       
    49 
       
    50     return self;
       
    51     }
       
    52  
       
    53 // ---------------------------------------------------------------------------
       
    54 // CCmDmSQLiteConnection::NewLC
       
    55 // ---------------------------------------------------------------------------
       
    56 //    
       
    57 CCmDmSQLiteConnection* CCmDmSQLiteConnection::NewLC()
       
    58     {
       
    59     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::NewLC()"));
       
    60     
       
    61     CCmDmSQLiteConnection* self = new ( ELeave ) CCmDmSQLiteConnection();
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64 
       
    65     return self;  
       
    66     }    
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CCmDmSQLiteConnection::~CCmDmSQLiteConnection
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CCmDmSQLiteConnection::~CCmDmSQLiteConnection()
       
    73     {
       
    74     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::~CCmDmSQLiteConnection()"));
       
    75     
       
    76     TRAP_IGNORE( BackUpIdL( ERuleGroupID, iRuleGroupID ) );
       
    77     TRAP_IGNORE( BackUpIdL( ERuleID, iRuleID ) );
       
    78     TRAP_IGNORE( BackUpIdL( ERuleParamID, iRuleParamID ) );
       
    79     TRAP_IGNORE( BackUpIdL( EMediaServerID, iMediaServerID ) );
       
    80     TRAP_IGNORE( BackUpIdL( EStoredID, iStoredID ) );
       
    81     TRAP_IGNORE( BackUpIdL( EFilledID, iFilledID ) );
       
    82     TRAP_IGNORE( BackUpIdL( EStoreRuleID, iStoreRuleID ) );
       
    83     TRAP_IGNORE( BackUpIdL( EStoreRuleParamID, iStoreRuleParamID ) );
       
    84     TRAP_IGNORE( BackUpIdL( EFillFileListId, iFillFileId ) );
       
    85     TRAP_IGNORE( BackUpIdL( EStoreFileListId, iStoreFileId ) );
       
    86     CloseDb();
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CCmDmSQLiteConnection::OpenDb
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 TInt CCmDmSQLiteConnection::OpenDb( const TDesC& aDb )
       
    94     {
       
    95     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::OpenDb()"));
       
    96     
       
    97     TInt err( iDatabase.Open( aDb, NULL ) );
       
    98     if ( err != KErrNone )
       
    99         {
       
   100         TRACE(Print(_L("[DATABASE MANAGER]\t CCmDmSQLiteConnection::OpenDb()\
       
   101          error %d"), err));
       
   102         }
       
   103     else 
       
   104         {
       
   105         err = iDatabase.Exec( KCmDbPragmaCacheSize );        
       
   106         
       
   107         }
       
   108     return err;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CCmDmSQLiteConnection::CloseDb
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CCmDmSQLiteConnection::CloseDb()
       
   116     {
       
   117     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::CloseDb()"));
       
   118     
       
   119     iDatabase.Close();         
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CCmDmSQLiteConnection::InitIDs
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CCmDmSQLiteConnection::InitIDs()
       
   127     {
       
   128     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::InitIDs()"));
       
   129     
       
   130     TInt err = iStatement.Prepare( iDatabase, KAddIDs );
       
   131     if( err )
       
   132         {
       
   133         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   134             CCmDmSQLiteConnection::SetIDs() FAILED ")));
       
   135         }
       
   136     else
       
   137         {
       
   138         for( TInt j=1; j <= KAmountOfIDs ; j++ )
       
   139             {    
       
   140             SetID( static_cast<TTypeOfID>(j) );
       
   141             }
       
   142         iStatement.Close();        
       
   143         }          
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CCmDmSQLiteConnection::SetID
       
   148 // ---------------------------------------------------------------------------
       
   149 //    
       
   150 void CCmDmSQLiteConnection::SetID( TTypeOfID aType )
       
   151     {
       
   152     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::SetID()"));
       
   153     
       
   154     // Init all ids to one    
       
   155     iStatement.BindInt64( 0, 1 );
       
   156     iStatement.BindInt( 1, aType );
       
   157     iStatement.Exec();
       
   158     iStatement.Reset();        
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CCmDmSQLiteConnection::BackUpIdL
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CCmDmSQLiteConnection::BackUpIdL( TTypeOfID aType, TUint64 aID )
       
   166     {
       
   167     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::BackUpIdL()"));
       
   168     
       
   169     iStatement.PrepareL( iDatabase, KUpdateID );
       
   170     iStatement.BindInt64( 0, aID );
       
   171     iStatement.BindInt( 1, aType );
       
   172     iStatement.Exec();
       
   173     iStatement.Reset();
       
   174     iStatement.Close();
       
   175     }
       
   176         
       
   177 // ---------------------------------------------------------------------------
       
   178 // CCmDmSQLiteConnection::LoadIDs
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CCmDmSQLiteConnection::LoadIDs()
       
   182     {    
       
   183     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::LoadIDs()"));
       
   184     
       
   185     TRAP_IGNORE( LoadIDL( iRuleGroupID, ERuleGroupID ) );
       
   186     TRAP_IGNORE( LoadIDL( iRuleID, ERuleID ) );
       
   187     TRAP_IGNORE( LoadIDL( iRuleParamID, ERuleParamID ) );
       
   188     TRAP_IGNORE( LoadIDL( iMediaServerID, EMediaServerID ) );
       
   189     TRAP_IGNORE( LoadIDL( iStoredID, EStoredID ) );
       
   190     TRAP_IGNORE( LoadIDL( iFilledID, EFilledID ) );
       
   191     TRAP_IGNORE( LoadIDL( iStoreRuleID, EStoreRuleID ) );
       
   192     TRAP_IGNORE( LoadIDL( iStoreRuleParamID, EStoreRuleParamID ) );
       
   193     TRAP_IGNORE( LoadIDL( iFillFileId, EFillFileListId) );
       
   194     TRAP_IGNORE( LoadIDL( iStoreFileId, EStoreFileListId) );       
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CCmDmSQLiteConnection::LoadIDL
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void CCmDmSQLiteConnection::LoadIDL( TUint64& aId, TTypeOfID aType )
       
   202     {
       
   203     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::LoadIDL()"));
       
   204     
       
   205     TInt err = iStatement.Prepare( iDatabase, KSelectID );
       
   206     if( err )
       
   207             {
       
   208             TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   209                 CCmDmSQLiteConnection::LoadIDL() FAILED ")));
       
   210             User::Leave( err );
       
   211             }
       
   212     else
       
   213         {
       
   214         iStatement.BindInt( 0, aType );
       
   215         
       
   216         // get id
       
   217         err = iStatement.Next();
       
   218         if (  err == KSqlAtRow )  
       
   219             {
       
   220             aId = iStatement.ColumnInt64( 0 );
       
   221             }
       
   222         iStatement.Reset();
       
   223         iStatement.Close();                    
       
   224         }            
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CCmDmSQLiteConnection::CreateDbFile
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 TInt CCmDmSQLiteConnection::CreateDbFile( const TDesC& aDb )
       
   232     {
       
   233     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::CreateDbFile()"));
       
   234     
       
   235     TInt err( iDatabase.Create( aDb ) );
       
   236     return err;
       
   237     }
       
   238     
       
   239 // ---------------------------------------------------------------------------
       
   240 // CCmDmSQLiteConnection::Validate
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 TBool CCmDmSQLiteConnection::Validate()
       
   244     {
       
   245     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::Validate()"));
       
   246     
       
   247     TInt ret( KErrNone );
       
   248     TInt err = iStatement.Prepare( iDatabase, 
       
   249         KValidateTableExistence );
       
   250     // Loop only one row in results
       
   251     if( err )
       
   252         {
       
   253         ret = KErrGeneral;
       
   254         }
       
   255     else
       
   256         {
       
   257         err = iStatement.Next();    
       
   258         if ( err != KSqlAtRow )  
       
   259             {
       
   260             ret = KErrGeneral;       
       
   261             }
       
   262         iStatement.Reset();
       
   263         iStatement.Close();          
       
   264         }                     
       
   265     TBool retval = EFalse;
       
   266     if ( ret == KErrNone ) 
       
   267         {
       
   268         retval = ETrue;
       
   269         }
       
   270     return retval;
       
   271     }
       
   272     
       
   273 // ---------------------------------------------------------------------------
       
   274 // CCmDmSQLiteConnection::ExecuteL
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CCmDmSQLiteConnection::ExecuteL( const TDesC8& aCommand )
       
   278     {
       
   279     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::ExecuteL()"));
       
   280     
       
   281     TInt err( iDatabase.Exec( aCommand ) );
       
   282     if ( KErrNone > err  )
       
   283         {
       
   284         User::Leave( err );    
       
   285         }    
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CCmDmSQLiteConnection::SetFillFiles
       
   290 // ---------------------------------------------------------------------------
       
   291 //    
       
   292 TInt CCmDmSQLiteConnection::SetFillFiles( 
       
   293     RPointerArray<CCmFillListItem>& aItems )
       
   294     {
       
   295     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::SetFillFiles()"));
       
   296     
       
   297     iDatabase.Exec( KCmDbBeginTransaction );
       
   298     TInt err(KErrNone);
       
   299     for( TInt i = 0; i < aItems.Count(); i++ )
       
   300         {
       
   301         err = iStatement.Prepare( iDatabase, KAddFillFile );
       
   302         if( err )
       
   303             {
       
   304             TRACE(Print(_L("[DATABASE MANAGER]\t Prepare err = %d"), err ));
       
   305             }
       
   306         else
       
   307             {
       
   308             iStatement.BindInt64( 0, aItems[i]->DbId() );  
       
   309             iStatement.BindText( 1, aItems[i]->PrimaryText() );
       
   310             iStatement.BindText( 2, 
       
   311                 aItems[i]->SecondaryText() );
       
   312             iStatement.BindText( 3, aItems[i]->Path() );
       
   313             iStatement.BindBinary( 4, aItems[i]->Uri() );
       
   314             iStatement.BindBinary( 5, aItems[i]->ItemId() );
       
   315             iStatement.BindText( 6, aItems[i]->UpnpClass() );
       
   316             iStatement.BindInt( 7, aItems[i]->MediaType() );
       
   317             iStatement.BindInt( 8, aItems[i]->Priority() );
       
   318             iStatement.BindInt( 9, aItems[i]->Size() );
       
   319             iStatement.BindInt( 10, aItems[i]->Status() );
       
   320             iStatement.BindInt64( 11, aItems[i]->Date().Int64() );
       
   321             iStatement.BindInt( 12, aItems[i]->ListId() );
       
   322             iStatement.BindInt( 13, aItems[i]->DevId() );
       
   323             iStatement.BindInt64( 14, aItems[i]->RefId() );
       
   324             iStatement.BindInt( 15, aItems[i]->Selected() );
       
   325             iStatement.BindInt64( 16, aItems[i]->DriveId() );
       
   326             iStatement.BindInt( 17, aItems[i]->DriveNumber() );
       
   327             iStatement.Exec();
       
   328             iStatement.Reset();  
       
   329             iStatement.Close();        
       
   330             }            
       
   331         }
       
   332     iDatabase.Exec( KCmDbSqlCommit );
       
   333     return err;
       
   334     }
       
   335     
       
   336 // ---------------------------------------------------------------------------
       
   337 // CCmDmSQLiteConnection::SetStoreFilesL
       
   338 // ---------------------------------------------------------------------------
       
   339 //    
       
   340 TInt CCmDmSQLiteConnection::SetStoreFilesL( 
       
   341     RPointerArray<CCmStoreListItem>& aItems )
       
   342     {
       
   343     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::SetStoreFilesL()"));
       
   344     
       
   345     iDatabase.Exec( KCmDbBeginTransaction );
       
   346     TInt err(KErrNone);
       
   347     for( TInt i = 0; i < aItems.Count(); i++ )
       
   348         {
       
   349         err = iStatement.Prepare( iDatabase, KAddStoreFile );
       
   350         if( err )
       
   351             {
       
   352             err = KErrGeneral;
       
   353             }
       
   354         else
       
   355             {   
       
   356             iStatement.BindInt64( 0, iStoreFileId );
       
   357             iStatement.BindText( 1, aItems[i]->PrimaryText() );
       
   358             iStatement.BindText( 2, 
       
   359                 aItems[i]->SecondaryText() );
       
   360             iStatement.BindText( 3, aItems[i]->Path() );
       
   361             iStatement.BindInt( 4, aItems[i]->Size() );
       
   362             iStatement.BindInt64( 5, aItems[i]->Date().Int64() );
       
   363             iStatement.BindInt( 6, aItems[i]->ListId() );
       
   364             iStatement.Exec();
       
   365             iStatement.Reset();
       
   366             iStatement.Close();            
       
   367             }    
       
   368         /** INSERT Server */
       
   369         RArray<TInt> serverIds( aItems[i]->DevIds() );
       
   370         RArray<TCmListItemStatus> statusValues( aItems[i]->StatusValues() );
       
   371         for( TInt j = 0; j < serverIds.Count(); j++ )
       
   372             {
       
   373             err = iStatement.Prepare( iDatabase, KAddStoreFileServer );
       
   374             if( err )
       
   375                 {
       
   376                 err = KErrGeneral;
       
   377                 }
       
   378             else
       
   379                 {
       
   380                 iStatement.BindInt64( 0, iStoreFileId );
       
   381                 iStatement.BindInt( 1, serverIds[j] );
       
   382                 iStatement.BindInt( 2, statusValues[j] );
       
   383                 iStatement.Exec();
       
   384                 iStatement.Reset();
       
   385                 iStatement.Close();            
       
   386                 }            
       
   387             }
       
   388         iStoreFileId++;                        
       
   389         }
       
   390     iDatabase.Exec( KCmDbSqlCommit );
       
   391     BackUpIdL( EStoreFileListId, iStoreFileId );
       
   392     return err;
       
   393     }
       
   394     
       
   395 // ---------------------------------------------------------------------------
       
   396 // CCmDmSQLiteConnection::AddStoreFile
       
   397 // ---------------------------------------------------------------------------
       
   398 //
       
   399 TInt CCmDmSQLiteConnection::AddStoreFile( CCmStoreListItem& aItem )
       
   400     {
       
   401     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::AddStoreFile()"));
       
   402     
       
   403     TInt err(KErrNone);
       
   404     err = iStatement.Prepare( iDatabase, KAddStoreFile );
       
   405     if( err )
       
   406         {
       
   407         err = KErrGeneral;
       
   408         }
       
   409     else
       
   410         {
       
   411         iStatement.BindInt64( 0, iStoreFileId );
       
   412         iStatement.BindText( 1, aItem.PrimaryText() );
       
   413         iStatement.BindText( 2, aItem.SecondaryText() );
       
   414         iStatement.BindText( 3, aItem.Path() );
       
   415         iStatement.BindInt( 4, aItem.Size() );
       
   416         iStatement.BindInt64( 5, aItem.Date().Int64() );
       
   417         iStatement.BindInt64( 6, aItem.ListId() );            
       
   418         iStatement.Exec();
       
   419         iStatement.Reset();
       
   420         iStatement.Close();
       
   421         /** INSERT Server */
       
   422         RArray<TInt>serverIds( aItem.DevIds() );
       
   423         RArray<TCmListItemStatus>statusValues( aItem.StatusValues() );        
       
   424         for( TInt j = 0; j < serverIds.Count() ; j++ )
       
   425             {
       
   426             err = iStatement.Prepare( iDatabase, KAddStoreFileServer );
       
   427             if( err )
       
   428                 {
       
   429                 err = KErrGeneral;
       
   430                 }
       
   431             else
       
   432                 {
       
   433                 iStatement.BindInt64( 0, iStoreFileId );
       
   434                 iStatement.BindInt( 1, serverIds[j] );
       
   435                 iStatement.BindInt( 2, statusValues[j] );
       
   436                 iStatement.Exec();
       
   437                 iStatement.Reset();
       
   438                 iStatement.Close();            
       
   439                 }            
       
   440             }                
       
   441         }
       
   442     iStoreFileId++;            
       
   443     return err;
       
   444     }
       
   445             
       
   446 // ---------------------------------------------------------------------------
       
   447 // CCmDmSQLiteConnection::AddStoredL
       
   448 // ---------------------------------------------------------------------------
       
   449 //
       
   450 TInt CCmDmSQLiteConnection::AddStoredL( 
       
   451     const TDesC& aFileName, 
       
   452     const TDesC8& aUDN, 
       
   453     TTime aTimeStamp )
       
   454     {
       
   455     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::AddStoredL()"));
       
   456     /* FIRST QYERY MediaServerID from the MediaServer table
       
   457     using UDN */
       
   458     TInt err = iStatement.Prepare( iDatabase, KSelectMediaServerIDByUDN ) ;
       
   459     TUint64 mediaServerID(0);    
       
   460     if( err )
       
   461         {
       
   462         TRACE(Print(_L("[DATABASE MANAGER]\t KSelectMediaServerIDByUDN \
       
   463             FAILED ")));
       
   464         err = KErrGeneral;
       
   465         }
       
   466     else
       
   467         {
       
   468         iStatement.BindBinary( 0, aUDN );
       
   469         // Loop only one row in results
       
   470         err = iStatement.Next();
       
   471         if ( err == KSqlAtRow )  
       
   472             {
       
   473             // Get cell contents    
       
   474             mediaServerID = iStatement.ColumnInt64( 0 );
       
   475             iStatement.Reset();            
       
   476             iStatement.Close();  // Destruct statement  
       
   477             err = KErrNone;          
       
   478             }        
       
   479         }
       
   480             
       
   481     err = iStatement.Prepare( iDatabase, KAddStored );
       
   482     if( err )
       
   483         {
       
   484         TRACE(Print(_L("[DATABASE MANAGER]\t KAddStored FAILED ")));
       
   485         err = KErrGeneral;
       
   486         }
       
   487     else
       
   488         {
       
   489         iStatement.BindInt64( 0, iStoredID );
       
   490         iStatement.BindText( 1, aFileName );          
       
   491         iStatement.BindInt64( 2, mediaServerID );    
       
   492         iStatement.BindInt64( 3, aTimeStamp.Int64() );
       
   493         iStatement.Exec();
       
   494         iStatement.Reset();
       
   495         iStatement.Close();
       
   496         err = KErrNone;   
       
   497         }
       
   498     iStoredID++;
       
   499     BackUpIdL( EStoredID, iStoredID );                
       
   500 
       
   501     return err;    
       
   502     }
       
   503 
       
   504 // ---------------------------------------------------------------------------
       
   505 // CCmDmSQLiteConnection::AddFillRuleL
       
   506 // ---------------------------------------------------------------------------
       
   507 //    
       
   508 TInt CCmDmSQLiteConnection::AddFillRuleL( CCmFillRule* aFillRule )
       
   509     {
       
   510     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::AddFillRuleL()"));
       
   511     
       
   512     iDatabase.Exec( KCmDbBeginTransaction );
       
   513     TInt err = iStatement.Prepare( iDatabase, KAddFillGroup );
       
   514     
       
   515     if ( err == KErrNone )
       
   516         {
       
   517         if( aFillRule->ListId() )
       
   518             {
       
   519             iRuleGroupID = aFillRule->ListId();
       
   520             }
       
   521         iStatement.BindInt64( 0, iRuleGroupID );        
       
   522         iStatement.BindBinary( 1, aFillRule->Name() );
       
   523         iStatement.BindInt( 2, aFillRule->Method() );
       
   524         iStatement.BindInt( 3, aFillRule->LimitType() );
       
   525         iStatement.BindInt( 4, aFillRule->Amount() );
       
   526         iStatement.BindInt( 5, aFillRule->Selected() );
       
   527         iStatement.BindInt( 6, aFillRule->Priority() );
       
   528         iStatement.BindInt( 7, aFillRule->TemplateId() );
       
   529         iStatement.BindInt( 8, aFillRule->MediaType() );
       
   530         iStatement.BindInt( 9, aFillRule->Status() );
       
   531         iStatement.BindInt64( 10, aFillRule->ListRealCount() );
       
   532         iStatement.BindInt64( 11, aFillRule->ListRealSizeInBytes() );
       
   533         iStatement.Exec();
       
   534         iStatement.Reset();
       
   535         iStatement.Close();                
       
   536    
       
   537         err = AddFillRuleMediaServersL( aFillRule );
       
   538                 
       
   539         if ( err == KErrNone )
       
   540             {
       
   541             err = AddFillRuleRulesAndParamsL( aFillRule );            
       
   542             }
       
   543         if ( err == KErrNone )
       
   544             {
       
   545             iRuleGroupID++;
       
   546             BackUpIdL( ERuleGroupID, iRuleGroupID );
       
   547             }
       
   548         }               
       
   549 
       
   550     iDatabase.Exec( KCmDbSqlCommit );    
       
   551         
       
   552     // in error cases force return value to KErrGeneral
       
   553     return ( err ? KErrGeneral : KErrNone );  
       
   554     }
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // CCmDmSQLiteConnection::AddFillRuleMediaServersL
       
   558 // ---------------------------------------------------------------------------
       
   559 //
       
   560 TInt CCmDmSQLiteConnection::AddFillRuleMediaServersL( CCmFillRule* aFillRule )
       
   561     {
       
   562     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
   563     AddFillRuleMediaServersL()"));
       
   564     
       
   565     TInt mediaServerCount( aFillRule->MediaServerCount() );
       
   566     
       
   567     TInt mediaserverID(0);
       
   568     TInt err( KErrNone );
       
   569     for( TInt i = 0; i < mediaServerCount ; i++ )
       
   570         {
       
   571         TPtrC8 udn = aFillRule->MediaServerL( i );
       
   572         aFillRule->MediaServerL( i, mediaserverID );
       
   573         if( udn.Length() )
       
   574             {
       
   575             err = 
       
   576                 iStatement.Prepare( iDatabase, KSelectMediaServerIDByUDN );
       
   577             if( !err )
       
   578                 {
       
   579                 iStatement.BindBinary( 0, udn );                 
       
   580                 // Loop all rows in results
       
   581                 while ( iStatement.Next() == KSqlAtRow )  
       
   582                     {
       
   583                     // Get cell contents    
       
   584                     mediaserverID = iStatement.ColumnInt64( 0 );
       
   585                     }                
       
   586                 }
       
   587             iStatement.Reset();                     
       
   588             iStatement.Close();                                               
       
   589             }
       
   590         if( mediaserverID > 0 )
       
   591             {
       
   592             err = iStatement.Prepare( iDatabase, KAddRuleGroupServer );
       
   593             if( err )
       
   594                 {
       
   595                 err = KErrGeneral;
       
   596                 }
       
   597             else
       
   598                 {
       
   599                 iStatement.BindInt64( 0, 
       
   600                     iRuleGroupID );    
       
   601                 iStatement.BindInt64( 1, 
       
   602                     mediaserverID );
       
   603                 iStatement.Exec();
       
   604                 iStatement.Reset();
       
   605                 iStatement.Close();
       
   606                 err = KErrNone;                                          
       
   607                 }             
       
   608             }                              
       
   609         }            
       
   610     
       
   611     return err;        
       
   612     }
       
   613 // ---------------------------------------------------------------------------
       
   614 // CCmDmSQLiteConnection::AddFillRuleRulesAndParamsL
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 TInt CCmDmSQLiteConnection::AddFillRuleRulesAndParamsL( 
       
   618     CCmFillRule* aFillRule )
       
   619     {
       
   620     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
   621     AddFillRuleRulesAndParamsL()"));
       
   622     
       
   623     TInt ruleCount(aFillRule->RuleCount());
       
   624     TInt err( KErrNone );
       
   625     TCmMetadataField metadataField;
       
   626     TPtrC8 dataField;
       
   627     TInt dataIndex;
       
   628     TCmOperatorType oper;
       
   629     TInt parameterCount(0);   
       
   630     for( TInt j = 0; j < ruleCount; j++)
       
   631         {
       
   632         aFillRule->RuleL( j, &metadataField, &oper, &parameterCount );
       
   633 
       
   634         err = iStatement.Prepare( iDatabase, KAddRule );
       
   635         
       
   636         if( err )
       
   637             {
       
   638             TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   639                 CCmDmSQLiteConnection::AddFilledL() FAILED ")));
       
   640             err = KErrGeneral;
       
   641             }
       
   642         else
       
   643             {
       
   644             iStatement.BindInt64( 0, iRuleID );
       
   645             iStatement.BindInt64( 1, iRuleGroupID );
       
   646             iStatement.BindInt( 2, metadataField );
       
   647             iStatement.BindInt( 3, oper );
       
   648             iStatement.Exec();
       
   649             iStatement.Reset();        
       
   650             iStatement.Close(); 
       
   651             err = KErrNone; 
       
   652             }
       
   653         
       
   654         // Add params of the rule to table        
       
   655         for( TInt k = 0; k < parameterCount; k++)
       
   656             {
       
   657             aFillRule->RuleParamL( j, k, &dataField );
       
   658             aFillRule->RuleParamL( j, k, dataIndex );
       
   659             err = iStatement.Prepare( iDatabase, KAddRuleParam );
       
   660             
       
   661             if( err )
       
   662                 {
       
   663                 TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   664                     CCmDmSQLiteConnection::AddFilledL() FAILED ")));
       
   665                 err = KErrGeneral;
       
   666                 }
       
   667             else
       
   668                 {
       
   669                 iStatement.BindInt64( 0, iRuleParamID );
       
   670                 iRuleParamID++; 
       
   671                 iStatement.BindInt64( 1, iRuleID );
       
   672                 if( dataField.Length() )
       
   673                     {
       
   674                     iStatement.BindBinary( 2, dataField );    
       
   675                     }
       
   676                 else
       
   677                     {
       
   678                     iStatement.BindInt64( 3, dataIndex );
       
   679                     }
       
   680                 iStatement.Exec();
       
   681                 iStatement.Reset();      
       
   682                 iStatement.Close();
       
   683                 err = KErrNone;  
       
   684                 }            
       
   685             }
       
   686         iRuleID++;            
       
   687         }
       
   688     BackUpIdL( ERuleID, iRuleID );
       
   689     BackUpIdL( ERuleParamID, iRuleParamID );                    
       
   690 
       
   691     return err;
       
   692     }        
       
   693 
       
   694 // ---------------------------------------------------------------------------
       
   695 // CCmDmSQLiteConnection::AddStoreRuleL
       
   696 // ---------------------------------------------------------------------------
       
   697 //
       
   698 TInt CCmDmSQLiteConnection::AddStoreRuleL( CCmStoreRule* aStoreRule )
       
   699     {
       
   700     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::AddStoreRuleL()"));
       
   701     
       
   702     TInt err = iStatement.Prepare( iDatabase, KAddStoreRule );
       
   703     
       
   704     if ( err == KErrNone )
       
   705         {
       
   706         iStatement.BindInt64( 0, iStoreRuleID );
       
   707         iStatement.BindBinary( 1, aStoreRule->Name() );
       
   708         iStatement.BindInt( 2, aStoreRule->Selected() );
       
   709         iStatement.BindInt( 3, aStoreRule->Status() );
       
   710         iStatement.Exec();
       
   711         iStatement.Reset();
       
   712         iStatement.Close();
       
   713     
       
   714         err = AddStoreRuleParamsL( aStoreRule );
       
   715 
       
   716         if ( err == KErrNone )
       
   717             {
       
   718             err = AddStoreRuleMediaServersL( aStoreRule );
       
   719             }
       
   720         if ( err == KErrNone )
       
   721             {
       
   722             iStoreRuleID++;
       
   723             BackUpIdL( EStoreRuleID, iStoreRuleID );
       
   724             }
       
   725         }
       
   726   
       
   727     // in error cases force return value to KErrGeneral
       
   728     return ( err ? KErrGeneral : KErrNone );    
       
   729     }
       
   730 
       
   731 // ---------------------------------------------------------------------------
       
   732 // CCmDmSQLiteConnection::AddStoreRuleParamsL
       
   733 // ---------------------------------------------------------------------------
       
   734 //
       
   735 TInt CCmDmSQLiteConnection::AddStoreRuleParamsL( CCmStoreRule* aStoreRule )
       
   736     {
       
   737     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::AddStoreRuleParamsL()"));
       
   738     
       
   739     TInt err( KErrNone );
       
   740     TCmMediaType mediaType; 
       
   741     // Ensin tavara fillrule group tauluun
       
   742     for(TInt i = 0; i < aStoreRule->DefCount(); i++ )
       
   743         {
       
   744         aStoreRule->StoreRule(i, &mediaType);
       
   745         err = iStatement.Prepare( iDatabase, KAddStoreRuleParams );    
       
   746         if( err )
       
   747             {
       
   748             TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   749                 CCmDmSQLiteConnection::AddStoreRuleParamsL() FAILED ")));
       
   750             err = KErrGeneral;
       
   751             }
       
   752         else
       
   753             {        
       
   754             iStatement.BindInt64( 0, iStoreRuleID );
       
   755             iStatement.BindInt64( 1, iStoreRuleParamID );
       
   756             iStatement.BindInt( 2, (TInt)mediaType );
       
   757             iStatement.Exec();
       
   758             iStatement.Reset();
       
   759             iStatement.Close();            
       
   760             }
       
   761         iStoreRuleParamID++;            
       
   762         }
       
   763     BackUpIdL( EStoreRuleParamID, iStoreRuleParamID );        
       
   764 
       
   765     return err;        
       
   766     }
       
   767 
       
   768 // ---------------------------------------------------------------------------
       
   769 // CCmDmSQLiteConnection::AddStoreRuleMediaServersL
       
   770 // ---------------------------------------------------------------------------
       
   771 //
       
   772 TInt CCmDmSQLiteConnection::AddStoreRuleMediaServersL( 
       
   773     CCmStoreRule* aStoreRule )
       
   774     {
       
   775     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
   776     AddStoreRuleMediaServersL()"));
       
   777     
       
   778     TInt err( KErrNone );         
       
   779     TInt mediaServerCount( aStoreRule->MediaServerCount() );
       
   780     TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   781         mediaServerCount = %d "), mediaServerCount));    
       
   782     if( mediaServerCount > KErrNone )
       
   783         {
       
   784         for( TInt i = 0; i < mediaServerCount ; i++ )
       
   785             {
       
   786             err = iStatement.Prepare( iDatabase, 
       
   787                 KSelectMediaServerIDByUDN );        
       
   788 
       
   789             TUint64 mediaserverID(0);            
       
   790             TPtrC8 udn = aStoreRule->MediaServerL( i );
       
   791             iStatement.BindBinary( 0, udn );
       
   792             if( err )
       
   793                 {
       
   794                 err = KErrGeneral;
       
   795                 }
       
   796             else
       
   797                 {        
       
   798                 // Loop all rows in results
       
   799                 if ( iStatement.Next() == KSqlAtRow )
       
   800                     {
       
   801                     // Get cell contents    
       
   802                     mediaserverID = iStatement.ColumnInt64( 0 );
       
   803                     iStatement.Reset();
       
   804                     iStatement.Close();                         
       
   805                     err = iStatement.Prepare( iDatabase, 
       
   806                         KAddStoreRuleServers );
       
   807                     if( err )
       
   808                         {
       
   809                         err = KErrGeneral;
       
   810                         }
       
   811                     else
       
   812                         {
       
   813                         iStatement.BindInt64( 0, iStoreRuleID );    
       
   814                         iStatement.BindInt64( 1, mediaserverID );
       
   815                         iStatement.Exec();
       
   816                         iStatement.Reset();
       
   817                         iStatement.Close();
       
   818                         err = KErrNone;
       
   819                         }
       
   820                                         
       
   821                     }   
       
   822                 }               
       
   823             }        
       
   824         }               
       
   825     
       
   826     return err;
       
   827     }
       
   828     
       
   829 // ---------------------------------------------------------------------------
       
   830 // CCmDmSQLiteConnection::AddMediaServerL
       
   831 // ---------------------------------------------------------------------------
       
   832 //
       
   833 TInt CCmDmSQLiteConnection::AddMediaServerL( 
       
   834     CCmMediaServerFull* aMediaServer )
       
   835     {
       
   836     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::AddMediaServerL()"));    
       
   837     
       
   838     TInt err = iStatement.Prepare( iDatabase, KAddMediaServer );
       
   839     if( err )
       
   840         {
       
   841         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   842             CCmDmSQLiteConnection::AddMediaServerL() FAILED ")));
       
   843         err = KErrGeneral;
       
   844         }
       
   845     else
       
   846         {
       
   847         iStatement.BindInt64( 0, iMediaServerID ); 
       
   848         iStatement.BindBinary( 1, aMediaServer->MediaServer() );
       
   849         iStatement.BindBinary( 2, aMediaServer->MediaServerName() );
       
   850         iStatement.BindInt( 3, aMediaServer->SystemUpdateID() );
       
   851         iStatement.BindInt64( 4, aMediaServer->VisibleDate().Int64() );
       
   852         iStatement.BindInt( 5, KErrNone );
       
   853         iStatement.BindInt( 6, KErrNone );
       
   854         iStatement.BindInt( 7, KErrNone );
       
   855         iStatement.BindInt( 8, KErrNone );
       
   856         iStatement.BindInt( 9, KErrNone );
       
   857         iStatement.BindInt( 10, (TInt)aMediaServer->CopyCapability() );
       
   858         iStatement.BindInt( 11, aMediaServer->FillUsage() );
       
   859         iStatement.BindInt( 12, aMediaServer->StoreUsage() );
       
   860         iStatement.Exec();
       
   861         iStatement.Reset();
       
   862         iStatement.Close();
       
   863         err = KErrNone;  
       
   864         }
       
   865     iMediaServerID++;
       
   866     BackUpIdL( EMediaServerID, iMediaServerID );        
       
   867    
       
   868     return err;
       
   869     }
       
   870 
       
   871 // ---------------------------------------------------------------------------
       
   872 // CCmDmSQLiteConnection::AddHashValue
       
   873 // ---------------------------------------------------------------------------
       
   874 //
       
   875 TInt CCmDmSQLiteConnection::AddHashValue( TInt64 aMediaServerId, 
       
   876                                           CCmSearchResponseHash* aHashValue )
       
   877     
       
   878     {
       
   879     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::AddHashValue()"));
       
   880         
       
   881     TInt err = iStatement.Prepare( iDatabase, KAddHashValue );
       
   882     if( err )
       
   883         {
       
   884         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   885             CCmDmSQLiteConnection::AddHashValue() FAILED ")));
       
   886         err = KErrGeneral;
       
   887         }
       
   888     else
       
   889         {
       
   890         iStatement.BindInt64( 0, aMediaServerId ); 
       
   891         iStatement.BindInt( 1, aHashValue->StartIndex() );
       
   892         iStatement.BindInt( 2, aHashValue->ItemCount()  );
       
   893         iStatement.BindBinary( 3, aHashValue->Hash() );
       
   894         iStatement.Exec();
       
   895         iStatement.Reset();
       
   896         iStatement.Close();
       
   897         err = KErrNone;  
       
   898         }
       
   899       
       
   900     return err;
       
   901     }
       
   902     
       
   903 // ---------------------------------------------------------------------------
       
   904 // CCmDmSQLiteConnection::SetMediaServersL
       
   905 // ---------------------------------------------------------------------------
       
   906 //
       
   907 TInt CCmDmSQLiteConnection::SetMediaServersL( 
       
   908     RPointerArray<CCmMediaServerFull>& aServers )  
       
   909     {
       
   910     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::SetMediaServersL()"));    
       
   911     TInt err( KErrNone );
       
   912     
       
   913     TInt sqlRet( iDatabase.Exec( KInitIsActiveFlags ) );
       
   914 
       
   915     if ( sqlRet >= KErrNone )
       
   916         {
       
   917         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   918             %d rows have been changed/inserted/deleted"), sqlRet ));
       
   919 
       
   920         TInt id( KErrNone );
       
   921         // Add new servers into 
       
   922         HBufC8* uuid = NULL;
       
   923         for( TInt j = 0; j < aServers.Count(); j++ )
       
   924             {
       
   925             uuid = aServers[j]->MediaServer().AllocLC();
       
   926             PrepareQueryCmdL(EMediaServerIdQuery);
       
   927             id = QueryMediaServerId( *uuid );
       
   928             if( id == KErrNotFound )
       
   929                 {
       
   930                 AddMediaServerL( aServers[j] );
       
   931                 }
       
   932             CleanupStack::PopAndDestroy( uuid );
       
   933             uuid = NULL;    
       
   934             }
       
   935         
       
   936         for( TInt i = 0; i < aServers.Count() ; i++ )
       
   937             {
       
   938             err = iStatement.Prepare( iDatabase, KUpdateMsIsActive );
       
   939         
       
   940             if( err )
       
   941                 {
       
   942                 TRACE(Print(_L("[DATABASE MANAGER]\t \
       
   943                 CCmDmSQLiteConnection::SetMediaServersL() FAILED ")));
       
   944                 err = KErrGeneral;
       
   945                 }
       
   946             else
       
   947                 {
       
   948                 iStatement.BindInt( 0, aServers[i]->IsActive() );
       
   949                 iStatement.BindInt( 1, aServers[i]->SystemUpdateID() );
       
   950                 //update the server name
       
   951                 iStatement.BindBinary( 2, aServers[i]->MediaServerName() );
       
   952                 iStatement.BindInt( 3, aServers[i]->FillUsage() );
       
   953                 iStatement.BindInt( 4, aServers[i]->StoreUsage() );
       
   954                 iStatement.BindBinary( 5, aServers[i]->MediaServer() );
       
   955                 iStatement.Exec();                
       
   956                 }
       
   957             iStatement.Reset(); 
       
   958             iStatement.Close();            
       
   959             }     
       
   960         
       
   961         if ( err == KErrNone )
       
   962             {
       
   963             err = DeleteInActiveRuleServers();
       
   964             }
       
   965     	        
       
   966         if ( err == KErrNone )
       
   967             {
       
   968             err = DeleteInActiveFiles();            
       
   969             }        
       
   970         }
       
   971 
       
   972     return err;
       
   973     }
       
   974 
       
   975 // ---------------------------------------------------------------------------
       
   976 // CCmDmSQLiteConnection::SetSyncTime
       
   977 // ---------------------------------------------------------------------------
       
   978 //
       
   979 TInt CCmDmSQLiteConnection::SetSyncTime()
       
   980     {
       
   981     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::SetSyncTime()"));    
       
   982     
       
   983     TInt err( iDatabase.Exec( KRemoveSyncTime ) );   
       
   984     
       
   985     if ( err == KErrNone )
       
   986         {
       
   987         err = iStatement.Prepare( iDatabase, KSetSyncTime );
       
   988         if ( err == KErrNone )
       
   989             {
       
   990             TTime time;
       
   991             time.HomeTime();
       
   992             iStatement.BindInt64( 0, time.Int64() );
       
   993             iStatement.Exec();               
       
   994             }
       
   995         iStatement.Reset(); 
       
   996         iStatement.Close();         
       
   997         }
       
   998     // in error cases force return value to KErrGeneral
       
   999     return ( err ? KErrGeneral : KErrNone ); 
       
  1000     }
       
  1001 
       
  1002 // ---------------------------------------------------------------------------
       
  1003 // CCmDmSQLiteConnection::GetSyncTime
       
  1004 // ---------------------------------------------------------------------------
       
  1005 //
       
  1006 TInt CCmDmSQLiteConnection::GetSyncTime( TTime& aTime )
       
  1007     {
       
  1008     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetSyncTime()"));    
       
  1009     
       
  1010     TInt err( iStatement.Prepare( iDatabase, KGetSyncTime ) );
       
  1011     aTime = KErrNone;
       
  1012     if( err )
       
  1013         {
       
  1014         err = KErrGeneral;  
       
  1015         }
       
  1016     else
       
  1017         {
       
  1018         err = iStatement.Next(); 
       
  1019         if ( err == KSqlAtRow )  
       
  1020             { 
       
  1021             aTime = iStatement.ColumnInt64( 0 );
       
  1022             err = KErrNone;                
       
  1023             }
       
  1024         }
       
  1025     iStatement.Reset(); 
       
  1026     iStatement.Close();     
       
  1027     return err;
       
  1028     }
       
  1029 
       
  1030 // ---------------------------------------------------------------------------
       
  1031 // CCmDmSQLiteConnection::SetProgressInfo
       
  1032 // ---------------------------------------------------------------------------
       
  1033 //
       
  1034 TInt CCmDmSQLiteConnection::SetProgressInfo( TInt aTransferred, 
       
  1035     TInt aTotalCount)
       
  1036     {
       
  1037     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::SetProgressInfo()"));    
       
  1038     
       
  1039     TInt err( iDatabase.Exec( KRemoveProgressInfo ) );
       
  1040     if ( err == KErrNone )
       
  1041         {
       
  1042         err = iStatement.Prepare( iDatabase, KSetProgressInfo );
       
  1043         if( err )
       
  1044             {
       
  1045             err = KErrGeneral;
       
  1046             }
       
  1047         else
       
  1048             {
       
  1049             iStatement.BindInt( 0, aTransferred );
       
  1050             iStatement.BindInt( 1, aTotalCount );
       
  1051             iStatement.Exec();        
       
  1052             }
       
  1053         iStatement.Reset(); 
       
  1054         iStatement.Close();                 
       
  1055         }
       
  1056         
       
  1057     return err;    
       
  1058     }
       
  1059 
       
  1060 // ---------------------------------------------------------------------------
       
  1061 // CCmDmSQLiteConnection::GetProgressInfo
       
  1062 // ---------------------------------------------------------------------------
       
  1063 //
       
  1064 TInt CCmDmSQLiteConnection::GetProgressInfo( TInt& aTransferred, 
       
  1065     TInt& aTotalCount )
       
  1066     {
       
  1067     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetProgressInfo()"));    
       
  1068     
       
  1069     TInt err( iStatement.Prepare( iDatabase, KGetProgressInfo ) );
       
  1070     if( err )
       
  1071         {
       
  1072         err = KErrGeneral;  
       
  1073         }
       
  1074     else
       
  1075         {
       
  1076         err = iStatement.Next();
       
  1077         if ( err == KSqlAtRow )  
       
  1078             {
       
  1079             aTransferred = iStatement.ColumnInt( 0 );
       
  1080             aTotalCount = iStatement.ColumnInt( 1 );
       
  1081             err = KErrNone;                         
       
  1082             }
       
  1083         }
       
  1084     iStatement.Reset(); 
       
  1085     iStatement.Close();     
       
  1086     return err;    
       
  1087     }
       
  1088 
       
  1089 // ---------------------------------------------------------------------------
       
  1090 // CCmDmSQLiteConnection::SetDrivesL
       
  1091 // ---------------------------------------------------------------------------
       
  1092 //
       
  1093 void CCmDmSQLiteConnection::SetDrivesL( RPointerArray<CCmDriveInfo>& aDrives )
       
  1094     {
       
  1095     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::SetDrivesL()"));    
       
  1096     
       
  1097     TInt err( iDatabase.Exec( KRemoveDrivesInfo ) );
       
  1098     
       
  1099     if ( err == KErrNone)
       
  1100         {
       
  1101         iDatabase.Exec( KCmDbBeginTransaction );   
       
  1102         for( TInt i = 0; i < aDrives.Count(); i++ )
       
  1103             {
       
  1104             err = iStatement.Prepare( iDatabase, KSetDrivesInfo );
       
  1105             User::LeaveIfError( err ); 
       
  1106             iStatement.BindInt( 0, aDrives[i]->DriveNumber() );
       
  1107             iStatement.BindInt( 1, aDrives[i]->DriveType() );
       
  1108             iStatement.BindText( 2, aDrives[i]->DriveName() );
       
  1109             iStatement.BindInt64( 3, aDrives[i]->DriveSize() );
       
  1110             iStatement.BindInt64( 4, aDrives[i]->DriveQuota() );
       
  1111             iStatement.BindInt64( 5, aDrives[i]->UsedDriveQuota() );
       
  1112             iStatement.BindInt64( 6, aDrives[i]->DriveId() );
       
  1113             iStatement.BindInt( 7, aDrives[i]->Status() );
       
  1114             iStatement.Exec();
       
  1115             iStatement.Reset();
       
  1116             iStatement.Close();
       
  1117             }        
       
  1118         }
       
  1119     iDatabase.Exec( KCmDbSqlCommit );              
       
  1120     }
       
  1121                 
       
  1122 // ---------------------------------------------------------------------------
       
  1123 // CCmDmSQLiteConnection::PrepareQueryCmdL
       
  1124 // ---------------------------------------------------------------------------
       
  1125 //
       
  1126 void CCmDmSQLiteConnection::PrepareQueryCmdL( TCMQueryCmdType aType )
       
  1127     {
       
  1128     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::PrepareQueryCmdL()"));
       
  1129     
       
  1130     TInt err( KErrNone );                  
       
  1131     switch( aType )
       
  1132         {
       
  1133         case EFillRuleQuery:
       
  1134             {
       
  1135             iDatabase.Exec( KCmDbBeginTransaction );
       
  1136             err = iStatement.Prepare( iDatabase, KSelectFillRule );
       
  1137             break;
       
  1138             }
       
  1139         case EMediaServerInfoQyery:
       
  1140             {
       
  1141             err = iStatement.Prepare( iDatabase, 
       
  1142                 KSelectDeviceInfoByUDN );
       
  1143             break;
       
  1144             }
       
  1145         case EMediaServerIdQuery:
       
  1146             {
       
  1147             err = iStatement.Prepare( iDatabase, 
       
  1148                 KSelectMediaServerIDByUDN );            
       
  1149             break;
       
  1150             }
       
  1151         case EMediaServerUDNQuery:
       
  1152             {
       
  1153             err = iStatement.Prepare( iDatabase, 
       
  1154                 KSelectMediaServerUDNByID );
       
  1155             break;    
       
  1156             }
       
  1157         case EMediaServersAllQuery:
       
  1158             {
       
  1159             err = iStatement.Prepare( iDatabase, 
       
  1160                 KSelectAllMediaServers );
       
  1161             break;            
       
  1162             }          
       
  1163         case EHashValueQuery:
       
  1164             {
       
  1165             err = iStatement.Prepare( iDatabase, 
       
  1166                 KSelectHashValuesByMediaServer );
       
  1167             break;            
       
  1168             }          
       
  1169         case EStoredQuery:
       
  1170             {
       
  1171             err = iStatement.Prepare( iDatabase, KIsFileAlreadyStored );
       
  1172             break;
       
  1173             }         
       
  1174         case EStoredRowQuery:
       
  1175             {
       
  1176             err = iStatement.Prepare( iDatabase, KSelectStoredByUDN );
       
  1177             break;
       
  1178             }
       
  1179         case ESelectedFillRuleQuery:
       
  1180             {
       
  1181             err = iStatement.Prepare( iDatabase, 
       
  1182                 KSelectSelectedFillRuleNames);
       
  1183             break;
       
  1184             }
       
  1185         case EFillRuleNamesQuery:
       
  1186             {
       
  1187             iDatabase.Exec( KCmDbBeginTransaction );
       
  1188             err = iStatement.Prepare( iDatabase, KSelectFillRuleNames );
       
  1189             break;
       
  1190             }
       
  1191         case EStoreRuleQuery:
       
  1192             {
       
  1193             err = iStatement.Prepare( iDatabase, KSelectStoreRule );
       
  1194             break;
       
  1195             }
       
  1196         case EStoreRuleNamesQuery:
       
  1197             {
       
  1198             err = iStatement.Prepare( iDatabase, KSelectStoreRuleNames );
       
  1199             break;
       
  1200             }
       
  1201         case ESelectedStoreRuleQuery:
       
  1202             {
       
  1203             err = iStatement.Prepare( iDatabase, 
       
  1204                 KSelectSelectedStoreRuleNames );
       
  1205             break;
       
  1206             } 
       
  1207         case ETransferHistoryQuery:
       
  1208             {    
       
  1209             err = iStatement.Prepare(  iDatabase, 
       
  1210                 KSelectTransferHistory );
       
  1211             break;
       
  1212             }
       
  1213         case EFillFilesQuery:
       
  1214             {
       
  1215             err = iStatement.Prepare( iDatabase, KSelectFillFiles );
       
  1216             break;
       
  1217             }
       
  1218         case EDeletedFillFilesQuery:
       
  1219             {
       
  1220             err = iStatement.Prepare( iDatabase, 
       
  1221                 KSelectDeletedFillFiles );
       
  1222             break;
       
  1223             }
       
  1224         case EStoreFilesQuery:
       
  1225             {
       
  1226             err = iStatement.Prepare( iDatabase, KSelectStoreFiles );
       
  1227             break;
       
  1228             }        
       
  1229         case EAllFillFilesQuery:
       
  1230             {
       
  1231             err = iStatement.Prepare( iDatabase, KSelectAllFillFiles );
       
  1232             break;
       
  1233             }        
       
  1234         case EAllStoreFilesQuery:
       
  1235             {
       
  1236             err = iStatement.Prepare( iDatabase, KSelectAllStoreFiles ); 
       
  1237             break;
       
  1238             }        
       
  1239         case EFilledLowPriorityQuery:
       
  1240             {
       
  1241             err = iStatement.Prepare( iDatabase, 
       
  1242                 KSelectLowestPriorityFilled );
       
  1243             break;
       
  1244             }
       
  1245         case EAllFillFilesStatusQuery:
       
  1246             {
       
  1247             err = iStatement.Prepare( iDatabase, KGetAllFillFiles );
       
  1248             break;
       
  1249             }
       
  1250         case EAllStoreFilesStatusQuery:    
       
  1251             {
       
  1252             err = iStatement.Prepare( iDatabase, KGetAllStoreFiles );
       
  1253             break;
       
  1254             }
       
  1255         case EDrivesQuery:
       
  1256             {
       
  1257             err = iStatement.Prepare( iDatabase, KGetDrives );
       
  1258             break;
       
  1259             }
       
  1260         default:
       
  1261             {
       
  1262             LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::PrepareQueryCmdL() \
       
  1263             type not found"));
       
  1264             break;
       
  1265             }
       
  1266                                                             
       
  1267         }
       
  1268     if( err )
       
  1269         {
       
  1270         TRACE(Print(_L("[DATABASE MANAGER]\t err = %d "), err ));        
       
  1271         User::Leave( err ); 
       
  1272         }      
       
  1273     }
       
  1274     
       
  1275 // ---------------------------------------------------------------------------
       
  1276 // CCmDmSQLiteConnection::QueryFillRuleL
       
  1277 // ---------------------------------------------------------------------------
       
  1278 //
       
  1279 TInt CCmDmSQLiteConnection::QueryFillRuleL( CCmFillRule* aFillRule )
       
  1280     {
       
  1281     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryFillRuleL()"));
       
  1282             
       
  1283     TInt err( KErrNone );
       
  1284     TUint64 ruleGroupID(0);
       
  1285     TPtrC8 tempptr;
       
  1286     iStatement.BindBinary( 0, aFillRule->Name() );                
       
  1287     // Loop only one row in results
       
  1288     err = iStatement.Next();
       
  1289     if ( err == KSqlAtRow )
       
  1290         {
       
  1291         // Get cell contents
       
  1292         ruleGroupID = iStatement.ColumnInt64( 0 );
       
  1293         aFillRule->SetListId( (TUint8)ruleGroupID );
       
  1294         iStatement.ColumnBinary( 1, tempptr );
       
  1295         aFillRule->SetNameL( tempptr );
       
  1296         aFillRule->SetMethod( 
       
  1297             (TCmFillMethod)iStatement.ColumnInt( 2 ) );
       
  1298         aFillRule->SetLimitType( 
       
  1299             (TCmLimitType)iStatement.ColumnInt( 3 ) );
       
  1300         aFillRule->SetAmount( 
       
  1301             iStatement.ColumnInt( 4 ) );
       
  1302         aFillRule->SetSelected( 
       
  1303             (TCmFillRuleStatus)iStatement.ColumnInt( 5 ) );
       
  1304         aFillRule->SetPriority( 
       
  1305             (TUint8)iStatement.ColumnInt( 6 ) );
       
  1306         aFillRule->SetTemplateId( 
       
  1307             (TUint8)iStatement.ColumnInt( 7 ) );
       
  1308         aFillRule->SetMediaType( 
       
  1309             (TCmMediaType)iStatement.ColumnInt( 8 ) );
       
  1310         aFillRule->SetStatus( 
       
  1311             (TCmListItemStatus)iStatement.ColumnInt( 9 ) );
       
  1312         aFillRule->SetListRealCount( iStatement.ColumnInt( 10 ) );    
       
  1313         aFillRule->SetListRealSizeInBytes( 
       
  1314             iStatement.ColumnInt(11) );
       
  1315         err = KErrNone;             
       
  1316         }    
       
  1317     iStatement.Reset();            
       
  1318     iStatement.Close();  // Destruct statement
       
  1319     err = QueryFillRuleServersL( aFillRule, ruleGroupID );
       
  1320     if ( err )
       
  1321         {
       
  1322         LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryFillRuleL() \
       
  1323         error getting servers"));
       
  1324         }
       
  1325 
       
  1326     err = QueryFillRuleParamsL( aFillRule );    
       
  1327     if ( err )
       
  1328         {
       
  1329         LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryFillRuleL() \
       
  1330         error getting fill list parameters"));
       
  1331         }
       
  1332     
       
  1333     iDatabase.Exec( KCmDbSqlCommit );
       
  1334     return err;
       
  1335     }
       
  1336 
       
  1337 // ---------------------------------------------------------------------------
       
  1338 // CCmDmSQLiteConnection::QueryFillRuleServersL
       
  1339 // ---------------------------------------------------------------------------
       
  1340 //    
       
  1341 TInt CCmDmSQLiteConnection::QueryFillRuleServersL( CCmFillRule* aFillRule, 
       
  1342     TUint64 aRuleGroupID )
       
  1343     {
       
  1344     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryFillRuleServersL()"));
       
  1345     
       
  1346     TInt err( iStatement.Prepare( iDatabase, 
       
  1347         KSelectMediaServerIDByRuleGroupID ) );
       
  1348     RArray<TUint64> mediaServerIds;
       
  1349     CleanupClosePushL( mediaServerIds );
       
  1350     if( err )
       
  1351         {
       
  1352         LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  1353         QueryFillRuleServersL() select mediaserver fail"));
       
  1354         }
       
  1355     else
       
  1356         {
       
  1357         iStatement.BindInt64( 0, aRuleGroupID );        
       
  1358         // Loop all rows in results
       
  1359         for ( err = iStatement.Next(); 
       
  1360               err == KSqlAtRow; 
       
  1361               err = iStatement.Next() )
       
  1362             {
       
  1363             // Get cell contents    
       
  1364             mediaServerIds.AppendL( 
       
  1365                 iStatement.ColumnInt64(0) );             
       
  1366             }    
       
  1367         iStatement.Reset();            
       
  1368         iStatement.Close();  // Destruct statement
       
  1369         }
       
  1370             
       
  1371     TInt mediaServerCount( mediaServerIds.Count());
       
  1372 
       
  1373     for( TInt mediaServerIndex = 0; mediaServerIndex < mediaServerCount ; 
       
  1374          mediaServerIndex++ )
       
  1375         {   
       
  1376         aFillRule->AddMediaServerL( 
       
  1377             mediaServerIds[mediaServerIndex]);
       
  1378         }
       
  1379         
       
  1380     mediaServerIds.Reset();
       
  1381     CleanupStack::PopAndDestroy( &mediaServerIds );
       
  1382     
       
  1383     return err;    
       
  1384     }
       
  1385 
       
  1386 // ---------------------------------------------------------------------------
       
  1387 // CCmDmSQLiteConnection::QueryFillRuleParamsL
       
  1388 // ---------------------------------------------------------------------------
       
  1389 //    
       
  1390 TInt CCmDmSQLiteConnection::QueryFillRuleParamsL( CCmFillRule* aFillRule )
       
  1391     {
       
  1392     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryFillRuleParamsL()"));
       
  1393     
       
  1394     TInt err( iStatement.Prepare( iDatabase, KSelectRule ) );
       
  1395     RArray<TUint64> ruleIds;    
       
  1396     CleanupClosePushL( ruleIds );
       
  1397     TPtrC8 temp;
       
  1398     if( err )
       
  1399         {
       
  1400         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  1401             CCmDmSQLiteConnection::QueryFillRule() FAIL5")));
       
  1402         err = KErrGeneral; 
       
  1403         }
       
  1404     else
       
  1405         {    
       
  1406         iStatement.BindBinary( 0, aFillRule->Name() );
       
  1407         // Loop all rows in results
       
  1408         for ( err = iStatement.Next(); 
       
  1409               err == KSqlAtRow; 
       
  1410               err = iStatement.Next() )
       
  1411             {
       
  1412             // Get cell content
       
  1413             ruleIds.AppendL( iStatement.ColumnInt64( 0 ) );
       
  1414             aFillRule->AddRuleL( 
       
  1415                 (TCmMetadataField)iStatement.ColumnInt( 1 ), 
       
  1416                 (TCmOperatorType)iStatement.ColumnInt( 2 ) );
       
  1417             }            
       
  1418         
       
  1419         iStatement.Reset();            
       
  1420         iStatement.Close();  // Destruct statement
       
  1421         }
       
  1422         
       
  1423     TInt numberOfRules( ruleIds.Count() );              
       
  1424     for( TInt index = 0; index < numberOfRules ; index++ )
       
  1425         {
       
  1426         err = iStatement.Prepare( iDatabase, 
       
  1427             KSelectRuleParamsByRuleID );
       
  1428         if( err )
       
  1429             {
       
  1430             TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  1431                 KSelectRuleParamsByRuleID FAIL")));
       
  1432             err = KErrGeneral;            
       
  1433             }
       
  1434         else
       
  1435             {
       
  1436             iStatement.BindInt64( 0, ruleIds[index] );
       
  1437             // Loop all rows in results
       
  1438             for ( err = iStatement.Next(); 
       
  1439                   err == KSqlAtRow; 
       
  1440                   err = iStatement.Next() )
       
  1441                 {
       
  1442                 // Get cell contents
       
  1443                 iStatement.ColumnBinary( 0, temp );
       
  1444                 if( temp.Length() )
       
  1445                     {
       
  1446                     aFillRule->AddRuleParamL( index, temp );
       
  1447                     }
       
  1448                 else
       
  1449                     {
       
  1450                     aFillRule->AddRuleParamL( index, 
       
  1451                         iStatement.ColumnInt64( 1 ) );
       
  1452                     }                                           
       
  1453                 }
       
  1454             iStatement.Reset();            
       
  1455             iStatement.Close();  // Destruct statement                    
       
  1456             }    
       
  1457         }                                          
       
  1458     
       
  1459     ruleIds.Reset();
       
  1460     CleanupStack::PopAndDestroy( &ruleIds );
       
  1461             
       
  1462     TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  1463         CCmDmSQLiteConnection::QueryFillRule() end")));
       
  1464     return err;                                
       
  1465     }
       
  1466 
       
  1467 // ---------------------------------------------------------------------------
       
  1468 // CCmDmSQLiteConnection::QuerySelectedFillRuleNamesL
       
  1469 // ---------------------------------------------------------------------------
       
  1470 //
       
  1471 void CCmDmSQLiteConnection::QuerySelectedFillRuleNamesL( 
       
  1472     RPointerArray<HBufC8>& aNames, TInt aSelected )
       
  1473     {
       
  1474     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  1475     QuerySelectedFillRuleNamesL()"));   
       
  1476     
       
  1477     iStatement.BindInt( 0, aSelected );      
       
  1478     // Loop only one row in results
       
  1479     TPtrC8 tempPtr;
       
  1480     while( KSqlAtRow == iStatement.Next() )   
       
  1481         {
       
  1482         // Get cell contents
       
  1483         iStatement.ColumnBinary( 0, tempPtr );
       
  1484         aNames.Append( tempPtr.AllocL() ); 
       
  1485         }    
       
  1486     iStatement.Reset();                
       
  1487     iStatement.Close();  // Destruct statement                                     
       
  1488     }
       
  1489 
       
  1490 // ---------------------------------------------------------------------------
       
  1491 // CCmDmSQLiteConnection::QueryFillRuleNamesL
       
  1492 // ---------------------------------------------------------------------------
       
  1493 //
       
  1494 void CCmDmSQLiteConnection::QueryFillRuleNamesL( 
       
  1495     RPointerArray<HBufC8>& aNames )
       
  1496     {
       
  1497     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryFillRuleNamesL()"));   
       
  1498                      
       
  1499     // Loop only one row in results
       
  1500     TPtrC8 temp;
       
  1501     while( KSqlAtRow == iStatement.Next() )  
       
  1502         {
       
  1503         // Get cell contents               
       
  1504         iStatement.ColumnBinary( 0, temp );        
       
  1505         aNames.Append( temp.AllocL() );                   
       
  1506         }    
       
  1507     iStatement.Reset();                
       
  1508     iStatement.Close();  // Destruct statement
       
  1509     iDatabase.Exec( KCmDbSqlCommit );                     
       
  1510     TRACE(Print(_L("[DATABASE MANAGER]\t CCmDmSQLiteConnection::\
       
  1511         QueryFillRuleNamesL() end")));                   
       
  1512     }
       
  1513 
       
  1514 // ---------------------------------------------------------------------------
       
  1515 // CCmDmSQLiteConnection::QueryStoreRuleL
       
  1516 // ---------------------------------------------------------------------------
       
  1517 //
       
  1518 TInt CCmDmSQLiteConnection::QueryStoreRuleL( CCmStoreRule* aStoreRule )    
       
  1519     {
       
  1520     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryStoreRuleL()"));
       
  1521     
       
  1522     TUint64 ruleGroupID(0);
       
  1523     TPtrC8 temp;
       
  1524     iStatement.BindBinary( 0, aStoreRule->Name() );                
       
  1525     // Loop only one row in results
       
  1526     TInt err( iStatement.Next() );
       
  1527     if ( err == KSqlAtRow )  
       
  1528         {
       
  1529         // Get cell contents
       
  1530         ruleGroupID = iStatement.ColumnInt64( 0 );
       
  1531         aStoreRule->SetListId( ruleGroupID );
       
  1532         iStatement.ColumnBinary( 1, temp );
       
  1533         aStoreRule->SetNameL( temp );   
       
  1534         aStoreRule->SetSelected( 
       
  1535             (TCmFillRuleStatus)iStatement.ColumnInt( 2 ) );
       
  1536         aStoreRule->SetStatus( 
       
  1537             (TCmListItemStatus)iStatement.ColumnInt( 3 ) );
       
  1538         err = KErrNone;                               
       
  1539         }    
       
  1540     iStatement.Reset();             
       
  1541     iStatement.Close();  // Destruct statement
       
  1542     err = QueryStoreRuleDefsL( aStoreRule, ruleGroupID );
       
  1543     
       
  1544     return err;        
       
  1545     }
       
  1546     
       
  1547 // ---------------------------------------------------------------------------
       
  1548 // CCmDmSQLiteConnection::QueryStoreRuleDefsL
       
  1549 // ---------------------------------------------------------------------------
       
  1550 //
       
  1551 TInt CCmDmSQLiteConnection::QueryStoreRuleDefsL( CCmStoreRule* aStoreRule,
       
  1552     TUint64 aRuleGroupID )    
       
  1553     {
       
  1554     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryStoreRuleDefsL()"));
       
  1555     
       
  1556     TInt err( iStatement.Prepare( iDatabase, KSelectStoreRuleDefs ) );
       
  1557     if( err )
       
  1558         {
       
  1559         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  1560             CCmDmSQLiteConnection::QueryStoreRuleL() FAIL5")));
       
  1561         err = KErrGeneral; 
       
  1562         }
       
  1563     else
       
  1564         {  
       
  1565         TPtrC8 temp;  
       
  1566         iStatement.BindBinary( 0, aStoreRule->Name() );
       
  1567         // Loop all rows in results
       
  1568         for ( err = iStatement.Next(); 
       
  1569               err == KSqlAtRow; 
       
  1570               err = iStatement.Next() )
       
  1571             {
       
  1572             // Get cell contents
       
  1573             aStoreRule->AddStoreRuleL( 
       
  1574                 (TCmMediaType)iStatement.ColumnInt( 1 ) ); 
       
  1575             }            
       
  1576         
       
  1577         iStatement.Reset();            
       
  1578         iStatement.Close();  // Destruct statement
       
  1579 
       
  1580         err = iStatement.Prepare( iDatabase, KSelectStoreRuleMediaServerID );
       
  1581         RArray<TUint64> mediaServerIds;
       
  1582         CleanupClosePushL( mediaServerIds );        
       
  1583         
       
  1584         if( err )
       
  1585             {
       
  1586             TRACE( Print(
       
  1587                 _L("[DATABASE MANAGER]\t KSelectMediaServerID FAIL") ) );
       
  1588             }
       
  1589         else
       
  1590             {
       
  1591             iStatement.BindInt64( 0, aRuleGroupID );
       
  1592             // Loop all rows in results
       
  1593             for ( err = iStatement.Next(); 
       
  1594                   err == KSqlAtRow; 
       
  1595                   err = iStatement.Next() )
       
  1596                 {
       
  1597                 // Get cell contents    
       
  1598                 mediaServerIds.AppendL( 
       
  1599                     iStatement.ColumnInt64( 0 ));
       
  1600                 }
       
  1601             iStatement.Reset();            
       
  1602             iStatement.Close();// Destruct statement
       
  1603             TInt mediaServerCount( mediaServerIds.Count() );             
       
  1604             for( TInt mediaServerIndex = 0; 
       
  1605                 mediaServerIndex < mediaServerCount ; mediaServerIndex++ )
       
  1606                 {
       
  1607                 err = iStatement.Prepare( iDatabase, 
       
  1608                     KSelectRuleUDNsByMediaServerID );
       
  1609                 if( err )
       
  1610                     {
       
  1611                     TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  1612                         KSelectRuleUDNsByMediaServerID FAIL")));
       
  1613                     err = KErrGeneral;            
       
  1614                     }
       
  1615                 else
       
  1616                     {
       
  1617                     iStatement.BindInt64( 0, 
       
  1618                         mediaServerIds[mediaServerIndex] );
       
  1619                     // Loop all rows in results
       
  1620                         for ( err = iStatement.Next(); 
       
  1621                               err == KSqlAtRow; 
       
  1622                               err = iStatement.Next() )
       
  1623                         {
       
  1624                         // Get cell contents
       
  1625                         iStatement.ColumnBinary( 0, temp );
       
  1626                         aStoreRule->AddMediaServerL( temp );
       
  1627                         }
       
  1628                     iStatement.Reset();            
       
  1629                     iStatement.Close();  // Destruct statement
       
  1630                     }                                                         
       
  1631                 }
       
  1632             mediaServerIds.Reset();
       
  1633             CleanupStack::PopAndDestroy( &mediaServerIds );
       
  1634             }
       
  1635         }        
       
  1636     return err;        
       
  1637     }
       
  1638 
       
  1639 // ---------------------------------------------------------------------------
       
  1640 // CCmDmSQLiteConnection::QueryStoreRuleNamesL
       
  1641 // ---------------------------------------------------------------------------
       
  1642 //
       
  1643 void CCmDmSQLiteConnection::QueryStoreRuleNamesL( 
       
  1644     RPointerArray<HBufC8>& aNames )
       
  1645     {
       
  1646     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryStoreRuleNamesL()"));  
       
  1647     
       
  1648     // Loop only one row in results
       
  1649     TPtrC8 temp;
       
  1650     while( KSqlAtRow == iStatement.Next() )  
       
  1651         {
       
  1652         // Get cell contents               
       
  1653         iStatement.ColumnBinary( 0, temp );
       
  1654         aNames.Append( temp.AllocL() );             
       
  1655         }    
       
  1656     iStatement.Reset();                
       
  1657     iStatement.Close();  // Destruct statement                        
       
  1658     }
       
  1659 
       
  1660 // ---------------------------------------------------------------------------
       
  1661 // CCmDmSQLiteConnection::QuerySelectedStoreRuleNamesL
       
  1662 // ---------------------------------------------------------------------------
       
  1663 //
       
  1664 void CCmDmSQLiteConnection::QuerySelectedStoreRuleNamesL(
       
  1665     RPointerArray<HBufC8>& aNames, TInt aSelected )
       
  1666     {
       
  1667     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  1668     QuerySelectedStoreRuleNamesL()"));
       
  1669         
       
  1670     // Do binding only for the first row
       
  1671     iStatement.BindInt( 0, aSelected );
       
  1672     // Loop only one row in results
       
  1673     TPtrC8 temp;
       
  1674     while( KSqlAtRow == iStatement.Next() )  
       
  1675         {
       
  1676         // Get cell contents
       
  1677         iStatement.ColumnBinary( 0, temp );
       
  1678         aNames.Append( temp.AllocL() );                
       
  1679         }    
       
  1680     iStatement.Reset();                
       
  1681     iStatement.Close();  // Destruct statement                    
       
  1682     }    
       
  1683     
       
  1684 // ---------------------------------------------------------------------------
       
  1685 // CCmDmSQLiteConnection::QueryMediaServerL
       
  1686 // ---------------------------------------------------------------------------
       
  1687 //    
       
  1688 TInt CCmDmSQLiteConnection::QueryMediaServerL( 
       
  1689     CCmMediaServerFull* aMediaServer )
       
  1690     {
       
  1691     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryMediaServerL()"));
       
  1692           
       
  1693     iStatement.BindBinary( 0, aMediaServer->MediaServer() ); 
       
  1694         // Loop only one row in results
       
  1695     TInt err( KErrNotFound );
       
  1696     if ( KSqlAtRow == iStatement.Next() )  
       
  1697         {
       
  1698         TPtrC8 temp;
       
  1699         // Get cell contents
       
  1700         iStatement.ColumnBinary( 2, temp );    
       
  1701         aMediaServer->SetMediaServerNameL( temp );
       
  1702         aMediaServer->SetSystemUpdateID( 
       
  1703             iStatement.ColumnInt( 3 ) );
       
  1704         aMediaServer->SetVisibleDate( 
       
  1705             iStatement.ColumnInt64( 4 ) );
       
  1706         aMediaServer->SetIsActive( 
       
  1707             iStatement.ColumnInt( 5 ) ); 
       
  1708         aMediaServer->SetFillUsage( 
       
  1709             iStatement.ColumnInt( 6 ) );
       
  1710         err = KErrNone;             
       
  1711         }    
       
  1712     iStatement.Reset();                
       
  1713     iStatement.Close();  // Destruct statement            
       
  1714 
       
  1715     return err;    
       
  1716     }
       
  1717 
       
  1718 // ---------------------------------------------------------------------------
       
  1719 // CCmDmSQLiteConnection::QueryMediaServerId
       
  1720 // ---------------------------------------------------------------------------
       
  1721 //
       
  1722 TInt64 CCmDmSQLiteConnection::QueryMediaServerId( const TDesC8& aUDN )
       
  1723     {
       
  1724     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryMediaServerId()"));
       
  1725     
       
  1726     iStatement.BindBinary( 0, aUDN );
       
  1727     // Loop only one row in results
       
  1728     TInt err( KErrNotFound );
       
  1729     if ( KSqlAtRow == iStatement.Next() )  
       
  1730         {
       
  1731         // Get cell contents   
       
  1732         err = iStatement.ColumnInt64( 0 );        
       
  1733         }    
       
  1734     iStatement.Reset();                
       
  1735     iStatement.Close();  // Destruct statement            
       
  1736 
       
  1737     return err;        
       
  1738     }
       
  1739 
       
  1740 // ---------------------------------------------------------------------------
       
  1741 // CCmDmSQLiteConnection::QueryMediaServerUdn
       
  1742 // ---------------------------------------------------------------------------
       
  1743 //
       
  1744 TInt CCmDmSQLiteConnection::QueryMediaServerUdn( HBufC8*& aUdn, 
       
  1745                                                  const TInt32 aId )
       
  1746     {
       
  1747     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryMediaServerId()"));
       
  1748     
       
  1749     iStatement.BindInt64( 0, aId );
       
  1750     // Loop only one row in results
       
  1751     TInt err( iStatement.Next() );
       
  1752     if ( err == KSqlAtRow )  
       
  1753         {
       
  1754         // Get cell contents
       
  1755         TPtrC8 temp;
       
  1756         iStatement.ColumnBinary( 0, temp );
       
  1757         aUdn = temp.Alloc();
       
  1758         err = KErrNone;
       
  1759         }
       
  1760     iStatement.Reset();                
       
  1761     iStatement.Close();  // Destruct statement            
       
  1762 
       
  1763     return err;        
       
  1764     }
       
  1765 
       
  1766 // ---------------------------------------------------------------------------
       
  1767 // CCmDmSQLiteConnection::QueryAllMediaServersL
       
  1768 // ---------------------------------------------------------------------------
       
  1769 //    
       
  1770 TInt CCmDmSQLiteConnection::QueryAllMediaServersL( 
       
  1771     CCmMediaServerFull* aMediaServer )
       
  1772     {
       
  1773     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryAllMediaServersL()"));
       
  1774     
       
  1775     // Loop only one row in results
       
  1776     TInt err( KErrNotFound );
       
  1777     if ( KSqlAtRow == iStatement.Next() )  
       
  1778         {
       
  1779         TPtrC8 temp;
       
  1780         // Get cell contents
       
  1781         iStatement.ColumnBinary( 0, temp );
       
  1782         aMediaServer->SetUDNL(temp);  
       
  1783         iStatement.ColumnBinary( 1, temp );    
       
  1784         aMediaServer->SetMediaServerNameL( temp );
       
  1785         aMediaServer->SetSystemUpdateID( 
       
  1786             iStatement.ColumnInt( 2 ) );
       
  1787         aMediaServer->SetVisibleDate( 
       
  1788             iStatement.ColumnInt64( 3 ) );
       
  1789         aMediaServer->SetIsActive( 
       
  1790             iStatement.ColumnInt( 4 ) );
       
  1791         aMediaServer->SetDbId( 
       
  1792             iStatement.ColumnInt( 5 ) );            
       
  1793         aMediaServer->SetCopyCapability( (TBool)iStatement.ColumnInt( 6 ) );
       
  1794         aMediaServer->SetFillUsage( iStatement.ColumnInt( 7 ) );
       
  1795         aMediaServer->SetStoreUsage( iStatement.ColumnInt( 8 ) );
       
  1796         err = KErrNone;                                       
       
  1797         }      
       
  1798     if( KErrNotFound == err )
       
  1799         {
       
  1800         iStatement.Reset();                
       
  1801         iStatement.Close();  // Destruct statement    
       
  1802         }            
       
  1803     return err;    
       
  1804     }
       
  1805 
       
  1806 // ---------------------------------------------------------------------------
       
  1807 // CCmDmSQLiteConnection::GetMediaServersL
       
  1808 // ---------------------------------------------------------------------------
       
  1809 //    
       
  1810 void CCmDmSQLiteConnection::GetMediaServersL( 
       
  1811     RPointerArray<CCmMediaServerFull>& aMediaServers )
       
  1812     {
       
  1813     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetMediaServersL()"));
       
  1814        
       
  1815     iStatement.PrepareL( iDatabase, KSelectAllMediaServers );
       
  1816     // Loop only one row in results
       
  1817     while ( KSqlAtRow == iStatement.Next() )  
       
  1818         {
       
  1819         CCmMediaServerFull* server = CCmMediaServerFull::NewLC();
       
  1820         TPtrC8 temp;
       
  1821         // Get cell contents
       
  1822         iStatement.ColumnBinary( 0, temp );
       
  1823         server->SetUDNL(temp);  
       
  1824         iStatement.ColumnBinary( 1, temp );    
       
  1825         server->SetMediaServerNameL( temp );
       
  1826         server->SetSystemUpdateID( 
       
  1827             iStatement.ColumnInt( 2 ) );
       
  1828         server->SetVisibleDate( 
       
  1829             iStatement.ColumnInt64( 3 ) );
       
  1830         server->SetIsActive( 
       
  1831             iStatement.ColumnInt( 4 ) );
       
  1832         server->SetDbId( 
       
  1833             iStatement.ColumnInt( 5 ) );
       
  1834         server->SetCopyCapability( 
       
  1835             iStatement.ColumnInt( 6 ) );
       
  1836         server->SetFillUsage( iStatement.ColumnInt( 7 ) );                
       
  1837         server->SetStoreUsage( iStatement.ColumnInt( 8 ) );                
       
  1838             
       
  1839         aMediaServers.AppendL( server ); // transfer ownership
       
  1840         CleanupStack::Pop( server );
       
  1841         server = NULL;
       
  1842         }      
       
  1843     iStatement.Reset();                
       
  1844     iStatement.Close();  // Destruct statement               
       
  1845     }
       
  1846 
       
  1847 // ---------------------------------------------------------------------------
       
  1848 // CCmDmSQLiteConnection::QueryHashValuesL
       
  1849 // ---------------------------------------------------------------------------
       
  1850 //
       
  1851 TInt CCmDmSQLiteConnection::QueryHashValuesL( TInt aMediaServer, 
       
  1852     RPointerArray<CCmSearchResponseHash>& aHashValues )
       
  1853     {
       
  1854     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryHashValuesL()"));
       
  1855     
       
  1856     iStatement.BindInt( 0, aMediaServer );        
       
  1857     // Loop only one row in results
       
  1858     TInt err( KErrNone );
       
  1859     while( ( err = iStatement.Next( ) ) == KSqlAtRow ) 
       
  1860         {
       
  1861         CCmSearchResponseHash* newHash = CCmSearchResponseHash::NewL();
       
  1862         CleanupStack::PushL( newHash );
       
  1863         // Get cell contents   
       
  1864         newHash->SetStartIndex( iStatement.ColumnInt( 0 ));
       
  1865         newHash->SetItemCount( iStatement.ColumnInt( 1 ));  
       
  1866         TPtrC8 temp; 
       
  1867         iStatement.ColumnBinary( 2, temp );
       
  1868         newHash->SetHashL( temp );
       
  1869         aHashValues.AppendL( newHash );             
       
  1870         CleanupStack::Pop( newHash );
       
  1871         
       
  1872         }    
       
  1873     iStatement.Reset( );                
       
  1874     iStatement.Close( );  // Destruct statement            
       
  1875     
       
  1876     return err;        
       
  1877     }
       
  1878         
       
  1879 // ---------------------------------------------------------------------------
       
  1880 // CCmDmSQLiteConnection::GetLowPriorityFilledFilesL
       
  1881 // ---------------------------------------------------------------------------
       
  1882 //
       
  1883 TInt CCmDmSQLiteConnection::GetLowPriorityFilledFilesL( TInt aDrive,
       
  1884     RPointerArray<CCmFillListItem>& aFilled )
       
  1885     {
       
  1886     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  1887     GetLowPriorityFilledFilesL()"));
       
  1888     
       
  1889     TPtrC temp;
       
  1890     TUint32 size( KErrNone );
       
  1891     TInt64 listId( KErrNone );
       
  1892     TInt64 fileId( KErrNone );      
       
  1893     iStatement.BindInt( 0, (TInt)ECmFilled );
       
  1894     iStatement.BindInt( 1, (TInt)ECmFilled );
       
  1895     iStatement.BindInt( 2, aDrive );
       
  1896     TInt err( KErrNone );        
       
  1897 
       
  1898     for ( err = iStatement.Next(); 
       
  1899           err == KSqlAtRow; 
       
  1900           err = iStatement.Next() )
       
  1901         {
       
  1902         iStatement.ColumnText( 0, temp );
       
  1903         size = iStatement.ColumnInt( 1 );
       
  1904         listId = iStatement.ColumnInt( 2 );
       
  1905         fileId = iStatement.ColumnInt64( 3 );   
       
  1906         if( temp.Length() )
       
  1907             {
       
  1908             CCmFillListItem* filled = CCmFillListItem::NewLC();
       
  1909             filled->SetPathL( temp );
       
  1910             filled->SetSize( size );
       
  1911             filled->SetListId( listId );
       
  1912             filled->SetDbId( fileId );
       
  1913             aFilled.AppendL( filled );
       
  1914             CleanupStack::Pop( filled );                
       
  1915             }                                
       
  1916         }
       
  1917     iStatement.Reset();                
       
  1918     iStatement.Close();  // Destruct statement    
       
  1919     return err;            
       
  1920     }
       
  1921     
       
  1922 // ---------------------------------------------------------------------------
       
  1923 // CCmDmSQLiteConnection::QueryFillFileListL
       
  1924 // ---------------------------------------------------------------------------
       
  1925 //
       
  1926 TInt CCmDmSQLiteConnection::QueryFillFileListL( 
       
  1927     RPointerArray<CCmBaseListItem>& aItems, 
       
  1928     const TDesC8& aName, 
       
  1929     TUint aStatus )
       
  1930     {
       
  1931     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryFillFileListL()"));
       
  1932     
       
  1933     iStatement.BindInt( 0, aStatus );
       
  1934     iStatement.BindBinary( 1, aName );
       
  1935     TPtrC temp;
       
  1936     TInt ret( KErrNone );
       
  1937     while( iStatement.Next() == KSqlAtRow )
       
  1938         {
       
  1939         CCmBaseListItem* item = CCmBaseListItem::NewLC();
       
  1940         /**
       
  1941         Read rows into package
       
  1942         */
       
  1943         iStatement.ColumnText( 0, temp );
       
  1944         item->SetPrimaryTextL( temp );
       
  1945         iStatement.ColumnText( 1, temp );
       
  1946         item->SetSecondaryTextL( temp );
       
  1947         iStatement.ColumnText( 2, temp );
       
  1948         item->SetPathL( temp );                           
       
  1949         item->SetSize( iStatement.ColumnInt64( 3 ));
       
  1950         item->SetStatus(
       
  1951             (TCmListItemStatus)iStatement.ColumnInt( 4 ));
       
  1952         item->SetDate( iStatement.ColumnInt64( 5 ) );
       
  1953         item->SetDbId( iStatement.ColumnInt64( 6 ) );
       
  1954         item->SetRefId( iStatement.ColumnInt64( 7 ) );
       
  1955         aItems.Append( item );
       
  1956         CleanupStack::Pop( item );
       
  1957         }
       
  1958     iStatement.Reset();                
       
  1959     iStatement.Close();  // Destruct statement    
       
  1960     return ret;            
       
  1961     }
       
  1962 
       
  1963 // ---------------------------------------------------------------------------
       
  1964 // CCmDmSQLiteConnection::GetAllFillFilesL
       
  1965 // ---------------------------------------------------------------------------
       
  1966 //
       
  1967 TInt CCmDmSQLiteConnection::GetAllFillFilesL( 
       
  1968                                     RPointerArray<CCmFillListItem>& aItems,
       
  1969                                     TUint aStatus )
       
  1970     {
       
  1971     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetAllFillFilesL()"));
       
  1972     
       
  1973     TInt ret(KErrNone);
       
  1974     TPtrC temp16;
       
  1975     TPtrC8 temp8;
       
  1976     iStatement.BindInt( 0, aStatus );
       
  1977     while( iStatement.Next() == KSqlAtRow)
       
  1978         {
       
  1979         CCmFillListItem* item = CCmFillListItem::NewLC();
       
  1980         /**
       
  1981         Read rows into package
       
  1982         */
       
  1983         item->SetDbId( iStatement.ColumnInt64( 0 ) );
       
  1984         iStatement.ColumnText( 1, temp16 );
       
  1985         item->SetPrimaryTextL( temp16 );
       
  1986         iStatement.ColumnText( 2, temp16 );
       
  1987         if ( temp16.Length() != 0 ) 
       
  1988             {
       
  1989             item->SetSecondaryTextL( temp16 );
       
  1990             }
       
  1991         else 
       
  1992             {
       
  1993             item->SetSecondaryTextL( KNullDesC() );
       
  1994             }
       
  1995         
       
  1996         iStatement.ColumnText( 3, temp16 );
       
  1997         if ( temp16.Length() != 0 ) 
       
  1998             {
       
  1999             item->SetPathL( temp16 );
       
  2000             }
       
  2001         else 
       
  2002             {
       
  2003             item->SetPathL( KNullDesC() );
       
  2004             }
       
  2005         iStatement.ColumnBinary( 4, temp8 );
       
  2006         item->SetUriL( temp8 );
       
  2007         iStatement.ColumnBinary( 5, temp8 );
       
  2008         item->SetItemIdL( temp8 );   
       
  2009         iStatement.ColumnText( 6, temp16 );
       
  2010         item->SetUpnpClassL( temp16 );
       
  2011         item->SetMediaType( (TCmMediaType)
       
  2012             iStatement.ColumnInt( 7 ) );    
       
  2013         item->SetPriority( iStatement.ColumnInt( 8 ) );
       
  2014         item->SetSize( iStatement.ColumnInt64( 9 ) );
       
  2015         item->SetStatus(
       
  2016             (TCmListItemStatus)iStatement.ColumnInt( 10 ) );
       
  2017         item->SetDate( iStatement.ColumnInt64( 11 ) );
       
  2018         item->SetListId( iStatement.ColumnInt( 12 ) );
       
  2019         item->SetDevId( iStatement.ColumnInt( 13 ) );
       
  2020         item->SetRefId( iStatement.ColumnInt64( 14 ) );
       
  2021         item->SetSelected( (TCmFillRuleStatus)
       
  2022             iStatement.ColumnInt( 15 ) );
       
  2023         item->SetDriveId( iStatement.ColumnInt64( 16 ) );
       
  2024         item->SetDriveNumber( iStatement.ColumnInt( 17 ) );    
       
  2025         aItems.Append( item );
       
  2026         CleanupStack::Pop( item );
       
  2027         }       
       
  2028     iStatement.Reset();                
       
  2029     iStatement.Close();  // Destruct statement    
       
  2030     return ret;    
       
  2031     }
       
  2032     
       
  2033 // ---------------------------------------------------------------------------
       
  2034 // CCmDmSQLiteConnection::QueryStoreFileListL
       
  2035 // ---------------------------------------------------------------------------
       
  2036 //    
       
  2037 TInt CCmDmSQLiteConnection::QueryStoreFileListL( 
       
  2038     RPointerArray<CCmBaseListItem>& aItems, 
       
  2039     const TDesC8& aName, 
       
  2040     TUint /*aStatus*/ )
       
  2041     {
       
  2042     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryStoreFileListL()"));
       
  2043     
       
  2044     TInt ret(KErrNone);
       
  2045     TPtrC temp16;
       
  2046     iStatement.BindBinary( 0, aName );
       
  2047     while( iStatement.Next() == KSqlAtRow )
       
  2048         {
       
  2049         CCmBaseListItem* item = CCmBaseListItem::NewLC();        
       
  2050         /**
       
  2051         Read rows into package
       
  2052         */
       
  2053         iStatement.ColumnText( 0, temp16 );
       
  2054         item->SetPrimaryTextL( temp16 );
       
  2055         iStatement.ColumnText( 1, temp16 );
       
  2056         item->SetSecondaryTextL( temp16 );
       
  2057         iStatement.ColumnText( 2, temp16 );
       
  2058         item->SetPathL( temp16 );                       
       
  2059         item->SetSize( iStatement.ColumnInt64( 3 ) );
       
  2060         item->SetDate( iStatement.ColumnInt64( 4 ) );
       
  2061         aItems.Append(item); // transfer ownership
       
  2062         CleanupStack::Pop( item );
       
  2063         }
       
  2064     iStatement.Reset();                
       
  2065     iStatement.Close();  // Destruct statement    
       
  2066     return ret;    
       
  2067     }
       
  2068 
       
  2069 // ---------------------------------------------------------------------------
       
  2070 // CCmDmSQLiteConnection::GetAllStoreFilesL
       
  2071 // ---------------------------------------------------------------------------
       
  2072 //
       
  2073 TInt CCmDmSQLiteConnection::GetAllStoreFilesL( 
       
  2074     RPointerArray<CCmStoreListItem>& aItems, TUint aStatus )
       
  2075     {
       
  2076     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetAllStoreFilesL()"));
       
  2077     
       
  2078     TInt ret(KErrNone);
       
  2079     iStatement.BindInt( 0, aStatus );
       
  2080     TPtrC temp16;
       
  2081     TUint status(KErrNone);
       
  2082     TUint8 devId(KErrNone);
       
  2083     while( iStatement.Next() == KSqlAtRow )
       
  2084         {
       
  2085         CCmStoreListItem* item = CCmStoreListItem::NewL();
       
  2086         CleanupStack::PushL( item );
       
  2087         /**
       
  2088         Read rows into package
       
  2089         */
       
  2090         iStatement.ColumnText( 0, temp16 );
       
  2091         item->SetPrimaryTextL( temp16 );
       
  2092         iStatement.ColumnText( 1, temp16 );
       
  2093         item->SetSecondaryTextL( temp16 );
       
  2094         iStatement.ColumnText( 2, temp16 );
       
  2095         item->SetPathL( temp16 );                        
       
  2096         item->SetSize( iStatement.ColumnInt64( 3 ));
       
  2097         status = iStatement.ColumnInt( 4 );
       
  2098         item->SetListId( iStatement.ColumnInt( 5 ) );
       
  2099         devId = iStatement.ColumnInt( 6 );
       
  2100         item->SetDevId( devId, (TCmListItemStatus)status );            
       
  2101         aItems.AppendL( item ); // transfer ownership
       
  2102         CleanupStack::Pop( item );
       
  2103         }       
       
  2104     iStatement.Reset();                
       
  2105     iStatement.Close();  // Destruct statement    
       
  2106     return ret;    
       
  2107     }
       
  2108     
       
  2109 // ---------------------------------------------------------------------------
       
  2110 // CCmDmSQLiteConnection::QueryAllFillFilesL
       
  2111 // ---------------------------------------------------------------------------
       
  2112 //    
       
  2113 TInt CCmDmSQLiteConnection::QueryAllFillFilesL( 
       
  2114     RPointerArray<CCmFillListItem>& aItems )
       
  2115     {
       
  2116     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryAllFillFilesL()"));
       
  2117     
       
  2118     TInt ret(KErrNone);
       
  2119     TPtrC temp16;
       
  2120     TPtrC8 temp8;
       
  2121     while( iStatement.Next() == KSqlAtRow )
       
  2122         {
       
  2123         CCmFillListItem* item = CCmFillListItem::NewL();
       
  2124         CleanupStack::PushL( item );
       
  2125         /**
       
  2126         Read rows into package
       
  2127         */
       
  2128         item->SetDbId( iStatement.ColumnInt64( 0 ) );
       
  2129         iStatement.ColumnText( 1, temp16 );
       
  2130         item->SetPrimaryTextL( temp16 );
       
  2131         iStatement.ColumnText( 2, temp16 );
       
  2132         item->SetSecondaryTextL( temp16 );
       
  2133         iStatement.ColumnText( 3, temp16 );
       
  2134         item->SetPathL( temp16 );             
       
  2135         iStatement.ColumnBinary( 4, temp8 );
       
  2136         item->SetUriL( temp8 );
       
  2137         iStatement.ColumnBinary( 5, temp8 );
       
  2138         item->SetItemIdL( temp8 );   
       
  2139         iStatement.ColumnText( 6, temp16 );
       
  2140         item->SetUpnpClassL( temp16 );
       
  2141         item->SetMediaType( (TCmMediaType)
       
  2142             iStatement.ColumnInt( 7 ) );    
       
  2143         item->SetPriority( iStatement.ColumnInt( 8 ) );
       
  2144         item->SetSize( iStatement.ColumnInt64( 9 ));
       
  2145         item->SetStatus(
       
  2146             (TCmListItemStatus)iStatement.ColumnInt( 10 ));
       
  2147         item->SetDate( iStatement.ColumnInt64( 11 ) );
       
  2148         item->SetListId( iStatement.ColumnInt( 12 ) );
       
  2149         item->SetDevId( iStatement.ColumnInt( 13 ) );
       
  2150         item->SetRefId( iStatement.ColumnInt64( 14 ) );
       
  2151         item->SetSelected( ( TCmFillRuleStatus )
       
  2152             iStatement.ColumnInt( 15 ));
       
  2153         item->SetDriveId( iStatement.ColumnInt64( 16 ) );
       
  2154         item->SetDriveNumber( iStatement.ColumnInt( 17 ) );    
       
  2155         aItems.AppendL( item ); // transfer ownership
       
  2156         CleanupStack::Pop( item );
       
  2157         }
       
  2158     iStatement.Reset();                
       
  2159     iStatement.Close();  // Destruct statement    
       
  2160     return ret;    
       
  2161     }
       
  2162 
       
  2163 // ---------------------------------------------------------------------------
       
  2164 // CCmDmSQLiteConnection::QueryAllStoreFilesL
       
  2165 // ---------------------------------------------------------------------------
       
  2166 //    
       
  2167 TInt CCmDmSQLiteConnection::QueryAllStoreFilesL( 
       
  2168     RPointerArray<CCmStoreListItem>& aItems )
       
  2169     {
       
  2170     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryAllStoreFilesL()"));
       
  2171     
       
  2172     TInt ret(KErrNone);
       
  2173     TPtrC temp16;
       
  2174     TBool found( EFalse );
       
  2175     TInt foundIndex( KErrNone );    
       
  2176     while( iStatement.Next() == KSqlAtRow )
       
  2177         {
       
  2178         CCmStoreListItem* item = CCmStoreListItem::NewL();
       
  2179         CleanupStack::PushL( item );
       
  2180         /**
       
  2181         Read rows into package
       
  2182         */
       
  2183         item->SetDbId( iStatement.ColumnInt64( 0 ) );
       
  2184         iStatement.ColumnText( 1, temp16  );
       
  2185         item->SetPrimaryTextL( temp16 );
       
  2186         iStatement.ColumnText( 2, temp16 );
       
  2187         item->SetSecondaryTextL( temp16 );    
       
  2188         iStatement.ColumnText( 3, temp16 );
       
  2189         item->SetPathL( temp16 );                               
       
  2190         item->SetSize( iStatement.ColumnInt64( 4 ) );
       
  2191         TCmListItemStatus status = 
       
  2192             (TCmListItemStatus)iStatement.ColumnInt( 5 );
       
  2193 
       
  2194         item->SetListId( iStatement.ColumnInt( 6 ) );
       
  2195         TInt devId = iStatement.ColumnInt( 7 );
       
  2196         item->SetDevId( devId, status );            
       
  2197         for( TInt i = 0; i < aItems.Count() && !found ; i++ )
       
  2198             {
       
  2199             if( aItems[i]->DbId() == item->DbId() )
       
  2200                 {
       
  2201                 found = ETrue;
       
  2202                 foundIndex = i;
       
  2203                 }
       
  2204             }
       
  2205         if( !found )
       
  2206             {
       
  2207             aItems.AppendL( item ); // transfer ownership
       
  2208             CleanupStack::Pop( item );
       
  2209             }
       
  2210         else
       
  2211             {
       
  2212             aItems[foundIndex]->SetDevId( devId, status );
       
  2213             CleanupStack::PopAndDestroy( item ); // Destroy item
       
  2214             }        
       
  2215         found = EFalse;
       
  2216         }
       
  2217     iStatement.Reset();                
       
  2218     iStatement.Close();  // Destruct statement    
       
  2219     return ret;    
       
  2220     }
       
  2221                 
       
  2222 // ---------------------------------------------------------------------------
       
  2223 // CCmDmSQLiteConnection::QueryStoredRowL
       
  2224 // ---------------------------------------------------------------------------
       
  2225 //
       
  2226 void CCmDmSQLiteConnection::QueryStoredRowL( 
       
  2227     RPointerArray<HBufC16>& aFiles, 
       
  2228     const TDesC8& aUDN, 
       
  2229     TInt aAmount )
       
  2230     {
       
  2231     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryStoredRowL()"));
       
  2232            
       
  2233     iStatement.BindBinary( 0, aUDN );
       
  2234     TInt amount = aAmount;    
       
  2235     // Loop only one row in results
       
  2236     while( KSqlAtRow == iStatement.Next() || amount == 0 )  
       
  2237         {
       
  2238         // Get cell contents    
       
  2239         TPtrC temp;
       
  2240         iStatement.ColumnText( 0, temp );
       
  2241         aFiles.Append( temp.AllocL() ); 
       
  2242         if( amount != KErrNotFound )
       
  2243             {
       
  2244             amount--;
       
  2245             }
       
  2246         }    
       
  2247     iStatement.Reset();                
       
  2248     iStatement.Close();  // Destruct statement                           
       
  2249     }
       
  2250 
       
  2251 // ---------------------------------------------------------------------------
       
  2252 // CCmDmSQLiteConnection::QueryTransferHistory
       
  2253 // ---------------------------------------------------------------------------
       
  2254 //
       
  2255 void CCmDmSQLiteConnection::QueryTransferHistory( 
       
  2256     const TDesC8& aUdn,
       
  2257     TInt64& aDownloadData, 
       
  2258     TInt64& aUploadData, 
       
  2259     TInt64& aDownloadTime, 
       
  2260     TInt64& aUploadTime )
       
  2261     {
       
  2262     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryTransferHistory()"));
       
  2263     
       
  2264     iStatement.BindBinary( 0, aUdn );
       
  2265     // Loop only one row
       
  2266     if( KSqlAtRow == iStatement.Next() )  
       
  2267         {
       
  2268         // Get cell contents    
       
  2269         aDownloadData = iStatement.ColumnInt64( 0 );
       
  2270         aUploadData = iStatement.ColumnInt64( 1 );
       
  2271         aDownloadTime = iStatement.ColumnInt64( 2 );
       
  2272         aUploadTime = iStatement.ColumnInt64( 3 );  
       
  2273         }        
       
  2274     iStatement.Reset();                
       
  2275     iStatement.Close();               
       
  2276     }
       
  2277 
       
  2278 // ---------------------------------------------------------------------------
       
  2279 // CCmDmSQLiteConnection::QueryDeletedItemsListsL
       
  2280 // ---------------------------------------------------------------------------
       
  2281 //
       
  2282 void CCmDmSQLiteConnection::QueryDeletedItemsListsL( 
       
  2283     RPointerArray<CCmBaseListItem>& aArray, TUint aStatus )
       
  2284     {
       
  2285     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  2286     QueryDeletedItemsListsL()"));
       
  2287 
       
  2288     TPtrC temp16;
       
  2289     iStatement.BindInt( 0, aStatus );        
       
  2290     while( iStatement.Next() == KSqlAtRow )
       
  2291         {
       
  2292         CCmBaseListItem* item = CCmBaseListItem::NewLC();
       
  2293         /**
       
  2294         Read rows into package
       
  2295         */
       
  2296         iStatement.ColumnText( 0, temp16 );
       
  2297         item->SetPrimaryTextL( temp16 );
       
  2298         iStatement.ColumnText( 1, temp16 );
       
  2299         item->SetSecondaryTextL( temp16 );
       
  2300         iStatement.ColumnText( 2, temp16 );
       
  2301         item->SetPathL( temp16 );                          
       
  2302         item->SetSize( iStatement.ColumnInt64( 3 ) );
       
  2303         item->SetStatus(
       
  2304             (TCmListItemStatus)iStatement.ColumnInt( 4 ) );
       
  2305         item->SetDate(iStatement.ColumnInt64( 5 ) );
       
  2306         item->SetDbId( iStatement.ColumnInt64( 6 ) );
       
  2307         aArray.Append( item );
       
  2308         CleanupStack::Pop( item );
       
  2309         }
       
  2310     iStatement.Reset();                
       
  2311     iStatement.Close();  // Destruct statement        
       
  2312     }
       
  2313 
       
  2314 // ---------------------------------------------------------------------------
       
  2315 // CCmDmSQLiteConnection::QueryDrivesL
       
  2316 // ---------------------------------------------------------------------------
       
  2317 //
       
  2318 void CCmDmSQLiteConnection::QueryDrivesL( 
       
  2319     RPointerArray<CCmDriveInfo>& aDrives )
       
  2320     {
       
  2321     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::QueryDrivesL()"));
       
  2322     
       
  2323     TPtrC temp16;       
       
  2324     while( iStatement.Next() == KSqlAtRow )
       
  2325         {
       
  2326         CCmDriveInfo* drive = CCmDriveInfo::NewLC();
       
  2327         /**
       
  2328         Read rows into package
       
  2329         */
       
  2330         drive->SetDriveNumber( iStatement.ColumnInt( 0 ) );
       
  2331         drive->SetDriveType( iStatement.ColumnInt( 1 ) );
       
  2332         iStatement.ColumnText( 2, temp16 );
       
  2333         if ( temp16.Length() != 0 ) 
       
  2334             {
       
  2335             drive->SetDriveNameL( temp16 );
       
  2336             }
       
  2337         else 
       
  2338             {
       
  2339             drive->SetDriveNameL( KNullDesC() );
       
  2340             }           
       
  2341         drive->SetDriveSize( iStatement.ColumnInt64( 3 ) );
       
  2342         drive->SetDriveQuota( iStatement.ColumnInt64( 4 ) );
       
  2343         drive->SetUsedDriveQuota( iStatement.ColumnInt64( 5 ) );
       
  2344         drive->SetDriveId( iStatement.ColumnInt64( 6 ) );
       
  2345         drive->SetStatus( (TBool)iStatement.ColumnInt( 7 ) );
       
  2346         aDrives.AppendL( drive );
       
  2347         CleanupStack::Pop( drive ); 
       
  2348         }   
       
  2349     iStatement.Reset();                
       
  2350     iStatement.Close();  // Destruct statement     
       
  2351     }
       
  2352       
       
  2353 // ---------------------------------------------------------------------------
       
  2354 // CCmDmSQLiteConnection::GetAvgImageShrinkTime
       
  2355 // ---------------------------------------------------------------------------
       
  2356 //
       
  2357 TInt CCmDmSQLiteConnection::GetAvgImageShrinkTime()
       
  2358     {
       
  2359     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetAvgImageShrinkTime()"));
       
  2360     
       
  2361     TInt err( iStatement.Prepare( iDatabase, KImageShrinkingInfo ) );
       
  2362     TInt64 count( KErrNone );
       
  2363     TInt64 time( KErrNone );
       
  2364     if( err )
       
  2365         {
       
  2366         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  2367             KImageShrinkingInfo illegal err = %d"), err ));
       
  2368         }
       
  2369     else
       
  2370         {
       
  2371         // Loop only one row
       
  2372         err = iStatement.Next();
       
  2373         if( err == KSqlAtRow )  
       
  2374             {
       
  2375             // Get cell contents    
       
  2376             count = iStatement.ColumnInt64( 0 );
       
  2377             time = iStatement.ColumnInt64( 1 );                   
       
  2378             }        
       
  2379         }
       
  2380         
       
  2381     iStatement.Reset();                
       
  2382     iStatement.Close();
       
  2383     if( count != KErrNone )
       
  2384         {
       
  2385         return TInt(time/count);
       
  2386         }
       
  2387     else
       
  2388         {
       
  2389         return KErrNone;
       
  2390         }
       
  2391     }
       
  2392 
       
  2393 // ---------------------------------------------------------------------------
       
  2394 // CCmDmSQLiteConnection::GetFillListNameL
       
  2395 // ---------------------------------------------------------------------------
       
  2396 //
       
  2397 void CCmDmSQLiteConnection::GetFillListNameL( HBufC8*& aListName, 
       
  2398     const TInt64 aListId )
       
  2399     {
       
  2400     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetFillListNameL()"));
       
  2401     
       
  2402     TInt err( iStatement.Prepare( iDatabase, KSelectFillRuleName ) );
       
  2403     if( err )
       
  2404         {
       
  2405         User::Leave( err );
       
  2406         }
       
  2407     else
       
  2408         {
       
  2409         iStatement.BindInt64( 0, aListId );
       
  2410         // Loop only one row
       
  2411         err = iStatement.Next();
       
  2412         if( err == KSqlAtRow )  
       
  2413             {
       
  2414             TPtrC8 temp;
       
  2415             iStatement.ColumnBinary( 0, temp );
       
  2416             aListName = temp.Alloc();
       
  2417             }        
       
  2418         }
       
  2419     iStatement.Reset();                
       
  2420     iStatement.Close();   
       
  2421     }
       
  2422                 
       
  2423 // ---------------------------------------------------------------------------
       
  2424 // CCmDmSQLiteConnection::DeleteMediaServer
       
  2425 // ---------------------------------------------------------------------------
       
  2426 //
       
  2427 TInt CCmDmSQLiteConnection::DeleteMediaServer( const TDesC8& aUDN )
       
  2428     {
       
  2429     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DeleteMediaServer()"));
       
  2430     
       
  2431     TInt err( iStatement.Prepare( iDatabase, KRemoveMediaServersByUDN ) );
       
  2432     if( !err )
       
  2433         {    
       
  2434         iStatement.BindBinary( 0, aUDN );
       
  2435         iStatement.Exec();
       
  2436         iStatement.Reset();
       
  2437         iStatement.Close();
       
  2438         }
       
  2439 
       
  2440     // In error cases for return value to KErrGeneral
       
  2441     return ( err ? KErrGeneral : KErrNone );    
       
  2442     }
       
  2443     
       
  2444 // ---------------------------------------------------------------------------
       
  2445 // CCmDmSQLiteConnection::DeleteFillRuleByName
       
  2446 // ---------------------------------------------------------------------------
       
  2447 //    
       
  2448 TInt CCmDmSQLiteConnection::DeleteFillRuleByName( const TDesC8& aName )
       
  2449     {
       
  2450     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DeleteFillRuleByName()"));
       
  2451     
       
  2452     // Remove ruleparams
       
  2453     TInt err( iStatement.Prepare( iDatabase, KRemoveRuleParamsByRuleID) );
       
  2454     if( !err )
       
  2455         {
       
  2456         iStatement.BindBinary( 0, aName );
       
  2457         iStatement.Exec();
       
  2458         iStatement.Reset();
       
  2459         iStatement.Close(); 
       
  2460 
       
  2461         // Remove rules
       
  2462         err = iStatement.Prepare( iDatabase, KRemoveRuleByRuleGroupID);
       
  2463         iStatement.BindBinary( 0, aName );
       
  2464         iStatement.Exec();
       
  2465         iStatement.Reset();
       
  2466         iStatement.Close();     
       
  2467 
       
  2468         // Remove Mediaservers from the mapping table
       
  2469         err = iStatement.Prepare( iDatabase, KRemoveRuleGroupServers);
       
  2470         iStatement.BindBinary( 0, aName );
       
  2471         iStatement.Exec();
       
  2472         iStatement.Reset();
       
  2473         iStatement.Close();
       
  2474 
       
  2475         // Remove FillRules
       
  2476         err = iStatement.Prepare( iDatabase, KRemoveFillRuleByName );
       
  2477         iStatement.BindBinary( 0, aName );
       
  2478         iStatement.Exec();
       
  2479         iStatement.Reset();
       
  2480         iStatement.Close();
       
  2481         }
       
  2482     
       
  2483     // In error cases for return value to KErrGeneral
       
  2484     return ( err ? KErrGeneral : KErrNone );         
       
  2485     }
       
  2486 
       
  2487 // ---------------------------------------------------------------------------
       
  2488 // CCmDmSQLiteConnection::DeleteAllFillRules
       
  2489 // ---------------------------------------------------------------------------
       
  2490 //
       
  2491 TInt CCmDmSQLiteConnection::DeleteAllFillRules()
       
  2492     {
       
  2493     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DeleteAllFillRules()"));
       
  2494     
       
  2495     // Remove ruleparams
       
  2496     TInt err( iStatement.Prepare( iDatabase, KRemoveRuleParamAll ) );
       
  2497     if( !err )
       
  2498         {
       
  2499         iStatement.Exec();
       
  2500         iStatement.Reset();
       
  2501         iStatement.Close(); 
       
  2502 
       
  2503         // Remove rules
       
  2504         err = iStatement.Prepare( iDatabase, KRemoveRuleAll );
       
  2505         if( !err )
       
  2506             {
       
  2507             iStatement.Exec();
       
  2508             iStatement.Reset();
       
  2509             iStatement.Close();     
       
  2510 
       
  2511             // Remove Mediaservers from the mapping table
       
  2512             err = iStatement.Prepare( iDatabase, KRemoveRuleGroupServerAll);
       
  2513             if( !err )
       
  2514                 {
       
  2515                 iStatement.Exec();
       
  2516                 iStatement.Reset();
       
  2517                 iStatement.Close();
       
  2518 
       
  2519                 // Remove FillRules
       
  2520                 err = iStatement.Prepare( iDatabase, KRemoveFillRuleAll );
       
  2521                 if( !err )
       
  2522                     {
       
  2523                     iStatement.Exec();
       
  2524                     iStatement.Reset();
       
  2525                     iStatement.Close();
       
  2526                     }
       
  2527                 }
       
  2528             }
       
  2529         iRuleGroupID = 1;
       
  2530         iRuleID = 1;
       
  2531         iRuleParamID = 1;             
       
  2532         }
       
  2533 
       
  2534     // In error cases for return value to KErrGeneral
       
  2535     return ( err ? KErrGeneral : KErrNone );          
       
  2536     }
       
  2537 
       
  2538 // ---------------------------------------------------------------------------
       
  2539 // CCmDmSQLiteConnection::DeleteAllStoreRules
       
  2540 // ---------------------------------------------------------------------------
       
  2541 //    
       
  2542 TInt CCmDmSQLiteConnection::DeleteAllStoreRules()
       
  2543     {
       
  2544     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DeleteAllStoreRules()"));
       
  2545     
       
  2546     // Remove ruleparams     
       
  2547     TInt err = iStatement.Prepare( iDatabase, KRemoveStoreRuleServers );
       
  2548     if( !err )
       
  2549         {
       
  2550         iStatement.Exec();
       
  2551         iStatement.Reset();
       
  2552         iStatement.Close();
       
  2553 
       
  2554         // Remove rules
       
  2555         err = iStatement.Prepare( iDatabase, KRemoveStoreRuleParams );
       
  2556         if( !err )
       
  2557             {
       
  2558             iStatement.Exec();
       
  2559             iStatement.Reset();
       
  2560             iStatement.Close();
       
  2561             // Remove Mediaservers from the mapping table
       
  2562             err = iStatement.Prepare( iDatabase, KRemoveStoreRules );
       
  2563             if( !err )
       
  2564                 {
       
  2565                 iStatement.Exec();
       
  2566                 iStatement.Reset();
       
  2567                 iStatement.Close();
       
  2568                 }
       
  2569             else
       
  2570                 {
       
  2571                 err = KErrGeneral;
       
  2572                 }
       
  2573             }
       
  2574         else
       
  2575             {
       
  2576             err = KErrGeneral;
       
  2577             }
       
  2578         }
       
  2579 
       
  2580     iStoreRuleID = 1;
       
  2581     iStoreRuleParamID = 1;                
       
  2582   
       
  2583     return err;         
       
  2584     }
       
  2585     
       
  2586 // ---------------------------------------------------------------------------
       
  2587 // CCmDmSQLiteConnection::DeleteFillFiles
       
  2588 // ---------------------------------------------------------------------------
       
  2589 //    
       
  2590 TInt CCmDmSQLiteConnection::DeleteFillFiles()
       
  2591     {
       
  2592     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DeleteFillFiles()"));
       
  2593     
       
  2594     return iDatabase.Exec( KRemoveFillFiles );
       
  2595     }
       
  2596 
       
  2597 // ---------------------------------------------------------------------------
       
  2598 // CCmDmSQLiteConnection::DeleteStoreFiles
       
  2599 // ---------------------------------------------------------------------------
       
  2600 //    
       
  2601 TInt CCmDmSQLiteConnection::DeleteStoreFiles()
       
  2602     {
       
  2603     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DeleteStoreFiles()"));
       
  2604     
       
  2605     iDatabase.Exec( KRemoveStoreFiles );    
       
  2606     TInt err = iDatabase.Exec( KRemoveStoreFileServers );
       
  2607     return err;
       
  2608     }
       
  2609 
       
  2610 // ---------------------------------------------------------------------------
       
  2611 // CCmDmSQLiteConnection::DeleteDeletedItemsL
       
  2612 // ---------------------------------------------------------------------------
       
  2613 //
       
  2614 void CCmDmSQLiteConnection::DeleteDeletedItemsL()
       
  2615     {
       
  2616     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DeleteDeletedItemsL()"));
       
  2617     
       
  2618     TInt err( iStatement.Prepare( iDatabase, KRemoveDeletedFillFiles ) );
       
  2619     if( !err )
       
  2620         {    
       
  2621         iStatement.Exec();
       
  2622         iStatement.Reset();
       
  2623         iStatement.Close(); 
       
  2624         }
       
  2625     else
       
  2626         {
       
  2627         User::Leave( err );
       
  2628         }   
       
  2629     }
       
  2630 
       
  2631 // ---------------------------------------------------------------------------
       
  2632 // CCmDmSQLiteConnection::DeleteDeletedMediaServersL
       
  2633 // ---------------------------------------------------------------------------
       
  2634 //
       
  2635 void CCmDmSQLiteConnection::DeleteDeletedMediaServersL()
       
  2636     {
       
  2637     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  2638     DeleteDeletedMediaServersL()"));
       
  2639     
       
  2640     TInt err( iStatement.Prepare( iDatabase, KRemoveDeletedMediaServers ) );
       
  2641     if( !err )
       
  2642         {    
       
  2643         iStatement.Exec();
       
  2644         iStatement.Reset();
       
  2645         iStatement.Close(); 
       
  2646         }
       
  2647     else
       
  2648         {
       
  2649         User::Leave( err );
       
  2650         }   
       
  2651     }
       
  2652 
       
  2653 // ---------------------------------------------------------------------------
       
  2654 // CCmDmSQLiteConnection::DeleteHashValuesL
       
  2655 // ---------------------------------------------------------------------------
       
  2656 //
       
  2657 void CCmDmSQLiteConnection::DeleteHashValuesL( const TInt aMediaserverId,
       
  2658     const TInt aSearchIndex )
       
  2659     {
       
  2660     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DeleteHashValuesL()"));
       
  2661     
       
  2662     TInt err( iStatement.Prepare( iDatabase, KRemoveHash ) );    
       
  2663     if( !err )
       
  2664         {
       
  2665         iStatement.BindInt( 0, aMediaserverId );
       
  2666         iStatement.BindInt( 1, aSearchIndex );
       
  2667         iStatement.Exec();
       
  2668         iStatement.Reset();
       
  2669         iStatement.Close();
       
  2670         }
       
  2671     else
       
  2672         {
       
  2673         User::Leave( err );
       
  2674         }            
       
  2675     }
       
  2676                 
       
  2677 // ---------------------------------------------------------------------------
       
  2678 // CCmDmSQLiteConnection::UpdateMediaServerInfo
       
  2679 // ---------------------------------------------------------------------------
       
  2680 //    
       
  2681 TInt CCmDmSQLiteConnection::UpdateMediaServerInfo( 
       
  2682     CCmMediaServerFull* aMediaServer )    
       
  2683     {
       
  2684     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::UpdateMediaServerInfo()"));
       
  2685     
       
  2686     // Remove ruleparams
       
  2687     TInt err( iStatement.Prepare( iDatabase, KUpdateMediaServerInfo ) );
       
  2688     if( !err )
       
  2689         {    
       
  2690         iStatement.BindBinary( 0, aMediaServer->MediaServerName() );
       
  2691         iStatement.BindInt( 1, aMediaServer->SystemUpdateID() );
       
  2692         iStatement.BindInt64( 2, aMediaServer->VisibleDate().Int64() );
       
  2693         iStatement.BindBinary( 3, aMediaServer->MediaServer() );    
       
  2694         iStatement.Exec();
       
  2695         iStatement.Reset();
       
  2696         iStatement.Close();
       
  2697         }
       
  2698   
       
  2699     // In error cases for return value to KErrGeneral
       
  2700     return ( err ? KErrGeneral : KErrNone ); 
       
  2701     }
       
  2702 
       
  2703 // ---------------------------------------------------------------------------
       
  2704 // CCmDmSQLiteConnection::UpdateFillRuleSelected
       
  2705 // ---------------------------------------------------------------------------
       
  2706 //
       
  2707 TInt CCmDmSQLiteConnection::UpdateFillRuleSelected( 
       
  2708     const TDesC8& aName, 
       
  2709     TInt aSelected )
       
  2710     {
       
  2711     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::UpdateFillRuleSelected()"));
       
  2712     
       
  2713     // Update Fill Rule
       
  2714     TInt err( iStatement.Prepare( iDatabase, KUpdateFillRuleSelected ) );
       
  2715     if( !err )
       
  2716         {
       
  2717         iStatement.BindInt( 0, aSelected );
       
  2718         iStatement.BindBinary( 1, aName );    
       
  2719         iStatement.Exec();
       
  2720         iStatement.Reset();
       
  2721         iStatement.Close();        
       
  2722         }    
       
  2723         
       
  2724     // In error cases for return value to KErrGeneral
       
  2725     return ( err ? KErrGeneral : KErrNone ); 
       
  2726     }
       
  2727 
       
  2728 // ---------------------------------------------------------------------------
       
  2729 // CCmDmSQLiteConnection::UpdateFillRuleGroupInfo
       
  2730 // ---------------------------------------------------------------------------
       
  2731 //
       
  2732 TInt CCmDmSQLiteConnection::UpdateFillRuleGroupInfo()
       
  2733 	{
       
  2734 	LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  2735 	UpdateFillRuleGroupInfo()"));
       
  2736 	
       
  2737 	TInt err = iDatabase.Exec( KSetNullRealSizes );
       
  2738 	return err;
       
  2739 	}
       
  2740 
       
  2741 // ---------------------------------------------------------------------------
       
  2742 // CCmDmSQLiteConnection::UpdateDownloadHistory
       
  2743 // ---------------------------------------------------------------------------
       
  2744 //
       
  2745 TInt CCmDmSQLiteConnection::UpdateDownloadHistory( TUint aMediaServerId,
       
  2746     TInt64& aDownloadData, TInt64& aDownloadTime )
       
  2747     {
       
  2748     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::UpdateDownloadHistory()"));
       
  2749     
       
  2750     TInt err( iStatement.Prepare( iDatabase, KUpdateDownloadHistory ) );
       
  2751     if( !err )
       
  2752         {
       
  2753         iStatement.BindInt64( 0, aDownloadData );
       
  2754         iStatement.BindInt64( 1, aDownloadTime );
       
  2755         iStatement.BindInt( 2, aMediaServerId );
       
  2756         err = iStatement.Exec();
       
  2757         iStatement.Reset(  );
       
  2758         iStatement.Close();         
       
  2759         }
       
  2760     return err;        
       
  2761     }
       
  2762     
       
  2763 // ---------------------------------------------------------------------------
       
  2764 // CCmDmSQLiteConnection::UpdateUploadHistory
       
  2765 // ---------------------------------------------------------------------------
       
  2766 //
       
  2767 TInt CCmDmSQLiteConnection::UpdateUploadHistory( TUint aMediaServerId,
       
  2768     TInt64& aUploadData, TInt64& aUploadTime )
       
  2769     {
       
  2770     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::UpdateUploadHistory()"));
       
  2771     
       
  2772     TInt err( iStatement.Prepare( iDatabase, KUpdateUploadHistory ) );
       
  2773     if( !err )
       
  2774         {
       
  2775         iStatement.BindInt64( 0, aUploadData );
       
  2776         iStatement.BindInt64( 1, aUploadTime );
       
  2777         iStatement.BindInt( 2, aMediaServerId );
       
  2778         err = iStatement.Exec();
       
  2779         iStatement.Reset();
       
  2780         iStatement.Close();         
       
  2781         }
       
  2782     return err;    
       
  2783     }
       
  2784 
       
  2785 // ---------------------------------------------------------------------------
       
  2786 // CCmDmSQLiteConnection::UpdateStatusValues
       
  2787 // ---------------------------------------------------------------------------
       
  2788 //
       
  2789 TInt CCmDmSQLiteConnection::UpdateStatusValues( 
       
  2790     RPointerArray<CCmBaseListItem>& aStatusValues )
       
  2791     {
       
  2792     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::UpdateStatusValues()"));
       
  2793     
       
  2794     TInt err( KErrNone );
       
  2795     iDatabase.Exec( KCmDbBeginTransaction );    
       
  2796     err = iStatement.Prepare( iDatabase, KUpdateFileStatus );    
       
  2797     if( !err ) 
       
  2798         {
       
  2799         for( TInt i = 0; i < aStatusValues.Count(); i++ )
       
  2800             {        
       
  2801             iStatement.BindInt64( 0, aStatusValues[i]->Status() );
       
  2802             iStatement.BindInt64( 1, aStatusValues[i]->DbId() );          
       
  2803             iStatement.BindInt64( 2, aStatusValues[i]->DbId() );
       
  2804             iStatement.Exec();
       
  2805             iStatement.Reset();             
       
  2806             }        
       
  2807         }
       
  2808     iStatement.Close();        
       
  2809     iDatabase.Exec( KCmDbSqlCommit );
       
  2810     return err;
       
  2811     }
       
  2812 
       
  2813 // ---------------------------------------------------------------------------
       
  2814 // CCmDmSQLiteConnection::UpdateFillListDriveStatusesL
       
  2815 // ---------------------------------------------------------------------------
       
  2816 //
       
  2817 void CCmDmSQLiteConnection::UpdateFillListDriveStatusesL( 
       
  2818     CCmDriveInfo* aOrigDrive, CCmDriveInfo* aNewDrive, 
       
  2819     TBool aDriveSelected )
       
  2820     {
       
  2821     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  2822     UpdateFillListDriveStatusesL()"));
       
  2823     
       
  2824     if( aDriveSelected )
       
  2825         {
       
  2826         // Update only drive number and drive id
       
  2827         TInt err( iStatement.Prepare( iDatabase, KUpdateFillDriveInfo ) );
       
  2828         User::LeaveIfError( err );
       
  2829         iStatement.BindInt( 0, aNewDrive->DriveNumber() );
       
  2830         iStatement.BindInt64( 1, aNewDrive->DriveId() );
       
  2831         iStatement.BindInt64( 2, aOrigDrive->DriveId() );       
       
  2832         iStatement.Exec();
       
  2833         iStatement.Reset();
       
  2834         iStatement.Close();                 
       
  2835         }
       
  2836     else
       
  2837         {
       
  2838         // Set path, drive number, drive id, quota, size to null and
       
  2839         // update fill status to orginal
       
  2840         TInt err( iStatement.Prepare( iDatabase, 
       
  2841             KUpdateFillDriveAndStatusInfo ) );
       
  2842         User::LeaveIfError( err );
       
  2843         iStatement.BindText( 0, KNullDesC() );
       
  2844         iStatement.BindInt( 1, 0 );
       
  2845         iStatement.BindInt64( 2, 0 );
       
  2846         iStatement.BindInt( 3, (TInt)ECmToBeFilled );
       
  2847         iStatement.BindInt64( 4, aOrigDrive->DriveId() );       
       
  2848         iStatement.Exec();
       
  2849         iStatement.Reset();
       
  2850         iStatement.Close();                          
       
  2851         }
       
  2852     }
       
  2853     
       
  2854 // ---------------------------------------------------------------------------
       
  2855 // CCmDmSQLiteConnection::UpdateFillListItemPriority
       
  2856 // ---------------------------------------------------------------------------
       
  2857 //
       
  2858 TInt CCmDmSQLiteConnection::UpdateFillListItemPriority( 
       
  2859     CCmFillRuleContainer* aContainer )    
       
  2860     {
       
  2861     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  2862     UpdateFillListItemPriority()"));
       
  2863     
       
  2864     iDatabase.Exec( KCmDbBeginTransaction );    
       
  2865     TInt err( iStatement.Prepare( iDatabase, KUpdateFillItemPriorities ) );
       
  2866     if ( !err )
       
  2867         {
       
  2868         for( TInt i = 0; i < aContainer->FillRuleCount(); i++ )    
       
  2869             {        
       
  2870             iStatement.BindInt( 0, aContainer->FillRule( i )->Priority() );
       
  2871             iStatement.BindInt( 1, aContainer->FillRule( i )->Selected() );
       
  2872             iStatement.BindBinary( 2, aContainer->FillRule( i )->Name() );
       
  2873             iStatement.Exec();
       
  2874             iStatement.Reset();                
       
  2875             }      
       
  2876         }
       
  2877     iStatement.Close();        
       
  2878     iDatabase.Exec( KCmDbSqlCommit );
       
  2879     
       
  2880     //update fill item's status 
       
  2881     iDatabase.Exec( KCmDbBeginTransaction );    
       
  2882     TInt err1( iStatement.Prepare( 
       
  2883         iDatabase, KUpdateFillItemStatusByRuleName ) );
       
  2884     if ( !err1 )
       
  2885         {
       
  2886         for( TInt i = 0; i < aContainer->FillRuleCount(); i++ )    
       
  2887             {        
       
  2888             iStatement.BindInt( 0, aContainer->FillRule( i )->Status() );
       
  2889             iStatement.BindBinary( 1, aContainer->FillRule( i )->Name() );
       
  2890             iStatement.Exec();
       
  2891             iStatement.Reset();            
       
  2892             }                        
       
  2893         }
       
  2894     iStatement.Close();
       
  2895     iDatabase.Exec( KCmDbSqlCommit );
       
  2896     return err;
       
  2897     }
       
  2898 
       
  2899 // ---------------------------------------------------------------------------
       
  2900 // CCmDmSQLiteConnection::SetFillListStateL
       
  2901 // ---------------------------------------------------------------------------
       
  2902 //
       
  2903 void CCmDmSQLiteConnection::SetFillListStateL( const TUint aListId, 
       
  2904     TCmFillRuleStatus aState )
       
  2905     {
       
  2906     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::SetFillListStateL()"));
       
  2907     
       
  2908     TInt err( iStatement.Prepare( iDatabase, KUpdateSelectionStatus ) );
       
  2909     if( err )
       
  2910         {
       
  2911         User::Leave( err );
       
  2912         }
       
  2913     else
       
  2914         {
       
  2915         iStatement.BindInt( 0, aState );   
       
  2916         iStatement.BindInt( 1, aListId );
       
  2917         iStatement.Exec();
       
  2918         iStatement.Reset();   
       
  2919         iStatement.Close();        
       
  2920         }         
       
  2921     }
       
  2922 
       
  2923 // ---------------------------------------------------------------------------
       
  2924 // CCmDmSQLiteConnection::RestoreFileStatusesL
       
  2925 // ---------------------------------------------------------------------------
       
  2926 //
       
  2927 void CCmDmSQLiteConnection::RestoreFileStatusesL( 
       
  2928     const RPointerArray<CCmFillListItem>& aItems, 
       
  2929     const TDesC8& aListName )
       
  2930     {
       
  2931     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::RestoreFileStatusesL()"));
       
  2932     
       
  2933     TInt err( iStatement.Prepare( iDatabase, KGetFillListStatus ) );
       
  2934     TRACE( Print( _L("[DB MNGR]\t KGetFillListStatus err = %d "), 
       
  2935         err ) );    
       
  2936     
       
  2937     TUint status( KErrNone );
       
  2938         
       
  2939     if( err )
       
  2940         {
       
  2941         User::Leave( err ); 
       
  2942         }        
       
  2943     else
       
  2944         {
       
  2945         iStatement.BindBinary( 0, aListName );
       
  2946         err = iStatement.Next();
       
  2947         if ( err == KSqlAtRow )  
       
  2948             {
       
  2949             status = iStatement.ColumnInt( 0 );
       
  2950             }
       
  2951         }
       
  2952     TRACE( Print( _L("[DB MNGR]\t Status to be updated = %d "), 
       
  2953         status ) );        
       
  2954     iStatement.Reset(); 
       
  2955     iStatement.Close();
       
  2956     DoRestoreFileStatusesL( aItems, status );   
       
  2957     }
       
  2958 
       
  2959 // ---------------------------------------------------------------------------
       
  2960 // CCmDmSQLiteConnection::DoRestoreFileStatusesL
       
  2961 // ---------------------------------------------------------------------------
       
  2962 //
       
  2963 void CCmDmSQLiteConnection::DoRestoreFileStatusesL( 
       
  2964                         const RPointerArray<CCmFillListItem>& aItems, 
       
  2965                         const TUint aStatus )
       
  2966     {
       
  2967     
       
  2968     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DoRestoreFileStatusesL"));
       
  2969     
       
  2970     iDatabase.Exec( KCmDbBeginTransaction );    
       
  2971     TInt err( iStatement.Prepare( iDatabase, KRestoreFileStatus ) );    
       
  2972     
       
  2973     if( err )
       
  2974         {
       
  2975         User::Leave( err );
       
  2976         }
       
  2977         
       
  2978     for( TInt i = 0; i < aItems.Count(); i++ )
       
  2979         {            
       
  2980         iStatement.BindInt( 0, aStatus );
       
  2981         iStatement.BindInt64( 1, aItems[i]->DbId() );
       
  2982         iStatement.BindInt64( 2, aItems[i]->DbId() );
       
  2983         iStatement.Exec();
       
  2984         iStatement.Reset();           
       
  2985         }
       
  2986         
       
  2987     iStatement.Close();        
       
  2988     iDatabase.Exec( KCmDbSqlCommit );
       
  2989     }
       
  2990 
       
  2991 // ---------------------------------------------------------------------------
       
  2992 // CCmDmSQLiteConnection::SetRefIdsToZero
       
  2993 // ---------------------------------------------------------------------------
       
  2994 //
       
  2995 void CCmDmSQLiteConnection::SetRefIdsToZero()
       
  2996     {
       
  2997     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::SetRefIdsToZero()"));
       
  2998     
       
  2999     iDatabase.Exec( KUpdateFillItemRef_Zero );        
       
  3000     }
       
  3001         
       
  3002 // ---------------------------------------------------------------------------
       
  3003 // CCmDmSQLiteConnection::IncrementShrinkTimeL
       
  3004 // ---------------------------------------------------------------------------
       
  3005 //
       
  3006 TInt CCmDmSQLiteConnection::IncrementShrinkTimeL( TInt aImageCount, 
       
  3007     TInt aMilliSeconds )
       
  3008     {
       
  3009     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::IncrementShrinkTimeL()"));
       
  3010     
       
  3011     TInt err( iStatement.Prepare( iDatabase, KIncrementImageShrinkingInfo ) );
       
  3012     if( err )
       
  3013         {
       
  3014         User::Leave( err );
       
  3015         }
       
  3016     else
       
  3017         {
       
  3018         iStatement.BindInt64( 0, aImageCount );
       
  3019         iStatement.BindInt64( 1, aMilliSeconds );
       
  3020         err = iStatement.Exec();
       
  3021         iStatement.Reset();
       
  3022         iStatement.Close();        
       
  3023         }        
       
  3024     return err;  
       
  3025     }
       
  3026     
       
  3027 // ---------------------------------------------------------------------------
       
  3028 // CCmDmSQLiteConnection::FillListSize
       
  3029 // ---------------------------------------------------------------------------
       
  3030 //
       
  3031 TInt64 CCmDmSQLiteConnection::FillListSize( const TDesC8& aListName, 
       
  3032                                              TUint aStatus )
       
  3033     {
       
  3034     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::FillListSize()"));
       
  3035     
       
  3036     TInt err( iStatement.Prepare( iDatabase, KFillListSize ) );
       
  3037     TInt64 size(KErrNone);
       
  3038     if( err )
       
  3039         {
       
  3040         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3041             FillListSize illegal err = %d"), err ));
       
  3042         }
       
  3043     else
       
  3044         {
       
  3045         iStatement.BindInt( 0, aStatus );
       
  3046         iStatement.BindBinary( 1, aListName );
       
  3047 
       
  3048         for ( err = iStatement.Next(); 
       
  3049               err == KSqlAtRow; 
       
  3050               err = iStatement.Next() )
       
  3051             {
       
  3052             // Get cell contents    
       
  3053             size = iStatement.ColumnInt64( 0 );             
       
  3054             }        
       
  3055         }    
       
  3056     iStatement.Reset();            
       
  3057     iStatement.Close();  // Destruct statement
       
  3058     return size;          
       
  3059     }
       
  3060 
       
  3061 // ---------------------------------------------------------------------------
       
  3062 // CCmDmSQLiteConnection::StoreListSize
       
  3063 // ---------------------------------------------------------------------------
       
  3064 //
       
  3065 TInt64 CCmDmSQLiteConnection::StoreListSize( 
       
  3066     const TDesC8& aListName, 
       
  3067     TUint /*aStatus*/ )
       
  3068     {
       
  3069     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::StoreListSize()"));
       
  3070     
       
  3071     TInt err( iStatement.Prepare( iDatabase, KStoreListSize ) );
       
  3072     TInt64 size(KErrNone);
       
  3073     if( err )
       
  3074         {
       
  3075         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3076             StoreListSize illegal err = %d"), err ));
       
  3077         }
       
  3078     else
       
  3079         {
       
  3080         iStatement.BindBinary( 0, aListName );
       
  3081 
       
  3082         for ( err = iStatement.Next(); 
       
  3083               err == KSqlAtRow; 
       
  3084               err = iStatement.Next() )
       
  3085             {
       
  3086             // Get cell contents    
       
  3087             size = iStatement.ColumnInt64( 0 );
       
  3088             }        
       
  3089         }    
       
  3090     iStatement.Reset();            
       
  3091     iStatement.Close();  // Destruct statement
       
  3092     return size;      
       
  3093     }
       
  3094 
       
  3095 // ---------------------------------------------------------------------------
       
  3096 // CCmDmSQLiteConnection::StoreFileCount
       
  3097 // ---------------------------------------------------------------------------
       
  3098 //    
       
  3099 TInt CCmDmSQLiteConnection::StoreFileCount( TUint aStatus )
       
  3100     {
       
  3101     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::StoreFileCount()"));
       
  3102     
       
  3103     TInt err( iStatement.Prepare( iDatabase, KStoreFileCount ) );
       
  3104     TInt count(KErrNone);
       
  3105     if( err )
       
  3106         {
       
  3107         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3108             Illegal err = %d"), err ));
       
  3109         }
       
  3110     else
       
  3111         {
       
  3112         iStatement.BindInt( 0, aStatus );
       
  3113 
       
  3114         for ( err = iStatement.Next(); 
       
  3115               err == KSqlAtRow; 
       
  3116               err = iStatement.Next() )
       
  3117             {
       
  3118             // Get cell contents    
       
  3119             count = iStatement.ColumnInt( 0 );               
       
  3120             }        
       
  3121         }    
       
  3122     iStatement.Reset();            
       
  3123     iStatement.Close();  // Destruct statement
       
  3124     return count;  
       
  3125     }
       
  3126 
       
  3127 // ---------------------------------------------------------------------------
       
  3128 // CCmDmSQLiteConnection::StoreFileCountNoDuplicates
       
  3129 // ---------------------------------------------------------------------------
       
  3130 //    
       
  3131 TInt CCmDmSQLiteConnection::StoreFileCountNoDuplicates()
       
  3132     {
       
  3133     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  3134     StoreFileCountNoDuplicates()"));
       
  3135     
       
  3136     TInt err( iStatement.Prepare( iDatabase, KStoreFileCountNoDuplicates ) );
       
  3137     TInt count(KErrNone);
       
  3138     if( err )
       
  3139         {
       
  3140         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3141             Illegal err = %d"), err ));
       
  3142         }
       
  3143     else
       
  3144         {
       
  3145         for ( err = iStatement.Next(); 
       
  3146               err == KSqlAtRow; 
       
  3147               err = iStatement.Next() ) 
       
  3148             {
       
  3149             // Get cell contents    
       
  3150             count = iStatement.ColumnInt( 0 );                
       
  3151             }        
       
  3152         }    
       
  3153     iStatement.Reset();            
       
  3154     iStatement.Close();  // Destruct statement
       
  3155     return count;  
       
  3156     }
       
  3157     
       
  3158 // ---------------------------------------------------------------------------
       
  3159 // CCmDmSQLiteConnection::FillFileCount
       
  3160 // ---------------------------------------------------------------------------
       
  3161 //    
       
  3162 TInt CCmDmSQLiteConnection::FillFileCount( TUint aStatus )
       
  3163     {
       
  3164     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::FillFileCount()"));
       
  3165     
       
  3166     TInt err( iStatement.Prepare( iDatabase, KFillFileCount ) );
       
  3167     TInt count(KErrNone);
       
  3168     if( err )
       
  3169         {
       
  3170         // Do nothing
       
  3171         }
       
  3172     else
       
  3173         {
       
  3174         iStatement.BindInt( 0, aStatus );
       
  3175 
       
  3176         for ( err = iStatement.Next(); 
       
  3177               err == KSqlAtRow; 
       
  3178               err = iStatement.Next() )
       
  3179             {
       
  3180             // Get cell contents    
       
  3181             count = iStatement.ColumnInt( 0 );             
       
  3182             }        
       
  3183         }    
       
  3184     iStatement.Reset();            
       
  3185     iStatement.Close();  // Destruct statement
       
  3186     return count;      
       
  3187     }
       
  3188 
       
  3189 // ---------------------------------------------------------------------------
       
  3190 // Returns size of the filled items
       
  3191 // ---------------------------------------------------------------------------
       
  3192 //
       
  3193 TInt64 CCmDmSQLiteConnection::BytesFilled( TUint aID )
       
  3194     {
       
  3195     TInt err( iStatement.Prepare( iDatabase, KDataAmountFilled ) );
       
  3196     TInt64 size(KErrNone);
       
  3197     if( err )
       
  3198         {
       
  3199         return size;
       
  3200         }
       
  3201     else
       
  3202         {
       
  3203         iStatement.BindInt( 0, aID );
       
  3204 
       
  3205         for ( err = iStatement.Next();
       
  3206               err == KSqlAtRow;
       
  3207               err = iStatement.Next() )
       
  3208             {
       
  3209             // Get cell contents
       
  3210             size = iStatement.ColumnInt64( 0 );
       
  3211             }
       
  3212         }
       
  3213     iStatement.Reset();
       
  3214     iStatement.Close();  // Destruct statement
       
  3215     return size;
       
  3216     }
       
  3217 
       
  3218 // ---------------------------------------------------------------------------
       
  3219 //
       
  3220 TInt64 CCmDmSQLiteConnection::KBytesToBeFilled( TUint8 aMediaServerId, 
       
  3221     TUint aStatus )    
       
  3222     {
       
  3223     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::KBytesToBeFilled()"));
       
  3224     
       
  3225     TInt err( iStatement.Prepare( iDatabase, KDataAmountToBeFilled ) );
       
  3226     TInt64 size(KErrNone);
       
  3227     if( err )
       
  3228         {
       
  3229         return size;
       
  3230         }
       
  3231     else
       
  3232         {
       
  3233         iStatement.BindInt( 0, aStatus );
       
  3234         iStatement.BindInt( 1, aMediaServerId );
       
  3235 
       
  3236         for ( err = iStatement.Next(); 
       
  3237               err == KSqlAtRow; 
       
  3238               err = iStatement.Next() )
       
  3239             {
       
  3240             // Get cell contents    
       
  3241             size = iStatement.ColumnInt64( 0 );             
       
  3242             }         
       
  3243         }    
       
  3244     iStatement.Reset();            
       
  3245     iStatement.Close();  // Destruct statement
       
  3246     return (size/1000);     
       
  3247     }
       
  3248 
       
  3249 // ---------------------------------------------------------------------------
       
  3250 // CCmDmSQLiteConnection::KBytesToBeStored
       
  3251 // ---------------------------------------------------------------------------
       
  3252 //
       
  3253 TInt64 CCmDmSQLiteConnection::KBytesToBeStored( TUint8 aMediaServerId, 
       
  3254     TUint aStatus )
       
  3255     {
       
  3256     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::KBytesToBeStored()"));
       
  3257     
       
  3258     TInt err( iStatement.Prepare( iDatabase, KDataAmountToBeStored ) );
       
  3259     TInt64 size(KErrNone);
       
  3260     if( !err )
       
  3261         {
       
  3262         iStatement.BindInt( 0, aMediaServerId );
       
  3263         iStatement.BindInt( 1, aStatus );
       
  3264 
       
  3265         for ( err = iStatement.Next(); 
       
  3266               err == KSqlAtRow; 
       
  3267               err = iStatement.Next() )
       
  3268             {
       
  3269             // Get cell contents    
       
  3270             size = iStatement.ColumnInt64( 0 );             
       
  3271             }        
       
  3272         }    
       
  3273     iStatement.Reset();            
       
  3274     iStatement.Close();  // Destruct statement
       
  3275     return (size/1000); 
       
  3276     }
       
  3277 
       
  3278 // ---------------------------------------------------------------------------
       
  3279 // CCmDmSQLiteConnection::UpdateTransferInfo
       
  3280 // ---------------------------------------------------------------------------
       
  3281 //    
       
  3282 TInt CCmDmSQLiteConnection::UpdateTransferInfo( TCmService aService, 
       
  3283     TInt aCount, TInt aTime )
       
  3284     {
       
  3285     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::UpdateTransferInfo()"));
       
  3286     
       
  3287     TInt err( iStatement.Prepare( iDatabase, KInitTransferInfo ) );
       
  3288     if( err )
       
  3289         {
       
  3290         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3291             KInitTransferInfo illegal err = %d"), err ));
       
  3292         }
       
  3293     else
       
  3294         {
       
  3295         iStatement.BindInt( 0, aService );
       
  3296         err = iStatement.Exec();                  
       
  3297         }
       
  3298     iStatement.Reset();
       
  3299     iStatement.Close();         
       
  3300     err = iStatement.Prepare( iDatabase, KUpdateTransferInfo );
       
  3301     if( err )
       
  3302         {
       
  3303         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3304             KUpdateTransferInfo illegal err = %d"), err ));
       
  3305         }
       
  3306     else
       
  3307         {
       
  3308         iStatement.BindInt( 0, aCount );
       
  3309         iStatement.BindInt( 1, aTime );
       
  3310         iStatement.BindInt( 2, aService );
       
  3311         err = iStatement.Exec();         
       
  3312         }
       
  3313     iStatement.Reset();
       
  3314     iStatement.Close();                    
       
  3315     return err;          
       
  3316     }   
       
  3317 
       
  3318 // ---------------------------------------------------------------------------
       
  3319 // CCmDmSQLiteConnection::UpdateStoreTransferStatus
       
  3320 // ---------------------------------------------------------------------------
       
  3321 //
       
  3322 void CCmDmSQLiteConnection::UpdateStoreTransferStatus( TUint aStatus,
       
  3323     TInt64 aFid, TInt64 aMsId )
       
  3324     {
       
  3325     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  3326     UpdateStoreTransferStatus()"));
       
  3327     
       
  3328     TInt err( iStatement.Prepare( iDatabase, KUpdateStoreTransferStatus ));
       
  3329     if( err )
       
  3330         {
       
  3331         
       
  3332         }
       
  3333     else
       
  3334         {
       
  3335         iStatement.BindInt( 0, aStatus );
       
  3336         iStatement.BindInt64( 1, aFid );
       
  3337         iStatement.BindInt64( 2, aMsId );
       
  3338         err = iStatement.Exec();
       
  3339         }
       
  3340     iStatement.Reset();
       
  3341     iStatement.Close();                
       
  3342     }
       
  3343 
       
  3344 // ---------------------------------------------------------------------------
       
  3345 // CCmDmSQLiteConnection::UpdateFillTransferStatus
       
  3346 // ---------------------------------------------------------------------------
       
  3347 //
       
  3348 void CCmDmSQLiteConnection::UpdateFillTransferStatus( TUint aStatus, 
       
  3349     CCmFillListItem* aItem )
       
  3350     {
       
  3351     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  3352     UpdateFillTransferStatus()"));
       
  3353     
       
  3354     TInt err( iStatement.Prepare( iDatabase, KUpdateFillTransferStatus ));
       
  3355     if( err )
       
  3356         {
       
  3357         LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  3358         UpdateFillTransferStatus() error preparing statement"));       
       
  3359         }
       
  3360     else
       
  3361         {
       
  3362         iStatement.BindInt( 0, aStatus );
       
  3363         iStatement.BindText( 1, aItem->Path() );
       
  3364         iStatement.BindInt64( 2, aItem->DriveId() );
       
  3365         iStatement.BindInt( 3, aItem->DriveNumber() );
       
  3366         iStatement.BindInt64( 4, aItem->DevId() );
       
  3367         iStatement.BindInt64( 5, aItem->DbId() );
       
  3368         iStatement.BindInt64( 6, aItem->ListId() );
       
  3369         iStatement.BindInt64( 7, aItem->DbId() );
       
  3370         err = iStatement.Exec();
       
  3371         }
       
  3372     iStatement.Reset();
       
  3373     iStatement.Close();      
       
  3374     }
       
  3375         
       
  3376 // ---------------------------------------------------------------------------
       
  3377 // CCmDmSQLiteConnection::GetTransferInfo
       
  3378 // ---------------------------------------------------------------------------
       
  3379 //    
       
  3380 TInt CCmDmSQLiteConnection::GetTransferInfo( TCmService aService, 
       
  3381     TInt& aCount, TInt& aTime )
       
  3382     {
       
  3383     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetTransferInfo()"));
       
  3384     
       
  3385     TInt err( iStatement.Prepare( iDatabase, KTranferValues ) );
       
  3386     aCount = 0;
       
  3387     if( err )
       
  3388         {
       
  3389         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3390             KTranferValues illegal err = %d"), err ));
       
  3391         }
       
  3392     else
       
  3393         {
       
  3394         iStatement.BindInt( 0, aService );
       
  3395 
       
  3396         for ( err = iStatement.Next(); 
       
  3397               err == KSqlAtRow; 
       
  3398               err = iStatement.Next() )
       
  3399             {
       
  3400             // Get cell contents    
       
  3401             aCount = iStatement.ColumnInt( 0 );
       
  3402             err = KErrNone;                   
       
  3403             }        
       
  3404         }    
       
  3405     iStatement.Reset();            
       
  3406     iStatement.Close();  // Destruct statement
       
  3407     err = iStatement.Prepare( iDatabase, KTranferTime );
       
  3408     aTime = 0;
       
  3409     if( err )
       
  3410         {
       
  3411         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3412             KTranferTime illegal err = %d"), err ));
       
  3413         }
       
  3414     else
       
  3415         {
       
  3416         iStatement.BindInt( 0, aService );
       
  3417 
       
  3418         for ( err = iStatement.Next(); 
       
  3419               err == KSqlAtRow; 
       
  3420               err = iStatement.Next() )
       
  3421             {
       
  3422             // Get cell contents    
       
  3423             aTime = iStatement.ColumnInt( 0 );
       
  3424             err = KErrNone;                  
       
  3425             }        
       
  3426         }
       
  3427     iStatement.Reset();            
       
  3428     iStatement.Close();  // Destruct statement            
       
  3429     return err;         
       
  3430     }
       
  3431 
       
  3432 // ---------------------------------------------------------------------------
       
  3433 // CCmDmSQLiteConnection::GetStoreFileCount
       
  3434 // ---------------------------------------------------------------------------
       
  3435 //    
       
  3436 TInt CCmDmSQLiteConnection::GetStoreFileCount( 
       
  3437     const TDesC8& aListName, 
       
  3438     TUint /*aStatus*/, 
       
  3439     TInt& aCount )
       
  3440     {
       
  3441     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetStoreFileCount()"));
       
  3442     
       
  3443     TInt err( iStatement.Prepare( iDatabase, KStoreListFileCount ) );
       
  3444     if( err )
       
  3445         {
       
  3446         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3447             GetStoreFileCount illegal err = %d"), err ));
       
  3448         }
       
  3449     else
       
  3450         {
       
  3451         iStatement.BindBinary( 0, aListName );
       
  3452 
       
  3453         for ( err = iStatement.Next(); 
       
  3454               err == KSqlAtRow; 
       
  3455               err = iStatement.Next() )
       
  3456             {
       
  3457             // Get cell contents    
       
  3458             aCount = iStatement.ColumnInt( 0 );
       
  3459             err = KErrNone;             
       
  3460             }        
       
  3461         }    
       
  3462     iStatement.Reset();            
       
  3463     iStatement.Close();  // Destruct statement
       
  3464     return err;  
       
  3465     }
       
  3466     
       
  3467 // ---------------------------------------------------------------------------
       
  3468 // CCmDmSQLiteConnection::GetFillFileCount
       
  3469 // ---------------------------------------------------------------------------
       
  3470 //
       
  3471 TInt CCmDmSQLiteConnection::GetFillFileCount( 
       
  3472     const TDesC8& aListName, 
       
  3473     TUint aStatus, 
       
  3474     TInt& aCount )
       
  3475     {
       
  3476     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::GetFillFileCount()"));
       
  3477     
       
  3478     TInt err( iStatement.Prepare( iDatabase, KFillListFileCount ) );
       
  3479     if( err )
       
  3480         {
       
  3481         TRACE(Print(_L("[DATABASE MANAGER]\t \
       
  3482             GetFillFileCount illegal err = %d"), err ));
       
  3483         }
       
  3484     else
       
  3485         {
       
  3486         iStatement.BindInt( 0, aStatus );        
       
  3487         iStatement.BindBinary( 1, aListName );
       
  3488         for ( err = iStatement.Next(); 
       
  3489               err == KSqlAtRow; 
       
  3490               err = iStatement.Next() ) 
       
  3491             {
       
  3492             // Get cell contents    
       
  3493             aCount = iStatement.ColumnInt64( 0 );
       
  3494             err = KErrNone;                               
       
  3495             }        
       
  3496         }    
       
  3497     iStatement.Reset();            
       
  3498     iStatement.Close();  // Destruct statement
       
  3499     return err;  
       
  3500     }
       
  3501 
       
  3502 // ---------------------------------------------------------------------------
       
  3503 // CmDmSQLiteConnection::GetStoreFileCountNoDuplicatesL
       
  3504 // ---------------------------------------------------------------------------
       
  3505 //
       
  3506 void CCmDmSQLiteConnection::GetStoreFileCountNoDuplicatesL( TInt& aCount,
       
  3507     TUint aStatus )
       
  3508     {
       
  3509     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  3510     GetStoreFileCountNoDuplicatesL()"));
       
  3511     
       
  3512     TInt err( iStatement.Prepare( iDatabase, 
       
  3513         KGetStoreFileCountNoDuplicates ));
       
  3514     if( err )
       
  3515         {
       
  3516         User::Leave( err );
       
  3517         }
       
  3518     else
       
  3519         {
       
  3520         iStatement.BindInt( 0, aStatus );
       
  3521         if( KSqlAtRow == iStatement.Next() )
       
  3522             {
       
  3523             aCount = iStatement.ColumnInt( 0 );
       
  3524             }
       
  3525         iStatement.Reset();
       
  3526         iStatement.Close();    
       
  3527         }        
       
  3528     }
       
  3529     
       
  3530 // ---------------------------------------------------------------------------
       
  3531 // CCmDmSQLiteConnection::SetFillListRealCountAndSizeL
       
  3532 // ---------------------------------------------------------------------------
       
  3533 //
       
  3534 void CCmDmSQLiteConnection::SetFillListRealCountAndSizeL( TInt64 aListId,
       
  3535     TInt64 aRealCount, TInt64 aRealSize )
       
  3536     {
       
  3537     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  3538     SetFillListRealCountAndSizeL()"));
       
  3539     
       
  3540     // Update Fill Rule
       
  3541     TInt err = iStatement.Prepare( iDatabase, 
       
  3542                                    KUpdateFillRuleRealInformation );
       
  3543     if( !err )
       
  3544         {
       
  3545         iStatement.BindInt64( 0, aRealCount );
       
  3546         iStatement.BindInt64( 1, aRealSize );
       
  3547         iStatement.BindInt64( 2, aListId );    
       
  3548         iStatement.Exec();
       
  3549         iStatement.Reset();
       
  3550         iStatement.Close();     
       
  3551         }
       
  3552     else
       
  3553         {
       
  3554         User::Leave( err );
       
  3555         }        
       
  3556     }
       
  3557     
       
  3558 // ---------------------------------------------------------------------------
       
  3559 // CCmDmSQLiteConnection::DeleteInActiveRuleServers
       
  3560 // ---------------------------------------------------------------------------
       
  3561 //
       
  3562 TInt CCmDmSQLiteConnection::DeleteInActiveRuleServers()
       
  3563     {
       
  3564     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  3565     DeleteInActiveRuleServers()"));
       
  3566     
       
  3567     TInt err( KErrNone );
       
  3568     err = iDatabase.Exec( KRemoveInActiveFillRuleServers );
       
  3569     if( err >= KErrNone )
       
  3570         {
       
  3571         err = iDatabase.Exec( KRemoveInActiveStoreRuleServers );
       
  3572         }
       
  3573     if( err >= KErrNone )
       
  3574         {
       
  3575         err = KErrNone;
       
  3576         }
       
  3577     return err;
       
  3578     }
       
  3579 
       
  3580 // ---------------------------------------------------------------------------
       
  3581 // CCmDmSQLiteConnection::DeleteInActiveFiles
       
  3582 // ---------------------------------------------------------------------------
       
  3583 //
       
  3584 TInt CCmDmSQLiteConnection::DeleteInActiveFiles()
       
  3585     {
       
  3586     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::DeleteInActiveFiles()"));
       
  3587     
       
  3588     TInt err( KErrNone );
       
  3589     iDatabase.Exec( KRemoveInActiveFillFiles );
       
  3590     iDatabase.Exec( KRemoveInActiveStoreFilesServers );
       
  3591     err = iDatabase.Exec( KRemoveInActiveStoreFiles );
       
  3592     if( err >= KErrNone )
       
  3593         {
       
  3594         err = KErrNone;
       
  3595         }
       
  3596     return err;
       
  3597     }
       
  3598 
       
  3599 // ---------------------------------------------------------------------------
       
  3600 // CCmDmSQLiteConnection::DeleteItemsByFillListId
       
  3601 // ---------------------------------------------------------------------------
       
  3602 //   
       
  3603 TInt CCmDmSQLiteConnection::DeleteItemsByFillListId( TInt aFillListId )
       
  3604     {
       
  3605     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::\
       
  3606     DeleteItemsByFillListId()"));
       
  3607     
       
  3608     TInt err( KErrNone );
       
  3609     err = iStatement.Prepare( iDatabase, KRemoveFillListItems );
       
  3610     iStatement.BindInt( 0, aFillListId );
       
  3611     iStatement.Exec();
       
  3612     iStatement.Reset();
       
  3613     iStatement.Close();   
       
  3614     return err;
       
  3615     }
       
  3616         
       
  3617 // ---------------------------------------------------------------------------
       
  3618 // CCmDmSQLiteConnection::RuleId
       
  3619 // ---------------------------------------------------------------------------
       
  3620 //
       
  3621 TInt64 CCmDmSQLiteConnection::RuleId( 
       
  3622     const TDesC8& aName, 
       
  3623     TCmRuleType aType )
       
  3624     {
       
  3625     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::RuleId()"));
       
  3626     
       
  3627     TInt64 ret( KErrNone );
       
  3628     // Fill rule id        
       
  3629     if( ECmFmFillRule == aType )
       
  3630         {
       
  3631         ret = iStatement.Prepare( iDatabase, KSelectRuleGroupID );        
       
  3632         }
       
  3633     // Store rule id        
       
  3634     else
       
  3635         {
       
  3636         ret = iStatement.Prepare( iDatabase, KSelectStoreRuleID );        
       
  3637         }
       
  3638     if( ret )
       
  3639         {
       
  3640         ret = KErrGeneral;
       
  3641         }
       
  3642     else
       
  3643         {
       
  3644         iStatement.BindBinary( 0, aName );                
       
  3645         // Loop only one row in results
       
  3646         ret = iStatement.Next();
       
  3647         if ( ret == KSqlAtRow )  
       
  3648             {
       
  3649             // Get cell contents   
       
  3650             ret = iStatement.ColumnInt64( 0 );        
       
  3651             }    
       
  3652         }
       
  3653     iStatement.Reset();                
       
  3654     iStatement.Close();  // Destruct statement            
       
  3655     TRACE(Print(_L("[DATABASE MANAGER]\t CCmDmSQLiteConnection::RuleId()\
       
  3656          end")));
       
  3657     return ret;        
       
  3658     }
       
  3659         
       
  3660 // ---------------------------------------------------------------------------
       
  3661 // CCmDmSQLiteConnection::CCmDmSQLiteConnection
       
  3662 // ---------------------------------------------------------------------------
       
  3663 //    
       
  3664 CCmDmSQLiteConnection::CCmDmSQLiteConnection()
       
  3665     {
       
  3666     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::CCmDmSQLiteConnection()"));
       
  3667     }
       
  3668  
       
  3669 // ---------------------------------------------------------------------------
       
  3670 // CCmDmSQLiteConnection::ConstructL
       
  3671 // ---------------------------------------------------------------------------
       
  3672 //   
       
  3673 void CCmDmSQLiteConnection::ConstructL()
       
  3674     {
       
  3675     LOG( _L( "[DB MNGR]\t CCmDmSQLiteConnection::ConstructL()"));   
       
  3676     }    
       
  3677 
       
  3678 // End of file