author | eilers <eilers> | 2005-03-20 17:47:23 (UTC) |
---|---|---|
committer | eilers <eilers> | 2005-03-20 17:47:23 (UTC) |
commit | 22d113c0b0dc0a9a71cb55f565c4df04272809e1 (patch) (unidiff) | |
tree | 4decc50e15c93f1c6afc9131e3124c4f11115475 | |
parent | 5bc93a55c05c7292502c908fc0a99d5010a641c7 (diff) | |
download | opie-22d113c0b0dc0a9a71cb55f565c4df04272809e1.zip opie-22d113c0b0dc0a9a71cb55f565c4df04272809e1.tar.gz opie-22d113c0b0dc0a9a71cb55f565c4df04272809e1.tar.bz2 |
Fixing #1608, second issue: QueryByExample-Datediff does not work properly.
This solution is not the best. I will rethink it as I have enough time. But it should
work..
-rw-r--r-- | libopie2/opiepim/ChangeLog | 4 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 46 |
2 files changed, 39 insertions, 11 deletions
diff --git a/libopie2/opiepim/ChangeLog b/libopie2/opiepim/ChangeLog index 84517fb..acb6cb1 100644 --- a/libopie2/opiepim/ChangeLog +++ b/libopie2/opiepim/ChangeLog | |||
@@ -1,7 +1,9 @@ | |||
1 | 2005-03.19 Stefan Eilers <stefan@eilers-online.net> | 1 | 2005-03-20 Stefan Eilers <stefan@eilers-online.net> |
2 | * #1608 Quickfix for problem with DateDiff on SQL backend. I have to rethink this solution, but due to the short time, this should work. | ||
3 | 2005-03-19 Stefan Eilers <stefan@eilers-online.net> | ||
2 | * Minor update for sorted(). Now ignoring any category search if "DoNotShowWithCategory" filter is activated. | 4 | * Minor update for sorted(). Now ignoring any category search if "DoNotShowWithCategory" filter is activated. |
3 | * Fixing uninitialized member variable, caused crash of backend | 5 | * Fixing uninitialized member variable, caused crash of backend |
4 | 2005-03-18 Stefan Eilers <stefan@eilers-online.net> | 6 | 2005-03-18 Stefan Eilers <stefan@eilers-online.net> |
5 | * Rewrote generic sorted filter and added filter for "DoNotShowWithCategory", needed by addressbook (other filters need to be added!) | 7 | * Rewrote generic sorted filter and added filter for "DoNotShowWithCategory", needed by addressbook (other filters need to be added!) |
6 | 2005-01-16 Stefan Eilers <stefan@eilers-online.net> | 8 | 2005-01-16 Stefan Eilers <stefan@eilers-online.net> |
7 | * Added new OPimEventSortVector class, improved OPimSortVector | 9 | * Added new OPimEventSortVector class, improved OPimSortVector |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 2368865..50421e2 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -544,13 +544,14 @@ UIDArray OPimContactAccessBackend_SQL::queryByExample ( const UIDArray& uidlist, | |||
544 | qu += " uid = " + QString::number( uidlist[i] ) + " OR"; | 544 | qu += " uid = " + QString::number( uidlist[i] ) + " OR"; |
545 | } | 545 | } |
546 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. | 546 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. |
547 | qu += " ) AND "; | 547 | qu += " ) AND "; |
548 | } | 548 | } |
549 | 549 | ||
550 | QString searchQuery =""; | 550 | QString searchQuery = ""; |
551 | QString temp_searchQuery = ""; | ||
551 | 552 | ||
552 | QDate startDate; | 553 | QDate startDate; |
553 | 554 | ||
554 | if ( qd.isValid() ) | 555 | if ( qd.isValid() ) |
555 | startDate = qd.date(); | 556 | startDate = qd.date(); |
556 | else | 557 | else |
@@ -582,26 +583,35 @@ UIDArray OPimContactAccessBackend_SQL::queryByExample ( const UIDArray& uidlist, | |||
582 | // Fall through ! | 583 | // Fall through ! |
583 | case Qtopia::Anniversary: | 584 | case Qtopia::Anniversary: |
584 | if ( endDate == 0l ) | 585 | if ( endDate == 0l ) |
585 | endDate = new QDate( query.anniversary() ); | 586 | endDate = new QDate( query.anniversary() ); |
586 | 587 | ||
587 | if ( settings & OPimContactAccess::DateDiff ) { | 588 | if ( settings & OPimContactAccess::DateDiff ) { |
588 | searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) | 589 | // To handle datediffs correctly, we need to remove the year information from |
590 | // the birthday and anniversary. | ||
591 | // To do this efficiently, we will create a temporary table which contains the | ||
592 | // information we need and do the query on it. | ||
593 | // This table is just visible for this process and will be removed | ||
594 | // automatically after using. | ||
595 | temp_searchQuery = "CREATE TEMP TABLE bs ( uid, \"Birthday\", \"Anniversary\" );"; | ||
596 | temp_searchQuery += "INSERT INTO bs SELECT uid,substr(\"Birthday\", 6, 10),substr(\"Anniversary\", 6, 10) FROM addressbook WHERE ( \"Birthday\" != '' OR \"Anniversary\" != '' );"; | ||
597 | |||
598 | temp_searchQuery += QString( "SELECT uid FROM bs WHERE (\"%1\" <= '%2-%3\' AND \"%4\" >= '%5-%6')" ) | ||
589 | .arg( *it ) | 599 | .arg( *it ) |
590 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) | 600 | //.arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) |
591 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) | 601 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) |
592 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) | 602 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) |
593 | .arg( *it ) | 603 | .arg( *it ) |
594 | .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) | 604 | //.arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) |
595 | .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) | 605 | .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) |
596 | .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; | 606 | .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; |
597 | } | 607 | } |
598 | 608 | ||
599 | if ( settings & OPimContactAccess::DateYear ){ | 609 | if ( settings & OPimContactAccess::DateYear ){ |
600 | if ( settings & OPimContactAccess::DateDiff ) | 610 | // if ( settings & OPimContactAccess::DateDiff ) |
601 | searchQuery += " AND"; | 611 | // searchQuery += " AND"; |
602 | 612 | ||
603 | searchQuery += QString( " (\"%1\" LIKE '%2-%')" ) | 613 | searchQuery += QString( " (\"%1\" LIKE '%2-%')" ) |
604 | .arg( *it ) | 614 | .arg( *it ) |
605 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); | 615 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); |
606 | } | 616 | } |
607 | 617 | ||
@@ -640,17 +650,26 @@ UIDArray OPimContactAccessBackend_SQL::queryByExample ( const UIDArray& uidlist, | |||
640 | 650 | ||
641 | } | 651 | } |
642 | } | 652 | } |
643 | 653 | ||
644 | delete endDate; | 654 | delete endDate; |
645 | } | 655 | } |
646 | // Skip trailing "AND" | ||
647 | // if ( isAnyFieldSelected ) | ||
648 | // qu = qu.left( qu.length() - 4 ); | ||
649 | 656 | ||
650 | qu += searchQuery; | 657 | // The following is very ugly! (eilers) |
658 | if ( !temp_searchQuery.isEmpty() && !searchQuery.isEmpty() ){ | ||
659 | // If we use DateDiff, we have to intersect two queries. | ||
660 | qu = temp_searchQuery + QString( " INTERSECT " ) + qu + searchQuery; | ||
661 | } else if ( temp_searchQuery.isEmpty() && !searchQuery.isEmpty() ){ | ||
662 | qu += searchQuery; | ||
663 | } else if ( !temp_searchQuery.isEmpty() && searchQuery.isEmpty() ){ | ||
664 | // This will cause wrong results!! Uid filter is not used here! | ||
665 | qu = temp_searchQuery; | ||
666 | } else if ( temp_searchQuery.isEmpty() && searchQuery.isEmpty() ){ | ||
667 | UIDArray empty; | ||
668 | return empty; | ||
669 | } | ||
651 | 670 | ||
652 | odebug << "queryByExample query: " << qu << "" << oendl; | 671 | odebug << "queryByExample query: " << qu << "" << oendl; |
653 | 672 | ||
654 | // Execute query and return the received uid's | 673 | // Execute query and return the received uid's |
655 | OSQLRawQuery raw( qu ); | 674 | OSQLRawQuery raw( qu ); |
656 | OSQLResult res = m_driver->query( &raw ); | 675 | OSQLResult res = m_driver->query( &raw ); |
@@ -658,12 +677,19 @@ UIDArray OPimContactAccessBackend_SQL::queryByExample ( const UIDArray& uidlist, | |||
658 | UIDArray empty; | 677 | UIDArray empty; |
659 | return empty; | 678 | return empty; |
660 | } | 679 | } |
661 | 680 | ||
662 | UIDArray list = extractUids( res ); | 681 | UIDArray list = extractUids( res ); |
663 | 682 | ||
683 | // Remove temp table if created | ||
684 | if ( !temp_searchQuery.isEmpty( ) ){ | ||
685 | qu = "DROP TABLE bs"; | ||
686 | OSQLRawQuery raw( qu ); | ||
687 | OSQLResult res = m_driver->query( &raw ); | ||
688 | } | ||
689 | |||
664 | return list; | 690 | return list; |
665 | } | 691 | } |
666 | 692 | ||
667 | UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 693 | UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
668 | { | 694 | { |
669 | #if 0 | 695 | #if 0 |