
    +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
Z	 G d de      Z
 G d de      Z G d de      ZeZy)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                   (    e Zd ZdZd Zd Zd Zd Zy)&MySQLExecutionContext_mariadbconnectorNc                 :    | j                   j                  d      S )NFbuffered_dbapi_connectioncursorselfs    ]/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/dialects/mysql/mariadbconnector.pycreate_server_side_cursorz@MySQLExecutionContext_mariadbconnector.create_server_side_cursor,   s    %%,,e,<<    c                 :    | j                   j                  d      S )NTr   r   r   s    r   create_default_cursorz<MySQLExecutionContext_mariadbconnector.create_default_cursor/   s    %%,,d,;;r   c                     | j                   r3| j                  j                  r| j                  j                  | _        y y y N)isinsertcompiledpostfetch_lastrowidr   	lastrowid
_lastrowidr   s    r   	post_execz0MySQLExecutionContext_mariadbconnector.post_exec2   s-    ==T]]>>"kk33DO ?=r   c                     | j                   S r   )r   r   s    r   get_lastrowidz4MySQLExecutionContext_mariadbconnector.get_lastrowid6   s    r   )__name__
__module____qualname__r   r   r   r    r"    r   r   r   r   )   s    J=<4r   r   c                       e Zd Zy)MySQLCompiler_mariadbconnectorN)r#   r$   r%   r&   r   r   r(   r(   :   s    r   r(   c                        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        Z fdZed        Z fdZd	 Zd
 Zd Z eg d      Z fdZd Zd Z	 ddZ 	 ddZ! xZ"S )MySQLDialect_mariadbconnectormariadbconnectorTutf8mb4qmarkc                     | j                   r`t        | j                   d      rJt        t        j                  d| j                   j
                        D cg c]  }t        |       c}      S yc c}w )N__version__z(\d+)(?:[-\.]?|$))c   r0   r0   )dbapihasattrtuplerefindallr/   int)r   xs     r   _dbapi_versionz,MySQLDialect_mariadbconnector._dbapi_versionX   sa    ::'$**m<  ZZ,djj.D.D F   s   A.c                     t        t        | 
  di | d| _        | j                  <| j
                  t        k  r(t        ddj                  d t        D              z        y y )Nr-   z?The minimum required version for MariaDB Connector/Python is %s.c              3   2   K   | ]  }t        |        y wr   )str).0r7   s     r   	<genexpr>z9MySQLDialect_mariadbconnector.__init__.<locals>.<genexpr>n   s     K!s1vKs   r&   )	superr*   __init__
paramstyler1   r8   mariadb_cpy_minimum_versionNotImplementedErrorjoin)r   kwargs	__class__s     r   r@   z&MySQLDialect_mariadbconnector.__init__f   sl    +T;EfE!::!""%@@)-hhK/JKKL  A "r   c                     t        d      S )Nmariadb)
__import__)clss    r   r1   z#MySQLDialect_mariadbconnector.dbapiq   s    )$$r   c                     t         t        |   |||      ryt        || j                  j
                        r#t        |      j                         }d|v xs d|v S y)NTznot connectedzisn't validF)r?   r*   is_disconnect
isinstancer1   Errorr<   lower)r   e
connectionr   str_erF   s        r   rL   z+MySQLDialect_mariadbconnector.is_disconnectu   sZ    .Cz6
 4::++,FLLNE"e+E}/EEr   c                    |j                         }g d}g d}|D ]  }t        j                  ||t                |D ]  }t        j                  ||t                |j                  dd      }| j                  K	 t        | j                  j                  dz         j                  j                  }||j                  z  }||d<   g |gS # t        t        f$ r
 d| _        Y !w xY w)N)connect_timeoutread_timeoutwrite_timeoutclient_flagport	pool_size)local_infilessl_verify_certsslpool_reset_connectionrW   r   z.constants.CLIENTF)translate_connect_argsr	   coerce_kw_typer6   boolgetr1   rI   r#   	constantsCLIENT
FOUND_ROWSAttributeErrorImportErrorsupports_sane_rowcount)r   urlopts
int_paramsbool_paramskeyrW   CLIENT_FLAGSs           r   create_connect_argsz1MySQLDialect_mariadbconnector.create_connect_args   s    ))+


  	0Cc3/	0 	1Cc40	1
 hh}a0::!4)JJ''*== )FF  |666 #.DDz #K0 4.3+4s   <AC
 
C#"C#c                 4    	 |j                   }|S #  d}Y |S xY w)N)errno)r   	exceptionrcs      r   _extract_error_codez1MySQLDialect_mariadbconnector._extract_error_code   s(    	B 		B	s    c                      y)Nr,   r&   )r   rQ   s     r   _detect_charsetz-MySQLDialect_mariadbconnector._detect_charset   s    r   )SERIALIZABLEzREAD UNCOMMITTEDzREAD COMMITTEDzREPEATABLE READ
AUTOCOMMITc                 V    |dk(  rd|_         y d|_         t        t        |   ||       y )Nrx   TF)
autocommitr?   r*   _set_isolation_level)r   rQ   levelrF   s      r   r{   z2MySQLDialect_mariadbconnector._set_isolation_level   s0    L $(J!$)J!/KEr   c           	          |j                  t        j                  d      j                  t        j                  d|d                   y )NzXA BEGIN :xidxidTliteral_executeexecuter   text
bindparams	bindparamr   rQ   r~   s      r   do_begin_twophasez/MySQLDialect_mariadbconnector.do_begin_twophase   s7    HH_%00eS$?	
r   c           	      (   |j                  t        j                  d      j                  t        j                  d|d                   |j                  t        j                  d      j                  t        j                  d|d                   y )NXA END :xidr~   Tr   zXA PREPARE :xidr   r   s      r   do_prepare_twophasez1MySQLDialect_mariadbconnector.do_prepare_twophase   so    HH]#..eS$?	

 	HH&'22eS$?	
r   c           	      ,   |sI|j                  t        j                  d      j                  t        j                  d|d                   |j                  t        j                  d      j                  t        j                  d|d                   y )Nr   r~   Tr   zXA ROLLBACK :xidr   r   rQ   r~   is_preparedrecovers        r   do_rollback_twophasez2MySQLDialect_mariadbconnector.do_rollback_twophase   st     '22MM%dC
 	HH'(33eS$?	
r   c           	          |s| j                  ||       |j                  t        j                  d      j	                  t        j
                  d|d                   y )NzXA COMMIT :xidr~   Tr   )r   r   r   r   r   r   r   s        r   do_commit_twophasez0MySQLDialect_mariadbconnector.do_commit_twophase   sM     $$Z5HH%&11eS$?	
r   )TF)#r#   r$   r%   driversupports_statement_cachesupports_unicode_statementsencodingconvert_unicoderg   supports_sane_multi_rowcountsupports_native_decimaldefault_paramstyler   execution_ctx_clsr(   statement_compilersupports_server_side_cursorsr	   memoized_propertyr8   r@   classmethodr1   rL   rn   rt   rv   set_isolation_lookupr{   r   r   r   r   __classcell__)rF   s   @r   r*   r*   >   s    F# #'HO!#' " >7#' 	   	 % %	#J 	



 :?
  :?	
r   r*   )__doc__r4   baser   r   r    r   r	   rB   r   r(   r*   dialectr&   r   r   <module>r      sS   , 
   '  ' -B "	] 	o
L o
d (r   