
    h                     ,   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
l	m
Z
 ddlmZ  G d de      Z G d de      Z G d d      Z G d dee      Z G d dee      Z G d de      Z G d de      Z G d de
e      ZeZeZy)a:  
.. dialect:: mysql+mysqlconnector
    :name: MySQL Connector/Python
    :dbapi: myconnpy
    :connectstring: mysql+mysqlconnector://<user>:<password>@<host>[:<port>]/<dbname>
    :url: https://pypi.org/project/mysql-connector-python/

Driver Status
-------------

MySQL Connector/Python is supported as of SQLAlchemy 2.0.39 to the
degree which the driver is functional.   There are still ongoing issues
with features such as server side cursors which remain disabled until
upstream issues are repaired.

.. versionchanged:: 2.0.39

    The MySQL Connector/Python dialect has been updated to support the
    latest version of this DBAPI.   Previously, MySQL Connector/Python
    was not fully supported.

Connecting to MariaDB with MySQL Connector/Python
--------------------------------------------------

MySQL Connector/Python may attempt to pass an incompatible collation to the
database when connecting to MariaDB.  Experimentation has shown that using
``?charset=utf8mb4&collation=utfmb4_general_ci`` or similar MariaDB-compatible
charset/collation will allow connectivity.


    N   )BIT)MariaDBIdentifierPreparer)MySQLCompiler)MySQLDialect)MySQLExecutionContext)MySQLIdentifierPreparer)MariaDBDialect   )utilc                       e Zd Zd Zd Zy)$MySQLExecutionContext_mysqlconnectorc                 :    | j                   j                  d      S )NFbuffered_dbapi_connectioncursorselfs    QD:\EasyAligner\venv\Lib\site-packages\sqlalchemy/dialects/mysql/mysqlconnector.pycreate_server_side_cursorz>MySQLExecutionContext_mysqlconnector.create_server_side_cursor7   s    %%,,e,<<    c                 :    | j                   j                  d      S )NTr   r   r   s    r   create_default_cursorz:MySQLExecutionContext_mysqlconnector.create_default_cursor:   s    %%,,d,;;r   N)__name__
__module____qualname__r   r    r   r   r   r   6   s    =<r   r   c                       e Zd Zd Zy)MySQLCompiler_mysqlconnectorc                 ~     | j                   |j                  fi |dz    | j                   |j                  fi |z   S )Nz % )processleftright)r   binaryoperatorkws       r   visit_mod_binaryz-MySQLCompiler_mysqlconnector.visit_mod_binary?   sB    DLL++dll6<<.2./	
r   N)r   r   r   r)   r   r   r   r!   r!   >   s    
r   r!   c                   F    e Zd Zed        Zej
                  d        Zd Zy)'IdentifierPreparerCommon_mysqlconnectorc                      y)NFr   r   s    r   _double_percentsz8IdentifierPreparerCommon_mysqlconnector._double_percentsH   s    r   c                      y Nr   r   values     r   r-   z8IdentifierPreparerCommon_mysqlconnector._double_percentsL   s    r   c                 R    |j                  | j                  | j                        }|S r/   )replaceescape_quoteescape_to_quoter0   s     r   _escape_identifierz:IdentifierPreparerCommon_mysqlconnector._escape_identifierP   s#    d//1E1EFr   N)r   r   r   propertyr-   setterr6   r   r   r   r+   r+   G   s3       r   r+   c                       e Zd Zy)&MySQLIdentifierPreparer_mysqlconnectorNr   r   r   r   r   r   r:   r:   U        	r   r:   c                       e Zd Zy)(MariaDBIdentifierPreparer_mysqlconnectorNr;   r   r   r   r>   r>   [   r<   r   r>   c                       e Zd Zd Zy)_myconnpyBITc                      y)z0MySQL-connector already converts mysql bits, so.Nr   )r   dialectcoltypes      r   result_processorz_myconnpyBIT.result_processorb   s     r   N)r   r   r   rD   r   r   r   r@   r@   a   s    r   r@   c                        e Zd ZdZdZdZdZdZdZdZ	dZ
eZeZeZ ej$                  ej(                  eei      Zed        Zd Zd Zej6                  d        Zd	 Zd
 Zd ZddZ ddZ!d Z" fdZ# xZ$S )MySQLDialect_mysqlconnectormysqlconnectorTFformatc                     ddl m} |S )Nr   )	connector)mysqlrJ   )clsrJ   s     r   import_dbapiz(MySQLDialect_mysqlconnector.import_dbapi   s    #r   c                 &    |j                  d       y)NFT)pingr   dbapi_connections     r   do_pingz#MySQLDialect_mysqlconnector.do_ping   s    e$r   c                    |j                  d      }|j                  |j                         t        j                  |dt
               t        j                  |dt
               t        j                  |dt
               t        j                  |dt               t        j                  |dt
               t        j                  |dt               t        j                  |d	t               t        j                  |d
t
               t        j                  |dt
               t        j                  |dt
               t        j                  |dt
               t        j                  |dt               t        j                  |dt
               t        j                  |dt
               t        j                  |dt
               t        j                  |dt
               t        j                  |dt
               d|d<   | j                  ?	 ddlm	} |j                  d|j                               }||j                  z  }||d<   g |gS g |gS # t        $ r Y g |gS w xY w)Nuser)usernameallow_local_infile
autocommitr   client_flagcompressconnection_timeoutconnect_timeoutconsume_results
force_ipv6get_warningspool_reset_session	pool_sizeraise_on_warningsrawssl_verify_certuse_pureuse_unicodeTr   )
ClientFlagclient_flags)translate_connect_argsupdatequeryr   coerce_kw_typeboolintdbapimysql.connector.constantsrf   getget_default
FOUND_ROWS	Exception)r   urloptsrf   rg   s        r   create_connect_argsz/MySQLDialect_mysqlconnector.create_connect_args   s   ))6):CIID"6=D,5D*d3D-5D*d3D"6<D"3S9D"3T:D,5D.$7D"6=D+s3D"5t<D%.D"3T:D*d3D-6  Z ::!	@#xx"J$:$:$<  
 5 55'3^$ DzDz  Dzs   :I 	IIc                     | j                   rgt        | j                   d      rPt        j                  d| j                   j                        }|r#t        d |j                  ddd      D              S y y y )N__version__z(\d+)\.(\d+)(?:\.(\d+))?c              3   8   K   | ]  }|t        |        y wr/   )rm   ).0xs     r   	<genexpr>zKMySQLDialect_mysqlconnector._mysqlconnector_version_info.<locals>.<genexpr>   s     O-=SV-=s   r      r   )rn   hasattrrematchrx   tuplegroup)r   ms     r   _mysqlconnector_version_infoz8MySQLDialect_mysqlconnector._mysqlconnector_version_info   s^    ::'$**m<4djj6L6LMAOQWWQ1-=OOO  =:r   c                 .    |j                   j                  S r/   )
connectioncharset)r   r   s     r   _detect_charsetz+MySQLDialect_mysqlconnector._detect_charset   s    $$,,,r   c                     |j                   S r/   )errno)r   	exceptions     r   _extract_error_codez/MySQLDialect_mysqlconnector._extract_error_code   s    r   c                     d}| j                   j                  | j                   j                  | j                   j                  f}t	        ||      r,|j
                  |v xs dt        |      v xs dt        |      v S y)N)i  i  i  i  i  i   zMySQL Connection not available.z$Connection to MySQL is not availableF)rn   OperationalErrorInterfaceErrorProgrammingError
isinstancer   str)r   er   r   errnos
exceptionss         r   is_disconnectz)MySQLDialect_mysqlconnector.is_disconnect   s{    5JJ''JJ%%JJ''


 a$6! D4A>D9SVC r   c                 "    |j                         S r/   )fetchallr   rpr   s      r   _compat_fetchallz,MySQLDialect_mysqlconnector._compat_fetchall       {{}r   c                 "    |j                         S r/   )fetchoner   s      r   _compat_fetchonez,MySQLDialect_mysqlconnector._compat_fetchone   r   r   c                      y)N)SERIALIZABLEzREAD UNCOMMITTEDzREAD COMMITTEDzREPEATABLE READ
AUTOCOMMITr   rP   s     r   get_isolation_level_valuesz6MySQLDialect_mysqlconnector.get_isolation_level_values   s    
r   c                 N    |dk(  rd|_         y d|_         t        | 	  ||       y )Nr   TF)rW   superset_isolation_level)r   r   level	__class__s      r   r   z/MySQLDialect_mysqlconnector.set_isolation_level   s*    L $(J!$)J!G'
E:r   r/   )%r   r   r   driversupports_statement_cachesupports_sane_rowcountsupports_sane_multi_rowcountsupports_native_decimalsupports_native_bitsupports_server_side_cursorsdefault_paramstyler!   statement_compilerr   execution_ctx_clsr:   preparerr   update_copyr   colspecsr   r@   classmethodrM   rR   rv   memoized_propertyr   r   r   r   r   r   r   r   __classcell__)r   s   @r   rF   rF   h   s    F#!#' " $) !5<5Ht 5 5\7JKH 
-^ 
P P- 
; ;r   rF   c                       e Zd ZdZdZeZy)MariaDBDialect_mysqlconnectorTFN)r   r   r   r   _allows_uuid_bindsr>   r   r   r   r   r   r      s      $7Hr   r   )__doc__r   baser   r   r   r   r   r	   mariadbr
    r   r   r!   r+   r:   r>   r@   rF   r   rB   mariadb_dialectr   r   r   <module>r      s   @ 
  +   ' ) # <+@ <
= 
 	+-D		+-F	3 A;, A;H8/8 &/r   