author | zecke <zecke> | 2002-10-07 14:59:44 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-07 14:59:44 (UTC) |
commit | e68537563c9950654b9a771730f0fc3890803a54 (patch) (unidiff) | |
tree | fd64fada00405ca8ad65e9334bcdb4c3da3f1a9a | |
parent | 645b377506fb32f4519e70d43c020084943debae (diff) | |
download | opie-e68537563c9950654b9a771730f0fc3890803a54.zip opie-e68537563c9950654b9a771730f0fc3890803a54.tar.gz opie-e68537563c9950654b9a771730f0fc3890803a54.tar.bz2 |
Fix sorted SQL query
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 7 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 7 |
2 files changed, 10 insertions, 4 deletions
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 25536e0..8add9f7 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -314,32 +314,34 @@ QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | |||
314 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 314 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
315 | int sortFilter, int cat ) { | 315 | int sortFilter, int cat ) { |
316 | QString query; | 316 | QString query; |
317 | query = "select uid from todolist WHERE "; | 317 | query = "select uid from todolist WHERE "; |
318 | 318 | ||
319 | /* | 319 | /* |
320 | * Sort Filter stuff | 320 | * Sort Filter stuff |
321 | * not that straight forward | 321 | * not that straight forward |
322 | * | 322 | * |
323 | */ | 323 | */ |
324 | /* Category */ | 324 | /* Category */ |
325 | if ( sortFilter & 1 ) { | 325 | if ( sortFilter & 1 ) { |
326 | query += " categories like '%" +QString::number(cat)+"%' AND"; | 326 | QString str; |
327 | if (cat != 0 ) str = QString::number( cat ); | ||
328 | query += " categories like '%" +str+"%' AND"; | ||
327 | } | 329 | } |
328 | /* Show only overdue */ | 330 | /* Show only overdue */ |
329 | if ( sortFilter & 2 ) { | 331 | if ( sortFilter & 2 ) { |
330 | QDate date = QDate::currentDate(); | 332 | QDate date = QDate::currentDate(); |
331 | QString due; | 333 | QString due; |
332 | QString base; | 334 | QString base; |
333 | base = QString("DueDate <= '%1-%2-%3' AND WHERE completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); | 335 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); |
334 | query += " " + base + " AND"; | 336 | query += " " + base + " AND"; |
335 | } | 337 | } |
336 | /* not show completed */ | 338 | /* not show completed */ |
337 | if ( sortFilter & 4 ) { | 339 | if ( sortFilter & 4 ) { |
338 | query += " completed = 0 AND"; | 340 | query += " completed = 0 AND"; |
339 | }else{ | 341 | }else{ |
340 | query += " ( completed = 1 OR completed = 0) AND"; | 342 | query += " ( completed = 1 OR completed = 0) AND"; |
341 | } | 343 | } |
342 | /* srtip the end */ | 344 | /* srtip the end */ |
343 | query = query.remove( query.length()-3, 3 ); | 345 | query = query.remove( query.length()-3, 3 ); |
344 | 346 | ||
345 | 347 | ||
@@ -434,21 +436,22 @@ void OTodoAccessBackendSQL::update() { | |||
434 | LoadQuery lo; | 436 | LoadQuery lo; |
435 | OSQLResult res = m_driver->query(&lo); | 437 | OSQLResult res = m_driver->query(&lo); |
436 | if ( res.state() != OSQLResult::Success ) | 438 | if ( res.state() != OSQLResult::Success ) |
437 | return; | 439 | return; |
438 | 440 | ||
439 | m_uids = uids( res ); | 441 | m_uids = uids( res ); |
440 | } | 442 | } |
441 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 443 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
442 | 444 | ||
443 | OSQLResultItem::ValueList list = res.results(); | 445 | OSQLResultItem::ValueList list = res.results(); |
444 | OSQLResultItem::ValueList::Iterator it; | 446 | OSQLResultItem::ValueList::Iterator it; |
445 | QArray<int> ints(list.count() ); | 447 | QArray<int> ints(list.count() ); |
448 | qWarning(" count = %d", list.count() ); | ||
446 | 449 | ||
447 | int i = 0; | 450 | int i = 0; |
448 | for (it = list.begin(); it != list.end(); ++it ) { | 451 | for (it = list.begin(); it != list.end(); ++it ) { |
449 | ints[i] = (*it).data("uid").toInt(); | 452 | ints[i] = (*it).data("uid").toInt(); |
450 | i++; | 453 | i++; |
451 | } | 454 | } |
452 | return ints; | 455 | return ints; |
453 | } | 456 | } |
454 | 457 | ||
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 25536e0..8add9f7 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -314,32 +314,34 @@ QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | |||
314 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 314 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
315 | int sortFilter, int cat ) { | 315 | int sortFilter, int cat ) { |
316 | QString query; | 316 | QString query; |
317 | query = "select uid from todolist WHERE "; | 317 | query = "select uid from todolist WHERE "; |
318 | 318 | ||
319 | /* | 319 | /* |
320 | * Sort Filter stuff | 320 | * Sort Filter stuff |
321 | * not that straight forward | 321 | * not that straight forward |
322 | * | 322 | * |
323 | */ | 323 | */ |
324 | /* Category */ | 324 | /* Category */ |
325 | if ( sortFilter & 1 ) { | 325 | if ( sortFilter & 1 ) { |
326 | query += " categories like '%" +QString::number(cat)+"%' AND"; | 326 | QString str; |
327 | if (cat != 0 ) str = QString::number( cat ); | ||
328 | query += " categories like '%" +str+"%' AND"; | ||
327 | } | 329 | } |
328 | /* Show only overdue */ | 330 | /* Show only overdue */ |
329 | if ( sortFilter & 2 ) { | 331 | if ( sortFilter & 2 ) { |
330 | QDate date = QDate::currentDate(); | 332 | QDate date = QDate::currentDate(); |
331 | QString due; | 333 | QString due; |
332 | QString base; | 334 | QString base; |
333 | base = QString("DueDate <= '%1-%2-%3' AND WHERE completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); | 335 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); |
334 | query += " " + base + " AND"; | 336 | query += " " + base + " AND"; |
335 | } | 337 | } |
336 | /* not show completed */ | 338 | /* not show completed */ |
337 | if ( sortFilter & 4 ) { | 339 | if ( sortFilter & 4 ) { |
338 | query += " completed = 0 AND"; | 340 | query += " completed = 0 AND"; |
339 | }else{ | 341 | }else{ |
340 | query += " ( completed = 1 OR completed = 0) AND"; | 342 | query += " ( completed = 1 OR completed = 0) AND"; |
341 | } | 343 | } |
342 | /* srtip the end */ | 344 | /* srtip the end */ |
343 | query = query.remove( query.length()-3, 3 ); | 345 | query = query.remove( query.length()-3, 3 ); |
344 | 346 | ||
345 | 347 | ||
@@ -434,21 +436,22 @@ void OTodoAccessBackendSQL::update() { | |||
434 | LoadQuery lo; | 436 | LoadQuery lo; |
435 | OSQLResult res = m_driver->query(&lo); | 437 | OSQLResult res = m_driver->query(&lo); |
436 | if ( res.state() != OSQLResult::Success ) | 438 | if ( res.state() != OSQLResult::Success ) |
437 | return; | 439 | return; |
438 | 440 | ||
439 | m_uids = uids( res ); | 441 | m_uids = uids( res ); |
440 | } | 442 | } |
441 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 443 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
442 | 444 | ||
443 | OSQLResultItem::ValueList list = res.results(); | 445 | OSQLResultItem::ValueList list = res.results(); |
444 | OSQLResultItem::ValueList::Iterator it; | 446 | OSQLResultItem::ValueList::Iterator it; |
445 | QArray<int> ints(list.count() ); | 447 | QArray<int> ints(list.count() ); |
448 | qWarning(" count = %d", list.count() ); | ||
446 | 449 | ||
447 | int i = 0; | 450 | int i = 0; |
448 | for (it = list.begin(); it != list.end(); ++it ) { | 451 | for (it = list.begin(); it != list.end(); ++it ) { |
449 | ints[i] = (*it).data("uid").toInt(); | 452 | ints[i] = (*it).data("uid").toInt(); |
450 | i++; | 453 | i++; |
451 | } | 454 | } |
452 | return ints; | 455 | return ints; |
453 | } | 456 | } |
454 | 457 | ||