简体   繁体   English

Sqlite3 插入查询错误?

[英]Sqlite3 INSERT query ERROR?

i want to insert in my DB 2 strings var我想插入我的 DB 2 字符串 var

one entered from the user ==> H and从用户输入的一个 ==> H 和

one generated form the chatbot==> B一个从聊天机器人中生成的==> B

Here is the code:这是代码:

# 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)

The codes works perfectly in generating and selecting the replay from the DB , but the problem is when i go back to the chatting_log table in the DB there is no data?这些代码在从 DB 生成和选择重播方面完美无缺,但问题是当我回到 DB 中的 chatting_log 表时没有数据?

PS: i am using python 3 PS:我正在使用 python 3

thank you,谢谢你,

Always remember to commit the changes that you make.永远记住提交您所做的更改。 In this case: connection.commit() .在这种情况下: connection.commit() Except it looks like you overrode your connection variable.除了看起来您覆盖了connection变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM