使用Python和SQlite3,其中c是游标,这段代码......。
print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
print("SQL and parameters:",sql,parm)
c.execute(sql,parm)
# Get the row
print("Executed OK")
response = c.fetchone()
# If not successful return null
if not response:
return None
#
print("and produced ", response)
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
给出这样的输出。
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
SQL and parameters: select * from Links where LinkNum = ? (301,)
Executed OK
and produced (301, 'Index', 'The Independent', 'https://www.independent.co.uk/', 6, 0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
SQL and parameters: select * from Links where LinkNum = ? (301,)
Encountered exception of type ProgrammingError with arguments ('Incorrect number of bindings supplied. The current statement uses 1, and there are 6 supplied.',)
The application will close
两个相同的语句. 1条有效,下一条则抛出异常。可以看出,我试图检索的行有6列,但这是我能看到的唯一的提示线索。有谁能帮忙追踪一下这个问题?谢谢。
不管是什么原因导致了SQLite发作,我通过在Links对象之外检索第二个rowobject,并将其作为参数传递给我正在调用的方法,而不是让该方法试图检索该对象来补救这个问题。
这个问题仍然存在,但一定是Python实例化和SQLite内部的问题。不管怎么样,这个问题用一些不那么花哨的代码就可以解决了。