I construct selection string to perform FTS3 search across multiple columns:
final String selection = "table MATCH 'column1:? OR column2:?'"
I am also passing selectionArgs containing the search terms. The problem is that I'm getting an exception during argument binding:
11-30 13:22:27.475 26281-26323/com.example.myapp W/SuggestionsAdapter﹕ Search suggestions query threw an exception. java.lang.IllegalArgumentException: Cannot bind argument at index 2 because the index is out of range. The statement has 0 parameters. at android.database.sqlite.SQLiteProgram.bind(SQLiteProgram.java:212) at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:166)
When I replace question marks in the MATCH argument string with hard-coded search terms and set selectionArgs = null
, the query works and returns correct results.
How can I bind selectionArgs to a FTS3 query that searches across multiple columns?
The following approach worked for me:
String.format()
to constructselectionArgs
, using search terms as arguments.selection
In code: