The foods table contains a field food_names , in which spaces of the product name are listed using spaces, for example: beer пиво пивко пивасик , and there can be one or more synonymous names.

I want to select all the rows in the table whose food_names fields contain at least one word used in the query. Those. I want to make a request, for example,

 SELECT * FROM foods WHERE food_names LIKE '% beer%'
It turns out:

 >>> import sqlite3
 >>> conn = sqlite3.connect ("foods.db")
 >>> c = conn.cursor ()
 >>> c.execute ("SELECT * FROM foods WHERE food_names LIKE '%?%'", ("beer"))
 Traceback (most recent call last):
   File "", line 1, in 
     c.execute ("SELECT * FROM foods WHERE food_names LIKE '%?%'", ("beer",))
 sqlite3.ProgrammingError: Incorrect number of bindings supplied.  The current statement uses 0, and there are 1.
 >>> 

What needs to be fixed?

1 answer 1

Will work option:

 c.execute("SELECT * FROM foods WHERE food_names LIKE ?", ("%пиво%",)) 

If the question mark? in the query text, wrapped in quotes (as in '%?%'), the parser recognizes it as a question mark as such, as a letter, but not as a parameter substitution point.