kakyo
kakyo

Reputation: 11640

python sqlite3: How to use LIKE and ? to do partial matching?

With python sqlite3, I'd like to something like

cursor.execute('SELECT * FROM songs WHERE filename LIKE "?%"', (key_string,))

so that I can use the key as a variable instead of having to hard code the pattern. But this does not work and gives me:

ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 1 supplied.

Please help.

Upvotes: 1

Views: 2041

Answers (1)

kakyo
kakyo

Reputation: 11640

Figured out the answer my self:

cursor.execute('SELECT * FROM songs WHERE filename LIKE ?', ('{}%'.format(key_string),))

Upvotes: 2

Related Questions