Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python MySQLdb prepared select语句_Python_Select_Prepared Statement_Mysql Python - Fatal编程技术网

python MySQLdb prepared select语句

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

在使用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 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模块不支持这些。