From c791f916d3b0462fcbfb5f57f19bfce5152f66bf Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Tue, 10 Dec 2019 11:41:23 +0300 Subject: [PATCH] postgresql_schema: use query_params with cursor object (#65679) --- ...79-postgresql_schema_user_query_params_with_cursor.yml | 2 ++ .../modules/database/postgresql/postgresql_schema.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/65679-postgresql_schema_user_query_params_with_cursor.yml diff --git a/changelogs/fragments/65679-postgresql_schema_user_query_params_with_cursor.yml b/changelogs/fragments/65679-postgresql_schema_user_query_params_with_cursor.yml new file mode 100644 index 00000000000..2af7242211a --- /dev/null +++ b/changelogs/fragments/65679-postgresql_schema_user_query_params_with_cursor.yml @@ -0,0 +1,2 @@ +bugfixes: +- postgresql_schema - use query parameters with cursor object (https://github.com/ansible/ansible/pull/65679). diff --git a/lib/ansible/modules/database/postgresql/postgresql_schema.py b/lib/ansible/modules/database/postgresql/postgresql_schema.py index 3fc4d06030a..9781a7387ac 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_schema.py +++ b/lib/ansible/modules/database/postgresql/postgresql_schema.py @@ -165,15 +165,15 @@ def set_owner(cursor, schema, owner): def get_schema_info(cursor, schema): query = ("SELECT schema_owner AS owner " "FROM information_schema.schemata " - "WHERE schema_name = '%s'" % schema) - cursor.execute(query) + "WHERE schema_name = %(schema)s") + cursor.execute(query, {'schema': schema}) return cursor.fetchone() def schema_exists(cursor, schema): query = ("SELECT schema_name FROM information_schema.schemata " - "WHERE schema_name = '%s'" % schema) - cursor.execute(query) + "WHERE schema_name = %(schema)s") + cursor.execute(query, {'schema': schema}) return cursor.rowcount == 1