[DB-SIG] Proposed improvements to DBAPI 2.0 Cursor.execute() method.

Ricardo Bugalho ricardo.b at zmail.pt
Mon Nov 13 19:46:31 CET 2006


On Mon, 2006-11-13 at 02:17 -0500, Martin Blais wrote:
> > "Martin Blais" <blais at furius.ca> writes:
> >
> > > I want to propose a few improvements on the DBAPI 2.0 Cursor.execute()
> > > method interface.  You can find the details of my proposed changes
> > > here:
> > > http://furius.ca/pubcode/pub/conf/common/lib/python/dbapiext.html

1 The process of building up a query happens in two steps

You propose 
	cursor.execute('''
	   SELECT name, address FROM %s WHERE id = %S
	''', (table_name, the_id,))

as a better alternative to 
	cursor.execute('''
	   SELECT name, address FROM %s WHERE id = %%s
	''' % table_name, (the_id,))

I do not like your proposal, for two reasons. First, dynamic query
construction can assume many forms, many more complex than this case. I
think it should not be added to the functions of .execute(). Second,
your proposal is error prone: %s vs %S

I like one is better:
	cursor.execute('''
	   SELECT name, address FROM %s WHERE id = :1
	''' % table_name, (the_id,))

Let's just remove or depreceate the format and pyformat parameter
sytles from the DB-API. They make dynamic query construction more error
prone. 

2 The optional parameters to execute()are not Pythonic enough 

Yeah, I agree with this one.

3 Having to join lists by hand is annoying and always performed the same
way

4 Dictionaries can be rendered as name=valuepairs

I still haven't decided if I like these two.





More information about the DB-SIG mailing list