我想在我的 DB 2 字符串中插入 var
用户输入的一个 ==> H 和
由聊天机器人生成的一个==> B
这是代码:
# initialize the connection to the database
sqlite_file = '/Users/emansaad/Desktop/chatbot1/brain.sqlite'
connection = sqlite3.connect(sqlite_file)
connection.create_function("REGEXP", 2, regexp)
cursor = connection.cursor()
connection.text_factory = str
connection = open
def new_data(Input,Output):
row = cursor.execute('SELECT * FROM chatting_log WHERE user=?',(Input,)).fetchone()
if row:
return
else:
cursor.execute('INSERT INTO chatting_log VALUES (?, ?)', (Input, Output))
while True:
print(("B:%s" % B))
H = input('H:')
New_H= ' '.join(PreProcess_text(H))
reply= cursor.execute('SELECT respoce FROM Conversation_Engine WHERE request REGEXP?',[New_H]).fetchone()
if reply:
B=reply[0]
new_data(H,B)
代码在从数据库生成和选择重播方面工作得很好,但问题是当我返回到数据库中的chatting_log表时没有数据?
PS:我使用的是 python 3
谢谢,
最佳答案
始终记住提交您所做的更改。在本例中:connection.commit()
。只是看起来您覆盖了 connection
变量。
关于python - Sqlite3 INSERT查询错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40047742/