cursor.fetchone() returns 一个不在数据库中的值
cursor.fetchone() returns a value that isn't in the database
我正在运行一个来自 Python 的存储过程,它在 MYSQL 数据库上执行 SELECT 查询以确定记录是否已经存在。
执行后,我使用 cursor.fetchone() 将查询结果与变量值进行比较。但是,当我检查查询结果中保存的值时,它与我通过查询传递的参数相同,即使数据库中不存在该记录。
这当然应该是 None
?
郑重声明,我传递的参数的方向为 IN,并且是一个整数。
我已经检查了 SO 的其余部分,我看到的所有此类问题都与我得到的相反!我还研究了 cursor.fetchone() 以确保我正确使用它,而且看起来我是。
如有任何帮助,我们将不胜感激!
table我正在查询
编号=1
名字=名字
存储过程
CREATE PROCEDURE `storedprocedure2`(IN `param` INT) NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER
SELECT `This`
FROM `That`
WHERE `This` = param
查询调用
def loadintodatabase(self, connection, args):
value1 = args[0]
value2 = args[1]
value3 = args[2]
value4 = args[3]
value5 = args[4]
value6 = args[5]
value7 = args[6]
value8 = args[7] #this is a list
value8length = len(value8)
value9 = args[8] #this is also a list
value9length = len(value9)
id = 0
i = 0
idlist = [] #this is not related to the id variable
idlistincrement = 0
if value 8 != []:
while i < value8length:
cursor = connection.cursor()
cursor.callproc('storedprocedure1', (value8[0], value8[1], value8[2])) #Inserts into a different table
idlist.append(value8[0])
cursor.close()
connection.commit()
i += 1
i = 0
if value3 != 0 and value4 is not None:
cursor = connection.cursor()
cursor.callproc('storedprocedure2', (param,)) #lets say param holds 11 as an int, sproc is a select query
result = cursor.fetchone() #result should be None but instead is (11L,)
if result is None:
id = None
else:
id = result[0]
if id is None:
cursor = connection.cursor()
cursor.callproc('storedprocedure3', (value3, value4)) #sproc inserts into the table I just selected the id from
cursor.close()
connection.commit()
存储过程有点错误。
SELECT `This`
FROM `That`
WHERE `This` = param
应该是
BEGIN
SELECT `This`
FROM `That`
WHERE `This` = param;
END
现在 cursor.fetchone() returns None
符合预期!
我正在运行一个来自 Python 的存储过程,它在 MYSQL 数据库上执行 SELECT 查询以确定记录是否已经存在。
执行后,我使用 cursor.fetchone() 将查询结果与变量值进行比较。但是,当我检查查询结果中保存的值时,它与我通过查询传递的参数相同,即使数据库中不存在该记录。
这当然应该是 None
?
郑重声明,我传递的参数的方向为 IN,并且是一个整数。
我已经检查了 SO 的其余部分,我看到的所有此类问题都与我得到的相反!我还研究了 cursor.fetchone() 以确保我正确使用它,而且看起来我是。
如有任何帮助,我们将不胜感激!
table我正在查询
编号=1
名字=名字
存储过程
CREATE PROCEDURE `storedprocedure2`(IN `param` INT) NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER
SELECT `This`
FROM `That`
WHERE `This` = param
查询调用
def loadintodatabase(self, connection, args):
value1 = args[0]
value2 = args[1]
value3 = args[2]
value4 = args[3]
value5 = args[4]
value6 = args[5]
value7 = args[6]
value8 = args[7] #this is a list
value8length = len(value8)
value9 = args[8] #this is also a list
value9length = len(value9)
id = 0
i = 0
idlist = [] #this is not related to the id variable
idlistincrement = 0
if value 8 != []:
while i < value8length:
cursor = connection.cursor()
cursor.callproc('storedprocedure1', (value8[0], value8[1], value8[2])) #Inserts into a different table
idlist.append(value8[0])
cursor.close()
connection.commit()
i += 1
i = 0
if value3 != 0 and value4 is not None:
cursor = connection.cursor()
cursor.callproc('storedprocedure2', (param,)) #lets say param holds 11 as an int, sproc is a select query
result = cursor.fetchone() #result should be None but instead is (11L,)
if result is None:
id = None
else:
id = result[0]
if id is None:
cursor = connection.cursor()
cursor.callproc('storedprocedure3', (value3, value4)) #sproc inserts into the table I just selected the id from
cursor.close()
connection.commit()
存储过程有点错误。
SELECT `This`
FROM `That`
WHERE `This` = param
应该是
BEGIN
SELECT `This`
FROM `That`
WHERE `This` = param;
END
现在 cursor.fetchone() returns None
符合预期!