当我以这种方式进行查询时
String where = "_id in(select phrase_id from words where word like '%FIRST%' intersect select phrase_id from words where word like '%SECOND%')";
Cursor cursor = database.query(PHRASES_TABLE, columns, where, null, null, null, null);
它正常工作。但是当我尝试使用selectionArgs而不是硬编码值时
String where = "_id in(select phrase_id from words where word like '%?%' intersect select phrase_id from words where word like '%?%')";
String[] args = {"FIRST", "SECOND"};
Cursor cursor = database.query(PHRASES_TABLE, columns, where, args, null, null, null);
我抓住了
android.database.sqlite.SQLiteBindOrColumnIndexOutOfRangeException: bind or column index out of range: handle 0x10b71e0
感谢。
答案 0 :(得分:4)
?
占位符不能包含在字符串文字中,但您可以使用SQL字符串连接||
将?
与%
字面值合并:
String where = "_id in(select phrase_id from words where word like '%' || ? || '%' intersect select phrase_id from words where word like '%' || ? || '%')";