summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index f4f3c94..105c106 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -28,26 +28,31 @@
28*/ 28*/
29/* 29/*
30 * SQL Backend for the OPIE-Calender Database. 30 * SQL Backend for the OPIE-Calender Database.
31 * 31 *
32 */ 32 */
33 33
34#include <stdio.h> 34/* OPIE */
35#include <stdlib.h>
36
37#include <qarray.h>
38#include <qstringlist.h>
39
40#include <qpe/global.h>
41
42#include <opie2/osqldriver.h> 35#include <opie2/osqldriver.h>
43#include <opie2/osqlmanager.h> 36#include <opie2/osqlmanager.h>
44#include <opie2/osqlquery.h> 37#include <opie2/osqlquery.h>
45 38
46#include <opie2/opimrecurrence.h> 39#include <opie2/opimrecurrence.h>
47#include <opie2/odatebookaccessbackend_sql.h> 40#include <opie2/odatebookaccessbackend_sql.h>
41#include <opie2/odebug.h>
42
43#include <qpe/global.h>
44
45/* QT */
46#include <qarray.h>
47#include <qstringlist.h>
48
49/* STD */
50#include <stdio.h>
51#include <stdlib.h>
52
48 53
49using namespace Opie::DB; 54using namespace Opie::DB;
50 55
51namespace { 56namespace {
52 /** 57 /**
53 * a find query for custom elements 58 * a find query for custom elements
@@ -159,13 +164,13 @@ bool ODateBookAccessBackend_SQL::load()
159 qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); 164 qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() );
160 } 165 }
161 qu += " );"; 166 qu += " );";
162 167
163 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) );";
164 169
165 qWarning( "command: %s", qu.latin1() ); 170 owarn << "command: " << qu << "" << oendl;
166 171
167 OSQLRawQuery raw( qu ); 172 OSQLRawQuery raw( qu );
168 OSQLResult res = m_driver->query( &raw ); 173 OSQLResult res = m_driver->query( &raw );
169 if ( res.state() != OSQLResult::Success ) 174 if ( res.state() != OSQLResult::Success )
170 return false; 175 return false;
171 176
@@ -218,18 +223,18 @@ void ODateBookAccessBackend_SQL::clear()
218 223
219 reload(); 224 reload();
220} 225}
221 226
222 227
223OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ 228OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
224 qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid ); 229 odebug << "ODateBookAccessBackend_SQL::find( " << uid << " )" << oendl;
225 230
226 QString qu = "select *"; 231 QString qu = "select *";
227 qu += "from datebook where uid = " + QString::number(uid); 232 qu += "from datebook where uid = " + QString::number(uid);
228 233
229 qDebug( "Query: %s", qu.latin1() ); 234 odebug << "Query: " << qu << "" << oendl;
230 235
231 OSQLRawQuery raw( qu ); 236 OSQLRawQuery raw( qu );
232 OSQLResult res = m_driver->query( &raw ); 237 OSQLResult res = m_driver->query( &raw );
233 238
234 OSQLResultItem resItem = res.first(); 239 OSQLResultItem resItem = res.first();
235 240
@@ -244,13 +249,13 @@ OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
244 } 249 }
245 250
246 // Last step: Put map into date event, add custom map and return it 251 // Last step: Put map into date event, add custom map and return it
247 OPimEvent retDate( dateEventMap ); 252 OPimEvent retDate( dateEventMap );
248 retDate.setExtraMap( requestCustom( uid ) ); 253 retDate.setExtraMap( requestCustom( uid ) );
249 254
250 qDebug( "ODateBookAccessBackend_SQL::find( %d ) end", uid ); 255 odebug << "ODateBookAccessBackend_SQL::find( " << uid << " ) end" << oendl;
251 return retDate; 256 return retDate;
252} 257}
253 258
254// FIXME: Speed up update of uid's.. 259// FIXME: Speed up update of uid's..
255bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) 260bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
256{ 261{
@@ -280,13 +285,13 @@ bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
280 + "'," 285 + "',"
281 + "0" // Priority for future enhancements 286 + "0" // Priority for future enhancements
282 + ",'" 287 + ",'"
283 + it.data() //.latin1() 288 + it.data() //.latin1()
284 + "');"; 289 + "');";
285 } 290 }
286 qWarning("add %s", qu.latin1() ); 291 owarn << "add " << qu << "" << oendl;
287 292
288 OSQLRawQuery raw( qu ); 293 OSQLRawQuery raw( qu );
289 OSQLResult res = m_driver->query( &raw ); 294 OSQLResult res = m_driver->query( &raw );
290 if ( res.state() != OSQLResult::Success ){ 295 if ( res.state() != OSQLResult::Success ){
291 return false; 296 return false;
292 } 297 }
@@ -387,13 +392,13 @@ QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
387 // Do it make sense to search other fields, too ? 392 // Do it make sense to search other fields, too ?
388 qu += " rlike(\""+ r.pattern() + "\", Location ) OR"; 393 qu += " rlike(\""+ r.pattern() + "\", Location ) OR";
389 qu += " rlike(\""+ r.pattern() + "\", Note )"; 394 qu += " rlike(\""+ r.pattern() + "\", Note )";
390 395
391 qu += " )"; 396 qu += " )";
392 397
393 qDebug( "query: %s", qu.latin1() ); 398 odebug << "query: " << qu << "" << oendl;
394 399
395 OSQLRawQuery raw( qu ); 400 OSQLRawQuery raw( qu );
396 OSQLResult res = m_driver->query( &raw ); 401 OSQLResult res = m_driver->query( &raw );
397 402
398 return extractUids( res ); 403 return extractUids( res );
399 404
@@ -402,26 +407,26 @@ QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
402} 407}
403 408
404/* ===== Private Functions ========================================== */ 409/* ===== Private Functions ========================================== */
405 410
406QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const 411QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
407{ 412{
408 qWarning("extractUids"); 413 owarn << "extractUids" << oendl;
409 QTime t; 414 QTime t;
410 t.start(); 415 t.start();
411 OSQLResultItem::ValueList list = res.results(); 416 OSQLResultItem::ValueList list = res.results();
412 OSQLResultItem::ValueList::Iterator it; 417 OSQLResultItem::ValueList::Iterator it;
413 QArray<int> ints(list.count() ); 418 QArray<int> ints(list.count() );
414 qWarning(" count = %d", list.count() ); 419 owarn << " count = " << list.count() << "" << oendl;
415 420
416 int i = 0; 421 int i = 0;
417 for (it = list.begin(); it != list.end(); ++it ) { 422 for (it = list.begin(); it != list.end(); ++it ) {
418 ints[i] = (*it).data("uid").toInt(); 423 ints[i] = (*it).data("uid").toInt();
419 i++; 424 i++;
420 } 425 }
421 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); 426 owarn << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl;
422 427
423 return ints; 428 return ints;
424 429
425} 430}
426 431
427QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const 432QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const
@@ -432,23 +437,23 @@ QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) cons
432 QMap<QString, QString> customMap; 437 QMap<QString, QString> customMap;
433 438
434 FindCustomQuery query( uid ); 439 FindCustomQuery query( uid );
435 OSQLResult res_custom = m_driver->query( &query ); 440 OSQLResult res_custom = m_driver->query( &query );
436 441
437 if ( res_custom.state() == OSQLResult::Failure ) { 442 if ( res_custom.state() == OSQLResult::Failure ) {
438 qWarning("OSQLResult::Failure in find query !!"); 443 owarn << "OSQLResult::Failure in find query !!" << oendl;
439 QMap<QString, QString> empty; 444 QMap<QString, QString> empty;
440 return empty; 445 return empty;
441 } 446 }
442 447
443 OSQLResultItem::ValueList list = res_custom.results(); 448 OSQLResultItem::ValueList list = res_custom.results();
444 OSQLResultItem::ValueList::Iterator it = list.begin(); 449 OSQLResultItem::ValueList::Iterator it = list.begin();
445 for ( ; it != list.end(); ++it ) { 450 for ( ; it != list.end(); ++it ) {
446 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 451 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
447 } 452 }
448 453
449 qDebug("RequestCustom needed: %d ms", t.elapsed() ); 454 odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl;
450 return customMap; 455 return customMap;
451} 456}
452 457
453 458
454} 459}