[DB-SIG] db module wrapper

Randall Smith randall at tnr.cc
Fri Aug 20 21:52:16 CEST 2004


Assume that the first item in the list is always sql.  Is that a valid 
assumption?

Randall

Ian Bicking wrote:
> Just thought about it, how would you deal with:
> 
> name = 'bob'
> query = ['select * from tname where col = ', name]
> 
> The query is just two strings -- the first is a SQL expression, the 
> second some data.  But there's no way to tell that just from looking at 
> the query list.
> 
> 
> 
> Randall Smith wrote:
> 
>> Ian,
>>
>> What do you think about Vernon Cole's idea with passing a query in as 
>> a list.  I thought about it and I'm starting to like it.  Check this out.
>>
>> 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)
>>
>> Note: This is like executemany.
>>
>> There is no need for parsing at all and the line breaking encouraged 
>> by using a list makes for readable code.
>>
>> What do you think?
>>
>> Randall
> 
> 


More information about the DB-SIG mailing list