From 78a8f4f240bb57fe4942a30085e6a84fb3c4bac6 Mon Sep 17 00:00:00 2001 From: eilers Date: Mon, 12 Apr 2004 17:46:08 +0000 Subject: Implementing regexp search. OSearch works now.. todo: Implemented removal of finished todo items.. --- (limited to 'libopie2/opiepim') 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() OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ + qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid ); + QString qu = "select *"; qu += "from datebook where uid = " + QString::number(uid); @@ -242,6 +244,8 @@ OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ // Last step: Put map into date event, add custom map and return it OPimEvent retDate( dateEventMap ); retDate.setExtraMap( requestCustom( uid ) ); + + qDebug( "ODateBookAccessBackend_SQL::find() end", uid ); return retDate; } @@ -375,8 +379,24 @@ OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() QArray ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const { - QArray null; - return null; + + QString qu = "SELECT uid FROM datebook WHERE ("; + + // Do it make sense to search other fields, too ? + qu += " rlike(\""+ r.pattern() + "\", Location ) OR"; + qu += " rlike(\""+ r.pattern() + "\", Note )"; + + qu += " )"; + + qDebug( "query: %s", qu.latin1() ); + + OSQLRawQuery raw( qu ); + OSQLResult res = m_driver->query( &raw ); + + return extractUids( res ); + + + } /* ===== 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 { : OSQLQuery(), m_uid( uid ) {} RemoveQuery::~RemoveQuery() {} QString RemoveQuery::query()const { - QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); + QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; + qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); return qu; } @@ -762,30 +763,29 @@ QArray OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ QArray OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const { -#warning OPimTodoAccessBackendSQL::matchRegexp() not implemented !! - #if 0 + QArray empty; + return empty; - Copied from xml-backend by not adapted to sql (eilers) +#else + QString qu = "SELECT uid FROM todolist WHERE ("; - QArray m_currentQuery( m_events.count() ); - uint arraycounter = 0; + // Do it make sense to search other fields, too ? + qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; + qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; + + qu += ")"; + qDebug( "query: %s", qu.latin1() ); + OSQLRawQuery raw( qu ); + OSQLResult res = m_driver->query( &raw ); - QMap::ConstIterator it; - for (it = m_events.begin(); it != m_events.end(); ++it ) { - if ( it.data().match( r ) ) - m_currentQuery[arraycounter++] = it.data().uid(); + return uids( res ); - } - // Shrink to fit.. - m_currentQuery.resize(arraycounter); - return m_currentQuery; #endif - QArray empty; - return empty; + } QBitArray OPimTodoAccessBackendSQL::supports()const { @@ -806,8 +806,49 @@ QBitArray OPimTodoAccessBackendSQL::sup() const{ } void OPimTodoAccessBackendSQL::removeAllCompleted(){ -#warning OPimTodoAccessBackendSQL::removeAllCompleted() not implemented !! + // First we need the uids from all entries which are + // completed. Then, we just have to remove them... + + QString qu = "SELECT uid FROM todolist WHERE completed = 1"; + + OSQLRawQuery raw( qu ); + OSQLResult res = m_driver->query( &raw ); + + QArray completed_uids = uids( res ); + qDebug( "Number of completed: %d", completed_uids.size() ); + + if ( completed_uids.size() == 0 ) + return; + + qu = "DELETE FROM todolist WHERE ("; + QString query; + + for ( int i = 0; i < completed_uids.size(); i++ ){ + if ( !query.isEmpty() ) + query += " OR "; + query += QString( "uid = %1" ).arg( completed_uids[i] ); + } + qu += query + " );"; + + // Put remove of custom entries in this query to speed up.. + qu += "DELETE FORM custom_data WHERE ("; + query = ""; + + for ( int i = 0; i < completed_uids.size(); i++ ){ + if ( !query.isEmpty() ) + query += " OR "; + query += QString( "uid = %1" ).arg( completed_uids[i] ); + } + qu += query + " );"; + + qDebug( "query: %s", qu.latin1() ); + + OSQLRawQuery raw2( qu ); + res = m_driver->query( &raw2 ); + if ( res.state() == OSQLResult::Failure ) { + qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() ); + } } -- cgit v0.9.0.2