Diffstat (limited to 'libopie/pim/otodoaccesssql.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 8add9f7..a059dab 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -83,2 +83,3 @@ namespace { | |||
83 | FindQuery(int uid); | 83 | FindQuery(int uid); |
84 | FindQuery(const QArray<int>& ); | ||
84 | ~FindQuery(); | 85 | ~FindQuery(); |
@@ -86,2 +87,5 @@ namespace { | |||
86 | private: | 87 | private: |
88 | QString single()const; | ||
89 | QString multi()const; | ||
90 | QArray<int> m_uids; | ||
87 | int m_uid; | 91 | int m_uid; |
@@ -140,2 +144,3 @@ namespace { | |||
140 | QString InsertQuery::query()const{ | 144 | QString InsertQuery::query()const{ |
145 | |||
141 | int year, month, day; | 146 | int year, month, day; |
@@ -177,2 +182,5 @@ namespace { | |||
177 | } | 182 | } |
183 | FindQuery::FindQuery(const QArray<int>& ints) | ||
184 | : OSQLQuery(), m_uids(ints){ | ||
185 | } | ||
178 | FindQuery::~FindQuery() { | 186 | FindQuery::~FindQuery() { |
@@ -180,2 +188,8 @@ namespace { | |||
180 | QString FindQuery::query()const{ | 188 | QString FindQuery::query()const{ |
189 | if (m_uids.count() == 0 ) | ||
190 | return single(); | ||
191 | else | ||
192 | return multi(); | ||
193 | } | ||
194 | QString FindQuery::single()const{ | ||
181 | QString qu = "select uid, categories, completed, progress, summary, "; | 195 | QString qu = "select uid, categories, completed, progress, summary, "; |
@@ -184,2 +198,11 @@ namespace { | |||
184 | } | 198 | } |
199 | QString FindQuery::multi()const { | ||
200 | QString qu = "select uid, categories, completed, progress, summary, "; | ||
201 | qu += "DueDate, priority, description from todolist where "; | ||
202 | for (uint i = 0; i < m_uids.count(); i++ ) { | ||
203 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | ||
204 | } | ||
205 | qu.remove( qu.length()-2, 2 ); | ||
206 | return qu; | ||
207 | } | ||
185 | 208 | ||
@@ -263,2 +286,35 @@ OTodo OTodoAccessBackendSQL::find(int uid ) const{ | |||
263 | } | 286 | } |
287 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | ||
288 | uint cur, Frontend::CacheDirection dir ) const{ | ||
289 | qWarning("searching for %d", uid ); | ||
290 | QArray<int> search( 8 ); | ||
291 | uint size =0; | ||
292 | OTodo to; | ||
293 | |||
294 | // we try to cache 8 items | ||
295 | switch( dir ) { | ||
296 | /* forward */ | ||
297 | case 0: | ||
298 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { | ||
299 | qWarning("size %d %d", size, ints[i] ); | ||
300 | search[size] = ints[i]; | ||
301 | size++; | ||
302 | } | ||
303 | break; | ||
304 | /* reverse */ | ||
305 | case 1: | ||
306 | for (uint i = cur; i >= 0 && size < 8; i-- ) { | ||
307 | search[size] = ints[i]; | ||
308 | size++; | ||
309 | } | ||
310 | break; | ||
311 | } | ||
312 | search.resize( size ); | ||
313 | FindQuery query( search ); | ||
314 | OSQLResult res = m_driver->query( &query ); | ||
315 | if ( res.state() != OSQLResult::Success ) | ||
316 | return to; | ||
317 | |||
318 | return todo( res ); | ||
319 | } | ||
264 | void OTodoAccessBackendSQL::clear() { | 320 | void OTodoAccessBackendSQL::clear() { |
@@ -395,10 +451,23 @@ OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | |||
395 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 451 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
452 | qWarning("todo1"); | ||
453 | OTodo to = todo( (*it) ); | ||
454 | cache( to ); | ||
455 | ++it; | ||
396 | 456 | ||
457 | for ( ; it != list.end(); ++it ) { | ||
458 | qWarning("caching"); | ||
459 | cache( todo( (*it) ) ); | ||
460 | } | ||
461 | return to; | ||
462 | } | ||
463 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | ||
464 | qWarning("todo"); | ||
397 | bool has = false; QDate da = QDate::currentDate(); | 465 | bool has = false; QDate da = QDate::currentDate(); |
398 | has = date( da, (*it).data("DueDate") ); | 466 | has = date( da, item.data("DueDate") ); |
399 | QStringList cats = QStringList::split(";", (*it).data("categories") ); | 467 | QStringList cats = QStringList::split(";", item.data("categories") ); |
400 | 468 | ||
401 | OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), | 469 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
402 | cats, (*it).data("summary"), (*it).data("description"), | 470 | cats, item.data("summary"), item.data("description"), |
403 | (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); | 471 | item.data("progress").toUShort(), has, da, |
472 | item.data("uid").toInt() ); | ||
404 | return to; | 473 | return to; |