author | eilers <eilers> | 2004-12-20 14:14:07 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-12-20 14:14:07 (UTC) |
commit | 18e47153532d016d878f47e0ce11cb1a9716218e (patch) (unidiff) | |
tree | 52eb6c25258fda0b2f295a29809c4603f5e17b0b /libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |
parent | 876e48baa20213d8265041cfac3034fe92cb0590 (diff) | |
download | opie-18e47153532d016d878f47e0ce11cb1a9716218e.zip opie-18e47153532d016d878f47e0ce11cb1a9716218e.tar.gz opie-18e47153532d016d878f47e0ce11cb1a9716218e.tar.bz2 |
Recovery of the following Changes:
* Implement fast and full featured version of sorted() for addressbook
* Implement generic queryByExample for all Addressboook backends. It allows incremental search.
* Update of API Documentation
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 | |||
@@ -129,3 +129,3 @@ namespace { | |||
129 | FindQuery(int uid); | 129 | FindQuery(int uid); |
130 | FindQuery(const QArray<int>& ); | 130 | FindQuery(const UIDArray& ); |
131 | ~FindQuery(); | 131 | ~FindQuery(); |
@@ -135,3 +135,3 @@ namespace { | |||
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; |
@@ -145,3 +145,3 @@ namespace { | |||
145 | FindCustomQuery(int uid); | 145 | FindCustomQuery(int uid); |
146 | FindCustomQuery(const QArray<int>& ); | 146 | FindCustomQuery(const UIDArray& ); |
147 | ~FindCustomQuery(); | 147 | ~FindCustomQuery(); |
@@ -151,3 +151,3 @@ namespace { | |||
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; |
@@ -296,3 +296,3 @@ namespace { | |||
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 ){ |
@@ -331,3 +331,3 @@ namespace { | |||
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 ){ |
@@ -424,3 +424,3 @@ bool OPimContactAccessBackend_SQL::wasChangedExternally() | |||
424 | 424 | ||
425 | QArray<int> OPimContactAccessBackend_SQL::allRecords() const | 425 | UIDArray OPimContactAccessBackend_SQL::allRecords() const |
426 | { | 426 | { |
@@ -487,3 +487,3 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const | |||
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 | { |
@@ -530,3 +530,4 @@ OPimContact OPimContactAccessBackend_SQL::find( int uid, const QArray<int>& quer | |||
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 | { |
@@ -641,3 +642,3 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu | |||
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; |
@@ -645,3 +646,3 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu | |||
645 | 646 | ||
646 | QArray<int> list = extractUids( res ); | 647 | UIDArray list = extractUids( res ); |
647 | 648 | ||
@@ -650,3 +651,3 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu | |||
650 | 651 | ||
651 | QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 652 | UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
652 | { | 653 | { |
@@ -681,3 +682,3 @@ QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | |||
681 | 682 | ||
682 | const uint OPimContactAccessBackend_SQL::querySettings() | 683 | const uint OPimContactAccessBackend_SQL::querySettings() const |
683 | { | 684 | { |
@@ -740,3 +741,4 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | |||
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 | { |
@@ -745,9 +747,103 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) | |||
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 | ||
@@ -756,3 +852,3 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) | |||
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; |
@@ -760,3 +856,3 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) | |||
760 | 856 | ||
761 | QArray<int> list = extractUids( res ); | 857 | UIDArray list = extractUids( res ); |
762 | 858 | ||
@@ -788,3 +884,3 @@ void OPimContactAccessBackend_SQL::update() | |||
788 | 884 | ||
789 | QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const | 885 | UIDArray OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const |
790 | { | 886 | { |
@@ -795,3 +891,3 @@ QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const | |||
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; |
@@ -839,3 +935,3 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co | |||
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 | { |
@@ -845,3 +941,3 @@ OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, cons | |||
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; |