【发布时间】:2016-02-04 05:53:33
【问题描述】:
我在 python 中使用 sqlite3 时遇到了问题。
def getEntryId(self, table, field, value, createNew=True):
cur=self.con.execute("select rowid from %s where %s = '%s'" % (table, field, value))
res=cur.fetchone()
if res==None:
cur=self.con.execute("insert into %s (%s) values('%s') " % (table, field, value))
return cur.lastrowid
else:
return res[0]
但是,我遇到了这个: OperationalError:无法识别的令牌:“'''”。看来我的第二行代码不正确。 我不知道为什么,所以我做了同样的事情:
cu.execute("select rowid from urllist where %s = '%s'" % ('url', 'yes'))
它没有出现错误。为什么?我该如何解决?
【问题讨论】:
-
很可能,您有一个 Bobby Tables 的亲戚访问您的程序,输入撇号表示您的值。