Update of /usr/cvs/Public/pygresql/module
In directory druid.net:/tmp/cvs-serv5759
Modified Files:
pg.py test_pg.py
Log Message:
Small bugfix and some code clean-up in pg module.
To see the diffs for this commit:
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/pg.py.diff?r1=1.63&r2=1.64
Index: pg.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/pg.py,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- pg.py 21 Nov 2008 21:17:53 -0000 1.63
+++ pg.py 21 Nov 2008 23:38:17 -0000 1.64
@@ -5,7 +5,7 @@
# Written by D'Arcy J.M. Cain
# Improved by Christoph Zwerschke
#
-# $Id: pg.py,v 1.63 2008/11/21 21:17:53 cito Exp $
+# $Id: pg.py,v 1.64 2008/11/21 23:38:17 cito Exp $
#
"""PyGreSQL classic interface.
@@ -290,7 +290,7 @@
self._do_debug(qstr)
return self.db.query(qstr)
- def pkey(self, cl, newpkey = None):
+ def pkey(self, cl, newpkey=None):
"""This method gets or sets the primary key of a class.
If newpkey is set and is not a dictionary then set that
@@ -338,7 +338,7 @@
return [s[0] for s in
self.db.query('SELECT datname FROM pg_database').getresult()]
- def get_relations(self, kinds = None):
+ def get_relations(self, kinds=None):
"""Get list of relations in connected database of specified kinds.
If kinds is None or empty, all kinds of relations are returned.
@@ -360,7 +360,7 @@
"""Return list of tables in connected database."""
return self.get_relations('r')
- def get_attnames(self, cl, newattnames = None):
+ def get_attnames(self, cl, newattnames=None):
"""Given the name of a table, digs out the set of attribute names.
Returns a dictionary of attribute names (the names are the keys,
@@ -417,7 +417,7 @@
self._attnames[qcl] = t # cache it
return self._attnames[qcl]
- def get(self, cl, arg, keyname = None, view = 0):
+ def get(self, cl, arg, keyname=None, view=0):
"""Get a tuple from a database table or view.
This method is the basic mechanism to get a single row. It assumes
@@ -455,7 +455,7 @@
q = 'SELECT * FROM %s WHERE oid=%s LIMIT 1' % (qcl, k)
elif view:
q = 'SELECT * FROM %s WHERE %s=%s LIMIT 1' % \
- (qcl, keyname, _quote(k, fnames[keyname]))
+ (qcl, keyname, self._quote(k, fnames[keyname]))
else:
q = 'SELECT %s FROM %s WHERE %s=%s LIMIT 1' % \
(','.join(fnames.keys()), qcl, \
@@ -471,7 +471,7 @@
arg[k] = d
return arg
- def insert(self, cl, d = None, **kw):
+ def insert(self, cl, d=None, **kw):
"""Insert a tuple into a database table.
This method inserts values into the table specified filling in the
@@ -510,7 +510,7 @@
except Exception:
return None
- def update(self, cl, d = None, **kw):
+ def update(self, cl, d=None, **kw):
"""Update an existing row in a database table.
Similar to insert but updates an existing row. The update is based
@@ -552,7 +552,6 @@
'Update needs primary key or oid as %s' % foid)
where = "%s='%s'" % (pk, a[pk])
v = []
- k = 0
fnames = self.get_attnames(qcl)
for ff in fnames.keys():
if ff != 'oid' and ff in a:
@@ -568,7 +567,7 @@
else:
return self.get(qcl, a)
- def clear(self, cl, a = None):
+ def clear(self, cl, a=None):
"""
This method clears all the attributes to values determined by the
types.
@@ -582,7 +581,6 @@
if a is None:
a = {} # empty if argument is not present
qcl = _join_parts(self._split_schema(cl)) # build qualified name
- foid = 'oid(%s)' % qcl # build mangled oid
fnames = self.get_attnames(qcl)
for k, t in fnames.items():
if k == 'oid':
@@ -595,7 +593,7 @@
a[k] = ''
return a
- def delete(self, cl, d = None, **kw):
+ def delete(self, cl, d=None, **kw):
"""Delete an existing row in a database table.
This method deletes the row from a table.
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/test_pg.py.diff?r1=1.18&r2=1.19
Index: test_pg.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/test_pg.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- test_pg.py 21 Nov 2008 23:24:38 -0000 1.18
+++ test_pg.py 21 Nov 2008 23:38:17 -0000 1.19
@@ -4,7 +4,7 @@
#
# Written by Christoph Zwerschke
#
-# $Id: test_pg.py,v 1.18 2008/11/21 23:24:38 cito Exp $
+# $Id: test_pg.py,v 1.19 2008/11/21 23:38:17 cito Exp $
#
"""Test the classic PyGreSQL interface in the pg module.
@@ -1043,6 +1043,9 @@
r = self.db.get('test_view', 14, 'i4')
self.assert_('v4' in r)
self.assertEqual(r['v4'], 'abc4')
+ r = self.db.get('test_view', 14, 'i4', view=True)
+ self.assert_('v4' in r)
+ self.assertEqual(r['v4'], 'abc4')
def testInsert(self):
for table in ('insert_test_table', 'test table for insert'):
_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql