I have a simple FTS5 query like source
function getRes(q) {
const sel = 'SELECT Count(id) AS c FROM t JOIN v ON t.id = v.id WHERE v MATCH ?';
return db.prepare(sel).get(q);
}
The above fails for getRes('Trematoda (awaiting allocation)')
with the following error
SqliteError: fts5: syntax error near "Trematoda"
Of course, it works fine for getRes('Trematoda')
so it is the parens that are causing the problem. Since I can't guarantee what characters will be in my query, how can I ensure this succeeds? From my Perl+Postgres days, I seem to remember that binding automatically did all the escaping properly. Seems that is not the case with JavaScript+SQLite. On further testing, it fails in the SQLite shell as well but it does work fine in TablePlus, a GUI for SQLite.