author | eilers <eilers> | 2004-04-12 17:46:08 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-04-12 17:46:08 (UTC) |
commit | 78a8f4f240bb57fe4942a30085e6a84fb3c4bac6 (patch) (unidiff) | |
tree | 23345a150cbc71ad8ad805fd1c8fa5522e10593f /libopie2/opiepim | |
parent | e8592cb2da1719d9ab1dc9e1144810af6af39e84 (diff) | |
download | opie-78a8f4f240bb57fe4942a30085e6a84fb3c4bac6.zip opie-78a8f4f240bb57fe4942a30085e6a84fb3c4bac6.tar.gz opie-78a8f4f240bb57fe4942a30085e6a84fb3c4bac6.tar.bz2 |
Implementing regexp search. OSearch works now..
todo: Implemented removal of finished todo items..
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 24 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 75 |
2 files changed, 80 insertions, 19 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index 8a8cb0b..495a8dd 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -221,6 +221,8 @@ void ODateBookAccessBackend_SQL::clear() | |||
221 | 221 | ||
222 | 222 | ||
223 | OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | 223 | OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ |
224 | qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid ); | ||
225 | |||
224 | QString qu = "select *"; | 226 | QString qu = "select *"; |
225 | qu += "from datebook where uid = " + QString::number(uid); | 227 | qu += "from datebook where uid = " + QString::number(uid); |
226 | 228 | ||
@@ -242,6 +244,8 @@ OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | |||
242 | // Last step: Put map into date event, add custom map and return it | 244 | // Last step: Put map into date event, add custom map and return it |
243 | OPimEvent retDate( dateEventMap ); | 245 | OPimEvent retDate( dateEventMap ); |
244 | retDate.setExtraMap( requestCustom( uid ) ); | 246 | retDate.setExtraMap( requestCustom( uid ) ); |
247 | |||
248 | qDebug( "ODateBookAccessBackend_SQL::find() end", uid ); | ||
245 | return retDate; | 249 | return retDate; |
246 | } | 250 | } |
247 | 251 | ||
@@ -375,8 +379,24 @@ OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() | |||
375 | 379 | ||
376 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 380 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
377 | { | 381 | { |
378 | QArray<int> null; | 382 | |
379 | return null; | 383 | QString qu = "SELECT uid FROM datebook WHERE ("; |
384 | |||
385 | // Do it make sense to search other fields, too ? | ||
386 | qu += " rlike(\""+ r.pattern() + "\", Location ) OR"; | ||
387 | qu += " rlike(\""+ r.pattern() + "\", Note )"; | ||
388 | |||
389 | qu += " )"; | ||
390 | |||
391 | qDebug( "query: %s", qu.latin1() ); | ||
392 | |||
393 | OSQLRawQuery raw( qu ); | ||
394 | OSQLResult res = m_driver->query( &raw ); | ||
395 | |||
396 | return extractUids( res ); | ||
397 | |||
398 | |||
399 | |||
380 | } | 400 | } |
381 | 401 | ||
382 | /* ===== Private Functions ========================================== */ | 402 | /* ===== Private Functions ========================================== */ |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index b4170fc..ef036d5 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -299,7 +299,8 @@ namespace { | |||
299 | : OSQLQuery(), m_uid( uid ) {} | 299 | : OSQLQuery(), m_uid( uid ) {} |
300 | RemoveQuery::~RemoveQuery() {} | 300 | RemoveQuery::~RemoveQuery() {} |
301 | QString RemoveQuery::query()const { | 301 | QString RemoveQuery::query()const { |
302 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); | 302 | QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; |
303 | qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); | ||
303 | return qu; | 304 | return qu; |
304 | } | 305 | } |
305 | 306 | ||
@@ -762,30 +763,29 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | |||
762 | QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | 763 | QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const |
763 | { | 764 | { |
764 | 765 | ||
765 | #warning OPimTodoAccessBackendSQL::matchRegexp() not implemented !! | ||
766 | |||
767 | #if 0 | 766 | #if 0 |
767 | QArray<int> empty; | ||
768 | return empty; | ||
768 | 769 | ||
769 | Copied from xml-backend by not adapted to sql (eilers) | 770 | #else |
771 | QString qu = "SELECT uid FROM todolist WHERE ("; | ||
770 | 772 | ||
771 | QArray<int> m_currentQuery( m_events.count() ); | 773 | // Do it make sense to search other fields, too ? |
772 | uint arraycounter = 0; | 774 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; |
775 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; | ||
776 | |||
777 | qu += ")"; | ||
773 | 778 | ||
779 | qDebug( "query: %s", qu.latin1() ); | ||
774 | 780 | ||
781 | OSQLRawQuery raw( qu ); | ||
782 | OSQLResult res = m_driver->query( &raw ); | ||
775 | 783 | ||
776 | QMap<int, OPimTodo>::ConstIterator it; | 784 | return uids( res ); |
777 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | ||
778 | if ( it.data().match( r ) ) | ||
779 | m_currentQuery[arraycounter++] = it.data().uid(); | ||
780 | 785 | ||
781 | } | ||
782 | // Shrink to fit.. | ||
783 | m_currentQuery.resize(arraycounter); | ||
784 | 786 | ||
785 | return m_currentQuery; | ||
786 | #endif | 787 | #endif |
787 | QArray<int> empty; | 788 | |
788 | return empty; | ||
789 | } | 789 | } |
790 | QBitArray OPimTodoAccessBackendSQL::supports()const { | 790 | QBitArray OPimTodoAccessBackendSQL::supports()const { |
791 | 791 | ||
@@ -806,8 +806,49 @@ QBitArray OPimTodoAccessBackendSQL::sup() const{ | |||
806 | } | 806 | } |
807 | 807 | ||
808 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ | 808 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ |
809 | #warning OPimTodoAccessBackendSQL::removeAllCompleted() not implemented !! | 809 | // First we need the uids from all entries which are |
810 | // completed. Then, we just have to remove them... | ||
811 | |||
812 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; | ||
813 | |||
814 | OSQLRawQuery raw( qu ); | ||
815 | OSQLResult res = m_driver->query( &raw ); | ||
816 | |||
817 | QArray<int> completed_uids = uids( res ); | ||
810 | 818 | ||
819 | qDebug( "Number of completed: %d", completed_uids.size() ); | ||
820 | |||
821 | if ( completed_uids.size() == 0 ) | ||
822 | return; | ||
823 | |||
824 | qu = "DELETE FROM todolist WHERE ("; | ||
825 | QString query; | ||
826 | |||
827 | for ( int i = 0; i < completed_uids.size(); i++ ){ | ||
828 | if ( !query.isEmpty() ) | ||
829 | query += " OR "; | ||
830 | query += QString( "uid = %1" ).arg( completed_uids[i] ); | ||
831 | } | ||
832 | qu += query + " );"; | ||
833 | |||
834 | // Put remove of custom entries in this query to speed up.. | ||
835 | qu += "DELETE FORM custom_data WHERE ("; | ||
836 | query = ""; | ||
837 | |||
838 | for ( int i = 0; i < completed_uids.size(); i++ ){ | ||
839 | if ( !query.isEmpty() ) | ||
840 | query += " OR "; | ||
841 | query += QString( "uid = %1" ).arg( completed_uids[i] ); | ||
842 | } | ||
843 | qu += query + " );"; | ||
844 | |||
845 | qDebug( "query: %s", qu.latin1() ); | ||
846 | |||
847 | OSQLRawQuery raw2( qu ); | ||
848 | res = m_driver->query( &raw2 ); | ||
849 | if ( res.state() == OSQLResult::Failure ) { | ||
850 | qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() ); | ||
851 | } | ||
811 | } | 852 | } |
812 | 853 | ||
813 | 854 | ||