python MySQLdb prepared select语句
在使用MySQLdb的python中,我尝试执行以下操作:python MySQLdb prepared select语句,python,select,prepared-statement,mysql-python,Python,Select,Prepared Statement,Mysql Python,在使用MySQLdb的python中,我尝试执行以下操作: cur.execute("select COUNT(*) from adjacency where r = %d and c = %d)" % (curRow, curCol) r和c是表邻接中的整数字段,也构成复合主键curRow和curCol是python程序中的整数变量。 MySQL正在抱怨: _mysql_exceptions.ProgrammingError: (1064, "You have an error in yo
cur.execute("select COUNT(*) from adjacency where r = %d and c = %d)" % (curRow, curCol)
r
和c
是表邻接
中的整数字段,也构成复合主键curRow
和curCol
是python程序中的整数变量。
MySQL正在抱怨:
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%d and c = %d' at line 1")
最后,我想检查是否已经存在与r=curCow
和c=curCol
相邻的行。如果是,则更新表中的字段。否则,在表中插入一行
非常感谢您的帮助 看起来你的括号放错地方了 改变
cur.execute("select COUNT(*) from adjacency where r = %d and c = %d)" % (curRow, curCol)
…到
cur.execute("select COUNT(*) from adjacency where r = %d and c = %d" % (curRow, curCol))
…虽然使用更安全
cur.execute("select COUNT(*) from adjacency where r = %s and c = %s", (curRow, curCol))
…这将保护您免受潜在的SQL注入。看起来您只是在错误的位置放了一个括号 改变
cur.execute("select COUNT(*) from adjacency where r = %d and c = %d)" % (curRow, curCol)
…到
cur.execute("select COUNT(*) from adjacency where r = %d and c = %d" % (curRow, curCol))
…虽然使用更安全
cur.execute("select COUNT(*) from adjacency where r = %s and c = %s", (curRow, curCol))
…这将保护您免受潜在的SQL注入。“我的预处理语句有什么问题?”您没有预处理语句。Python MySQLdb模块不支持这些语句。“我的prepared语句有什么问题?”您没有prepared语句。Python MySQLdb模块不支持这些。