On Thu, 19 Jan 2006 20:10:18 +0100
Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> I would solve the problem differently, as already explained here:
> http://mailman.vex.net/pipermail/pygresql/2005-November/001548.html

Ah.  I forgot that I already broached the subject.

> If you agree, I can make the changes proposed in the link above this week.

I do agree but I worked out the following changes.  It passes the unit
test.  Would you do it differently?  Note that I redefined get_tables
in terms of get_relations.

Index: pg.py
===================================================================
RCS file: /usr/pubcvs/pygresql/module/pg.py,v
retrieving revision 1.35
diff -u -p -u -r1.35 pg.py
--- pg.py   28 Dec 2005 00:23:33 -0000  1.35
+++ pg.py   19 Jan 2006 20:32:44 -0000
@@ -244,15 +244,26 @@ class DB:
        return [s for s, in
            self.db.query('SELECT datname FROM pg_database').getresult
()]

-   def get_tables(self):
+   def get_relations(self, typ = None):
        """Get list of tables in connected database."""
+
+       if typ:
+           where = "pg_class.relkind IN (%s) AND" % \
+                           ','.join(["'%s'" % x for x in typ])
+       else:
+           where = ''
+
        return [_join_parts(s) for s in
-           self.db.query("SELECT pg_namespace.nspname"
-               ",pg_class.relname FROM pg_class"
-               " JOIN pg_namespace ON
pg_namespace.oid=pg_class.relnamespace"
-               " WHERE pg_class.relkind='r' AND"
-               " pg_class.relname!~'^Inv' AND "
-               " pg_class.relname!~'^pg_' ORDER BY 1,2").getresult()]
+           self.db.query(
+               "SELECT pg_namespace.nspname, pg_class.relname "
+               "FROM pg_class "
+               "JOIN pg_namespace ON
pg_namespace.oid=pg_class.relnamespace "
+               "WHERE %s pg_class.relname !~ '^Inv' AND "
+                   "pg_class.relname !~ '^pg_' "
+               "ORDER BY 1,2" % where).getresult()]
+
+   def get_tables(self):
+       return self.get_relations('r')

    def get_attnames(self, cl, newattnames = None):
        """Given the name of a table, digs out the set of attribute
names. @@ -274,7 +285,7 @@ class DB:
        # May as well cache them:
        if self.__attnames.has_key(qcl):
            return self.__attnames[qcl]
-       if qcl not in self.get_tables():
+       if qcl not in self.get_relations('rv'):
            raise ProgrammingError, 'Class %s does not exist' % qcl
        t = {}
        for att, typ in self.db.query("SELECT pg_attribute.attname"

-- 
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org
_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to