473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Python sqlite qmark create table

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:

# CODE BEGIN
import sqlite3

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

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

This throws up the following error:

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

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
0 1716

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

Similar topics

11
by: Gerhard Haering | last post by:
Last December, we had a short thread discussing (in python-dev) the integration of PySQLite into Python 2.4. At the time, I was against inclusion, because I thought PySQLite was not ripe for it,...
8
by: Vittorio | last post by:
I am reading "Beginning Python from Novice to Professional" and the book is really awesome. Nonetheless on ch 13 "Database Support" I found this code to import data (in a txt file) into a SQLite...
1
by: jander22 | last post by:
Hi, I just started playing with Python and I am working on a program that pulls data from a table in Oracle and creates a similar table in SQLite. Basically, I want to be able to do this: create...
4
by: Jim Carlock | last post by:
I added the following lines to PHP.INI. extension=php_pdo.dll extension=php_pdo_sqlite.dll extension=php_sqlite.dll specifically in that order. I noticed the extensions getting loaded are...
11
by: walterbyrd | last post by:
With PHP, libraries, apps, etc. to do basic CRUD are everywhere. Ajax and non-Ajax solutions abound. With Python, finding such library, or apps. seems to be much more difficult to find. I...
2
by: Joe Goldthwaite | last post by:
I'm confused. (Not a new experience). I've got a web application running under Zope. I use the Wing IDE for testing and debugging. When trying to recreate problems that come up on the web, I...
0
by: Guilherme Polo | last post by:
On Tue, Jul 1, 2008 at 9:51 PM, Joe Goldthwaite <joe@goldthwaites.comwrote: You need sqlite itself (www.sqlite.org) and bindings, pysqlite 2 (http://oss.itsystementwicklung.de/trac/pysqlite/) or...
0
by: Joe Goldthwaite | last post by:
Thanks Guilherme. That helped. I guess I was thinking that pysqlite would automatically come with some version of sqlite. The fact that it doesn't is what was causing me to get the strange...
2
by: Guillermo | last post by:
Hi! Is it possible to use the full-text module of SQLite with the sqlite3 module? I've done a bit of investigation and it seems the stand-alone distribution of SQLite is compiled without it, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.