在使用下面的查询时,我得到了以下错误,在执行cursor.fetchall时已经给出了变量,不知道为什么会出现这个错误,如何克服这个错误?
查询:-
query = """SELECT metabuild,testbed FROM gerrits.pw WHERE warehouse ='%s'"""%(warehouse_name)
rows = cursor.execute(query)
(metaBuild,testbed)= cursor.fetchall() 错误:-
(metaBuild,testbed)= cursor.fetchall()
ValueError: need more than 1 value to unpack发布于 2015-07-17 00:27:09
或者,使用fetchone()
metaBuild, testbed = cursor.fetchone() 另外,不要通过字符串格式或插值来进行查询--这样您的代码就容易受到SQL注入攻击。相反,“参数化”查询:
query = """
SELECT
metabuild, testbed
FROM
gerrits.pw
WHERE
warehouse = %s
"""
cursor.execute(query, (warehouse_name, ))https://stackoverflow.com/questions/31466641
复制相似问题