我在python中有一个sqlite3表,如下所示:
CREATE TABLE words
(ID INTEGER PRIMARY KEY AUTOINCREMENT,
CURRENT_WORD TEXT NOT NULL,
BEFORE_WORD TEXT NOT NULL,
AFTER_WORD TEXT NOT NULL,
OCCURANCES INTEGER NOT NULL)
它返回以下数据库值:
(1, u'is', u'This', u'true', 0)
(2, u'you', u'are', u'ready', 1)
我希望能够提升价值' OCCURANCES'来自id 2.我尝试了以下内容,然后我计划使用正则表达式解析返回的值,但我的代码似乎没有工作:
def db_check(db, words):
conn = sqlite3.connect(db)
c = conn.cursor()
frequency = 0
print("SELECT * FROM words WHERE CURRENT_WORD = '" + words[1] + "' AND BEFORE_WORD = '" + words[0] + "' AND AFTER_WORD = '" + words[2] + "'")
for row in c.execute("SELECT * FROM words WHERE CURRENT_WORD = '" + words[1] + "' AND BEFORE_WORD = '" + words[0] + "' AND AFTER_WORD = '" + words[2] + "'"):
print "FOUND: "
print row
conn.commit()
if frequency == 0: frequency = 1
return frequency
知道我哪里出错了吗?我在最后一部分说我的SQL错了。有没有更好的方法来做到这一点,比如准确地拉动频率?