Backport of 65093, postgresql_lang: use query parameters with cursor.execute() (#65165)

* Backport of 65093, postgresql_lang: use query parameters with cursor.execute()

* fix CI tests
pull/65504/head
Andrey Klychkov 6 years ago committed by Matt Davis
parent f5fa6ace4a
commit 81a7957929

@ -0,0 +1,2 @@
bugfixes:
- postgresql_lang - use query params with cursor.execute (https://github.com/ansible/ansible/pull/65093).

@ -179,23 +179,23 @@ executed_queries = []
def lang_exists(cursor, lang): def lang_exists(cursor, lang):
"""Checks if language exists for db""" """Checks if language exists for db"""
query = "SELECT lanname FROM pg_language WHERE lanname = '%s'" % lang query = "SELECT lanname FROM pg_language WHERE lanname = %(lang)s"
cursor.execute(query) cursor.execute(query, {'lang': lang})
return cursor.rowcount > 0 return cursor.rowcount > 0
def lang_istrusted(cursor, lang): def lang_istrusted(cursor, lang):
"""Checks if language is trusted for db""" """Checks if language is trusted for db"""
query = "SELECT lanpltrusted FROM pg_language WHERE lanname = '%s'" % lang query = "SELECT lanpltrusted FROM pg_language WHERE lanname = %(lang)s"
cursor.execute(query) cursor.execute(query, {'lang': lang})
return cursor.fetchone()[0] return cursor.fetchone()[0]
def lang_altertrust(cursor, lang, trust): def lang_altertrust(cursor, lang, trust):
"""Changes if language is trusted for db""" """Changes if language is trusted for db"""
query = "UPDATE pg_language SET lanpltrusted = '%s' WHERE lanname = '%s'" % (trust, lang) query = "UPDATE pg_language SET lanpltrusted = %(trust)s WHERE lanname = %(lang)s"
executed_queries.append(query) cursor.execute(query, {'trust': trust, 'lang': lang})
cursor.execute(query) executed_queries.append(cursor.mogrify(query, {'trust': trust, 'lang': lang}))
return True return True

@ -107,7 +107,9 @@
# depend only on Postgres version # depend only on Postgres version
# (CentOS 6 repo contains the oldest PG version in these tests - 9.0): # (CentOS 6 repo contains the oldest PG version in these tests - 9.0):
- import_tasks: postgresql_lang.yml - import_tasks: postgresql_lang.yml
when: ansible_distribution == 'CentOS' when:
- ansible_distribution == 'CentOS'
- postgres_version_resp.stdout is version('9.4', '>=')
# dump/restore tests per format # dump/restore tests per format
# ============================================================ # ============================================================

@ -181,11 +181,12 @@
force_trust: yes force_trust: yes
register: result register: result
ignore_errors: yes ignore_errors: yes
when: postgres_version_resp.stdout is version('9.4', '>=')
- assert: - assert:
that: that:
- result is changed - result is changed
- result.queries == ['CREATE TRUSTED LANGUAGE "plpythonu"', "UPDATE pg_language SET lanpltrusted = 'True' WHERE lanname = 'plpythonu'"] - result.queries == ['CREATE TRUSTED LANGUAGE "plpythonu"', "UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'plpythonu'"]
- name: postgresql_lang - check that lang exists and it's trusted after previous step - name: postgresql_lang - check that lang exists and it's trusted after previous step
become_user: "{{ pg_user }}" become_user: "{{ pg_user }}"

Loading…
Cancel
Save