mysql_query: fix false change reports when IF NOT EXISTS clause is used (#322)

* mysql_query: fix false change reports when IF NOT EXISTS clause is used

* Fix

* Fix doc, add fragment

* Improve doc
This commit is contained in:
Andrew Klychkov 2022-05-25 17:19:31 +03:00 committed by GitHub
parent ceda7662d0
commit 647461010d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 4 deletions

View file

@ -321,6 +321,39 @@
- result is changed
- result.rowcount == [2]
# Issue https://github.com/ansible-collections/community.mysql/issues/268
- name: Create table
mysql_query:
<<: *mysql_params
login_db: '{{ test_db }}'
query: "CREATE TABLE issue268 (id int)"
single_transaction: yes
# Issue https://github.com/ansible-collections/community.mysql/issues/268
- name: Create table with IF NOT EXISTS
mysql_query:
<<: *mysql_params
login_db: '{{ test_db }}'
query: "CREATE TABLE IF NOT EXISTS issue268 (id int)"
single_transaction: yes
register: result
# Issue https://github.com/ansible-collections/community.mysql/issues/268
- assert:
that:
# PyMySQL driver throws a warning, so the following is correct
- result is not changed
when: connector.name.0 is search('pymysql')
# Issue https://github.com/ansible-collections/community.mysql/issues/268
- assert:
that:
# mysqlclient driver throws nothing, so it's impossible to figure out
# if the state was changed or not.
# We assume that it was for DDL queryes by default in the code
- result is changed
when: connector.name.0 is search('mysqlclient')
- name: Drop db {{ test_db }}
mysql_query:
<<: *mysql_params