Python MySQL parameterized query conflicts with % wildcard in LIKE statement

前端 未结 2 727
無奈伤痛
無奈伤痛 2021-01-16 16:29

My query on execution of this fails:

cursor.execute(\"SELECT name FROM products WHERE rating > %s AND category like \'Automation %\'\", (3));
2条回答
  •  粉色の甜心
    2021-01-16 17:00

    You can probably escape it using an extra %:

    cursor.execute("SELECT name FROM products WHERE rating > %s AND category like 'Automation %%'", (3));
    

    This apparently works for MySQLdb and I would expect it to work for python-mysql as well. . .

提交回复
热议问题