Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 129 |
1 files changed, 32 insertions, 97 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 4e3e47b..2bcab29 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp @@ -456,5 +456,4 @@ OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ FindQuery query( uid ); return parseResultAndCache( uid, m_driver->query(&query) ); - } @@ -466,5 +465,4 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, QArray<int> search( CACHE ); uint size =0; - OPimTodo to; // we try to cache CACHE items @@ -473,5 +471,4 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, case Frontend::Forward: for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { - odebug << "size " << size << " " << ints[i] << "" << oendl; search[size] = ints[i]; size++; @@ -491,5 +488,5 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, OSQLResult res = m_driver->query( &query ); if ( res.state() != OSQLResult::Success ) - return to; + return OPimTodo(); return parseResultAndCache( uid, res ); @@ -508,4 +505,5 @@ bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { if ( res.state() == OSQLResult::Failure ) return false; + int c = m_uids.count(); m_uids.resize( c+1 ); @@ -535,5 +533,5 @@ bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { return b; } -QArray<int> OPimTodoAccessBackendSQL::overDue() { +QArray<int> OPimTodoAccessBackendSQL::overDue()const { OverDueQuery qu; return uids( m_driver->query(&qu ) ); @@ -541,8 +539,10 @@ QArray<int> OPimTodoAccessBackendSQL::overDue() { QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, const QDate& t, - bool u) { + bool u)const { EffQuery ef(s, t, u ); return uids (m_driver->query(&ef) ); } + +#if 0 /* * @@ -561,5 +561,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, */ /* Category */ - if ( sortFilter & 1 ) { + if ( sortFilter & OPimTodoAccess::FilterCategory ) { QString str; if (cat != 0 ) str = QString::number( cat ); @@ -567,5 +567,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, } /* Show only overdue */ - if ( sortFilter & 2 ) { + if ( sortFilter & OPimTodoAccess::OnlyOverDue ) { QDate date = QDate::currentDate(); QString due; @@ -578,5 +578,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, } /* not show completed */ - if ( sortFilter & 4 ) { + if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) { query += " completed = 0 AND"; }else{ @@ -594,22 +594,21 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, switch( sortOrder ) { /* completed */ - case 0: + case OPimTodoAccess::Completed: query += "completed"; break; - case 1: + case OPimTodoAccess::Priority: query += "priority"; break; - case 2: + case OPimTodoAccess::SortSummary: query += "summary"; break; - case 3: + case OPimTodoAccess::Deadline: query += "DueDate"; break; } - if ( !asc ) { - odebug << "not ascending!" << oendl; + if ( !asc ) query += " DESC"; - } + odebug << query << oendl; @@ -617,4 +616,7 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, return uids( m_driver->query(&raw) ); } +#endif + + bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ if ( str == "0-0-0" ) @@ -630,4 +632,6 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ } } + + OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ if ( res.state() == OSQLResult::Failure ) { @@ -640,12 +644,8 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); - odebug << "todo1" << oendl; - OPimTodo to = todo( (*it) ); - cache( to ); - ++it; + OPimTodo to, tmp; for ( ; it != list.end(); ++it ) { - odebug << "caching" << oendl; - OPimTodo newTodo = todo( (*it) ); + OPimTodo newTodo = parse( (*it) ); cache( newTodo ); if ( newTodo.uid() == uid ) @@ -654,6 +654,5 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul return retTodo; } -OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { - odebug << "todo(ResultItem)" << oendl; +OPimTodo OPimTodoAccessBackendSQL::parse( OSQLResultItem& item )const { // Request information from addressbook table and create the OPimTodo-object. @@ -663,6 +662,4 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { QStringList cats = QStringList::split(";", item.data("categories") ); - odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl; - OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), cats, item.data("summary"), item.data("description"), @@ -718,34 +715,6 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { return parseResultAndCache( uid, m_driver->query(&find) ); } -/* - * update the dict - */ -void OPimTodoAccessBackendSQL::fillDict() { -#if 0 - /* initialize dict */ - /* - * UPDATE dict if you change anything!!! - * FIXME: Isn't this dict obsolete ? (eilers) - */ - m_dict.setAutoDelete( TRUE ); - m_dict.insert("Categories" , new int(OPimTodo::Category) ); - m_dict.insert("Uid" , new int(OPimTodo::Uid) ); - m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); - m_dict.insert("Completed" , new int(OPimTodo::Completed) ); - m_dict.insert("Description" , new int(OPimTodo::Description) ); - m_dict.insert("Summary" , new int(OPimTodo::Summary) ); - m_dict.insert("Priority" , new int(OPimTodo::Priority) ); - m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); - m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); - m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); - m_dict.insert("Progress" , new int(OPimTodo::Progress) ); - m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) - m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); -// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) -// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) -#endif -} /* * need to be const so let's fool the @@ -766,5 +735,4 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ OSQLResultItem::ValueList::Iterator it; QArray<int> ints(list.count() ); - odebug << " count = " << list.count() << "" << oendl; int i = 0; @@ -778,13 +746,7 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const { - -#if 0 - QArray<int> empty; - return empty; - -#else QString qu = "SELECT uid FROM todolist WHERE ("; - // Do it make sense to search other fields, too ? + // Does it make sense to search other fields, too ? qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; @@ -792,31 +754,8 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const qu += ")"; - odebug << "query: " << qu << "" << oendl; - OSQLRawQuery raw( qu ); OSQLResult res = m_driver->query( &raw ); return uids( res ); - - -#endif - -} -QBitArray OPimTodoAccessBackendSQL::supports()const { - - return sup(); -} - -QBitArray OPimTodoAccessBackendSQL::sup() const{ - - QBitArray ar( OPimTodo::CompletedDate + 1 ); - ar.fill( true ); - ar[OPimTodo::CrossReference] = false; - ar[OPimTodo::State ] = false; - ar[OPimTodo::Reminders] = false; - ar[OPimTodo::Notifiers] = false; - ar[OPimTodo::Maintainer] = false; - - return ar; } @@ -832,6 +771,4 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){ QArray<int> completed_uids = uids( res ); - odebug << "Number of completed: " << completed_uids.size() << "" << oendl; - if ( completed_uids.size() == 0 ) return; @@ -840,5 +777,5 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){ QString query; - for ( int i = 0; i < completed_uids.size(); i++ ){ + for ( uint i = 0; i < completed_uids.size(); i++ ){ if ( !query.isEmpty() ) query += " OR "; @@ -851,5 +788,5 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){ query = ""; - for ( int i = 0; i < completed_uids.size(); i++ ){ + for ( uint i = 0; i < completed_uids.size(); i++ ){ if ( !query.isEmpty() ) query += " OR "; @@ -858,11 +795,10 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){ qu += query + " );"; - odebug << "query: " << qu << "" << oendl; - OSQLRawQuery raw2( qu ); res = m_driver->query( &raw2 ); - if ( res.state() == OSQLResult::Failure ) { + + if ( res.state() == OSQLResult::Failure ) owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; - } + } @@ -877,13 +813,12 @@ QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const if ( res_custom.state() == OSQLResult::Failure ) { owarn << "OSQLResult::Failure in find query !!" << oendl; - QMap<QString, QString> empty; - return empty; + return QMap<QString, QString>(); } OSQLResultItem::ValueList list = res_custom.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); - for ( ; it != list.end(); ++it ) { + for ( ; it != list.end(); ++it ) customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); - } + return customMap; |