-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 6f65c48..12a8bea 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -436,82 +436,87 @@ bool OPimTodoAccessBackendSQL::load(){ | |||
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 todo( m_driver->query(&query) ); |
458 | 458 | ||
459 | } | 459 | } |
460 | |||
461 | // Remember: uid is already in the list of uids, called ints ! | ||
460 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 462 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
461 | uint cur, Frontend::CacheDirection dir ) const{ | 463 | uint cur, Frontend::CacheDirection dir ) const{ |
462 | uint CACHE = readAhead(); | 464 | uint CACHE = readAhead(); |
463 | odebug << "searching for " << uid << "" << oendl; | 465 | odebug << "searching for " << uid << "" << oendl; |
464 | QArray<int> search( CACHE ); | 466 | QArray<int> search( CACHE ); |
465 | uint size =0; | 467 | uint size =0; |
466 | OPimTodo to; | 468 | OPimTodo to; |
467 | 469 | ||
468 | // we try to cache CACHE items | 470 | // we try to cache CACHE items |
469 | switch( dir ) { | 471 | switch( dir ) { |
470 | /* forward */ | 472 | /* forward */ |
471 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) | 473 | case Frontend::Forward: |
472 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 474 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
473 | odebug << "size " << size << " " << ints[i] << "" << oendl; | 475 | odebug << "size " << size << " " << ints[i] << "" << oendl; |
474 | search[size] = ints[i]; | 476 | search[size] = ints[i]; |
475 | size++; | 477 | size++; |
476 | } | 478 | } |
477 | break; | 479 | break; |
478 | /* reverse */ | 480 | /* reverse */ |
479 | case 1: // FIXME: Not a good style to use magic numbers here (eilers) | 481 | case Frontend::Reverse: |
480 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { | 482 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { |
481 | search[size] = ints[i]; | 483 | search[size] = ints[i]; |
482 | size++; | 484 | size++; |
483 | } | 485 | } |
484 | break; | 486 | break; |
485 | } | 487 | } |
488 | |||
486 | search.resize( size ); | 489 | search.resize( size ); |
487 | FindQuery query( search ); | 490 | FindQuery query( search ); |
488 | OSQLResult res = m_driver->query( &query ); | 491 | OSQLResult res = m_driver->query( &query ); |
489 | if ( res.state() != OSQLResult::Success ) | 492 | if ( res.state() != OSQLResult::Success ) |
490 | return to; | 493 | return to; |
491 | 494 | ||
492 | return todo( res ); | 495 | todo( res ); //FIXME: Don't like polymorphism here. It makes the code hard to read here..(eilers) |
496 | return cacheFind( uid ); | ||
493 | } | 497 | } |
498 | |||
494 | void OPimTodoAccessBackendSQL::clear() { | 499 | void OPimTodoAccessBackendSQL::clear() { |
495 | ClearQuery cle; | 500 | ClearQuery cle; |
496 | OSQLResult res = m_driver->query( &cle ); | 501 | OSQLResult res = m_driver->query( &cle ); |
497 | CreateQuery qu; | 502 | CreateQuery qu; |
498 | res = m_driver->query(&qu); | 503 | res = m_driver->query(&qu); |
499 | } | 504 | } |
500 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { | 505 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { |
501 | InsertQuery ins( t ); | 506 | InsertQuery ins( t ); |
502 | OSQLResult res = m_driver->query( &ins ); | 507 | OSQLResult res = m_driver->query( &ins ); |
503 | 508 | ||
504 | if ( res.state() == OSQLResult::Failure ) | 509 | if ( res.state() == OSQLResult::Failure ) |
505 | return false; | 510 | return false; |
506 | int c = m_uids.count(); | 511 | int c = m_uids.count(); |
507 | m_uids.resize( c+1 ); | 512 | m_uids.resize( c+1 ); |
508 | m_uids[c] = t.uid(); | 513 | m_uids[c] = t.uid(); |
509 | 514 | ||
510 | return true; | 515 | return true; |
511 | } | 516 | } |
512 | bool OPimTodoAccessBackendSQL::remove( int uid ) { | 517 | bool OPimTodoAccessBackendSQL::remove( int uid ) { |
513 | RemoveQuery rem( uid ); | 518 | RemoveQuery rem( uid ); |
514 | OSQLResult res = m_driver->query(&rem ); | 519 | OSQLResult res = m_driver->query(&rem ); |
515 | 520 | ||
516 | if ( res.state() == OSQLResult::Failure ) | 521 | if ( res.state() == OSQLResult::Failure ) |
517 | return false; | 522 | return false; |