Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 132b5a6..6f65c48 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -25,27 +25,31 @@ | |||
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <qdatetime.h> | 31 | /* OPIE */ |
32 | #include <qmap.h> | ||
33 | #include <qstring.h> | ||
34 | |||
35 | #include <qpe/global.h> | ||
36 | |||
37 | #include <opie2/osqldriver.h> | 32 | #include <opie2/osqldriver.h> |
38 | #include <opie2/osqlresult.h> | 33 | #include <opie2/osqlresult.h> |
39 | #include <opie2/osqlmanager.h> | 34 | #include <opie2/osqlmanager.h> |
40 | #include <opie2/osqlquery.h> | 35 | #include <opie2/osqlquery.h> |
41 | 36 | ||
42 | #include <opie2/otodoaccesssql.h> | 37 | #include <opie2/otodoaccesssql.h> |
43 | #include <opie2/opimstate.h> | 38 | #include <opie2/opimstate.h> |
44 | #include <opie2/opimnotifymanager.h> | 39 | #include <opie2/opimnotifymanager.h> |
45 | #include <opie2/opimrecurrence.h> | 40 | #include <opie2/opimrecurrence.h> |
41 | #include <opie2/odebug.h> | ||
42 | |||
43 | #include <qpe/global.h> | ||
44 | |||
45 | /* QT */ | ||
46 | #include <qdatetime.h> | ||
47 | #include <qmap.h> | ||
48 | #include <qstring.h> | ||
49 | |||
46 | 50 | ||
47 | using namespace Opie::DB; | 51 | using namespace Opie::DB; |
48 | 52 | ||
49 | using namespace Opie; | 53 | using namespace Opie; |
50 | /* | 54 | /* |
51 | * first some query | 55 | * first some query |
@@ -288,13 +292,13 @@ namespace { | |||
288 | + ",'" | 292 | + ",'" |
289 | + it.data() | 293 | + it.data() |
290 | + "');"; | 294 | + "');"; |
291 | } | 295 | } |
292 | 296 | ||
293 | 297 | ||
294 | qDebug("add %s", qu.latin1() ); | 298 | odebug << "add " << qu << "" << oendl; |
295 | return qu; | 299 | return qu; |
296 | } | 300 | } |
297 | 301 | ||
298 | RemoveQuery::RemoveQuery(int uid ) | 302 | RemoveQuery::RemoveQuery(int uid ) |
299 | : OSQLQuery(), m_uid( uid ) {} | 303 | : OSQLQuery(), m_uid( uid ) {} |
300 | RemoveQuery::~RemoveQuery() {} | 304 | RemoveQuery::~RemoveQuery() {} |
@@ -453,23 +457,23 @@ OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ | |||
453 | return todo( m_driver->query(&query) ); | 457 | return todo( m_driver->query(&query) ); |
454 | 458 | ||
455 | } | 459 | } |
456 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 460 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
457 | uint cur, Frontend::CacheDirection dir ) const{ | 461 | uint cur, Frontend::CacheDirection dir ) const{ |
458 | uint CACHE = readAhead(); | 462 | uint CACHE = readAhead(); |
459 | qDebug("searching for %d", uid ); | 463 | odebug << "searching for " << uid << "" << oendl; |
460 | QArray<int> search( CACHE ); | 464 | QArray<int> search( CACHE ); |
461 | uint size =0; | 465 | uint size =0; |
462 | OPimTodo to; | 466 | OPimTodo to; |
463 | 467 | ||
464 | // we try to cache CACHE items | 468 | // we try to cache CACHE items |
465 | switch( dir ) { | 469 | switch( dir ) { |
466 | /* forward */ | 470 | /* forward */ |
467 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) | 471 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) |
468 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 472 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
469 | qDebug("size %d %d", size, ints[i] ); | 473 | odebug << "size " << size << " " << ints[i] << "" << oendl; |
470 | search[size] = ints[i]; | 474 | search[size] = ints[i]; |
471 | size++; | 475 | size++; |
472 | } | 476 | } |
473 | break; | 477 | break; |
474 | /* reverse */ | 478 | /* reverse */ |
475 | case 1: // FIXME: Not a good style to use magic numbers here (eilers) | 479 | case 1: // FIXME: Not a good style to use magic numbers here (eilers) |
@@ -538,13 +542,13 @@ QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, | |||
538 | } | 542 | } |
539 | /* | 543 | /* |
540 | * | 544 | * |
541 | */ | 545 | */ |
542 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 546 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
543 | int sortFilter, int cat ) { | 547 | int sortFilter, int cat ) { |
544 | qDebug("sorted %d, %d", asc, sortOrder ); | 548 | odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; |
545 | QString query; | 549 | QString query; |
546 | query = "select uid from todolist WHERE "; | 550 | query = "select uid from todolist WHERE "; |
547 | 551 | ||
548 | /* | 552 | /* |
549 | * Sort Filter stuff | 553 | * Sort Filter stuff |
550 | * not that straight forward | 554 | * not that straight forward |
@@ -597,17 +601,17 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
597 | case 3: | 601 | case 3: |
598 | query += "DueDate"; | 602 | query += "DueDate"; |
599 | break; | 603 | break; |
600 | } | 604 | } |
601 | 605 | ||
602 | if ( !asc ) { | 606 | if ( !asc ) { |
603 | qDebug("not ascending!"); | 607 | odebug << "not ascending!" << oendl; |
604 | query += " DESC"; | 608 | query += " DESC"; |
605 | } | 609 | } |
606 | 610 | ||
607 | qDebug( query ); | 611 | odebug << query << oendl; |
608 | OSQLRawQuery raw(query ); | 612 | OSQLRawQuery raw(query ); |
609 | return uids( m_driver->query(&raw) ); | 613 | return uids( m_driver->query(&raw) ); |
610 | } | 614 | } |
611 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 615 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
612 | if ( str == "0-0-0" ) | 616 | if ( str == "0-0-0" ) |
613 | return false; | 617 | return false; |
@@ -626,33 +630,33 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ | |||
626 | OPimTodo to; | 630 | OPimTodo to; |
627 | return to; | 631 | return to; |
628 | } | 632 | } |
629 | 633 | ||
630 | OSQLResultItem::ValueList list = res.results(); | 634 | OSQLResultItem::ValueList list = res.results(); |
631 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 635 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
632 | qDebug("todo1"); | 636 | odebug << "todo1" << oendl; |
633 | OPimTodo to = todo( (*it) ); | 637 | OPimTodo to = todo( (*it) ); |
634 | cache( to ); | 638 | cache( to ); |
635 | ++it; | 639 | ++it; |
636 | 640 | ||
637 | for ( ; it != list.end(); ++it ) { | 641 | for ( ; it != list.end(); ++it ) { |
638 | qDebug("caching"); | 642 | odebug << "caching" << oendl; |
639 | cache( todo( (*it) ) ); | 643 | cache( todo( (*it) ) ); |
640 | } | 644 | } |
641 | return to; | 645 | return to; |
642 | } | 646 | } |
643 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 647 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
644 | qDebug("todo(ResultItem)"); | 648 | odebug << "todo(ResultItem)" << oendl; |
645 | 649 | ||
646 | // Request information from addressbook table and create the OPimTodo-object. | 650 | // Request information from addressbook table and create the OPimTodo-object. |
647 | 651 | ||
648 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); | 652 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
649 | hasDueDate = date( dueDate, item.data("DueDate") ); | 653 | hasDueDate = date( dueDate, item.data("DueDate") ); |
650 | QStringList cats = QStringList::split(";", item.data("categories") ); | 654 | QStringList cats = QStringList::split(";", item.data("categories") ); |
651 | 655 | ||
652 | qDebug("Item is completed: %d", item.data("completed").toInt() ); | 656 | odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl; |
653 | 657 | ||
654 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 658 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
655 | cats, item.data("summary"), item.data("description"), | 659 | cats, item.data("summary"), item.data("description"), |
656 | item.data("progress").toUShort(), hasDueDate, dueDate, | 660 | item.data("progress").toUShort(), hasDueDate, dueDate, |
657 | item.data("uid").toInt() ); | 661 | item.data("uid").toInt() ); |
658 | 662 | ||
@@ -747,13 +751,13 @@ void OPimTodoAccessBackendSQL::update()const { | |||
747 | } | 751 | } |
748 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 752 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
749 | 753 | ||
750 | OSQLResultItem::ValueList list = res.results(); | 754 | OSQLResultItem::ValueList list = res.results(); |
751 | OSQLResultItem::ValueList::Iterator it; | 755 | OSQLResultItem::ValueList::Iterator it; |
752 | QArray<int> ints(list.count() ); | 756 | QArray<int> ints(list.count() ); |
753 | qDebug(" count = %d", list.count() ); | 757 | odebug << " count = " << list.count() << "" << oendl; |
754 | 758 | ||
755 | int i = 0; | 759 | int i = 0; |
756 | for (it = list.begin(); it != list.end(); ++it ) { | 760 | for (it = list.begin(); it != list.end(); ++it ) { |
757 | ints[i] = (*it).data("uid").toInt(); | 761 | ints[i] = (*it).data("uid").toInt(); |
758 | i++; | 762 | i++; |
759 | } | 763 | } |
@@ -773,13 +777,13 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | |||
773 | // Do it make sense to search other fields, too ? | 777 | // Do it make sense to search other fields, too ? |
774 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; | 778 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; |
775 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; | 779 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; |
776 | 780 | ||
777 | qu += ")"; | 781 | qu += ")"; |
778 | 782 | ||
779 | qDebug( "query: %s", qu.latin1() ); | 783 | odebug << "query: " << qu << "" << oendl; |
780 | 784 | ||
781 | OSQLRawQuery raw( qu ); | 785 | OSQLRawQuery raw( qu ); |
782 | OSQLResult res = m_driver->query( &raw ); | 786 | OSQLResult res = m_driver->query( &raw ); |
783 | 787 | ||
784 | return uids( res ); | 788 | return uids( res ); |
785 | 789 | ||
@@ -813,13 +817,13 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){ | |||
813 | 817 | ||
814 | OSQLRawQuery raw( qu ); | 818 | OSQLRawQuery raw( qu ); |
815 | OSQLResult res = m_driver->query( &raw ); | 819 | OSQLResult res = m_driver->query( &raw ); |
816 | 820 | ||
817 | QArray<int> completed_uids = uids( res ); | 821 | QArray<int> completed_uids = uids( res ); |
818 | 822 | ||
819 | qDebug( "Number of completed: %d", completed_uids.size() ); | 823 | odebug << "Number of completed: " << completed_uids.size() << "" << oendl; |
820 | 824 | ||
821 | if ( completed_uids.size() == 0 ) | 825 | if ( completed_uids.size() == 0 ) |
822 | return; | 826 | return; |
823 | 827 | ||
824 | qu = "DELETE FROM todolist WHERE ("; | 828 | qu = "DELETE FROM todolist WHERE ("; |
825 | QString query; | 829 | QString query; |
@@ -839,31 +843,31 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){ | |||
839 | if ( !query.isEmpty() ) | 843 | if ( !query.isEmpty() ) |
840 | query += " OR "; | 844 | query += " OR "; |
841 | query += QString( "uid = %1" ).arg( completed_uids[i] ); | 845 | query += QString( "uid = %1" ).arg( completed_uids[i] ); |
842 | } | 846 | } |
843 | qu += query + " );"; | 847 | qu += query + " );"; |
844 | 848 | ||
845 | qDebug( "query: %s", qu.latin1() ); | 849 | odebug << "query: " << qu << "" << oendl; |
846 | 850 | ||
847 | OSQLRawQuery raw2( qu ); | 851 | OSQLRawQuery raw2( qu ); |
848 | res = m_driver->query( &raw2 ); | 852 | res = m_driver->query( &raw2 ); |
849 | if ( res.state() == OSQLResult::Failure ) { | 853 | if ( res.state() == OSQLResult::Failure ) { |
850 | qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() ); | 854 | owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; |
851 | } | 855 | } |
852 | } | 856 | } |
853 | 857 | ||
854 | 858 | ||
855 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const | 859 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const |
856 | { | 860 | { |
857 | QMap<QString, QString> customMap; | 861 | QMap<QString, QString> customMap; |
858 | 862 | ||
859 | FindCustomQuery query( uid ); | 863 | FindCustomQuery query( uid ); |
860 | OSQLResult res_custom = m_driver->query( &query ); | 864 | OSQLResult res_custom = m_driver->query( &query ); |
861 | 865 | ||
862 | if ( res_custom.state() == OSQLResult::Failure ) { | 866 | if ( res_custom.state() == OSQLResult::Failure ) { |
863 | qWarning("OSQLResult::Failure in find query !!"); | 867 | owarn << "OSQLResult::Failure in find query !!" << oendl; |
864 | QMap<QString, QString> empty; | 868 | QMap<QString, QString> empty; |
865 | return empty; | 869 | return empty; |
866 | } | 870 | } |
867 | 871 | ||
868 | OSQLResultItem::ValueList list = res_custom.results(); | 872 | OSQLResultItem::ValueList list = res_custom.results(); |
869 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 873 | OSQLResultItem::ValueList::Iterator it = list.begin(); |