V
V
viktormarkov2016-06-01 14:56:30
Android
viktormarkov, 2016-06-01 14:56:30

How to properly set SQLite IN Condition in Android?

Hello!
It is necessary to extract from the database all the records that match the condition (COLUMN_ICON == value1 or value2 or value3 ... etc.)
I'm trying to do it like this:

final String SELECTION = MySQLiteHelper.COLUMN_ICON + " IN ";
        final String[] SELECTION_ARGS = {"default_red", "default_blue"};

        Cursor cursor = mDatabase.query(MySQLiteHelper.TABLE_NOTES,
                allColumns,
                SELECTION,
                SELECTION_ARGS,
                null, null,
                MySQLiteHelper.COLUMN_ID);

This produces an error:
Caused by: android.database.sqlite.SQLiteException: near "ORDER": syntax error (code 1): , while compiling: 
SELECT _id, text, title, icon FROM notes WHERE icon IN  ORDER BY _id

Actually the question is, where did my crooked hands do something wrong?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2016-06-01
@viktormarkov

So immediately and put the values ​​in SELECTION

final String SELECTION = MySQLiteHelper.COLUMN_ICON + " IN ( \"default_red\", \"default_blue\") ";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question