author | ar <ar> | 2004-06-01 21:38:07 (UTC) |
---|---|---|
committer | ar <ar> | 2004-06-01 21:38:07 (UTC) |
commit | baed1d5ab8589aef14440009bc4e7380bcc5a741 (patch) (unidiff) | |
tree | c636e892c5eec0df2b36d16cb601a7da41a2ef0f /libopie2/opiepim/backend/otodoaccesssql.cpp | |
parent | 4438393d8eef624565e840b798429071829adea8 (diff) | |
download | opie-baed1d5ab8589aef14440009bc4e7380bcc5a741.zip opie-baed1d5ab8589aef14440009bc4e7380bcc5a741.tar.gz opie-baed1d5ab8589aef14440009bc4e7380bcc5a741.tar.bz2 |
- convert to odebug framework
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 444 |
1 files changed, 224 insertions, 220 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 132b5a6..6f65c48 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -28,12 +28,7 @@ | |||
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <qdatetime.h> | 31 | /* OPIE */ |
32 | #include <qmap.h> | ||
33 | #include <qstring.h> | ||
34 | |||
35 | #include <qpe/global.h> | ||
36 | |||
37 | #include <opie2/osqldriver.h> | 32 | #include <opie2/osqldriver.h> |
38 | #include <opie2/osqlresult.h> | 33 | #include <opie2/osqlresult.h> |
39 | #include <opie2/osqlmanager.h> | 34 | #include <opie2/osqlmanager.h> |
@@ -43,6 +38,15 @@ | |||
43 | #include <opie2/opimstate.h> | 38 | #include <opie2/opimstate.h> |
44 | #include <opie2/opimnotifymanager.h> | 39 | #include <opie2/opimnotifymanager.h> |
45 | #include <opie2/opimrecurrence.h> | 40 | #include <opie2/opimrecurrence.h> |
41 | #include <opie2/odebug.h> | ||
42 | |||
43 | #include <qpe/global.h> | ||
44 | |||
45 | /* QT */ | ||
46 | #include <qdatetime.h> | ||
47 | #include <qmap.h> | ||
48 | #include <qstring.h> | ||
49 | |||
46 | 50 | ||
47 | using namespace Opie::DB; | 51 | using namespace Opie::DB; |
48 | 52 | ||
@@ -151,21 +155,21 @@ namespace { | |||
151 | }; | 155 | }; |
152 | 156 | ||
153 | 157 | ||
154 | /** | 158 | /** |
155 | * a find query for custom elements | 159 | * a find query for custom elements |
156 | */ | 160 | */ |
157 | class FindCustomQuery : public OSQLQuery { | 161 | class FindCustomQuery : public OSQLQuery { |
158 | public: | 162 | public: |
159 | FindCustomQuery(int uid); | 163 | FindCustomQuery(int uid); |
160 | FindCustomQuery(const QArray<int>& ); | 164 | FindCustomQuery(const QArray<int>& ); |
161 | ~FindCustomQuery(); | 165 | ~FindCustomQuery(); |
162 | QString query()const; | 166 | QString query()const; |
163 | private: | 167 | private: |
164 | QString single()const; | 168 | QString single()const; |
165 | QString multi()const; | 169 | QString multi()const; |
166 | QArray<int> m_uids; | 170 | QArray<int> m_uids; |
167 | int m_uid; | 171 | int m_uid; |
168 | }; | 172 | }; |
169 | 173 | ||
170 | 174 | ||
171 | 175 | ||
@@ -175,10 +179,10 @@ namespace { | |||
175 | QString qu; | 179 | QString qu; |
176 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; | 180 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; |
177 | qu += "description, summary, priority, DueDate, progress , state, "; | 181 | qu += "description, summary, priority, DueDate, progress , state, "; |
178 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) | 182 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) |
179 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; | 183 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; |
180 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; | 184 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; |
181 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 185 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
182 | return qu; | 186 | return qu; |
183 | } | 187 | } |
184 | 188 | ||
@@ -186,7 +190,7 @@ namespace { | |||
186 | LoadQuery::~LoadQuery() {} | 190 | LoadQuery::~LoadQuery() {} |
187 | QString LoadQuery::query()const { | 191 | QString LoadQuery::query()const { |
188 | QString qu; | 192 | QString qu; |
189 | // We do not need "distinct" here. The primary key is always unique.. | 193 | // We do not need "distinct" here. The primary key is always unique.. |
190 | //qu += "select distinct uid from todolist"; | 194 | //qu += "select distinct uid from todolist"; |
191 | qu += "select uid from todolist"; | 195 | qu += "select uid from todolist"; |
192 | 196 | ||
@@ -213,85 +217,85 @@ namespace { | |||
213 | year = date.year(); | 217 | year = date.year(); |
214 | month = date.month(); | 218 | month = date.month(); |
215 | day = date.day(); | 219 | day = date.day(); |
216 | } | 220 | } |
217 | int sYear = 0, sMonth = 0, sDay = 0; | 221 | int sYear = 0, sMonth = 0, sDay = 0; |
218 | if( m_todo.hasStartDate() ){ | 222 | if( m_todo.hasStartDate() ){ |
219 | QDate sDate = m_todo.startDate(); | 223 | QDate sDate = m_todo.startDate(); |
220 | sYear = sDate.year(); | 224 | sYear = sDate.year(); |
221 | sMonth= sDate.month(); | 225 | sMonth= sDate.month(); |
222 | sDay = sDate.day(); | 226 | sDay = sDate.day(); |
223 | } | 227 | } |
224 | 228 | ||
225 | int eYear = 0, eMonth = 0, eDay = 0; | 229 | int eYear = 0, eMonth = 0, eDay = 0; |
226 | if( m_todo.hasCompletedDate() ){ | 230 | if( m_todo.hasCompletedDate() ){ |
227 | QDate eDate = m_todo.completedDate(); | 231 | QDate eDate = m_todo.completedDate(); |
228 | eYear = eDate.year(); | 232 | eYear = eDate.year(); |
229 | eMonth= eDate.month(); | 233 | eMonth= eDate.month(); |
230 | eDay = eDate.day(); | 234 | eDay = eDate.day(); |
231 | } | 235 | } |
232 | QString qu; | 236 | QString qu; |
233 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); | 237 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); |
234 | qu = "insert into todolist VALUES(" | 238 | qu = "insert into todolist VALUES(" |
235 | + QString::number( m_todo.uid() ) + "," | 239 | + QString::number( m_todo.uid() ) + "," |
236 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," | 240 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," |
237 | + QString::number( m_todo.isCompleted() ) + "," | 241 | + QString::number( m_todo.isCompleted() ) + "," |
238 | + "'" + m_todo.description() + "'" + "," | 242 | + "'" + m_todo.description() + "'" + "," |
239 | + "'" + m_todo.summary() + "'" + "," | 243 | + "'" + m_todo.summary() + "'" + "," |
240 | + QString::number(m_todo.priority() ) + "," | 244 | + QString::number(m_todo.priority() ) + "," |
241 | + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" | 245 | + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" |
242 | + QString::number(month).rightJustify( 2, '0' ) | 246 | + QString::number(month).rightJustify( 2, '0' ) |
243 | + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," | 247 | + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," |
244 | + QString::number( m_todo.progress() ) + "," | 248 | + QString::number( m_todo.progress() ) + "," |
245 | + QString::number( m_todo.state().state() ) + "," | 249 | + QString::number( m_todo.state().state() ) + "," |
246 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," | 250 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," |
247 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," | 251 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," |
248 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," | 252 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," |
249 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," | 253 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," |
250 | + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," | 254 | + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," |
251 | + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," | 255 | + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," |
252 | + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," | 256 | + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," |
253 | + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; | 257 | + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; |
254 | 258 | ||
255 | if ( m_todo.hasNotifiers() ) { | 259 | if ( m_todo.hasNotifiers() ) { |
256 | OPimNotifyManager manager = m_todo.notifiers(); | 260 | OPimNotifyManager manager = m_todo.notifiers(); |
257 | qu += "'" + manager.remindersToString() + "'" + "," | 261 | qu += "'" + manager.remindersToString() + "'" + "," |
258 | + "'" + manager.alarmsToString() + "'" + ","; | 262 | + "'" + manager.alarmsToString() + "'" + ","; |
259 | } | 263 | } |
260 | else{ | 264 | else{ |
261 | qu += QString( "''" ) + "," | 265 | qu += QString( "''" ) + "," |
262 | + "''" + ","; | 266 | + "''" + ","; |
263 | } | 267 | } |
264 | 268 | ||
265 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) | 269 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) |
266 | + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" | 270 | + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" |
267 | + QString::number(sMonth).rightJustify( 2, '0' ) | 271 | + QString::number(sMonth).rightJustify( 2, '0' ) |
268 | + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," | 272 | + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," |
269 | + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" | 273 | + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" |
270 | + QString::number(eMonth).rightJustify( 2, '0' ) | 274 | + QString::number(eMonth).rightJustify( 2, '0' ) |
271 | + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" | 275 | + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" |
272 | + "); "; | 276 | + "); "; |
273 | 277 | ||
274 | // Save custom Entries: | 278 | // Save custom Entries: |
275 | int id = 0; | 279 | int id = 0; |
276 | id = 0; | 280 | id = 0; |
277 | QMap<QString, QString> customMap = m_todo.toExtraMap(); | 281 | QMap<QString, QString> customMap = m_todo.toExtraMap(); |
278 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 282 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
279 | it != customMap.end(); ++it ){ | 283 | it != customMap.end(); ++it ){ |
280 | qu += "insert into custom_data VALUES(" | 284 | qu += "insert into custom_data VALUES(" |
281 | + QString::number( m_todo.uid() ) | 285 | + QString::number( m_todo.uid() ) |
282 | + "," | 286 | + "," |
283 | + QString::number( id++ ) | 287 | + QString::number( id++ ) |
284 | + ",'" | 288 | + ",'" |
285 | + it.key() | 289 | + it.key() |
286 | + "'," | 290 | + "'," |
287 | + "0" // Priority for future enhancements | 291 | + "0" // Priority for future enhancements |
288 | + ",'" | 292 | + ",'" |
289 | + it.data() | 293 | + it.data() |
290 | + "');"; | 294 | + "');"; |
291 | } | 295 | } |
292 | 296 | ||
293 | 297 | ||
294 | qDebug("add %s", qu.latin1() ); | 298 | odebug << "add " << qu << "" << oendl; |
295 | return qu; | 299 | return qu; |
296 | } | 300 | } |
297 | 301 | ||
@@ -300,7 +304,7 @@ namespace { | |||
300 | RemoveQuery::~RemoveQuery() {} | 304 | RemoveQuery::~RemoveQuery() {} |
301 | QString RemoveQuery::query()const { | 305 | QString RemoveQuery::query()const { |
302 | QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; | 306 | QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; |
303 | qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); | 307 | qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); |
304 | return qu; | 308 | return qu; |
305 | } | 309 | } |
306 | 310 | ||
@@ -345,9 +349,9 @@ namespace { | |||
345 | QDate date = QDate::currentDate(); | 349 | QDate date = QDate::currentDate(); |
346 | QString str; | 350 | QString str; |
347 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'") | 351 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'") |
348 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) | 352 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) |
349 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) | 353 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) |
350 | .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); | 354 | .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); |
351 | 355 | ||
352 | return str; | 356 | return str; |
353 | } | 357 | } |
@@ -362,50 +366,50 @@ namespace { | |||
362 | QString EffQuery::with()const { | 366 | QString EffQuery::with()const { |
363 | QString str; | 367 | QString str; |
364 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") | 368 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") |
365 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) | 369 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) |
366 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) | 370 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) |
367 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) | 371 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) |
368 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) | 372 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) |
369 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) | 373 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) |
370 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); | 374 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); |
371 | return str; | 375 | return str; |
372 | } | 376 | } |
373 | QString EffQuery::out()const { | 377 | QString EffQuery::out()const { |
374 | QString str; | 378 | QString str; |
375 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 379 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
376 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) | 380 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) |
377 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) | 381 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) |
378 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) | 382 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) |
379 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) | 383 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) |
380 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) | 384 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) |
381 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); | 385 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); |
382 | 386 | ||
383 | return str; | 387 | return str; |
384 | } | 388 | } |
385 | 389 | ||
386 | FindCustomQuery::FindCustomQuery(int uid) | 390 | FindCustomQuery::FindCustomQuery(int uid) |
387 | : OSQLQuery(), m_uid( uid ) { | 391 | : OSQLQuery(), m_uid( uid ) { |
388 | } | 392 | } |
389 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) | 393 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) |
390 | : OSQLQuery(), m_uids( ints ){ | 394 | : OSQLQuery(), m_uids( ints ){ |
391 | } | 395 | } |
392 | FindCustomQuery::~FindCustomQuery() { | 396 | FindCustomQuery::~FindCustomQuery() { |
393 | } | 397 | } |
394 | QString FindCustomQuery::query()const{ | 398 | QString FindCustomQuery::query()const{ |
395 | return single(); // Multiple requests not supported ! | 399 | return single(); // Multiple requests not supported ! |
396 | } | 400 | } |
397 | QString FindCustomQuery::single()const{ | 401 | QString FindCustomQuery::single()const{ |
398 | QString qu = "select uid, type, value from custom_data where uid = "; | 402 | QString qu = "select uid, type, value from custom_data where uid = "; |
399 | qu += QString::number(m_uid); | 403 | qu += QString::number(m_uid); |
400 | return qu; | 404 | return qu; |
401 | } | 405 | } |
402 | 406 | ||
403 | }; | 407 | }; |
404 | 408 | ||
405 | 409 | ||
406 | namespace Opie { | 410 | namespace Opie { |
407 | OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) | 411 | OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) |
408 | : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) | 412 | : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) |
409 | { | 413 | { |
410 | QString fi = file; | 414 | QString fi = file; |
411 | if ( fi.isEmpty() ) | 415 | if ( fi.isEmpty() ) |
@@ -417,8 +421,8 @@ OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) | |||
417 | } | 421 | } |
418 | 422 | ||
419 | OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ | 423 | OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ |
420 | if( m_driver ) | 424 | if( m_driver ) |
421 | delete m_driver; | 425 | delete m_driver; |
422 | } | 426 | } |
423 | 427 | ||
424 | bool OPimTodoAccessBackendSQL::load(){ | 428 | bool OPimTodoAccessBackendSQL::load(){ |
@@ -456,7 +460,7 @@ OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ | |||
456 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 460 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
457 | uint cur, Frontend::CacheDirection dir ) const{ | 461 | uint cur, Frontend::CacheDirection dir ) const{ |
458 | uint CACHE = readAhead(); | 462 | uint CACHE = readAhead(); |
459 | qDebug("searching for %d", uid ); | 463 | odebug << "searching for " << uid << "" << oendl; |
460 | QArray<int> search( CACHE ); | 464 | QArray<int> search( CACHE ); |
461 | uint size =0; | 465 | uint size =0; |
462 | OPimTodo to; | 466 | OPimTodo to; |
@@ -466,7 +470,7 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | |||
466 | /* forward */ | 470 | /* forward */ |
467 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) | 471 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) |
468 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 472 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
469 | qDebug("size %d %d", size, ints[i] ); | 473 | odebug << "size " << size << " " << ints[i] << "" << oendl; |
470 | search[size] = ints[i]; | 474 | search[size] = ints[i]; |
471 | size++; | 475 | size++; |
472 | } | 476 | } |
@@ -541,7 +545,7 @@ QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, | |||
541 | */ | 545 | */ |
542 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 546 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
543 | int sortFilter, int cat ) { | 547 | int sortFilter, int cat ) { |
544 | qDebug("sorted %d, %d", asc, sortOrder ); | 548 | odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; |
545 | QString query; | 549 | QString query; |
546 | query = "select uid from todolist WHERE "; | 550 | query = "select uid from todolist WHERE "; |
547 | 551 | ||
@@ -563,9 +567,9 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
563 | QString due; | 567 | QString due; |
564 | QString base; | 568 | QString base; |
565 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0") | 569 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0") |
566 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) | 570 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) |
567 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) | 571 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) |
568 | .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); | 572 | .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); |
569 | query += " " + base + " AND"; | 573 | query += " " + base + " AND"; |
570 | } | 574 | } |
571 | /* not show completed */ | 575 | /* not show completed */ |
@@ -600,11 +604,11 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
600 | } | 604 | } |
601 | 605 | ||
602 | if ( !asc ) { | 606 | if ( !asc ) { |
603 | qDebug("not ascending!"); | 607 | odebug << "not ascending!" << oendl; |
604 | query += " DESC"; | 608 | query += " DESC"; |
605 | } | 609 | } |
606 | 610 | ||
607 | qDebug( query ); | 611 | odebug << query << oendl; |
608 | OSQLRawQuery raw(query ); | 612 | OSQLRawQuery raw(query ); |
609 | return uids( m_driver->query(&raw) ); | 613 | return uids( m_driver->query(&raw) ); |
610 | } | 614 | } |
@@ -629,19 +633,19 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ | |||
629 | 633 | ||
630 | OSQLResultItem::ValueList list = res.results(); | 634 | OSQLResultItem::ValueList list = res.results(); |
631 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 635 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
632 | qDebug("todo1"); | 636 | odebug << "todo1" << oendl; |
633 | OPimTodo to = todo( (*it) ); | 637 | OPimTodo to = todo( (*it) ); |
634 | cache( to ); | 638 | cache( to ); |
635 | ++it; | 639 | ++it; |
636 | 640 | ||
637 | for ( ; it != list.end(); ++it ) { | 641 | for ( ; it != list.end(); ++it ) { |
638 | qDebug("caching"); | 642 | odebug << "caching" << oendl; |
639 | cache( todo( (*it) ) ); | 643 | cache( todo( (*it) ) ); |
640 | } | 644 | } |
641 | return to; | 645 | return to; |
642 | } | 646 | } |
643 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 647 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
644 | qDebug("todo(ResultItem)"); | 648 | odebug << "todo(ResultItem)" << oendl; |
645 | 649 | ||
646 | // Request information from addressbook table and create the OPimTodo-object. | 650 | // Request information from addressbook table and create the OPimTodo-object. |
647 | 651 | ||
@@ -649,7 +653,7 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
649 | hasDueDate = date( dueDate, item.data("DueDate") ); | 653 | hasDueDate = date( dueDate, item.data("DueDate") ); |
650 | QStringList cats = QStringList::split(";", item.data("categories") ); | 654 | QStringList cats = QStringList::split(";", item.data("categories") ); |
651 | 655 | ||
652 | qDebug("Item is completed: %d", item.data("completed").toInt() ); | 656 | odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl; |
653 | 657 | ||
654 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 658 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
655 | cats, item.data("summary"), item.data("description"), | 659 | cats, item.data("summary"), item.data("description"), |
@@ -659,7 +663,7 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
659 | bool isOk; | 663 | bool isOk; |
660 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); | 664 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); |
661 | if ( isOk ) | 665 | if ( isOk ) |
662 | to.setPriority( prioInt ); | 666 | to.setPriority( prioInt ); |
663 | 667 | ||
664 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); | 668 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); |
665 | hasStartDate = date( startDate, item.data("startdate") ); | 669 | hasStartDate = date( startDate, item.data("startdate") ); |
@@ -667,9 +671,9 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
667 | hasCompletedDate = date( completedDate, item.data("completeddate") ); | 671 | hasCompletedDate = date( completedDate, item.data("completeddate") ); |
668 | 672 | ||
669 | if ( hasStartDate ) | 673 | if ( hasStartDate ) |
670 | to.setStartDate( startDate ); | 674 | to.setStartDate( startDate ); |
671 | if ( hasCompletedDate ) | 675 | if ( hasCompletedDate ) |
672 | to.setCompletedDate( completedDate ); | 676 | to.setCompletedDate( completedDate ); |
673 | 677 | ||
674 | OPimNotifyManager& manager = to.notifiers(); | 678 | OPimNotifyManager& manager = to.notifiers(); |
675 | manager.alarmsFromString( item.data("alarms") ); | 679 | manager.alarmsFromString( item.data("alarms") ); |
@@ -750,7 +754,7 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | |||
750 | OSQLResultItem::ValueList list = res.results(); | 754 | OSQLResultItem::ValueList list = res.results(); |
751 | OSQLResultItem::ValueList::Iterator it; | 755 | OSQLResultItem::ValueList::Iterator it; |
752 | QArray<int> ints(list.count() ); | 756 | QArray<int> ints(list.count() ); |
753 | qDebug(" count = %d", list.count() ); | 757 | odebug << " count = " << list.count() << "" << oendl; |
754 | 758 | ||
755 | int i = 0; | 759 | int i = 0; |
756 | for (it = list.begin(); it != list.end(); ++it ) { | 760 | for (it = list.begin(); it != list.end(); ++it ) { |
@@ -764,24 +768,24 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | |||
764 | { | 768 | { |
765 | 769 | ||
766 | #if 0 | 770 | #if 0 |
767 | QArray<int> empty; | 771 | QArray<int> empty; |
768 | return empty; | 772 | return empty; |
769 | 773 | ||
770 | #else | 774 | #else |
771 | QString qu = "SELECT uid FROM todolist WHERE ("; | 775 | QString qu = "SELECT uid FROM todolist WHERE ("; |
772 | 776 | ||
773 | // Do it make sense to search other fields, too ? | 777 | // Do it make sense to search other fields, too ? |
774 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; | 778 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; |
775 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; | 779 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; |
776 | 780 | ||
777 | qu += ")"; | 781 | qu += ")"; |
778 | 782 | ||
779 | qDebug( "query: %s", qu.latin1() ); | 783 | odebug << "query: " << qu << "" << oendl; |
780 | 784 | ||
781 | OSQLRawQuery raw( qu ); | 785 | OSQLRawQuery raw( qu ); |
782 | OSQLResult res = m_driver->query( &raw ); | 786 | OSQLResult res = m_driver->query( &raw ); |
783 | 787 | ||
784 | return uids( res ); | 788 | return uids( res ); |
785 | 789 | ||
786 | 790 | ||
787 | #endif | 791 | #endif |
@@ -789,89 +793,89 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | |||
789 | } | 793 | } |
790 | QBitArray OPimTodoAccessBackendSQL::supports()const { | 794 | QBitArray OPimTodoAccessBackendSQL::supports()const { |
791 | 795 | ||
792 | return sup(); | 796 | return sup(); |
793 | } | 797 | } |
794 | 798 | ||
795 | QBitArray OPimTodoAccessBackendSQL::sup() const{ | 799 | QBitArray OPimTodoAccessBackendSQL::sup() const{ |
796 | 800 | ||
797 | QBitArray ar( OPimTodo::CompletedDate + 1 ); | 801 | QBitArray ar( OPimTodo::CompletedDate + 1 ); |
798 | ar.fill( true ); | 802 | ar.fill( true ); |
799 | ar[OPimTodo::CrossReference] = false; | 803 | ar[OPimTodo::CrossReference] = false; |
800 | ar[OPimTodo::State ] = false; | 804 | ar[OPimTodo::State ] = false; |
801 | ar[OPimTodo::Reminders] = false; | 805 | ar[OPimTodo::Reminders] = false; |
802 | ar[OPimTodo::Notifiers] = false; | 806 | ar[OPimTodo::Notifiers] = false; |
803 | ar[OPimTodo::Maintainer] = false; | 807 | ar[OPimTodo::Maintainer] = false; |
804 | 808 | ||
805 | return ar; | 809 | return ar; |
806 | } | 810 | } |
807 | 811 | ||
808 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ | 812 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ |
809 | // First we need the uids from all entries which are | 813 | // First we need the uids from all entries which are |
810 | // completed. Then, we just have to remove them... | 814 | // completed. Then, we just have to remove them... |
811 | 815 | ||
812 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; | 816 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; |
813 | 817 | ||
814 | OSQLRawQuery raw( qu ); | 818 | OSQLRawQuery raw( qu ); |
815 | OSQLResult res = m_driver->query( &raw ); | 819 | OSQLResult res = m_driver->query( &raw ); |
816 | 820 | ||
817 | QArray<int> completed_uids = uids( res ); | 821 | QArray<int> completed_uids = uids( res ); |
818 | 822 | ||
819 | qDebug( "Number of completed: %d", completed_uids.size() ); | 823 | odebug << "Number of completed: " << completed_uids.size() << "" << oendl; |
820 | 824 | ||
821 | if ( completed_uids.size() == 0 ) | 825 | if ( completed_uids.size() == 0 ) |
822 | return; | 826 | return; |
823 | 827 | ||
824 | qu = "DELETE FROM todolist WHERE ("; | 828 | qu = "DELETE FROM todolist WHERE ("; |
825 | QString query; | 829 | QString query; |
826 | 830 | ||
827 | for ( int i = 0; i < completed_uids.size(); i++ ){ | 831 | for ( int i = 0; i < completed_uids.size(); i++ ){ |
828 | if ( !query.isEmpty() ) | 832 | if ( !query.isEmpty() ) |
829 | query += " OR "; | 833 | query += " OR "; |
830 | query += QString( "uid = %1" ).arg( completed_uids[i] ); | 834 | query += QString( "uid = %1" ).arg( completed_uids[i] ); |
831 | } | 835 | } |
832 | qu += query + " );"; | 836 | qu += query + " );"; |
833 | 837 | ||
834 | // Put remove of custom entries in this query to speed up.. | 838 | // Put remove of custom entries in this query to speed up.. |
835 | qu += "DELETE FORM custom_data WHERE ("; | 839 | qu += "DELETE FORM custom_data WHERE ("; |
836 | query = ""; | 840 | query = ""; |
837 | 841 | ||
838 | for ( int i = 0; i < completed_uids.size(); i++ ){ | 842 | for ( int i = 0; i < completed_uids.size(); i++ ){ |
839 | if ( !query.isEmpty() ) | 843 | if ( !query.isEmpty() ) |
840 | query += " OR "; | 844 | query += " OR "; |
841 | query += QString( "uid = %1" ).arg( completed_uids[i] ); | 845 | query += QString( "uid = %1" ).arg( completed_uids[i] ); |
842 | } | 846 | } |
843 | qu += query + " );"; | 847 | qu += query + " );"; |
844 | 848 | ||
845 | qDebug( "query: %s", qu.latin1() ); | 849 | odebug << "query: " << qu << "" << oendl; |
846 | 850 | ||
847 | OSQLRawQuery raw2( qu ); | 851 | OSQLRawQuery raw2( qu ); |
848 | res = m_driver->query( &raw2 ); | 852 | res = m_driver->query( &raw2 ); |
849 | if ( res.state() == OSQLResult::Failure ) { | 853 | if ( res.state() == OSQLResult::Failure ) { |
850 | qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() ); | 854 | owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; |
851 | } | 855 | } |
852 | } | 856 | } |
853 | 857 | ||
854 | 858 | ||
855 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const | 859 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const |
856 | { | 860 | { |
857 | QMap<QString, QString> customMap; | 861 | QMap<QString, QString> customMap; |
858 | 862 | ||
859 | FindCustomQuery query( uid ); | 863 | FindCustomQuery query( uid ); |
860 | OSQLResult res_custom = m_driver->query( &query ); | 864 | OSQLResult res_custom = m_driver->query( &query ); |
861 | 865 | ||
862 | if ( res_custom.state() == OSQLResult::Failure ) { | 866 | if ( res_custom.state() == OSQLResult::Failure ) { |
863 | qWarning("OSQLResult::Failure in find query !!"); | 867 | owarn << "OSQLResult::Failure in find query !!" << oendl; |
864 | QMap<QString, QString> empty; | 868 | QMap<QString, QString> empty; |
865 | return empty; | 869 | return empty; |
866 | } | 870 | } |
867 | 871 | ||
868 | OSQLResultItem::ValueList list = res_custom.results(); | 872 | OSQLResultItem::ValueList list = res_custom.results(); |
869 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 873 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
870 | for ( ; it != list.end(); ++it ) { | 874 | for ( ; it != list.end(); ++it ) { |
871 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 875 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
872 | } | 876 | } |
873 | 877 | ||
874 | return customMap; | 878 | return customMap; |
875 | } | 879 | } |
876 | 880 | ||
877 | 881 | ||