simon
simon

Reputation: 83

using sqlite3 and kivy

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

I want to add records into my database using the TextInput in kivy hence the 'self.post_text_input.text' etc, but I get this error:

OperationalError: no such column: self.nob_text_input.text
  

I tried putting the columns next to table name in the query:

c.execute("INSERT INTO business(column1, column2,column3) VALUES(self.nob_text_input.text....)

But I still get the same error.

Upvotes: 1

Views: 152

Answers (1)

squ1dd13
squ1dd13

Reputation: 84

Turning my comment into a more detailed answer.

If you're trying to use the values of the variables (self.nob_text_input.text and friends) in the string, you need to embed those values in the string.

One way is to use a format string:

"INSERT INTO business VALUES(%s, %s, %s)" % (self.nob_text_input.text, self.post_text_input.text, self.descrip_text_input.text)

And another is to just concatenate the strings:

"INSERT INTO business VALUES(" + self.nob_text_input.text + ", " + self.post_text_input.text + ", " + self.descrip_text_input.text + ")"

Upvotes: 1

Related Questions