By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

Python sqlite qmark create table

P: 1
Hope somebody could help me with the creation of a table in sqlite3 from python.

I am developing an application that allows a user to import a data file and insert the data into a sqlite3 database.

I want the names of the fields to be derived from the first row of the file.

I have been trying to perform this with code like:

import sqlite3

con = sqlite3.connect(":memory:")
cur = con.cursor()

# Create the table
con.execute("CREATE TABLE table1 (?, ?)", ('one', 'two'))

This throws up the following error:

Traceback (most recent call last):
File "/Users/xxx/Documents/Projects/", line 7, in <module>
con.execute("CREATE TABLE table1 (?, ?)", ('one', 'two'))
OperationalError: near "?": syntax error

Any help or suggestions on how to get the field names from the file dynamically inserted as the field names on the creation of the table would be much appreciated. Just for further information the names 'one' and 'two' are used as an example but in reality are stripped from the data file as the file is read into python.

Thanks in advance
Jan 21 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.