我知道在同一个问题上有很多问题,但是我还没有找到解决问题的办法。你知道吗
据我所知,这不是一个元组问题。你知道吗
我将一个2元组传递给一个带有2个问号的查询。 Sqlite说它只需要1。你知道吗
代码:
def getRecipeId(categoryId, name):
query = "SELECT id from tbl_recipes where name = '?' and categoryId = ?"
result = sql.getOne(query, (name, int(categoryId)))
print(result)
def getOne(query, parameters = ()):
conn = sqlite3.connect(db.name)
c = conn.cursor()
print(query)
print(parameters)
c.execute(query, parameters)
a = c.fetchone()
return a
当我调用getRecipeId(6,“SomeName”)时,我得到如下输出:
SELECT id from tbl_recipes where name = '?' and categoryId = ?
('SomeName', 6)
Traceback (most recent call last):
File "C:\Users\Peter\AppData\Local\Programs\Python\Python35-32\lib\site-packages\bottle.py", line 862, in _handle
return route.call(**args)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python35-32\lib\site-packages\bottle.py", line 1732, in wrapper
rv = callback(*a, **ka)
File "calculator.py", line 106, in finishEdit
recipes.updateRecipe(categoryId, name, ingredientList)
File "C:\Users\Peter\Documents\perso\costCalculator\recipes.py", line 40, in updateRecipe
recId = getRecipeId(categoryId, name)
File "C:\Users\Peter\Documents\perso\costCalculator\recipes.py", line 36, in getRecipeId
result = sql.getOne(query, (name, int(categoryId)))
File "C:\Users\Peter\Documents\perso\costCalculator\sql.py", line 59, in getOne
c.execute(query, parameters)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied.
我一辈子都察觉不出我做错了什么。你知道吗
不要把占位符放在引号里。你知道吗
相关问题 更多 >
编程相关推荐