scooby
scooby

Reputation: 603

sql query in android

I am trying to fetch rows from the database which has data1 field euqal to values from a string array. this is how i am trying to do.. but it is giving a sqliteexception.

String[] Projection = { ContactsContract.Data.DATA1, ContactsContract.Data.DATA6, ContactsContract.Data.DATA8 };
String Selection = ContactsContract.Data.DATA1 + "= ? ";
c = mContext.getContentResolver().query(CONTENT_URI, Projection, Selection, id, null);

c is the cursor. and id is the string array which contains strings which should match with those in the DATA1 field of the database. is there any other way of doing this?? perhaps using 'IN' ? the logcat exception is :

07-03 17:42:49.118 391 391 E DatabaseUtils: android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x584c30

Upvotes: 0

Views: 211

Answers (1)

Alex Lockwood
Alex Lockwood

Reputation: 83311

Make sure id contains only one String.

And make sure you call c.moveToFirst() before you attempt to extract values from the Cursor, as it may be empty.

Upvotes: 1

Related Questions