sqlite3.OperationalError: no such column: - Python

1286
January 31, 2018, at 5:55 PM

I am trying to Inserat something from Input into my Database. But getting the Error:

sqlite3.OperationalError: no such column: kundename

import sqlite3
conn = sqlite3.connect('datenbank.db')
print ("Opened database successfully")
kundenname= input("Kundename: ")
auftragstyp= input("Auftragstyp: ")
auftragsurl= input("Auftragsurl: ")
anzahl= input("Anzahl der Bewertungen: ")
conn.execute("INSERT INTO kundenname VALUES (kundename,auftragstyp,auftragsurl,anzahl)", (kundenname, auftragstyp,         auftragsurl,  anzahl))
conn.commit()
print ("Records created successfully")
conn.close()

But if I make like:

import sqlite3
conn = sqlite3.connect('datenbank.db')
print ("Opened database successfully")
conn = conn.execute("SELECT ID, kundename from kundenname")
for row in conn:
print ("ID = ", row[0])
print ("kundename = ", row[1])
print ("Operation done successfully")
conn.close()

then it works and Shows me the Datas in the Base. But why insert saying the colum dosent excist?

Thank you very much!

Answer 1

I think you have a problem with this line:

conn.execute("INSERT INTO kundenname VALUES 
(kundename,auftragstyp,auftragsurl,anzahl)", (kundenname, auftragstyp,         
auftragsurl,  anzahl))

This is not the way to insert, try this:

conn.execute("INSERT INTO kundenname 
('kundename','auftragstyp','auftragsurl','anzahl') VALUES (" + 
str(kundename) +"," + str(auftragstyp) + "," +  str(auftragsurl) + "," 
+ str(anzahl)+")"
Answer 2

The interpreter is complaining about your using unquoted strings. It's interpreting them as variable names in your insert statement. Try this:

conn.execute("INSERT INTO kundenname ('kundename','auftragstyp','auftragsurl','anzahl') VALUES (kundenname, auftragstyp,  auftragsurl,  anzahl)")
READ ALSO
Looping through data in a CSV file in order to output '1' and '0' to a text file (Python)

Looping through data in a CSV file in order to output '1' and '0' to a text file (Python)

I have recently started learning Python and have run into a problem in trying to format some data for a project I am working onI have managed to take in a CSV file as an input and I am now trying to go through that data and output '1's and '0's based upon the data, in to a text file

230
Could not find wheel packages using pip command on CentOS?

Could not find wheel packages using pip command on CentOS?

If I am running pip install scipy on Ubuntu, pip finds whl package and installs it but for centos, it tries to download the source and compile and install it explicitlyI have observed this with lots of packages while installing on centos I would like to know is there anything...

288
Issues with matshow

Issues with matshow

I am trying to show a matrix and a related vector data together using matplotlib matshow

263