Changeset 525e2e2


Ignore:
Timestamp:
07/12/11 22:16:12 (10 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master, qt5
Children:
fdf4d9c
Parents:
0ea5709
Message:

This commit closes ticket #12. The search terms are ANDed now and a call to trimmed() before splitting the search string avoids problems with leading/trailing spaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sql/sqlengine.cpp

    r0ea5709 r525e2e2  
    314314    sql += QString("WHERE EVENT.xid_conference = %1 AND (").arg( aConferenceId );
    315315
    316     QStringList searchKeywords = aKeyword.split(QRegExp("\\s+"));
    317     foreach (QString table, aColumns.uniqueKeys()){
    318         foreach (QString column, aColumns.values(table)){
    319             for (int i=0; i < searchKeywords.count(); i++){
    320                  sql += QString("%1.%2 LIKE '\%' || :%1%2%3 || '\%' OR ").arg(table).arg(column).arg(i);
    321             }
    322         }
    323     }
    324     sql.chop( QString(" OR ").length() );
     316    QStringList searchKeywords = aKeyword.trimmed().split(QRegExp("\\s+"));
     317    QStringList whereAnd;
     318    for (int i=0; i < searchKeywords.count(); i++) {
     319        QStringList whereOr;
     320        foreach (QString table, aColumns.uniqueKeys()) {
     321            foreach (QString column, aColumns.values(table)){
     322                 whereOr.append(QString("%1.%2 LIKE '\%' || :%1%2%3 || '\%'").arg(table).arg(column).arg(i));
     323            }
     324        }
     325        whereAnd.append(whereOr.join(" OR "));
     326    }
     327    sql += whereAnd.join(") AND (");
    325328    sql += QString(")");
    326329
    327330    QSqlQuery query(db);
    328331    query.prepare(sql);
    329     foreach (QString table, aColumns.uniqueKeys()){
    330         foreach (QString column, aColumns.values(table)){
    331             for (int i = 0; i != searchKeywords.size(); ++i) {
    332                 QString keyword = searchKeywords[i];
     332    for (int i = 0; i != searchKeywords.size(); ++i) {
     333        QString keyword = searchKeywords[i];
     334        foreach (QString table, aColumns.uniqueKeys()) {
     335            foreach (QString column, aColumns.values(table)) {
    333336                query.bindValue(QString(":%1%2%3").arg(table).arg(column).arg(i), keyword );
    334337            }
Note: See TracChangeset for help on using the changeset viewer.