Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 12a8bea..4e3e47b 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -433,88 +433,87 @@ bool OPimTodoAccessBackendSQL::load(){ | |||
433 | OSQLResult res = m_driver->query(&creat ); | 433 | OSQLResult res = m_driver->query(&creat ); |
434 | 434 | ||
435 | m_dirty = true; | 435 | m_dirty = true; |
436 | return true; | 436 | return true; |
437 | } | 437 | } |
438 | bool OPimTodoAccessBackendSQL::reload(){ | 438 | bool OPimTodoAccessBackendSQL::reload(){ |
439 | return load(); | 439 | return load(); |
440 | } | 440 | } |
441 | 441 | ||
442 | bool OPimTodoAccessBackendSQL::save(){ | 442 | bool OPimTodoAccessBackendSQL::save(){ |
443 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 443 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
444 | } | 444 | } |
445 | QArray<int> OPimTodoAccessBackendSQL::allRecords()const { | 445 | 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 todo( m_driver->query(&query) ); | 457 | return parseResultAndCache( uid, m_driver->query(&query) ); |
458 | 458 | ||
459 | } | 459 | } |
460 | 460 | ||
461 | // Remember: uid is already in the list of uids, called ints ! | 461 | // Remember: uid is already in the list of uids, called ints ! |
462 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 462 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
463 | uint cur, Frontend::CacheDirection dir ) const{ | 463 | uint cur, Frontend::CacheDirection dir ) const{ |
464 | uint CACHE = readAhead(); | 464 | uint CACHE = readAhead(); |
465 | odebug << "searching for " << uid << "" << oendl; | 465 | odebug << "searching for " << uid << "" << oendl; |
466 | QArray<int> search( CACHE ); | 466 | QArray<int> search( CACHE ); |
467 | uint size =0; | 467 | uint size =0; |
468 | OPimTodo to; | 468 | OPimTodo to; |
469 | 469 | ||
470 | // we try to cache CACHE items | 470 | // we try to cache CACHE items |
471 | switch( dir ) { | 471 | switch( dir ) { |
472 | /* forward */ | 472 | /* forward */ |
473 | case Frontend::Forward: | 473 | case Frontend::Forward: |
474 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 474 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
475 | odebug << "size " << size << " " << ints[i] << "" << oendl; | 475 | odebug << "size " << size << " " << ints[i] << "" << oendl; |
476 | search[size] = ints[i]; | 476 | search[size] = ints[i]; |
477 | size++; | 477 | size++; |
478 | } | 478 | } |
479 | break; | 479 | break; |
480 | /* reverse */ | 480 | /* reverse */ |
481 | case Frontend::Reverse: | 481 | case Frontend::Reverse: |
482 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { | 482 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { |
483 | search[size] = ints[i]; | 483 | search[size] = ints[i]; |
484 | size++; | 484 | size++; |
485 | } | 485 | } |
486 | break; | 486 | break; |
487 | } | 487 | } |
488 | 488 | ||
489 | search.resize( size ); | 489 | search.resize( size ); |
490 | FindQuery query( search ); | 490 | FindQuery query( search ); |
491 | OSQLResult res = m_driver->query( &query ); | 491 | OSQLResult res = m_driver->query( &query ); |
492 | if ( res.state() != OSQLResult::Success ) | 492 | if ( res.state() != OSQLResult::Success ) |
493 | return to; | 493 | return to; |
494 | 494 | ||
495 | todo( res ); //FIXME: Don't like polymorphism here. It makes the code hard to read here..(eilers) | 495 | return parseResultAndCache( uid, res ); |
496 | return cacheFind( uid ); | ||
497 | } | 496 | } |
498 | 497 | ||
499 | void OPimTodoAccessBackendSQL::clear() { | 498 | void OPimTodoAccessBackendSQL::clear() { |
500 | ClearQuery cle; | 499 | ClearQuery cle; |
501 | OSQLResult res = m_driver->query( &cle ); | 500 | OSQLResult res = m_driver->query( &cle ); |
502 | CreateQuery qu; | 501 | CreateQuery qu; |
503 | res = m_driver->query(&qu); | 502 | res = m_driver->query(&qu); |
504 | } | 503 | } |
505 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { | 504 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { |
506 | InsertQuery ins( t ); | 505 | InsertQuery ins( t ); |
507 | OSQLResult res = m_driver->query( &ins ); | 506 | OSQLResult res = m_driver->query( &ins ); |
508 | 507 | ||
509 | if ( res.state() == OSQLResult::Failure ) | 508 | if ( res.state() == OSQLResult::Failure ) |
510 | return false; | 509 | return false; |
511 | int c = m_uids.count(); | 510 | int c = m_uids.count(); |
512 | m_uids.resize( c+1 ); | 511 | m_uids.resize( c+1 ); |
513 | m_uids[c] = t.uid(); | 512 | m_uids[c] = t.uid(); |
514 | 513 | ||
515 | return true; | 514 | return true; |
516 | } | 515 | } |
517 | bool OPimTodoAccessBackendSQL::remove( int uid ) { | 516 | bool OPimTodoAccessBackendSQL::remove( int uid ) { |
518 | RemoveQuery rem( uid ); | 517 | RemoveQuery rem( uid ); |
519 | OSQLResult res = m_driver->query(&rem ); | 518 | OSQLResult res = m_driver->query(&rem ); |
520 | 519 | ||
@@ -609,66 +608,71 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
609 | } | 608 | } |
610 | 609 | ||
611 | if ( !asc ) { | 610 | if ( !asc ) { |
612 | odebug << "not ascending!" << oendl; | 611 | odebug << "not ascending!" << oendl; |
613 | query += " DESC"; | 612 | query += " DESC"; |
614 | } | 613 | } |
615 | 614 | ||
616 | odebug << query << oendl; | 615 | odebug << query << oendl; |
617 | OSQLRawQuery raw(query ); | 616 | OSQLRawQuery raw(query ); |
618 | return uids( m_driver->query(&raw) ); | 617 | return uids( m_driver->query(&raw) ); |
619 | } | 618 | } |
620 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 619 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
621 | if ( str == "0-0-0" ) | 620 | if ( str == "0-0-0" ) |
622 | return false; | 621 | return false; |
623 | else{ | 622 | else{ |
624 | int day, year, month; | 623 | int day, year, month; |
625 | QStringList list = QStringList::split("-", str ); | 624 | QStringList list = QStringList::split("-", str ); |
626 | year = list[0].toInt(); | 625 | year = list[0].toInt(); |
627 | month = list[1].toInt(); | 626 | month = list[1].toInt(); |
628 | day = list[2].toInt(); | 627 | day = list[2].toInt(); |
629 | da.setYMD( year, month, day ); | 628 | da.setYMD( year, month, day ); |
630 | return true; | 629 | return true; |
631 | } | 630 | } |
632 | } | 631 | } |
633 | OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ | 632 | OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ |
634 | if ( res.state() == OSQLResult::Failure ) { | 633 | if ( res.state() == OSQLResult::Failure ) { |
635 | OPimTodo to; | 634 | OPimTodo to; |
636 | return to; | 635 | return to; |
637 | } | 636 | } |
638 | 637 | ||
638 | OPimTodo retTodo; | ||
639 | |||
639 | OSQLResultItem::ValueList list = res.results(); | 640 | OSQLResultItem::ValueList list = res.results(); |
640 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 641 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
641 | odebug << "todo1" << oendl; | 642 | odebug << "todo1" << oendl; |
642 | OPimTodo to = todo( (*it) ); | 643 | OPimTodo to = todo( (*it) ); |
643 | cache( to ); | 644 | cache( to ); |
644 | ++it; | 645 | ++it; |
645 | 646 | ||
646 | for ( ; it != list.end(); ++it ) { | 647 | for ( ; it != list.end(); ++it ) { |
647 | odebug << "caching" << oendl; | 648 | odebug << "caching" << oendl; |
648 | cache( todo( (*it) ) ); | 649 | OPimTodo newTodo = todo( (*it) ); |
650 | cache( newTodo ); | ||
651 | if ( newTodo.uid() == uid ) | ||
652 | retTodo = newTodo; | ||
649 | } | 653 | } |
650 | return to; | 654 | return retTodo; |
651 | } | 655 | } |
652 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 656 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
653 | odebug << "todo(ResultItem)" << oendl; | 657 | odebug << "todo(ResultItem)" << oendl; |
654 | 658 | ||
655 | // Request information from addressbook table and create the OPimTodo-object. | 659 | // Request information from addressbook table and create the OPimTodo-object. |
656 | 660 | ||
657 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); | 661 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
658 | hasDueDate = date( dueDate, item.data("DueDate") ); | 662 | hasDueDate = date( dueDate, item.data("DueDate") ); |
659 | QStringList cats = QStringList::split(";", item.data("categories") ); | 663 | QStringList cats = QStringList::split(";", item.data("categories") ); |
660 | 664 | ||
661 | odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl; | 665 | odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl; |
662 | 666 | ||
663 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 667 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
664 | cats, item.data("summary"), item.data("description"), | 668 | cats, item.data("summary"), item.data("description"), |
665 | item.data("progress").toUShort(), hasDueDate, dueDate, | 669 | item.data("progress").toUShort(), hasDueDate, dueDate, |
666 | item.data("uid").toInt() ); | 670 | item.data("uid").toInt() ); |
667 | 671 | ||
668 | bool isOk; | 672 | bool isOk; |
669 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); | 673 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); |
670 | if ( isOk ) | 674 | if ( isOk ) |
671 | to.setPriority( prioInt ); | 675 | to.setPriority( prioInt ); |
672 | 676 | ||
673 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); | 677 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); |
674 | hasStartDate = date( startDate, item.data("startdate") ); | 678 | hasStartDate = date( startDate, item.data("startdate") ); |
@@ -686,51 +690,53 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
686 | 690 | ||
687 | OPimState pimState; | 691 | OPimState pimState; |
688 | pimState.setState( QString( item.data("state") ).toInt() ); | 692 | pimState.setState( QString( item.data("state") ).toInt() ); |
689 | to.setState( pimState ); | 693 | to.setState( pimState ); |
690 | 694 | ||
691 | QMap<int, QString> recMap; | 695 | QMap<int, QString> recMap; |
692 | recMap.insert( OPimRecurrence::RType , item.data("RType") ); | 696 | recMap.insert( OPimRecurrence::RType , item.data("RType") ); |
693 | recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); | 697 | recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); |
694 | recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); | 698 | recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); |
695 | recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); | 699 | recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); |
696 | recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); | 700 | recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); |
697 | recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); | 701 | recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); |
698 | recMap.insert( OPimRecurrence::Created , item.data("Created") ); | 702 | recMap.insert( OPimRecurrence::Created , item.data("Created") ); |
699 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); | 703 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); |
700 | 704 | ||
701 | OPimRecurrence recur; | 705 | OPimRecurrence recur; |
702 | recur.fromMap( recMap ); | 706 | recur.fromMap( recMap ); |
703 | to.setRecurrence( recur ); | 707 | to.setRecurrence( recur ); |
704 | 708 | ||
705 | // Finally load the custom-entries for this UID and put it into the created object | 709 | // Finally load the custom-entries for this UID and put it into the created object |
706 | to.setExtraMap( requestCustom( to.uid() ) ); | 710 | to.setExtraMap( requestCustom( to.uid() ) ); |
707 | 711 | ||
708 | return to; | 712 | return to; |
709 | } | 713 | } |
714 | |||
715 | // FIXME: Where is the difference to "find" ? (eilers) | ||
710 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { | 716 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { |
711 | FindQuery find( uid ); | 717 | FindQuery find( uid ); |
712 | return todo( m_driver->query(&find) ); | 718 | return parseResultAndCache( uid, m_driver->query(&find) ); |
713 | } | 719 | } |
714 | /* | 720 | /* |
715 | * update the dict | 721 | * update the dict |
716 | */ | 722 | */ |
717 | void OPimTodoAccessBackendSQL::fillDict() { | 723 | void OPimTodoAccessBackendSQL::fillDict() { |
718 | 724 | ||
719 | #if 0 | 725 | #if 0 |
720 | /* initialize dict */ | 726 | /* initialize dict */ |
721 | /* | 727 | /* |
722 | * UPDATE dict if you change anything!!! | 728 | * UPDATE dict if you change anything!!! |
723 | * FIXME: Isn't this dict obsolete ? (eilers) | 729 | * FIXME: Isn't this dict obsolete ? (eilers) |
724 | */ | 730 | */ |
725 | m_dict.setAutoDelete( TRUE ); | 731 | m_dict.setAutoDelete( TRUE ); |
726 | m_dict.insert("Categories" , new int(OPimTodo::Category) ); | 732 | m_dict.insert("Categories" , new int(OPimTodo::Category) ); |
727 | m_dict.insert("Uid" , new int(OPimTodo::Uid) ); | 733 | m_dict.insert("Uid" , new int(OPimTodo::Uid) ); |
728 | m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); | 734 | m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); |
729 | m_dict.insert("Completed" , new int(OPimTodo::Completed) ); | 735 | m_dict.insert("Completed" , new int(OPimTodo::Completed) ); |
730 | m_dict.insert("Description" , new int(OPimTodo::Description) ); | 736 | m_dict.insert("Description" , new int(OPimTodo::Description) ); |
731 | m_dict.insert("Summary" , new int(OPimTodo::Summary) ); | 737 | m_dict.insert("Summary" , new int(OPimTodo::Summary) ); |
732 | m_dict.insert("Priority" , new int(OPimTodo::Priority) ); | 738 | m_dict.insert("Priority" , new int(OPimTodo::Priority) ); |
733 | m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); | 739 | m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); |
734 | m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); | 740 | m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); |
735 | m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); | 741 | m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); |
736 | m_dict.insert("Progress" , new int(OPimTodo::Progress) ); | 742 | m_dict.insert("Progress" , new int(OPimTodo::Progress) ); |