MySQL 中的准备语句 - 尝试删除一行导致 ProgrammingError
Prepared Statements in MySQL - Trying to remove a row results in ProgrammingError
我想使用准备好的语句从 table 中删除一行,但会导致错误:mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
相关代码:
db = mysql.connector.connect(
host='localhost',
user='user',
database='web_board',
password='password',
auth_plugin='mysql_native_password'
)
crs = db.cursor()
# construct the query and remove post from the database
query = 'DELETE FROM posts WHERE postid=%s'
crs.execute(query, tuple(request.data))
db.commit()
crs.close()
db.close()
request.data
看起来像这样:b'9b23f24e-ff4d-4113-85ae-ff8a4a5de3be'
与 documentation states 一样,要使用准备好的语句,您应该使用以下配置实例化您的游标:
crs = db.cursor(prepared=True)
使用 MySQLCursorPrepared 执行的准备好的语句可以使用格式 (%s) 或 qmark (?) 参数化样式。
我想使用准备好的语句从 table 中删除一行,但会导致错误:mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
相关代码:
db = mysql.connector.connect(
host='localhost',
user='user',
database='web_board',
password='password',
auth_plugin='mysql_native_password'
)
crs = db.cursor()
# construct the query and remove post from the database
query = 'DELETE FROM posts WHERE postid=%s'
crs.execute(query, tuple(request.data))
db.commit()
crs.close()
db.close()
request.data
看起来像这样:b'9b23f24e-ff4d-4113-85ae-ff8a4a5de3be'
与 documentation states 一样,要使用准备好的语句,您应该使用以下配置实例化您的游标:
crs = db.cursor(prepared=True)
使用 MySQLCursorPrepared 执行的准备好的语句可以使用格式 (%s) 或 qmark (?) 参数化样式。