postgresql modules: use query parameters with cursor objects (#65791)
This commit is contained in:
parent
f5a0d6e4ba
commit
885cecfc94
5 changed files with 25 additions and 17 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
bugfixes:
|
||||||
|
- postgresql_set - use query parameters with cursor object (https://github.com/ansible/ansible/pull/65791).
|
||||||
|
- postgresql_slot - use query parameters with cursor object (https://github.com/ansible/ansible/pull/65791).
|
||||||
|
- postgresql_subscription - use query parameters with cursor object (https://github.com/ansible/ansible/pull/65791).
|
|
@ -185,9 +185,9 @@ POSSIBLE_SIZE_UNITS = ("mb", "gb", "tb")
|
||||||
|
|
||||||
def param_get(cursor, module, name):
|
def param_get(cursor, module, name):
|
||||||
query = ("SELECT name, setting, unit, context, boot_val "
|
query = ("SELECT name, setting, unit, context, boot_val "
|
||||||
"FROM pg_settings WHERE name = '%s'" % name)
|
"FROM pg_settings WHERE name = %(name)s")
|
||||||
try:
|
try:
|
||||||
cursor.execute(query)
|
cursor.execute(query, {'name': name})
|
||||||
info = cursor.fetchall()
|
info = cursor.fetchall()
|
||||||
cursor.execute("SHOW %s" % name)
|
cursor.execute("SHOW %s" % name)
|
||||||
val = cursor.fetchone()
|
val = cursor.fetchone()
|
||||||
|
|
|
@ -184,26 +184,30 @@ class PgSlot(object):
|
||||||
if kind == 'physical':
|
if kind == 'physical':
|
||||||
# Check server version (needs for immedately_reserverd needs 9.6+):
|
# Check server version (needs for immedately_reserverd needs 9.6+):
|
||||||
if self.cursor.connection.server_version < 96000:
|
if self.cursor.connection.server_version < 96000:
|
||||||
query = "SELECT pg_create_physical_replication_slot('%s')" % self.name
|
query = "SELECT pg_create_physical_replication_slot(%(name)s)"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
query = "SELECT pg_create_physical_replication_slot('%s', %s)" % (self.name, immediately_reserve)
|
query = "SELECT pg_create_physical_replication_slot(%(name)s, %(i_reserve)s)"
|
||||||
|
|
||||||
|
self.changed = exec_sql(self, query,
|
||||||
|
query_params={'name': self.name, 'i_reserve': immediately_reserve},
|
||||||
|
ddl=True)
|
||||||
|
|
||||||
elif kind == 'logical':
|
elif kind == 'logical':
|
||||||
query = "SELECT pg_create_logical_replication_slot('%s', '%s')" % (self.name, output_plugin)
|
query = "SELECT pg_create_logical_replication_slot(%(name)s, %(o_plugin)s)"
|
||||||
|
self.changed = exec_sql(self, query,
|
||||||
self.changed = exec_sql(self, query, ddl=True)
|
query_params={'name': self.name, 'o_plugin': output_plugin}, ddl=True)
|
||||||
|
|
||||||
def drop(self):
|
def drop(self):
|
||||||
if not self.exists:
|
if not self.exists:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
query = "SELECT pg_drop_replication_slot('%s')" % self.name
|
query = "SELECT pg_drop_replication_slot(%(name)s)"
|
||||||
self.changed = exec_sql(self, query, ddl=True)
|
self.changed = exec_sql(self, query, query_params={'name': self.name}, ddl=True)
|
||||||
|
|
||||||
def __slot_exists(self):
|
def __slot_exists(self):
|
||||||
query = "SELECT slot_type FROM pg_replication_slots WHERE slot_name = '%s'" % self.name
|
query = "SELECT slot_type FROM pg_replication_slots WHERE slot_name = %(name)s"
|
||||||
res = exec_sql(self, query, add_to_executed=False)
|
res = exec_sql(self, query, query_params={'name': self.name}, add_to_executed=False)
|
||||||
if res:
|
if res:
|
||||||
self.exists = True
|
self.exists = True
|
||||||
self.kind = res[0][0]
|
self.kind = res[0][0]
|
||||||
|
|
|
@ -555,9 +555,9 @@ class PgSubscription():
|
||||||
"ON s.subdbid = d.oid "
|
"ON s.subdbid = d.oid "
|
||||||
"JOIN pg_catalog.pg_roles AS r "
|
"JOIN pg_catalog.pg_roles AS r "
|
||||||
"ON s.subowner = r.oid "
|
"ON s.subowner = r.oid "
|
||||||
"WHERE s.subname = '%s' AND d.datname = '%s'" % (self.name, self.db))
|
"WHERE s.subname = %(name)s AND d.datname = %(db)s")
|
||||||
|
|
||||||
result = exec_sql(self, query, add_to_executed=False)
|
result = exec_sql(self, query, query_params={'name': self.name, 'db': self.db}, add_to_executed=False)
|
||||||
if result:
|
if result:
|
||||||
return result[0]
|
return result[0]
|
||||||
else:
|
else:
|
||||||
|
@ -573,9 +573,9 @@ class PgSubscription():
|
||||||
"FROM pg_catalog.pg_subscription_rel r "
|
"FROM pg_catalog.pg_subscription_rel r "
|
||||||
"JOIN pg_catalog.pg_subscription s ON s.oid = r.srsubid "
|
"JOIN pg_catalog.pg_subscription s ON s.oid = r.srsubid "
|
||||||
"JOIN pg_catalog.pg_class c ON c.oid = r.srrelid "
|
"JOIN pg_catalog.pg_class c ON c.oid = r.srrelid "
|
||||||
"WHERE s.subname = '%s'" % self.name)
|
"WHERE s.subname = %(name)s")
|
||||||
|
|
||||||
result = exec_sql(self, query, add_to_executed=False)
|
result = exec_sql(self, query, query_params={'name': self.name}, add_to_executed=False)
|
||||||
if result:
|
if result:
|
||||||
return [dict(row) for row in result]
|
return [dict(row) for row in result]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ["SELECT pg_create_physical_replication_slot('slot0', False)"]
|
- result.queries == ["SELECT pg_create_physical_replication_slot('slot0', false)"]
|
||||||
when: postgres_version_resp.stdout is version('9.6', '>=')
|
when: postgres_version_resp.stdout is version('9.6', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
|
@ -177,7 +177,7 @@
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ["SELECT pg_create_physical_replication_slot('slot1', True)"]
|
- result.queries == ["SELECT pg_create_physical_replication_slot('slot1', true)"]
|
||||||
when: postgres_version_resp.stdout is version('9.6', '>=')
|
when: postgres_version_resp.stdout is version('9.6', '>=')
|
||||||
|
|
||||||
# Check, rowcount must be 1
|
# Check, rowcount must be 1
|
||||||
|
|
Loading…
Reference in a new issue