conn = sqlite3.connect('business_database.db')
c = conn.cursor()
c.execute("INSERT INTO business VALUES(self.nob_text_input.text, self.post_text_input.text, self.descrip_text_input.text )")
conn.commit()
conn.close()
我想使用kivy中的TextInput将记录添加到我的数据库中,因此使用"self.post_text_input.text"等,但我收到了以下错误:
OperationalError: no such column: self.nob_text_input.text
我尝试将列放在查询中的表名旁边:
c.execute("INSERT INTO business(column1, column2,column3) VALUES(self.nob_text_input.text....)
但我还是犯了同样的错误。
将我的评论转化为更详细的答案
如果您试图在字符串中使用变量(self.nob_text_input.text
和友元(的值,则需要将这些值嵌入字符串中。
一种方法是使用格式字符串:
"INSERT INTO business VALUES(%s, %s, %s)" % (self.nob_text_input.text, self.post_text_input.text, self.descrip_text_input.text)
另一种是将字符串连接起来:
"INSERT INTO business VALUES(" + self.nob_text_input.text + ", " + self.post_text_input.text + ", " + self.descrip_text_input.text + ")"