[TransWarp] pgdb.py from PostgreSQL 7.3.2
Phillip J. Eby
pje at telecommunity.com
Fri Feb 14 12:53:07 EST 2003
At 05:05 PM 2/14/03 +0100, Radek Kanovsky wrote:
>There was no method pgdbCursor.nextset() in 7.2.4 version of PostgreSQL.
>If I understand DBAPI 2.0 correctly, pgdb.py behaviour follows
>specification.
Yes, but it goes against the recommendation in footnote 3, that says the
preferred approach is not to have the attribute in the first place. They
sure went to a lot of trouble to add a function that doesn't do anything
and guarantees that any generic SQL layer will waste time calling the
function and throwing the exception! I would suggest encouraging them to
remove the method, if it never does anything. The spec says quite clearly:
"The preferred approach is to not implement the method and thus have Python
generate an AttributeError in case the method is requested. This allows the
programmer to check for database capabilities using the standard hasattr()
function."
>So I have made small patch:
>
>--- /home/radekk/work/PEAK/src/peak/storage/SQL.py
>+++ /usr/local/python-2.2.2/lib/python2.2/site-packages/peak/storage/SQL.py
>@@ -77,7 +77,10 @@
>
>
> def nextset(self):
>- return getattr(self._cursor, 'nextset', _nothing)()
>+ try :
>+ return getattr(self._cursor, 'nextset', _nothing)()
>+ except self.conn.API.NotSupportedError :
>+ return None
>
>
> def execute(self, *args):
>
>
>Is NotSupportedError dereferencing through self.conn.API correct?
Yes, that's fine. I will probably make a similar change to PEAK, but I may
add NotSupportedError to the connection's bindings so that it can be done
as 'self.conn.NotSupportedError'. Anyway, thanks for bringing it to my
attention, although I would again encourage any DB driver developers to
follow the DBAPI recommendation in this, as it allows for less calling
overhead in this situation.
More information about the PEAK
mailing list