Ticket #5086: owned-tables-only.patch

File owned-tables-only.patch, 1.3 KB (added by shaunc <shaun@…>, 17 years ago)

patch of ...introspection.get_table_list, returning by default only tables owned by current user

  • introspection.py

     
    11from django.db.backends.postgresql_psycopg2.base import quote_name
    22
    3 def get_table_list(cursor):
    4     "Returns a list of table names in the current database."
    5     cursor.execute("""
     3def 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 ("""
    614        SELECT c.relname
    715        FROM pg_catalog.pg_class c
    816        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
     17        %s
    918        WHERE c.relkind IN ('r', 'v', '')
    1019            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 )  )
    1222    return [row[0] for row in cursor.fetchall()]
    1323
    1424def get_table_description(cursor, table_name):
Back to Top