Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 135 |
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 | |||
@@ -446,76 +446,74 @@ QArray<int> OPimTodoAccessBackendSQL::allRecords()const { | |||
446 | if (m_dirty ) | 446 | if (m_dirty ) |
447 | update(); | 447 | update(); |
448 | 448 | ||
449 | return m_uids; | 449 | return m_uids; |
450 | } | 450 | } |
451 | QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ | 451 | QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ |
452 | QArray<int> ints(0); | 452 | QArray<int> ints(0); |
453 | return ints; | 453 | return ints; |
454 | } | 454 | } |
455 | OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ | 455 | OPimTodo 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 ! |
462 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 461 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
463 | uint cur, Frontend::CacheDirection dir ) const{ | 462 | uint cur, Frontend::CacheDirection dir ) const{ |
464 | uint CACHE = readAhead(); | 463 | uint CACHE = readAhead(); |
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++; |
485 | } | 482 | } |
486 | break; | 483 | break; |
487 | } | 484 | } |
488 | 485 | ||
489 | search.resize( size ); | 486 | search.resize( size ); |
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 | } |
497 | 494 | ||
498 | void OPimTodoAccessBackendSQL::clear() { | 495 | void OPimTodoAccessBackendSQL::clear() { |
499 | ClearQuery cle; | 496 | ClearQuery cle; |
500 | OSQLResult res = m_driver->query( &cle ); | 497 | OSQLResult res = m_driver->query( &cle ); |
501 | CreateQuery qu; | 498 | CreateQuery qu; |
502 | res = m_driver->query(&qu); | 499 | res = m_driver->query(&qu); |
503 | } | 500 | } |
504 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { | 501 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { |
505 | InsertQuery ins( t ); | 502 | InsertQuery ins( t ); |
506 | OSQLResult res = m_driver->query( &ins ); | 503 | OSQLResult res = m_driver->query( &ins ); |
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(); |
513 | 511 | ||
514 | return true; | 512 | return true; |
515 | } | 513 | } |
516 | bool OPimTodoAccessBackendSQL::remove( int uid ) { | 514 | bool OPimTodoAccessBackendSQL::remove( int uid ) { |
517 | RemoveQuery rem( uid ); | 515 | RemoveQuery rem( uid ); |
518 | OSQLResult res = m_driver->query(&rem ); | 516 | OSQLResult res = m_driver->query(&rem ); |
519 | 517 | ||
520 | if ( res.state() == OSQLResult::Failure ) | 518 | if ( res.state() == OSQLResult::Failure ) |
521 | return false; | 519 | return false; |
@@ -525,154 +523,153 @@ bool OPimTodoAccessBackendSQL::remove( int uid ) { | |||
525 | } | 523 | } |
526 | /* | 524 | /* |
527 | * FIXME better set query | 525 | * FIXME better set query |
528 | * but we need the cache for that | 526 | * but we need the cache for that |
529 | * now we remove | 527 | * now we remove |
530 | */ | 528 | */ |
531 | bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { | 529 | bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { |
532 | remove( t.uid() ); | 530 | remove( t.uid() ); |
533 | bool b= add(t); | 531 | bool b= add(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 | } |
537 | QArray<int> OPimTodoAccessBackendSQL::overDue() { | 535 | QArray<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 | } |
541 | QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 539 | QArray<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 | */ |
550 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 550 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
551 | int sortFilter, int cat ) { | 551 | int sortFilter, int cat ) { |
552 | odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; | 552 | odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; |
553 | QString query; | 553 | QString query; |
554 | query = "select uid from todolist WHERE "; | 554 | query = "select uid from todolist WHERE "; |
555 | 555 | ||
556 | /* | 556 | /* |
557 | * Sort Filter stuff | 557 | * Sort Filter stuff |
558 | * not that straight forward | 558 | * not that straight forward |
559 | * FIXME: Replace magic numbers | 559 | * FIXME: Replace magic numbers |
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; |
573 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0") | 573 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0") |
574 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) | 574 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) |
575 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) | 575 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) |
576 | .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); | 576 | .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); |
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"; |
584 | } | 584 | } |
585 | /* strip the end */ | 585 | /* strip the end */ |
586 | query = query.remove( query.length()-3, 3 ); | 586 | query = query.remove( query.length()-3, 3 ); |
587 | 587 | ||
588 | 588 | ||
589 | /* | 589 | /* |
590 | * sort order stuff | 590 | * sort order stuff |
591 | * quite straight forward | 591 | * quite straight forward |
592 | */ | 592 | */ |
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 | |||
619 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 621 | bool 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; |
622 | else{ | 624 | else{ |
623 | int day, year, month; | 625 | int day, year, month; |
624 | QStringList list = QStringList::split("-", str ); | 626 | QStringList list = QStringList::split("-", str ); |
625 | year = list[0].toInt(); | 627 | year = list[0].toInt(); |
626 | month = list[1].toInt(); | 628 | month = list[1].toInt(); |
627 | day = list[2].toInt(); | 629 | day = list[2].toInt(); |
628 | da.setYMD( year, month, day ); | 630 | da.setYMD( year, month, day ); |
629 | return true; | 631 | return true; |
630 | } | 632 | } |
631 | } | 633 | } |
634 | |||
635 | |||
632 | OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ | 636 | OPimTodo 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; |
635 | return to; | 639 | return to; |
636 | } | 640 | } |
637 | 641 | ||
638 | OPimTodo retTodo; | 642 | OPimTodo retTodo; |
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 | } |
656 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 656 | OPimTodo 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 | ||
661 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); | 660 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
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, |
670 | item.data("uid").toInt() ); | 667 | item.data("uid").toInt() ); |
671 | 668 | ||
672 | bool isOk; | 669 | bool isOk; |
673 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); | 670 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); |
674 | if ( isOk ) | 671 | if ( isOk ) |
675 | to.setPriority( prioInt ); | 672 | to.setPriority( prioInt ); |
676 | 673 | ||
677 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); | 674 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); |
678 | hasStartDate = date( startDate, item.data("startdate") ); | 675 | hasStartDate = date( startDate, item.data("startdate") ); |
@@ -708,188 +705,126 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
708 | 705 | ||
709 | // Finally load the custom-entries for this UID and put it into the created object | 706 | // Finally load the custom-entries for this UID and put it into the created object |
710 | to.setExtraMap( requestCustom( to.uid() ) ); | 707 | to.setExtraMap( requestCustom( to.uid() ) ); |
711 | 708 | ||
712 | return to; | 709 | return to; |
713 | } | 710 | } |
714 | 711 | ||
715 | // FIXME: Where is the difference to "find" ? (eilers) | 712 | // FIXME: Where is the difference to "find" ? (eilers) |
716 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { | 713 | 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 | */ | ||
723 | void 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 :( |
753 | */ | 722 | */ |
754 | void OPimTodoAccessBackendSQL::update()const { | 723 | void OPimTodoAccessBackendSQL::update()const { |
755 | ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; | 724 | ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; |
756 | LoadQuery lo; | 725 | LoadQuery lo; |
757 | OSQLResult res = m_driver->query(&lo); | 726 | OSQLResult res = m_driver->query(&lo); |
758 | if ( res.state() != OSQLResult::Success ) | 727 | if ( res.state() != OSQLResult::Success ) |
759 | return; | 728 | return; |
760 | 729 | ||
761 | ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); | 730 | ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
762 | } | 731 | } |
763 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 732 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
764 | 733 | ||
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 ) { |
772 | ints[i] = (*it).data("uid").toInt(); | 740 | ints[i] = (*it).data("uid").toInt(); |
773 | i++; | 741 | i++; |
774 | } | 742 | } |
775 | return ints; | 743 | return ints; |
776 | } | 744 | } |
777 | 745 | ||
778 | QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | 746 | QArray<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 | } | ||
805 | QBitArray OPimTodoAccessBackendSQL::supports()const { | ||
806 | |||
807 | return sup(); | ||
808 | } | ||
809 | |||
810 | QBitArray 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 | ||
823 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ | 762 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ |
824 | // First we need the uids from all entries which are | 763 | // First we need the uids from all entries which are |
825 | // completed. Then, we just have to remove them... | 764 | // completed. Then, we just have to remove them... |
826 | 765 | ||
827 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; | 766 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; |
828 | 767 | ||
829 | OSQLRawQuery raw( qu ); | 768 | OSQLRawQuery raw( qu ); |
830 | OSQLResult res = m_driver->query( &raw ); | 769 | OSQLResult res = m_driver->query( &raw ); |
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] ); |
846 | } | 783 | } |
847 | qu += query + " );"; | 784 | qu += query + " );"; |
848 | 785 | ||
849 | // Put remove of custom entries in this query to speed up.. | 786 | // Put remove of custom entries in this query to speed up.. |
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 | ||
870 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const | 806 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const |
871 | { | 807 | { |
872 | QMap<QString, QString> customMap; | 808 | QMap<QString, QString> customMap; |
873 | 809 | ||
874 | FindCustomQuery query( uid ); | 810 | FindCustomQuery query( uid ); |
875 | OSQLResult res_custom = m_driver->query( &query ); | 811 | OSQLResult res_custom = m_driver->query( &query ); |
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 | } |
891 | 826 | ||
892 | 827 | ||
893 | 828 | ||
894 | 829 | ||
895 | } | 830 | } |