【发布时间】:2015-07-12 01:37:41
【问题描述】:
我正在尝试检查一个条目是否已经在数据库中,如果没有则添加该条目,但即使满足条件,if 语句也不会运行。
userCurs.execute("SELECT EXISTS(SELECT 1 FROM images WHERE imageLink=?)", (image,))
exists = userCurs.fetchone()
if exists is None:
addImage(userName,image,'','')
else:
print '--------> image skipped'
print userCurs.fetchone()
我得到这个输出:
--------> image skipped
None
--------> image skipped
None
数据库中没有任何条目
【问题讨论】:
-
你给
fetchone打了两次电话。这可能是个问题吗? -
当我将其更改为存在时,我得到
--------> image skipped (0,) --------> image skipped (0,) -
你调用了两次
fetchOne,如果你在最后一行print exists呢?