o
    Rc{                     @   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 d
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+mariadbconnector
    :name: MariaDB Connector/Python
    :dbapi: mariadb
    :connectstring: mariadb+mariadbconnector://<user>:<password>@<host>[:<port>]/<dbname>
    :url: https://pypi.org/project/mariadb/

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

MariaDB Connector/Python enables Python programs to access MariaDB and MySQL
databases using an API which is compliant with the Python DB API 2.0 (PEP-249).
It is written in C and uses MariaDB Connector/C client library for client server
communication.

Note that the default driver for a ``mariadb://`` connection URI continues to
be ``mysqldb``. ``mariadb+mariadbconnector://`` is required to use this driver.

.. mariadb: https://github.com/mariadb-corporation/mariadb-connector-python

    N   )MySQLCompiler)MySQLDialect)MySQLExecutionContext   )sql)util)r   r   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 ZdS )
&MySQLExecutionContext_mariadbconnectorNc                 C      | j jddS )NFbufferedZ_dbapi_connectioncursorself r   LD:\Flask\env\Lib\site-packages\sqlalchemy/dialects/mysql/mariadbconnector.pycreate_server_side_cursor,      z@MySQLExecutionContext_mariadbconnector.create_server_side_cursorc                 C   r
   )NTr   r   r   r   r   r   create_default_cursor/   r   z<MySQLExecutionContext_mariadbconnector.create_default_cursorc                 C   s$   | j r| jjr| jj| _d S d S d S N)ZisinsertcompiledZpostfetch_lastrowidr   Z	lastrowid
_lastrowidr   r   r   r   	post_exec2   s   z0MySQLExecutionContext_mariadbconnector.post_execc                 C   s   | j S r   )r   r   r   r   r   get_lastrowid6   s   z4MySQLExecutionContext_mariadbconnector.get_lastrowid)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r	   )   s    r	   c                   @   s   e Zd ZdS )MySQLCompiler_mariadbconnectorN)r   r   r   r   r   r   r   r   :   s    r   c                       s   e Zd ZdZdZdZdZdZdZdZ	dZ
dZeZeZdZejdd Z fddZed	d
 Z fddZdd Zdd Zdd Zeg dZ fddZdd Zdd Z	dddZ 	dddZ!  Z"S ) MySQLDialect_mariadbconnectorZmariadbconnectorTutf8mb4qmarkc                 C   s4   | j rt| j drtdd td| j jD S dS )N__version__c                 S   s   g | ]}t |qS r   )int.0xr   r   r   
<listcomp>\   s    z@MySQLDialect_mariadbconnector._dbapi_version.<locals>.<listcomp>z(\d+)(?:[-\.]?|$))c   r(   r(   )dbapihasattrtuplerefindallr"   r   r   r   r   _dbapi_versionX   s   	z,MySQLDialect_mariadbconnector._dbapi_versionc                    sT   t t| jdi | d| _| jd ur&| jtk r(tdddd tD  d S d S )Nr!   z?The minimum required version for MariaDB Connector/Python is %s.c                 s   s    | ]}t |V  qd S r   )strr$   r   r   r   	<genexpr>n   s    z9MySQLDialect_mariadbconnector.__init__.<locals>.<genexpr>r   )	superr   __init__Z
paramstyler)   r.   mariadb_cpy_minimum_versionNotImplementedErrorjoin)r   kwargs	__class__r   r   r3   f   s   

z&MySQLDialect_mariadbconnector.__init__c                 C   s   t dS )NZmariadb)
__import__)clsr   r   r   r)   q   s   z#MySQLDialect_mariadbconnector.dbapic                    sF   t t| |||rdS t|| jjr!t| }d|v p d|v S dS )NTznot connectedzisn't validF)r2   r   is_disconnect
isinstancer)   Errorr0   lower)r   e
connectionr   Zstr_er8   r   r   r<   u   s   
z+MySQLDialect_mariadbconnector.is_disconnectc              	   C   s   |  }g d}g d}|D ]	}t||t q|D ]	}t||t q|dd}| jd urSzt| jjd j	j
}||jO }W n ttfyN   d| _Y nw ||d< g |gS )N)connect_timeoutread_timeoutZwrite_timeoutclient_flagportZ	pool_size)Zlocal_infileZssl_verify_certsslZpool_reset_connectionrD   r   z.constants.CLIENTF)Ztranslate_connect_argsr   Zcoerce_kw_typer#   boolgetr)   r:   r   	constantsZCLIENTZ
FOUND_ROWSAttributeErrorImportErrorsupports_sane_rowcount)r   urloptsZ
int_paramsZbool_paramskeyrD   ZCLIENT_FLAGSr   r   r   create_connect_args   s*   


z1MySQLDialect_mariadbconnector.create_connect_argsc                 C   s   z|j }W |S    d}Y |S )N)errno)r   	exceptionrcr   r   r   _extract_error_code   s   z1MySQLDialect_mariadbconnector._extract_error_codec                 C   s   dS )Nr    r   )r   rA   r   r   r   _detect_charset   s   z-MySQLDialect_mariadbconnector._detect_charset)ZSERIALIZABLEzREAD UNCOMMITTEDzREAD COMMITTEDzREPEATABLE READ
AUTOCOMMITc                    s.   |dkr	d|_ d S d|_ tt| || d S )NrW   TF)Z
autocommitr2   r   _set_isolation_level)r   rA   levelr8   r   r   rX      s   

z2MySQLDialect_mariadbconnector._set_isolation_levelc              	   C   s&   | tdtjd|dd d S )NzXA BEGIN :xidxidTZliteral_executeexecuter   text
bindparams	bindparamr   rA   rZ   r   r   r   do_begin_twophase   s
   
z/MySQLDialect_mariadbconnector.do_begin_twophasec              	   C   sH   | tdtjd|dd | tdtjd|dd d S )NXA END :xidrZ   Tr[   zXA PREPARE :xidr\   ra   r   r   r   do_prepare_twophase   s   

z1MySQLDialect_mariadbconnector.do_prepare_twophaseFc              	   C   sL   |s| tdtjd|dd | tdtjd|dd d S )Nrc   rZ   Tr[   zXA ROLLBACK :xidr\   r   rA   rZ   Zis_preparedZrecoverr   r   r   do_rollback_twophase   s   

z2MySQLDialect_mariadbconnector.do_rollback_twophasec              	   C   s6   |s|  || |tdtjd|dd d S )NzXA COMMIT :xidrZ   Tr[   )rd   r]   r   r^   r_   r`   re   r   r   r   do_commit_twophase   s   
z0MySQLDialect_mariadbconnector.do_commit_twophase)TF)#r   r   r   ZdriverZsupports_statement_cacheZsupports_unicode_statementsencodingZconvert_unicoderL   Zsupports_sane_multi_rowcountZsupports_native_decimalZdefault_paramstyler	   Zexecution_ctx_clsr   Zstatement_compilerZsupports_server_side_cursorsr   Zmemoized_propertyr.   r3   classmethodr)   r<   rP   rU   rV   setZ_isolation_lookuprX   rb   rd   rf   rg   __classcell__r   r   r8   r   r   >   s@    

%
	
r   )__doc__r,   baser   r   r    r   r   r4   r	   r   r   dialectr   r   r   r   <module>   s    3