summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
authorar <ar>2004-06-01 21:38:07 (UTC)
committer ar <ar>2004-06-01 21:38:07 (UTC)
commitbaed1d5ab8589aef14440009bc4e7380bcc5a741 (patch) (unidiff)
treec636e892c5eec0df2b36d16cb601a7da41a2ef0f /libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
parent4438393d8eef624565e840b798429071829adea8 (diff)
downloadopie-baed1d5ab8589aef14440009bc4e7380bcc5a741.zip
opie-baed1d5ab8589aef14440009bc4e7380bcc5a741.tar.gz
opie-baed1d5ab8589aef14440009bc4e7380bcc5a741.tar.bz2
- convert to odebug framework
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp64
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
@@ -29,26 +29,30 @@
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
50using namespace Opie; 54using namespace Opie;
51using namespace Opie::DB; 55using namespace Opie::DB;
52 56
53 57
54/* 58/*
@@ -265,13 +269,13 @@ namespace {
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 ) {}
@@ -313,13 +317,13 @@ namespace {
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 ) {
@@ -347,13 +351,13 @@ namespace {
347namespace Opie { 351namespace Opie {
348 352
349OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, 353OPimContactAccessBackend_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" );
@@ -364,13 +368,13 @@ OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* a
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
373OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () 377OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL ()
374{ 378{
375 if( m_driver ) 379 if( m_driver )
376 delete m_driver; 380 delete m_driver;
@@ -427,13 +431,13 @@ QArray<int> OPimContactAccessBackend_SQL::allRecords() const
427 431
428 return m_uids; 432 return m_uids;
429} 433}
430 434
431bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) 435bool 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
@@ -466,20 +470,20 @@ bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact )
466 return add( contact ); 470 return add( contact );
467} 471}
468 472
469 473
470OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const 474OPimContact 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
485QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) 489QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd )
@@ -582,13 +586,13 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
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;
@@ -617,13 +621,13 @@ QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
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
@@ -698,31 +702,31 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
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
720void OPimContactAccessBackend_SQL::update() 724void 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
@@ -732,31 +736,31 @@ void OPimContactAccessBackend_SQL::update()
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
741QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const 745QArray<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
762QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const 766QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const
@@ -785,13 +789,13 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
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 );
@@ -803,25 +807,25 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
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
826QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const 830QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const
827{ 831{
@@ -831,22 +835,22 @@ QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) c
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}