summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
authoreilers <eilers>2004-04-10 17:13:14 (UTC)
committer eilers <eilers>2004-04-10 17:13:14 (UTC)
commit096b94bf150d2f3a2ef9a26940871ee7ffa58bdf (patch) (unidiff)
treec5cab0e19edc9aed9f8367a720619532ddac669c /libopie2/opiepim
parent4113636e53922f292477ca3f97035a624cf0450b (diff)
downloadopie-096b94bf150d2f3a2ef9a26940871ee7ffa58bdf.zip
opie-096b94bf150d2f3a2ef9a26940871ee7ffa58bdf.tar.gz
opie-096b94bf150d2f3a2ef9a26940871ee7ffa58bdf.tar.bz2
Some fixes to the namespace using.
the first test implementation of regexp-search for addressbook (disabled)
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp37
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
@@ -554,110 +554,135 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
554 554
555 if ( settings & OPimContactAccess::DateDay ){ 555 if ( settings & OPimContactAccess::DateDay ){
556 if ( ( settings & OPimContactAccess::DateDiff ) 556 if ( ( settings & OPimContactAccess::DateDiff )
557 || ( settings & OPimContactAccess::DateYear ) 557 || ( settings & OPimContactAccess::DateYear )
558 || ( settings & OPimContactAccess::DateMonth ) ) 558 || ( settings & OPimContactAccess::DateMonth ) )
559 searchQuery += " AND"; 559 searchQuery += " AND";
560 560
561 searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" ) 561 searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" )
562 .arg( *it ) 562 .arg( *it )
563 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ); 563 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) );
564 } 564 }
565 565
566 break; 566 break;
567 default: 567 default:
568 // Switching between case sensitive and insensitive... 568 // Switching between case sensitive and insensitive...
569 // LIKE is not case sensitive, GLOB is case sensitive 569 // LIKE is not case sensitive, GLOB is case sensitive
570 // Do exist a better solution to switch this ? 570 // Do exist a better solution to switch this ?
571 if ( settings & OPimContactAccess::IgnoreCase ) 571 if ( settings & OPimContactAccess::IgnoreCase )
572 searchQuery += "(\"" + *it + "\"" + " LIKE " + "'" 572 searchQuery += "(\"" + *it + "\"" + " LIKE " + "'"
573 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; 573 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")";
574 else 574 else
575 searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" 575 searchQuery += "(\"" + *it + "\"" + " GLOB " + "'"
576 + queryStr + "'" + ")"; 576 + queryStr + "'" + ")";
577 577
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
602QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 602QArray<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
608const uint OPimContactAccessBackend_SQL::querySettings() 633const 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
619bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const 644bool 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..
640 665
641 // IngoreCase alone is invalid 666 // IngoreCase alone is invalid
642 if ( querySettings == OPimContactAccess::IgnoreCase ) 667 if ( querySettings == OPimContactAccess::IgnoreCase )
643 return false; 668 return false;
644 669
645 // WildCards, RegExp and ExactMatch should never used at the same time 670 // WildCards, RegExp and ExactMatch should never used at the same time
646 switch ( querySettings & ~( OPimContactAccess::IgnoreCase 671 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
647 | OPimContactAccess::DateDiff 672 | OPimContactAccess::DateDiff
648 | OPimContactAccess::DateYear 673 | OPimContactAccess::DateYear
649 | OPimContactAccess::DateMonth 674 | OPimContactAccess::DateMonth
650 | OPimContactAccess::DateDay 675 | OPimContactAccess::DateDay
651 ) 676 )
652 ){ 677 ){
653 case OPimContactAccess::RegExp: 678 case OPimContactAccess::RegExp:
654 return ( true ); 679 return ( true );
655 case OPimContactAccess::WildCards: 680 case OPimContactAccess::WildCards:
656 return ( true ); 681 return ( true );
657 case OPimContactAccess::ExactMatch: 682 case OPimContactAccess::ExactMatch:
658 return ( true ); 683 return ( true );
659 case 0: // one of the upper removed bits were set.. 684 case 0: // one of the upper removed bits were set..
660 return ( true ); 685 return ( true );
661 default: 686 default:
662 return ( false ); 687 return ( false );
663 } 688 }