Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 180 |
1 files changed, 123 insertions, 57 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 1ea35a8..3142f75 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -36,31 +36,32 @@ | |||
36 | #include <qdatetime.h> | 36 | #include <qdatetime.h> |
37 | #include <qstringlist.h> | 37 | #include <qstringlist.h> |
38 | 38 | ||
39 | #include <qpe/global.h> | 39 | #include <qpe/global.h> |
40 | #include <qpe/recordfields.h> | 40 | #include <qpe/recordfields.h> |
41 | 41 | ||
42 | #include <opie2/opimcontact.h> | ||
42 | #include <opie2/opimcontactfields.h> | 43 | #include <opie2/opimcontactfields.h> |
43 | #include <opie2/opimdateconversion.h> | 44 | #include <opie2/opimdateconversion.h> |
44 | #include <opie2/osqldriver.h> | 45 | #include <opie2/osqldriver.h> |
45 | #include <opie2/osqlresult.h> | 46 | #include <opie2/osqlresult.h> |
46 | #include <opie2/osqlmanager.h> | 47 | #include <opie2/osqlmanager.h> |
47 | #include <opie2/osqlquery.h> | 48 | #include <opie2/osqlquery.h> |
48 | 49 | ||
50 | using namespace Opie; | ||
49 | using namespace Opie::DB; | 51 | using namespace Opie::DB; |
50 | 52 | ||
51 | 53 | ||
52 | /* | 54 | /* |
53 | * Implementation of used query types | 55 | * Implementation of used query types * CREATE query |
54 | * CREATE query | ||
55 | * LOAD query | 56 | * LOAD query |
56 | * INSERT | 57 | * INSERT |
57 | * REMOVE | 58 | * REMOVE |
58 | * CLEAR | 59 | * CLEAR |
59 | */ | 60 | */ |
60 | namespace Opie { | 61 | namespace { |
61 | /** | 62 | /** |
62 | * CreateQuery for the Todolist Table | 63 | * CreateQuery for the Todolist Table |
63 | */ | 64 | */ |
64 | class CreateQuery : public OSQLQuery { | 65 | class CreateQuery : public OSQLQuery { |
65 | public: | 66 | public: |
66 | CreateQuery(); | 67 | CreateQuery(); |
@@ -147,13 +148,13 @@ namespace Opie { | |||
147 | QArray<int> m_uids; | 148 | QArray<int> m_uids; |
148 | int m_uid; | 149 | int m_uid; |
149 | }; | 150 | }; |
150 | 151 | ||
151 | 152 | ||
152 | 153 | ||
153 | // We using three tables to store the information: | 154 | // We using two tables to store the information: |
154 | // 1. addressbook : It contains General information about the contact (non custom) | 155 | // 1. addressbook : It contains General information about the contact (non custom) |
155 | // 2. custom_data : Not official supported entries | 156 | // 2. custom_data : Not official supported entries |
156 | // All tables are connected by the uid of the contact. | 157 | // All tables are connected by the uid of the contact. |
157 | // Maybe I should add a table for meta-information ? | 158 | // Maybe I should add a table for meta-information ? |
158 | CreateQuery::CreateQuery() : OSQLQuery() {} | 159 | CreateQuery::CreateQuery() : OSQLQuery() {} |
159 | CreateQuery::~CreateQuery() {} | 160 | CreateQuery::~CreateQuery() {} |
@@ -165,13 +166,13 @@ namespace Opie { | |||
165 | QStringList fieldList = OPimContactFields::untrfields( false ); | 166 | QStringList fieldList = OPimContactFields::untrfields( false ); |
166 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 167 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
167 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); | 168 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); |
168 | } | 169 | } |
169 | qu += " );"; | 170 | qu += " );"; |
170 | 171 | ||
171 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; | 172 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
172 | 173 | ||
173 | return qu; | 174 | return qu; |
174 | } | 175 | } |
175 | 176 | ||
176 | ClearQuery::ClearQuery() | 177 | ClearQuery::ClearQuery() |
177 | : OSQLQuery() {} | 178 | : OSQLQuery() {} |
@@ -218,41 +219,32 @@ namespace Opie { | |||
218 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 219 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
219 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 220 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
220 | // Convert Column-String to Id and get value for this id.. | 221 | // Convert Column-String to Id and get value for this id.. |
221 | // Hmmm.. Maybe not very cute solution.. | 222 | // Hmmm.. Maybe not very cute solution.. |
222 | int id = translate[*it]; | 223 | int id = translate[*it]; |
223 | switch ( id ){ | 224 | switch ( id ){ |
224 | case Qtopia::Birthday:{ | 225 | case Qtopia::Birthday: |
225 | // These entries should stored in a special format | 226 | case Qtopia::Anniversary:{ |
226 | // year-month-day | 227 | QDate day; |
227 | QDate day = m_contact.birthday(); | 228 | if ( id == Qtopia::Birthday ){ |
228 | if ( day.isValid() ){ | 229 | day = m_contact.birthday(); |
229 | qu += QString(",\"%1-%2-%3\"") | ||
230 | .arg( day.year() ) | ||
231 | .arg( day.month() ) | ||
232 | .arg( day.day() ); | ||
233 | } else { | 230 | } else { |
234 | qu += ",\"\""; | 231 | day = m_contact.anniversary(); |
235 | } | 232 | } |
236 | } | ||
237 | break; | ||
238 | case Qtopia::Anniversary:{ | ||
239 | // These entries should stored in a special format | 233 | // These entries should stored in a special format |
240 | // year-month-day | 234 | // year-month-day |
241 | QDate day = m_contact.anniversary(); | ||
242 | if ( day.isValid() ){ | 235 | if ( day.isValid() ){ |
243 | qu += QString(",\"%1-%2-%3\"") | 236 | qu += QString(",\"%1-%2-%3\"") |
244 | .arg( day.year() ) | 237 | .arg( QString::number( day.year() ).rightJustify( 4, '0' ) ) |
245 | .arg( day.month() ) | 238 | .arg( QString::number( day.month() ).rightJustify( 2, '0' ) ) |
246 | .arg( day.day() ); | 239 | .arg( QString::number( day.day() ).rightJustify( 2, '0' ) ); |
247 | } else { | 240 | } else { |
248 | qu += ",\"\""; | 241 | qu += ",\"\""; |
249 | } | 242 | } |
250 | } | 243 | } |
251 | break; | 244 | break; |
252 | |||
253 | default: | 245 | default: |
254 | qu += QString( ",\"%1\"" ).arg( contactMap[id] ); | 246 | qu += QString( ",\"%1\"" ).arg( contactMap[id] ); |
255 | } | 247 | } |
256 | } | 248 | } |
257 | qu += " );"; | 249 | qu += " );"; |
258 | 250 | ||
@@ -265,21 +257,21 @@ namespace Opie { | |||
265 | it != customMap.end(); ++it ){ | 257 | it != customMap.end(); ++it ){ |
266 | qu += "insert into custom_data VALUES(" | 258 | qu += "insert into custom_data VALUES(" |
267 | + QString::number( m_contact.uid() ) | 259 | + QString::number( m_contact.uid() ) |
268 | + "," | 260 | + "," |
269 | + QString::number( id++ ) | 261 | + QString::number( id++ ) |
270 | + ",'" | 262 | + ",'" |
271 | + it.key() //.latin1() | 263 | + it.key() |
272 | + "'," | 264 | + "'," |
273 | + "0" // Priority for future enhancements | 265 | + "0" // Priority for future enhancements |
274 | + ",'" | 266 | + ",'" |
275 | + it.data() //.latin1() | 267 | + it.data() |
276 | + "');"; | 268 | + "');"; |
277 | } | 269 | } |
278 | // qu += "commit;"; | 270 | // qu += "commit;"; |
279 | qWarning("add %s", qu.latin1() ); | 271 | qDebug("add %s", qu.latin1() ); |
280 | return qu; | 272 | return qu; |
281 | } | 273 | } |
282 | 274 | ||
283 | 275 | ||
284 | RemoveQuery::RemoveQuery(int uid ) | 276 | RemoveQuery::RemoveQuery(int uid ) |
285 | : OSQLQuery(), m_uid( uid ) {} | 277 | : OSQLQuery(), m_uid( uid ) {} |
@@ -355,13 +347,13 @@ namespace Opie { | |||
355 | namespace Opie { | 347 | namespace Opie { |
356 | 348 | ||
357 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, | 349 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, |
358 | const QString& filename ): | 350 | const QString& filename ): |
359 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) | 351 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) |
360 | { | 352 | { |
361 | qWarning("C'tor OPimContactAccessBackend_SQL starts"); | 353 | qDebug("C'tor OPimContactAccessBackend_SQL starts"); |
362 | QTime t; | 354 | QTime t; |
363 | t.start(); | 355 | t.start(); |
364 | 356 | ||
365 | /* Expecting to access the default filename if nothing else is set */ | 357 | /* Expecting to access the default filename if nothing else is set */ |
366 | if ( filename.isEmpty() ){ | 358 | if ( filename.isEmpty() ){ |
367 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); | 359 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); |
@@ -372,13 +364,13 @@ OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* a | |||
372 | OSQLManager man; | 364 | OSQLManager man; |
373 | m_driver = man.standard(); | 365 | m_driver = man.standard(); |
374 | m_driver->setUrl( m_fileName ); | 366 | m_driver->setUrl( m_fileName ); |
375 | 367 | ||
376 | load(); | 368 | load(); |
377 | 369 | ||
378 | qWarning("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); | 370 | qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); |
379 | } | 371 | } |
380 | 372 | ||
381 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () | 373 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () |
382 | { | 374 | { |
383 | if( m_driver ) | 375 | if( m_driver ) |
384 | delete m_driver; | 376 | delete m_driver; |
@@ -473,60 +465,129 @@ bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) | |||
473 | return add( contact ); | 465 | return add( contact ); |
474 | } | 466 | } |
475 | 467 | ||
476 | 468 | ||
477 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const | 469 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const |
478 | { | 470 | { |
479 | qWarning("OPimContactAccessBackend_SQL::find()"); | 471 | qDebug("OPimContactAccessBackend_SQL::find()"); |
480 | QTime t; | 472 | QTime t; |
481 | t.start(); | 473 | t.start(); |
482 | 474 | ||
483 | OPimContact retContact( requestNonCustom( uid ) ); | 475 | OPimContact retContact( requestNonCustom( uid ) ); |
484 | retContact.setExtraMap( requestCustom( uid ) ); | 476 | retContact.setExtraMap( requestCustom( uid ) ); |
485 | 477 | ||
486 | qWarning("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); | 478 | qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); |
487 | return retContact; | 479 | return retContact; |
488 | } | 480 | } |
489 | 481 | ||
490 | 482 | ||
491 | 483 | ||
492 | QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() ) | 484 | QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) |
493 | { | 485 | { |
494 | QString qu = "SELECT uid FROM addressbook WHERE"; | 486 | QString qu = "SELECT uid FROM addressbook WHERE"; |
487 | QString searchQuery =""; | ||
488 | |||
489 | QDate startDate; | ||
490 | |||
491 | if ( qd.isValid() ) | ||
492 | startDate = qd.date(); | ||
493 | else | ||
494 | startDate = QDate::currentDate(); | ||
495 | |||
495 | 496 | ||
496 | QMap<int, QString> queryFields = query.toMap(); | 497 | QMap<int, QString> queryFields = query.toMap(); |
497 | QStringList fieldList = OPimContactFields::untrfields( false ); | 498 | QStringList fieldList = OPimContactFields::untrfields( false ); |
498 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 499 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
499 | 500 | ||
500 | // Convert every filled field to a SQL-Query | 501 | // Convert every filled field to a SQL-Query |
501 | bool isAnyFieldSelected = false; | 502 | // bool isAnyFieldSelected = false; |
502 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 503 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
504 | |||
503 | int id = translate[*it]; | 505 | int id = translate[*it]; |
504 | QString queryStr = queryFields[id]; | 506 | QString queryStr = queryFields[id]; |
507 | QDate* endDate = 0l; | ||
508 | |||
505 | if ( !queryStr.isEmpty() ){ | 509 | if ( !queryStr.isEmpty() ){ |
506 | isAnyFieldSelected = true; | 510 | // If something is alredy stored in the query, add an "AND" |
511 | // to the end of the string to prepare for the next .. | ||
512 | if ( !searchQuery.isEmpty() ) | ||
513 | searchQuery += " AND"; | ||
514 | |||
515 | // isAnyFieldSelected = true; | ||
507 | switch( id ){ | 516 | switch( id ){ |
517 | case Qtopia::Birthday: | ||
518 | endDate = new QDate( query.birthday() ); | ||
519 | // Fall through ! | ||
520 | case Qtopia::Anniversary: | ||
521 | if ( endDate == 0l ) | ||
522 | endDate = new QDate( query.anniversary() ); | ||
523 | |||
524 | if ( settings & OPimContactAccess::DateDiff ) { | ||
525 | searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) | ||
526 | .arg( *it ) | ||
527 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) | ||
528 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) | ||
529 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) | ||
530 | .arg( *it ) | ||
531 | .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) | ||
532 | .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) | ||
533 | .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; | ||
534 | } | ||
535 | |||
536 | if ( settings & OPimContactAccess::DateYear ){ | ||
537 | if ( settings & OPimContactAccess::DateDiff ) | ||
538 | searchQuery += " AND"; | ||
539 | |||
540 | searchQuery += QString( " (\"%1\" LIKE '%2-%')" ) | ||
541 | .arg( *it ) | ||
542 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); | ||
543 | } | ||
544 | |||
545 | if ( settings & OPimContactAccess::DateMonth ){ | ||
546 | if ( ( settings & OPimContactAccess::DateDiff ) | ||
547 | || ( settings & OPimContactAccess::DateYear ) ) | ||
548 | searchQuery += " AND"; | ||
549 | |||
550 | searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" ) | ||
551 | .arg( *it ) | ||
552 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ); | ||
553 | } | ||
554 | |||
555 | if ( settings & OPimContactAccess::DateDay ){ | ||
556 | if ( ( settings & OPimContactAccess::DateDiff ) | ||
557 | || ( settings & OPimContactAccess::DateYear ) | ||
558 | || ( settings & OPimContactAccess::DateMonth ) ) | ||
559 | searchQuery += " AND"; | ||
560 | |||
561 | searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" ) | ||
562 | .arg( *it ) | ||
563 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ); | ||
564 | } | ||
565 | |||
566 | break; | ||
508 | default: | 567 | default: |
509 | // Switching between case sensitive and insensitive... | 568 | // Switching between case sensitive and insensitive... |
510 | // LIKE is not case sensitive, GLOB is case sensitive | 569 | // LIKE is not case sensitive, GLOB is case sensitive |
511 | // Do exist a better solution to switch this ? | 570 | // Do exist a better solution to switch this ? |
512 | if ( settings & OPimContactAccess::IgnoreCase ) | 571 | if ( settings & OPimContactAccess::IgnoreCase ) |
513 | qu += "(\"" + *it + "\"" + " LIKE " + "'" | 572 | searchQuery += "(\"" + *it + "\"" + " LIKE " + "'" |
514 | + queryStr.replace(QRegExp("\\*"),"%") + "'" + ") AND "; | 573 | + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; |
515 | else | 574 | else |
516 | qu += "(\"" + *it + "\"" + " GLOB " + "'" | 575 | searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" |
517 | + queryStr + "'" + ") AND "; | 576 | + queryStr + "'" + ")"; |
518 | 577 | ||
519 | } | 578 | } |
520 | } | 579 | } |
521 | } | 580 | } |
522 | // Skip trailing "AND" | 581 | // Skip trailing "AND" |
523 | if ( isAnyFieldSelected ) | 582 | // if ( isAnyFieldSelected ) |
524 | qu = qu.left( qu.length() - 4 ); | 583 | // qu = qu.left( qu.length() - 4 ); |
584 | |||
585 | qu += searchQuery; | ||
525 | 586 | ||
526 | qWarning( "queryByExample query: %s", qu.latin1() ); | 587 | qDebug( "queryByExample query: %s", qu.latin1() ); |
527 | 588 | ||
528 | // Execute query and return the received uid's | 589 | // Execute query and return the received uid's |
529 | OSQLRawQuery raw( qu ); | 590 | OSQLRawQuery raw( qu ); |
530 | OSQLResult res = m_driver->query( &raw ); | 591 | OSQLResult res = m_driver->query( &raw ); |
531 | if ( res.state() != OSQLResult::Success ){ | 592 | if ( res.state() != OSQLResult::Success ){ |
532 | QArray<int> empty; | 593 | QArray<int> empty; |
@@ -544,13 +605,18 @@ QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | |||
544 | return nix; | 605 | return nix; |
545 | } | 606 | } |
546 | 607 | ||
547 | const uint OPimContactAccessBackend_SQL::querySettings() | 608 | const uint OPimContactAccessBackend_SQL::querySettings() |
548 | { | 609 | { |
549 | return OPimContactAccess::IgnoreCase | 610 | return OPimContactAccess::IgnoreCase |
550 | || OPimContactAccess::WildCards; | 611 | || OPimContactAccess::WildCards |
612 | || OPimContactAccess::DateDiff | ||
613 | || OPimContactAccess::DateYear | ||
614 | || OPimContactAccess::DateMonth | ||
615 | || OPimContactAccess::DateDay | ||
616 | ; | ||
551 | } | 617 | } |
552 | 618 | ||
553 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | 619 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const |
554 | { | 620 | { |
555 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 621 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
556 | * may be added with any of the other settings. IgnoreCase should never used alone. | 622 | * may be added with any of the other settings. IgnoreCase should never used alone. |
@@ -558,16 +624,16 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | |||
558 | */ | 624 | */ |
559 | 625 | ||
560 | // Step 1: Check whether the given settings are supported by this backend | 626 | // Step 1: Check whether the given settings are supported by this backend |
561 | if ( ( querySettings & ( | 627 | if ( ( querySettings & ( |
562 | OPimContactAccess::IgnoreCase | 628 | OPimContactAccess::IgnoreCase |
563 | | OPimContactAccess::WildCards | 629 | | OPimContactAccess::WildCards |
564 | // | OPimContactAccess::DateDiff | 630 | | OPimContactAccess::DateDiff |
565 | // | OPimContactAccess::DateYear | 631 | | OPimContactAccess::DateYear |
566 | // | OPimContactAccess::DateMonth | 632 | | OPimContactAccess::DateMonth |
567 | // | OPimContactAccess::DateDay | 633 | | OPimContactAccess::DateDay |
568 | // | OPimContactAccess::RegExp | 634 | // | OPimContactAccess::RegExp |
569 | // | OPimContactAccess::ExactMatch | 635 | // | OPimContactAccess::ExactMatch |
570 | ) ) != querySettings ) | 636 | ) ) != querySettings ) |
571 | return false; | 637 | return false; |
572 | 638 | ||
573 | // Step 2: Check whether the given combinations are ok.. | 639 | // Step 2: Check whether the given combinations are ok.. |
@@ -606,31 +672,31 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) | |||
606 | QString query = "SELECT uid FROM addressbook "; | 672 | QString query = "SELECT uid FROM addressbook "; |
607 | query += "ORDER BY \"Last Name\" "; | 673 | query += "ORDER BY \"Last Name\" "; |
608 | 674 | ||
609 | if ( !asc ) | 675 | if ( !asc ) |
610 | query += "DESC"; | 676 | query += "DESC"; |
611 | 677 | ||
612 | // qWarning("sorted query is: %s", query.latin1() ); | 678 | // qDebug("sorted query is: %s", query.latin1() ); |
613 | 679 | ||
614 | OSQLRawQuery raw( query ); | 680 | OSQLRawQuery raw( query ); |
615 | OSQLResult res = m_driver->query( &raw ); | 681 | OSQLResult res = m_driver->query( &raw ); |
616 | if ( res.state() != OSQLResult::Success ){ | 682 | if ( res.state() != OSQLResult::Success ){ |
617 | QArray<int> empty; | 683 | QArray<int> empty; |
618 | return empty; | 684 | return empty; |
619 | } | 685 | } |
620 | 686 | ||
621 | QArray<int> list = extractUids( res ); | 687 | QArray<int> list = extractUids( res ); |
622 | 688 | ||
623 | qWarning("sorted needed %d ms!", t.elapsed() ); | 689 | qDebug("sorted needed %d ms!", t.elapsed() ); |
624 | return list; | 690 | return list; |
625 | } | 691 | } |
626 | 692 | ||
627 | 693 | ||
628 | void OPimContactAccessBackend_SQL::update() | 694 | void OPimContactAccessBackend_SQL::update() |
629 | { | 695 | { |
630 | qWarning("Update starts"); | 696 | qDebug("Update starts"); |
631 | QTime t; | 697 | QTime t; |
632 | t.start(); | 698 | t.start(); |
633 | 699 | ||
634 | // Now load the database set and extract the uid's | 700 | // Now load the database set and extract the uid's |
635 | // which will be held locally | 701 | // which will be held locally |
636 | 702 | ||
@@ -640,31 +706,31 @@ void OPimContactAccessBackend_SQL::update() | |||
640 | return; | 706 | return; |
641 | 707 | ||
642 | m_uids = extractUids( res ); | 708 | m_uids = extractUids( res ); |
643 | 709 | ||
644 | m_changed = false; | 710 | m_changed = false; |
645 | 711 | ||
646 | qWarning("Update ends %d ms", t.elapsed() ); | 712 | qDebug("Update ends %d ms", t.elapsed() ); |
647 | } | 713 | } |
648 | 714 | ||
649 | QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const | 715 | QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const |
650 | { | 716 | { |
651 | qWarning("extractUids"); | 717 | qDebug("extractUids"); |
652 | QTime t; | 718 | QTime t; |
653 | t.start(); | 719 | t.start(); |
654 | OSQLResultItem::ValueList list = res.results(); | 720 | OSQLResultItem::ValueList list = res.results(); |
655 | OSQLResultItem::ValueList::Iterator it; | 721 | OSQLResultItem::ValueList::Iterator it; |
656 | QArray<int> ints(list.count() ); | 722 | QArray<int> ints(list.count() ); |
657 | qWarning(" count = %d", list.count() ); | 723 | qDebug(" count = %d", list.count() ); |
658 | 724 | ||
659 | int i = 0; | 725 | int i = 0; |
660 | for (it = list.begin(); it != list.end(); ++it ) { | 726 | for (it = list.begin(); it != list.end(); ++it ) { |
661 | ints[i] = (*it).data("uid").toInt(); | 727 | ints[i] = (*it).data("uid").toInt(); |
662 | i++; | 728 | i++; |
663 | } | 729 | } |
664 | qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); | 730 | qDebug("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); |
665 | 731 | ||
666 | return ints; | 732 | return ints; |
667 | 733 | ||
668 | } | 734 | } |
669 | 735 | ||
670 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const | 736 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const |
@@ -693,13 +759,13 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co | |||
693 | // Get data for the selected column and store it with the | 759 | // Get data for the selected column and store it with the |
694 | // corresponding id into the map.. | 760 | // corresponding id into the map.. |
695 | 761 | ||
696 | int id = translate[*it]; | 762 | int id = translate[*it]; |
697 | QString value = resItem.data( (*it) ); | 763 | QString value = resItem.data( (*it) ); |
698 | 764 | ||
699 | // qWarning("Reading %s... found: %s", (*it).latin1(), value.latin1() ); | 765 | // qDebug("Reading %s... found: %s", (*it).latin1(), value.latin1() ); |
700 | 766 | ||
701 | switch( id ){ | 767 | switch( id ){ |
702 | case Qtopia::Birthday: | 768 | case Qtopia::Birthday: |
703 | case Qtopia::Anniversary:{ | 769 | case Qtopia::Anniversary:{ |
704 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) | 770 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) |
705 | QStringList list = QStringList::split( '-', value ); | 771 | QStringList list = QStringList::split( '-', value ); |
@@ -711,24 +777,24 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co | |||
711 | QDate date( year, month, day ); | 777 | QDate date( year, month, day ); |
712 | nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); | 778 | nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); |
713 | } | 779 | } |
714 | } | 780 | } |
715 | break; | 781 | break; |
716 | case Qtopia::AddressCategory: | 782 | case Qtopia::AddressCategory: |
717 | qWarning("Category is: %s", value.latin1() ); | 783 | qDebug("Category is: %s", value.latin1() ); |
718 | default: | 784 | default: |
719 | nonCustomMap.insert( id, value ); | 785 | nonCustomMap.insert( id, value ); |
720 | } | 786 | } |
721 | } | 787 | } |
722 | 788 | ||
723 | // First insert uid | 789 | // First insert uid |
724 | nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); | 790 | nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); |
725 | t3needed = t3.elapsed(); | 791 | t3needed = t3.elapsed(); |
726 | 792 | ||
727 | // qWarning("Adding UID: %s", resItem.data( "uid" ).latin1() ); | 793 | // qDebug("Adding UID: %s", resItem.data( "uid" ).latin1() ); |
728 | qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", | 794 | qDebug("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", |
729 | t.elapsed(), t2needed, t3needed ); | 795 | t.elapsed(), t2needed, t3needed ); |
730 | 796 | ||
731 | return nonCustomMap; | 797 | return nonCustomMap; |
732 | } | 798 | } |
733 | 799 | ||
734 | QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const | 800 | QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const |
@@ -750,11 +816,11 @@ QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) c | |||
750 | OSQLResultItem::ValueList list = res_custom.results(); | 816 | OSQLResultItem::ValueList list = res_custom.results(); |
751 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 817 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
752 | for ( ; it != list.end(); ++it ) { | 818 | for ( ; it != list.end(); ++it ) { |
753 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 819 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
754 | } | 820 | } |
755 | 821 | ||
756 | qWarning("RequestCustom needed: %d ms", t.elapsed() ); | 822 | qDebug("RequestCustom needed: %d ms", t.elapsed() ); |
757 | return customMap; | 823 | return customMap; |
758 | } | 824 | } |
759 | 825 | ||
760 | } | 826 | } |