summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp136
1 files changed, 68 insertions, 68 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index d0c8052..f121cc2 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -39,8 +39,8 @@
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/ocontactfields.h> 42#include <opie2/opimcontactfields.h>
43#include <opie2/oconversion.h> 43#include <opie2/opimdateconversion.h>
44#include <opie2/osqldriver.h> 44#include <opie2/osqldriver.h>
45#include <opie2/osqlresult.h> 45#include <opie2/osqlresult.h>
46#include <opie2/osqlmanager.h> 46#include <opie2/osqlmanager.h>
@@ -105,15 +105,15 @@ namespace Opie {
105 }; 105 };
106 106
107 /** 107 /**
108 * inserts/adds a OContact to the table 108 * inserts/adds a OPimContact to the table
109 */ 109 */
110 class InsertQuery : public OSQLQuery { 110 class InsertQuery : public OSQLQuery {
111 public: 111 public:
112 InsertQuery(const OContact& ); 112 InsertQuery(const OPimContact& );
113 ~InsertQuery(); 113 ~InsertQuery();
114 QString query()const; 114 QString query()const;
115 private: 115 private:
116 OContact m_contact; 116 OPimContact m_contact;
117 }; 117 };
118 118
119 119
@@ -176,7 +176,7 @@ namespace Opie {
176 176
177 qu += "create table addressbook( uid PRIMARY KEY "; 177 qu += "create table addressbook( uid PRIMARY KEY ";
178 178
179 QStringList fieldList = OContactFields::untrfields( false ); 179 QStringList fieldList = OPimContactFields::untrfields( false );
180 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 180 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
181 qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); 181 qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it );
182 } 182 }
@@ -223,7 +223,7 @@ namespace Opie {
223 } 223 }
224 224
225 225
226 InsertQuery::InsertQuery( const OContact& contact ) 226 InsertQuery::InsertQuery( const OPimContact& contact )
227 : OSQLQuery(), m_contact( contact ) { 227 : OSQLQuery(), m_contact( contact ) {
228 } 228 }
229 229
@@ -231,7 +231,7 @@ namespace Opie {
231 } 231 }
232 232
233 /* 233 /*
234 * converts from a OContact to a query 234 * converts from a OPimContact to a query
235 */ 235 */
236 QString InsertQuery::query()const{ 236 QString InsertQuery::query()const{
237 237
@@ -244,8 +244,8 @@ namespace Opie {
244 // Remember: The category is stored in contactMap, too ! 244 // Remember: The category is stored in contactMap, too !
245 QMap<int, QString> contactMap = m_contact.toMap(); 245 QMap<int, QString> contactMap = m_contact.toMap();
246 246
247 QStringList fieldList = OContactFields::untrfields( false ); 247 QStringList fieldList = OPimContactFields::untrfields( false );
248 QMap<QString, int> translate = OContactFields::untrFieldsToId(); 248 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
249 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 249 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
250 // Convert Column-String to Id and get value for this id.. 250 // Convert Column-String to Id and get value for this id..
251 // Hmmm.. Maybe not very cute solution.. 251 // Hmmm.. Maybe not very cute solution..
@@ -295,7 +295,7 @@ namespace Opie {
295 QMap<QString, QString> addressbook_db; 295 QMap<QString, QString> addressbook_db;
296 296
297 // Get the translation from the ID to the String 297 // Get the translation from the ID to the String
298 QMap<int, QString> transMap = OContactFields::idToUntrFields(); 298 QMap<int, QString> transMap = OPimContactFields::idToUntrFields();
299 299
300 for( QMap<int, QString>::Iterator it = contactMap.begin(); 300 for( QMap<int, QString>::Iterator it = contactMap.begin();
301 it != contactMap.end(); ++it ){ 301 it != contactMap.end(); ++it ){
@@ -459,11 +459,11 @@ namespace Opie {
459 459
460namespace Opie { 460namespace Opie {
461 461
462OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, 462OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */,
463 const QString& filename ): 463 const QString& filename ):
464 OContactAccessBackend(), m_changed(false), m_driver( NULL ) 464 OPimContactAccessBackend(), m_changed(false), m_driver( NULL )
465{ 465{
466 qWarning("C'tor OContactAccessBackend_SQL starts"); 466 qWarning("C'tor OPimContactAccessBackend_SQL starts");
467 QTime t; 467 QTime t;
468 t.start(); 468 t.start();
469 469
@@ -480,16 +480,16 @@ OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname
480 480
481 load(); 481 load();
482 482
483 qWarning("C'tor OContactAccessBackend_SQL ends: %d ms", t.elapsed() ); 483 qWarning("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() );
484} 484}
485 485
486OContactAccessBackend_SQL::~OContactAccessBackend_SQL () 486OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL ()
487{ 487{
488 if( m_driver ) 488 if( m_driver )
489 delete m_driver; 489 delete m_driver;
490} 490}
491 491
492bool OContactAccessBackend_SQL::load () 492bool OPimContactAccessBackend_SQL::load ()
493{ 493{
494 if (!m_driver->open() ) 494 if (!m_driver->open() )
495 return false; 495 return false;
@@ -506,18 +506,18 @@ bool OContactAccessBackend_SQL::load ()
506 506
507} 507}
508 508
509bool OContactAccessBackend_SQL::reload() 509bool OPimContactAccessBackend_SQL::reload()
510{ 510{
511 return load(); 511 return load();
512} 512}
513 513
514bool OContactAccessBackend_SQL::save() 514bool OPimContactAccessBackend_SQL::save()
515{ 515{
516 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 516 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
517} 517}
518 518
519 519
520void OContactAccessBackend_SQL::clear () 520void OPimContactAccessBackend_SQL::clear ()
521{ 521{
522 ClearQuery cle; 522 ClearQuery cle;
523 OSQLResult res = m_driver->query( &cle ); 523 OSQLResult res = m_driver->query( &cle );
@@ -525,23 +525,23 @@ void OContactAccessBackend_SQL::clear ()
525 reload(); 525 reload();
526} 526}
527 527
528bool OContactAccessBackend_SQL::wasChangedExternally() 528bool OPimContactAccessBackend_SQL::wasChangedExternally()
529{ 529{
530 return false; 530 return false;
531} 531}
532 532
533QArray<int> OContactAccessBackend_SQL::allRecords() const 533QArray<int> OPimContactAccessBackend_SQL::allRecords() const
534{ 534{
535 535
536 // FIXME: Think about cute handling of changed tables.. 536 // FIXME: Think about cute handling of changed tables..
537 // Thus, we don't have to call update here... 537 // Thus, we don't have to call update here...
538 if ( m_changed ) 538 if ( m_changed )
539 ((OContactAccessBackend_SQL*)this)->update(); 539 ((OPimContactAccessBackend_SQL*)this)->update();
540 540
541 return m_uids; 541 return m_uids;
542} 542}
543 543
544bool OContactAccessBackend_SQL::add ( const OContact &newcontact ) 544bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact )
545{ 545{
546 InsertQuery ins( newcontact ); 546 InsertQuery ins( newcontact );
547 OSQLResult res = m_driver->query( &ins ); 547 OSQLResult res = m_driver->query( &ins );
@@ -557,7 +557,7 @@ bool OContactAccessBackend_SQL::add ( const OContact &newcontact )
557} 557}
558 558
559 559
560bool OContactAccessBackend_SQL::remove ( int uid ) 560bool OPimContactAccessBackend_SQL::remove ( int uid )
561{ 561{
562 RemoveQuery rem( uid ); 562 RemoveQuery rem( uid );
563 OSQLResult res = m_driver->query(&rem ); 563 OSQLResult res = m_driver->query(&rem );
@@ -570,7 +570,7 @@ bool OContactAccessBackend_SQL::remove ( int uid )
570 return true; 570 return true;
571} 571}
572 572
573bool OContactAccessBackend_SQL::replace ( const OContact &contact ) 573bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact )
574{ 574{
575 if ( !remove( contact.uid() ) ) 575 if ( !remove( contact.uid() ) )
576 return false; 576 return false;
@@ -579,28 +579,28 @@ bool OContactAccessBackend_SQL::replace ( const OContact &contact )
579} 579}
580 580
581 581
582OContact OContactAccessBackend_SQL::find ( int uid ) const 582OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
583{ 583{
584 qWarning("OContactAccessBackend_SQL::find()"); 584 qWarning("OPimContactAccessBackend_SQL::find()");
585 QTime t; 585 QTime t;
586 t.start(); 586 t.start();
587 587
588 OContact retContact( requestNonCustom( uid ) ); 588 OPimContact retContact( requestNonCustom( uid ) );
589 retContact.setExtraMap( requestCustom( uid ) ); 589 retContact.setExtraMap( requestCustom( uid ) );
590 590
591 qWarning("OContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); 591 qWarning("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() );
592 return retContact; 592 return retContact;
593} 593}
594 594
595 595
596 596
597QArray<int> OContactAccessBackend_SQL::queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ) 597QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() )
598{ 598{
599 QString qu = "SELECT uid FROM addressbook WHERE"; 599 QString qu = "SELECT uid FROM addressbook WHERE";
600 600
601 QMap<int, QString> queryFields = query.toMap(); 601 QMap<int, QString> queryFields = query.toMap();
602 QStringList fieldList = OContactFields::untrfields( false ); 602 QStringList fieldList = OPimContactFields::untrfields( false );
603 QMap<QString, int> translate = OContactFields::untrFieldsToId(); 603 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
604 604
605 // Convert every filled field to a SQL-Query 605 // Convert every filled field to a SQL-Query
606 bool isAnyFieldSelected = false; 606 bool isAnyFieldSelected = false;
@@ -614,7 +614,7 @@ QArray<int> OContactAccessBackend_SQL::queryByExample ( const OContact &query, i
614 // Switching between case sensitive and insensitive... 614 // Switching between case sensitive and insensitive...
615 // LIKE is not case sensitive, GLOB is case sensitive 615 // LIKE is not case sensitive, GLOB is case sensitive
616 // Do exist a better solution to switch this ? 616 // Do exist a better solution to switch this ?
617 if ( settings & OContactAccess::IgnoreCase ) 617 if ( settings & OPimContactAccess::IgnoreCase )
618 qu += "(\"" + *it + "\"" + " LIKE " + "'" 618 qu += "(\"" + *it + "\"" + " LIKE " + "'"
619 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ") AND "; 619 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ") AND ";
620 else 620 else
@@ -643,57 +643,57 @@ QArray<int> OContactAccessBackend_SQL::queryByExample ( const OContact &query, i
643 return list; 643 return list;
644} 644}
645 645
646QArray<int> OContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 646QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
647{ 647{
648 QArray<int> nix(0); 648 QArray<int> nix(0);
649 return nix; 649 return nix;
650} 650}
651 651
652const uint OContactAccessBackend_SQL::querySettings() 652const uint OPimContactAccessBackend_SQL::querySettings()
653{ 653{
654 return OContactAccess::IgnoreCase 654 return OPimContactAccess::IgnoreCase
655 || OContactAccess::WildCards; 655 || OPimContactAccess::WildCards;
656} 656}
657 657
658bool OContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const 658bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
659{ 659{
660 /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 660 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
661 * may be added with any of the other settings. IgnoreCase should never used alone. 661 * may be added with any of the other settings. IgnoreCase should never used alone.
662 * Wildcards, RegExp, ExactMatch should never used at the same time... 662 * Wildcards, RegExp, ExactMatch should never used at the same time...
663 */ 663 */
664 664
665 // Step 1: Check whether the given settings are supported by this backend 665 // Step 1: Check whether the given settings are supported by this backend
666 if ( ( querySettings & ( 666 if ( ( querySettings & (
667 OContactAccess::IgnoreCase 667 OPimContactAccess::IgnoreCase
668 | OContactAccess::WildCards 668 | OPimContactAccess::WildCards
669 // | OContactAccess::DateDiff 669 // | OPimContactAccess::DateDiff
670 // | OContactAccess::DateYear 670 // | OPimContactAccess::DateYear
671 // | OContactAccess::DateMonth 671 // | OPimContactAccess::DateMonth
672 // | OContactAccess::DateDay 672 // | OPimContactAccess::DateDay
673 // | OContactAccess::RegExp 673 // | OPimContactAccess::RegExp
674 // | OContactAccess::ExactMatch 674 // | OPimContactAccess::ExactMatch
675 ) ) != querySettings ) 675 ) ) != querySettings )
676 return false; 676 return false;
677 677
678 // Step 2: Check whether the given combinations are ok.. 678 // Step 2: Check whether the given combinations are ok..
679 679
680 // IngoreCase alone is invalid 680 // IngoreCase alone is invalid
681 if ( querySettings == OContactAccess::IgnoreCase ) 681 if ( querySettings == OPimContactAccess::IgnoreCase )
682 return false; 682 return false;
683 683
684 // WildCards, RegExp and ExactMatch should never used at the same time 684 // WildCards, RegExp and ExactMatch should never used at the same time
685 switch ( querySettings & ~( OContactAccess::IgnoreCase 685 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
686 | OContactAccess::DateDiff 686 | OPimContactAccess::DateDiff
687 | OContactAccess::DateYear 687 | OPimContactAccess::DateYear
688 | OContactAccess::DateMonth 688 | OPimContactAccess::DateMonth
689 | OContactAccess::DateDay 689 | OPimContactAccess::DateDay
690 ) 690 )
691 ){ 691 ){
692 case OContactAccess::RegExp: 692 case OPimContactAccess::RegExp:
693 return ( true ); 693 return ( true );
694 case OContactAccess::WildCards: 694 case OPimContactAccess::WildCards:
695 return ( true ); 695 return ( true );
696 case OContactAccess::ExactMatch: 696 case OPimContactAccess::ExactMatch:
697 return ( true ); 697 return ( true );
698 case 0: // one of the upper removed bits were set.. 698 case 0: // one of the upper removed bits were set..
699 return ( true ); 699 return ( true );
@@ -703,7 +703,7 @@ bool OContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
703 703
704} 704}
705 705
706QArray<int> OContactAccessBackend_SQL::sorted( bool asc, int , int , int ) 706QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
707{ 707{
708 QTime t; 708 QTime t;
709 t.start(); 709 t.start();
@@ -735,7 +735,7 @@ QArray<int> OContactAccessBackend_SQL::sorted( bool asc, int , int , int )
735} 735}
736 736
737 737
738void OContactAccessBackend_SQL::update() 738void OPimContactAccessBackend_SQL::update()
739{ 739{
740 qWarning("Update starts"); 740 qWarning("Update starts");
741 QTime t; 741 QTime t;
@@ -756,7 +756,7 @@ void OContactAccessBackend_SQL::update()
756 qWarning("Update ends %d ms", t.elapsed() ); 756 qWarning("Update ends %d ms", t.elapsed() );
757} 757}
758 758
759QArray<int> OContactAccessBackend_SQL::extractUids( OSQLResult& res ) const 759QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
760{ 760{
761 qWarning("extractUids"); 761 qWarning("extractUids");
762 QTime t; 762 QTime t;
@@ -778,7 +778,7 @@ QArray<int> OContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
778} 778}
779 779
780#ifdef __STORE_HORIZONTAL_ 780#ifdef __STORE_HORIZONTAL_
781QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const 781QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const
782{ 782{
783 QTime t; 783 QTime t;
784 t.start(); 784 t.start();
@@ -798,8 +798,8 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
798 QTime t3; 798 QTime t3;
799 t3.start(); 799 t3.start();
800 // Now loop through all columns 800 // Now loop through all columns
801 QStringList fieldList = OContactFields::untrfields( false ); 801 QStringList fieldList = OPimContactFields::untrfields( false );
802 QMap<QString, int> translate = OContactFields::untrFieldsToId(); 802 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
803 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 803 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
804 // Get data for the selected column and store it with the 804 // Get data for the selected column and store it with the
805 // corresponding id into the map.. 805 // corresponding id into the map..
@@ -820,7 +820,7 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
820 int day = (*(++lit)).toInt(); 820 int day = (*(++lit)).toInt();
821 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ 821 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){
822 QDate date( year, month, day ); 822 QDate date( year, month, day );
823 nonCustomMap.insert( id, OConversion::dateToString( date ) ); 823 nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) );
824 } 824 }
825 } 825 }
826 break; 826 break;
@@ -843,7 +843,7 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
843} 843}
844#else 844#else
845 845
846QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const 846QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const
847{ 847{
848 QTime t; 848 QTime t;
849 t.start(); 849 t.start();
@@ -866,7 +866,7 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
866 int t3needed = 0; 866 int t3needed = 0;
867 QTime t3; 867 QTime t3;
868 t3.start(); 868 t3.start();
869 QMap<QString, int> translateMap = OContactFields::untrFieldsToId(); 869 QMap<QString, int> translateMap = OPimContactFields::untrFieldsToId();
870 870
871 OSQLResultItem::ValueList list = res_noncustom.results(); 871 OSQLResultItem::ValueList list = res_noncustom.results();
872 OSQLResultItem::ValueList::Iterator it = list.begin(); 872 OSQLResultItem::ValueList::Iterator it = list.begin();
@@ -887,7 +887,7 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
887 qWarning("3. %s", (*lit).latin1()); 887 qWarning("3. %s", (*lit).latin1());
888 qWarning( "RequestNonCustom->Converting:%s to Year: %d, Month: %d, Day: %d ", (*it).data( "value" ).latin1(), year, month, day ); 888 qWarning( "RequestNonCustom->Converting:%s to Year: %d, Month: %d, Day: %d ", (*it).data( "value" ).latin1(), year, month, day );
889 QDate date( year, month, day ); 889 QDate date( year, month, day );
890 nonCustomMap.insert( typeId, OConversion::dateToString( date ) ); 890 nonCustomMap.insert( typeId, OPimDateConversion::dateToString( date ) );
891 } 891 }
892 break; 892 break;
893 default: 893 default:
@@ -906,7 +906,7 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
906 906
907#endif // __STORE_HORIZONTAL_ 907#endif // __STORE_HORIZONTAL_
908 908
909QMap<QString, QString> OContactAccessBackend_SQL::requestCustom( int uid ) const 909QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const
910{ 910{
911 QTime t; 911 QTime t;
912 t.start(); 912 t.start();