mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 10:51:24 -07:00
Migrate from MySQLdb to PyMySQL (#40123)
* Migrate from MySQLdb to PyMySQL * Deduplicate driver loading and failure message * Explain requirements * Apply requirements docs change to proxysql too * Add changelog
This commit is contained in:
parent
205693a3f9
commit
d34cf93f1a
20 changed files with 92 additions and 179 deletions
|
@ -30,10 +30,14 @@
|
|||
import os
|
||||
|
||||
try:
|
||||
import MySQLdb
|
||||
mysqldb_found = True
|
||||
import pymysql as mysql_driver
|
||||
except ImportError:
|
||||
mysqldb_found = False
|
||||
try:
|
||||
import MySQLdb as mysql_driver
|
||||
except ImportError:
|
||||
mysql_driver = None
|
||||
|
||||
mysql_driver_fail_msg = 'The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required.'
|
||||
|
||||
|
||||
def mysql_connect(module, login_user=None, login_password=None, config_file='', ssl_cert=None, ssl_key=None, ssl_ca=None, db=None, cursor_class=None,
|
||||
|
@ -69,8 +73,8 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='',
|
|||
if connect_timeout is not None:
|
||||
config['connect_timeout'] = connect_timeout
|
||||
|
||||
db_connection = MySQLdb.connect(**config)
|
||||
db_connection = mysql_driver.connect(**config)
|
||||
if cursor_class is not None:
|
||||
return db_connection.cursor(cursorclass=MySQLdb.cursors.DictCursor)
|
||||
return db_connection.cursor(cursorclass=mysql_driver.cursors.DictCursor)
|
||||
else:
|
||||
return db_connection.cursor()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue