change suggested

This commit is contained in:
Andrew Klychkov 2020-11-03 09:44:34 +03:00
parent faf4469432
commit 4189c430a6
2 changed files with 23 additions and 3 deletions

View file

@ -20,7 +20,7 @@ options:
query:
description:
- SQL query to run. Multiple queries can be passed using YAML list syntax.
- Must be a string or YAML list.
- Must be a string or YAML list containing strings.
type: raw
required: yes
positional_args:
@ -149,6 +149,13 @@ def main():
if not isinstance(query, str) and not isinstance(query, list):
module.fail_json(msg="the query option value must be a string or list, passed %s" % type(query))
if isinstance(query, str):
query = [query]
for elem in query:
if not isinstance(elem, str):
module.fail_json(msg="the elements in query list must be strings, passed '%s' %s" % (elem, type(elem)))
if module.params["single_transaction"]:
autocommit = False
else:
@ -185,8 +192,6 @@ def main():
query_result = []
executed_queries = []
rowcount = []
if isinstance(query, str):
query = [query]
for q in query:
try:

View file

@ -274,6 +274,21 @@
- result is failed
- result.msg is search('the query option value must be a string or list')
- name: Pass wrong query element
mysql_query:
<<: *mysql_params
login_db: '{{ test_db }}'
query:
- 'SELECT now()'
- {'this type is': 'wrong'}
register: result
ignore_errors: yes
- assert:
that:
- result is failed
- result.msg is search('the elements in query list must be strings')
- name: Drop db {{ test_db }}
mysql_query:
<<: *mysql_params