Пример #1
0
/*!
 * Updates match flags for columns.
 */
void CntFilterDetail::updateForMatchFlag(const QContactDetailFilter& filter,
                                         QString& fieldToUpdate ,
                                         QContactManager::Error* error) const
{
    // Modify the filed depending on the query
    switch (filter.matchFlags()) {
        case QContactFilter::MatchExactly: {
            // Pattern for MatchExactly:
            // " ='xyz'"
            fieldToUpdate = " ='"
                           + filter.value().toString() + '\'';
            *error = QContactManager::NoError;
            break;
        }
        case QContactFilter::MatchContains: {
            // Pattern for MatchContains:
            // " LIKE '%xyz%'"
            fieldToUpdate = " LIKE '%" + filter.value().toString() + "%'" ;
            *error = QContactManager::NoError;
            break;
        }
        case QContactFilter::MatchStartsWith: {
            // Pattern for MatchStartsWith:
            // " LIKE 'xyz%'"
            fieldToUpdate = " LIKE '" +  filter.value().toString() + "%'"  ;
            *error = QContactManager::NoError;
            break;
        }
        case QContactFilter::MatchEndsWith: {
            // Pattern for MatchEndsWith:
            // " LIKE '%xyz'"
            fieldToUpdate = " LIKE '%" + filter.value().toString() + '\'' ;
            *error = QContactManager::NoError;
            break;
        }
        case QContactFilter::MatchFixedString: {
            // Pattern for MatchFixedString:
            // " ='xyz' COLLATE NOCASE"
            fieldToUpdate = " ='"
                       + filter.value().toString() + '\'' + " COLLATE NOCASE";
            *error = QContactManager::NoError;
            break;
        }
        case QContactFilter::MatchCaseSensitive: {
            *error = QContactManager::NotSupportedError;
            break;
        }
        default: {
            *error = QContactManager::NotSupportedError;
            break;
        }
    }
}
Пример #2
0
void CntFilterDetail::getTableNameWhereClause(const QContactDetailFilter& detailfilter,
                                              QString& tableName,
                                              QString& sqlWhereClause ,
                                              QContactManager::Error* error) const
{
    //Get the table name and the column name
    QString columnName;
    bool isSubType;

    m_dbInfo.getDbTableAndColumnName(detailfilter.detailDefinitionName(), detailfilter.detailFieldName(), tableName, columnName, isSubType);

    // return if tableName is empty
    if (tableName.isEmpty()) {
        *error = QContactManager::NotSupportedError;
        return;
    }

    //check columnName
    if (columnName.isEmpty()) {
        *error = QContactManager::NotSupportedError;
        return;
    }
    else if (isSubType) {
        sqlWhereClause += columnName;
        sqlWhereClause += " NOT NULL ";
    }
    else if (detailfilter.detailDefinitionName() == QContactFavorite::DefinitionName) {
        bool favoritesSearch = true;
        if (detailfilter.value().canConvert(QVariant::Bool)) {
            if (!detailfilter.value().toBool()) {
                //filter to fetch non-favorite contacts
                favoritesSearch = false;    
            }
        }
        sqlWhereClause += columnName;
        if (favoritesSearch) {
            sqlWhereClause += " NOT NULL ";   
        }
        else {
            sqlWhereClause += " IS NULL ";
        }
    }
    else {
        sqlWhereClause += ' ' + columnName + ' ';
        QString fieldToUpdate;
        //Update the value depending on the match flag
        updateForMatchFlag(detailfilter,fieldToUpdate,error);
        sqlWhereClause +=  fieldToUpdate;
    }
}
void CntDisplayLabelSqlFilter::createSqlQuery(const QContactDetailFilter& filter,
                        QString& sqlQuery,
                        QContactManager::Error* error)
{
    *error = QContactManager::NoError;
    
    //get the contact fields that should be checked
    CntDisplayLabel displayLabel;
    QList<QPair<QLatin1String, QLatin1String> > contactFields = displayLabel.contactFilterDetails();
    
    //search values
    QStringList searchStrings = filter.value().toStringList();

    //default sql query
    sqlQuery = "SELECT contact_id FROM contact WHERE (type_flags>>24)=0";
    
    //everything ok
    if(!searchStrings.isEmpty() && searchStrings.count() <= contactFields.count() )
    {
        QString subQuery;
        QStringList columns;
        
        //get the column names
        for(int i = 0; i < contactFields.count(); i++)
        {
            columns << columnName(contactFields.at(i));
        }
        
        //single search value
        if(searchStrings.count() == 1)
        {
            createQuerySingleSearchValue(subQuery, searchStrings.at(0), columns);
        }
        
        //multiple search values
        else
        {
            createQueryMultipleSearchValues(subQuery, searchStrings, columns);    
        }
        
        if(!subQuery.isEmpty()){
            sqlQuery += " AND (" + subQuery + ')';
        }
   
        *error = QContactManager::NoError;
    }
    
    //if specified more filter criterias than contact fields return error
    else if(searchStrings.count() > contactFields.count()){
        *error = QContactManager::BadArgumentError;
    }
}