Skip to content

Commit

Permalink
mysql_query: correctly reflect changed status in replace statements (#…
Browse files Browse the repository at this point in the history
…193) (#195)

* mysql_query: correctly reflect changed status in replace statements.

* Fix the wrong indent.

(cherry picked from commit 9055bb4)

Co-authored-by: Tong He <[email protected]>
  • Loading branch information
Andersson007 and unnecessary-username authored Aug 10, 2021
1 parent 5d7451a commit 0c261b7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ Tronde
tvlooy
tyll
UncertaintyP
unnecessary-username
vamshi8
vanne
vdboor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- mysql_query - correctly reflect changed status in replace statements (https://github.com/ansible-collections/community.mysql/pull/193).
2 changes: 1 addition & 1 deletion plugins/modules/mysql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
)
from ansible.module_utils._text import to_native

DML_QUERY_KEYWORDS = ('INSERT', 'UPDATE', 'DELETE')
DML_QUERY_KEYWORDS = ('INSERT', 'UPDATE', 'DELETE', 'REPLACE')
# TRUNCATE is not DDL query but it also returns 0 rows affected:
DDL_QUERY_KEYWORDS = ('CREATE', 'DROP', 'ALTER', 'RENAME', 'TRUNCATE')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test_db: testdb
test_table1: test1
test_table2: test2
test_table3: test3
test_table4: test4
test_script_path: /tmp/test.sql

user_name_1: 'db_user1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,38 @@
- result is failed
- result.msg is search('the elements in query list must be strings')

- name: Create {{ test_table4 }}
mysql_query:
<<: *mysql_params
login_db: '{{ test_db }}'
query: 'CREATE TABLE {{ test_table4 }} (id int primary key, story text)'

- name: Insert test data using replace statement
mysql_query:
<<: *mysql_params
login_db: '{{ test_db }}'
query: "REPLACE INTO {{ test_table4 }} VALUES (1, 'first')"
single_transaction: yes
register: result

- assert:
that:
- result is changed
- result.rowcount == [1]

- name: Replace test data
mysql_query:
<<: *mysql_params
login_db: '{{ test_db }}'
query: "REPLACE INTO {{ test_table4 }} VALUES (1, 'one')"
single_transaction: yes
register: result

- assert:
that:
- result is changed
- result.rowcount == [2]

- name: Drop db {{ test_db }}
mysql_query:
<<: *mysql_params
Expand Down

0 comments on commit 0c261b7

Please sign in to comment.