Search in sources :

Example 6 with SearchCondition

use of com.fsck.k9.search.SearchSpecification.SearchCondition 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

SearchCondition (com.fsck.k9.search.SearchSpecification.SearchCondition)5 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Account (com.fsck.k9.Account)1 Preferences (com.fsck.k9.Preferences)1 LocalSearch (com.fsck.k9.search.LocalSearch)1 SearchAccount (com.fsck.k9.search.SearchAccount)1 SearchField (com.fsck.k9.search.SearchSpecification.SearchField)1