Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index 105c106..41b714e 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -158,26 +158,24 @@ bool ODateBookAccessBackend_SQL::load() | |||
158 | // It is save here to create the table, even if it | 158 | // It is save here to create the table, even if it |
159 | // do exist. ( Is that correct for all databases ?? ) | 159 | // do exist. ( Is that correct for all databases ?? ) |
160 | QString qu = "create table datebook( uid INTEGER PRIMARY KEY "; | 160 | QString qu = "create table datebook( uid INTEGER PRIMARY KEY "; |
161 | 161 | ||
162 | QMap<int, QString>::Iterator it; | 162 | QMap<int, QString>::Iterator it; |
163 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 163 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
164 | qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); | 164 | qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); |
165 | } | 165 | } |
166 | qu += " );"; | 166 | qu += " );"; |
167 | 167 | ||
168 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 168 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
169 | 169 | ||
170 | owarn << "command: " << qu << "" << oendl; | ||
171 | |||
172 | OSQLRawQuery raw( qu ); | 170 | OSQLRawQuery raw( qu ); |
173 | OSQLResult res = m_driver->query( &raw ); | 171 | OSQLResult res = m_driver->query( &raw ); |
174 | if ( res.state() != OSQLResult::Success ) | 172 | if ( res.state() != OSQLResult::Success ) |
175 | return false; | 173 | return false; |
176 | 174 | ||
177 | update(); | 175 | update(); |
178 | 176 | ||
179 | return true; | 177 | return true; |
180 | } | 178 | } |
181 | 179 | ||
182 | void ODateBookAccessBackend_SQL::update() | 180 | void ODateBookAccessBackend_SQL::update() |
183 | { | 181 | { |
@@ -279,25 +277,24 @@ bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) | |||
279 | qu += "insert into custom_data VALUES(" | 277 | qu += "insert into custom_data VALUES(" |
280 | + QString::number( ev.uid() ) | 278 | + QString::number( ev.uid() ) |
281 | + "," | 279 | + "," |
282 | + QString::number( id++ ) | 280 | + QString::number( id++ ) |
283 | + ",'" | 281 | + ",'" |
284 | + it.key() //.latin1() | 282 | + it.key() //.latin1() |
285 | + "'," | 283 | + "'," |
286 | + "0" // Priority for future enhancements | 284 | + "0" // Priority for future enhancements |
287 | + ",'" | 285 | + ",'" |
288 | + it.data() //.latin1() | 286 | + it.data() //.latin1() |
289 | + "');"; | 287 | + "');"; |
290 | } | 288 | } |
291 | owarn << "add " << qu << "" << oendl; | ||
292 | 289 | ||
293 | OSQLRawQuery raw( qu ); | 290 | OSQLRawQuery raw( qu ); |
294 | OSQLResult res = m_driver->query( &raw ); | 291 | OSQLResult res = m_driver->query( &raw ); |
295 | if ( res.state() != OSQLResult::Success ){ | 292 | if ( res.state() != OSQLResult::Success ){ |
296 | return false; | 293 | return false; |
297 | } | 294 | } |
298 | 295 | ||
299 | // Update list of uid's | 296 | // Update list of uid's |
300 | update(); | 297 | update(); |
301 | 298 | ||
302 | return true; | 299 | return true; |
303 | } | 300 | } |
@@ -319,28 +316,24 @@ bool ODateBookAccessBackend_SQL::remove( int uid ) | |||
319 | // Update list of uid's | 316 | // Update list of uid's |
320 | update(); | 317 | update(); |
321 | 318 | ||
322 | return true; | 319 | return true; |
323 | } | 320 | } |
324 | 321 | ||
325 | bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev ) | 322 | bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev ) |
326 | { | 323 | { |
327 | remove( ev.uid() ); | 324 | remove( ev.uid() ); |
328 | return add( ev ); | 325 | return add( ev ); |
329 | } | 326 | } |
330 | 327 | ||
331 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const | ||
332 | { | ||
333 | return allRecords(); | ||
334 | } | ||
335 | 328 | ||
336 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const | 329 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const |
337 | { | 330 | { |
338 | QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; | 331 | QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; |
339 | OSQLRawQuery raw( qu ); | 332 | OSQLRawQuery raw( qu ); |
340 | OSQLResult res = m_driver->query( &raw ); | 333 | OSQLResult res = m_driver->query( &raw ); |
341 | if ( res.state() != OSQLResult::Success ){ | 334 | if ( res.state() != OSQLResult::Success ){ |
342 | QArray<int> nix; | 335 | QArray<int> nix; |
343 | return nix; | 336 | return nix; |
344 | } | 337 | } |
345 | 338 | ||
346 | return extractUids( res ); | 339 | return extractUids( res ); |
@@ -350,37 +343,37 @@ QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const | |||
350 | { | 343 | { |
351 | QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; | 344 | QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; |
352 | OSQLRawQuery raw( qu ); | 345 | OSQLRawQuery raw( qu ); |
353 | OSQLResult res = m_driver->query( &raw ); | 346 | OSQLResult res = m_driver->query( &raw ); |
354 | if ( res.state() != OSQLResult::Success ){ | 347 | if ( res.state() != OSQLResult::Success ){ |
355 | QArray<int> nix; | 348 | QArray<int> nix; |
356 | return nix; | 349 | return nix; |
357 | } | 350 | } |
358 | 351 | ||
359 | return extractUids( res ); | 352 | return extractUids( res ); |
360 | } | 353 | } |
361 | 354 | ||
362 | OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() | 355 | OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()const |
363 | { | 356 | { |
364 | QArray<int> nonRepUids = nonRepeats(); | 357 | QArray<int> nonRepUids = nonRepeats(); |
365 | OPimEvent::ValueList list; | 358 | OPimEvent::ValueList list; |
366 | 359 | ||
367 | for (uint i = 0; i < nonRepUids.count(); ++i ){ | 360 | for (uint i = 0; i < nonRepUids.count(); ++i ){ |
368 | list.append( find( nonRepUids[i] ) ); | 361 | list.append( find( nonRepUids[i] ) ); |
369 | } | 362 | } |
370 | 363 | ||
371 | return list; | 364 | return list; |
372 | 365 | ||
373 | } | 366 | } |
374 | OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() | 367 | OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()const |
375 | { | 368 | { |
376 | QArray<int> rawRepUids = rawRepeats(); | 369 | QArray<int> rawRepUids = rawRepeats(); |
377 | OPimEvent::ValueList list; | 370 | OPimEvent::ValueList list; |
378 | 371 | ||
379 | for (uint i = 0; i < rawRepUids.count(); ++i ){ | 372 | for (uint i = 0; i < rawRepUids.count(); ++i ){ |
380 | list.append( find( rawRepUids[i] ) ); | 373 | list.append( find( rawRepUids[i] ) ); |
381 | } | 374 | } |
382 | 375 | ||
383 | return list; | 376 | return list; |
384 | } | 377 | } |
385 | 378 | ||
386 | 379 | ||
@@ -401,55 +394,51 @@ QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | |||
401 | OSQLResult res = m_driver->query( &raw ); | 394 | OSQLResult res = m_driver->query( &raw ); |
402 | 395 | ||
403 | return extractUids( res ); | 396 | return extractUids( res ); |
404 | 397 | ||
405 | 398 | ||
406 | 399 | ||
407 | } | 400 | } |
408 | 401 | ||
409 | /* ===== Private Functions ========================================== */ | 402 | /* ===== Private Functions ========================================== */ |
410 | 403 | ||
411 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const | 404 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const |
412 | { | 405 | { |
413 | owarn << "extractUids" << oendl; | ||
414 | QTime t; | 406 | QTime t; |
415 | t.start(); | 407 | t.start(); |
416 | OSQLResultItem::ValueList list = res.results(); | 408 | OSQLResultItem::ValueList list = res.results(); |
417 | OSQLResultItem::ValueList::Iterator it; | 409 | OSQLResultItem::ValueList::Iterator it; |
418 | QArray<int> ints(list.count() ); | 410 | QArray<int> ints(list.count() ); |
419 | owarn << " count = " << list.count() << "" << oendl; | ||
420 | 411 | ||
421 | int i = 0; | 412 | int i = 0; |
422 | for (it = list.begin(); it != list.end(); ++it ) { | 413 | for (it = list.begin(); it != list.end(); ++it ) { |
423 | ints[i] = (*it).data("uid").toInt(); | 414 | ints[i] = (*it).data("uid").toInt(); |
424 | i++; | 415 | i++; |
425 | } | 416 | } |
426 | owarn << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; | ||
427 | 417 | ||
428 | return ints; | 418 | return ints; |
429 | 419 | ||
430 | } | 420 | } |
431 | 421 | ||
432 | QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const | 422 | QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const |
433 | { | 423 | { |
434 | QTime t; | 424 | QTime t; |
435 | t.start(); | 425 | t.start(); |
436 | 426 | ||
437 | QMap<QString, QString> customMap; | 427 | QMap<QString, QString> customMap; |
438 | 428 | ||
439 | FindCustomQuery query( uid ); | 429 | FindCustomQuery query( uid ); |
440 | OSQLResult res_custom = m_driver->query( &query ); | 430 | OSQLResult res_custom = m_driver->query( &query ); |
441 | 431 | ||
442 | if ( res_custom.state() == OSQLResult::Failure ) { | 432 | if ( res_custom.state() == OSQLResult::Failure ) { |
443 | owarn << "OSQLResult::Failure in find query !!" << oendl; | ||
444 | QMap<QString, QString> empty; | 433 | QMap<QString, QString> empty; |
445 | return empty; | 434 | return empty; |
446 | } | 435 | } |
447 | 436 | ||
448 | OSQLResultItem::ValueList list = res_custom.results(); | 437 | OSQLResultItem::ValueList list = res_custom.results(); |
449 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 438 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
450 | for ( ; it != list.end(); ++it ) { | 439 | for ( ; it != list.end(); ++it ) { |
451 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 440 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
452 | } | 441 | } |
453 | 442 | ||
454 | odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; | 443 | odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; |
455 | return customMap; | 444 | return customMap; |