Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 144 |
1 files changed, 120 insertions, 24 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 3d284f7..9375f43 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -118,47 +118,47 @@ namespace { | |||
118 | ~RemoveQuery(); | 118 | ~RemoveQuery(); |
119 | QString query()const; | 119 | QString query()const; |
120 | private: | 120 | private: |
121 | int m_uid; | 121 | int m_uid; |
122 | }; | 122 | }; |
123 | 123 | ||
124 | /** | 124 | /** |
125 | * a find query for noncustom elements | 125 | * a find query for noncustom elements |
126 | */ | 126 | */ |
127 | class FindQuery : public OSQLQuery { | 127 | class FindQuery : public OSQLQuery { |
128 | public: | 128 | public: |
129 | FindQuery(int uid); | 129 | FindQuery(int uid); |
130 | FindQuery(const QArray<int>& ); | 130 | FindQuery(const UIDArray& ); |
131 | ~FindQuery(); | 131 | ~FindQuery(); |
132 | QString query()const; | 132 | QString query()const; |
133 | private: | 133 | private: |
134 | QString single()const; | 134 | QString single()const; |
135 | QString multi()const; | 135 | QString multi()const; |
136 | QArray<int> m_uids; | 136 | UIDArray m_uids; |
137 | int m_uid; | 137 | int m_uid; |
138 | }; | 138 | }; |
139 | 139 | ||
140 | /** | 140 | /** |
141 | * a find query for custom elements | 141 | * a find query for custom elements |
142 | */ | 142 | */ |
143 | class FindCustomQuery : public OSQLQuery { | 143 | class FindCustomQuery : public OSQLQuery { |
144 | public: | 144 | public: |
145 | FindCustomQuery(int uid); | 145 | FindCustomQuery(int uid); |
146 | FindCustomQuery(const QArray<int>& ); | 146 | FindCustomQuery(const UIDArray& ); |
147 | ~FindCustomQuery(); | 147 | ~FindCustomQuery(); |
148 | QString query()const; | 148 | QString query()const; |
149 | private: | 149 | private: |
150 | QString single()const; | 150 | QString single()const; |
151 | QString multi()const; | 151 | QString multi()const; |
152 | QArray<int> m_uids; | 152 | UIDArray m_uids; |
153 | int m_uid; | 153 | int m_uid; |
154 | }; | 154 | }; |
155 | 155 | ||
156 | 156 | ||
157 | 157 | ||
158 | // We using two tables to store the information: | 158 | // We using two tables to store the information: |
159 | // 1. addressbook : It contains General information about the contact (non custom) | 159 | // 1. addressbook : It contains General information about the contact (non custom) |
160 | // 2. custom_data : Not official supported entries | 160 | // 2. custom_data : Not official supported entries |
161 | // All tables are connected by the uid of the contact. | 161 | // All tables are connected by the uid of the contact. |
162 | // Maybe I should add a table for meta-information ? | 162 | // Maybe I should add a table for meta-information ? |
163 | CreateQuery::CreateQuery() : OSQLQuery() {} | 163 | CreateQuery::CreateQuery() : OSQLQuery() {} |
164 | CreateQuery::~CreateQuery() {} | 164 | CreateQuery::~CreateQuery() {} |
@@ -285,25 +285,25 @@ namespace { | |||
285 | + QString::number(m_uid) + ";"; | 285 | + QString::number(m_uid) + ";"; |
286 | qu += "DELETE from custom_data where uid = " | 286 | qu += "DELETE from custom_data where uid = " |
287 | + QString::number(m_uid) + ";"; | 287 | + QString::number(m_uid) + ";"; |
288 | return qu; | 288 | return qu; |
289 | } | 289 | } |
290 | 290 | ||
291 | 291 | ||
292 | 292 | ||
293 | 293 | ||
294 | FindQuery::FindQuery(int uid) | 294 | FindQuery::FindQuery(int uid) |
295 | : OSQLQuery(), m_uid( uid ) { | 295 | : OSQLQuery(), m_uid( uid ) { |
296 | } | 296 | } |
297 | FindQuery::FindQuery(const QArray<int>& ints) | 297 | FindQuery::FindQuery(const UIDArray& 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 { |
@@ -320,25 +320,25 @@ namespace { | |||
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 UIDArray& ints) |
333 | : OSQLQuery(), m_uids( ints ){ | 333 | : OSQLQuery(), m_uids( ints ){ |
334 | } | 334 | } |
335 | FindCustomQuery::~FindCustomQuery() { | 335 | FindCustomQuery::~FindCustomQuery() { |
336 | } | 336 | } |
337 | QString FindCustomQuery::query()const{ | 337 | QString FindCustomQuery::query()const{ |
338 | // if ( m_uids.count() == 0 ) | 338 | // if ( m_uids.count() == 0 ) |
339 | return single(); | 339 | return single(); |
340 | } | 340 | } |
341 | QString FindCustomQuery::single()const{ | 341 | QString FindCustomQuery::single()const{ |
342 | QString qu = "select uid, type, value from custom_data where uid = "; | 342 | QString qu = "select uid, type, value from custom_data where uid = "; |
343 | qu += QString::number(m_uid); | 343 | qu += QString::number(m_uid); |
344 | return qu; | 344 | return qu; |
@@ -413,25 +413,25 @@ void OPimContactAccessBackend_SQL::clear () | |||
413 | { | 413 | { |
414 | ClearQuery cle; | 414 | ClearQuery cle; |
415 | OSQLResult res = m_driver->query( &cle ); | 415 | OSQLResult res = m_driver->query( &cle ); |
416 | 416 | ||
417 | reload(); | 417 | reload(); |
418 | } | 418 | } |
419 | 419 | ||
420 | bool OPimContactAccessBackend_SQL::wasChangedExternally() | 420 | bool OPimContactAccessBackend_SQL::wasChangedExternally() |
421 | { | 421 | { |
422 | return false; | 422 | return false; |
423 | } | 423 | } |
424 | 424 | ||
425 | QArray<int> OPimContactAccessBackend_SQL::allRecords() const | 425 | UIDArray OPimContactAccessBackend_SQL::allRecords() const |
426 | { | 426 | { |
427 | 427 | ||
428 | // FIXME: Think about cute handling of changed tables.. | 428 | // FIXME: Think about cute handling of changed tables.. |
429 | // Thus, we don't have to call update here... | 429 | // Thus, we don't have to call update here... |
430 | if ( m_changed ) | 430 | if ( m_changed ) |
431 | ((OPimContactAccessBackend_SQL*)this)->update(); | 431 | ((OPimContactAccessBackend_SQL*)this)->update(); |
432 | 432 | ||
433 | return m_uids; | 433 | return m_uids; |
434 | } | 434 | } |
435 | 435 | ||
436 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) | 436 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) |
437 | { | 437 | { |
@@ -476,25 +476,25 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const | |||
476 | { | 476 | { |
477 | odebug << "OPimContactAccessBackend_SQL::find(" << uid << ")" << oendl; | 477 | odebug << "OPimContactAccessBackend_SQL::find(" << uid << ")" << oendl; |
478 | QTime t; | 478 | QTime t; |
479 | t.start(); | 479 | t.start(); |
480 | 480 | ||
481 | OPimContact retContact( requestNonCustom( uid ) ); | 481 | OPimContact retContact( requestNonCustom( uid ) ); |
482 | retContact.setExtraMap( requestCustom( uid ) ); | 482 | retContact.setExtraMap( requestCustom( uid ) ); |
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 | ||
488 | OPimContact OPimContactAccessBackend_SQL::find( int uid, const QArray<int>& queryUids, uint current, Frontend::CacheDirection direction ) const | 488 | OPimContact OPimContactAccessBackend_SQL::find( int uid, const UIDArray& 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 | ||
@@ -519,25 +519,26 @@ OPimContact OPimContactAccessBackend_SQL::find( int uid, const QArray<int>& quer | |||
519 | } | 519 | } |
520 | 520 | ||
521 | //Shrink to real size.. | 521 | //Shrink to real size.. |
522 | searchList.resize( size ); | 522 | searchList.resize( size ); |
523 | 523 | ||
524 | OPimContact retContact( requestContactsAndCache( uid, searchList ) ); | 524 | OPimContact retContact( requestContactsAndCache( uid, searchList ) ); |
525 | 525 | ||
526 | odebug << "OPimContactAccessBackend_SQL::find( ..multi.. ) needed: " << t.elapsed() << " ms" << oendl; | 526 | odebug << "OPimContactAccessBackend_SQL::find( ..multi.. ) needed: " << t.elapsed() << " ms" << oendl; |
527 | return retContact; | 527 | return retContact; |
528 | } | 528 | } |
529 | 529 | ||
530 | 530 | ||
531 | QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) | 531 | UIDArray OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, |
532 | const QDateTime& qd ) const | ||
532 | { | 533 | { |
533 | QString qu = "SELECT uid FROM addressbook WHERE"; | 534 | QString qu = "SELECT uid FROM addressbook WHERE"; |
534 | QString searchQuery =""; | 535 | QString searchQuery =""; |
535 | 536 | ||
536 | QDate startDate; | 537 | QDate startDate; |
537 | 538 | ||
538 | if ( qd.isValid() ) | 539 | if ( qd.isValid() ) |
539 | startDate = qd.date(); | 540 | startDate = qd.date(); |
540 | else | 541 | else |
541 | startDate = QDate::currentDate(); | 542 | startDate = QDate::currentDate(); |
542 | 543 | ||
543 | 544 | ||
@@ -630,34 +631,34 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu | |||
630 | // Skip trailing "AND" | 631 | // Skip trailing "AND" |
631 | // if ( isAnyFieldSelected ) | 632 | // if ( isAnyFieldSelected ) |
632 | // qu = qu.left( qu.length() - 4 ); | 633 | // qu = qu.left( qu.length() - 4 ); |
633 | 634 | ||
634 | qu += searchQuery; | 635 | qu += searchQuery; |
635 | 636 | ||
636 | odebug << "queryByExample query: " << qu << "" << oendl; | 637 | odebug << "queryByExample query: " << qu << "" << oendl; |
637 | 638 | ||
638 | // Execute query and return the received uid's | 639 | // Execute query and return the received uid's |
639 | OSQLRawQuery raw( qu ); | 640 | OSQLRawQuery raw( qu ); |
640 | OSQLResult res = m_driver->query( &raw ); | 641 | OSQLResult res = m_driver->query( &raw ); |
641 | if ( res.state() != OSQLResult::Success ){ | 642 | if ( res.state() != OSQLResult::Success ){ |
642 | QArray<int> empty; | 643 | UIDArray empty; |
643 | return empty; | 644 | return empty; |
644 | } | 645 | } |
645 | 646 | ||
646 | QArray<int> list = extractUids( res ); | 647 | UIDArray list = extractUids( res ); |
647 | 648 | ||
648 | return list; | 649 | return list; |
649 | } | 650 | } |
650 | 651 | ||
651 | QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 652 | UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
652 | { | 653 | { |
653 | #if 0 | 654 | #if 0 |
654 | QArray<int> nix(0); | 655 | QArray<int> nix(0); |
655 | return nix; | 656 | return nix; |
656 | 657 | ||
657 | #else | 658 | #else |
658 | QString qu = "SELECT uid FROM addressbook WHERE ("; | 659 | QString qu = "SELECT uid FROM addressbook WHERE ("; |
659 | QString searchlist; | 660 | QString searchlist; |
660 | 661 | ||
661 | QStringList fieldList = OPimContactFields::untrfields( false ); | 662 | QStringList fieldList = OPimContactFields::untrfields( false ); |
662 | // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 663 | // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
663 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 664 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
@@ -670,25 +671,25 @@ QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | |||
670 | 671 | ||
671 | odebug << "query: " << qu << "" << oendl; | 672 | odebug << "query: " << qu << "" << oendl; |
672 | 673 | ||
673 | OSQLRawQuery raw( qu ); | 674 | OSQLRawQuery raw( qu ); |
674 | OSQLResult res = m_driver->query( &raw ); | 675 | OSQLResult res = m_driver->query( &raw ); |
675 | 676 | ||
676 | return extractUids( res ); | 677 | return extractUids( res ); |
677 | 678 | ||
678 | 679 | ||
679 | #endif | 680 | #endif |
680 | } | 681 | } |
681 | 682 | ||
682 | const uint OPimContactAccessBackend_SQL::querySettings() | 683 | const uint OPimContactAccessBackend_SQL::querySettings() const |
683 | { | 684 | { |
684 | return OPimContactAccess::IgnoreCase | 685 | return OPimContactAccess::IgnoreCase |
685 | | OPimContactAccess::WildCards | 686 | | OPimContactAccess::WildCards |
686 | | OPimContactAccess::DateDiff | 687 | | OPimContactAccess::DateDiff |
687 | | OPimContactAccess::DateYear | 688 | | OPimContactAccess::DateYear |
688 | | OPimContactAccess::DateMonth | 689 | | OPimContactAccess::DateMonth |
689 | | OPimContactAccess::DateDay | 690 | | OPimContactAccess::DateDay |
690 | ; | 691 | ; |
691 | } | 692 | } |
692 | 693 | ||
693 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | 694 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const |
694 | { | 695 | { |
@@ -729,45 +730,140 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | |||
729 | case OPimContactAccess::WildCards: | 730 | case OPimContactAccess::WildCards: |
730 | return ( true ); | 731 | return ( true ); |
731 | case OPimContactAccess::ExactMatch: | 732 | case OPimContactAccess::ExactMatch: |
732 | return ( true ); | 733 | return ( true ); |
733 | case 0: // one of the upper removed bits were set.. | 734 | case 0: // one of the upper removed bits were set.. |
734 | return ( true ); | 735 | return ( true ); |
735 | default: | 736 | default: |
736 | return ( false ); | 737 | return ( false ); |
737 | } | 738 | } |
738 | 739 | ||
739 | } | 740 | } |
740 | 741 | ||
741 | QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) | 742 | UIDArray OPimContactAccessBackend_SQL::sorted( const UIDArray& ar, bool asc, int sortOrder, |
743 | int filter, const QArray<int>& categories )const | ||
742 | { | 744 | { |
743 | QTime t; | 745 | QTime t; |
744 | t.start(); | 746 | t.start(); |
745 | 747 | ||
746 | QString query = "SELECT uid FROM addressbook "; | 748 | QString query = "SELECT uid FROM addressbook"; |
747 | query += "ORDER BY \"Last Name\" "; | 749 | |
750 | query += " WHERE ("; | ||
751 | for ( uint i = 0; i < ar.count(); i++ ) { | ||
752 | query += " uid = " + QString::number( ar[i] ) + " OR"; | ||
753 | } | ||
754 | query.remove( query.length()-2, 2 ); // Hmmmm.. | ||
755 | query += ")"; | ||
756 | |||
757 | |||
758 | if ( filter != OPimBase::FilterOff ){ | ||
759 | if ( filter & OPimContactAccess::DoNotShowWithCategory ){ | ||
760 | query += " AND ( \"Categories\" == '' )"; | ||
761 | } else if ( filter & OPimBase::FilterCategory ){ | ||
762 | query += " AND ("; | ||
763 | for ( uint i = 0; i < categories.count(); i++ ){ | ||
764 | query += "\"Categories\" LIKE"; | ||
765 | query += QString( " '%" ) + QString::number( categories[i] ) + "%' OR"; | ||
766 | } | ||
767 | query.remove( query.length()-2, 2 ); // Hmmmm.. | ||
768 | query += ")"; | ||
769 | } | ||
770 | |||
771 | if ( filter & OPimContactAccess::DoNotShowWithoutChildren ){ | ||
772 | query += " AND ( \"Children\" != '' )"; | ||
773 | } | ||
774 | |||
775 | if ( filter & OPimContactAccess::DoNotShowWithoutAnniversary ){ | ||
776 | query += " AND ( \"Anniversary\" != '' )"; | ||
777 | } | ||
778 | |||
779 | if ( filter & OPimContactAccess::DoNotShowWithoutBirthday ){ | ||
780 | query += " AND ( \"Birthday\" != '' )"; | ||
781 | } | ||
782 | |||
783 | if ( filter & OPimContactAccess::DoNotShowWithoutHomeAddress ){ | ||
784 | // Expect that no Street means no Address, too! (eilers) | ||
785 | query += " AND ( \"Home Street\" != '' )"; | ||
786 | } | ||
787 | |||
788 | if ( filter & OPimContactAccess::DoNotShowWithoutBusinessAddress ){ | ||
789 | // Expect that no Street means no Address, too! (eilers) | ||
790 | query += " AND ( \"Business Street\" != '' )"; | ||
791 | } | ||
792 | |||
793 | } | ||
794 | |||
795 | query += " ORDER BY"; | ||
796 | |||
797 | switch ( sortOrder ) { | ||
798 | case OPimContactAccess::SortSummary: | ||
799 | query += " \"Notes\""; | ||
800 | break; | ||
801 | case OPimContactAccess::SortByCategory: | ||
802 | query += " \"Categories\""; | ||
803 | break; | ||
804 | case OPimContactAccess::SortByDate: | ||
805 | query += " \"\""; | ||
806 | break; | ||
807 | case OPimContactAccess::SortTitle: | ||
808 | query += " \"Name Title\""; | ||
809 | break; | ||
810 | case OPimContactAccess::SortFirstName: | ||
811 | query += " \"First Name\""; | ||
812 | break; | ||
813 | case OPimContactAccess::SortMiddleName: | ||
814 | query += " \"Middle Name\""; | ||
815 | break; | ||
816 | case OPimContactAccess::SortLastName: | ||
817 | query += " \"Last Name\""; | ||
818 | break; | ||
819 | case OPimContactAccess::SortFileAsName: | ||
820 | query += " \"File As\""; | ||
821 | break; | ||
822 | case OPimContactAccess::SortSuffix: | ||
823 | query += " \"Suffix\""; | ||
824 | break; | ||
825 | case OPimContactAccess::SortEmail: | ||
826 | query += " \"Default Email\""; | ||
827 | break; | ||
828 | case OPimContactAccess::SortNickname: | ||
829 | query += " \"Nickname\""; | ||
830 | break; | ||
831 | case OPimContactAccess::SortAnniversary: | ||
832 | query += " \"Anniversary\""; | ||
833 | break; | ||
834 | case OPimContactAccess::SortBirthday: | ||
835 | query += " \"Birthday\""; | ||
836 | break; | ||
837 | case OPimContactAccess::SortGender: | ||
838 | query += " \"Gender\""; | ||
839 | break; | ||
840 | default: | ||
841 | query += " \"Last Name\""; | ||
842 | } | ||
748 | 843 | ||
749 | if ( !asc ) | 844 | if ( !asc ) |
750 | query += "DESC"; | 845 | query += " DESC"; |
846 | |||
751 | 847 | ||
752 | // odebug << "sorted query is: " << query << "" << oendl; | 848 | odebug << "sorted query is: " << query << "" << oendl; |
753 | 849 | ||
754 | OSQLRawQuery raw( query ); | 850 | OSQLRawQuery raw( query ); |
755 | OSQLResult res = m_driver->query( &raw ); | 851 | OSQLResult res = m_driver->query( &raw ); |
756 | if ( res.state() != OSQLResult::Success ){ | 852 | if ( res.state() != OSQLResult::Success ){ |
757 | QArray<int> empty; | 853 | UIDArray empty; |
758 | return empty; | 854 | return empty; |
759 | } | 855 | } |
760 | 856 | ||
761 | QArray<int> list = extractUids( res ); | 857 | UIDArray list = extractUids( res ); |
762 | 858 | ||
763 | odebug << "sorted needed " << t.elapsed() << " ms!" << oendl; | 859 | odebug << "sorted needed " << t.elapsed() << " ms!" << oendl; |
764 | return list; | 860 | return list; |
765 | } | 861 | } |
766 | 862 | ||
767 | 863 | ||
768 | void OPimContactAccessBackend_SQL::update() | 864 | void OPimContactAccessBackend_SQL::update() |
769 | { | 865 | { |
770 | odebug << "Update starts" << oendl; | 866 | odebug << "Update starts" << oendl; |
771 | QTime t; | 867 | QTime t; |
772 | t.start(); | 868 | t.start(); |
773 | 869 | ||
@@ -777,32 +873,32 @@ void OPimContactAccessBackend_SQL::update() | |||
777 | LoadQuery lo; | 873 | LoadQuery lo; |
778 | OSQLResult res = m_driver->query(&lo); | 874 | OSQLResult res = m_driver->query(&lo); |
779 | if ( res.state() != OSQLResult::Success ) | 875 | if ( res.state() != OSQLResult::Success ) |
780 | return; | 876 | return; |
781 | 877 | ||
782 | m_uids = extractUids( res ); | 878 | m_uids = extractUids( res ); |
783 | 879 | ||
784 | m_changed = false; | 880 | m_changed = false; |
785 | 881 | ||
786 | odebug << "Update ends " << t.elapsed() << " ms" << oendl; | 882 | odebug << "Update ends " << t.elapsed() << " ms" << oendl; |
787 | } | 883 | } |
788 | 884 | ||
789 | QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const | 885 | UIDArray OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const |
790 | { | 886 | { |
791 | odebug << "extractUids" << oendl; | 887 | odebug << "extractUids" << oendl; |
792 | QTime t; | 888 | QTime t; |
793 | t.start(); | 889 | t.start(); |
794 | OSQLResultItem::ValueList list = res.results(); | 890 | OSQLResultItem::ValueList list = res.results(); |
795 | OSQLResultItem::ValueList::Iterator it; | 891 | OSQLResultItem::ValueList::Iterator it; |
796 | QArray<int> ints(list.count() ); | 892 | UIDArray ints(list.count() ); |
797 | odebug << " count = " << list.count() << "" << oendl; | 893 | odebug << " count = " << list.count() << "" << oendl; |
798 | 894 | ||
799 | int i = 0; | 895 | int i = 0; |
800 | for (it = list.begin(); it != list.end(); ++it ) { | 896 | for (it = list.begin(); it != list.end(); ++it ) { |
801 | ints[i] = (*it).data("uid").toInt(); | 897 | ints[i] = (*it).data("uid").toInt(); |
802 | i++; | 898 | i++; |
803 | } | 899 | } |
804 | odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; | 900 | odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; |
805 | 901 | ||
806 | return ints; | 902 | return ints; |
807 | 903 | ||
808 | } | 904 | } |
@@ -828,31 +924,31 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co | |||
828 | nonCustomMap = fillNonCustomMap( resItem ); | 924 | nonCustomMap = fillNonCustomMap( resItem ); |
829 | t3needed = t3.elapsed(); | 925 | t3needed = t3.elapsed(); |
830 | 926 | ||
831 | 927 | ||
832 | // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; | 928 | // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; |
833 | odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed | 929 | odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed |
834 | << " ms, mapping: " << t3needed << " ms" << oendl; | 930 | << " ms, mapping: " << t3needed << " ms" << oendl; |
835 | 931 | ||
836 | return nonCustomMap; | 932 | return nonCustomMap; |
837 | } | 933 | } |
838 | 934 | ||
839 | /* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */ | 935 | /* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */ |
840 | OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const QArray<int>& uidlist )const | 936 | OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const UIDArray& uidlist )const |
841 | { | 937 | { |
842 | // We want to get all contacts with one query. | 938 | // We want to get all contacts with one query. |
843 | // We don't have to add the given uid to the uidlist, it is expected to be there already (see opimrecordlist.h). | 939 | // We don't have to add the given uid to the uidlist, it is expected to be there already (see opimrecordlist.h). |
844 | // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned | 940 | // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned |
845 | // by using the cache.. | 941 | // by using the cache.. |
846 | QArray<int> cachelist = uidlist; | 942 | UIDArray cachelist = uidlist; |
847 | OPimContact retContact; | 943 | OPimContact retContact; |
848 | 944 | ||
849 | odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl; | 945 | odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl; |
850 | 946 | ||
851 | QTime t; | 947 | QTime t; |
852 | t.start(); | 948 | t.start(); |
853 | 949 | ||
854 | int t2needed = 0; | 950 | int t2needed = 0; |
855 | int t3needed = 0; | 951 | int t3needed = 0; |
856 | QTime t2; | 952 | QTime t2; |
857 | t2.start(); | 953 | t2.start(); |
858 | FindQuery query( cachelist ); | 954 | FindQuery query( cachelist ); |