[PyGreSQL] DB API-2.0 + copy from stdin

Christoph Zwerschke cito at online.de
Wed Sep 24 04:24:25 EDT 2008


Christopher Sean Hilton schrieb:
> Here's the first cut at my solution. The example code is at the
> bottom.

I think that's a reasonable suggestion. If I understand you right, then 
all we need to do is:

1) Add a parameter "db" to the pg.DB class. If it is set to None (the 
default), then a new connection will be established, otherwise the given 
connection will be used. (I suggest the name "db" instead of "cnx" 
because the name of the corresponding attribute is already "db".)

2) Add an attribute "_closeable" to pg.DB which will be set when the 
instance has not been created with a preestablihed connection. The 
close() and reopen() methods of pg.DB will then raise an exception when 
_closeable is false.

3) Add a pdb.pgdbCnx method for getting a classic pg.DB instance.
Maybe we don't even need that, since getting it is as easy as
DB(db=con._cnx) when con is a pgdb connection. So the pgdb module would 
normally not need to import the pg module, and it would be clearer that 
you're leaving the DB-API2 world if you're using this feature.

An additional suggestion from my site is making the (pseudo) private 
attributes of pg.DB public, as we did with the private attributes in 
pgdb. A single underscore should suffice to indicate that these should 
not be used from outside unless really necessary as in cases like this.

-- Christoph


More information about the PyGreSQL mailing list