From 4cd74766045d85f2fe248271d5135c75b34e7b8b Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:18:59 +0100 Subject: [PATCH] odbc: adding parameter to disable auto-commit (#1137) (#1139) (#1240) * Adding parameter to disable auto-commit (#1137) * Update plugins/modules/database/misc/odbc.py Co-authored-by: Felix Fontein * Update plugins/modules/database/misc/odbc.py Co-authored-by: Felix Fontein * Update plugins/modules/database/misc/odbc.py Co-authored-by: Felix Fontein * Update plugins/modules/database/misc/odbc.py Co-authored-by: Felix Fontein * 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 Co-authored-by: Felix Fontein Co-authored-by: Andrew Klychkov (cherry picked from commit 6441814f8b6479bc83bb33813e92aceb03674d43) Co-authored-by: John Westcott IV <32551173+john-westcott-iv@users.noreply.github.com> --- changelogs/fragments/odbc.yml | 2 ++ plugins/modules/database/misc/odbc.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/odbc.yml diff --git a/changelogs/fragments/odbc.yml b/changelogs/fragments/odbc.yml new file mode 100644 index 0000000000..606a26f421 --- /dev/null +++ b/changelogs/fragments/odbc.yml @@ -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)." diff --git a/plugins/modules/database/misc/odbc.py b/plugins/modules/database/misc/odbc.py index 4ebda69747..313a7f7096 100644 --- a/plugins/modules/database/misc/odbc.py +++ b/plugins/modules/database/misc/odbc.py @@ -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():