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 | |||
@@ -445,25 +445,25 @@ bool OPimTodoAccessBackendSQL::save(){ | |||
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 | ||
@@ -483,26 +483,25 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | |||
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 | ||
@@ -621,42 +620,47 @@ 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 | ||
@@ -698,27 +702,29 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
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 | */ |