postgresql_ext: use query_params (#64994)

* postgresql_ext: use query_params

* added changelog
This commit is contained in:
Andrey Klychkov 2019-12-02 16:32:25 +03:00 committed by John R Barker
parent c53b8030ab
commit 0cadb952f9
3 changed files with 23 additions and 10 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- postgresql_ext - use query parameters with cursor object (https://github.com/ansible/ansible/pull/64994).

View file

@ -228,11 +228,13 @@ def ext_update_version(cursor, ext, version):
version (str) -- extension version
"""
if version != 'latest':
query = ("ALTER EXTENSION \"%s\" UPDATE TO '%s'" % (ext, version))
query = ("ALTER EXTENSION \"%s\"" % ext)
cursor.execute(query + " UPDATE TO %(ver)s", {'ver': version})
executed_queries.append(cursor.mogrify(query + " UPDATE TO %(ver)s", {'ver': version}))
else:
query = ("ALTER EXTENSION \"%s\" UPDATE" % ext)
cursor.execute(query)
executed_queries.append(query)
cursor.execute(query)
executed_queries.append(query)
return True
@ -241,11 +243,16 @@ def ext_create(cursor, ext, schema, cascade, version):
if schema:
query += " WITH SCHEMA \"%s\"" % schema
if version:
query += " VERSION '%s'" % version
query += " VERSION %(ver)s"
if cascade:
query += " CASCADE"
cursor.execute(query)
executed_queries.append(query)
if version:
cursor.execute(query, {'ver': version})
executed_queries.append(cursor.mogrify(query, {'ver': version}))
else:
cursor.execute(query)
executed_queries.append(query)
return True
@ -267,18 +274,18 @@ def ext_get_versions(cursor, ext):
# 1. Get the current extension version:
query = ("SELECT extversion FROM pg_catalog.pg_extension "
"WHERE extname = '%s'" % ext)
"WHERE extname = %(ext)s")
current_version = '0'
cursor.execute(query)
cursor.execute(query, {'ext': ext})
res = cursor.fetchone()
if res:
current_version = res[0]
# 2. Get available versions:
query = ("SELECT version FROM pg_available_extension_versions "
"WHERE name = '%s'" % ext)
cursor.execute(query)
"WHERE name = %(ext)s")
cursor.execute(query, {'ext': ext})
res = cursor.fetchall()
available_versions = []

View file

@ -1,3 +1,7 @@
destructive
shippable/posix/group4
skip/osx
skip/centos
skip/redhat
skip/freebsd
skip/opensuse