locationdataharvester/locationdatalookupdb/locationdatalookupdb.cpp
changeset 41 b3dd5ec3089d
parent 35 59575560d1e6
equal deleted inserted replaced
38:793f76d9ab0c 41:b3dd5ec3089d
    20 #include <QSqlDatabase>
    20 #include <QSqlDatabase>
    21 #include <QSqlError>
    21 #include <QSqlError>
    22 #include <QSqlQuery>
    22 #include <QSqlQuery>
    23 #include <QSqlRecord>
    23 #include <QSqlRecord>
    24 #include <QVariant>
    24 #include <QVariant>
    25 #include<locationservicedefines.h>
    25 #include <locationservicedefines.h>
    26 
    26 #include <mylocationsdefines.h>
    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 
    27 
    34 
    28 
    35 // ================= MEMBER FUNCTIONS =======================
    29 // ================= MEMBER FUNCTIONS =======================
    36 //
    30 //
    37 // ---------------------------------------------------------
    31 // ---------------------------------------------------------
    72                                              "icontype int,"
    66                                              "icontype int,"
    73                                              "iconpath varchar(255),"
    67                                              "iconpath varchar(255),"
    74                                              "maptile varchar(255))");
    68                                              "maptile varchar(255))");
    75     
    69     
    76     
    70     
    77     query.exec("create table if not exists lplookupaddress ("
    71     query.exec("create table if not exists calendarlocation ("
    78                                              "sourceid int,"
    72                                              "sourceid int,"
    79                                              "address varchar(255))");
    73                                              "address varchar(255))");
    80     mDb->close();
    74     mDb->close();
    81 }
    75 }
    82 
    76 
   171         query.bindValue(":maptile", aLookupItem.mMapTilePath);
   165         query.bindValue(":maptile", aLookupItem.mMapTilePath);
   172         query.exec();
   166         query.exec();
   173         
   167         
   174         QVariant var = query.lastInsertId();
   168         QVariant var = query.lastInsertId();
   175         aLookupItem.mId = var.toInt();
   169         aLookupItem.mId = var.toInt();
   176         
   170               
   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     }
   171     }
   193 }
   172 }
   194 
   173 
   195 // ---------------------------------------------------------
   174 // ---------------------------------------------------------
   196 // LocationDataLookupDb::updateEntryBySourceIdAndType()
   175 // LocationDataLookupDb::updateEntryBySourceIdAndType()
   238     
   217     
   239         query.addBindValue( aLookupItem.mSourceUid );
   218         query.addBindValue( aLookupItem.mSourceUid );
   240         query.addBindValue( aLookupItem.mSourceType );
   219         query.addBindValue( aLookupItem.mSourceType );
   241     
   220     
   242         query.exec();
   221         query.exec();
   243         
   222        
   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     }
   223     }
   257     
   224     
   258 }
   225 }
   259 
   226 
   260 // ---------------------------------------------------------
   227 // ---------------------------------------------------------
   323         query.addBindValue( aLookupItem.mMapTilePath );
   290         query.addBindValue( aLookupItem.mMapTilePath );
   324     
   291     
   325         query.addBindValue( aLookupItem.mId );
   292         query.addBindValue( aLookupItem.mId );
   326     
   293     
   327         query.exec();
   294         query.exec();
   328         
   295       
   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     }
   296     }
   340 }
   297 }
   341 
   298 
   342 
   299 
   343 // ---------------------------------------------------------
   300 // ---------------------------------------------------------
   374     
   331     
   375         query.addBindValue( aLookupItem.mSourceUid );
   332         query.addBindValue( aLookupItem.mSourceUid );
   376         query.addBindValue( aLookupItem.mSourceType );
   333         query.addBindValue( aLookupItem.mSourceType );
   377     
   334     
   378         query.exec();
   335         query.exec();
   379         
   336                 
   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     }
   337     }
   389 }
   338 }
   390 
   339 
   391 // ---------------------------------------------------------
   340 // ---------------------------------------------------------
   392 // LocationDataLookupDb::findEntryBySourceIdAndType()
   341 // LocationDataLookupDb::findEntryBySourceIdAndType()
   601             }
   550             }
   602 
   551 
   603         }
   552         }
   604         else if (aSourceType == ESourceCalendar)
   553         else if (aSourceType == ESourceCalendar)
   605         {
   554         {
   606             query.prepare("SELECT * FROM lplookupaddress "
   555             query.prepare("SELECT * FROM calendarlocation "
   607                 "WHERE sourceid = ? ");
   556                 "WHERE sourceid = ? ");
   608             query.addBindValue( aId );
   557             query.addBindValue( aId );
   609             query.exec();
   558             query.exec();
   610             if ( query.first() )
   559             if ( query.first() )
   611             {
   560             {
   690          
   639          
   691     
   640     
   692     }
   641     }
   693 }
   642 }
   694 
   643 
       
   644 // ---------------------------------------------------------
       
   645 // LocationDataLookupDb::updateCalendarLocationById()
       
   646 // ---------------------------------------------------------
       
   647 void LocationDataLookupDb::updateCalendarLocationById(quint32 id , QString location)
       
   648 {
       
   649     QSqlQuery query(*mDb);
       
   650     query.prepare("SELECT * FROM calendarlocation "
       
   651         "WHERE sourceid = ? ");
       
   652     query.addBindValue(id);
       
   653     query.exec();
       
   654     if (query.first()) {
       
   655 
       
   656         query.prepare("UPDATE calendarlocation SET "
       
   657             "address = ? "
       
   658             "WHERE sourceid = ?");
       
   659         query.addBindValue( location );
       
   660         query.addBindValue( id); 
       
   661 
       
   662     }
       
   663     else {
       
   664         query.prepare("INSERT INTO calendarlocation ("
       
   665             "sourceid ,"
       
   666             "address )"
       
   667             "VALUES ("
       
   668             ":sourceid, "
       
   669             ":address) ");
       
   670         query.bindValue(":sourceid", id);
       
   671         query.bindValue(":address", location);       
       
   672        
       
   673     }
       
   674     query.exec();
       
   675 
       
   676 }
       
   677 
       
   678 // ---------------------------------------------------------
       
   679 // LocationDataLookupDb::deleteCalendarEntry()
       
   680 // ---------------------------------------------------------
       
   681 void LocationDataLookupDb::deleteCalendarEntry(quint32 id)
       
   682 {
       
   683     QSqlQuery query(*mDb);
       
   684     query.prepare( "DELETE FROM calendarlocation "
       
   685                                       "WHERE sourceid = ? " );                
       
   686     query.addBindValue( id );
       
   687     query.exec();
       
   688 
       
   689 }
       
   690 // ---------------------------------------------------------
       
   691 // LocationDataLookupDb::getAllCalendarEntry()
       
   692 // ---------------------------------------------------------
       
   693 void LocationDataLookupDb::getAllCalendarEntry(QList<QCalendarLocationDetails>& lookupItemArray)
       
   694 {
       
   695     
       
   696     QSqlQuery query(*mDb);
       
   697     query.prepare( "SELECT * FROM calendarlocation ");    
       
   698     query.exec();
       
   699     while( query.next() ) {  
       
   700     QCalendarLocationDetails calendarEntry;
       
   701     QSqlRecord rec = query.record();
       
   702     calendarEntry.mSourceUid = query.value( rec.indexOf("sourceid") ).toUInt();
       
   703     calendarEntry.mOnelineLocation = query.value( rec.indexOf("address") ).toString();
       
   704     lookupItemArray.append(calendarEntry);
       
   705     }
       
   706     
       
   707 }
   695 // End of file
   708 // End of file