1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

odbc: adding parameter to disable auto-commit (#1137) (#1139)

* Adding parameter to disable auto-commit (#1137)

* Update plugins/modules/database/misc/odbc.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/database/misc/odbc.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/database/misc/odbc.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/database/misc/odbc.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Adding odbc changelog fragment

* Picking a better word while fixing a typo

* Adding additional wording per felixfontein suggestion

* Update wording in plugins/modules/database/misc/odbc.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
John Westcott IV 2020-11-06 14:41:34 -05:00 committed by GitHub
parent ce0f327875
commit 6441814f8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "odbc - added a parameter ``commit`` which allows users to disable the explicit commit after the execute call (https://github.com/ansible-collections/community.general/pull/1139)."

View file

@ -31,7 +31,14 @@ options:
- Parameters to pass to the SQL query.
type: list
elements: str
commit:
description:
- Perform a commit after the execution of the SQL query.
- Some databases allow a commit after a select whereas others raise an exception.
- Default is C(true) to support legacy module behavior.
type: bool
default: yes
version_added: 1.3.0
requirements:
- "python >= 2.6"
- "pyodbc"
@ -49,6 +56,7 @@ EXAMPLES = '''
query: "Select * from table_a where column1 = ?"
params:
- "value1"
commit: false
changed_when: no
'''
@ -86,12 +94,14 @@ def main():
dsn=dict(type='str', required=True, no_log=True),
query=dict(type='str', required=True),
params=dict(type='list', elements='str'),
commit=dict(type='bool', default=True),
),
)
dsn = module.params.get('dsn')
query = module.params.get('query')
params = module.params.get('params')
commit = module.params.get('commit')
if not HAS_PYODBC:
module.fail_json(msg=missing_required_lib('pyodbc'))
@ -117,7 +127,8 @@ def main():
cursor.execute(query, params)
else:
cursor.execute(query)
cursor.commit()
if commit:
cursor.commit()
try:
# Get the rows out into an 2d array
for row in cursor.fetchall():