Changeset 709 for trunk


Ignore:
Timestamp:
Jan 10, 2016, 5:12:03 PM (4 years ago)
Author:
cito
Message:

get_tables() should not list the information schema tables

Since get_tables() does not return the other system tables starting with pg_,
so it should not return the information schema tables either.

Also removed an ancient check for tables starting with Inv
that is not relevant any more since PostgreSQL 7.1 or so.

Location:
trunk/module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/pg.py

    r706 r709  
    105105def _join_parts(s):
    106106    """Join all parts of a dot separated string."""
    107     return '.'.join([_is_quoted(p) and '"%s"' % p or p for p in s])
     107    return '.'.join(['"%s"' % p if _is_quoted(p) else p for p in s])
    108108
    109109
     
    622622
    623623        """
    624         where = kinds and "pg_class.relkind IN (%s) AND" % ','.join(
    625             ["'%s'" % x for x in kinds]) or ''
     624        where = "pg_class.relkind IN (%s) AND" % ','.join(
     625            ["'%s'" % x for x in kinds]) if kinds else ''
    626626        return [_join_parts(x) for x in self.db.query(
    627             "SELECT pg_namespace.nspname, pg_class.relname "
    628             "FROM pg_class "
    629             "JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace "
    630             "WHERE %s pg_class.relname !~ '^Inv' AND "
    631                 "pg_class.relname !~ '^pg_' "
    632             "ORDER BY 1, 2" % where).getresult()]
     627            "SELECT pg_namespace.nspname, pg_class.relname"
     628            " FROM pg_class "
     629            " JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace "
     630            " WHERE %s pg_namespace.nspname != 'information_schema'"
     631                " AND pg_namespace.nspname !~ '^pg_' "
     632            " ORDER BY 1, 2" % where).getresult()]
    633633
    634634    def get_tables(self):
  • trunk/module/tests/test_classic_dbwrapper.py

    r706 r709  
    596596        get_tables = self.db.get_tables
    597597        result1 = get_tables()
     598        self.assertIsInstance(result1, list)
     599        for t in result1:
     600            t = t.split('.', 1)
     601            self.assertGreaterEqual(len(t), 2)
     602            if len(t) > 2:
     603                self.assertTrue(t[1].startswith('"'))
     604            t = t[0]
     605            self.assertNotEqual(t, 'information_schema')
     606            self.assertFalse(t.startswith('pg_'))
    598607        tables = ('"A very Special Name"',
    599608            '"A_MiXeD_quoted_NaMe"', 'a1', 'a2',
Note: See TracChangeset for help on using the changeset viewer.