ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
784 stars 1.45k forks source link

community.general.mssql_script - multiple likes and the % sign #8560

Open willemri opened 1 week ago

willemri commented 1 week ago

Summary

i'm having issues, using wildcard searches in the community.general.mssql_script module when changing the search query to: ([DisplayName] LIKE '%wildcardsearch%' OR [LoginID] LIKE 'wildcardsearch%') The query works does work. when changing it to: ([DisplayName] LIKE '%wildcardsearch%' OR [LoginID] LIKE '%wildcardsearch%'), give me the error ValueError: more placeholders in sql than params available

Issue Type

Bug Report

Component Name

community.general.mssql_script

Ansible Version

  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/xxxx@xxxx.xxx.xx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/xxxxx@xxxx.xxx.xxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.12.1 (main, Feb 21 2024, 10:25:11) [GCC 8.5.0 20210514 (Red Hat 8.5.0-21)] (/usr/bin/python3.12)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

# /home/xx@xxxx.xxxx.be/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 9.1.0  

Configuration

CONFIG_FILE() = /etc/ansible/ansible.cfg

OS / Environment

RHEL8.10

Steps to Reproduce

- name: Execute SQL Query on Database
  community.general.mssql_script:
    login_user: "{{ db_username }}"
    login_password: "{{ db_password }}"
    login_host: "{{ db_host }}"
    login_port: 1433
    db: "{{ db_name }}"
    output: dict
    script: |
      SELECT *
       FROM Employee
       WHERE ([DisplayName] LIKE '%wildcardsearch%' OR [LoginID] LIKE '%wildcardsearch%')
  register: query_result_raw

Expected Results

I expected my variable query_result_raw to be filled in.

Actual Results

Code of Conduct

ansibullbot commented 1 week ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 1 week ago

cc @kbudde click here for bot help

felixfontein commented 6 days ago

I don't know the module and MSSQL at all, but maybe (just guessing) you have to use something like %% to get a regular % in the actual query that is run, to avoid the % to be interpreted as an interpolation for a prepared statement.

willemri commented 6 days ago

I have tried with all the same result: %% \% \%