mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* 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>
(cherry picked from commit 6441814f8b
)
Co-authored-by: John Westcott IV <32551173+john-westcott-iv@users.noreply.github.com>
This commit is contained in:
parent
24f973a9d1
commit
4cd7476604
2 changed files with 15 additions and 2 deletions
2
changelogs/fragments/odbc.yml
Normal file
2
changelogs/fragments/odbc.yml
Normal 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)."
|
|
@ -31,7 +31,14 @@ options:
|
||||||
- Parameters to pass to the SQL query.
|
- Parameters to pass to the SQL query.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
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:
|
requirements:
|
||||||
- "python >= 2.6"
|
- "python >= 2.6"
|
||||||
- "pyodbc"
|
- "pyodbc"
|
||||||
|
@ -49,6 +56,7 @@ EXAMPLES = '''
|
||||||
query: "Select * from table_a where column1 = ?"
|
query: "Select * from table_a where column1 = ?"
|
||||||
params:
|
params:
|
||||||
- "value1"
|
- "value1"
|
||||||
|
commit: false
|
||||||
changed_when: no
|
changed_when: no
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -86,12 +94,14 @@ def main():
|
||||||
dsn=dict(type='str', required=True, no_log=True),
|
dsn=dict(type='str', required=True, no_log=True),
|
||||||
query=dict(type='str', required=True),
|
query=dict(type='str', required=True),
|
||||||
params=dict(type='list', elements='str'),
|
params=dict(type='list', elements='str'),
|
||||||
|
commit=dict(type='bool', default=True),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
dsn = module.params.get('dsn')
|
dsn = module.params.get('dsn')
|
||||||
query = module.params.get('query')
|
query = module.params.get('query')
|
||||||
params = module.params.get('params')
|
params = module.params.get('params')
|
||||||
|
commit = module.params.get('commit')
|
||||||
|
|
||||||
if not HAS_PYODBC:
|
if not HAS_PYODBC:
|
||||||
module.fail_json(msg=missing_required_lib('pyodbc'))
|
module.fail_json(msg=missing_required_lib('pyodbc'))
|
||||||
|
@ -117,6 +127,7 @@ def main():
|
||||||
cursor.execute(query, params)
|
cursor.execute(query, params)
|
||||||
else:
|
else:
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
if commit:
|
||||||
cursor.commit()
|
cursor.commit()
|
||||||
try:
|
try:
|
||||||
# Get the rows out into an 2d array
|
# Get the rows out into an 2d array
|
||||||
|
|
Loading…
Reference in a new issue