You don't appear to show how the table name is being substituted in? You set q, but there is no reference to the table.
q
Also has the table been created as an FTS table?