summaryrefslogtreecommitdiff
authoreilers <eilers>2004-04-12 17:46:08 (UTC)
committer eilers <eilers>2004-04-12 17:46:08 (UTC)
commit78a8f4f240bb57fe4942a30085e6a84fb3c4bac6 (patch) (unidiff)
tree23345a150cbc71ad8ad805fd1c8fa5522e10593f
parente8592cb2da1719d9ab1dc9e1144810af6af39e84 (diff)
downloadopie-78a8f4f240bb57fe4942a30085e6a84fb3c4bac6.zip
opie-78a8f4f240bb57fe4942a30085e6a84fb3c4bac6.tar.gz
opie-78a8f4f240bb57fe4942a30085e6a84fb3c4bac6.tar.bz2
Implementing regexp search. OSearch works now..
todo: Implemented removal of finished todo items..
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp24
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp75
2 files changed, 80 insertions, 19 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index 8a8cb0b..495a8dd 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -160,149 +160,153 @@ bool ODateBookAccessBackend_SQL::load()
160 } 160 }
161 qu += " );"; 161 qu += " );";
162 162
163 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; 163 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
164 164
165 qWarning( "command: %s", qu.latin1() ); 165 qWarning( "command: %s", qu.latin1() );
166 166
167 OSQLRawQuery raw( qu ); 167 OSQLRawQuery raw( qu );
168 OSQLResult res = m_driver->query( &raw ); 168 OSQLResult res = m_driver->query( &raw );
169 if ( res.state() != OSQLResult::Success ) 169 if ( res.state() != OSQLResult::Success )
170 return false; 170 return false;
171 171
172 update(); 172 update();
173 173
174 return true; 174 return true;
175} 175}
176 176
177void ODateBookAccessBackend_SQL::update() 177void ODateBookAccessBackend_SQL::update()
178{ 178{
179 179
180 QString qu = "select uid from datebook"; 180 QString qu = "select uid from datebook";
181 OSQLRawQuery raw( qu ); 181 OSQLRawQuery raw( qu );
182 OSQLResult res = m_driver->query( &raw ); 182 OSQLResult res = m_driver->query( &raw );
183 if ( res.state() != OSQLResult::Success ){ 183 if ( res.state() != OSQLResult::Success ){
184 // m_uids.clear(); 184 // m_uids.clear();
185 return; 185 return;
186 } 186 }
187 187
188 m_uids = extractUids( res ); 188 m_uids = extractUids( res );
189 189
190} 190}
191 191
192bool ODateBookAccessBackend_SQL::reload() 192bool ODateBookAccessBackend_SQL::reload()
193{ 193{
194 return load(); 194 return load();
195} 195}
196 196
197bool ODateBookAccessBackend_SQL::save() 197bool ODateBookAccessBackend_SQL::save()
198{ 198{
199 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 199 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
200} 200}
201 201
202QArray<int> ODateBookAccessBackend_SQL::allRecords()const 202QArray<int> ODateBookAccessBackend_SQL::allRecords()const
203{ 203{
204 return m_uids; 204 return m_uids;
205} 205}
206 206
207QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) { 207QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) {
208 return QArray<int>(); 208 return QArray<int>();
209} 209}
210 210
211void ODateBookAccessBackend_SQL::clear() 211void ODateBookAccessBackend_SQL::clear()
212{ 212{
213 QString qu = "drop table datebook;"; 213 QString qu = "drop table datebook;";
214 qu += "drop table custom_data;"; 214 qu += "drop table custom_data;";
215 215
216 OSQLRawQuery raw( qu ); 216 OSQLRawQuery raw( qu );
217 OSQLResult res = m_driver->query( &raw ); 217 OSQLResult res = m_driver->query( &raw );
218 218
219 reload(); 219 reload();
220} 220}
221 221
222 222
223OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ 223OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
224 qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid );
225
224 QString qu = "select *"; 226 QString qu = "select *";
225 qu += "from datebook where uid = " + QString::number(uid); 227 qu += "from datebook where uid = " + QString::number(uid);
226 228
227 OSQLRawQuery raw( qu ); 229 OSQLRawQuery raw( qu );
228 OSQLResult res = m_driver->query( &raw ); 230 OSQLResult res = m_driver->query( &raw );
229 231
230 OSQLResultItem resItem = res.first(); 232 OSQLResultItem resItem = res.first();
231 233
232 // Create Map for date event and insert UID 234 // Create Map for date event and insert UID
233 QMap<int,QString> dateEventMap; 235 QMap<int,QString> dateEventMap;
234 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) ); 236 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) );
235 237
236 // Now insert the data out of the columns into the map. 238 // Now insert the data out of the columns into the map.
237 QMapConstIterator<int, QString> it; 239 QMapConstIterator<int, QString> it;
238 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 240 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
239 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); 241 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) );
240 } 242 }
241 243
242 // Last step: Put map into date event, add custom map and return it 244 // Last step: Put map into date event, add custom map and return it
243 OPimEvent retDate( dateEventMap ); 245 OPimEvent retDate( dateEventMap );
244 retDate.setExtraMap( requestCustom( uid ) ); 246 retDate.setExtraMap( requestCustom( uid ) );
247
248 qDebug( "ODateBookAccessBackend_SQL::find() end", uid );
245 return retDate; 249 return retDate;
246} 250}
247 251
248// FIXME: Speed up update of uid's.. 252// FIXME: Speed up update of uid's..
249bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) 253bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
250{ 254{
251 QMap<int,QString> eventMap = ev.toMap(); 255 QMap<int,QString> eventMap = ev.toMap();
252 256
253 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); 257 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() );
254 QMap<int, QString>::Iterator it; 258 QMap<int, QString>::Iterator it;
255 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 259 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
256 if ( !eventMap[it.key()].isEmpty() ) 260 if ( !eventMap[it.key()].isEmpty() )
257 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); 261 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] );
258 else 262 else
259 qu += QString( ",\"\"" ); 263 qu += QString( ",\"\"" );
260 } 264 }
261 qu += " );"; 265 qu += " );";
262 266
263 // Add custom entries 267 // Add custom entries
264 int id = 0; 268 int id = 0;
265 QMap<QString, QString> customMap = ev.toExtraMap(); 269 QMap<QString, QString> customMap = ev.toExtraMap();
266 for( QMap<QString, QString>::Iterator it = customMap.begin(); 270 for( QMap<QString, QString>::Iterator it = customMap.begin();
267 it != customMap.end(); ++it ){ 271 it != customMap.end(); ++it ){
268 qu += "insert into custom_data VALUES(" 272 qu += "insert into custom_data VALUES("
269 + QString::number( ev.uid() ) 273 + QString::number( ev.uid() )
270 + "," 274 + ","
271 + QString::number( id++ ) 275 + QString::number( id++ )
272 + ",'" 276 + ",'"
273 + it.key() //.latin1() 277 + it.key() //.latin1()
274 + "'," 278 + "',"
275 + "0" // Priority for future enhancements 279 + "0" // Priority for future enhancements
276 + ",'" 280 + ",'"
277 + it.data() //.latin1() 281 + it.data() //.latin1()
278 + "');"; 282 + "');";
279 } 283 }
280 qWarning("add %s", qu.latin1() ); 284 qWarning("add %s", qu.latin1() );
281 285
282 OSQLRawQuery raw( qu ); 286 OSQLRawQuery raw( qu );
283 OSQLResult res = m_driver->query( &raw ); 287 OSQLResult res = m_driver->query( &raw );
284 if ( res.state() != OSQLResult::Success ){ 288 if ( res.state() != OSQLResult::Success ){
285 return false; 289 return false;
286 } 290 }
287 291
288 // Update list of uid's 292 // Update list of uid's
289 update(); 293 update();
290 294
291 return true; 295 return true;
292} 296}
293 297
294// FIXME: Speed up update of uid's.. 298// FIXME: Speed up update of uid's..
295bool ODateBookAccessBackend_SQL::remove( int uid ) 299bool ODateBookAccessBackend_SQL::remove( int uid )
296{ 300{
297 QString qu = "DELETE from datebook where uid = " 301 QString qu = "DELETE from datebook where uid = "
298 + QString::number( uid ) + ";"; 302 + QString::number( uid ) + ";";
299 qu += "DELETE from custom_data where uid = " 303 qu += "DELETE from custom_data where uid = "
300 + QString::number( uid ) + ";"; 304 + QString::number( uid ) + ";";
301 305
302 OSQLRawQuery raw( qu ); 306 OSQLRawQuery raw( qu );
303 OSQLResult res = m_driver->query( &raw ); 307 OSQLResult res = m_driver->query( &raw );
304 if ( res.state() != OSQLResult::Success ){ 308 if ( res.state() != OSQLResult::Success ){
305 return false; 309 return false;
306 } 310 }
307 311
308 // Update list of uid's 312 // Update list of uid's
@@ -314,119 +318,135 @@ bool ODateBookAccessBackend_SQL::remove( int uid )
314bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev ) 318bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev )
315{ 319{
316 remove( ev.uid() ); 320 remove( ev.uid() );
317 return add( ev ); 321 return add( ev );
318} 322}
319 323
320QArray<int> ODateBookAccessBackend_SQL::rawEvents()const 324QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
321{ 325{
322 return allRecords(); 326 return allRecords();
323} 327}
324 328
325QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const 329QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
326{ 330{
327 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; 331 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\"";
328 OSQLRawQuery raw( qu ); 332 OSQLRawQuery raw( qu );
329 OSQLResult res = m_driver->query( &raw ); 333 OSQLResult res = m_driver->query( &raw );
330 if ( res.state() != OSQLResult::Success ){ 334 if ( res.state() != OSQLResult::Success ){
331 QArray<int> nix; 335 QArray<int> nix;
332 return nix; 336 return nix;
333 } 337 }
334 338
335 return extractUids( res ); 339 return extractUids( res );
336} 340}
337 341
338QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const 342QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
339{ 343{
340 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; 344 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\"";
341 OSQLRawQuery raw( qu ); 345 OSQLRawQuery raw( qu );
342 OSQLResult res = m_driver->query( &raw ); 346 OSQLResult res = m_driver->query( &raw );
343 if ( res.state() != OSQLResult::Success ){ 347 if ( res.state() != OSQLResult::Success ){
344 QArray<int> nix; 348 QArray<int> nix;
345 return nix; 349 return nix;
346 } 350 }
347 351
348 return extractUids( res ); 352 return extractUids( res );
349} 353}
350 354
351OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() 355OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
352{ 356{
353 QArray<int> nonRepUids = nonRepeats(); 357 QArray<int> nonRepUids = nonRepeats();
354 OPimEvent::ValueList list; 358 OPimEvent::ValueList list;
355 359
356 for (uint i = 0; i < nonRepUids.count(); ++i ){ 360 for (uint i = 0; i < nonRepUids.count(); ++i ){
357 list.append( find( nonRepUids[i] ) ); 361 list.append( find( nonRepUids[i] ) );
358 } 362 }
359 363
360 return list; 364 return list;
361 365
362} 366}
363OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() 367OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
364{ 368{
365 QArray<int> rawRepUids = rawRepeats(); 369 QArray<int> rawRepUids = rawRepeats();
366 OPimEvent::ValueList list; 370 OPimEvent::ValueList list;
367 371
368 for (uint i = 0; i < rawRepUids.count(); ++i ){ 372 for (uint i = 0; i < rawRepUids.count(); ++i ){
369 list.append( find( rawRepUids[i] ) ); 373 list.append( find( rawRepUids[i] ) );
370 } 374 }
371 375
372 return list; 376 return list;
373} 377}
374 378
375 379
376QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 380QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
377{ 381{
378 QArray<int> null; 382
379 return null; 383 QString qu = "SELECT uid FROM datebook WHERE (";
384
385 // Do it make sense to search other fields, too ?
386 qu += " rlike(\""+ r.pattern() + "\", Location ) OR";
387 qu += " rlike(\""+ r.pattern() + "\", Note )";
388
389 qu += " )";
390
391 qDebug( "query: %s", qu.latin1() );
392
393 OSQLRawQuery raw( qu );
394 OSQLResult res = m_driver->query( &raw );
395
396 return extractUids( res );
397
398
399
380} 400}
381 401
382/* ===== Private Functions ========================================== */ 402/* ===== Private Functions ========================================== */
383 403
384QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const 404QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
385{ 405{
386 qWarning("extractUids"); 406 qWarning("extractUids");
387 QTime t; 407 QTime t;
388 t.start(); 408 t.start();
389 OSQLResultItem::ValueList list = res.results(); 409 OSQLResultItem::ValueList list = res.results();
390 OSQLResultItem::ValueList::Iterator it; 410 OSQLResultItem::ValueList::Iterator it;
391 QArray<int> ints(list.count() ); 411 QArray<int> ints(list.count() );
392 qWarning(" count = %d", list.count() ); 412 qWarning(" count = %d", list.count() );
393 413
394 int i = 0; 414 int i = 0;
395 for (it = list.begin(); it != list.end(); ++it ) { 415 for (it = list.begin(); it != list.end(); ++it ) {
396 ints[i] = (*it).data("uid").toInt(); 416 ints[i] = (*it).data("uid").toInt();
397 i++; 417 i++;
398 } 418 }
399 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); 419 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() );
400 420
401 return ints; 421 return ints;
402 422
403} 423}
404 424
405QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const 425QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const
406{ 426{
407 QTime t; 427 QTime t;
408 t.start(); 428 t.start();
409 429
410 QMap<QString, QString> customMap; 430 QMap<QString, QString> customMap;
411 431
412 FindCustomQuery query( uid ); 432 FindCustomQuery query( uid );
413 OSQLResult res_custom = m_driver->query( &query ); 433 OSQLResult res_custom = m_driver->query( &query );
414 434
415 if ( res_custom.state() == OSQLResult::Failure ) { 435 if ( res_custom.state() == OSQLResult::Failure ) {
416 qWarning("OSQLResult::Failure in find query !!"); 436 qWarning("OSQLResult::Failure in find query !!");
417 QMap<QString, QString> empty; 437 QMap<QString, QString> empty;
418 return empty; 438 return empty;
419 } 439 }
420 440
421 OSQLResultItem::ValueList list = res_custom.results(); 441 OSQLResultItem::ValueList list = res_custom.results();
422 OSQLResultItem::ValueList::Iterator it = list.begin(); 442 OSQLResultItem::ValueList::Iterator it = list.begin();
423 for ( ; it != list.end(); ++it ) { 443 for ( ; it != list.end(); ++it ) {
424 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 444 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
425 } 445 }
426 446
427 qDebug("RequestCustom needed: %d ms", t.elapsed() ); 447 qDebug("RequestCustom needed: %d ms", t.elapsed() );
428 return customMap; 448 return customMap;
429} 449}
430 450
431 451
432} 452}
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index b4170fc..ef036d5 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -238,129 +238,130 @@ namespace {
238 + "'" + m_todo.description() + "'" + "," 238 + "'" + m_todo.description() + "'" + ","
239 + "'" + m_todo.summary() + "'" + "," 239 + "'" + m_todo.summary() + "'" + ","
240 + QString::number(m_todo.priority() ) + "," 240 + QString::number(m_todo.priority() ) + ","
241 + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" 241 + "'" + QString::number(year).rightJustify( 4, '0' ) + "-"
242 + QString::number(month).rightJustify( 2, '0' ) 242 + QString::number(month).rightJustify( 2, '0' )
243 + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," 243 + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + ","
244 + QString::number( m_todo.progress() ) + "," 244 + QString::number( m_todo.progress() ) + ","
245 + QString::number( m_todo.state().state() ) + "," 245 + QString::number( m_todo.state().state() ) + ","
246 + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," 246 + "'" + recMap[ OPimRecurrence::RType ] + "'" + ","
247 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," 247 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + ","
248 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," 248 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + ","
249 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," 249 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + ","
250 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," 250 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + ","
251 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," 251 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + ","
252 + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," 252 + "'" + recMap[ OPimRecurrence::Created ] + "'" + ","
253 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; 253 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ",";
254 254
255 if ( m_todo.hasNotifiers() ) { 255 if ( m_todo.hasNotifiers() ) {
256 OPimNotifyManager manager = m_todo.notifiers(); 256 OPimNotifyManager manager = m_todo.notifiers();
257 qu += "'" + manager.remindersToString() + "'" + "," 257 qu += "'" + manager.remindersToString() + "'" + ","
258 + "'" + manager.alarmsToString() + "'" + ","; 258 + "'" + manager.alarmsToString() + "'" + ",";
259 } 259 }
260 else{ 260 else{
261 qu += QString( "''" ) + "," 261 qu += QString( "''" ) + ","
262 + "''" + ","; 262 + "''" + ",";
263 } 263 }
264 264
265 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) 265 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
266 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" 266 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-"
267 + QString::number(sMonth).rightJustify( 2, '0' ) 267 + QString::number(sMonth).rightJustify( 2, '0' )
268 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," 268 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + ","
269 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" 269 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-"
270 + QString::number(eMonth).rightJustify( 2, '0' ) 270 + QString::number(eMonth).rightJustify( 2, '0' )
271 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" 271 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'"
272 + ")"; 272 + ")";
273 273
274 // Save custom Entries: 274 // Save custom Entries:
275 int id = 0; 275 int id = 0;
276 id = 0; 276 id = 0;
277 QMap<QString, QString> customMap = m_todo.toExtraMap(); 277 QMap<QString, QString> customMap = m_todo.toExtraMap();
278 for( QMap<QString, QString>::Iterator it = customMap.begin(); 278 for( QMap<QString, QString>::Iterator it = customMap.begin();
279 it != customMap.end(); ++it ){ 279 it != customMap.end(); ++it ){
280 qu += "insert into custom_data VALUES(" 280 qu += "insert into custom_data VALUES("
281 + QString::number( m_todo.uid() ) 281 + QString::number( m_todo.uid() )
282 + "," 282 + ","
283 + QString::number( id++ ) 283 + QString::number( id++ )
284 + ",'" 284 + ",'"
285 + it.key() 285 + it.key()
286 + "'," 286 + "',"
287 + "0" // Priority for future enhancements 287 + "0" // Priority for future enhancements
288 + ",'" 288 + ",'"
289 + it.data() 289 + it.data()
290 + "');"; 290 + "');";
291 } 291 }
292 292
293 293
294 qDebug("add %s", qu.latin1() ); 294 qDebug("add %s", qu.latin1() );
295 return qu; 295 return qu;
296 } 296 }
297 297
298 RemoveQuery::RemoveQuery(int uid ) 298 RemoveQuery::RemoveQuery(int uid )
299 : OSQLQuery(), m_uid( uid ) {} 299 : OSQLQuery(), m_uid( uid ) {}
300 RemoveQuery::~RemoveQuery() {} 300 RemoveQuery::~RemoveQuery() {}
301 QString RemoveQuery::query()const { 301 QString RemoveQuery::query()const {
302 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); 302 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;";
303 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
303 return qu; 304 return qu;
304 } 305 }
305 306
306 307
307 ClearQuery::ClearQuery() 308 ClearQuery::ClearQuery()
308 : OSQLQuery() {} 309 : OSQLQuery() {}
309 ClearQuery::~ClearQuery() {} 310 ClearQuery::~ClearQuery() {}
310 QString ClearQuery::query()const { 311 QString ClearQuery::query()const {
311 QString qu = "drop table todolist"; 312 QString qu = "drop table todolist";
312 return qu; 313 return qu;
313 } 314 }
314 FindQuery::FindQuery(int uid) 315 FindQuery::FindQuery(int uid)
315 : OSQLQuery(), m_uid(uid ) { 316 : OSQLQuery(), m_uid(uid ) {
316 } 317 }
317 FindQuery::FindQuery(const QArray<int>& ints) 318 FindQuery::FindQuery(const QArray<int>& ints)
318 : OSQLQuery(), m_uids(ints){ 319 : OSQLQuery(), m_uids(ints){
319 } 320 }
320 FindQuery::~FindQuery() { 321 FindQuery::~FindQuery() {
321 } 322 }
322 QString FindQuery::query()const{ 323 QString FindQuery::query()const{
323 if (m_uids.count() == 0 ) 324 if (m_uids.count() == 0 )
324 return single(); 325 return single();
325 else 326 else
326 return multi(); 327 return multi();
327 } 328 }
328 QString FindQuery::single()const{ 329 QString FindQuery::single()const{
329 QString qu = "select * from todolist where uid = " + QString::number(m_uid); 330 QString qu = "select * from todolist where uid = " + QString::number(m_uid);
330 return qu; 331 return qu;
331 } 332 }
332 QString FindQuery::multi()const { 333 QString FindQuery::multi()const {
333 QString qu = "select * from todolist where "; 334 QString qu = "select * from todolist where ";
334 for (uint i = 0; i < m_uids.count(); i++ ) { 335 for (uint i = 0; i < m_uids.count(); i++ ) {
335 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 336 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
336 } 337 }
337 qu.remove( qu.length()-2, 2 ); 338 qu.remove( qu.length()-2, 2 );
338 return qu; 339 return qu;
339 } 340 }
340 341
341 OverDueQuery::OverDueQuery(): OSQLQuery() {} 342 OverDueQuery::OverDueQuery(): OSQLQuery() {}
342 OverDueQuery::~OverDueQuery() {} 343 OverDueQuery::~OverDueQuery() {}
343 QString OverDueQuery::query()const { 344 QString OverDueQuery::query()const {
344 QDate date = QDate::currentDate(); 345 QDate date = QDate::currentDate();
345 QString str; 346 QString str;
346 str = QString("select uid from todolist where DueDate ='%1-%2-%3'") 347 str = QString("select uid from todolist where DueDate ='%1-%2-%3'")
347 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) 348 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
348 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) 349 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
349 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); 350 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) );
350 351
351 return str; 352 return str;
352 } 353 }
353 354
354 355
355 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 356 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
356 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 357 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
357 EffQuery::~EffQuery() {} 358 EffQuery::~EffQuery() {}
358 QString EffQuery::query()const { 359 QString EffQuery::query()const {
359 return m_inc ? with() : out(); 360 return m_inc ? with() : out();
360 } 361 }
361 QString EffQuery::with()const { 362 QString EffQuery::with()const {
362 QString str; 363 QString str;
363 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 364 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
364 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) 365 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
365 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) 366 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
366 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) 367 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
@@ -701,139 +702,179 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
701 FindQuery find( uid ); 702 FindQuery find( uid );
702 return todo( m_driver->query(&find) ); 703 return todo( m_driver->query(&find) );
703} 704}
704/* 705/*
705 * update the dict 706 * update the dict
706 */ 707 */
707void OPimTodoAccessBackendSQL::fillDict() { 708void OPimTodoAccessBackendSQL::fillDict() {
708 709
709#if 0 710#if 0
710 /* initialize dict */ 711 /* initialize dict */
711 /* 712 /*
712 * UPDATE dict if you change anything!!! 713 * UPDATE dict if you change anything!!!
713 * FIXME: Isn't this dict obsolete ? (eilers) 714 * FIXME: Isn't this dict obsolete ? (eilers)
714 */ 715 */
715 m_dict.setAutoDelete( TRUE ); 716 m_dict.setAutoDelete( TRUE );
716 m_dict.insert("Categories" , new int(OPimTodo::Category) ); 717 m_dict.insert("Categories" , new int(OPimTodo::Category) );
717 m_dict.insert("Uid" , new int(OPimTodo::Uid) ); 718 m_dict.insert("Uid" , new int(OPimTodo::Uid) );
718 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); 719 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) );
719 m_dict.insert("Completed" , new int(OPimTodo::Completed) ); 720 m_dict.insert("Completed" , new int(OPimTodo::Completed) );
720 m_dict.insert("Description" , new int(OPimTodo::Description) ); 721 m_dict.insert("Description" , new int(OPimTodo::Description) );
721 m_dict.insert("Summary" , new int(OPimTodo::Summary) ); 722 m_dict.insert("Summary" , new int(OPimTodo::Summary) );
722 m_dict.insert("Priority" , new int(OPimTodo::Priority) ); 723 m_dict.insert("Priority" , new int(OPimTodo::Priority) );
723 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); 724 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) );
724 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); 725 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) );
725 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); 726 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) );
726 m_dict.insert("Progress" , new int(OPimTodo::Progress) ); 727 m_dict.insert("Progress" , new int(OPimTodo::Progress) );
727 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) 728 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers)
728 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); 729 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) );
729// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) 730// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers)
730// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) 731// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers)
731 732
732#endif 733#endif
733} 734}
734/* 735/*
735 * need to be const so let's fool the 736 * need to be const so let's fool the
736 * compiler :( 737 * compiler :(
737 */ 738 */
738void OPimTodoAccessBackendSQL::update()const { 739void OPimTodoAccessBackendSQL::update()const {
739 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; 740 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false;
740 LoadQuery lo; 741 LoadQuery lo;
741 OSQLResult res = m_driver->query(&lo); 742 OSQLResult res = m_driver->query(&lo);
742 if ( res.state() != OSQLResult::Success ) 743 if ( res.state() != OSQLResult::Success )
743 return; 744 return;
744 745
745 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); 746 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res );
746} 747}
747QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 748QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
748 749
749 OSQLResultItem::ValueList list = res.results(); 750 OSQLResultItem::ValueList list = res.results();
750 OSQLResultItem::ValueList::Iterator it; 751 OSQLResultItem::ValueList::Iterator it;
751 QArray<int> ints(list.count() ); 752 QArray<int> ints(list.count() );
752 qDebug(" count = %d", list.count() ); 753 qDebug(" count = %d", list.count() );
753 754
754 int i = 0; 755 int i = 0;
755 for (it = list.begin(); it != list.end(); ++it ) { 756 for (it = list.begin(); it != list.end(); ++it ) {
756 ints[i] = (*it).data("uid").toInt(); 757 ints[i] = (*it).data("uid").toInt();
757 i++; 758 i++;
758 } 759 }
759 return ints; 760 return ints;
760} 761}
761 762
762QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const 763QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
763{ 764{
764 765
765#warning OPimTodoAccessBackendSQL::matchRegexp() not implemented !!
766
767#if 0 766#if 0
767 QArray<int> empty;
768 return empty;
768 769
769 Copied from xml-backend by not adapted to sql (eilers) 770#else
771 QString qu = "SELECT uid FROM todolist WHERE (";
770 772
771 QArray<int> m_currentQuery( m_events.count() ); 773 // Do it make sense to search other fields, too ?
772 uint arraycounter = 0; 774 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR";
775 qu += " rlike(\""+ r.pattern() + "\",\"summary\")";
776
777 qu += ")";
773 778
779 qDebug( "query: %s", qu.latin1() );
774 780
781 OSQLRawQuery raw( qu );
782 OSQLResult res = m_driver->query( &raw );
775 783
776 QMap<int, OPimTodo>::ConstIterator it; 784 return uids( res );
777 for (it = m_events.begin(); it != m_events.end(); ++it ) {
778 if ( it.data().match( r ) )
779 m_currentQuery[arraycounter++] = it.data().uid();
780 785
781 }
782 // Shrink to fit..
783 m_currentQuery.resize(arraycounter);
784 786
785 return m_currentQuery;
786#endif 787#endif
787 QArray<int> empty; 788
788 return empty;
789} 789}
790QBitArray OPimTodoAccessBackendSQL::supports()const { 790QBitArray OPimTodoAccessBackendSQL::supports()const {
791 791
792 return sup(); 792 return sup();
793} 793}
794 794
795QBitArray OPimTodoAccessBackendSQL::sup() const{ 795QBitArray OPimTodoAccessBackendSQL::sup() const{
796 796
797 QBitArray ar( OPimTodo::CompletedDate + 1 ); 797 QBitArray ar( OPimTodo::CompletedDate + 1 );
798 ar.fill( true ); 798 ar.fill( true );
799 ar[OPimTodo::CrossReference] = false; 799 ar[OPimTodo::CrossReference] = false;
800 ar[OPimTodo::State ] = false; 800 ar[OPimTodo::State ] = false;
801 ar[OPimTodo::Reminders] = false; 801 ar[OPimTodo::Reminders] = false;
802 ar[OPimTodo::Notifiers] = false; 802 ar[OPimTodo::Notifiers] = false;
803 ar[OPimTodo::Maintainer] = false; 803 ar[OPimTodo::Maintainer] = false;
804 804
805 return ar; 805 return ar;
806} 806}
807 807
808void OPimTodoAccessBackendSQL::removeAllCompleted(){ 808void OPimTodoAccessBackendSQL::removeAllCompleted(){
809#warning OPimTodoAccessBackendSQL::removeAllCompleted() not implemented !! 809 // First we need the uids from all entries which are
810 // completed. Then, we just have to remove them...
811
812 QString qu = "SELECT uid FROM todolist WHERE completed = 1";
813
814 OSQLRawQuery raw( qu );
815 OSQLResult res = m_driver->query( &raw );
816
817 QArray<int> completed_uids = uids( res );
810 818
819 qDebug( "Number of completed: %d", completed_uids.size() );
820
821 if ( completed_uids.size() == 0 )
822 return;
823
824 qu = "DELETE FROM todolist WHERE (";
825 QString query;
826
827 for ( int i = 0; i < completed_uids.size(); i++ ){
828 if ( !query.isEmpty() )
829 query += " OR ";
830 query += QString( "uid = %1" ).arg( completed_uids[i] );
831 }
832 qu += query + " );";
833
834 // Put remove of custom entries in this query to speed up..
835 qu += "DELETE FORM custom_data WHERE (";
836 query = "";
837
838 for ( int i = 0; i < completed_uids.size(); i++ ){
839 if ( !query.isEmpty() )
840 query += " OR ";
841 query += QString( "uid = %1" ).arg( completed_uids[i] );
842 }
843 qu += query + " );";
844
845 qDebug( "query: %s", qu.latin1() );
846
847 OSQLRawQuery raw2( qu );
848 res = m_driver->query( &raw2 );
849 if ( res.state() == OSQLResult::Failure ) {
850 qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() );
851 }
811} 852}
812 853
813 854
814QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const 855QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
815{ 856{
816 QMap<QString, QString> customMap; 857 QMap<QString, QString> customMap;
817 858
818 FindCustomQuery query( uid ); 859 FindCustomQuery query( uid );
819 OSQLResult res_custom = m_driver->query( &query ); 860 OSQLResult res_custom = m_driver->query( &query );
820 861
821 if ( res_custom.state() == OSQLResult::Failure ) { 862 if ( res_custom.state() == OSQLResult::Failure ) {
822 qWarning("OSQLResult::Failure in find query !!"); 863 qWarning("OSQLResult::Failure in find query !!");
823 QMap<QString, QString> empty; 864 QMap<QString, QString> empty;
824 return empty; 865 return empty;
825 } 866 }
826 867
827 OSQLResultItem::ValueList list = res_custom.results(); 868 OSQLResultItem::ValueList list = res_custom.results();
828 OSQLResultItem::ValueList::Iterator it = list.begin(); 869 OSQLResultItem::ValueList::Iterator it = list.begin();
829 for ( ; it != list.end(); ++it ) { 870 for ( ; it != list.end(); ++it ) {
830 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 871 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
831 } 872 }
832 873
833 return customMap; 874 return customMap;
834} 875}
835 876
836 877
837 878
838 879
839} 880}