$ ./guess_the_languageSQL & Databases
SQL & Databases · hard · #54

Why can this return items not containing "50%"?

# input = '50%'  (parameterized)
cur.execute(
  "SELECT * FROM items WHERE name LIKE ?",
  ('%' + input + '%',))
  1. The driver strips the % signs
  2. Parameters disable the LIKE match
  3. The % in input acts as a wildcard
  4. LIKE here compares numbers only
Binding stops injection but not pattern meaning: escape % and _ and add an ESCAPE clause.
Play SQL & Databases ▸