问题描述:

print msg returns ['2013-07-08 10','temperature','kitchen','22.5']

When I run this code :

data="bdd.sq3"

conn=sqlite3.connect(data)

cur=conn.cursor()

cur.execute("CREATE TABLE IF NOT EXISTS temperature (date TEXT, type TEXT, zone TEXT, value REAL)")

cur.execute("INSERT INTO temperature (date TEXT, type TEXT, zone TEXT, value REAL) VALUES(?,?,?,?)",(msg))

I have this error :

cur.execute("INSERT INTO temperature (date TEXT, type TEXT, zone TEXT, value REAL) VALUES(?,?,?,?)",(msg))

sqlite3.OperationnalError: near "TEXT": syntax error

But I can’t see what’s wrong. I use similar code in other program and it works perfectly.

网友答案:

You don't need those TEXT tags when inserting in your database. You only use that when creating the database table. Just make sure that the values you're inserting in the database are the same type as you've given when creating the table.

相关阅读:
Top