using array as execute parameter in dbapi

gglegrp112 at alhashash.net gglegrp112 at alhashash.net
Fri Jul 21 16:52:14 EDT 2006


Is it possible to send an array as a parameter for an execute method in
dbapi2 module?


I'm using adodbapi and try to perfrom the following SQL query:
     select * from item where storeid in ('01', '02')

When I use direct string formating it works:

     a=('01','02')
cur.execute('select * from item where storeid in %s' % a.__repr__())

but trying to use parameter does not work:

     cur.execute('select * from item where storeid in ?', a)
     cur.execute('select * from item where storeid in ?', (a,))
     cur.execute('select * from item where storeid in ?', ([a],)

and even this does not work:
     cur.execute('select * from item where storeid in ?', a.__repr__())
     cur.execute('select * from item where storeid in ?',
(a.__repr__(),))

surprisingly, this get executed be returns wrong result:
     cur.execute('select * from item where storeid in (\'?\'),
"','".join(a))
I guess the question mark gets escaped by the quotes the parameter is
ignored.

Regards,

Magdy Salam




More information about the Python-list mailing list