diff --git a/changelogs/fragments/11754-mssql-script-params-substitution.yml b/changelogs/fragments/11754-mssql-script-params-substitution.yml new file mode 100644 index 0000000000..3b06a9cfd8 --- /dev/null +++ b/changelogs/fragments/11754-mssql-script-params-substitution.yml @@ -0,0 +1,4 @@ +bugfixes: + - mssql_script - only passes ``params`` to ``cursor.execute()`` when the user actually provides them + (https://github.com/ansible-collections/community.general/issues/11699, + https://github.com/ansible-collections/community.general/pull/11754). diff --git a/plugins/modules/mssql_script.py b/plugins/modules/mssql_script.py index 3dceb9ed95..7c014dc09c 100644 --- a/plugins/modules/mssql_script.py +++ b/plugins/modules/mssql_script.py @@ -377,7 +377,10 @@ def run_module(): for query in queries: # Catch and exit on any bad query errors try: - cursor.execute(query, sql_params) + if sql_params: + cursor.execute(query, sql_params) + else: + cursor.execute(query) qry_result = [] rows = cursor.fetchall() while rows: