tags:

views:

21

answers:

1

Hello, 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

A: 

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.

EboMike
Thanks for the reply and sorry for the late response.i am using an SQLiteDatabase query function and yes, the selection parameter is where i am having the problem. the string array values can grow dynamically and has to be determined by array[].size() but of course it can't grow past the database table; so its not possible to just create a string as you suggested or rather, i don't know how to write it, taking into consideration array[].size();
Rexx
It is trivial to create a string from an array of strings. Give it a shot.
EboMike
had to re-implement the logic for my app and not it works. Thanks!
Rexx