-1

大家好

我有一个游标,我需要在 where 子句中验证特定 id 是否属于数组。

但是我有一个错误

android.database.sqlite.SQLiteException:靠近“?”:语法错误:,编译时:SELECT display_name,_id FROM view_data_restricted data WHERE (1) AND (data1 IN ? AND mimetype='vnd.android.cursor.item/group_membership' AND display_name like '%r%') ORDER BY display_name

这是我的代码

cursorContactosGrupos = managedQuery(ContactsContract.Data.CONTENT_URI,
                new String[]{ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME, ContactsContract.CommonDataKinds.GroupMembership._ID},
                ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " IN ? AND " + Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME + " like '%" + filter + "%'" ,
                new String[]{arrayTeste.toString().replace("[","(").replace("]",")")},
                ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME
                );

你能帮助我吗?谢谢

4

1 回答 1

0

尝试以下操作:

cursorContactosGrupos = managedQuery(ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME, ContactsContract.CommonDataKinds.GroupMembership._ID},
                ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " IN (?) AND " + Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME + " like '%" + filter + "%'" ,
                new String[]{arrayTeste.toString().replace("[","(").replace("]",")")},
                ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME
                );

只需?附上(?)

因为我们将查询写成... IN (VALUE)

于 2012-07-02T09:54:26.280 回答