Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd274105

Browse files
committed
> 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
1 parent482ed83 commitd274105

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

‎doc/src/sgml/pygresql.sgml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/Attic/pygresql.sgml,v 1.8 2002/09/23 23:20:38 tgl Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/Attic/pygresql.sgml,v 1.9 2002/12/12 22:49:27 momjian Exp $ -->
22

33
<chapter id="pygresql">
44
<title><application>PyGreSQL</application> - <application>Python</application> Interface</title>
@@ -2413,12 +2413,17 @@ loimport(<parameter>filename</parameter>)
24132413
<title>Database Wrapper Class: <classname>DB</classname></title>
24142414

24152415
<para>
2416-
<classname>pg</classname> module contains a class called
2417-
<classname>DB</classname>. All <classname>pgobject</classname>
2418-
methods are included in this class also. A number of additional
2419-
<classname>DB</classname> class methods are described below. The
2420-
preferred way to use this module is as follows (See description of
2421-
the initialization method below.):
2416+
The <literal>pg</literal> module contains a class called
2417+
<classname>DB</classname> wrapping a <classname>pgobject</classname>.
2418+
This <classname>pgobject</classname> can be addressed as a
2419+
<classname>DB</classname> class member named <varname>db</varname>
2420+
to get access to the read-only attributes of the corresponding connection
2421+
(e.g. <varname>db.error</varname>). All <classname>pgobject</classname>
2422+
methods (e.g. <function>query()</function>) are directly included as members
2423+
in the class <classname>DB</classname> also. A number of additional
2424+
higher level <classname>DB</classname> class methods are described below.
2425+
The preferred way to use this module is as follows (see description of the
2426+
initialization method below):
24222427

24232428
<programlisting>
24242429
import pg

‎src/interfaces/python/pg.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,10 @@ class DB:
4848
def__init__(self,*args,**kw):
4949
self.db=apply(connect,args,kw)
5050

51-
# Create convience methods, in a way that is still overridable.
52-
forein ('query','reset','close','getnotify','inserttable',
53-
'putline','getline','endcopy',
54-
'host','port','db','options',
55-
'tty','error','status','user',
56-
'locreate','getlo','loimport' ):
57-
ifnothasattr(self,e)andhasattr(self.db,e):
58-
exec'self.%s = self.db.%s'% (e,e )
51+
# Create convience methods, in a way that is still overridable
52+
# (members are not copied because they are actually functions)
53+
foreinself.db.__methods__:
54+
setattr(self,e,getattr(self.db,e))
5955

6056
self.__attnames__= {}
6157
self.__pkeys__= {}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp