summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccesssql.cpp
authoreilers <eilers>2004-04-12 17:46:08 (UTC)
committer eilers <eilers>2004-04-12 17:46:08 (UTC)
commit78a8f4f240bb57fe4942a30085e6a84fb3c4bac6 (patch) (side-by-side diff)
tree23345a150cbc71ad8ad805fd1c8fa5522e10593f /libopie2/opiepim/backend/otodoaccesssql.cpp
parente8592cb2da1719d9ab1dc9e1144810af6af39e84 (diff)
downloadopie-78a8f4f240bb57fe4942a30085e6a84fb3c4bac6.zip
opie-78a8f4f240bb57fe4942a30085e6a84fb3c4bac6.tar.gz
opie-78a8f4f240bb57fe4942a30085e6a84fb3c4bac6.tar.bz2
Implementing regexp search. OSearch works now..
todo: Implemented removal of finished todo items..
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp75
1 files changed, 58 insertions, 17 deletions
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
@@ -298,9 +298,10 @@ namespace {
RemoveQuery::RemoveQuery(int uid )
: 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;
}
@@ -761,32 +762,31 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
{
-#warning OPimTodoAccessBackendSQL::matchRegexp() not implemented !!
-
#if 0
+ QArray<int> empty;
+ return empty;
- Copied from xml-backend by not adapted to sql (eilers)
+#else
+ QString qu = "SELECT uid FROM todolist WHERE (";
- QArray<int> 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<int, OPimTodo>::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<int> empty;
- return empty;
+
}
QBitArray OPimTodoAccessBackendSQL::supports()const {
return sup();
@@ -805,10 +805,51 @@ QBitArray OPimTodoAccessBackendSQL::sup() const{
return ar;
}
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<int> 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() );
+ }
}
QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const