Re: Error Binding Parameter 0

Adrian Klaver <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
On Wednesday 20 December 2006 5:17 pm, Rich Shepard wrote:
> On Wed, 20 Dec 2006, Rich Shepard wrote:
> >   What do you suggest as a way of re-writing the above as a set of
> > concatenated strings? My first attempt generates an error near the comma
> > in the third line.
>
>    I don't know near which comma the error is located. After several other
> format changes I now have this:
>
>    stmt1 = """insert into variable (var_name, var_desc, policy_name,
> sub_policy_name) values (?,?,?,?),
                                                      ^ comma referenced
>            (varDlg().varName, varDlg().varDesc, varDlg().polName,
> varDlg().subName) """
>    self.appData.cur.execute(stmt1)
>
> and the error message is:
>
>    File "/data1/eikos/variablePage.py", line 239, in OnVarAdd
>      self.appData.cur.execute(stmt1)
> pysqlite2.dbapi2.OperationalError: near ",": syntax error
>
>    I don't know _which_ comma is referenced so I don't see the error.
>
> Rich
The problem is that triple quoting leads to a stmt1 string passed to 
cur.execute of:

 "insert into variable (var_name, var_desc, policy_name,
 sub_policy_name) values (?,?,?,?),(varDlg().varName, varDlg().varDesc, 
varDlg().polName,varDlg().subName) "
                                                          ^ quote
when what you want is:

"insert into variable (var_name, var_desc, policy_name,
 sub_policy_name) values (?,?,?,?)",(varDlg().varName, varDlg().varDesc, 
varDlg().polName,varDlg().subName) 
                                                         ^ no quote
To do this you need to have stmt1 be:

"insert into variable (var_name, var_desc, policy_name, sub_policy_name) 
values (?,?,?,?)"

and your execute be:

cur.execute(stmt1,(varDlg().varName, varDlg().varDesc, 
varDlg().polName,varDlg().subName)
-- 
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.