query a column in an sqlite database with a set of array values
i am sorry to ask again since i asked something similar to this earlier, but am in serious need of help here. situation is this, i have an Arraylist with values of strings, which i have converted to an array i want to query a "NAME" column in my sqlite database and return rows that have the string values in the name column.
e.g the `String [] a = {"do this", "do that", "help here"}; but it grows dynamically and can have a lenght开发者_开发技巧 with respect to the database column.(i mean it can't grow past the size of the database table.)
how can i construct an sqlite query to return rows that have this string in their array? Am having sqlite error of "incorrect syntax" or "bind or column index out of bounds" when using the suggestions from this post.
[http://stackoverflow.com/questions/3985263/using-an-array-to-query-an-sqlite-database-android][1]
i have no idea how to query the table anymore. please help, any help will be greatly appreciated. Thank you
In a nutshell: The function you want is ContentResolver.query()
. You get the resolver via context.getContentResolver()
.
You pass in:
- Uri - the URI of your content provider.
- Projection - the columns you want.
- selection - okay, that's where it gets interesting. Create a string here that looks like this:
NAME=? OR NAME=? OR NAME=?
. - selectionArgs - this is essentially the string array
a
in your question. - sortOrder - whatever you want.
If you're not using a content provider, you can use SQLiteDatabase's query function which works in an almost identical fashion.
精彩评论