locationdataharvester/locationdatalookupdb/locationdatalookupdb.cpp
branchRCL_3
changeset 17 1fc85118c3ae
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
       
     1 /*
       
     2 * Copyright (c) 2010 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: Location data lookup db implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "locationdatalookupdb.h"
       
    20 #include <QSqlDatabase>
       
    21 #include <QSqlError>
       
    22 #include <QSqlQuery>
       
    23 #include <QSqlRecord>
       
    24 #include <QVariant>
       
    25 #include<locationservicedefines.h>
       
    26 
       
    27 // database name
       
    28 #ifdef LOCPICKER_UNIT_TEST
       
    29 const QString KLocationDataLookupDbName = "c:\\locationdatalookuptestdb.db"; 
       
    30 #else    
       
    31 const QString KLocationDataLookupDbName = "c:\\locationdatalookupdb.db"; 
       
    32 #endif
       
    33 
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 //
       
    37 // ---------------------------------------------------------
       
    38 // LocationDataLookupDb::LocationDataLookupDb()
       
    39 // Constructor
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 LocationDataLookupDb::LocationDataLookupDb( QObject *parent) : 
       
    43         QObject( parent ),
       
    44         mDb( NULL ),
       
    45         mDbOpen( false )
       
    46 {
       
    47     mDb = new QSqlDatabase();
       
    48     *mDb = QSqlDatabase::addDatabase( "QSQLITE" );
       
    49     mDb->setDatabaseName( KLocationDataLookupDbName );
       
    50     if (!mDb->open())
       
    51     {
       
    52         delete mDb;
       
    53         mDb = NULL;
       
    54         return;
       
    55     }
       
    56 
       
    57     // create lookup table if doesnot exist
       
    58     QSqlQuery query(*mDb);
       
    59     query.exec("create table if not exists lplookup (id INTEGER PRIMARY KEY AUTOINCREMENT,"
       
    60                                              "duplicate int,"
       
    61                                              "sourceid int,"
       
    62                                              "sourcetype int,"
       
    63                                              "destid int,"
       
    64                                              "name varchar(255),"
       
    65                                              "street varchar(255),"
       
    66                                              "postal varchar(50),"
       
    67                                              "city varchar(50),"
       
    68                                              "state varchar(50),"
       
    69                                              "country varchar(50),"
       
    70                                              "latitude double,"
       
    71                                              "longitude double,"
       
    72                                              "icontype int,"
       
    73                                              "iconpath varchar(255),"
       
    74                                              "maptile varchar(255))");
       
    75     
       
    76     
       
    77     query.exec("create table if not exists lplookupaddress ("
       
    78                                              "sourceid int,"
       
    79                                              "address varchar(255))");
       
    80     mDb->close();
       
    81 }
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // LocationDataLookupDb::~LocationDataLookupDb()
       
    85 // destructor
       
    86 // ---------------------------------------------------------
       
    87 LocationDataLookupDb::~LocationDataLookupDb()
       
    88 {
       
    89     if( mDb )
       
    90         delete mDb;
       
    91 }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // LocationDataLookupDb::open()
       
    95 // ---------------------------------------------------------
       
    96 bool LocationDataLookupDb::open()
       
    97 {
       
    98     if( !mDbOpen )
       
    99     {
       
   100         mDbOpen = mDb->open();
       
   101     }
       
   102     return mDbOpen;
       
   103 }
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // LocationDataLookupDb::close()
       
   107 // ---------------------------------------------------------
       
   108 void LocationDataLookupDb::close()
       
   109 {
       
   110     if( mDbOpen )
       
   111         mDb->close();
       
   112     mDbOpen = false;
       
   113 }
       
   114 
       
   115 // ---------------------------------------------------------
       
   116 // LocationDataLookupDb::createEntry()
       
   117 // ---------------------------------------------------------
       
   118 void LocationDataLookupDb::createEntry( QLookupItem& aLookupItem )
       
   119 {
       
   120     if( mDbOpen )
       
   121     {
       
   122         QSqlQuery query(*mDb);
       
   123         query.prepare("INSERT INTO lplookup ("
       
   124                               "id, "
       
   125                               "duplicate, "
       
   126                               "sourceid, "
       
   127                               "sourcetype, "
       
   128                               "destid, "
       
   129                               "name, "
       
   130                               "street, "
       
   131                               "postal, "
       
   132                               "city, "
       
   133                               "state, "
       
   134                               "country, "
       
   135                               "latitude, "
       
   136                               "longitude, "
       
   137                               "icontype, "
       
   138                               "iconpath, "
       
   139                               "maptile) "
       
   140                       "VALUES ("
       
   141                               "NULL, "
       
   142                               ":duplicate, "
       
   143                               ":sourceid, "
       
   144                               ":sourcetype, "
       
   145                               ":destid, "
       
   146                               ":name, "
       
   147                               ":street, "
       
   148                               ":postal, "
       
   149                               ":city, "
       
   150                               ":state, "
       
   151                               ":country, "
       
   152                               ":latitude, "
       
   153                               ":longitude, "
       
   154                               ":icontype, "
       
   155                               ":iconpath, "
       
   156                               ":maptile)" );
       
   157         query.bindValue(":duplicate", aLookupItem.mIsDuplicate);
       
   158         query.bindValue(":sourceid", aLookupItem.mSourceUid);
       
   159         query.bindValue(":sourcetype", aLookupItem.mSourceType);
       
   160         query.bindValue(":destid", aLookupItem.mDestId);
       
   161         query.bindValue(":name", aLookupItem.mName);
       
   162         query.bindValue(":street", aLookupItem.mStreet);
       
   163         query.bindValue(":postal", aLookupItem.mPostalCode);
       
   164         query.bindValue(":city", aLookupItem.mCity);
       
   165         query.bindValue(":state", aLookupItem.mState);
       
   166         query.bindValue(":country", aLookupItem.mCountry);
       
   167         query.bindValue(":latitude", aLookupItem.mLatitude);
       
   168         query.bindValue(":longitude", aLookupItem.mLongitude);
       
   169         query.bindValue(":icontype", aLookupItem.mIconType);
       
   170         query.bindValue(":iconpath", aLookupItem.mIconPath);
       
   171         query.bindValue(":maptile", aLookupItem.mMapTilePath);
       
   172         query.exec();
       
   173         
       
   174         QVariant var = query.lastInsertId();
       
   175         aLookupItem.mId = var.toInt();
       
   176         
       
   177         if(aLookupItem.mSourceType==ESourceCalendar)
       
   178         {
       
   179             query.prepare("INSERT INTO lplookupaddress ("
       
   180                     "sourceid ,"
       
   181                     "address )"
       
   182                     "VALUES ("
       
   183                     ":sourceid, "
       
   184                     ":address) " );
       
   185             
       
   186             query.bindValue(":sourceid", aLookupItem.mSourceUid);
       
   187             query.bindValue(":address", aLookupItem.mSingleLineAddress);
       
   188             query.exec();       
       
   189                     
       
   190         }
       
   191         
       
   192     }
       
   193 }
       
   194 
       
   195 // ---------------------------------------------------------
       
   196 // LocationDataLookupDb::updateEntryBySourceIdAndType()
       
   197 // ---------------------------------------------------------
       
   198 void LocationDataLookupDb::updateEntryBySourceIdAndType( const QLookupItem& aLookupItem )
       
   199 {
       
   200     if( mDbOpen )
       
   201     {
       
   202         QSqlQuery query(*mDb);
       
   203         query.prepare("UPDATE lplookup SET "
       
   204                         "id = ?, "
       
   205                         "duplicate = ?, "
       
   206                         "sourceid = ?, "
       
   207                         "sourcetype = ?, "
       
   208                         "destid = ?, "
       
   209                         "name = ?, "
       
   210                         "street = ?, "
       
   211                         "postal = ?, "
       
   212                         "city = ?, "
       
   213                         "state = ?, "
       
   214                         "country = ?, "
       
   215                         "latitude = ?, "
       
   216                         "longitude = ?, "
       
   217                         "icontype = ?, "
       
   218                         "iconpath = ?, "
       
   219                         "maptile = ? "
       
   220                       "WHERE sourceid = ? AND sourcetype = ?");
       
   221     
       
   222         query.addBindValue( aLookupItem.mId );
       
   223         query.addBindValue( aLookupItem.mIsDuplicate );
       
   224         query.addBindValue( aLookupItem.mSourceUid );
       
   225         query.addBindValue( aLookupItem.mSourceType );
       
   226         query.addBindValue( aLookupItem.mDestId );
       
   227         query.addBindValue( aLookupItem.mName );
       
   228         query.addBindValue( aLookupItem.mStreet );
       
   229         query.addBindValue( aLookupItem.mPostalCode );
       
   230         query.addBindValue( aLookupItem.mCity );
       
   231         query.addBindValue( aLookupItem.mState );
       
   232         query.addBindValue( aLookupItem.mCountry );
       
   233         query.addBindValue( aLookupItem.mLatitude );
       
   234         query.addBindValue( aLookupItem.mLongitude );
       
   235         query.addBindValue( aLookupItem.mIconType );
       
   236         query.addBindValue( aLookupItem.mIconPath );
       
   237         query.addBindValue( aLookupItem.mMapTilePath );
       
   238     
       
   239         query.addBindValue( aLookupItem.mSourceUid );
       
   240         query.addBindValue( aLookupItem.mSourceType );
       
   241     
       
   242         query.exec();
       
   243         
       
   244         if(aLookupItem.mSourceType==ESourceCalendar)
       
   245         {
       
   246             query.prepare("UPDATE lplookupaddress SET "
       
   247                         "address = ? "
       
   248                         "WHERE sourceid = ? ");
       
   249             
       
   250            
       
   251             query.addBindValue( aLookupItem.mSingleLineAddress);
       
   252             query.addBindValue( aLookupItem.mSourceUid);
       
   253             query.exec();       
       
   254                     
       
   255         }
       
   256     }
       
   257     
       
   258 }
       
   259 
       
   260 // ---------------------------------------------------------
       
   261 // LocationDataLookupDb::updateMaptileBySourceIdAndType()
       
   262 // ---------------------------------------------------------
       
   263 void LocationDataLookupDb::updateMaptileBySourceIdAndType( quint32 aSourceId, 
       
   264         quint32 aSourceType, QString aImagePath )
       
   265 {
       
   266     if( mDbOpen )
       
   267     {
       
   268         QSqlQuery query(*mDb);
       
   269         query.prepare("UPDATE lplookup SET "
       
   270                         "maptile = ? "
       
   271                       "WHERE sourceid = ? AND sourcetype = ?");
       
   272     
       
   273         query.addBindValue( aImagePath );
       
   274         query.addBindValue( aSourceId );
       
   275         query.addBindValue( aSourceType );
       
   276     
       
   277         query.exec();
       
   278     }
       
   279 }
       
   280 
       
   281 // ---------------------------------------------------------
       
   282 // LocationDataLookupDb::updateEntryById()
       
   283 // ---------------------------------------------------------
       
   284 void LocationDataLookupDb::updateEntryById( const QLookupItem& aLookupItem )
       
   285 {
       
   286     if( mDbOpen )
       
   287     {
       
   288         QSqlQuery query(*mDb);
       
   289         query.prepare("UPDATE lplookup SET "
       
   290                         "id = ?, "
       
   291                         "duplicate = ?, "
       
   292                         "sourceid = ?, "
       
   293                         "sourcetype = ?, "
       
   294                         "destid = ?, "
       
   295                         "name = ?, "
       
   296                         "street = ?, "
       
   297                         "postal = ?, "
       
   298                         "city = ?, "
       
   299                         "state = ?, "
       
   300                         "country = ?, "
       
   301                         "latitude = ?, "
       
   302                         "longitude = ?, "
       
   303                         "icontype = ?, "
       
   304                         "iconpath = ?, "
       
   305                         "maptile = ? "
       
   306                       "WHERE id = ?");
       
   307     
       
   308         query.addBindValue( aLookupItem.mId );
       
   309         query.addBindValue( aLookupItem.mIsDuplicate );
       
   310         query.addBindValue( aLookupItem.mSourceUid );
       
   311         query.addBindValue( aLookupItem.mSourceType );
       
   312         query.addBindValue( aLookupItem.mDestId );
       
   313         query.addBindValue( aLookupItem.mName );
       
   314         query.addBindValue( aLookupItem.mStreet );
       
   315         query.addBindValue( aLookupItem.mPostalCode );
       
   316         query.addBindValue( aLookupItem.mCity );
       
   317         query.addBindValue( aLookupItem.mState );
       
   318         query.addBindValue( aLookupItem.mCountry );
       
   319         query.addBindValue( aLookupItem.mLatitude );
       
   320         query.addBindValue( aLookupItem.mLongitude );
       
   321         query.addBindValue( aLookupItem.mIconType );
       
   322         query.addBindValue( aLookupItem.mIconPath );
       
   323         query.addBindValue( aLookupItem.mMapTilePath );
       
   324     
       
   325         query.addBindValue( aLookupItem.mId );
       
   326     
       
   327         query.exec();
       
   328         
       
   329         if(aLookupItem.mSourceType==ESourceCalendar)
       
   330         {
       
   331             query.prepare("UPDATE lplookupaddress SET "
       
   332                           "address = ? " 
       
   333                         "WHERE sourceid = ?");
       
   334                      
       
   335             query.addBindValue( aLookupItem.mSingleLineAddress);
       
   336             query.addBindValue( aLookupItem.mSourceUid );
       
   337             query.exec();     
       
   338         }
       
   339     }
       
   340 }
       
   341 
       
   342 
       
   343 // ---------------------------------------------------------
       
   344 // LocationDataLookupDb::updateEntryNameById()
       
   345 // ---------------------------------------------------------
       
   346 void LocationDataLookupDb::updateEntryNameByIdAndType(quint32 aSourceId, quint32 aSourceType , QString aName)
       
   347 {
       
   348 	if( mDbOpen )
       
   349 		{
       
   350 			QSqlQuery query(*mDb);
       
   351 			query.prepare("UPDATE lplookup SET "							
       
   352 							"name = ? "							
       
   353 						    "WHERE sourceid = ? AND sourcetype = ?");
       
   354 		
       
   355 			query.addBindValue( aName );
       
   356 			
       
   357 			query.addBindValue( aSourceId );
       
   358 			query.addBindValue( aSourceType );				
       
   359 			
       
   360 			query.exec();
       
   361 		}
       
   362 }
       
   363 
       
   364 // ---------------------------------------------------------
       
   365 // LocationDataLookupDb::deleteEntryBySourceIdAndType()
       
   366 // ---------------------------------------------------------
       
   367 void LocationDataLookupDb::deleteEntryBySourceIdAndType( const QLookupItem& aLookupItem )
       
   368 {
       
   369     if( mDbOpen )
       
   370     {
       
   371         QSqlQuery query(*mDb);
       
   372         query.prepare( "DELETE FROM lplookup "
       
   373                        "WHERE sourceid = ? AND sourcetype = ?" );
       
   374     
       
   375         query.addBindValue( aLookupItem.mSourceUid );
       
   376         query.addBindValue( aLookupItem.mSourceType );
       
   377     
       
   378         query.exec();
       
   379         
       
   380         if(aLookupItem.mSourceType==ESourceCalendar)
       
   381         {
       
   382             query.prepare( "DELETE FROM lplookupaddress "
       
   383                                    "WHERE sourceid = ? " );                
       
   384             query.addBindValue( aLookupItem.mSourceUid );
       
   385             query.exec();
       
   386         }
       
   387         
       
   388     }
       
   389 }
       
   390 
       
   391 // ---------------------------------------------------------
       
   392 // LocationDataLookupDb::findEntryBySourceIdAndType()
       
   393 // ---------------------------------------------------------
       
   394 bool LocationDataLookupDb::findEntryBySourceIdAndType( QLookupItem& aLookupItem )
       
   395 {
       
   396     if( mDbOpen )
       
   397     {
       
   398         QSqlQuery query(*mDb);
       
   399         query.prepare( "SELECT * FROM lplookup "    
       
   400                     "WHERE sourceid = ? AND sourcetype = ?" );
       
   401         query.addBindValue( aLookupItem.mSourceUid );
       
   402         query.addBindValue( aLookupItem.mSourceType );
       
   403     
       
   404         query.exec();
       
   405         
       
   406         if( !query.first() )
       
   407         {
       
   408             return false;
       
   409         }
       
   410     
       
   411         fillLookupEntry( query, aLookupItem );
       
   412         return true;
       
   413     }
       
   414     return false;
       
   415 }
       
   416 
       
   417 // ---------------------------------------------------------
       
   418 // LocationDataLookupDb::findEntryById()
       
   419 // ---------------------------------------------------------
       
   420 bool LocationDataLookupDb::findEntryById( QLookupItem& aLookupItem )
       
   421 {
       
   422     if( mDbOpen )
       
   423     {
       
   424         QSqlQuery query(*mDb);
       
   425         query.prepare( "SELECT * FROM lplookup "    
       
   426                     "WHERE id = ?" );
       
   427         query.addBindValue( aLookupItem.mId );
       
   428     
       
   429         query.exec();
       
   430         
       
   431         if( !query.first() )
       
   432         {
       
   433             return false;
       
   434         }
       
   435     
       
   436         fillLookupEntry( query, aLookupItem );    
       
   437         return true;
       
   438     }
       
   439     
       
   440     return false;
       
   441 }
       
   442 
       
   443 
       
   444 // ---------------------------------------------------------
       
   445 // LocationDataLookupDb::findEntriesByLandmarkId()
       
   446 // ---------------------------------------------------------
       
   447 void LocationDataLookupDb::findEntriesByLandmarkId( const quint32 aLandmarkId, 
       
   448         QList<QLookupItem>& aLookupItemArray )
       
   449 {
       
   450     if( mDbOpen )
       
   451     {
       
   452 
       
   453         QSqlQuery query(*mDb);
       
   454         query.prepare( "SELECT * FROM lplookup "    
       
   455                        "WHERE destid = ?" );
       
   456     
       
   457         query.addBindValue( aLandmarkId );
       
   458         query.exec();
       
   459         
       
   460         while( query.next() )
       
   461         {    
       
   462             QLookupItem lookupItem;
       
   463             fillLookupEntry( query, lookupItem );        
       
   464             aLookupItemArray.append( lookupItem );
       
   465         } 
       
   466     }   
       
   467 }
       
   468 // ---------------------------------------------------------
       
   469 // LocationDataLookupDb::getEntries()
       
   470 // ---------------------------------------------------------
       
   471 void LocationDataLookupDb::getEntries( QList<QLookupItem>& aLookupItemArray, const quint32 aCollectionId )
       
   472 {
       
   473     if( mDbOpen )
       
   474     {
       
   475         QSqlQuery query(*mDb);
       
   476         if( aCollectionId == ESourceLandmarksContactsCat )
       
   477         {
       
   478             query.prepare( "SELECT * FROM lplookup " 
       
   479                     "WHERE sourcetype = ? OR sourcetype = ? OR sourcetype = ?" );
       
   480             query.addBindValue( ESourceContactsPref );
       
   481             query.addBindValue( ESourceContactsWork );
       
   482             query.addBindValue( ESourceContactsHome );
       
   483             query.exec();
       
   484         }
       
   485         else if( aCollectionId == ESourceLandmarksCalendarCat )
       
   486         {
       
   487             query.prepare( "SELECT * FROM lplookup " 
       
   488                     "WHERE sourcetype = ?" );
       
   489             query.addBindValue( ESourceCalendar );
       
   490             query.exec();
       
   491            
       
   492         }
       
   493         else if(  aCollectionId == ESourceLandmarks )
       
   494         {
       
   495             query.prepare( "SELECT * FROM lplookup " 
       
   496                     "WHERE sourcetype = ?" );
       
   497             query.addBindValue( ESourceLandmarks );
       
   498             query.exec();
       
   499            
       
   500         }
       
   501         else // all contents
       
   502         {
       
   503             query.prepare( "SELECT * FROM lplookup" );
       
   504             query.exec();
       
   505         }
       
   506         while( query.next() )
       
   507         {    
       
   508             QLookupItem lookupItem;            
       
   509             fillLookupEntry( query, lookupItem );
       
   510             aLookupItemArray.append( lookupItem );
       
   511         }    
       
   512     }
       
   513 }
       
   514 
       
   515 // ---------------------------------------------------------
       
   516 // LocationDataLookupDb::getEntfillLookupEntryries()
       
   517 // ---------------------------------------------------------
       
   518 void LocationDataLookupDb::fillLookupEntry( QSqlQuery &aQuery, QLookupItem &aLookupItem )
       
   519 {
       
   520     QSqlRecord rec = aQuery.record();
       
   521     aLookupItem.mId = aQuery.value( rec.indexOf("id") ).toUInt();
       
   522     aLookupItem.mIsDuplicate = aQuery.value( rec.indexOf("duplicate") ).toUInt();
       
   523     aLookupItem.mSourceUid = aQuery.value( rec.indexOf("sourceid") ).toUInt();
       
   524     aLookupItem.mSourceType = aQuery.value( rec.indexOf("sourcetype") ).toUInt();
       
   525     aLookupItem.mDestId = aQuery.value( rec.indexOf("destid") ).toUInt();
       
   526     aLookupItem.mName = aQuery.value( rec.indexOf("name") ).toString();
       
   527     aLookupItem.mStreet = aQuery.value( rec.indexOf("street") ).toString();
       
   528     aLookupItem.mPostalCode = aQuery.value( rec.indexOf("postal") ).toString();
       
   529     aLookupItem.mCity = aQuery.value( rec.indexOf("city") ).toString();
       
   530     aLookupItem.mState = aQuery.value( rec.indexOf("state") ).toString();
       
   531     aLookupItem.mCountry = aQuery.value( rec.indexOf("country") ).toString();
       
   532     aLookupItem.mLatitude = aQuery.value( rec.indexOf("latitude") ).toDouble();
       
   533     aLookupItem.mLongitude = aQuery.value( rec.indexOf("longitude") ).toDouble();
       
   534     aLookupItem.mIconType = aQuery.value( rec.indexOf("icontype") ).toUInt();
       
   535     aLookupItem.mIconPath = aQuery.value( rec.indexOf("iconpath") ).toString();
       
   536     aLookupItem.mMapTilePath = aQuery.value( rec.indexOf("maptile") ).toString();
       
   537 
       
   538 }
       
   539 
       
   540 // ---------------------------------------------------------
       
   541 // LocationDataLookupDb::getAddressDetails()
       
   542 // ---------------------------------------------------------
       
   543 QString LocationDataLookupDb::getAddressDetails( quint32 aId , quint32 aSourceType )
       
   544 {
       
   545     QString addressDetails;
       
   546     if (mDbOpen)
       
   547     {
       
   548         QSqlQuery query(*mDb);
       
   549         if ( aSourceType == ESourceContactsPref || aSourceType
       
   550                 == ESourceContactsWork || aSourceType == ESourceContactsHome)
       
   551         {
       
   552             query.prepare("SELECT * FROM lplookup "
       
   553                 "WHERE sourceid = ? AND sourcetype = ?");
       
   554             query.addBindValue( aId );
       
   555             query.addBindValue( aSourceType );
       
   556             query.exec();
       
   557             if (query.first()) {
       
   558                 QSqlRecord rec = query.record();
       
   559                 QString temp;
       
   560                 temp.clear();
       
   561                 temp = query.value(rec.indexOf("street")).toString();
       
   562                 if (!temp.isEmpty()) 
       
   563                 {
       
   564                     addressDetails.append(temp);
       
   565                 }
       
   566                 temp.clear();
       
   567 
       
   568                 temp = query.value(rec.indexOf("city")).toString();
       
   569                 if (!temp.isEmpty()) {
       
   570                     if (!addressDetails.isEmpty()) 
       
   571                     {
       
   572                         addressDetails.append(QChar(','));
       
   573                         addressDetails.append(QChar(' '));
       
   574                     }
       
   575                     addressDetails.append(temp);
       
   576 
       
   577                 }
       
   578                 temp.clear();
       
   579                 temp = query.value(rec.indexOf("state")).toString();
       
   580                 if (!temp.isEmpty()) {
       
   581                     if (!addressDetails.isEmpty()) 
       
   582                     {
       
   583                         addressDetails.append(QChar(','));
       
   584                         addressDetails.append(QChar(' '));
       
   585                     }
       
   586                     addressDetails.append(temp);
       
   587 
       
   588                 }
       
   589                 temp.clear();
       
   590                 temp = query.value(rec.indexOf("country")).toString();
       
   591                 if (!temp.isEmpty()) {
       
   592                     if (!addressDetails.isEmpty()) 
       
   593                     {
       
   594                         addressDetails.append(QChar(','));
       
   595                         addressDetails.append(QChar(' '));
       
   596                     }
       
   597                     addressDetails.append(temp);
       
   598 
       
   599                 }
       
   600 
       
   601             }
       
   602 
       
   603         }
       
   604         else if (aSourceType == ESourceCalendar)
       
   605         {
       
   606             query.prepare("SELECT * FROM lplookupaddress "
       
   607                 "WHERE sourceid = ? ");
       
   608             query.addBindValue( aId );
       
   609             query.exec();
       
   610             if ( query.first() )
       
   611             {
       
   612                 QSqlRecord rec = query.record();
       
   613                 addressDetails.append(
       
   614                         query.value(rec.indexOf("address")).toString());
       
   615             }
       
   616         }
       
   617     }
       
   618     return addressDetails;
       
   619 }
       
   620 
       
   621 // ---------------------------------------------------------
       
   622 // LocationDataLookupDb::getCount()
       
   623 // ---------------------------------------------------------
       
   624 void LocationDataLookupDb::getCount( QList<int>& aCount, const quint32 /*aCollectionId*/ )
       
   625 {
       
   626     if( mDb )
       
   627      {
       
   628          //   ESourceLandmarksContactsCat 
       
   629          {
       
   630              QSqlQuery query(*mDb);
       
   631              query.prepare( "SELECT * FROM lplookup " 
       
   632                      "WHERE sourcetype = ? OR sourcetype = ? OR sourcetype = ?" );
       
   633              query.addBindValue( ESourceContactsPref );
       
   634              query.addBindValue( ESourceContactsWork );
       
   635              query.addBindValue( ESourceContactsHome );
       
   636              query.exec();
       
   637              
       
   638              
       
   639              qDebug("size %d",query.size());         
       
   640              int count=0;
       
   641              while( query.next() )  count++;
       
   642              aCount.append(count);
       
   643          }
       
   644              
       
   645 
       
   646          
       
   647       //   ESourceLandmarksCalendarCat
       
   648          {
       
   649              QSqlQuery query(*mDb);
       
   650              query.prepare( "SELECT * FROM lplookup " 
       
   651                      "WHERE sourcetype = ? AND duplicate = ?" );
       
   652              query.addBindValue( ESourceCalendar );
       
   653              query.addBindValue( 0 );
       
   654              query.exec();
       
   655              
       
   656              qDebug("size %d",query.size());             
       
   657              int count=0;
       
   658              while( query.next() )  count++;
       
   659              aCount.append(count);
       
   660          }
       
   661          
       
   662          
       
   663          
       
   664      //    ESourceLandmarks
       
   665          {
       
   666              QSqlQuery query(*mDb);
       
   667              query.prepare( "SELECT * FROM lplookup " 
       
   668                      "WHERE sourcetype = ?" );
       
   669              query.addBindValue( ESourceLandmarks );
       
   670              query.exec();
       
   671              
       
   672              qDebug("size %d",query.size());
       
   673              int count=0;
       
   674              while( query.next() )  count++;
       
   675              aCount.append(count);
       
   676          }
       
   677              
       
   678          
       
   679     //     else // all contents
       
   680          {
       
   681              QSqlQuery query(*mDb);
       
   682              query.prepare( "SELECT * FROM lplookup"
       
   683                      "WHERE duplicate = ?" );
       
   684              query.addBindValue( 0 );
       
   685              query.exec();
       
   686              int count=0;
       
   687              while( query.next() )  count++;
       
   688              aCount.append(count);
       
   689          }
       
   690          
       
   691     
       
   692     }
       
   693 }
       
   694 
       
   695 // End of file