Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 14207be..dda23cc 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -23,38 +23,42 @@ | |||
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | /* | 29 | /* |
30 | * SQL Backend for the OPIE-Contact Database. | 30 | * SQL Backend for the OPIE-Contact Database. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include "ocontactaccessbackend_sql.h" | 33 | #include "ocontactaccessbackend_sql.h" |
34 | 34 | ||
35 | #include <qarray.h> | 35 | /* OPIE */ |
36 | #include <qdatetime.h> | ||
37 | #include <qstringlist.h> | ||
38 | |||
39 | #include <qpe/global.h> | ||
40 | #include <qpe/recordfields.h> | ||
41 | |||
42 | #include <opie2/opimcontact.h> | 36 | #include <opie2/opimcontact.h> |
43 | #include <opie2/opimcontactfields.h> | 37 | #include <opie2/opimcontactfields.h> |
44 | #include <opie2/opimdateconversion.h> | 38 | #include <opie2/opimdateconversion.h> |
45 | #include <opie2/osqldriver.h> | 39 | #include <opie2/osqldriver.h> |
46 | #include <opie2/osqlresult.h> | 40 | #include <opie2/osqlresult.h> |
47 | #include <opie2/osqlmanager.h> | 41 | #include <opie2/osqlmanager.h> |
48 | #include <opie2/osqlquery.h> | 42 | #include <opie2/osqlquery.h> |
43 | #include <opie2/odebug.h> | ||
44 | |||
45 | #include <qpe/global.h> | ||
46 | #include <qpe/recordfields.h> | ||
47 | |||
48 | /* QT */ | ||
49 | #include <qarray.h> | ||
50 | #include <qdatetime.h> | ||
51 | #include <qstringlist.h> | ||
52 | |||
49 | 53 | ||
50 | using namespace Opie; | 54 | using namespace Opie; |
51 | using namespace Opie::DB; | 55 | using namespace Opie::DB; |
52 | 56 | ||
53 | 57 | ||
54 | /* | 58 | /* |
55 | * Implementation of used query types * CREATE query | 59 | * Implementation of used query types * CREATE query |
56 | * LOAD query | 60 | * LOAD query |
57 | * INSERT | 61 | * INSERT |
58 | * REMOVE | 62 | * REMOVE |
59 | * CLEAR | 63 | * CLEAR |
60 | */ | 64 | */ |
@@ -259,25 +263,25 @@ namespace { | |||
259 | + QString::number( m_contact.uid() ) | 263 | + QString::number( m_contact.uid() ) |
260 | + "," | 264 | + "," |
261 | + QString::number( id++ ) | 265 | + QString::number( id++ ) |
262 | + ",'" | 266 | + ",'" |
263 | + it.key() | 267 | + it.key() |
264 | + "'," | 268 | + "'," |
265 | + "0" // Priority for future enhancements | 269 | + "0" // Priority for future enhancements |
266 | + ",'" | 270 | + ",'" |
267 | + it.data() | 271 | + it.data() |
268 | + "');"; | 272 | + "');"; |
269 | } | 273 | } |
270 | // qu += "commit;"; | 274 | // qu += "commit;"; |
271 | qDebug("add %s", qu.latin1() ); | 275 | odebug << "add " << qu << "" << oendl; |
272 | return qu; | 276 | return qu; |
273 | } | 277 | } |
274 | 278 | ||
275 | 279 | ||
276 | RemoveQuery::RemoveQuery(int uid ) | 280 | RemoveQuery::RemoveQuery(int uid ) |
277 | : OSQLQuery(), m_uid( uid ) {} | 281 | : OSQLQuery(), m_uid( uid ) {} |
278 | RemoveQuery::~RemoveQuery() {} | 282 | RemoveQuery::~RemoveQuery() {} |
279 | QString RemoveQuery::query()const { | 283 | QString RemoveQuery::query()const { |
280 | QString qu = "DELETE from addressbook where uid = " | 284 | QString qu = "DELETE from addressbook where uid = " |
281 | + QString::number(m_uid) + ";"; | 285 | + QString::number(m_uid) + ";"; |
282 | qu += "DELETE from custom_data where uid = " | 286 | qu += "DELETE from custom_data where uid = " |
283 | + QString::number(m_uid) + ";"; | 287 | + QString::number(m_uid) + ";"; |
@@ -307,25 +311,25 @@ namespace { | |||
307 | QString qu = "select uid, type, value from addressbook where"; | 311 | QString qu = "select uid, type, value from addressbook where"; |
308 | for (uint i = 0; i < m_uids.count(); i++ ) { | 312 | for (uint i = 0; i < m_uids.count(); i++ ) { |
309 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | 313 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; |
310 | } | 314 | } |
311 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. | 315 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. |
312 | return qu; | 316 | return qu; |
313 | } | 317 | } |
314 | */ | 318 | */ |
315 | QString FindQuery::single()const{ | 319 | QString FindQuery::single()const{ |
316 | QString qu = "select *"; | 320 | QString qu = "select *"; |
317 | qu += " from addressbook where uid = " + QString::number(m_uid); | 321 | qu += " from addressbook where uid = " + QString::number(m_uid); |
318 | 322 | ||
319 | // qWarning("find query: %s", qu.latin1() ); | 323 | // owarn << "find query: " << qu << "" << oendl; |
320 | return qu; | 324 | return qu; |
321 | } | 325 | } |
322 | 326 | ||
323 | 327 | ||
324 | FindCustomQuery::FindCustomQuery(int uid) | 328 | FindCustomQuery::FindCustomQuery(int uid) |
325 | : OSQLQuery(), m_uid( uid ) { | 329 | : OSQLQuery(), m_uid( uid ) { |
326 | } | 330 | } |
327 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) | 331 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) |
328 | : OSQLQuery(), m_uids( ints ){ | 332 | : OSQLQuery(), m_uids( ints ){ |
329 | } | 333 | } |
330 | FindCustomQuery::~FindCustomQuery() { | 334 | FindCustomQuery::~FindCustomQuery() { |
331 | } | 335 | } |
@@ -341,42 +345,42 @@ namespace { | |||
341 | 345 | ||
342 | }; | 346 | }; |
343 | 347 | ||
344 | 348 | ||
345 | /* --------------------------------------------------------------------------- */ | 349 | /* --------------------------------------------------------------------------- */ |
346 | 350 | ||
347 | namespace Opie { | 351 | namespace Opie { |
348 | 352 | ||
349 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, | 353 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, |
350 | const QString& filename ): | 354 | const QString& filename ): |
351 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) | 355 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) |
352 | { | 356 | { |
353 | qDebug("C'tor OPimContactAccessBackend_SQL starts"); | 357 | odebug << "C'tor OPimContactAccessBackend_SQL starts" << oendl; |
354 | QTime t; | 358 | QTime t; |
355 | t.start(); | 359 | t.start(); |
356 | 360 | ||
357 | /* Expecting to access the default filename if nothing else is set */ | 361 | /* Expecting to access the default filename if nothing else is set */ |
358 | if ( filename.isEmpty() ){ | 362 | if ( filename.isEmpty() ){ |
359 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); | 363 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); |
360 | } else | 364 | } else |
361 | m_fileName = filename; | 365 | m_fileName = filename; |
362 | 366 | ||
363 | // Get the standart sql-driver from the OSQLManager.. | 367 | // Get the standart sql-driver from the OSQLManager.. |
364 | OSQLManager man; | 368 | OSQLManager man; |
365 | m_driver = man.standard(); | 369 | m_driver = man.standard(); |
366 | m_driver->setUrl( m_fileName ); | 370 | m_driver->setUrl( m_fileName ); |
367 | 371 | ||
368 | load(); | 372 | load(); |
369 | 373 | ||
370 | qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); | 374 | odebug << "C'tor OPimContactAccessBackend_SQL ends: " << t.elapsed() << " ms" << oendl; |
371 | } | 375 | } |
372 | 376 | ||
373 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () | 377 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () |
374 | { | 378 | { |
375 | if( m_driver ) | 379 | if( m_driver ) |
376 | delete m_driver; | 380 | delete m_driver; |
377 | } | 381 | } |
378 | 382 | ||
379 | bool OPimContactAccessBackend_SQL::load () | 383 | bool OPimContactAccessBackend_SQL::load () |
380 | { | 384 | { |
381 | if (!m_driver->open() ) | 385 | if (!m_driver->open() ) |
382 | return false; | 386 | return false; |
@@ -421,25 +425,25 @@ QArray<int> OPimContactAccessBackend_SQL::allRecords() const | |||
421 | { | 425 | { |
422 | 426 | ||
423 | // FIXME: Think about cute handling of changed tables.. | 427 | // FIXME: Think about cute handling of changed tables.. |
424 | // Thus, we don't have to call update here... | 428 | // Thus, we don't have to call update here... |
425 | if ( m_changed ) | 429 | if ( m_changed ) |
426 | ((OPimContactAccessBackend_SQL*)this)->update(); | 430 | ((OPimContactAccessBackend_SQL*)this)->update(); |
427 | 431 | ||
428 | return m_uids; | 432 | return m_uids; |
429 | } | 433 | } |
430 | 434 | ||
431 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) | 435 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) |
432 | { | 436 | { |
433 | qDebug("add in contact SQL-Backend"); | 437 | odebug << "add in contact SQL-Backend" << oendl; |
434 | InsertQuery ins( newcontact ); | 438 | InsertQuery ins( newcontact ); |
435 | OSQLResult res = m_driver->query( &ins ); | 439 | OSQLResult res = m_driver->query( &ins ); |
436 | 440 | ||
437 | if ( res.state() == OSQLResult::Failure ) | 441 | if ( res.state() == OSQLResult::Failure ) |
438 | return false; | 442 | return false; |
439 | 443 | ||
440 | int c = m_uids.count(); | 444 | int c = m_uids.count(); |
441 | m_uids.resize( c+1 ); | 445 | m_uids.resize( c+1 ); |
442 | m_uids[c] = newcontact.uid(); | 446 | m_uids[c] = newcontact.uid(); |
443 | 447 | ||
444 | return true; | 448 | return true; |
445 | } | 449 | } |
@@ -460,32 +464,32 @@ bool OPimContactAccessBackend_SQL::remove ( int uid ) | |||
460 | 464 | ||
461 | bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) | 465 | bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) |
462 | { | 466 | { |
463 | if ( !remove( contact.uid() ) ) | 467 | if ( !remove( contact.uid() ) ) |
464 | return false; | 468 | return false; |
465 | 469 | ||
466 | return add( contact ); | 470 | return add( contact ); |
467 | } | 471 | } |
468 | 472 | ||
469 | 473 | ||
470 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const | 474 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const |
471 | { | 475 | { |
472 | qDebug("OPimContactAccessBackend_SQL::find()"); | 476 | odebug << "OPimContactAccessBackend_SQL::find()" << oendl; |
473 | QTime t; | 477 | QTime t; |
474 | t.start(); | 478 | t.start(); |
475 | 479 | ||
476 | OPimContact retContact( requestNonCustom( uid ) ); | 480 | OPimContact retContact( requestNonCustom( uid ) ); |
477 | retContact.setExtraMap( requestCustom( uid ) ); | 481 | retContact.setExtraMap( requestCustom( uid ) ); |
478 | 482 | ||
479 | qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); | 483 | odebug << "OPimContactAccessBackend_SQL::find() needed: " << t.elapsed() << " ms" << oendl; |
480 | return retContact; | 484 | return retContact; |
481 | } | 485 | } |
482 | 486 | ||
483 | 487 | ||
484 | 488 | ||
485 | QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) | 489 | QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) |
486 | { | 490 | { |
487 | QString qu = "SELECT uid FROM addressbook WHERE"; | 491 | QString qu = "SELECT uid FROM addressbook WHERE"; |
488 | QString searchQuery =""; | 492 | QString searchQuery =""; |
489 | 493 | ||
490 | QDate startDate; | 494 | QDate startDate; |
491 | 495 | ||
@@ -576,25 +580,25 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu | |||
576 | searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" | 580 | searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" |
577 | + queryStr + "'" + ")"; | 581 | + queryStr + "'" + ")"; |
578 | 582 | ||
579 | } | 583 | } |
580 | } | 584 | } |
581 | } | 585 | } |
582 | // Skip trailing "AND" | 586 | // Skip trailing "AND" |
583 | // if ( isAnyFieldSelected ) | 587 | // if ( isAnyFieldSelected ) |
584 | // qu = qu.left( qu.length() - 4 ); | 588 | // qu = qu.left( qu.length() - 4 ); |
585 | 589 | ||
586 | qu += searchQuery; | 590 | qu += searchQuery; |
587 | 591 | ||
588 | qDebug( "queryByExample query: %s", qu.latin1() ); | 592 | odebug << "queryByExample query: " << qu << "" << oendl; |
589 | 593 | ||
590 | // Execute query and return the received uid's | 594 | // Execute query and return the received uid's |
591 | OSQLRawQuery raw( qu ); | 595 | OSQLRawQuery raw( qu ); |
592 | OSQLResult res = m_driver->query( &raw ); | 596 | OSQLResult res = m_driver->query( &raw ); |
593 | if ( res.state() != OSQLResult::Success ){ | 597 | if ( res.state() != OSQLResult::Success ){ |
594 | QArray<int> empty; | 598 | QArray<int> empty; |
595 | return empty; | 599 | return empty; |
596 | } | 600 | } |
597 | 601 | ||
598 | QArray<int> list = extractUids( res ); | 602 | QArray<int> list = extractUids( res ); |
599 | 603 | ||
600 | return list; | 604 | return list; |
@@ -611,25 +615,25 @@ QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | |||
611 | QString searchlist; | 615 | QString searchlist; |
612 | 616 | ||
613 | QStringList fieldList = OPimContactFields::untrfields( false ); | 617 | QStringList fieldList = OPimContactFields::untrfields( false ); |
614 | // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 618 | // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
615 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 619 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
616 | if ( !searchlist.isEmpty() ) | 620 | if ( !searchlist.isEmpty() ) |
617 | searchlist += " OR "; | 621 | searchlist += " OR "; |
618 | searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; | 622 | searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; |
619 | } | 623 | } |
620 | 624 | ||
621 | qu = qu + searchlist + ")"; | 625 | qu = qu + searchlist + ")"; |
622 | 626 | ||
623 | qDebug( "query: %s", qu.latin1() ); | 627 | odebug << "query: " << qu << "" << oendl; |
624 | 628 | ||
625 | OSQLRawQuery raw( qu ); | 629 | OSQLRawQuery raw( qu ); |
626 | OSQLResult res = m_driver->query( &raw ); | 630 | OSQLResult res = m_driver->query( &raw ); |
627 | 631 | ||
628 | return extractUids( res ); | 632 | return extractUids( res ); |
629 | 633 | ||
630 | 634 | ||
631 | #endif | 635 | #endif |
632 | } | 636 | } |
633 | 637 | ||
634 | const uint OPimContactAccessBackend_SQL::querySettings() | 638 | const uint OPimContactAccessBackend_SQL::querySettings() |
635 | { | 639 | { |
@@ -692,77 +696,77 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | |||
692 | 696 | ||
693 | QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) | 697 | QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) |
694 | { | 698 | { |
695 | QTime t; | 699 | QTime t; |
696 | t.start(); | 700 | t.start(); |
697 | 701 | ||
698 | QString query = "SELECT uid FROM addressbook "; | 702 | QString query = "SELECT uid FROM addressbook "; |
699 | query += "ORDER BY \"Last Name\" "; | 703 | query += "ORDER BY \"Last Name\" "; |
700 | 704 | ||
701 | if ( !asc ) | 705 | if ( !asc ) |
702 | query += "DESC"; | 706 | query += "DESC"; |
703 | 707 | ||
704 | // qDebug("sorted query is: %s", query.latin1() ); | 708 | // odebug << "sorted query is: " << query << "" << oendl; |
705 | 709 | ||
706 | OSQLRawQuery raw( query ); | 710 | OSQLRawQuery raw( query ); |
707 | OSQLResult res = m_driver->query( &raw ); | 711 | OSQLResult res = m_driver->query( &raw ); |
708 | if ( res.state() != OSQLResult::Success ){ | 712 | if ( res.state() != OSQLResult::Success ){ |
709 | QArray<int> empty; | 713 | QArray<int> empty; |
710 | return empty; | 714 | return empty; |
711 | } | 715 | } |
712 | 716 | ||
713 | QArray<int> list = extractUids( res ); | 717 | QArray<int> list = extractUids( res ); |
714 | 718 | ||
715 | qDebug("sorted needed %d ms!", t.elapsed() ); | 719 | odebug << "sorted needed " << t.elapsed() << " ms!" << oendl; |
716 | return list; | 720 | return list; |
717 | } | 721 | } |
718 | 722 | ||
719 | 723 | ||
720 | void OPimContactAccessBackend_SQL::update() | 724 | void OPimContactAccessBackend_SQL::update() |
721 | { | 725 | { |
722 | qDebug("Update starts"); | 726 | odebug << "Update starts" << oendl; |
723 | QTime t; | 727 | QTime t; |
724 | t.start(); | 728 | t.start(); |
725 | 729 | ||
726 | // Now load the database set and extract the uid's | 730 | // Now load the database set and extract the uid's |
727 | // which will be held locally | 731 | // which will be held locally |
728 | 732 | ||
729 | LoadQuery lo; | 733 | LoadQuery lo; |
730 | OSQLResult res = m_driver->query(&lo); | 734 | OSQLResult res = m_driver->query(&lo); |
731 | if ( res.state() != OSQLResult::Success ) | 735 | if ( res.state() != OSQLResult::Success ) |
732 | return; | 736 | return; |
733 | 737 | ||
734 | m_uids = extractUids( res ); | 738 | m_uids = extractUids( res ); |
735 | 739 | ||
736 | m_changed = false; | 740 | m_changed = false; |
737 | 741 | ||
738 | qDebug("Update ends %d ms", t.elapsed() ); | 742 | odebug << "Update ends " << t.elapsed() << " ms" << oendl; |
739 | } | 743 | } |
740 | 744 | ||
741 | QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const | 745 | QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const |
742 | { | 746 | { |
743 | qDebug("extractUids"); | 747 | odebug << "extractUids" << oendl; |
744 | QTime t; | 748 | QTime t; |
745 | t.start(); | 749 | t.start(); |
746 | OSQLResultItem::ValueList list = res.results(); | 750 | OSQLResultItem::ValueList list = res.results(); |
747 | OSQLResultItem::ValueList::Iterator it; | 751 | OSQLResultItem::ValueList::Iterator it; |
748 | QArray<int> ints(list.count() ); | 752 | QArray<int> ints(list.count() ); |
749 | qDebug(" count = %d", list.count() ); | 753 | odebug << " count = " << list.count() << "" << oendl; |
750 | 754 | ||
751 | int i = 0; | 755 | int i = 0; |
752 | for (it = list.begin(); it != list.end(); ++it ) { | 756 | for (it = list.begin(); it != list.end(); ++it ) { |
753 | ints[i] = (*it).data("uid").toInt(); | 757 | ints[i] = (*it).data("uid").toInt(); |
754 | i++; | 758 | i++; |
755 | } | 759 | } |
756 | qDebug("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); | 760 | odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; |
757 | 761 | ||
758 | return ints; | 762 | return ints; |
759 | 763 | ||
760 | } | 764 | } |
761 | 765 | ||
762 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const | 766 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const |
763 | { | 767 | { |
764 | QTime t; | 768 | QTime t; |
765 | t.start(); | 769 | t.start(); |
766 | 770 | ||
767 | QMap<int, QString> nonCustomMap; | 771 | QMap<int, QString> nonCustomMap; |
768 | 772 | ||
@@ -779,74 +783,74 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co | |||
779 | QTime t3; | 783 | QTime t3; |
780 | t3.start(); | 784 | t3.start(); |
781 | // Now loop through all columns | 785 | // Now loop through all columns |
782 | QStringList fieldList = OPimContactFields::untrfields( false ); | 786 | QStringList fieldList = OPimContactFields::untrfields( false ); |
783 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 787 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
784 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 788 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
785 | // Get data for the selected column and store it with the | 789 | // Get data for the selected column and store it with the |
786 | // corresponding id into the map.. | 790 | // corresponding id into the map.. |
787 | 791 | ||
788 | int id = translate[*it]; | 792 | int id = translate[*it]; |
789 | QString value = resItem.data( (*it) ); | 793 | QString value = resItem.data( (*it) ); |
790 | 794 | ||
791 | // qDebug("Reading %s... found: %s", (*it).latin1(), value.latin1() ); | 795 | // odebug << "Reading " << (*it) << "... found: " << value << "" << oendl; |
792 | 796 | ||
793 | switch( id ){ | 797 | switch( id ){ |
794 | case Qtopia::Birthday: | 798 | case Qtopia::Birthday: |
795 | case Qtopia::Anniversary:{ | 799 | case Qtopia::Anniversary:{ |
796 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) | 800 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) |
797 | QStringList list = QStringList::split( '-', value ); | 801 | QStringList list = QStringList::split( '-', value ); |
798 | QStringList::Iterator lit = list.begin(); | 802 | QStringList::Iterator lit = list.begin(); |
799 | int year = (*lit).toInt(); | 803 | int year = (*lit).toInt(); |
800 | int month = (*(++lit)).toInt(); | 804 | int month = (*(++lit)).toInt(); |
801 | int day = (*(++lit)).toInt(); | 805 | int day = (*(++lit)).toInt(); |
802 | if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ | 806 | if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ |
803 | QDate date( year, month, day ); | 807 | QDate date( year, month, day ); |
804 | nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); | 808 | nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); |
805 | } | 809 | } |
806 | } | 810 | } |
807 | break; | 811 | break; |
808 | case Qtopia::AddressCategory: | 812 | case Qtopia::AddressCategory: |
809 | qDebug("Category is: %s", value.latin1() ); | 813 | odebug << "Category is: " << value << "" << oendl; |
810 | default: | 814 | default: |
811 | nonCustomMap.insert( id, value ); | 815 | nonCustomMap.insert( id, value ); |
812 | } | 816 | } |
813 | } | 817 | } |
814 | 818 | ||
815 | // First insert uid | 819 | // First insert uid |
816 | nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); | 820 | nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); |
817 | t3needed = t3.elapsed(); | 821 | t3needed = t3.elapsed(); |
818 | 822 | ||
819 | // qDebug("Adding UID: %s", resItem.data( "uid" ).latin1() ); | 823 | // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; |
820 | qDebug("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", | 824 | odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed |
821 | t.elapsed(), t2needed, t3needed ); | 825 | << " ms, mapping: " << t3needed << " ms" << oendl; |
822 | 826 | ||
823 | return nonCustomMap; | 827 | return nonCustomMap; |
824 | } | 828 | } |
825 | 829 | ||
826 | QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const | 830 | QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const |
827 | { | 831 | { |
828 | QTime t; | 832 | QTime t; |
829 | t.start(); | 833 | t.start(); |
830 | 834 | ||
831 | QMap<QString, QString> customMap; | 835 | QMap<QString, QString> customMap; |
832 | 836 | ||
833 | FindCustomQuery query( uid ); | 837 | FindCustomQuery query( uid ); |
834 | OSQLResult res_custom = m_driver->query( &query ); | 838 | OSQLResult res_custom = m_driver->query( &query ); |
835 | 839 | ||
836 | if ( res_custom.state() == OSQLResult::Failure ) { | 840 | if ( res_custom.state() == OSQLResult::Failure ) { |
837 | qWarning("OSQLResult::Failure in find query !!"); | 841 | owarn << "OSQLResult::Failure in find query !!" << oendl; |
838 | QMap<QString, QString> empty; | 842 | QMap<QString, QString> empty; |
839 | return empty; | 843 | return empty; |
840 | } | 844 | } |
841 | 845 | ||
842 | OSQLResultItem::ValueList list = res_custom.results(); | 846 | OSQLResultItem::ValueList list = res_custom.results(); |
843 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 847 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
844 | for ( ; it != list.end(); ++it ) { | 848 | for ( ; it != list.end(); ++it ) { |
845 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 849 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
846 | } | 850 | } |
847 | 851 | ||
848 | qDebug("RequestCustom needed: %d ms", t.elapsed() ); | 852 | odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; |
849 | return customMap; | 853 | return customMap; |
850 | } | 854 | } |
851 | 855 | ||
852 | } | 856 | } |