mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-08-02 12:14:28 -07:00
connection arguments: use 'passwd' instead of 'password' with older drivers
This commit is contained in:
parent
5d3ce47226
commit
2e0dbef296
1 changed files with 8 additions and 2 deletions
|
@ -144,18 +144,24 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='',
|
|||
if _mysql_cursor_param == 'cursor':
|
||||
# In case of PyMySQL driver:
|
||||
if mysql_driver.version_info[0] < 1:
|
||||
# for PyMySQL < 1.0.0, use 'db' instead of 'database'
|
||||
# for PyMySQL < 1.0.0, use 'db' instead of 'database' and 'passwd' instead of 'password'
|
||||
if 'database' in config:
|
||||
config['db'] = config['database']
|
||||
del config['database']
|
||||
if 'password' in config:
|
||||
config['passwd'] = config['password']
|
||||
del config['password']
|
||||
db_connection = mysql_driver.connect(autocommit=autocommit, **config)
|
||||
else:
|
||||
# In case of MySQLdb driver
|
||||
if mysql_driver.version_info[0] < 2 and mysql_driver.version_info[1] < 1:
|
||||
# for MySQLdb < 2.1.0, use 'db' instead of 'database'
|
||||
# for MySQLdb < 2.1.0, use 'db' instead of 'database' and 'passwd' instead of 'password'
|
||||
if 'database' in config:
|
||||
config['db'] = config['database']
|
||||
del config['database']
|
||||
if 'password' in config:
|
||||
config['passwd'] = config['password']
|
||||
del config['password']
|
||||
db_connection = mysql_driver.connect(**config)
|
||||
if autocommit:
|
||||
db_connection.autocommit(True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue