mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-08 11:40:33 -07:00
mysql_query: fix failing when single-row query contains commas
This commit is contained in:
parent
0dfd63a4cb
commit
a86282cd5e
3 changed files with 20 additions and 3 deletions
|
@ -20,8 +20,7 @@ options:
|
||||||
query:
|
query:
|
||||||
description:
|
description:
|
||||||
- SQL query to run. Multiple queries can be passed using YAML list syntax.
|
- SQL query to run. Multiple queries can be passed using YAML list syntax.
|
||||||
type: list
|
type: raw
|
||||||
elements: str
|
|
||||||
required: yes
|
required: yes
|
||||||
positional_args:
|
positional_args:
|
||||||
description:
|
description:
|
||||||
|
@ -123,7 +122,7 @@ DDL_QUERY_KEYWORDS = ('CREATE', 'DROP', 'ALTER', 'RENAME', 'TRUNCATE')
|
||||||
def main():
|
def main():
|
||||||
argument_spec = mysql_common_argument_spec()
|
argument_spec = mysql_common_argument_spec()
|
||||||
argument_spec.update(
|
argument_spec.update(
|
||||||
query=dict(type='list', elements='str', required=True),
|
query=dict(type='raw', required=True),
|
||||||
login_db=dict(type='str'),
|
login_db=dict(type='str'),
|
||||||
positional_args=dict(type='list'),
|
positional_args=dict(type='list'),
|
||||||
named_args=dict(type='dict'),
|
named_args=dict(type='dict'),
|
||||||
|
@ -183,6 +182,9 @@ def main():
|
||||||
query_result = []
|
query_result = []
|
||||||
executed_queries = []
|
executed_queries = []
|
||||||
rowcount = []
|
rowcount = []
|
||||||
|
if isinstance(query, str):
|
||||||
|
query = [query]
|
||||||
|
|
||||||
for q in query:
|
for q in query:
|
||||||
try:
|
try:
|
||||||
cursor.execute(q, arguments)
|
cursor.execute(q, arguments)
|
||||||
|
|
|
@ -6,6 +6,7 @@ db_name: data
|
||||||
test_db: testdb
|
test_db: testdb
|
||||||
test_table1: test1
|
test_table1: test1
|
||||||
test_table2: test2
|
test_table2: test2
|
||||||
|
test_table3: test3
|
||||||
test_script_path: /tmp/test.sql
|
test_script_path: /tmp/test.sql
|
||||||
|
|
||||||
user_name_1: 'db_user1'
|
user_name_1: 'db_user1'
|
||||||
|
|
|
@ -238,6 +238,20 @@
|
||||||
that:
|
that:
|
||||||
- result.rowcount == [0]
|
- result.rowcount == [0]
|
||||||
|
|
||||||
|
- name: Create {{ test_table3 }}
|
||||||
|
mysql_query:
|
||||||
|
<<: *mysql_params
|
||||||
|
login_db: '{{ test_db }}'
|
||||||
|
query: 'CREATE TABLE {{ test_table3 }} (id int, story text)'
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Select from {{ test_table3 }}
|
||||||
|
mysql_query:
|
||||||
|
<<: *mysql_params
|
||||||
|
login_db: '{{ test_db }}'
|
||||||
|
query: 'SELECT id, story FROM {{ test_table3 }}'
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Drop db {{ test_db }}
|
- name: Drop db {{ test_db }}
|
||||||
mysql_query:
|
mysql_query:
|
||||||
<<: *mysql_params
|
<<: *mysql_params
|
||||||
|
|
Loading…
Add table
Reference in a new issue