Author: cito
Date: Sun Jan 10 17:12:03 2016
New Revision: 709
Log:
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.
Modified:
branches/4.x/docs/contents/changelog.rst
branches/4.x/module/pg.py
branches/4.x/module/tests/test_classic_dbwrapper.py
trunk/module/pg.py
trunk/module/tests/test_classic_dbwrapper.py
Modified: branches/4.x/docs/contents/changelog.rst
==============================================================================
--- branches/4.x/docs/contents/changelog.rst Sun Jan 10 15:59:01 2016
(r708)
+++ branches/4.x/docs/contents/changelog.rst Sun Jan 10 17:12:03 2016
(r709)
@@ -10,6 +10,7 @@
- Fix decimal point handling.
- Add option to return boolean values as bool objects.
- Add option to return money values as string.
+- get_tables() does not list information schema tables any more.
- Fix notification handler (Thanks Patrick TJ McPhee).
- Fix a small issue with large objects.
- The tutorial files have become a chapter in the documentation.
Modified: branches/4.x/module/pg.py
==============================================================================
--- branches/4.x/module/pg.py Sun Jan 10 15:59:01 2016 (r708)
+++ branches/4.x/module/pg.py Sun Jan 10 17:12:03 2016 (r709)
@@ -622,12 +622,12 @@
where = kinds and "pg_class.relkind IN (%s) AND" % ','.join(
["'%s'" % x for x in kinds]) or ''
return [_join_parts(x) for x 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 %s pg_class.relname !~ '^Inv' AND "
- "pg_class.relname !~ '^pg_' "
- "ORDER BY 1, 2" % where).getresult()]
+ "SELECT pg_namespace.nspname, pg_class.relname"
+ " FROM pg_class "
+ " JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace "
+ " WHERE %s pg_namespace.nspname != 'information_schema'"
+ " AND pg_namespace.nspname !~ '^pg_' "
+ " ORDER BY 1, 2" % where).getresult()]
def get_tables(self):
"""Return list of tables in connected database."""
Modified: branches/4.x/module/tests/test_classic_dbwrapper.py
==============================================================================
--- branches/4.x/module/tests/test_classic_dbwrapper.py Sun Jan 10 15:59:01
2016 (r708)
+++ branches/4.x/module/tests/test_classic_dbwrapper.py Sun Jan 10 17:12:03
2016 (r709)
@@ -557,6 +557,15 @@
def testGetTables(self):
get_tables = self.db.get_tables
result1 = get_tables()
+ self.assertIsInstance(result1, list)
+ for t in result1:
+ t = t.split('.', 1)
+ self.assertGreaterEqual(len(t), 2)
+ if len(t) > 2:
+ self.assertTrue(t[1].startswith('"'))
+ t = t[0]
+ self.assertNotEqual(t, 'information_schema')
+ self.assertFalse(t.startswith('pg_'))
tables = ('"A very Special Name"',
'"A_MiXeD_quoted_NaMe"', 'a1', 'a2',
'A_MiXeD_NaMe', '"another special name"',
Modified: trunk/module/pg.py
==============================================================================
--- trunk/module/pg.py Sun Jan 10 15:59:01 2016 (r708)
+++ trunk/module/pg.py Sun Jan 10 17:12:03 2016 (r709)
@@ -104,7 +104,7 @@
def _join_parts(s):
"""Join all parts of a dot separated string."""
- return '.'.join([_is_quoted(p) and '"%s"' % p or p for p in s])
+ return '.'.join(['"%s"' % p if _is_quoted(p) else p for p in s])
def _oid_key(qcl):
@@ -621,15 +621,15 @@
specifying which kind of relations you want to list.
"""
- where = kinds and "pg_class.relkind IN (%s) AND" % ','.join(
- ["'%s'" % x for x in kinds]) or ''
+ where = "pg_class.relkind IN (%s) AND" % ','.join(
+ ["'%s'" % x for x in kinds]) if kinds else ''
return [_join_parts(x) for x 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 %s pg_class.relname !~ '^Inv' AND "
- "pg_class.relname !~ '^pg_' "
- "ORDER BY 1, 2" % where).getresult()]
+ "SELECT pg_namespace.nspname, pg_class.relname"
+ " FROM pg_class "
+ " JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace "
+ " WHERE %s pg_namespace.nspname != 'information_schema'"
+ " AND pg_namespace.nspname !~ '^pg_' "
+ " ORDER BY 1, 2" % where).getresult()]
def get_tables(self):
"""Return list of tables in connected database."""
Modified: trunk/module/tests/test_classic_dbwrapper.py
==============================================================================
--- trunk/module/tests/test_classic_dbwrapper.py Sun Jan 10 15:59:01
2016 (r708)
+++ trunk/module/tests/test_classic_dbwrapper.py Sun Jan 10 17:12:03
2016 (r709)
@@ -595,6 +595,15 @@
def testGetTables(self):
get_tables = self.db.get_tables
result1 = get_tables()
+ self.assertIsInstance(result1, list)
+ for t in result1:
+ t = t.split('.', 1)
+ self.assertGreaterEqual(len(t), 2)
+ if len(t) > 2:
+ self.assertTrue(t[1].startswith('"'))
+ t = t[0]
+ self.assertNotEqual(t, 'information_schema')
+ self.assertFalse(t.startswith('pg_'))
tables = ('"A very Special Name"',
'"A_MiXeD_quoted_NaMe"', 'a1', 'a2',
'A_MiXeD_NaMe', '"another special name"',
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql