o
    Šåga  ã                   @   s�   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 G d
d„ deƒZ	G dd„ deƒZ
G dd„ deƒZG dd„ deƒZeZdS )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/

.. note::

    The MySQL Connector/Python DBAPI has had many issues since its release,
    some of which may remain unresolved, and the mysqlconnector dialect is
    **not tested as part of SQLAlchemy's continuous integration**.
    The recommended MySQL dialects are mysqlclient and PyMySQL.

é    Né   )ÚBIT)ÚMySQLCompiler)ÚMySQLDialect)ÚMySQLIdentifierPrepareré   )Úutilc                   @   ó   e Zd Zdd„ ZdS )ÚMySQLCompiler_mysqlconnectorc                 K   s,   | j |jfi |¤Žd | j |jfi |¤Ž S )Nz % )ÚprocessÚleftÚright)ÚselfÚbinaryÚoperatorÚkw© r   úd/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/dialects/mysql/mysqlconnector.pyÚvisit_mod_binary$   s   ÿþÿz-MySQLCompiler_mysqlconnector.visit_mod_binaryN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r
   #   ó    r
   c                   @   s.   e Zd Zedd„ ƒZejdd„ ƒZdd„ ZdS )Ú&MySQLIdentifierPreparer_mysqlconnectorc                 C   ó   dS )NFr   )r   r   r   r   Ú_double_percents-   ó   z7MySQLIdentifierPreparer_mysqlconnector._double_percentsc                 C   s   d S ©Nr   ©r   Úvaluer   r   r   r   1   r   c                 C   s   |  | j| j¡}|S r   )ÚreplaceÚescape_quoteÚescape_to_quoter   r   r   r   Ú_escape_identifier5   s   z9MySQLIdentifierPreparer_mysqlconnector._escape_identifierN)r   r   r   Úpropertyr   Úsetterr#   r   r   r   r   r   ,   s    

r   c                   @   r	   )Ú_myconnpyBITc                 C   r   )z0MySQL-connector already converts mysql bits, so.Nr   )r   ÚdialectÚcoltyper   r   r   Úresult_processor;   s   z_myconnpyBIT.result_processorN)r   r   r   r)   r   r   r   r   r&   :   r   r&   c                       s¬   e Zd ZdZdZdZdZdZdZe	Z
eZe ejeei¡Zedd„ ƒZdd„ Zdd	„ Zejd
d„ ƒZdd„ Zdd„ Zdd„ Zddd„Zddd„Zh d£Z‡ fdd„Z‡  Z S )ÚMySQLDialect_mysqlconnectorÚmysqlconnectorTÚformatc                 C   s   ddl m} |S )Nr   )Ú	connector)Úmysqlr-   )Úclsr-   r   r   r   Úimport_dbapiQ   s   z(MySQLDialect_mysqlconnector.import_dbapic                 C   s   |  d¡ dS )NFT)Úping)r   Údbapi_connectionr   r   r   Údo_pingW   s   
z#MySQLDialect_mysqlconnector.do_pingc                 C   sv  |j dd�}| |j¡ t |dt¡ t |dt¡ t |dt¡ t |dt¡ t |dt¡ t |dt¡ t |d	t¡ t |d
t¡ t |dt¡ t |dt¡ t |dt¡ t |dt¡ t |dt¡ t |dt¡ t |dt¡ t |dt¡ t |dt¡ | dd¡ | jd ur·zddl	m
} | d| ¡ ¡}||jO }||d< W g |gS  ty¶   Y g |gS w g |gS )NÚuser)ÚusernameÚallow_local_infileÚ
autocommitÚbufferedÚ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Ú
setdefaultÚdbapiÚmysql.connector.constantsrG   ÚgetÚget_defaultÚ
FOUND_ROWSÚ	Exception)r   ÚurlÚoptsrG   rH   r   r   r   Úcreate_connect_args[   sD   
ÿ

þþz/MySQLDialect_mysqlconnector.create_connect_argsc                 C   sN   | j r!t| j dƒr#t d| j j¡}|r%tdd„ | ddd¡D ƒƒS d S d S d S )NÚ__version__z(\d+)\.(\d+)(?:\.(\d+))?c                 s   s    � | ]}|d urt |ƒV  qd S r   )rN   )Ú.0Úxr   r   r   Ú	<genexpr>Š   s   € zKMySQLDialect_mysqlconnector._mysqlconnector_version_info.<locals>.<genexpr>r   é   r   )rP   ÚhasattrÚreÚmatchrY   ÚtupleÚgroup)r   Úmr   r   r   Ú_mysqlconnector_version_info…   s   ýz8MySQLDialect_mysqlconnector._mysqlconnector_version_infoc                 C   s   |j jS r   )Ú
connectionÚcharset)r   re   r   r   r   Ú_detect_charsetŒ   ó   z+MySQLDialect_mysqlconnector._detect_charsetc                 C   s   |j S r   )Úerrno)r   Ú	exceptionr   r   r   Ú_extract_error_code�   s   z/MySQLDialect_mysqlconnector._extract_error_codec                 C   sD   d}| j j| j jf}t||ƒr |j|v pdt|ƒv pdt|ƒv S dS )N)iÖ  iÝ  iÞ  iý  i  i   zMySQL Connection not available.z$Connection to MySQL is not availableF)rP   ÚOperationalErrorÚInterfaceErrorÚ
isinstanceri   Ústr)r   Úere   ÚcursorÚerrnosÚ
exceptionsr   r   r   Úis_disconnect’   s   


ÿ
ýz)MySQLDialect_mysqlconnector.is_disconnectNc                 C   ó   |  ¡ S r   )Úfetchall©r   Úrprf   r   r   r   Ú_compat_fetchallž   rh   z,MySQLDialect_mysqlconnector._compat_fetchallc                 C   ru   r   )Úfetchonerw   r   r   r   Ú_compat_fetchone¡   rh   z,MySQLDialect_mysqlconnector._compat_fetchone>   úREAD COMMITTEDúREPEATABLE READúREAD UNCOMMITTEDÚ
AUTOCOMMITÚSERIALIZABLEc                    s*   |dkr	d|_ d S d|_ tƒ  ||¡ d S )Nr   TF)r7   ÚsuperÚ_set_isolation_level)r   re   Úlevel©Ú	__class__r   r   r‚   ¬   s   
z0MySQLDialect_mysqlconnector._set_isolation_levelr   )!r   r   r   ÚdriverÚsupports_statement_cacheÚsupports_sane_rowcountÚsupports_sane_multi_rowcountÚsupports_native_decimalÚdefault_paramstyler
   Ústatement_compilerr   Úpreparerr   Úupdate_copyr   Úcolspecsr   r&   Úclassmethodr0   r3   rX   Úmemoized_propertyrd   rg   rk   rt   ry   r{   Ú_isolation_lookupr‚   Ú__classcell__r   r   r„   r   r*   A   s.    
*


r*   )Ú__doc__r_   Úbaser   r   r   r   Ú r   r
   r   r&   r*   r'   r   r   r   r   Ú<module>   s   		s