postgresql modules: use query parameters with cursor objects (#65862)
* postgresql modules: use query parameters with cursor objects * add changelog fragment * fix typo in changelog fragment
This commit is contained in:
parent
aa53eb0e71
commit
b48366c2fe
4 changed files with 14 additions and 10 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
bugfixes:
|
||||||
|
- postgresql_table - use query parameters with cursor object (https://github.com/ansible/ansible/pull/65862).
|
||||||
|
- postgresql_tablespace - use query parameters with cursor object (https://github.com/ansible/ansible/pull/65862).
|
||||||
|
- postgresql_user - use query parameters with cursor object (https://github.com/ansible/ansible/pull/65862).
|
|
@ -288,9 +288,10 @@ class Table(object):
|
||||||
"FROM pg_tables AS t "
|
"FROM pg_tables AS t "
|
||||||
"INNER JOIN pg_class AS c ON c.relname = t.tablename "
|
"INNER JOIN pg_class AS c ON c.relname = t.tablename "
|
||||||
"INNER JOIN pg_namespace AS n ON c.relnamespace = n.oid "
|
"INNER JOIN pg_namespace AS n ON c.relnamespace = n.oid "
|
||||||
"WHERE t.tablename = '%s' "
|
"WHERE t.tablename = %(tblname)s "
|
||||||
"AND n.nspname = '%s'" % (tblname, schema))
|
"AND n.nspname = %(schema)s")
|
||||||
res = exec_sql(self, query, add_to_executed=False)
|
res = exec_sql(self, query, query_params={'tblname': tblname, 'schema': schema},
|
||||||
|
add_to_executed=False)
|
||||||
if res:
|
if res:
|
||||||
self.exists = True
|
self.exists = True
|
||||||
self.info = dict(
|
self.info = dict(
|
||||||
|
|
|
@ -248,16 +248,15 @@ class PgTablespace(object):
|
||||||
query = ("SELECT r.rolname, (SELECT Null), %s "
|
query = ("SELECT r.rolname, (SELECT Null), %s "
|
||||||
"FROM pg_catalog.pg_tablespace AS t "
|
"FROM pg_catalog.pg_tablespace AS t "
|
||||||
"JOIN pg_catalog.pg_roles AS r "
|
"JOIN pg_catalog.pg_roles AS r "
|
||||||
"ON t.spcowner = r.oid "
|
"ON t.spcowner = r.oid " % location)
|
||||||
"WHERE t.spcname = '%s'" % (location, self.name))
|
|
||||||
else:
|
else:
|
||||||
query = ("SELECT r.rolname, t.spcoptions, %s "
|
query = ("SELECT r.rolname, t.spcoptions, %s "
|
||||||
"FROM pg_catalog.pg_tablespace AS t "
|
"FROM pg_catalog.pg_tablespace AS t "
|
||||||
"JOIN pg_catalog.pg_roles AS r "
|
"JOIN pg_catalog.pg_roles AS r "
|
||||||
"ON t.spcowner = r.oid "
|
"ON t.spcowner = r.oid " % location)
|
||||||
"WHERE t.spcname = '%s'" % (location, self.name))
|
|
||||||
|
|
||||||
res = exec_sql(self, query, add_to_executed=False)
|
res = exec_sql(self, query + "WHERE t.spcname = %(name)s",
|
||||||
|
query_params={'name': self.name}, add_to_executed=False)
|
||||||
|
|
||||||
if not res:
|
if not res:
|
||||||
self.exists = False
|
self.exists = False
|
||||||
|
|
|
@ -541,8 +541,8 @@ def get_table_privileges(cursor, user, table):
|
||||||
else:
|
else:
|
||||||
schema = 'public'
|
schema = 'public'
|
||||||
query = ("SELECT privilege_type FROM information_schema.role_table_grants "
|
query = ("SELECT privilege_type FROM information_schema.role_table_grants "
|
||||||
"WHERE grantee='%s' AND table_name='%s' AND table_schema='%s'" % (user, table, schema))
|
"WHERE grantee=%(user)s AND table_name=%(table)s AND table_schema=%(schema)s")
|
||||||
cursor.execute(query)
|
cursor.execute(query, {'user': user, 'table': table, 'schema': schema})
|
||||||
return frozenset([x[0] for x in cursor.fetchall()])
|
return frozenset([x[0] for x in cursor.fetchall()])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue