summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
authoreilers <eilers>2004-12-20 14:14:07 (UTC)
committer eilers <eilers>2004-12-20 14:14:07 (UTC)
commit18e47153532d016d878f47e0ce11cb1a9716218e (patch) (unidiff)
tree52eb6c25258fda0b2f295a29809c4603f5e17b0b /libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
parent876e48baa20213d8265041cfac3034fe92cb0590 (diff)
downloadopie-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.cpp144
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
@@ -127,13 +127,13 @@ namespace {
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
@@ -143,13 +143,13 @@ namespace {
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
@@ -294,7 +294,7 @@ namespace {
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() {
@@ -329,7 +329,7 @@ namespace {
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() {
@@ -422,7 +422,7 @@ bool OPimContactAccessBackend_SQL::wasChangedExternally()
422 return false; 422 return false;
423} 423}
424 424
425QArray<int> OPimContactAccessBackend_SQL::allRecords() const 425UIDArray 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..
@@ -485,7 +485,7 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
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 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;
@@ -528,7 +528,8 @@ OPimContact OPimContactAccessBackend_SQL::find( int uid, const QArray<int>& quer
528} 528}
529 529
530 530
531QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) 531UIDArray 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 ="";
@@ -639,16 +640,16 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
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
651QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 652UIDArray 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);
@@ -679,7 +680,7 @@ QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
679#endif 680#endif
680} 681}
681 682
682const uint OPimContactAccessBackend_SQL::querySettings() 683const uint OPimContactAccessBackend_SQL::querySettings() const
683{ 684{
684 return OPimContactAccess::IgnoreCase 685 return OPimContactAccess::IgnoreCase
685 | OPimContactAccess::WildCards 686 | OPimContactAccess::WildCards
@@ -738,27 +739,122 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
738 739
739} 740}
740 741
741QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) 742UIDArray 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;
@@ -786,14 +882,14 @@ void OPimContactAccessBackend_SQL::update()
786 odebug << "Update ends " << t.elapsed() << " ms" << oendl; 882 odebug << "Update ends " << t.elapsed() << " ms" << oendl;
787} 883}
788 884
789QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const 885UIDArray 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;
@@ -837,13 +933,13 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
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 */
840OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const QArray<int>& uidlist )const 936OPimContact 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;