Re: Refactoring Table Creation

Adrian Klaver <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
On Monday 27 November 2006 01:15 pm, Rich Shepard wrote:
>    I don't have the proper syntax to insert values into a table when it's
> created. In my application there are three tables with text values that are
> used in the model; I want to enter those values when the tables are
> created.
>
>    With the syntax,
>
>            categoryList = ['natural', 'economic', 'societal']
>            self.cur.execute("CREATE TABLE category (cat_name TEXT NOT NULL
> PRIMARY KEY);") for i in categoryList:
>              self.cur.execute("insert into category (cat_name) values (?)",
> i)
>
>    I get a pysqlite2 error, "pysqlite2.dbapi2.ProgrammingError: Incorrect
> number of bindings supplied. The current statement uses 1, and there are 7
> supplied."
>
>    If I make three separate insert statements, it works.
>
>    What is the correct syntax to keep the words in a list and have them
> correctly inserted?
>
> TIA,
>
> Rich
The parameters need to be supplied in a tuple, even if there is only one. 
So the statement should be-
self.cur.execute("insert into category (cat_name) values (?)",(i,))
-- 
Adrian Klaver	
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.