sqlite - Populating sqlite3 database in Python loop -
i have constructed database when loop through data populate it, following error:
operationalerror: no such column: tmp1
code:
with con: cur = con.cursor() cur.execute("create table testtable(x real, y real)") in xrange(0,5): tmp1 = array[i,0] tmp2 = array[i,1] con: cur.execute("""insert testtable values(tmp1,tmp2)""")
basically have big array want transfer database. isn't efficient way of going it. suggestions?
if want insert values row, need pass values along sql parameters .execute()
call:
with con: in xrange(0,5): tmp1 = array[i, 0] tmp2 = array[i, 1] cur.execute("""insert testtable values(?, ?)""", (tmp1, tmp2))
the ?
characters parameters, , filled, in order, values takes second argument .execute()
, tuple. above code insert numbers 0 through 4 pairs database.
names in sql code have no correlation names define in python, values can passed in explicitly.
Comments
Post a Comment