author | zecke <zecke> | 2005-06-27 18:08:35 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-06-27 18:08:35 (UTC) |
commit | cecffa1dc3a7bd1526be00e7bc4a4a151e6f2c9c (patch) (unidiff) | |
tree | f1507ae7e0ba8d3c41e0381b84827c97823edeca | |
parent | 058e3b6b0bc8f29314ee794bf7e993ebf3bfe072 (diff) | |
download | opie-cecffa1dc3a7bd1526be00e7bc4a4a151e6f2c9c.zip opie-cecffa1dc3a7bd1526be00e7bc4a4a151e6f2c9c.tar.gz opie-cecffa1dc3a7bd1526be00e7bc4a4a151e6f2c9c.tar.bz2 |
-Fix compile warning (signed vs unsigned)
-Somehow the split up patches missed the query string... (I knew I would mess up)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 8 |
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 | |||
@@ -555,193 +555,193 @@ UIDArray OPimContactAccessBackend_SQL::queryByExample ( const UIDArray& uidlist, | |||
555 | if ( qd.isValid() ) | 555 | if ( qd.isValid() ) |
556 | startDate = qd.date(); | 556 | startDate = qd.date(); |
557 | else | 557 | else |
558 | startDate = QDate::currentDate(); | 558 | startDate = QDate::currentDate(); |
559 | 559 | ||
560 | 560 | ||
561 | QMap<int, QString> queryFields = query.toMap(); | 561 | QMap<int, QString> queryFields = query.toMap(); |
562 | QStringList fieldList = OPimContactFields::untrfields( false ); | 562 | QStringList fieldList = OPimContactFields::untrfields( false ); |
563 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 563 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
564 | 564 | ||
565 | // Convert every filled field to a SQL-Query | 565 | // Convert every filled field to a SQL-Query |
566 | // bool isAnyFieldSelected = false; | 566 | // bool isAnyFieldSelected = false; |
567 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 567 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
568 | 568 | ||
569 | int id = translate[*it]; | 569 | int id = translate[*it]; |
570 | QString queryStr = queryFields[id]; | 570 | QString queryStr = queryFields[id]; |
571 | QDate* endDate = 0l; | 571 | QDate* endDate = 0l; |
572 | 572 | ||
573 | if ( !queryStr.isEmpty() ){ | 573 | if ( !queryStr.isEmpty() ){ |
574 | // If something is alredy stored in the query, add an "AND" | 574 | // If something is alredy stored in the query, add an "AND" |
575 | // to the end of the string to prepare for the next .. | 575 | // to the end of the string to prepare for the next .. |
576 | if ( !searchQuery.isEmpty() ) | 576 | if ( !searchQuery.isEmpty() ) |
577 | searchQuery += " AND"; | 577 | searchQuery += " AND"; |
578 | 578 | ||
579 | // isAnyFieldSelected = true; | 579 | // isAnyFieldSelected = true; |
580 | switch( id ){ | 580 | switch( id ){ |
581 | case Qtopia::Birthday: | 581 | case Qtopia::Birthday: |
582 | endDate = new QDate( query.birthday() ); | 582 | endDate = new QDate( query.birthday() ); |
583 | // Fall through ! | 583 | // Fall through ! |
584 | case Qtopia::Anniversary: | 584 | case Qtopia::Anniversary: |
585 | if ( endDate == 0l ) | 585 | if ( endDate == 0l ) |
586 | endDate = new QDate( query.anniversary() ); | 586 | endDate = new QDate( query.anniversary() ); |
587 | 587 | ||
588 | if ( settings & OPimContactAccess::DateDiff ) { | 588 | if ( settings & OPimContactAccess::DateDiff ) { |
589 | // To handle datediffs correctly, we need to remove the year information from | 589 | // To handle datediffs correctly, we need to remove the year information from |
590 | // the birthday and anniversary. | 590 | // the birthday and anniversary. |
591 | // To do this efficiently, we will create a temporary table which contains the | 591 | // To do this efficiently, we will create a temporary table which contains the |
592 | // information we need and do the query on it. | 592 | // information we need and do the query on it. |
593 | // This table is just visible for this process and will be removed | 593 | // This table is just visible for this process and will be removed |
594 | // automatically after using. | 594 | // automatically after using. |
595 | datediff_query = "SELECT uid,substr(\"Birthday\", 6, 10) as \"BirthdayMD\", substr(\"Anniversary\", 6, 10) as \"AnniversaryMD\" FROM addressbook WHERE ( \"Birthday\" != '' OR \"Anniversary\" != '' ) AND "; | 595 | datediff_query = "SELECT uid,substr(\"Birthday\", 6, 10) as \"BirthdayMD\", substr(\"Anniversary\", 6, 10) as \"AnniversaryMD\" FROM addressbook WHERE ( \"Birthday\" != '' OR \"Anniversary\" != '' ) AND "; |
596 | datediff_query += QString( " (\"%1MD\" <= '%2-%3\' AND \"%4MD\" >= '%5-%6')" ) | 596 | datediff_query += QString( " (\"%1MD\" <= '%2-%3\' AND \"%4MD\" >= '%5-%6')" ) |
597 | .arg( *it ) | 597 | .arg( *it ) |
598 | //.arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) | 598 | //.arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) |
599 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) | 599 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) |
600 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) | 600 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) |
601 | .arg( *it ) | 601 | .arg( *it ) |
602 | //.arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) | 602 | //.arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) |
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 | ||
688 | UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 688 | UIDArray 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(); |
700 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 700 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
701 | if ( !searchlist.isEmpty() ) | 701 | if ( !searchlist.isEmpty() ) |
702 | searchlist += " OR "; | 702 | searchlist += " OR "; |
703 | searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; | 703 | searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; |
704 | } | 704 | } |
705 | 705 | ||
706 | qu = qu + searchlist + ")"; | 706 | qu = qu + searchlist + ")"; |
707 | 707 | ||
708 | odebug << "query: " << qu << "" << oendl; | 708 | odebug << "query: " << qu << "" << oendl; |
709 | 709 | ||
710 | OSQLRawQuery raw( qu ); | 710 | OSQLRawQuery raw( qu ); |
711 | OSQLResult res = m_driver->query( &raw ); | 711 | OSQLResult res = m_driver->query( &raw ); |
712 | 712 | ||
713 | return extractUids( res ); | 713 | return extractUids( res ); |
714 | 714 | ||
715 | 715 | ||
716 | #endif | 716 | #endif |
717 | } | 717 | } |
718 | 718 | ||
719 | const uint OPimContactAccessBackend_SQL::querySettings() const | 719 | const uint OPimContactAccessBackend_SQL::querySettings() const |
720 | { | 720 | { |
721 | return OPimContactAccess::IgnoreCase | 721 | return OPimContactAccess::IgnoreCase |
722 | | OPimContactAccess::WildCards | 722 | | OPimContactAccess::WildCards |
723 | | OPimContactAccess::DateDiff | 723 | | OPimContactAccess::DateDiff |
724 | | OPimContactAccess::DateYear | 724 | | OPimContactAccess::DateYear |
725 | | OPimContactAccess::DateMonth | 725 | | OPimContactAccess::DateMonth |
726 | | OPimContactAccess::DateDay | 726 | | OPimContactAccess::DateDay |
727 | ; | 727 | ; |
728 | } | 728 | } |
729 | 729 | ||
730 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | 730 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const |
731 | { | 731 | { |
732 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 732 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
733 | * may be added with any of the other settings. IgnoreCase should never used alone. | 733 | * may be added with any of the other settings. IgnoreCase should never used alone. |
734 | * Wildcards, RegExp, ExactMatch should never used at the same time... | 734 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
735 | */ | 735 | */ |
736 | 736 | ||
737 | // Step 1: Check whether the given settings are supported by this backend | 737 | // Step 1: Check whether the given settings are supported by this backend |
738 | if ( ( querySettings & ( | 738 | if ( ( querySettings & ( |
739 | OPimContactAccess::IgnoreCase | 739 | OPimContactAccess::IgnoreCase |
740 | | OPimContactAccess::WildCards | 740 | | OPimContactAccess::WildCards |
741 | | OPimContactAccess::DateDiff | 741 | | OPimContactAccess::DateDiff |
742 | | OPimContactAccess::DateYear | 742 | | OPimContactAccess::DateYear |
743 | | OPimContactAccess::DateMonth | 743 | | OPimContactAccess::DateMonth |
744 | | OPimContactAccess::DateDay | 744 | | OPimContactAccess::DateDay |
745 | // | OPimContactAccess::RegExp | 745 | // | OPimContactAccess::RegExp |
746 | // | OPimContactAccess::ExactMatch | 746 | // | OPimContactAccess::ExactMatch |
747 | ) ) != querySettings ) | 747 | ) ) != querySettings ) |
@@ -780,192 +780,198 @@ UIDArray OPimContactAccessBackend_SQL::sorted( const UIDArray& ar, bool asc, int | |||
780 | { | 780 | { |
781 | QTime t; | 781 | QTime t; |
782 | t.start(); | 782 | t.start(); |
783 | 783 | ||
784 | QString query = "SELECT uid FROM addressbook"; | 784 | QString query = "SELECT uid FROM addressbook"; |
785 | 785 | ||
786 | query += " WHERE ("; | 786 | query += " WHERE ("; |
787 | for ( uint i = 0; i < ar.count(); i++ ) { | 787 | for ( uint i = 0; i < ar.count(); i++ ) { |
788 | query += " uid = " + QString::number( ar[i] ) + " OR"; | 788 | query += " uid = " + QString::number( ar[i] ) + " OR"; |
789 | } | 789 | } |
790 | query.remove( query.length()-2, 2 ); // Hmmmm.. | 790 | query.remove( query.length()-2, 2 ); // Hmmmm.. |
791 | query += ")"; | 791 | query += ")"; |
792 | 792 | ||
793 | 793 | ||
794 | if ( filter != OPimBase::FilterOff ){ | 794 | if ( filter != OPimBase::FilterOff ){ |
795 | if ( filter & OPimContactAccess::DoNotShowWithCategory ){ | 795 | if ( filter & OPimContactAccess::DoNotShowWithCategory ){ |
796 | query += " AND ( \"Categories\" == '' )"; | 796 | query += " AND ( \"Categories\" == '' )"; |
797 | } else if ( filter & OPimBase::FilterCategory ){ | 797 | } else if ( filter & OPimBase::FilterCategory ){ |
798 | query += " AND ("; | 798 | query += " AND ("; |
799 | for ( uint i = 0; i < categories.count(); i++ ){ | 799 | for ( uint i = 0; i < categories.count(); i++ ){ |
800 | query += "\"Categories\" LIKE"; | 800 | query += "\"Categories\" LIKE"; |
801 | query += QString( " '%" ) + QString::number( categories[i] ) + "%' OR"; | 801 | query += QString( " '%" ) + QString::number( categories[i] ) + "%' OR"; |
802 | } | 802 | } |
803 | query.remove( query.length()-2, 2 ); // Hmmmm.. | 803 | query.remove( query.length()-2, 2 ); // Hmmmm.. |
804 | query += ")"; | 804 | query += ")"; |
805 | } | 805 | } |
806 | 806 | ||
807 | if ( filter & OPimContactAccess::DoNotShowWithoutChildren ){ | 807 | if ( filter & OPimContactAccess::DoNotShowWithoutChildren ){ |
808 | query += " AND ( \"Children\" != '' )"; | 808 | query += " AND ( \"Children\" != '' )"; |
809 | } | 809 | } |
810 | 810 | ||
811 | if ( filter & OPimContactAccess::DoNotShowWithoutAnniversary ){ | 811 | if ( filter & OPimContactAccess::DoNotShowWithoutAnniversary ){ |
812 | query += " AND ( \"Anniversary\" != '' )"; | 812 | query += " AND ( \"Anniversary\" != '' )"; |
813 | } | 813 | } |
814 | 814 | ||
815 | if ( filter & OPimContactAccess::DoNotShowWithoutBirthday ){ | 815 | if ( filter & OPimContactAccess::DoNotShowWithoutBirthday ){ |
816 | query += " AND ( \"Birthday\" != '' )"; | 816 | query += " AND ( \"Birthday\" != '' )"; |
817 | } | 817 | } |
818 | 818 | ||
819 | if ( filter & OPimContactAccess::DoNotShowWithoutHomeAddress ){ | 819 | if ( filter & OPimContactAccess::DoNotShowWithoutHomeAddress ){ |
820 | // Expect that no Street means no Address, too! (eilers) | 820 | // Expect that no Street means no Address, too! (eilers) |
821 | query += " AND ( \"Home Street\" != '' )"; | 821 | query += " AND ( \"Home Street\" != '' )"; |
822 | } | 822 | } |
823 | 823 | ||
824 | if ( filter & OPimContactAccess::DoNotShowWithoutBusinessAddress ){ | 824 | if ( filter & OPimContactAccess::DoNotShowWithoutBusinessAddress ){ |
825 | // Expect that no Street means no Address, too! (eilers) | 825 | // Expect that no Street means no Address, too! (eilers) |
826 | query += " AND ( \"Business Street\" != '' )"; | 826 | query += " AND ( \"Business Street\" != '' )"; |
827 | } | 827 | } |
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 | ||
900 | void OPimContactAccessBackend_SQL::update() | 906 | void 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 | ||
921 | UIDArray OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const | 927 | UIDArray OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const |
922 | { | 928 | { |
923 | odebug << "extractUids" << oendl; | 929 | odebug << "extractUids" << oendl; |
924 | QTime t; | 930 | QTime t; |
925 | t.start(); | 931 | t.start(); |
926 | OSQLResultItem::ValueList list = res.results(); | 932 | OSQLResultItem::ValueList list = res.results(); |
927 | OSQLResultItem::ValueList::Iterator it; | 933 | OSQLResultItem::ValueList::Iterator it; |
928 | UIDArray ints(list.count() ); | 934 | UIDArray ints(list.count() ); |
929 | odebug << " count = " << list.count() << "" << oendl; | 935 | odebug << " count = " << list.count() << "" << oendl; |
930 | 936 | ||
931 | int i = 0; | 937 | int i = 0; |
932 | for (it = list.begin(); it != list.end(); ++it ) { | 938 | for (it = list.begin(); it != list.end(); ++it ) { |
933 | ints[i] = (*it).data("uid").toInt(); | 939 | ints[i] = (*it).data("uid").toInt(); |
934 | i++; | 940 | i++; |
935 | } | 941 | } |
936 | odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; | 942 | odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; |
937 | 943 | ||
938 | return ints; | 944 | return ints; |
939 | 945 | ||
940 | } | 946 | } |
941 | 947 | ||
942 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const | 948 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const |
943 | { | 949 | { |
944 | QTime t; | 950 | QTime t; |
945 | t.start(); | 951 | t.start(); |
946 | 952 | ||
947 | int t2needed = 0; | 953 | int t2needed = 0; |
948 | int t3needed = 0; | 954 | int t3needed = 0; |
949 | QTime t2; | 955 | QTime t2; |
950 | t2.start(); | 956 | t2.start(); |
951 | FindQuery query( uid ); | 957 | FindQuery query( uid ); |
952 | OSQLResult res_noncustom = m_driver->query( &query ); | 958 | OSQLResult res_noncustom = m_driver->query( &query ); |
953 | t2needed = t2.elapsed(); | 959 | t2needed = t2.elapsed(); |
954 | 960 | ||
955 | OSQLResultItem resItem = res_noncustom.first(); | 961 | OSQLResultItem resItem = res_noncustom.first(); |
956 | 962 | ||
957 | QMap<int, QString> nonCustomMap; | 963 | QMap<int, QString> nonCustomMap; |
958 | QTime t3; | 964 | QTime t3; |
959 | t3.start(); | 965 | t3.start(); |
960 | nonCustomMap = fillNonCustomMap( resItem ); | 966 | nonCustomMap = fillNonCustomMap( resItem ); |
961 | t3needed = t3.elapsed(); | 967 | t3needed = t3.elapsed(); |
962 | 968 | ||
963 | 969 | ||
964 | // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; | 970 | // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; |
965 | odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed | 971 | odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed |
966 | << " ms, mapping: " << t3needed << " ms" << oendl; | 972 | << " ms, mapping: " << t3needed << " ms" << oendl; |
967 | 973 | ||
968 | return nonCustomMap; | 974 | return nonCustomMap; |
969 | } | 975 | } |
970 | 976 | ||
971 | /* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */ | 977 | /* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */ |