Search in sources :

Example 1 with SearchField

use of com.fsck.k9.search.SearchSpecification.SearchField in project k-9 by k9mail.

the class SqlQueryBuilder method appendExprRight.

private static void appendExprRight(SearchCondition condition, StringBuilder query, List<String> selectionArgs) {
    String value = condition.value;
    SearchField field = condition.field;
    query.append(" ");
    String selectionArg = null;
    switch(condition.attribute) {
        case NOT_CONTAINS:
            query.append("NOT ");
        //$FALL-THROUGH$
        case CONTAINS:
            {
                query.append("LIKE ?");
                selectionArg = "%" + value + "%";
                break;
            }
        case NOT_STARTSWITH:
            query.append("NOT ");
        //$FALL-THROUGH$
        case STARTSWITH:
            {
                query.append("LIKE ?");
                selectionArg = "%" + value;
                break;
            }
        case NOT_ENDSWITH:
            query.append("NOT ");
        //$FALL-THROUGH$
        case ENDSWITH:
            {
                query.append("LIKE ?");
                selectionArg = value + "%";
                break;
            }
        case NOT_EQUALS:
            {
                if (isNumberColumn(field)) {
                    query.append("!= ?");
                } else {
                    query.append("NOT LIKE ?");
                }
                selectionArg = value;
                break;
            }
        case EQUALS:
            {
                if (isNumberColumn(field)) {
                    query.append("= ?");
                } else {
                    query.append("LIKE ?");
                }
                selectionArg = value;
                break;
            }
    }
    if (selectionArg == null) {
        throw new RuntimeException("Unhandled case");
    }
    selectionArgs.add(selectionArg);
}
Also used : SearchField(com.fsck.k9.search.SearchSpecification.SearchField)

Aggregations

SearchField (com.fsck.k9.search.SearchSpecification.SearchField)1