diff --git a/changelogs/fragments/11972-odbc-fix-commit-fetch-order.yml b/changelogs/fragments/11972-odbc-fix-commit-fetch-order.yml new file mode 100644 index 0000000000..a7022fe82c --- /dev/null +++ b/changelogs/fragments/11972-odbc-fix-commit-fetch-order.yml @@ -0,0 +1,2 @@ +bugfixes: + - odbc - fetch rows before committing to fix ``HY010`` function sequence error (https://github.com/ansible-collections/community.general/issues/5395, https://github.com/ansible-collections/community.general/pull/11972). diff --git a/plugins/modules/odbc.py b/plugins/modules/odbc.py index 883dd60d56..d329916419 100644 --- a/plugins/modules/odbc.py +++ b/plugins/modules/odbc.py @@ -132,8 +132,6 @@ def main(): cursor.execute(query, params) else: cursor.execute(query) - if commit: - cursor.commit() try: # Get the rows out into an 2d array for row in cursor.fetchall(): @@ -158,6 +156,8 @@ def main(): except Exception as e: module.fail_json(msg=f"Exception while reading rows: {e}") + if commit: + cursor.commit() cursor.close() except Exception as e: module.fail_json(msg=f"Failed to execute query: {e}")