-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 @@ -396,162 +396,167 @@ namespace { FindCustomQuery::~FindCustomQuery() { } QString FindCustomQuery::query()const{ return single(); // Multiple requests not supported ! } QString FindCustomQuery::single()const{ QString qu = "select uid, type, value from custom_data where uid = "; qu += QString::number(m_uid); return qu; } }; namespace Opie { OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) { QString fi = file; if ( fi.isEmpty() ) fi = Global::applicationFileName( "todolist", "todolist.db" ); OSQLManager man; m_driver = man.standard(); m_driver->setUrl(fi); // fillDict(); } OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ if( m_driver ) delete m_driver; } bool OPimTodoAccessBackendSQL::load(){ if (!m_driver->open() ) return false; CreateQuery creat; OSQLResult res = m_driver->query(&creat ); m_dirty = true; return true; } bool OPimTodoAccessBackendSQL::reload(){ return load(); } bool OPimTodoAccessBackendSQL::save(){ return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) } QArray<int> OPimTodoAccessBackendSQL::allRecords()const { if (m_dirty ) update(); return m_uids; } QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ QArray<int> ints(0); return ints; } OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ FindQuery query( uid ); return todo( m_driver->query(&query) ); } + +// Remember: uid is already in the list of uids, called ints ! OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, uint cur, Frontend::CacheDirection dir ) const{ uint CACHE = readAhead(); odebug << "searching for " << uid << "" << oendl; QArray<int> search( CACHE ); uint size =0; OPimTodo to; // we try to cache CACHE items switch( dir ) { /* forward */ - case 0: // FIXME: Not a good style to use magic numbers here (eilers) + case Frontend::Forward: for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { odebug << "size " << size << " " << ints[i] << "" << oendl; search[size] = ints[i]; size++; } break; /* reverse */ - case 1: // FIXME: Not a good style to use magic numbers here (eilers) + case Frontend::Reverse: for (uint i = cur; i != 0 && size < CACHE; i-- ) { search[size] = ints[i]; size++; } break; } + search.resize( size ); FindQuery query( search ); OSQLResult res = m_driver->query( &query ); if ( res.state() != OSQLResult::Success ) return to; - return todo( res ); + todo( res ); //FIXME: Don't like polymorphism here. It makes the code hard to read here..(eilers) + return cacheFind( uid ); } + void OPimTodoAccessBackendSQL::clear() { ClearQuery cle; OSQLResult res = m_driver->query( &cle ); CreateQuery qu; res = m_driver->query(&qu); } bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { InsertQuery ins( t ); OSQLResult res = m_driver->query( &ins ); if ( res.state() == OSQLResult::Failure ) return false; int c = m_uids.count(); m_uids.resize( c+1 ); m_uids[c] = t.uid(); return true; } bool OPimTodoAccessBackendSQL::remove( int uid ) { RemoveQuery rem( uid ); OSQLResult res = m_driver->query(&rem ); if ( res.state() == OSQLResult::Failure ) return false; m_dirty = true; return true; } /* * FIXME better set query * but we need the cache for that * now we remove */ bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { remove( t.uid() ); bool b= add(t); m_dirty = false; // we changed some stuff but the UID stayed the same return b; } QArray<int> OPimTodoAccessBackendSQL::overDue() { OverDueQuery qu; return uids( m_driver->query(&qu ) ); } QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, const QDate& t, bool u) { EffQuery ef(s, t, u ); return uids (m_driver->query(&ef) ); } /* * */ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; QString query; query = "select uid from todolist WHERE "; /* * Sort Filter stuff * not that straight forward * FIXME: Replace magic numbers * */ |