Ticket #5086: owned-tables-only.patch
File owned-tables-only.patch, 1.3 KB (added by , 17 years ago) |
---|
-
introspection.py
1 1 from django.db.backends.postgresql_psycopg2.base import quote_name 2 2 3 def get_table_list(cursor): 4 "Returns a list of table names in the current database." 5 cursor.execute(""" 3 def get_table_list(cursor, owned_only = True ): 4 """Returns a list of table names in the current database. 5 6 If owned_only is set, only tables owned by current user are returned. 7 """ 8 if owned_only: 9 owned_join = "LEFT JOIN pg_catalog.pg_roles r ON r.oid = c.relowner" 10 owned_where = "AND r.rolname = current_user" 11 else: 12 owned_join = owned_where = "" 13 cursor.execute (""" 6 14 SELECT c.relname 7 15 FROM pg_catalog.pg_class c 8 16 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace 17 %s 9 18 WHERE c.relkind IN ('r', 'v', '') 10 19 AND n.nspname NOT IN ('pg_catalog', 'pg_toast') 11 AND pg_catalog.pg_table_is_visible(c.oid)""") 20 AND pg_catalog.pg_table_is_visible(c.oid) 21 %s""" % ( owned_join, owned_where ) ) 12 22 return [row[0] for row in cursor.fetchall()] 13 23 14 24 def get_table_description(cursor, table_name):