Inserting multiple types into an SQLite database with Python

Posted by mankoff on Stack Overflow See other posts from Stack Overflow or by mankoff
Published on 2009-12-26T16:55:44Z Indexed on 2010/03/15 2:59 UTC
Read the original article Hit count: 292

Filed under:
|
|
|

I'm trying to create an SQLite 3 database from Python. I have a few types I'd like to insert into each record: A float, and then 3 groups of n floats, currently a tuple but could be an array or list.. I'm not well-enough versed in Python to understand all the differences. My problem is the INSERT statement.

DAS = 12345
lats = (42,43,44,45)
lons = (10,11,12,13)
times = (1,2,3,4,5,6,7,8,9)

import sqlite3
connection = sqlite3.connect("test.db")
cursor = connection.cursor()
cursor.execute( "create table foo(DAS LONG PRIMARY KEY,lats real(4),lons real(4), times real(9) )" )

I'm not sure what comes next. Something along the lines of:

cmd = 'INSERT into foo values (?,?,?,?), ..."
cursor.execute(cmd)

How should I best build the SQL insert command given this data?

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlite