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>
This commit is contained in:
parent
ce0f327875
commit
6441814f8b
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,7 +127,8 @@ def main():
|
||||||
cursor.execute(query, params)
|
cursor.execute(query, params)
|
||||||
else:
|
else:
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
cursor.commit()
|
if commit:
|
||||||
|
cursor.commit()
|
||||||
try:
|
try:
|
||||||
# Get the rows out into an 2d array
|
# Get the rows out into an 2d array
|
||||||
for row in cursor.fetchall():
|
for row in cursor.fetchall():
|
||||||
|
|
Loading…
Reference in a new issue