qmark style updates

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

qmark style updates

dannykmcdaniel
I am trying following a simple example shown in one of
the online tutorials on pysqlite.
The example shows how to input a value using qmarks in
the statement. I am getting an error message
like"Incorrect number of bindings supplied. The
current statement uses 1, and there are -1 supplied."
my code is:

from pysqlite2 import dbapi2 as sqlite

con = sqlite.connect("mydb.db")
c = con.cursor()

s1 =333333333
toDo ="Update ex set amount = ? where ex_id = 1"
c.execute(toDo,s1)
con.commit()
c.close()


Can anyone help?

Dan


       
               
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: qmark style updates

Jay Sprenkle
the question mark is the indicator for a bound value.
Escape it, I think like this
> toDo ="Update ex set amount = '?' where ex_id = 1"
or
> toDo ="Update ex set amount = '\?' where ex_id = 1"

On 11/11/05, Dan McDaniel <[hidden email]> wrote:

> I am trying following a simple example shown in one of
> the online tutorials on pysqlite.
> The example shows how to input a value using qmarks in
> the statement. I am getting an error message
> like"Incorrect number of bindings supplied. The
> current statement uses 1, and there are -1 supplied."
> my code is:
>
> from pysqlite2 import dbapi2 as sqlite
>
> con = sqlite.connect("mydb.db")
> c = con.cursor()
>
> s1 =333333333
> toDo ="Update ex set amount = ? where ex_id = 1"
> c.execute(toDo,s1)
> con.commit()
> c.close()
>
>
> Can anyone help?
>
> Dan
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>


--
---
The Castles of Dereth Calendar: a tour of the art and architecture of
Asheron's Call
http://www.lulu.com/content/77264
Reply | Threaded
Open this post in threaded view
|

Re: qmark style updates

dannykmcdaniel
Thanks for the suggestion. It did not help however.
My code is modified from the code that I found at the
following web site:
http://initd.org/tracker/pysqlite/wiki/basicintro
The difference is that the examples on the above
website use the x =raw_input =('enter a value) syntax

I tried this to and got some strange behavior, like if
I entered a value like "3333333" it would give me a
similar error message, counting out the number
individual tokens as the number of values supplied in
the error message. Only when I entered a single
character at the raw input prompt could I get it to
work.

What I am really trying to do is find a
straightforward way to update a datetime.date field of
a data base.

I will continue to search for an  answer. Any help
will be appreciated.

again thanks for your response.
Dan

--- Jay Sprenkle <[hidden email]> wrote:

> the question mark is the indicator for a bound
> value.
> Escape it, I think like this
> > toDo ="Update ex set amount = '?' where ex_id = 1"
> or
> > toDo ="Update ex set amount = '\?' where ex_id =
> 1"
>
> On 11/11/05, Dan McDaniel <[hidden email]>
> wrote:
> > I am trying following a simple example shown in
> one of
> > the online tutorials on pysqlite.
> > The example shows how to input a value using
> qmarks in
> > the statement. I am getting an error message
> > like"Incorrect number of bindings supplied. The
> > current statement uses 1, and there are -1
> supplied."
> > my code is:
> >
> > from pysqlite2 import dbapi2 as sqlite
> >
> > con = sqlite.connect("mydb.db")
> > c = con.cursor()
> >
> > s1 =333333333
> > toDo ="Update ex set amount = ? where ex_id = 1"
> > c.execute(toDo,s1)
> > con.commit()
> > c.close()
> >
> >
> > Can anyone help?
> >
> > Dan
> >
> >
> >
> >
> > __________________________________
> > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > http://mail.yahoo.com
> >
>
>
> --
> ---
> The Castles of Dereth Calendar: a tour of the art
> and architecture of
> Asheron's Call
> http://www.lulu.com/content/77264
>



               
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: qmark style updates

Alexander J. Kozlovsky
In reply to this post by dannykmcdaniel
The second parameter of cursor.execute() accept **sequence** of
bindings. Try this:

     c.execute(toDo, [s1])
     

> from pysqlite2 import dbapi2 as sqlite
>
> con = sqlite.connect("mydb.db")
> c = con.cursor()
>
> s1 =333333333
> toDo ="Update ex set amount = ? where ex_id = 1"
> c.execute(toDo,s1)
> con.commit()
> c.close()
>
>
> Can anyone help?
 

Best regards,
 Alexander                            mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Thanks Alexander

dannykmcdaniel
Yes!
This works Thanks very much Alexander.

--- Alexander Kozlovsky <[hidden email]>
wrote:

> The second parameter of cursor.execute() accept
> **sequence** of
> bindings. Try this:
>
>      c.execute(toDo, [s1])
>      
>
> > from pysqlite2 import dbapi2 as sqlite
> >
> > con = sqlite.connect("mydb.db")
> > c = con.cursor()
> >
> > s1 =333333333
> > toDo ="Update ex set amount = ? where ex_id = 1"
> > c.execute(toDo,s1)
> > con.commit()
> > c.close()
> >
> >
> > Can anyone help?
>  
>
> Best regards,
>  Alexander                          
> mailto:[hidden email]
>
>



       
               
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: qmark style updates

Jay Sprenkle
In reply to this post by dannykmcdaniel
> I tried this to and got some strange behavior, like if
> I entered a value like "3333333" it would give me a

All text constants are entered with single quotes.
 insert into mytable(five) values( 'data' )