Changeset 312 for trunk/module/pg.py


Ignore:
Timestamp:
Dec 30, 2006, 2:13:24 AM (13 years ago)
Author:
darcy
Message:

Using _join_parts is inefficient for certain ops. Just joing tablespace
name to table in query.
Use list comprehension and dict method for clarity.
Minor formatting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/pg.py

    r308 r312  
    66# Improved by Christoph Zwerschke
    77#
    8 # $Id: pg.py,v 1.49 2006-11-24 18:18:01 cito Exp $
     8# $Id: pg.py,v 1.50 2006-12-30 07:13:24 darcy Exp $
    99#
    1010
     
    113113                self.__args = args, kw
    114114                self.debug = None # For debugging scripts, this can be set
    115                         # * to a string format specification (e.g. in a CGI set to "%s<BR>"),
     115                        # * to a string format specification (e.g. in CGI set to "%s<BR>"),
    116116                        # * to a function which takes a string argument or
    117117                        # * to a file object to write debug statements to.
     
    243243                if self.__pkeys == {} or not self.__pkeys.has_key(qcl):
    244244                        # if not found, check again in case it was added after we started
    245                         for r in self.db.query("SELECT pg_namespace.nspname"
    246                                 ",pg_class.relname,pg_attribute.attname FROM pg_class"
     245                        self.__pkeys = dict(self.db.query(
     246                                "SELECT pg_namespace.nspname||'.'||pg_class.relname"
     247                                        ",pg_attribute.attname FROM pg_class"
    247248                                " JOIN pg_namespace ON pg_namespace.oid=pg_class.relnamespace"
    248                                 " AND pg_namespace.nspname NOT LIKE 'pg_%'"
     249                                        " AND pg_namespace.nspname NOT LIKE 'pg_%'"
    249250                                " JOIN pg_attribute ON pg_attribute.attrelid=pg_class.oid"
    250                                 " AND pg_attribute.attisdropped='f'"
     251                                        " AND pg_attribute.attisdropped='f'"
    251252                                " JOIN pg_index ON pg_index.indrelid=pg_class.oid"
    252                                 " AND pg_index.indisprimary='t'"
    253                                 " AND pg_index.indkey[0]=pg_attribute.attnum").getresult():
    254                                 self.__pkeys[_join_parts(r[:2])] = r[2] # build qualified name
     253                                        " AND pg_index.indisprimary='t'"
     254                                        " AND pg_index.indkey[0]=pg_attribute.attnum").getresult())
    255255                        self._do_debug(self.__pkeys)
    256256                # will raise an exception if primary key doesn't exist
     
    276276                        where = ''
    277277
    278                 return [_join_parts(s) for s in
     278                return [s[0] for s in
    279279                        self.db.query(
    280                                 "SELECT pg_namespace.nspname, pg_class.relname "
     280                                "SELECT pg_namespace.nspname || '.' || pg_class.relname "
    281281                                "FROM pg_class "
    282282                                "JOIN pg_namespace ON pg_namespace.oid=pg_class.relnamespace "
    283283                                "WHERE %s pg_class.relname !~ '^Inv' AND "
    284284                                        "pg_class.relname !~ '^pg_' "
    285                                 "ORDER BY 1,2" % where).getresult()]
     285                                "ORDER BY 1" % where).getresult()]
    286286
    287287        def get_tables(self):
Note: See TracChangeset for help on using the changeset viewer.