psycopg2遵循DB-API
2.0的规则(在PEP-249中设置)。这意味着您可以
execute从
cursor对象中调用方法并使用
pyformat绑定样式,它将为您进行转义。例如,以下
应该 是安全的(并且可以正常工作):
cursor.execute("SELECt * FROM student WHERe last_name = %(lname)s", {"lname": "Robert'); DROP TABLE students;--"})
psycopg2遵循DB-API
execute从
cursor对象中调用方法并使用
pyformat绑定样式,它将为您进行转义。例如,以下
cursor.execute("SELECt * FROM student WHERe last_name = %(lname)s", {"lname": "Robert'); DROP TABLE students;--"})