Pyodbc query string quote escaping

后端 未结 1 1463
粉色の甜心
粉色の甜心 2021-01-20 09:52

I\'m trying to execute a query using pyodbc with this kind of code

cursor.execute(\"SELECT x from y where Name=\'%s\'\"%namepar)

The parame

相关标签:
1条回答
  • 2021-01-20 10:18

    You can pass parameters, and that will be escaped.

    cursor.execute("SELECT x from y where Name = ?", (namepar,))
    

    http://www.python.org/dev/peps/pep-0249/#id15

    http://code.google.com/p/pyodbc/wiki/Cursor

    0 讨论(0)
提交回复
热议问题