-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 3142f75..bb5c99b 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -578,62 +578,87 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu | |||
578 | } | 578 | } |
579 | } | 579 | } |
580 | } | 580 | } |
581 | // Skip trailing "AND" | 581 | // Skip trailing "AND" |
582 | // if ( isAnyFieldSelected ) | 582 | // if ( isAnyFieldSelected ) |
583 | // qu = qu.left( qu.length() - 4 ); | 583 | // qu = qu.left( qu.length() - 4 ); |
584 | 584 | ||
585 | qu += searchQuery; | 585 | qu += searchQuery; |
586 | 586 | ||
587 | qDebug( "queryByExample query: %s", qu.latin1() ); | 587 | qDebug( "queryByExample query: %s", qu.latin1() ); |
588 | 588 | ||
589 | // Execute query and return the received uid's | 589 | // Execute query and return the received uid's |
590 | OSQLRawQuery raw( qu ); | 590 | OSQLRawQuery raw( qu ); |
591 | OSQLResult res = m_driver->query( &raw ); | 591 | OSQLResult res = m_driver->query( &raw ); |
592 | if ( res.state() != OSQLResult::Success ){ | 592 | if ( res.state() != OSQLResult::Success ){ |
593 | QArray<int> empty; | 593 | QArray<int> empty; |
594 | return empty; | 594 | return empty; |
595 | } | 595 | } |
596 | 596 | ||
597 | QArray<int> list = extractUids( res ); | 597 | QArray<int> list = extractUids( res ); |
598 | 598 | ||
599 | return list; | 599 | return list; |
600 | } | 600 | } |
601 | 601 | ||
602 | QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 602 | QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
603 | { | 603 | { |
604 | #if 1 | ||
604 | QArray<int> nix(0); | 605 | QArray<int> nix(0); |
605 | return nix; | 606 | return nix; |
607 | |||
608 | #else | ||
609 | QString qu = "SELECT uid FROM addressbook WHERE ("; | ||
610 | QString searchlist; | ||
611 | |||
612 | QStringList fieldList = OPimContactFields::untrfields( false ); | ||
613 | // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | ||
614 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | ||
615 | if ( !searchlist.isEmpty() ) | ||
616 | searchlist += " OR "; | ||
617 | searchlist += "\"" + *it + "\" rlike(\"" + r.pattern() + "\") "; | ||
618 | } | ||
619 | |||
620 | qu = qu + searchlist + ")"; | ||
621 | |||
622 | qDebug( "query: %s", qu.latin1() ); | ||
623 | |||
624 | OSQLRawQuery raw( qu ); | ||
625 | OSQLResult res = m_driver->query( &raw ); | ||
626 | |||
627 | return extractUids( res ); | ||
628 | |||
629 | |||
630 | #endif | ||
606 | } | 631 | } |
607 | 632 | ||
608 | const uint OPimContactAccessBackend_SQL::querySettings() | 633 | const uint OPimContactAccessBackend_SQL::querySettings() |
609 | { | 634 | { |
610 | return OPimContactAccess::IgnoreCase | 635 | return OPimContactAccess::IgnoreCase |
611 | || OPimContactAccess::WildCards | 636 | | OPimContactAccess::WildCards |
612 | || OPimContactAccess::DateDiff | 637 | | OPimContactAccess::DateDiff |
613 | || OPimContactAccess::DateYear | 638 | | OPimContactAccess::DateYear |
614 | || OPimContactAccess::DateMonth | 639 | | OPimContactAccess::DateMonth |
615 | || OPimContactAccess::DateDay | 640 | | OPimContactAccess::DateDay |
616 | ; | 641 | ; |
617 | } | 642 | } |
618 | 643 | ||
619 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | 644 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const |
620 | { | 645 | { |
621 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 646 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
622 | * may be added with any of the other settings. IgnoreCase should never used alone. | 647 | * may be added with any of the other settings. IgnoreCase should never used alone. |
623 | * Wildcards, RegExp, ExactMatch should never used at the same time... | 648 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
624 | */ | 649 | */ |
625 | 650 | ||
626 | // Step 1: Check whether the given settings are supported by this backend | 651 | // Step 1: Check whether the given settings are supported by this backend |
627 | if ( ( querySettings & ( | 652 | if ( ( querySettings & ( |
628 | OPimContactAccess::IgnoreCase | 653 | OPimContactAccess::IgnoreCase |
629 | | OPimContactAccess::WildCards | 654 | | OPimContactAccess::WildCards |
630 | | OPimContactAccess::DateDiff | 655 | | OPimContactAccess::DateDiff |
631 | | OPimContactAccess::DateYear | 656 | | OPimContactAccess::DateYear |
632 | | OPimContactAccess::DateMonth | 657 | | OPimContactAccess::DateMonth |
633 | | OPimContactAccess::DateDay | 658 | | OPimContactAccess::DateDay |
634 | // | OPimContactAccess::RegExp | 659 | // | OPimContactAccess::RegExp |
635 | // | OPimContactAccess::ExactMatch | 660 | // | OPimContactAccess::ExactMatch |
636 | ) ) != querySettings ) | 661 | ) ) != querySettings ) |
637 | return false; | 662 | return false; |
638 | 663 | ||
639 | // Step 2: Check whether the given combinations are ok.. | 664 | // Step 2: Check whether the given combinations are ok.. |