Sqlite and python timestamp -
i have code in python 2.4:
import datetime, time, sqlite def metodo(date): conn = sqlite.connect('database.db') c = conn.cursor() c.execute("insert f values(?,?)", (3,date)) conn.commit() conn.close() end_date=datetime.datetime(2012, 10, 21, 0, 0) print end_date metodo(end_date)
and sqlite database int , timestamp
create table f(id int, time timestamp)
but obtain in python:
traceback (most recent call last): file "prueba.py", line 13, in ? metodo(end_date) file "prueba.py", line 6, in metodo c.execute("insert f values(?,?)", (3,date)) file "/usr/lib/python2.4/site-packages/sqlite/main.py", line 255, in execute self.rs = self.con.db.execute(sql % parms) typeerror: not arguments converted during string formatting
this code run well. problem timestamp:
import datetime, time, sqlite def metodo(date): conn = sqlite.connect('database.db') c = conn.cursor() c.execute("insert values(%s)", date) conn.commit() conn.close() metodo("stringtest")
and sqlite database int , timestamp
create table a(test text)
i think should parameterize this:
def metodo(date): conn = sqlite.connect('database.db') c = conn.cursor() c.execute("insert values(%s)", (date,)) conn.commit() conn.close()
Comments
Post a Comment