Retrieving a set of rows from the sqlite database
SELECT * FROM <TableName> WHERE <attribute(id)> IN <ArrayList type>
but theres an error
04-24 21:18:41.748: ERROR/Error(29495): android.database.sqlite.SQLiteException: no such table: 1: , while compiling: SELECT * FROM Main WHERE id IN [1]
basically i want to select those rows with Attribute(id) wh开发者_高级运维ich are present in an ArrayList... but the format of the ArrayList is not the same as the one reqd for this type of query(i guess) and i think this is the reason, its not workin correctly
if i query it with:
SELECT * FROM <TableName> WHERE <attribute(id)> IN <Integer>
it shows me the correct result... but obv it only selects that particular id's row...
note: ArrayList is replaced with Integer... (which is the data-type of my attribute(id))
Thanks in advance :)
There is no such thing as IN <ArrayList type>
.
You need to compute the enumerating string yourself by using JAVA code.
SELECT * FROM <TableName> WHERE _id IN ('1','2','3','4','5')
Also please note that on Android the primary key is recommended to be _id
with underscore.
When working with apps, I prefer to let the List
I'm using to contain the elements it's holding like:
List<ElementType> = ...
By doing this, you can simply ask each element for their id's. Pentium10's solution will do the job, but I prefer doing this as it gives more flexibility.
精彩评论