summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccesssql.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp135
1 files changed, 35 insertions, 100 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
@@ -455,7 +455,6 @@ QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, con
455OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ 455OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
456 FindQuery query( uid ); 456 FindQuery query( uid );
457 return parseResultAndCache( uid, m_driver->query(&query) ); 457 return parseResultAndCache( uid, m_driver->query(&query) );
458
459} 458}
460 459
461// Remember: uid is already in the list of uids, called ints ! 460// Remember: uid is already in the list of uids, called ints !
@@ -465,20 +464,18 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
465 odebug << "searching for " << uid << "" << oendl; 464 odebug << "searching for " << uid << "" << oendl;
466 QArray<int> search( CACHE ); 465 QArray<int> search( CACHE );
467 uint size =0; 466 uint size =0;
468 OPimTodo to;
469 467
470 // we try to cache CACHE items 468 // we try to cache CACHE items
471 switch( dir ) { 469 switch( dir ) {
472 /* forward */ 470 /* forward */
473 case Frontend::Forward: 471 case Frontend::Forward:
474 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { 472 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
475 odebug << "size " << size << " " << ints[i] << "" << oendl;
476 search[size] = ints[i]; 473 search[size] = ints[i];
477 size++; 474 size++;
478 } 475 }
479 break; 476 break;
480 /* reverse */ 477 /* reverse */
481 case Frontend::Reverse: 478 case Frontend::Reverse:
482 for (uint i = cur; i != 0 && size < CACHE; i-- ) { 479 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
483 search[size] = ints[i]; 480 search[size] = ints[i];
484 size++; 481 size++;
@@ -490,7 +487,7 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
490 FindQuery query( search ); 487 FindQuery query( search );
491 OSQLResult res = m_driver->query( &query ); 488 OSQLResult res = m_driver->query( &query );
492 if ( res.state() != OSQLResult::Success ) 489 if ( res.state() != OSQLResult::Success )
493 return to; 490 return OPimTodo();
494 491
495 return parseResultAndCache( uid, res ); 492 return parseResultAndCache( uid, res );
496} 493}
@@ -507,6 +504,7 @@ bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) {
507 504
508 if ( res.state() == OSQLResult::Failure ) 505 if ( res.state() == OSQLResult::Failure )
509 return false; 506 return false;
507
510 int c = m_uids.count(); 508 int c = m_uids.count();
511 m_uids.resize( c+1 ); 509 m_uids.resize( c+1 );
512 m_uids[c] = t.uid(); 510 m_uids[c] = t.uid();
@@ -534,16 +532,18 @@ bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) {
534 m_dirty = false; // we changed some stuff but the UID stayed the same 532 m_dirty = false; // we changed some stuff but the UID stayed the same
535 return b; 533 return b;
536} 534}
537QArray<int> OPimTodoAccessBackendSQL::overDue() { 535QArray<int> OPimTodoAccessBackendSQL::overDue()const {
538 OverDueQuery qu; 536 OverDueQuery qu;
539 return uids( m_driver->query(&qu ) ); 537 return uids( m_driver->query(&qu ) );
540} 538}
541QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, 539QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
542 const QDate& t, 540 const QDate& t,
543 bool u) { 541 bool u)const {
544 EffQuery ef(s, t, u ); 542 EffQuery ef(s, t, u );
545 return uids (m_driver->query(&ef) ); 543 return uids (m_driver->query(&ef) );
546} 544}
545
546#if 0
547/* 547/*
548 * 548 *
549 */ 549 */
@@ -560,13 +560,13 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
560 * 560 *
561 */ 561 */
562 /* Category */ 562 /* Category */
563 if ( sortFilter & 1 ) { 563 if ( sortFilter & OPimTodoAccess::FilterCategory ) {
564 QString str; 564 QString str;
565 if (cat != 0 ) str = QString::number( cat ); 565 if (cat != 0 ) str = QString::number( cat );
566 query += " categories like '%" +str+"%' AND"; 566 query += " categories like '%" +str+"%' AND";
567 } 567 }
568 /* Show only overdue */ 568 /* Show only overdue */
569 if ( sortFilter & 2 ) { 569 if ( sortFilter & OPimTodoAccess::OnlyOverDue ) {
570 QDate date = QDate::currentDate(); 570 QDate date = QDate::currentDate();
571 QString due; 571 QString due;
572 QString base; 572 QString base;
@@ -577,7 +577,7 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
577 query += " " + base + " AND"; 577 query += " " + base + " AND";
578 } 578 }
579 /* not show completed */ 579 /* not show completed */
580 if ( sortFilter & 4 ) { 580 if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) {
581 query += " completed = 0 AND"; 581 query += " completed = 0 AND";
582 }else{ 582 }else{
583 query += " ( completed = 1 OR completed = 0) AND"; 583 query += " ( completed = 1 OR completed = 0) AND";
@@ -593,29 +593,31 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
593 query += "ORDER BY "; 593 query += "ORDER BY ";
594 switch( sortOrder ) { 594 switch( sortOrder ) {
595 /* completed */ 595 /* completed */
596 case 0: 596 case OPimTodoAccess::Completed:
597 query += "completed"; 597 query += "completed";
598 break; 598 break;
599 case 1: 599 case OPimTodoAccess::Priority:
600 query += "priority"; 600 query += "priority";
601 break; 601 break;
602 case 2: 602 case OPimTodoAccess::SortSummary:
603 query += "summary"; 603 query += "summary";
604 break; 604 break;
605 case 3: 605 case OPimTodoAccess::Deadline:
606 query += "DueDate"; 606 query += "DueDate";
607 break; 607 break;
608 } 608 }
609 609
610 if ( !asc ) { 610 if ( !asc )
611 odebug << "not ascending!" << oendl;
612 query += " DESC"; 611 query += " DESC";
613 } 612
614 613
615 odebug << query << oendl; 614 odebug << query << oendl;
616 OSQLRawQuery raw(query ); 615 OSQLRawQuery raw(query );
617 return uids( m_driver->query(&raw) ); 616 return uids( m_driver->query(&raw) );
618} 617}
618#endif
619
620
619bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 621bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
620 if ( str == "0-0-0" ) 622 if ( str == "0-0-0" )
621 return false; 623 return false;
@@ -629,6 +631,8 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
629 return true; 631 return true;
630 } 632 }
631} 633}
634
635
632OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ 636OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{
633 if ( res.state() == OSQLResult::Failure ) { 637 if ( res.state() == OSQLResult::Failure ) {
634 OPimTodo to; 638 OPimTodo to;
@@ -639,22 +643,17 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul
639 643
640 OSQLResultItem::ValueList list = res.results(); 644 OSQLResultItem::ValueList list = res.results();
641 OSQLResultItem::ValueList::Iterator it = list.begin(); 645 OSQLResultItem::ValueList::Iterator it = list.begin();
642 odebug << "todo1" << oendl; 646 OPimTodo to, tmp;
643 OPimTodo to = todo( (*it) );
644 cache( to );
645 ++it;
646 647
647 for ( ; it != list.end(); ++it ) { 648 for ( ; it != list.end(); ++it ) {
648 odebug << "caching" << oendl; 649 OPimTodo newTodo = parse( (*it) );
649 OPimTodo newTodo = todo( (*it) );
650 cache( newTodo ); 650 cache( newTodo );
651 if ( newTodo.uid() == uid ) 651 if ( newTodo.uid() == uid )
652 retTodo = newTodo; 652 retTodo = newTodo;
653 } 653 }
654 return retTodo; 654 return retTodo;
655} 655}
656OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 656OPimTodo OPimTodoAccessBackendSQL::parse( OSQLResultItem& item )const {
657 odebug << "todo(ResultItem)" << oendl;
658 657
659 // Request information from addressbook table and create the OPimTodo-object. 658 // Request information from addressbook table and create the OPimTodo-object.
660 659
@@ -662,8 +661,6 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
662 hasDueDate = date( dueDate, item.data("DueDate") ); 661 hasDueDate = date( dueDate, item.data("DueDate") );
663 QStringList cats = QStringList::split(";", item.data("categories") ); 662 QStringList cats = QStringList::split(";", item.data("categories") );
664 663
665 odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl;
666
667 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 664 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
668 cats, item.data("summary"), item.data("description"), 665 cats, item.data("summary"), item.data("description"),
669 item.data("progress").toUShort(), hasDueDate, dueDate, 666 item.data("progress").toUShort(), hasDueDate, dueDate,
@@ -717,36 +714,8 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
717 FindQuery find( uid ); 714 FindQuery find( uid );
718 return parseResultAndCache( uid, m_driver->query(&find) ); 715 return parseResultAndCache( uid, m_driver->query(&find) );
719} 716}
720/*
721 * update the dict
722 */
723void OPimTodoAccessBackendSQL::fillDict() {
724 717
725#if 0
726 /* initialize dict */
727 /*
728 * UPDATE dict if you change anything!!!
729 * FIXME: Isn't this dict obsolete ? (eilers)
730 */
731 m_dict.setAutoDelete( TRUE );
732 m_dict.insert("Categories" , new int(OPimTodo::Category) );
733 m_dict.insert("Uid" , new int(OPimTodo::Uid) );
734 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) );
735 m_dict.insert("Completed" , new int(OPimTodo::Completed) );
736 m_dict.insert("Description" , new int(OPimTodo::Description) );
737 m_dict.insert("Summary" , new int(OPimTodo::Summary) );
738 m_dict.insert("Priority" , new int(OPimTodo::Priority) );
739 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) );
740 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) );
741 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) );
742 m_dict.insert("Progress" , new int(OPimTodo::Progress) );
743 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers)
744 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) );
745// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers)
746// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers)
747 718
748#endif
749}
750/* 719/*
751 * need to be const so let's fool the 720 * need to be const so let's fool the
752 * compiler :( 721 * compiler :(
@@ -765,7 +734,6 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
765 OSQLResultItem::ValueList list = res.results(); 734 OSQLResultItem::ValueList list = res.results();
766 OSQLResultItem::ValueList::Iterator it; 735 OSQLResultItem::ValueList::Iterator it;
767 QArray<int> ints(list.count() ); 736 QArray<int> ints(list.count() );
768 odebug << " count = " << list.count() << "" << oendl;
769 737
770 int i = 0; 738 int i = 0;
771 for (it = list.begin(); it != list.end(); ++it ) { 739 for (it = list.begin(); it != list.end(); ++it ) {
@@ -777,47 +745,18 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
777 745
778QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const 746QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
779{ 747{
780
781#if 0
782 QArray<int> empty;
783 return empty;
784
785#else
786 QString qu = "SELECT uid FROM todolist WHERE ("; 748 QString qu = "SELECT uid FROM todolist WHERE (";
787 749
788 // Do it make sense to search other fields, too ? 750 // Does it make sense to search other fields, too ?
789 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; 751 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR";
790 qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; 752 qu += " rlike(\""+ r.pattern() + "\",\"summary\")";
791 753
792 qu += ")"; 754 qu += ")";
793 755
794 odebug << "query: " << qu << "" << oendl;
795
796 OSQLRawQuery raw( qu ); 756 OSQLRawQuery raw( qu );
797 OSQLResult res = m_driver->query( &raw ); 757 OSQLResult res = m_driver->query( &raw );
798 758
799 return uids( res ); 759 return uids( res );
800
801
802#endif
803
804}
805QBitArray OPimTodoAccessBackendSQL::supports()const {
806
807 return sup();
808}
809
810QBitArray OPimTodoAccessBackendSQL::sup() const{
811
812 QBitArray ar( OPimTodo::CompletedDate + 1 );
813 ar.fill( true );
814 ar[OPimTodo::CrossReference] = false;
815 ar[OPimTodo::State ] = false;
816 ar[OPimTodo::Reminders] = false;
817 ar[OPimTodo::Notifiers] = false;
818 ar[OPimTodo::Maintainer] = false;
819
820 return ar;
821} 760}
822 761
823void OPimTodoAccessBackendSQL::removeAllCompleted(){ 762void OPimTodoAccessBackendSQL::removeAllCompleted(){
@@ -831,15 +770,13 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
831 770
832 QArray<int> completed_uids = uids( res ); 771 QArray<int> completed_uids = uids( res );
833 772
834 odebug << "Number of completed: " << completed_uids.size() << "" << oendl;
835
836 if ( completed_uids.size() == 0 ) 773 if ( completed_uids.size() == 0 )
837 return; 774 return;
838 775
839 qu = "DELETE FROM todolist WHERE ("; 776 qu = "DELETE FROM todolist WHERE (";
840 QString query; 777 QString query;
841 778
842 for ( int i = 0; i < completed_uids.size(); i++ ){ 779 for ( uint i = 0; i < completed_uids.size(); i++ ){
843 if ( !query.isEmpty() ) 780 if ( !query.isEmpty() )
844 query += " OR "; 781 query += " OR ";
845 query += QString( "uid = %1" ).arg( completed_uids[i] ); 782 query += QString( "uid = %1" ).arg( completed_uids[i] );
@@ -850,20 +787,19 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
850 qu += "DELETE FORM custom_data WHERE ("; 787 qu += "DELETE FORM custom_data WHERE (";
851 query = ""; 788 query = "";
852 789
853 for ( int i = 0; i < completed_uids.size(); i++ ){ 790 for ( uint i = 0; i < completed_uids.size(); i++ ){
854 if ( !query.isEmpty() ) 791 if ( !query.isEmpty() )
855 query += " OR "; 792 query += " OR ";
856 query += QString( "uid = %1" ).arg( completed_uids[i] ); 793 query += QString( "uid = %1" ).arg( completed_uids[i] );
857 } 794 }
858 qu += query + " );"; 795 qu += query + " );";
859 796
860 odebug << "query: " << qu << "" << oendl;
861
862 OSQLRawQuery raw2( qu ); 797 OSQLRawQuery raw2( qu );
863 res = m_driver->query( &raw2 ); 798 res = m_driver->query( &raw2 );
864 if ( res.state() == OSQLResult::Failure ) { 799
800 if ( res.state() == OSQLResult::Failure )
865 owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; 801 owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl;
866 } 802
867} 803}
868 804
869 805
@@ -876,15 +812,14 @@ QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
876 812
877 if ( res_custom.state() == OSQLResult::Failure ) { 813 if ( res_custom.state() == OSQLResult::Failure ) {
878 owarn << "OSQLResult::Failure in find query !!" << oendl; 814 owarn << "OSQLResult::Failure in find query !!" << oendl;
879 QMap<QString, QString> empty; 815 return QMap<QString, QString>();
880 return empty;
881 } 816 }
882 817
883 OSQLResultItem::ValueList list = res_custom.results(); 818 OSQLResultItem::ValueList list = res_custom.results();
884 OSQLResultItem::ValueList::Iterator it = list.begin(); 819 OSQLResultItem::ValueList::Iterator it = list.begin();
885 for ( ; it != list.end(); ++it ) { 820 for ( ; it != list.end(); ++it )
886 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 821 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
887 } 822
888 823
889 return customMap; 824 return customMap;
890} 825}