diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-12-12 22:49:27 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-12-12 22:49:27 +0000 |
commit | d27410594227302de6ee66c1757a955d953bf635 (patch) | |
tree | b2165cd380195e57226789e606d16e08741bb546 /src/interfaces/python/pg.py | |
parent | 482ed836f7324ec558c8c6164659965ffff61de4 (diff) | |
download | postgresql-d27410594227302de6ee66c1757a955d953bf635.tar.gz postgresql-d27410594227302de6ee66c1757a955d953bf635.zip |
> There is an ugly little problem with the DB wrapper class.
>
> In pg.py the attributes of DB are defined as being the same as
> the attributes of the corresponding pgobject "db", using the following
...
> The problem is that the attributes of db (which are read only)
> are not static (they are actually function calls to PostgreSQL),
> especially "status" and "error", but those attributes are copied
> and this is done only once when initializing the DB object.
>
> So, in effect, only the attribute "db.error" of a DB instance
> will be updated, but not the attribute "error". Same with "status".
> Don't copy the (read only) attributes of the pgobject to the
> DB object, but only the methods, and all of them, like this:
>
> --------------- change in pg.py ------------------
> # Create convience methods, in a way that is still overridable.
> for e in self.db.__methods__:
> setattr(self, e, getattr(self.db, e))
> ----------------------------------------------------
>
> Furthermore, make an addition to the documentation of the
> DB wrapper class (i.e. in pygresql-pg-db.html):
> After the sentence "All pgobject methods are included in this class also."
> add the following sentence "The pgobject read-only attributes can be
> accessed py adding the prefix 'db.' to them."
Christoph Zwerschke
Diffstat (limited to 'src/interfaces/python/pg.py')
-rw-r--r-- | src/interfaces/python/pg.py | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/interfaces/python/pg.py b/src/interfaces/python/pg.py index df502397fa6..0e40a6e5a47 100644 --- a/src/interfaces/python/pg.py +++ b/src/interfaces/python/pg.py @@ -48,14 +48,10 @@ class DB: def __init__(self, *args, **kw): self.db = apply(connect, args, kw) - # Create convience methods, in a way that is still overridable. - for e in ( 'query', 'reset', 'close', 'getnotify', 'inserttable', - 'putline', 'getline', 'endcopy', - 'host', 'port', 'db', 'options', - 'tty', 'error', 'status', 'user', - 'locreate', 'getlo', 'loimport' ): - if not hasattr(self,e) and hasattr(self.db,e): - exec 'self.%s = self.db.%s' % ( e, e ) + # Create convience methods, in a way that is still overridable + # (members are not copied because they are actually functions) + for e in self.db.__methods__: + setattr(self, e, getattr(self.db, e)) self.__attnames__ = {} self.__pkeys__ = {} |