locationdataharvester/maptileservice/src/maptiledblookuptable.cpp
changeset 30 96df3ab41000
parent 26 f3533f6eae3f
child 41 b3dd5ec3089d
equal deleted inserted replaced
26:f3533f6eae3f 30:96df3ab41000
    15 *     Retrieving maptile path from lookup db implementation
    15 *     Retrieving maptile path from lookup db implementation
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 #include <bautils.h>
    19 #include <bautils.h>
       
    20 #include <maptileservice.h>
    20 #include "maptiledblookuptable.h"
    21 #include "maptiledblookuptable.h"
    21 
    22 
    22 // select all from
    23 // select all from
    23 _LIT( KSelectAllFrom, "SELECT * FROM " );
    24 _LIT( KSelectAllFrom, "SELECT * FROM " );
    24 
    25 
    30 
    31 
    31 // string 'And'
    32 // string 'And'
    32 _LIT( KStringAnd, " AND " );
    33 _LIT( KStringAnd, " AND " );
    33 
    34 
    34 
    35 
    35 
    36 _LIT(KQueryByMaptileState,"SELECT * FROM cntmaptilelookuptable WHERE cntuid = %d AND ( fetchingstatus = %d OR fetchingstatus = %d )");
    36 
    37 
    37 // -----------------------------------------------------------------------------
    38 // -----------------------------------------------------------------------------
    38 // CLookupMapTileDatabase::CLookupMapTileDatabase()
    39 // CLookupMapTileDatabase::CLookupMapTileDatabase()
    39 // Default constructor.
    40 // Default constructor.
    40 // -----------------------------------------------------------------------------
    41 // -----------------------------------------------------------------------------
   106         // database exists 
   107         // database exists 
   107         iDatabaseExists = ETrue; 
   108         iDatabaseExists = ETrue; 
   108     }
   109     }
   109 }
   110 }
   110 
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CLookupMapTileDatabase::FindNumberOfAddressL()
       
   114 // find the number of address associated with the aId.
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 int CLookupMapTileDatabase::FindNumberOfAddressL( int& aId )
       
   118 {
       
   119     int count = 0;
       
   120     
       
   121     // Create a query to find the item.
       
   122     TFileName queryBuffer;
       
   123     queryBuffer.Format( KQueryByMaptileState,aId,
       
   124              MapTileService::MapTileFetchingInProgress,
       
   125              MapTileService::MapTileFetchingNetworkError );
       
   126   
       
   127     TInt ret = iItemsDatabase.Open( iFsSession, iDbFileName );
       
   128     
       
   129     if( ret != KErrNone )
       
   130     {          
       
   131         //if already opened , close and open again
       
   132         iItemsDatabase.Close();          
       
   133         User::LeaveIfError( iItemsDatabase.Open( iFsSession, iDbFileName ) );
       
   134     }
       
   135     
       
   136     User::LeaveIfError( iItemsDatabase.Begin() );       
       
   137     // Create a view of the table with the above query.
       
   138     RDbView myView;
       
   139     myView.Prepare( iItemsDatabase, TDbQuery( queryBuffer ) );
       
   140     CleanupClosePushL( myView );
       
   141     myView.EvaluateAll();
       
   142     myView.FirstL();
       
   143     
       
   144     
       
   145     while (myView.AtRow())
       
   146     {
       
   147         count++;
       
   148         myView.NextL();
       
   149     }
       
   150     
       
   151     CleanupStack::PopAndDestroy( &myView ); // myView
       
   152          
       
   153     //Close the database
       
   154     iItemsDatabase.Close();
       
   155 
       
   156     return count;
       
   157 }
   111 
   158 
   112 // -----------------------------------------------------------------------------
   159 // -----------------------------------------------------------------------------
   113 // CLookupMapTileDatabase::FindEntryL()
   160 // CLookupMapTileDatabase::FindEntryL()
   114 // Finds an entry in the lookup table.
   161 // Finds an entry in the lookup table.
   115 // -----------------------------------------------------------------------------
   162 // -----------------------------------------------------------------------------
   157             // Item found. get the details.
   204             // Item found. get the details.
   158             myView.GetL();      
   205             myView.GetL();      
   159             if( aLookupItem.iUid == myView.ColUint( KColumnUid ) )
   206             if( aLookupItem.iUid == myView.ColUint( KColumnUid ) )
   160             {               
   207             {               
   161                 aLookupItem.iFilePath.Copy( myView.ColDes16( KColumnFilePath ) );
   208                 aLookupItem.iFilePath.Copy( myView.ColDes16( KColumnFilePath ) );
       
   209                 aLookupItem.iFetchingStatus = myView.ColUint( KColumnMapTileFetchingStatus );
   162                 entryAvailable = ETrue;
   210                 entryAvailable = ETrue;
   163             }      
   211             }      
   164         } 
   212         } 
   165     
   213     
   166         CleanupStack::PopAndDestroy( &myView ); // myView
   214         CleanupStack::PopAndDestroy( &myView ); // myView