summaryrefslogtreecommitdiff
authorzecke <zecke>2004-09-12 23:48:59 (UTC)
committer zecke <zecke>2004-09-12 23:48:59 (UTC)
commitdf292cd5dbd8f3c11efa06db1a2ed565a6efa9b8 (patch) (unidiff)
tree749fce3927b9dad57bb4e836771860a8607963ba
parent03d8f31d45fa569d944ff635428ad9a946f077b9 (diff)
downloadopie-df292cd5dbd8f3c11efa06db1a2ed565a6efa9b8.zip
opie-df292cd5dbd8f3c11efa06db1a2ed565a6efa9b8.tar.gz
opie-df292cd5dbd8f3c11efa06db1a2ed565a6efa9b8.tar.bz2
-Sorry for the whitespaces
-Delete endDate which is used by queryByExample Eilers can you look if a QDate::isValid makes more sense?
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index 221e977..3d284f7 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -296,40 +296,40 @@ namespace {
296 } 296 }
297 FindQuery::FindQuery(const QArray<int>& ints) 297 FindQuery::FindQuery(const QArray<int>& ints)
298 : OSQLQuery(), m_uids( ints ){ 298 : OSQLQuery(), m_uids( ints ){
299 } 299 }
300 FindQuery::~FindQuery() { 300 FindQuery::~FindQuery() {
301 } 301 }
302 QString FindQuery::query()const{ 302 QString FindQuery::query()const{
303 if ( m_uids.count() == 0 ) 303 if ( m_uids.count() == 0 )
304 return single(); 304 return single();
305 else 305 else
306 return multi(); 306 return multi();
307 } 307 }
308 308
309 QString FindQuery::multi()const { 309 QString FindQuery::multi()const {
310 QString qu = "select * from addressbook where"; 310 QString qu = "select * from addressbook where";
311 for (uint i = 0; i < m_uids.count(); i++ ) { 311 for (uint i = 0; i < m_uids.count(); i++ ) {
312 qu += " uid = " + QString::number( m_uids[i] ) + " OR"; 312 qu += " uid = " + QString::number( m_uids[i] ) + " OR";
313 } 313 }
314 qu.remove( qu.length()-2, 2 ); // Hmmmm.. 314 qu.remove( qu.length()-2, 2 ); // Hmmmm..
315 315
316 odebug << "find query: " << qu << "" << oendl; 316 odebug << "find query: " << qu << "" << oendl;
317 return qu; 317 return qu;
318 } 318 }
319 319
320 QString FindQuery::single()const{ 320 QString FindQuery::single()const{
321 QString qu = "select *"; 321 QString qu = "select *";
322 qu += " from addressbook where uid = " + QString::number(m_uid); 322 qu += " from addressbook where uid = " + QString::number(m_uid);
323 323
324 // owarn << "find query: " << qu << "" << oendl; 324 // owarn << "find query: " << qu << "" << oendl;
325 return qu; 325 return qu;
326 } 326 }
327 327
328 328
329 FindCustomQuery::FindCustomQuery(int uid) 329 FindCustomQuery::FindCustomQuery(int uid)
330 : OSQLQuery(), m_uid( uid ) { 330 : OSQLQuery(), m_uid( uid ) {
331 } 331 }
332 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 332 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
333 : OSQLQuery(), m_uids( ints ){ 333 : OSQLQuery(), m_uids( ints ){
334 } 334 }
335 FindCustomQuery::~FindCustomQuery() { 335 FindCustomQuery::~FindCustomQuery() {
@@ -483,28 +483,28 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
483 483
484 odebug << "OPimContactAccessBackend_SQL::find() needed: " << t.elapsed() << " ms" << oendl; 484 odebug << "OPimContactAccessBackend_SQL::find() needed: " << t.elapsed() << " ms" << oendl;
485 return retContact; 485 return retContact;
486} 486}
487 487
488OPimContact OPimContactAccessBackend_SQL::find( int uid, const QArray<int>& queryUids, uint current, Frontend::CacheDirection direction ) const 488OPimContact OPimContactAccessBackend_SQL::find( int uid, const QArray<int>& queryUids, uint current, Frontend::CacheDirection direction ) const
489{ 489{
490 odebug << "OPimContactAccessBackend_SQL::find( ..multi.. )" << oendl; 490 odebug << "OPimContactAccessBackend_SQL::find( ..multi.. )" << oendl;
491 odebug << "searching for " << uid << "" << oendl; 491 odebug << "searching for " << uid << "" << oendl;
492 492
493 QTime t; 493 QTime t;
494 t.start(); 494 t.start();
495 495
496 uint numReadAhead = readAhead(); 496 uint numReadAhead = readAhead();
497 QArray<int> searchList( numReadAhead ); 497 QArray<int> searchList( numReadAhead );
498 498
499 uint size =0; 499 uint size =0;
500 500
501 // Build an array with all elements which should be requested and cached 501 // Build an array with all elements which should be requested and cached
502 // We will just request "numReadAhead" elements, starting from "current" position in 502 // We will just request "numReadAhead" elements, starting from "current" position in
503 // the list of many uids ! 503 // the list of many uids !
504 switch( direction ) { 504 switch( direction ) {
505 /* forward */ 505 /* forward */
506 case Frontend::Forward: 506 case Frontend::Forward:
507 for ( uint i = current; i < queryUids.count() && size < numReadAhead; i++ ) { 507 for ( uint i = current; i < queryUids.count() && size < numReadAhead; i++ ) {
508 searchList[size] = queryUids[i]; 508 searchList[size] = queryUids[i];
509 size++; 509 size++;
510 } 510 }
@@ -615,24 +615,26 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
615 // Switching between case sensitive and insensitive... 615 // Switching between case sensitive and insensitive...
616 // LIKE is not case sensitive, GLOB is case sensitive 616 // LIKE is not case sensitive, GLOB is case sensitive
617 // Do exist a better solution to switch this ? 617 // Do exist a better solution to switch this ?
618 if ( settings & OPimContactAccess::IgnoreCase ) 618 if ( settings & OPimContactAccess::IgnoreCase )
619 searchQuery += "(\"" + *it + "\"" + " LIKE " + "'" 619 searchQuery += "(\"" + *it + "\"" + " LIKE " + "'"
620 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; 620 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")";
621 else 621 else
622 searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" 622 searchQuery += "(\"" + *it + "\"" + " GLOB " + "'"
623 + queryStr + "'" + ")"; 623 + queryStr + "'" + ")";
624 624
625 } 625 }
626 } 626 }
627
628 delete endDate;
627 } 629 }
628 // Skip trailing "AND" 630 // Skip trailing "AND"
629// if ( isAnyFieldSelected ) 631// if ( isAnyFieldSelected )
630// qu = qu.left( qu.length() - 4 ); 632// qu = qu.left( qu.length() - 4 );
631 633
632 qu += searchQuery; 634 qu += searchQuery;
633 635
634 odebug << "queryByExample query: " << qu << "" << oendl; 636 odebug << "queryByExample query: " << qu << "" << oendl;
635 637
636 // Execute query and return the received uid's 638 // Execute query and return the received uid's
637 OSQLRawQuery raw( qu ); 639 OSQLRawQuery raw( qu );
638 OSQLResult res = m_driver->query( &raw ); 640 OSQLResult res = m_driver->query( &raw );
@@ -816,40 +818,40 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
816 t2.start(); 818 t2.start();
817 FindQuery query( uid ); 819 FindQuery query( uid );
818 OSQLResult res_noncustom = m_driver->query( &query ); 820 OSQLResult res_noncustom = m_driver->query( &query );
819 t2needed = t2.elapsed(); 821 t2needed = t2.elapsed();
820 822
821 OSQLResultItem resItem = res_noncustom.first(); 823 OSQLResultItem resItem = res_noncustom.first();
822 824
823 QMap<int, QString> nonCustomMap; 825 QMap<int, QString> nonCustomMap;
824 QTime t3; 826 QTime t3;
825 t3.start(); 827 t3.start();
826 nonCustomMap = fillNonCustomMap( resItem ); 828 nonCustomMap = fillNonCustomMap( resItem );
827 t3needed = t3.elapsed(); 829 t3needed = t3.elapsed();
828 830
829 831
830 // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; 832 // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl;
831 odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed 833 odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed
832 << " ms, mapping: " << t3needed << " ms" << oendl; 834 << " ms, mapping: " << t3needed << " ms" << oendl;
833 835
834 return nonCustomMap; 836 return nonCustomMap;
835} 837}
836 838
837/* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */ 839/* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */
838OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const QArray<int>& uidlist )const 840OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const QArray<int>& uidlist )const
839{ 841{
840 // We want to get all contacts with one query. 842 // We want to get all contacts with one query.
841 // We don't have to add the given uid to the uidlist, it is expected to be there already (see opimrecordlist.h). 843 // We don't have to add the given uid to the uidlist, it is expected to be there already (see opimrecordlist.h).
842 // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned 844 // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned
843 // by using the cache.. 845 // by using the cache..
844 QArray<int> cachelist = uidlist; 846 QArray<int> cachelist = uidlist;
845 OPimContact retContact; 847 OPimContact retContact;
846 848
847 odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl; 849 odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl;
848 850
849 QTime t; 851 QTime t;
850 t.start(); 852 t.start();
851 853
852 int t2needed = 0; 854 int t2needed = 0;
853 int t3needed = 0; 855 int t3needed = 0;
854 QTime t2; 856 QTime t2;
855 t2.start(); 857 t2.start();
@@ -862,30 +864,30 @@ OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, cons
862 t3.start(); 864 t3.start();
863 OSQLResultItem resItem = res_noncustom.first(); 865 OSQLResultItem resItem = res_noncustom.first();
864 do { 866 do {
865 OPimContact contact( fillNonCustomMap( resItem ) ); 867 OPimContact contact( fillNonCustomMap( resItem ) );
866 contact.setExtraMap( requestCustom( contact.uid() ) ); 868 contact.setExtraMap( requestCustom( contact.uid() ) );
867 odebug << "Caching uid: " << contact.uid() << oendl; 869 odebug << "Caching uid: " << contact.uid() << oendl;
868 cache( contact ); 870 cache( contact );
869 if ( contact.uid() == uid ) 871 if ( contact.uid() == uid )
870 retContact = contact; 872 retContact = contact;
871 resItem = res_noncustom.next(); 873 resItem = res_noncustom.next();
872 } while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !! 874 } while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !!
873 t3needed = t3.elapsed(); 875 t3needed = t3.elapsed();
874 876
875 877
876 // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; 878 // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl;
877 odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed 879 odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed
878 << " ms, mapping: " << t3needed << " ms" << oendl; 880 << " ms, mapping: " << t3needed << " ms" << oendl;
879 881
880 return retContact; 882 return retContact;
881} 883}
882 884
883QMap<int, QString> OPimContactAccessBackend_SQL::fillNonCustomMap( const OSQLResultItem& resultItem ) const 885QMap<int, QString> OPimContactAccessBackend_SQL::fillNonCustomMap( const OSQLResultItem& resultItem ) const
884{ 886{
885 QMap<int, QString> nonCustomMap; 887 QMap<int, QString> nonCustomMap;
886 888
887 // Now loop through all columns 889 // Now loop through all columns
888 QStringList fieldList = OPimContactFields::untrfields( false ); 890 QStringList fieldList = OPimContactFields::untrfields( false );
889 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 891 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
890 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 892 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
891 // Get data for the selected column and store it with the 893 // Get data for the selected column and store it with the