[DB-SIG] db module wrapper
Ian Bicking
ianb at colorstudy.com
Fri Aug 20 23:06:41 CEST 2004
Randall Smith wrote:
>> I'm still thinking about how .executemany() might work...
>> -----
>
> Easy. Look at my previous posts.
>
> l1 = ['harry', 'sam', 'charley']
> l2 = [1, 2, 3]
>
> query = "select * from tname where col1 = ", l1, " and col2 = ", l2
> cursor.execute(query)
>
> query = []
> query.append('select * from tname where col1 = ')
> query.append(l1)
> query.append('and col2 = ')
> query.append(l2)
> cursor.execute(query)
I think you'd still want cursor.executemany(query), as you don't want to
simple infer executemany by the presence of a list. In essence, what I
think you are suggesting is that this executemany:
cursor.executemany(
"SELECT * FROM tname WHERE col = ? AND col2 = ?",
[('harry', 1), ('sam', 2), ('charley', 3)])
Becomes:
cursor.executemany(
"SELECT * FROM tname WHERE col = ",
['harry', 'sam', 'charley'],
" AND col 2 = ",
[1, 2, 3])
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the DB-SIG
mailing list