mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-17 16:01:25 -07:00
Monkey patch the Connection class
This commit is contained in:
parent
f6d552d95e
commit
18fd739a04
1 changed files with 6 additions and 0 deletions
|
@ -89,6 +89,12 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='',
|
||||||
if autocommit:
|
if autocommit:
|
||||||
db_connection.autocommit(True)
|
db_connection.autocommit(True)
|
||||||
|
|
||||||
|
# Monkey patch the Connection class to close the connection when garbage collected
|
||||||
|
def _conn_patch(conn_self):
|
||||||
|
conn_self.close()
|
||||||
|
db_connection.__class__.__del__ = _conn_patch
|
||||||
|
# Patched
|
||||||
|
|
||||||
if cursor_class == 'DictCursor':
|
if cursor_class == 'DictCursor':
|
||||||
return db_connection.cursor(**{_mysql_cursor_param: mysql_driver.cursors.DictCursor}), db_connection
|
return db_connection.cursor(**{_mysql_cursor_param: mysql_driver.cursors.DictCursor}), db_connection
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue