summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index 6aaa14c..f684f8c 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -603,97 +603,97 @@ UIDArray OPimContactAccessBackend_SQL::queryByExample ( const UIDArray& uidlist,
603 .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) 603 .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) )
604 .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; 604 .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ;
605 } 605 }
606 606
607 if ( settings & OPimContactAccess::DateYear ){ 607 if ( settings & OPimContactAccess::DateYear ){
608 searchQuery += QString( " (\"%1\" LIKE '%2-%')" ) 608 searchQuery += QString( " (\"%1\" LIKE '%2-%')" )
609 .arg( *it ) 609 .arg( *it )
610 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); 610 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) );
611 } 611 }
612 612
613 if ( settings & OPimContactAccess::DateMonth ){ 613 if ( settings & OPimContactAccess::DateMonth ){
614 if ( settings & OPimContactAccess::DateYear ) 614 if ( settings & OPimContactAccess::DateYear )
615 searchQuery += " AND"; 615 searchQuery += " AND";
616 616
617 searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" ) 617 searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" )
618 .arg( *it ) 618 .arg( *it )
619 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ); 619 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) );
620 } 620 }
621 621
622 if ( settings & OPimContactAccess::DateDay ){ 622 if ( settings & OPimContactAccess::DateDay ){
623 if ( ( settings & OPimContactAccess::DateYear ) 623 if ( ( settings & OPimContactAccess::DateYear )
624 || ( settings & OPimContactAccess::DateMonth ) ) 624 || ( settings & OPimContactAccess::DateMonth ) )
625 searchQuery += " AND"; 625 searchQuery += " AND";
626 626
627 searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" ) 627 searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" )
628 .arg( *it ) 628 .arg( *it )
629 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ); 629 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) );
630 } 630 }
631 631
632 break; 632 break;
633 default: 633 default:
634 // Switching between case sensitive and insensitive... 634 // Switching between case sensitive and insensitive...
635 // LIKE is not case sensitive, GLOB is case sensitive 635 // LIKE is not case sensitive, GLOB is case sensitive
636 // Do exist a better solution to switch this ? 636 // Do exist a better solution to switch this ?
637 if ( settings & OPimContactAccess::IgnoreCase ) 637 if ( settings & OPimContactAccess::IgnoreCase )
638 searchQuery += " (\"" + *it + "\"" + " LIKE " + "'" 638 searchQuery += " (\"" + *it + "\"" + " LIKE " + "'"
639 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; 639 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")";
640 else 640 else
641 searchQuery += " (\"" + *it + "\"" + " GLOB " + "'" 641 searchQuery += " (\"" + *it + "\"" + " GLOB " + "'"
642 + queryStr + "'" + ")"; 642 + queryStr + "'" + ")";
643 643
644 } 644 }
645 } 645 }
646 646
647 delete endDate; 647 delete endDate;
648 648
649 // The following if line is a replacement for 649 // The following if line is a replacement for
650 // if ( searchQuery.endsWith( "AND" ) ) 650 // if ( searchQuery.endsWith( "AND" ) )
651 if ( searchQuery.findRev( "AND" ) == ( searchQuery.length() - 3 ) ){ 651 if ( searchQuery.findRev( "AND" ) == static_cast<int>( searchQuery.length() - 3 ) ){
652 odebug << "remove AND" << oendl; 652 odebug << "remove AND" << oendl;
653 searchQuery.remove( searchQuery.length()-3, 3 ); // Hmmmm.. 653 searchQuery.remove( searchQuery.length()-3, 3 ); // Hmmmm..
654 } 654 }
655 655
656 } 656 }
657 657
658 // Now compose the complete query 658 // Now compose the complete query
659 QString qu = "SELECT uid FROM addressbook WHERE " + uid_query; 659 QString qu = "SELECT uid FROM addressbook WHERE " + uid_query;
660 660
661 if ( !datediff_query.isEmpty() && !searchQuery.isEmpty() ){ 661 if ( !datediff_query.isEmpty() && !searchQuery.isEmpty() ){
662 // If we use DateDiff, we have to intersect two queries. 662 // If we use DateDiff, we have to intersect two queries.
663 qu = datediff_query + QString( " INTERSECT " ) + qu + searchQuery; 663 qu = datediff_query + QString( " INTERSECT " ) + qu + searchQuery;
664 } else if ( datediff_query.isEmpty() && !searchQuery.isEmpty() ){ 664 } else if ( datediff_query.isEmpty() && !searchQuery.isEmpty() ){
665 qu += searchQuery; 665 qu += searchQuery;
666 } else if ( !datediff_query.isEmpty() && searchQuery.isEmpty() ){ 666 } else if ( !datediff_query.isEmpty() && searchQuery.isEmpty() ){
667 qu = datediff_query; 667 qu = datediff_query;
668 } else if ( datediff_query.isEmpty() && searchQuery.isEmpty() ){ 668 } else if ( datediff_query.isEmpty() && searchQuery.isEmpty() ){
669 UIDArray empty; 669 UIDArray empty;
670 return empty; 670 return empty;
671 } 671 }
672 672
673 odebug << "queryByExample query: " << qu << "" << oendl; 673 odebug << "queryByExample query: " << qu << "" << oendl;
674 674
675 // Execute query and return the received uid's 675 // Execute query and return the received uid's
676 OSQLRawQuery raw( qu ); 676 OSQLRawQuery raw( qu );
677 OSQLResult res = m_driver->query( &raw ); 677 OSQLResult res = m_driver->query( &raw );
678 if ( res.state() != OSQLResult::Success ){ 678 if ( res.state() != OSQLResult::Success ){
679 UIDArray empty; 679 UIDArray empty;
680 return empty; 680 return empty;
681 } 681 }
682 682
683 UIDArray list = extractUids( res ); 683 UIDArray list = extractUids( res );
684 684
685 return list; 685 return list;
686} 686}
687 687
688UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 688UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
689{ 689{
690#if 0 690#if 0
691 QArray<int> nix(0); 691 QArray<int> nix(0);
692 return nix; 692 return nix;
693 693
694#else 694#else
695 QString qu = "SELECT uid FROM addressbook WHERE ("; 695 QString qu = "SELECT uid FROM addressbook WHERE (";
696 QString searchlist; 696 QString searchlist;
697 697
698 QStringList fieldList = OPimContactFields::untrfields( false ); 698 QStringList fieldList = OPimContactFields::untrfields( false );
699 // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 699 // QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
@@ -828,96 +828,102 @@ UIDArray OPimContactAccessBackend_SQL::sorted( const UIDArray& ar, bool asc, int
828 828
829 } 829 }
830 830
831 query += " ORDER BY"; 831 query += " ORDER BY";
832 832
833 switch ( sortOrder ) { 833 switch ( sortOrder ) {
834 case OPimContactAccess::SortSummary: 834 case OPimContactAccess::SortSummary:
835 query += " \"Notes\""; 835 query += " \"Notes\"";
836 break; 836 break;
837 case OPimContactAccess::SortByCategory: 837 case OPimContactAccess::SortByCategory:
838 query += " \"Categories\""; 838 query += " \"Categories\"";
839 break; 839 break;
840 case OPimContactAccess::SortByDate: 840 case OPimContactAccess::SortByDate:
841 query += " \"\""; 841 query += " \"\"";
842 break; 842 break;
843 case OPimContactAccess::SortTitle: 843 case OPimContactAccess::SortTitle:
844 query += " \"Name Title\""; 844 query += " \"Name Title\"";
845 break; 845 break;
846 case OPimContactAccess::SortFirstName: 846 case OPimContactAccess::SortFirstName:
847 query += " \"First Name\""; 847 query += " \"First Name\"";
848 break; 848 break;
849 case OPimContactAccess::SortMiddleName: 849 case OPimContactAccess::SortMiddleName:
850 query += " \"Middle Name\""; 850 query += " \"Middle Name\"";
851 break; 851 break;
852 case OPimContactAccess::SortLastName: 852 case OPimContactAccess::SortLastName:
853 query += " \"Last Name\""; 853 query += " \"Last Name\"";
854 break; 854 break;
855 case OPimContactAccess::SortFileAsName: 855 case OPimContactAccess::SortFileAsName:
856 query += " \"File As\""; 856 query += " \"File As\"";
857 break; 857 break;
858 case OPimContactAccess::SortSuffix: 858 case OPimContactAccess::SortSuffix:
859 query += " \"Suffix\""; 859 query += " \"Suffix\"";
860 break; 860 break;
861 case OPimContactAccess::SortEmail: 861 case OPimContactAccess::SortEmail:
862 query += " \"Default Email\""; 862 query += " \"Default Email\"";
863 break; 863 break;
864 case OPimContactAccess::SortNickname: 864 case OPimContactAccess::SortNickname:
865 query += " \"Nickname\""; 865 query += " \"Nickname\"";
866 break; 866 break;
867 case OPimContactAccess::SortAnniversary: 867 case OPimContactAccess::SortAnniversary:
868 query += " \"Anniversary\""; 868 query += " \"Anniversary\"";
869 break; 869 break;
870 case OPimContactAccess::SortBirthday: 870 case OPimContactAccess::SortBirthday:
871 query += " \"Birthday\""; 871 query += " \"Birthday\"";
872 break; 872 break;
873 case OPimContactAccess::SortGender: 873 case OPimContactAccess::SortGender:
874 query += " \"Gender\""; 874 query += " \"Gender\"";
875 break; 875 break;
876 case OPimContactAccess::SortBirthdayWithoutYear:
877 query += " substr(\"Birthday\", 6, 10)";
878 break;
879 case OPimContactAccess::SortAnniversaryWithoutYear:
880 query += " substr(\"Anniversary\", 6, 10)";
881 break;
876 default: 882 default:
877 query += " \"Last Name\""; 883 query += " \"Last Name\"";
878 } 884 }
879 885
880 if ( !asc ) 886 if ( !asc )
881 query += " DESC"; 887 query += " DESC";
882 888
883 889
884 odebug << "sorted query is: " << query << "" << oendl; 890 odebug << "sorted query is: " << query << "" << oendl;
885 891
886 OSQLRawQuery raw( query ); 892 OSQLRawQuery raw( query );
887 OSQLResult res = m_driver->query( &raw ); 893 OSQLResult res = m_driver->query( &raw );
888 if ( res.state() != OSQLResult::Success ){ 894 if ( res.state() != OSQLResult::Success ){
889 UIDArray empty; 895 UIDArray empty;
890 return empty; 896 return empty;
891 } 897 }
892 898
893 UIDArray list = extractUids( res ); 899 UIDArray list = extractUids( res );
894 900
895 odebug << "sorted needed " << t.elapsed() << " ms!" << oendl; 901 odebug << "sorted needed " << t.elapsed() << " ms!" << oendl;
896 return list; 902 return list;
897} 903}
898 904
899 905
900void OPimContactAccessBackend_SQL::update() 906void OPimContactAccessBackend_SQL::update()
901{ 907{
902 odebug << "Update starts" << oendl; 908 odebug << "Update starts" << oendl;
903 QTime t; 909 QTime t;
904 t.start(); 910 t.start();
905 911
906 // Now load the database set and extract the uid's 912 // Now load the database set and extract the uid's
907 // which will be held locally 913 // which will be held locally
908 914
909 LoadQuery lo; 915 LoadQuery lo;
910 OSQLResult res = m_driver->query(&lo); 916 OSQLResult res = m_driver->query(&lo);
911 if ( res.state() != OSQLResult::Success ) 917 if ( res.state() != OSQLResult::Success )
912 return; 918 return;
913 919
914 m_uids = extractUids( res ); 920 m_uids = extractUids( res );
915 921
916 m_changed = false; 922 m_changed = false;
917 923
918 odebug << "Update ends " << t.elapsed() << " ms" << oendl; 924 odebug << "Update ends " << t.elapsed() << " ms" << oendl;
919} 925}
920 926
921UIDArray OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const 927UIDArray OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
922{ 928{
923 odebug << "extractUids" << oendl; 929 odebug << "extractUids" << oendl;