L i&ndZddlmZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z d d l m Z d d l mZd dl mZd dl mZddlmZddlmZe r6ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z GddeZ!Gdde Z"Gd d!eZ#e#Z$y)"a .. dialect:: mysql+mysqldb :name: mysqlclient (maintained fork of MySQL-Python) :dbapi: mysqldb :connectstring: mysql+mysqldb://:@[:]/ :url: https://pypi.org/project/mysqlclient/ Driver Status ------------- The mysqlclient DBAPI is a maintained fork of the `MySQL-Python `_ DBAPI that is no longer maintained. `mysqlclient`_ supports Python 2 and Python 3 and is very stable. .. _mysqlclient: https://github.com/PyMySQL/mysqlclient-python .. _mysqldb_unicode: Unicode ------- Please see :ref:`mysql_unicode` for current recommendations on unicode handling. .. _mysqldb_ssl: SSL Connections ---------------- The mysqlclient and PyMySQL DBAPIs accept an additional dictionary under the key "ssl", which may be specified using the :paramref:`_sa.create_engine.connect_args` dictionary:: engine = create_engine( "mysql+mysqldb://scott:tiger@192.168.0.134/test", connect_args={ "ssl": { "ca": "/home/gord/client-ssl/ca.pem", "cert": "/home/gord/client-ssl/client-cert.pem", "key": "/home/gord/client-ssl/client-key.pem", } }, ) For convenience, the following keys may also be specified inline within the URL where they will be interpreted into the "ssl" dictionary automatically: "ssl_ca", "ssl_cert", "ssl_key", "ssl_capath", "ssl_cipher", "ssl_check_hostname". An example is as follows:: connection_uri = ( "mysql+mysqldb://scott:tiger@192.168.0.134/test" "?ssl_ca=/home/gord/client-ssl/ca.pem" "&ssl_cert=/home/gord/client-ssl/client-cert.pem" "&ssl_key=/home/gord/client-ssl/client-key.pem" ) .. seealso:: :ref:`pymysql_ssl` in the PyMySQL dialect Using MySQLdb with Google Cloud SQL ----------------------------------- Google Cloud SQL now recommends use of the MySQLdb dialect. Connect using a URL like the following: .. sourcecode:: text mysql+mysqldb://root@/?unix_socket=/cloudsql/: Server Side Cursors ------------------- The mysqldb dialect supports server-side cursors. See :ref:`mysql_ss_cursors`. ) annotationsN)Any)Callable)cast)Dict)Optional)Tuple) TYPE_CHECKING) MySQLCompiler) MySQLDialect)MySQLExecutionContext)MySQLIdentifierPreparer)util)Literal) Connection)_DBAPIMultiExecuteParams)ConnectArgsType)DBAPIConnection) DBAPICursor) DBAPIModule)ExecutionContext)IsolationLevel)URLc eZdZy)MySQLExecutionContext_mysqldbN__name__ __module__ __qualname__g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/dialects/mysql/mysqldb.pyrrvr#rc eZdZy)MySQLCompiler_mysqldbNrr"r#r$r'r'zr%r#r'c8eZdZUdZdZdZdZdZdZdZ e Z e Z eZded<dfd ZddZej(j*ddZedd Zdfd Zdd Z d dd Z d dd ZddZddZddZ d dZ d!dZ! d"fd Z"xZ#S)#MySQLDialect_mysqldbmysqldbTformatTuple[int, ...]server_version_infoc t|di||jAt|jdr+|j |jj |_yd|_y)N __version__rrrr")super__init__dbapihasattr_parse_dbapi_versionr/_mysql_dbapi_version)selfkwargs __class__s r$r2zMySQLDialect_mysqldb.__init__s[ "6"zz%'$**m*L  % %djj&<&< = ! !r#cztjd|}|r#td|jdddDSy)Nz(\d+)\.(\d+)(?:\.(\d+))?c38K|]}|t|ywN)int).0xs r$ z.sKAQ]QKsr rr0)rematchtuplegroup)r7versionms r$r5z)MySQLDialect_mysqldb._parse_dbapi_versions7 HH0' : KAq)9KK Kr#c| tdj}|j|_y#tt f$rYywxYw)NzMySQLdb.cursorsTF) __import__cursorsSSCursor _sscursor ImportErrorAttributeError)r7rJs r$supports_server_side_cursorsz1MySQLDialect_mysqldb.supports_server_side_cursorss?  !23;;G$--DN^,  s &);;ctdS)NMySQLdb)rI)clss r$ import_dbapiz!MySQLDialect_mysqldb.import_dbapis )$$r#c2t|dfd }|S)Nc||j}|5|j}|jd|z|jyy)Nz SET NAMES %s)character_set_namecursorexecuteclose)conn charset_namerWsuper_s r$ on_connectz3MySQLDialect_mysqldb.on_connect..on_connectsN!t 224L'~ <= (r#)rZrreturnNone)r1r])r7r]r\r9s @r$r]zMySQLDialect_mysqldb.on_connects#% r#c$|jy)NT)ping)r7dbapi_connections r$do_pingzMySQLDialect_mysqldb.do_pingsr#cX|j||}||tt|_yyr<) executemanyrr _rowcount)r7rW statement parameterscontextrowcounts r$do_executemanyz#MySQLDialect_mysqldb.do_executemanys1%%i<  =ED& 0 : r#ch|tddd}|jdi|}|j|jt j |dt t j |dtt j |dtt j |dtt j |d tt j |d t t j |d t t j |d ti}d tfdtfdtfdtfdtfdt fg}|D]2\}}||vs ||||dd<t j ||dd|||=4|r||d<|jd d}|j} | || z}||d <g|fS)Ndbuserpasswd)databaseusernamepasswordcompressconnect_timeout read_timeout write_timeout client_flag local_infile use_unicodecharsetssl_cassl_keyssl_cert ssl_capath ssl_cipherssl_check_hostnamesslrr") dicttranslate_connect_argsupdatequeryrcoerce_kw_typeboolr=strget_found_rows_client_flag) r7url_translate_argsoptsrkeyskeykw_typerwclient_flag_found_rowss r$create_connect_argsz(MySQLDialect_mysqldb.create_connect_argss  ""O*s))rsN^#  ')")=440053! $9  M yA<yAx r#