Mazlum Ozdogan
Mazlum Ozdogan

Reputation: 219

Android SQLite query for consecutive text?

Is there any sql method for querying consecutive texts from database?

For example I want to query just "koma azad" but the query method shows me "koma dengê azad", too.

Code:

public Cursor getmatches(String query, String[] columns) {
    String selection = KEY_WORD + " MATCH ?";
    String[] selectionArgs = new String[]{query};

    return query(selection, selectionArgs, columns);
}

Upvotes: 1

Views: 52

Answers (2)

Mazlum Ozdogan
Mazlum Ozdogan

Reputation: 219

public Cursor getmatchs(String query, String[] columns) {
    String selection = KEY_WORD + " MATCH ?";
    String[] selectionArgs = new String[]{query};

    return query(selection, selectionArgs, columns);
}

Solution is adding double quotes:

public Cursor getmatchs(String query, String[] columns) {
    String selection = KEY_WORD + " MATCH ?";
    String[] selectionArgs = new String[]{"\""+query+"\""};

    return query(selection, selectionArgs, columns);
}

}

Upvotes: 0

Karakuri
Karakuri

Reputation: 38595

You have to use double quotes if the match phrase has separators in it. If you were to inline the query text in the selection string, it looks like this:

String selection = KEY_WORD + " MATCH '\"" + query + "\"'";

I'm not sure if this will work with the ? placeholder character, but you can try it and let us know.

Upvotes: 1

Related Questions