author | zecke <zecke> | 2002-10-13 02:22:58 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-13 02:22:58 (UTC) |
commit | d96ce086c617b5b2efc5081cd10a43257a78f488 (patch) (unidiff) | |
tree | 4f6b80b7295127bd82cc5fb8ffd1d532c42a396b | |
parent | 2ce86d9be1bbf99092348adf815578b110fe7289 (diff) | |
download | opie-d96ce086c617b5b2efc5081cd10a43257a78f488.zip opie-d96ce086c617b5b2efc5081cd10a43257a78f488.tar.gz opie-d96ce086c617b5b2efc5081cd10a43257a78f488.tar.bz2 |
OPimAccessBackend nothing tried a isDirty()const ... but removed it
ORecordList uidAt(uint index ) added
Speed Improvements at the SQL backend
do not load the list of uids until it's really needed
do not reload the uid list until it's really needed
we got a bitfield m_dirty there...
-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 2 | ||||
-rw-r--r-- | libopie/pim/orecordlist.h | 5 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 31 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 31 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 5 |
8 files changed, 58 insertions, 24 deletions
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index 92d7192..a0d8f63 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h | |||
@@ -179,22 +179,20 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | |||
179 | uint current, CacheDirection dir )const { | 179 | uint current, CacheDirection dir )const { |
180 | /* | 180 | /* |
181 | * better do T.isEmpty() | 181 | * better do T.isEmpty() |
182 | * after a find this way we would | 182 | * after a find this way we would |
183 | * avoid two finds in QCache... | 183 | * avoid two finds in QCache... |
184 | */ | 184 | */ |
185 | // qWarning("find it now %d", uid ); | 185 | // qWarning("find it now %d", uid ); |
186 | if (m_cache.contains( uid ) ) { | 186 | if (m_cache.contains( uid ) ) { |
187 | qWarning("m cache contains %d", uid); | ||
188 | return m_cache.find( uid ); | 187 | return m_cache.find( uid ); |
189 | } | 188 | } |
190 | 189 | ||
191 | T t = m_backEnd->find( uid, ar, current, dir ); | 190 | T t = m_backEnd->find( uid, ar, current, dir ); |
192 | qWarning("found it and cache it now %d", uid); | ||
193 | cache( t ); | 191 | cache( t ); |
194 | return t; | 192 | return t; |
195 | } | 193 | } |
196 | template <class T> | 194 | template <class T> |
197 | void OPimAccessTemplate<T>::clear() { | 195 | void OPimAccessTemplate<T>::clear() { |
198 | invalidateCache(); | 196 | invalidateCache(); |
199 | m_backEnd->clear(); | 197 | m_backEnd->clear(); |
200 | } | 198 | } |
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index 08f5c85..5404910 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h | |||
@@ -104,16 +104,17 @@ public: | |||
104 | Iterator end(); | 104 | Iterator end(); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * the number of items in the list | 107 | * the number of items in the list |
108 | */ | 108 | */ |
109 | uint count()const; | 109 | uint count()const; |
110 | 110 | ||
111 | T operator[]( uint i ); | 111 | T operator[]( uint i ); |
112 | int uidAt(uint i ); | ||
112 | // FIXME implemenent remove | 113 | // FIXME implemenent remove |
113 | /* | 114 | /* |
114 | ConstIterator begin()const; | 115 | ConstIterator begin()const; |
115 | ConstIterator end()const; | 116 | ConstIterator end()const; |
116 | */ | 117 | */ |
117 | private: | 118 | private: |
118 | QArray<int> m_ids; | 119 | QArray<int> m_ids; |
119 | const Base* m_acc; | 120 | const Base* m_acc; |
@@ -257,9 +258,13 @@ template <class T> | |||
257 | uint ORecordList<T>::count()const { | 258 | uint ORecordList<T>::count()const { |
258 | return m_ids.count(); | 259 | return m_ids.count(); |
259 | } | 260 | } |
260 | template <class T> | 261 | template <class T> |
261 | T ORecordList<T>::operator[]( uint i ) { | 262 | T ORecordList<T>::operator[]( uint i ) { |
262 | /* forward */ | 263 | /* forward */ |
263 | return m_acc->find( m_ids[i], m_ids, i ); | 264 | return m_acc->find( m_ids[i], m_ids, i ); |
264 | } | 265 | } |
266 | template <class T> | ||
267 | int ORecordList<T>::uidAt( uint i ) { | ||
268 | return m_ids[i]; | ||
269 | } | ||
265 | #endif | 270 | #endif |
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index a059dab..ea8b3c9 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -236,17 +236,17 @@ namespace { | |||
236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) | 236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) |
237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); | 237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); |
238 | 238 | ||
239 | return str; | 239 | return str; |
240 | } | 240 | } |
241 | }; | 241 | }; |
242 | 242 | ||
243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
244 | : OTodoAccessBackend(), m_dict(15) | 244 | : OTodoAccessBackend(), m_dict(15), m_dirty(true) |
245 | { | 245 | { |
246 | QString fi = file; | 246 | QString fi = file; |
247 | if ( fi.isEmpty() ) | 247 | if ( fi.isEmpty() ) |
248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
249 | OSQLManager man; | 249 | OSQLManager man; |
250 | m_driver = man.standard(); | 250 | m_driver = man.standard(); |
251 | m_driver->setUrl(fi); | 251 | m_driver->setUrl(fi); |
252 | fillDict(); | 252 | fillDict(); |
@@ -256,28 +256,30 @@ OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | |||
256 | } | 256 | } |
257 | bool OTodoAccessBackendSQL::load(){ | 257 | bool OTodoAccessBackendSQL::load(){ |
258 | if (!m_driver->open() ) | 258 | if (!m_driver->open() ) |
259 | return false; | 259 | return false; |
260 | 260 | ||
261 | CreateQuery creat; | 261 | CreateQuery creat; |
262 | OSQLResult res = m_driver->query(&creat ); | 262 | OSQLResult res = m_driver->query(&creat ); |
263 | 263 | ||
264 | update(); | 264 | m_dirty = true; |
265 | qWarning("loaded %d", m_uids.count() ); | ||
266 | return true; | 265 | return true; |
267 | } | 266 | } |
268 | bool OTodoAccessBackendSQL::reload(){ | 267 | bool OTodoAccessBackendSQL::reload(){ |
269 | return load(); | 268 | return load(); |
270 | } | 269 | } |
271 | 270 | ||
272 | bool OTodoAccessBackendSQL::save(){ | 271 | bool OTodoAccessBackendSQL::save(){ |
273 | return m_driver->close(); | 272 | return m_driver->close(); |
274 | } | 273 | } |
275 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 274 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
275 | if (m_dirty ) | ||
276 | update(); | ||
277 | |||
276 | return m_uids; | 278 | return m_uids; |
277 | } | 279 | } |
278 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ | 280 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ |
279 | QArray<int> ints(0); | 281 | QArray<int> ints(0); |
280 | return ints; | 282 | return ints; |
281 | } | 283 | } |
282 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 284 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
283 | FindQuery query( uid ); | 285 | FindQuery query( uid ); |
@@ -298,17 +300,17 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | |||
298 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { | 300 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { |
299 | qWarning("size %d %d", size, ints[i] ); | 301 | qWarning("size %d %d", size, ints[i] ); |
300 | search[size] = ints[i]; | 302 | search[size] = ints[i]; |
301 | size++; | 303 | size++; |
302 | } | 304 | } |
303 | break; | 305 | break; |
304 | /* reverse */ | 306 | /* reverse */ |
305 | case 1: | 307 | case 1: |
306 | for (uint i = cur; i >= 0 && size < 8; i-- ) { | 308 | for (uint i = cur; i != 0 && size < 8; i-- ) { |
307 | search[size] = ints[i]; | 309 | search[size] = ints[i]; |
308 | size++; | 310 | size++; |
309 | } | 311 | } |
310 | break; | 312 | break; |
311 | } | 313 | } |
312 | search.resize( size ); | 314 | search.resize( size ); |
313 | FindQuery query( search ); | 315 | FindQuery query( search ); |
314 | OSQLResult res = m_driver->query( &query ); | 316 | OSQLResult res = m_driver->query( &query ); |
@@ -337,43 +339,46 @@ bool OTodoAccessBackendSQL::add( const OTodo& t) { | |||
337 | } | 339 | } |
338 | bool OTodoAccessBackendSQL::remove( int uid ) { | 340 | bool OTodoAccessBackendSQL::remove( int uid ) { |
339 | RemoveQuery rem( uid ); | 341 | RemoveQuery rem( uid ); |
340 | OSQLResult res = m_driver->query(&rem ); | 342 | OSQLResult res = m_driver->query(&rem ); |
341 | 343 | ||
342 | if ( res.state() == OSQLResult::Failure ) | 344 | if ( res.state() == OSQLResult::Failure ) |
343 | return false; | 345 | return false; |
344 | 346 | ||
345 | update(); | 347 | m_dirty = true; |
346 | return true; | 348 | return true; |
347 | } | 349 | } |
348 | /* | 350 | /* |
349 | * FIXME better set query | 351 | * FIXME better set query |
350 | * but we need the cache for that | 352 | * but we need the cache for that |
351 | * now we remove | 353 | * now we remove |
352 | */ | 354 | */ |
353 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 355 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { |
354 | remove( t.uid() ); | 356 | remove( t.uid() ); |
355 | return add(t); | 357 | bool b= add(t); |
358 | m_dirty = false; // we changed some stuff but the UID stayed the same | ||
359 | return b; | ||
356 | } | 360 | } |
357 | QArray<int> OTodoAccessBackendSQL::overDue() { | 361 | QArray<int> OTodoAccessBackendSQL::overDue() { |
358 | OverDueQuery qu; | 362 | OverDueQuery qu; |
359 | return uids( m_driver->query(&qu ) ); | 363 | return uids( m_driver->query(&qu ) ); |
360 | } | 364 | } |
361 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 365 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
362 | const QDate& t, | 366 | const QDate& t, |
363 | bool u) { | 367 | bool u) { |
364 | EffQuery ef(s, t, u ); | 368 | EffQuery ef(s, t, u ); |
365 | return uids (m_driver->query(&ef) ); | 369 | return uids (m_driver->query(&ef) ); |
366 | } | 370 | } |
367 | /* | 371 | /* |
368 | * | 372 | * |
369 | */ | 373 | */ |
370 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 374 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
371 | int sortFilter, int cat ) { | 375 | int sortFilter, int cat ) { |
376 | qWarning("sorted %d, %d", asc, sortOrder ); | ||
372 | QString query; | 377 | QString query; |
373 | query = "select uid from todolist WHERE "; | 378 | query = "select uid from todolist WHERE "; |
374 | 379 | ||
375 | /* | 380 | /* |
376 | * Sort Filter stuff | 381 | * Sort Filter stuff |
377 | * not that straight forward | 382 | * not that straight forward |
378 | * | 383 | * |
379 | */ | 384 | */ |
@@ -416,18 +421,21 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
416 | break; | 421 | break; |
417 | case 2: | 422 | case 2: |
418 | query += "description"; | 423 | query += "description"; |
419 | break; | 424 | break; |
420 | case 3: | 425 | case 3: |
421 | query += "DueDate"; | 426 | query += "DueDate"; |
422 | break; | 427 | break; |
423 | } | 428 | } |
424 | if ( !asc ) | 429 | |
430 | if ( !asc ) { | ||
431 | qWarning("not ascending!"); | ||
425 | query += " DESC"; | 432 | query += " DESC"; |
433 | } | ||
426 | 434 | ||
427 | qWarning( query ); | 435 | qWarning( query ); |
428 | OSQLRawQuery raw(query ); | 436 | OSQLRawQuery raw(query ); |
429 | return uids( m_driver->query(&raw) ); | 437 | return uids( m_driver->query(&raw) ); |
430 | } | 438 | } |
431 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 439 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
432 | if ( str == "0-0-0" ) | 440 | if ( str == "0-0-0" ) |
433 | return false; | 441 | return false; |
@@ -496,23 +504,28 @@ void OTodoAccessBackendSQL::fillDict() { | |||
496 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 504 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
497 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 505 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
498 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 506 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
499 | m_dict.insert("Completed", new int(OTodo::Completed) ); | 507 | m_dict.insert("Completed", new int(OTodo::Completed) ); |
500 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 508 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
501 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 509 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); |
502 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 510 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); |
503 | } | 511 | } |
504 | void OTodoAccessBackendSQL::update() { | 512 | /* |
513 | * need to be const so let's fool the | ||
514 | * compiler :( | ||
515 | */ | ||
516 | void OTodoAccessBackendSQL::update()const { | ||
517 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; | ||
505 | LoadQuery lo; | 518 | LoadQuery lo; |
506 | OSQLResult res = m_driver->query(&lo); | 519 | OSQLResult res = m_driver->query(&lo); |
507 | if ( res.state() != OSQLResult::Success ) | 520 | if ( res.state() != OSQLResult::Success ) |
508 | return; | 521 | return; |
509 | 522 | ||
510 | m_uids = uids( res ); | 523 | ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
511 | } | 524 | } |
512 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 525 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
513 | 526 | ||
514 | OSQLResultItem::ValueList list = res.results(); | 527 | OSQLResultItem::ValueList list = res.results(); |
515 | OSQLResultItem::ValueList::Iterator it; | 528 | OSQLResultItem::ValueList::Iterator it; |
516 | QArray<int> ints(list.count() ); | 529 | QArray<int> ints(list.count() ); |
517 | qWarning(" count = %d", list.count() ); | 530 | qWarning(" count = %d", list.count() ); |
518 | 531 | ||
diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h index c1aa2ed..0f6dd2c 100644 --- a/libopie/pim/otodoaccesssql.h +++ b/libopie/pim/otodoaccesssql.h | |||
@@ -27,23 +27,24 @@ public: | |||
27 | bool replace( const OTodo& t ); | 27 | bool replace( const OTodo& t ); |
28 | 28 | ||
29 | QArray<int> overDue(); | 29 | QArray<int> overDue(); |
30 | QArray<int> effectiveToDos( const QDate& start, | 30 | QArray<int> effectiveToDos( const QDate& start, |
31 | const QDate& end, bool includeNoDates ); | 31 | const QDate& end, bool includeNoDates ); |
32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); | 32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); |
33 | 33 | ||
34 | private: | 34 | private: |
35 | void update(); | 35 | void update()const; |
36 | void fillDict(); | 36 | void fillDict(); |
37 | inline bool date( QDate& date, const QString& )const; | 37 | inline bool date( QDate& date, const QString& )const; |
38 | inline OTodo todo( const OSQLResult& )const; | 38 | inline OTodo todo( const OSQLResult& )const; |
39 | inline OTodo todo( OSQLResultItem& )const; | 39 | inline OTodo todo( OSQLResultItem& )const; |
40 | inline QArray<int> uids( const OSQLResult& )const; | 40 | inline QArray<int> uids( const OSQLResult& )const; |
41 | OTodo todo( int uid )const; | 41 | OTodo todo( int uid )const; |
42 | 42 | ||
43 | QAsciiDict<int> m_dict; | 43 | QAsciiDict<int> m_dict; |
44 | OSQLDriver* m_driver; | 44 | OSQLDriver* m_driver; |
45 | QArray<int> m_uids; | 45 | QArray<int> m_uids; |
46 | bool m_dirty : 1; | ||
46 | }; | 47 | }; |
47 | 48 | ||
48 | 49 | ||
49 | #endif | 50 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index a059dab..ea8b3c9 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -236,17 +236,17 @@ namespace { | |||
236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) | 236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) |
237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); | 237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); |
238 | 238 | ||
239 | return str; | 239 | return str; |
240 | } | 240 | } |
241 | }; | 241 | }; |
242 | 242 | ||
243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
244 | : OTodoAccessBackend(), m_dict(15) | 244 | : OTodoAccessBackend(), m_dict(15), m_dirty(true) |
245 | { | 245 | { |
246 | QString fi = file; | 246 | QString fi = file; |
247 | if ( fi.isEmpty() ) | 247 | if ( fi.isEmpty() ) |
248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
249 | OSQLManager man; | 249 | OSQLManager man; |
250 | m_driver = man.standard(); | 250 | m_driver = man.standard(); |
251 | m_driver->setUrl(fi); | 251 | m_driver->setUrl(fi); |
252 | fillDict(); | 252 | fillDict(); |
@@ -256,28 +256,30 @@ OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | |||
256 | } | 256 | } |
257 | bool OTodoAccessBackendSQL::load(){ | 257 | bool OTodoAccessBackendSQL::load(){ |
258 | if (!m_driver->open() ) | 258 | if (!m_driver->open() ) |
259 | return false; | 259 | return false; |
260 | 260 | ||
261 | CreateQuery creat; | 261 | CreateQuery creat; |
262 | OSQLResult res = m_driver->query(&creat ); | 262 | OSQLResult res = m_driver->query(&creat ); |
263 | 263 | ||
264 | update(); | 264 | m_dirty = true; |
265 | qWarning("loaded %d", m_uids.count() ); | ||
266 | return true; | 265 | return true; |
267 | } | 266 | } |
268 | bool OTodoAccessBackendSQL::reload(){ | 267 | bool OTodoAccessBackendSQL::reload(){ |
269 | return load(); | 268 | return load(); |
270 | } | 269 | } |
271 | 270 | ||
272 | bool OTodoAccessBackendSQL::save(){ | 271 | bool OTodoAccessBackendSQL::save(){ |
273 | return m_driver->close(); | 272 | return m_driver->close(); |
274 | } | 273 | } |
275 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 274 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
275 | if (m_dirty ) | ||
276 | update(); | ||
277 | |||
276 | return m_uids; | 278 | return m_uids; |
277 | } | 279 | } |
278 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ | 280 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ |
279 | QArray<int> ints(0); | 281 | QArray<int> ints(0); |
280 | return ints; | 282 | return ints; |
281 | } | 283 | } |
282 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 284 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
283 | FindQuery query( uid ); | 285 | FindQuery query( uid ); |
@@ -298,17 +300,17 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | |||
298 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { | 300 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { |
299 | qWarning("size %d %d", size, ints[i] ); | 301 | qWarning("size %d %d", size, ints[i] ); |
300 | search[size] = ints[i]; | 302 | search[size] = ints[i]; |
301 | size++; | 303 | size++; |
302 | } | 304 | } |
303 | break; | 305 | break; |
304 | /* reverse */ | 306 | /* reverse */ |
305 | case 1: | 307 | case 1: |
306 | for (uint i = cur; i >= 0 && size < 8; i-- ) { | 308 | for (uint i = cur; i != 0 && size < 8; i-- ) { |
307 | search[size] = ints[i]; | 309 | search[size] = ints[i]; |
308 | size++; | 310 | size++; |
309 | } | 311 | } |
310 | break; | 312 | break; |
311 | } | 313 | } |
312 | search.resize( size ); | 314 | search.resize( size ); |
313 | FindQuery query( search ); | 315 | FindQuery query( search ); |
314 | OSQLResult res = m_driver->query( &query ); | 316 | OSQLResult res = m_driver->query( &query ); |
@@ -337,43 +339,46 @@ bool OTodoAccessBackendSQL::add( const OTodo& t) { | |||
337 | } | 339 | } |
338 | bool OTodoAccessBackendSQL::remove( int uid ) { | 340 | bool OTodoAccessBackendSQL::remove( int uid ) { |
339 | RemoveQuery rem( uid ); | 341 | RemoveQuery rem( uid ); |
340 | OSQLResult res = m_driver->query(&rem ); | 342 | OSQLResult res = m_driver->query(&rem ); |
341 | 343 | ||
342 | if ( res.state() == OSQLResult::Failure ) | 344 | if ( res.state() == OSQLResult::Failure ) |
343 | return false; | 345 | return false; |
344 | 346 | ||
345 | update(); | 347 | m_dirty = true; |
346 | return true; | 348 | return true; |
347 | } | 349 | } |
348 | /* | 350 | /* |
349 | * FIXME better set query | 351 | * FIXME better set query |
350 | * but we need the cache for that | 352 | * but we need the cache for that |
351 | * now we remove | 353 | * now we remove |
352 | */ | 354 | */ |
353 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 355 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { |
354 | remove( t.uid() ); | 356 | remove( t.uid() ); |
355 | return add(t); | 357 | bool b= add(t); |
358 | m_dirty = false; // we changed some stuff but the UID stayed the same | ||
359 | return b; | ||
356 | } | 360 | } |
357 | QArray<int> OTodoAccessBackendSQL::overDue() { | 361 | QArray<int> OTodoAccessBackendSQL::overDue() { |
358 | OverDueQuery qu; | 362 | OverDueQuery qu; |
359 | return uids( m_driver->query(&qu ) ); | 363 | return uids( m_driver->query(&qu ) ); |
360 | } | 364 | } |
361 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 365 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
362 | const QDate& t, | 366 | const QDate& t, |
363 | bool u) { | 367 | bool u) { |
364 | EffQuery ef(s, t, u ); | 368 | EffQuery ef(s, t, u ); |
365 | return uids (m_driver->query(&ef) ); | 369 | return uids (m_driver->query(&ef) ); |
366 | } | 370 | } |
367 | /* | 371 | /* |
368 | * | 372 | * |
369 | */ | 373 | */ |
370 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 374 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
371 | int sortFilter, int cat ) { | 375 | int sortFilter, int cat ) { |
376 | qWarning("sorted %d, %d", asc, sortOrder ); | ||
372 | QString query; | 377 | QString query; |
373 | query = "select uid from todolist WHERE "; | 378 | query = "select uid from todolist WHERE "; |
374 | 379 | ||
375 | /* | 380 | /* |
376 | * Sort Filter stuff | 381 | * Sort Filter stuff |
377 | * not that straight forward | 382 | * not that straight forward |
378 | * | 383 | * |
379 | */ | 384 | */ |
@@ -416,18 +421,21 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
416 | break; | 421 | break; |
417 | case 2: | 422 | case 2: |
418 | query += "description"; | 423 | query += "description"; |
419 | break; | 424 | break; |
420 | case 3: | 425 | case 3: |
421 | query += "DueDate"; | 426 | query += "DueDate"; |
422 | break; | 427 | break; |
423 | } | 428 | } |
424 | if ( !asc ) | 429 | |
430 | if ( !asc ) { | ||
431 | qWarning("not ascending!"); | ||
425 | query += " DESC"; | 432 | query += " DESC"; |
433 | } | ||
426 | 434 | ||
427 | qWarning( query ); | 435 | qWarning( query ); |
428 | OSQLRawQuery raw(query ); | 436 | OSQLRawQuery raw(query ); |
429 | return uids( m_driver->query(&raw) ); | 437 | return uids( m_driver->query(&raw) ); |
430 | } | 438 | } |
431 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 439 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
432 | if ( str == "0-0-0" ) | 440 | if ( str == "0-0-0" ) |
433 | return false; | 441 | return false; |
@@ -496,23 +504,28 @@ void OTodoAccessBackendSQL::fillDict() { | |||
496 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 504 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
497 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 505 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
498 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 506 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
499 | m_dict.insert("Completed", new int(OTodo::Completed) ); | 507 | m_dict.insert("Completed", new int(OTodo::Completed) ); |
500 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 508 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
501 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 509 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); |
502 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 510 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); |
503 | } | 511 | } |
504 | void OTodoAccessBackendSQL::update() { | 512 | /* |
513 | * need to be const so let's fool the | ||
514 | * compiler :( | ||
515 | */ | ||
516 | void OTodoAccessBackendSQL::update()const { | ||
517 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; | ||
505 | LoadQuery lo; | 518 | LoadQuery lo; |
506 | OSQLResult res = m_driver->query(&lo); | 519 | OSQLResult res = m_driver->query(&lo); |
507 | if ( res.state() != OSQLResult::Success ) | 520 | if ( res.state() != OSQLResult::Success ) |
508 | return; | 521 | return; |
509 | 522 | ||
510 | m_uids = uids( res ); | 523 | ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
511 | } | 524 | } |
512 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 525 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
513 | 526 | ||
514 | OSQLResultItem::ValueList list = res.results(); | 527 | OSQLResultItem::ValueList list = res.results(); |
515 | OSQLResultItem::ValueList::Iterator it; | 528 | OSQLResultItem::ValueList::Iterator it; |
516 | QArray<int> ints(list.count() ); | 529 | QArray<int> ints(list.count() ); |
517 | qWarning(" count = %d", list.count() ); | 530 | qWarning(" count = %d", list.count() ); |
518 | 531 | ||
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index c1aa2ed..0f6dd2c 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h | |||
@@ -27,23 +27,24 @@ public: | |||
27 | bool replace( const OTodo& t ); | 27 | bool replace( const OTodo& t ); |
28 | 28 | ||
29 | QArray<int> overDue(); | 29 | QArray<int> overDue(); |
30 | QArray<int> effectiveToDos( const QDate& start, | 30 | QArray<int> effectiveToDos( const QDate& start, |
31 | const QDate& end, bool includeNoDates ); | 31 | const QDate& end, bool includeNoDates ); |
32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); | 32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); |
33 | 33 | ||
34 | private: | 34 | private: |
35 | void update(); | 35 | void update()const; |
36 | void fillDict(); | 36 | void fillDict(); |
37 | inline bool date( QDate& date, const QString& )const; | 37 | inline bool date( QDate& date, const QString& )const; |
38 | inline OTodo todo( const OSQLResult& )const; | 38 | inline OTodo todo( const OSQLResult& )const; |
39 | inline OTodo todo( OSQLResultItem& )const; | 39 | inline OTodo todo( OSQLResultItem& )const; |
40 | inline QArray<int> uids( const OSQLResult& )const; | 40 | inline QArray<int> uids( const OSQLResult& )const; |
41 | OTodo todo( int uid )const; | 41 | OTodo todo( int uid )const; |
42 | 42 | ||
43 | QAsciiDict<int> m_dict; | 43 | QAsciiDict<int> m_dict; |
44 | OSQLDriver* m_driver; | 44 | OSQLDriver* m_driver; |
45 | QArray<int> m_uids; | 45 | QArray<int> m_uids; |
46 | bool m_dirty : 1; | ||
46 | }; | 47 | }; |
47 | 48 | ||
48 | 49 | ||
49 | #endif | 50 | #endif |
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 92d7192..a0d8f63 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -179,22 +179,20 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | |||
179 | uint current, CacheDirection dir )const { | 179 | uint current, CacheDirection dir )const { |
180 | /* | 180 | /* |
181 | * better do T.isEmpty() | 181 | * better do T.isEmpty() |
182 | * after a find this way we would | 182 | * after a find this way we would |
183 | * avoid two finds in QCache... | 183 | * avoid two finds in QCache... |
184 | */ | 184 | */ |
185 | // qWarning("find it now %d", uid ); | 185 | // qWarning("find it now %d", uid ); |
186 | if (m_cache.contains( uid ) ) { | 186 | if (m_cache.contains( uid ) ) { |
187 | qWarning("m cache contains %d", uid); | ||
188 | return m_cache.find( uid ); | 187 | return m_cache.find( uid ); |
189 | } | 188 | } |
190 | 189 | ||
191 | T t = m_backEnd->find( uid, ar, current, dir ); | 190 | T t = m_backEnd->find( uid, ar, current, dir ); |
192 | qWarning("found it and cache it now %d", uid); | ||
193 | cache( t ); | 191 | cache( t ); |
194 | return t; | 192 | return t; |
195 | } | 193 | } |
196 | template <class T> | 194 | template <class T> |
197 | void OPimAccessTemplate<T>::clear() { | 195 | void OPimAccessTemplate<T>::clear() { |
198 | invalidateCache(); | 196 | invalidateCache(); |
199 | m_backEnd->clear(); | 197 | m_backEnd->clear(); |
200 | } | 198 | } |
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 08f5c85..5404910 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h | |||
@@ -104,16 +104,17 @@ public: | |||
104 | Iterator end(); | 104 | Iterator end(); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * the number of items in the list | 107 | * the number of items in the list |
108 | */ | 108 | */ |
109 | uint count()const; | 109 | uint count()const; |
110 | 110 | ||
111 | T operator[]( uint i ); | 111 | T operator[]( uint i ); |
112 | int uidAt(uint i ); | ||
112 | // FIXME implemenent remove | 113 | // FIXME implemenent remove |
113 | /* | 114 | /* |
114 | ConstIterator begin()const; | 115 | ConstIterator begin()const; |
115 | ConstIterator end()const; | 116 | ConstIterator end()const; |
116 | */ | 117 | */ |
117 | private: | 118 | private: |
118 | QArray<int> m_ids; | 119 | QArray<int> m_ids; |
119 | const Base* m_acc; | 120 | const Base* m_acc; |
@@ -257,9 +258,13 @@ template <class T> | |||
257 | uint ORecordList<T>::count()const { | 258 | uint ORecordList<T>::count()const { |
258 | return m_ids.count(); | 259 | return m_ids.count(); |
259 | } | 260 | } |
260 | template <class T> | 261 | template <class T> |
261 | T ORecordList<T>::operator[]( uint i ) { | 262 | T ORecordList<T>::operator[]( uint i ) { |
262 | /* forward */ | 263 | /* forward */ |
263 | return m_acc->find( m_ids[i], m_ids, i ); | 264 | return m_acc->find( m_ids[i], m_ids, i ); |
264 | } | 265 | } |
266 | template <class T> | ||
267 | int ORecordList<T>::uidAt( uint i ) { | ||
268 | return m_ids[i]; | ||
269 | } | ||
265 | #endif | 270 | #endif |