o
    "i"                     @   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d
l	mZ ddl
mZ dZG dd dejej 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)UUID   )MySQLCompiler)MySQLDialect)MySQLExecutionContext   )sql)util)sqltypes)r   r   r   c                   @   s   e Zd Zdd ZdS )_MariaDBUUIDc                 C   s   | j r	dd }|S dd }|S )Nc                 S   s(   | d urt | dr| d} t| } | S Ndecodeascii)hasattrr   _python_UUIDvalue r   n/var/www/html/voicebot/backend/venv/lib/python3.10/site-packages/sqlalchemy/dialects/mysql/mariadbconnector.pyprocess5   s
   

z._MariaDBUUID.result_processor.<locals>.processc                 S   s,   | d urt | dr| d} tt| } | S r   )r   r   strr   r   r   r   r   r   ?   s
   

)as_uuid)selfdialectcoltyper   r   r   r   result_processor2   s
   z_MariaDBUUID.result_processorN)__name__
__module____qualname__r   r   r   r   r   r   .   s    r   c                       sD   e Zd ZdZdd Zdd Z fddZedd	 Zd
d Z	  Z
S )&MySQLExecutionContext_mariadbconnectorNc                 C      | j jddS )NFbuffered_dbapi_connectioncursorr   r   r   r   create_server_side_cursorL      z@MySQLExecutionContext_mariadbconnector.create_server_side_cursorc                 C   r    )NTr!   r#   r&   r   r   r   create_default_cursorO   r(   z<MySQLExecutionContext_mariadbconnector.create_default_cursorc                    s8   t    | jj| _| jr| jjr| jj| _	d S d S d S N)
super	post_execr%   rowcount	_rowcountisinsertcompiledpostfetch_lastrowid	lastrowid
_lastrowidr&   	__class__r   r   r,   R   s
   

z0MySQLExecutionContext_mariadbconnector.post_execc                 C   s   | j d ur| j S | jjS r*   )r.   r%   r-   r&   r   r   r   r-   Z   s   
z/MySQLExecutionContext_mariadbconnector.rowcountc                 C   s   | j S r*   )r3   r&   r   r   r   get_lastrowida   s   z4MySQLExecutionContext_mariadbconnector.get_lastrowid)r   r   r   r3   r'   r)   r,   propertyr-   r6   __classcell__r   r   r4   r   r   I   s    
r   c                   @   s   e Zd ZdS )MySQLCompiler_mariadbconnectorN)r   r   r   r   r   r   r   r9   e   s    r9   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ejejei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 dd Z! fddZ"dd Z#dd Z$	d ddZ%	d ddZ&  Z'S )!MySQLDialect_mariadbconnector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   rD   rD   )dbapir   tuplerefindallr>   r&   r   r   r   _dbapi_version   s   	z,MySQLDialect_mariadbconnector._dbapi_versionc                    sP   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*   )r   r@   r   r   r   	<genexpr>   s    z9MySQLDialect_mariadbconnector.__init__.<locals>.<genexpr>r   )r+   __init__
paramstylerE   rI   mariadb_cpy_minimum_versionNotImplementedErrorjoin)r   kwargsr4   r   r   rL      s   

z&MySQLDialect_mariadbconnector.__init__c                 C   s   t dS )Nmariadb)
__import__)clsr   r   r   import_dbapi   s   z*MySQLDialect_mariadbconnector.import_dbapic                    sB   t  |||r
dS t|| jjrt| }d|v pd|v S dS )NTznot connectedzisn't validF)r+   is_disconnect
isinstancerE   Errorr   lower)r   e
connectionr%   str_er4   r   r   rV      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_timeoutwrite_timeoutclient_flagport	pool_size)local_infilessl_verify_certsslpool_reset_connectionr`   r   z.constants.CLIENTF)translate_connect_argsr	   coerce_kw_typer?   boolgetrE   rS   r   	constantsCLIENT
FOUND_ROWSAttributeErrorImportErrorsupports_sane_rowcount)r   urlopts
int_paramsbool_paramskeyr`   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      dS )Nr<   r   )r   r[   r   r   r   _detect_charset      z-MySQLDialect_mariadbconnector._detect_charsetc                 C   r}   )N)SERIALIZABLEzREAD UNCOMMITTEDzREAD COMMITTEDzREPEATABLE READ
AUTOCOMMITr   )r   dbapi_connectionr   r   r   get_isolation_level_values   r   z8MySQLDialect_mariadbconnector.get_isolation_level_valuesc                    s*   |dkr	d|_ d S d|_ t || d S )Nr   TF)
autocommitr+   set_isolation_level)r   r[   levelr4   r   r   r      s   
z1MySQLDialect_mariadbconnector.set_isolation_levelc              	   C   s&   | tdtjd|dd d S )NzXA BEGIN :xidxidTliteral_executeexecuter   text
bindparams	bindparamr   r[   r   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 :xidr   Tr   zXA PREPARE :xidr   r   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 )Nr   r   Tr   zXA ROLLBACK :xidr   r   r[   r   is_prepared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 :xidr   Tr   )r   r   r   r   r   r   r   r   r   r   do_commit_twophase  s   
z0MySQLDialect_mariadbconnector.do_commit_twophase)TF)(r   r   r   driversupports_statement_cachesupports_unicode_statementsencodingconvert_unicoderp   supports_sane_multi_rowcountsupports_native_decimaldefault_paramstyler   execution_ctx_clsr9   statement_compilersupports_server_side_cursorsr	   update_copyr   colspecsr
   Uuidr   memoized_propertyrI   rL   classmethodrU   rV   rw   r|   r~   r   r   r   r   r   r   r8   r   r   r4   r   r:   i   sB    

	%	
r:   )__doc__rG   uuidr   r   baser   r   r    r   r	   r
   rN   _UUID_RETURNr   r   r9   r:   r   r   r   r   r   <module>   s    	 2