U
    ¤�©jÊ•  ã                
   @   sÎ  d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZmZmZmZ ddlmZ ddlmZmZ ddlmZmZmZmZmZmZ ddlmZ dd	lmZm Z m!Z!m"Z"m#Z# dd
l$m%Z% ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1 dZ2zTddl3Z3ddl3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA dZ2W n6 eBk
�rŠ ZC zeBdeC› d�ƒeC‚W 5 dZC[CX Y nX ddlDmEZE ddlFmGZG eE�rºddlHmIZImJZJ G dd„ deƒZKdS )z'Connection class using the C Extension.é    N)
ÚAnyÚBinaryIOÚDictÚListÚNoReturnÚOptionalÚSequenceÚTupleÚTypeÚUnioné   )Úversion)ÚCMySQLPrepStmtÚMySQLConnectionAbstract)Ú
ClientFlagÚ	FieldFlagÚ	FieldTypeÚ
ServerFlagÚShutdownTypeÚ-raise_warning_against_deprecated_cursor_class)ÚMySQLConverter)ÚInterfaceErrorÚInternalErrorÚOperationalErrorÚProgrammingErrorÚget_mysql_exception)ÚMySQLProtocol)ÚCextEofPacketTypeÚCextResultTypeÚDescriptionTypeÚParamsSequenceOrDictTypeÚRowTypeÚStatsPacketTypeÚ
StrOrBytes)Úimport_objectÚwarn_ciphersuites_deprecatedÚwarn_tls_version_deprecatedF)ÚMySQLInterfaceError)ÚCMySQLCursorÚCMySQLCursorBufferedÚCMySQLCursorBufferedDictÚCMySQLCursorBufferedNamedTupleÚCMySQLCursorBufferedRawÚCMySQLCursorDictÚCMySQLCursorNamedTupleÚCMySQLCursorPreparedÚCMySQLCursorPreparedDictÚCMySQLCursorPreparedNamedTupleÚCMySQLCursorPreparedRawÚCMySQLCursorRawTz2MySQL Connector/Python C Extension not available (ú))ÚOTEL_ENABLED)Úwith_context_propagation)Úend_spanÚrecord_exception_eventc                       s¦  e Zd ZdZeddœ‡ fdd„Zddœdd„Zddœd	d
„Zee	dœdd„ƒZ
eddœdd„Zd‹eddœdd„Zeedœdd„ƒZejeddœdd„ƒZeedœdd„ƒZejeddœdd„ƒZeedœdd„ƒZddœdd„Zddœdd„ZeZedœd d!„Zedœd"d#„ZdŒee	e	dd'œd(d)„Zedd*œd+d,„Zeee d-œd.d/„Zeee	 dœd0d1„ƒZd�ee	 eeee   ee ee! e"ee ee# f d2œd3d4„Z$dŽeeee   ee ee! e"ee ee# f d5œd6d7„Z%ee dœd8d9„Z&ddœd:d;„Z'ddœd<d=„Z(ddœd>d?„Z)edd@œdAdB„Z*d�ee! e+dCœdDdE„Z,ee# dœdFdG„Z-e.e!dHœdIdJ„Z/e0e!eee1e#e+f  dKœdLdM„ƒZ2e!ddNœdOdP„Z3e!ddNœdQdR„Z4e0d�eee eeee1e#e+f  dSœdTdU„ƒZ5e5Z6d‘ee ee ee ee7e8  ee ee e8dVœdWdX„Z9ee	dœdYdZ„ƒZ:ee	dœd[d\„ƒZ;eedœd]d^„ƒZ<eedœd_d`„ƒZ=eedœdadb„ƒZ>e?e1e@e. eAee.f f dcœddde„ZBddœdfdg„ZCd’eeeee	 eeeee ee ddiœ
djdk„ZDedœdldm„ZEe	ee# dnœdodp„ZFddœdqdr„ZGd“ee	 ddsœdtdu„ZHeIdœdvdw„ZJe	ddxœdydz„ZKeLdœd{d|„ZMeLdœd}d~„ZNeeLdœd€d�„ZOe!e	ePeLd‚œdƒd„„ZQd”edd…œd†d‡„ZRd•eeAeef  eeAeef  ddˆœd‰dŠ„ZS‡  ZTS )–ÚCMySQLConnectionz6Class initiating a MySQL Connection using Connector/C.N)ÚkwargsÚreturnc                    s¶   t stdƒ‚d| _g | _tj tj tj t	j
¡¡ddd¡| _t ¡ dkrntj | j¡sntj d¡rhdnd| _d| _tƒ  ¡  |r²z| jf |Ž W n tk
r°   |  ¡  ‚ Y nX dS )	ZInitializationz0MySQL Connector/Python C Extension not availableNZmysqlÚvendorZpluginÚLinuxz/usr/lib64/mysql/pluginz/usr/lib/mysql/plugin)ÚHAVE_CMYSQLÚRuntimeErrorÚ_cmysqlÚ_columnsÚosÚpathÚjoinÚdirnameÚabspathÚ_mysql_connectorÚ__file__Ú_plugin_dirÚplatformÚsystemÚexistsÚ	converterÚsuperÚ__init__ÚconnectÚ	ExceptionÚclose)Úselfr:   ©Ú	__class__© úC/tmp/pip-unpacked-wheel-d6bt0v6z/mysql/connector/connection_cext.pyrO   {   s2    þü
ÿý
zCMySQLConnection.__init__)r;   c              
   C   sZ   t j d¡}|d dkrd}nd}| j d|d dd	„ t jdd
… D ƒ¡t ¡ dœ¡ dS )z!Add default connection attributesú r   ZGPLv2zGPL-2.0Z
Commercialzmysql-connector-pythonÚ.c                 S   s   g | ]}t |ƒ‘qS rV   )Ústr)Ú.0ÚxrV   rV   rW   Ú
<listcomp>¨   s     z<CMySQLConnection._add_default_conn_attrs.<locals>.<listcomp>é   )Z_connector_nameZ_connector_licenseZ_connector_versionZ_source_hostN)	r   ÚLICENSEÚsplitÚ_conn_attrsÚupdaterD   ÚVERSIONÚsocketÚgethostname)rS   Zlicense_chunksZclient_licenserV   rV   rW   Ú_add_default_conn_attrsœ   s    üÿz(CMySQLConnection._add_default_conn_attrsc              	   C   sT   | j  ¡ | j  ¡ | j  ¡ dddd| j  ¡ dœ| _|  | jd ¡| _| j 	| j¡ dS )z<Gather information of the MySQL server before authenticationN)ÚprotocolÚserver_version_originalZserver_threadidÚcharsetÚserver_statusÚauth_pluginZ	auth_dataZcapabilitiesrh   )
r@   Zget_proto_infoZget_server_infoÚ	thread_idZst_server_capabilitiesZ
_handshakeZ_check_server_versionZ_server_versionÚ_character_setZset_mysql_version©rS   rV   rV   rW   Ú_do_handshake­   s    øÿzCMySQLConnection._do_handshakec                 C   s
   | j  ¡ S )z6Returns the server status attribute of MYSQL structure)r@   Zst_server_statusrn   rV   rV   rW   Ú_server_status¿   s    zCMySQLConnection._server_status)rC   r;   c                 C   s   | j r| j  |¡ dS )zJset local_infile_in_path

        Set allow_local_infile_in_path.
        N)r@   Z!set_load_data_local_infile_option)rS   rC   rV   rV   rW   Úset_allow_local_infile_in_pathÄ   s    z/CMySQLConnection.set_allow_local_infile_in_pathT)Úvaluer;   c                 C   s.   || _ | jr| j |¡ | jr*| j |¡ dS )zuToggle unicode mode

        Set whether we return string fields as unicode or not.
        Default is True.
        N)Ú_use_unicoder@   Úuse_unicoderM   Úset_unicode©rS   rr   rV   rV   rW   ru   Í   s
    zCMySQLConnection.set_unicodec                 C   s   |   d¡d }|dkS )z#Get whether autocommit is on or offzSELECT @@session.autocommitr   r   ©Ú
info_queryrv   rV   rV   rW   Ú
autocommitÙ   s    zCMySQLConnection.autocommitc              
   C   sT   z| j  |¡ || _W n8 tk
rN } zt|j|j|jd�|‚W 5 d}~X Y nX dS )zToggle autocommit©ÚmsgÚerrnoÚsqlstateN)r@   ry   Z_autocommitr'   r   r{   r|   r}   ©rS   rr   ÚerrrV   rV   rW   ry   ß   s    
  ÿþc                 C   s   |   d¡d S )zGet the current databasezSELECT DATABASE()r   rw   rn   rV   rV   rW   Údatabaseê   s    zCMySQLConnection.databasec              
   C   sN   z| j  |¡ W n8 tk
rH } zt|j|j|jd�|‚W 5 d}~X Y nX dS )zSet the current databaserz   N©r@   Z	select_dbr'   r   r{   r|   r}   r~   rV   rV   rW   r€   ï   s      ÿþc                 C   s   t | jtj@ ƒS )z'MySQL session has started a transaction)Úboolrp   r   ZSTATUS_IN_TRANSrn   rV   rV   rW   Úin_transactionù   s    zCMySQLConnection.in_transactionc           	      C   s€  | j  | j¡d }tj| j| j|| jp(d| j| j	| j
d�| _|  tj¡sNi | _| j| j| j| j| j| j| j| j| j| j| jd| j| j| j| j| jt| j t!ƒr¦t"| j ƒn| j dœ}| j# $d¡}|d k	rÚ|j%dd� d &|¡}| j# $d¡d k	�r| j# $d¡d }| j# $d¡d	 }nd }d }|d k	�r4d
|k�r4|�s4d}| j'�s�| (| j# $d¡| j# $d¡| j# $d¡|||| j# $d¡�ptd| j# $d¡�p„d| j'dœ	¡ t)j*dk�r°| j+dk�r°d|d< z.| jj,f |Ž | j-| j_.| j/�rÜ| j-| j/_0W n: t1k
�r } zt2|j3|j4|j5d�|‚W 5 d }~X Y nX |  6¡  | j'�s|t7| jdƒ�r|t8| jj9ƒ�r|| j 9¡ }t:| j# $dg ¡ƒD ]}t;|ƒ t<||ƒ �qbd S )Nr   )ÚbufferedÚrawÚcharset_nameZconnection_timeoutrt   rk   Z
plugin_dirT)ÚhostÚuserÚpasswordÚ	password1Ú	password2Ú	password3r€   ÚportZclient_flagsZunix_socketÚcompressÚssl_disabledZ
conn_attrsZlocal_infileZload_data_local_dirÚoci_config_fileÚoci_config_profileZwebauthn_callbackÚtls_versions)Úreverseú,Útls_ciphersuitesr   zTLSv1.3ZTLS_AES_256_GCM_SHA384ÚcaÚcertÚkeyZverify_certFZverify_identity)	Zssl_caZssl_certZssl_keyZssl_cipher_suitesr’   Ztls_cipher_suitesZssl_verify_certZssl_verify_identityr�   ÚntZMySQLKerberosAuthPluginZuse_kerberos_gssapirz   Úget_ssl_cipher)=rm   Úget_infoÚ_charset_idrG   ZMySQLÚ	_bufferedÚ_rawZ_connection_timeoutrs   Z_auth_pluginrI   r@   Zisset_client_flagr   ZCONNECT_ARGSra   Ú_hostÚ_userÚ	_passwordÚ
_password1Ú
_password2Ú
_password3Ú	_databaseÚ_portZ_client_flagsÚ_unix_socketZ	_compressZ_allow_local_infileZ_allow_local_infile_in_pathÚ_oci_config_fileÚ_oci_config_profileÚ
isinstanceZ_webauthn_callbackrZ   r$   Ú_sslÚgetÚsortrD   Z_ssl_disabledrb   rB   ÚnameZ_auth_plugin_classrP   Ú_converter_str_fallbackÚconverter_str_fallbackrM   Zstr_fallbackr'   r   r{   r|   r}   ro   ÚhasattrÚcallablerš   Úsetr&   r%   )	rS   r†   Z
cnx_kwargsr’   Zssl_ciphersuitesr•   r   ÚcipherZtls_versionrV   rV   rW   Ú_open_connectionþ   s¸    ù

ÿë

ÿ
ÿÿþý


÷ÿ
  ÿþÿ
þ
ý	
z!CMySQLConnection._open_connectionc              
   C   s¨   | j r$| j  ¡ r$t| j t ¡ d ƒ | js.dS zdz|  ¡  | j 	¡  W nH t
k
rŽ } z*trht| j |ƒ t|j|j|jd�|‚W 5 d}~X Y nX W 5 tr¢t| j ƒ X dS )z Disconnect from the MySQL serverr   Nrz   )Z_spanZis_recordingr8   ÚsysÚexc_infor@   r5   r7   Úfree_resultrR   r'   r   r{   r|   r}   )rS   r   rV   rV   rW   rR   g  s&      ÿþzCMySQLConnection.closec                 C   s   | j  ¡  S )z8Return True if the connection to MySQL Server is closed.)r@   Ú	connectedrn   rV   rV   rW   Ú	is_closed  s    zCMySQLConnection.is_closedc                 C   s   | j r|  ¡  | j  ¡ S dS )z;Reports whether the connection to MySQL Server is availableF)r@   Úhandle_unread_resultÚpingrn   rV   rV   rW   Úis_connectedƒ  s    
zCMySQLConnection.is_connectedFr   r   )Ú	reconnectÚattemptsÚdelayr;   c                 C   sT   |   ¡  z| j ¡ }W n tk
r*   Y n
X |r4dS |rH| j||d� ntdƒ‚dS )aî  Check availability of the MySQL server

        When reconnect is set to True, one or more attempts are made to try
        to reconnect to the MySQL server using the reconnect()-method.

        delay is the number of seconds to wait between each retry.

        When the connection is not available, an InterfaceError is raised. Use
        the is_connected()-method if you just want to check the connection
        without raising an error.

        Raises InterfaceError on errors.
        N)r¿   rÀ   z$Connection to MySQL is not available)r»   r@   r¼   ÚAttributeErrorr¾   r   )rS   r¾   r¿   rÀ   r¹   rV   rV   rW   r¼   ‹  s    zCMySQLConnection.ping)ri   r;   c                 C   s   | j  |¡ dS )z;Sets the default character set name for current connection.N)r@   Zset_character_set)rS   ri   rV   rV   rW   Úset_character_set_name¨  s    z'CMySQLConnection.set_character_set_name)Úqueryr;   c              
   C   sŠ   d}zH| j  |¡ | j jr@| j  ¡ }| j  ¡ r@| j  ¡  tdƒ‚| j  ¡  W n8 tk
r„ } zt|j|j	|j
d�|‚W 5 d}~X Y nX |S )z%Send a query which only returns 1 rowrV   z'Query should not return more than 1 rowrz   N)r@   rÃ   Úhave_result_setÚ	fetch_rowr¸   r   r'   r   r{   r|   r}   )rS   rÃ   Z	first_rowr   rV   rV   rW   rx   ¬  s$    


  ÿþzCMySQLConnection.info_queryc                 C   s&   z| j  ¡ W S  tk
r    Y nX dS )zMySQL connection IDN)r@   rl   r'   rn   rV   rV   rW   Úconnection_id¾  s
    zCMySQLConnection.connection_id)ÚcountÚbinaryÚcolumnsr…   Ú	prep_stmtr;   c              
   C   sä  |r
|j n| j}| jr|s"tdƒ‚|dkr0| j}g }|dk	rL|dkrLtdƒ‚d}�z*|r^|jn| jj}	| jrx| j d¡ |	ƒ }
|
�rBt	|
ƒ}
| j ¡ sÎ|sÎt
| jƒD ](\}}|d tjkr¤t |
| ¡|
|< q¤| j�s| j�rt
|
ƒD ](\}}|sæ| j | j| |
| ¡|
|< qæ| t|
ƒ¡ |d7 }|�r:||k�r:�qB|	ƒ }
q~|
�sv|  |¡d }|�rl| ¡  d| _n|  ¡  nd}W n^ tk
�rÚ } z>|�r¬| ¡  tt|ƒƒ|‚|  ¡  t|j|j|jd	�|‚W 5 d}~X Y nX ||fS )
z8Get all or a subset of rows returned by the MySQL serverzNo result set availableNr   z$count should be 1 or higher, or NoneTr   ÚeofFrz   )rÄ   Úunread_resultr@   r   rž   rÁ   rÅ   rM   r…   ÚlistÚ	enumeraterA   r   ZVECTORr   Z_vector_to_pythonZ	to_pythonÚappendÚtupleÚfetch_eof_columnsr¸   Ú_unread_resultr'   r   rZ   r   r{   r|   r}   )rS   rÇ   rÈ   rÉ   r…   rÊ   rÌ   ÚrowsÚcounterrÅ   ÚrowÚiZdscÚ_Ú_eofr   rV   rV   rW   Úget_rowsÈ  sf    	

ÿ
  ÿþzCMySQLConnection.get_rows)rÈ   rÉ   r…   rÊ   r;   c                 C   sP   z4| j d||||d�\}}|r,|d |fW S d|fW S  tk
rJ   Y dS X dS )z.Get the next rows returned by the MySQL serverr   )rÇ   rÈ   rÉ   r…   rÊ   r   N)NN)rÙ   Ú
IndexError)rS   rÈ   rÉ   r…   rÊ   rÓ   rË   rV   rV   rW   Úget_row  s    û

zCMySQLConnection.get_rowc                 C   s   | j r| j  ¡  | j  ¡ S dS )zReads the next resultN)r@   Úconsume_resultÚnext_resultrn   rV   rV   rW   rÝ   0  s    

zCMySQLConnection.next_resultc                 C   s   | j r| j  ¡  dS )zFrees the resultN)r@   r¸   rn   rV   rV   rW   r¸   7  s    zCMySQLConnection.free_resultc                 C   s   | j r|  ¡  | j  ¡  dS )zCommit current transactionN)r@   r»   Úcommitrn   rV   rV   rW   rÞ   <  s    zCMySQLConnection.commitc                 C   s   | j r| j  ¡  | j  ¡  dS )zRollback current transactionN)r@   rÜ   Úrollbackrn   rV   rV   rW   rß   B  s    
zCMySQLConnection.rollback)r€   r;   c              
   C   sN   z| j  |¡ W n8 tk
rH } zt|j|j|jd�|‚W 5 d}~X Y nX dS )zChange the current databaserz   Nr�   )rS   r€   r   rV   rV   rW   Úcmd_init_dbH  s      ÿþzCMySQLConnection.cmd_init_db)rÊ   r;   c                 C   s¨   |r
|j n| jj }|stdƒ‚|r*| ¡ n| j ¡ }g | _|D ]N}| j |d t|d ƒddddt|d ƒ tj@ t|d ƒt|d ƒf	¡ q>| j	| j 
¡ dœ| jdœS )	z Fetch EOF and column informationúNo result seté   é   Né	   é   )Zstatus_flagÚwarning_count)rË   rÉ   )rÄ   r@   r   Zfetch_fieldsrA   rÏ   Úintr   ZNOT_NULLrp   Úst_warning_count)rS   rÊ   rÄ   ÚfieldsÚcolrV   rV   rW   rÑ   Q  s0    ÿ


÷ÿþûz"CMySQLConnection.fetch_eof_columnsc                 C   s4   | j r0| j  ¡ | j  ¡ | j  ¡ | j  ¡ | jdœS dS )z Fetch EOF and status information)ræ   Zfield_countÚ	insert_idÚaffected_rowsrj   N)r@   rè   Zst_field_countrë   rì   rp   rn   rV   rV   rW   Úfetch_eof_statust  s    ûz!CMySQLConnection.fetch_eof_status)Ú	statementr;   c              
   C   sb   | j stdƒ‚z| j  |¡}| j|_t|ƒW S  tk
r\ } ztt|ƒƒ|‚W 5 d}~X Y nX dS )zPrepares the SQL statementúMySQL Connection not availableN)	r@   r   Zstmt_preparer¯   r°   r   r'   r   rZ   )rS   rî   Zstmtr   rV   rV   rW   Úcmd_stmt_prepare�  s    
z!CMySQLConnection.cmd_stmt_prepare)Ústatement_idÚargsr;   c              
   G   sr   z|j |d| jiŽ W n0 tk
rF } ztt|ƒƒ|‚W 5 d}~X Y nX g | _|jsbd| _|  ¡ S d| _|  	|¡S )zExecutes the prepared statementÚquery_attrsNFT)
Zstmt_executeró   r'   r   rZ   rA   rÄ   rÒ   rí   rÑ   )rS   rñ   rò   r   rV   rV   rW   Úcmd_stmt_execute�  s     z!CMySQLConnection.cmd_stmt_execute)rñ   r;   c                 C   s   | j rtdƒ‚| ¡  dS )zCloses the prepared statementúUnread result foundN)rÒ   r   Z
stmt_close©rS   rñ   rV   rV   rW   Úcmd_stmt_close   s    zCMySQLConnection.cmd_stmt_closec                 C   s   | j rtdƒ‚| ¡  dS )zResets the prepared statementrõ   N)rÒ   r   Z
stmt_resetrö   rV   rV   rW   Úcmd_stmt_reset©  s    zCMySQLConnection.cmd_stmt_reset)rÃ   r…   r„   Úraw_as_stringr;   c              
   C   sî   |   ¡  |dkr| j}z0t|tƒs,| d¡}| jj||||| jd� W nˆ tk
r~ } zt	|j
|j|jd�|‚W 5 d}~X Y nR tk
rÎ } z4| jrš| jn| j› d| j› �}td|dfd�|‚W 5 d}~X Y nX g | _| jjsæ|  ¡ S |  ¡ S )	z Send a query to the MySQL serverNzutf-8)r…   r„   rù   ró   )r{   r}   ú:i  zConnection not available.)r|   Úvalues)r»   rž   rª   ÚbytesÚencoder@   rÃ   ró   r'   r   r|   r{   r}   rÁ   r§   rŸ   r¦   r   rA   rÄ   rí   rÑ   )rS   rÃ   r…   r„   rù   r   ÚaddrrV   rV   rW   Ú	cmd_query²  sD    	

û
  ÿþÿ ÿþzCMySQLConnection.cmd_query)r„   r…   ÚpreparedÚcursor_classÚ
dictionaryÚnamed_tupler;   c                    s(  |   |¡ |  ¡ stdƒ‚|dk	r<t|tƒs4tdƒ‚|| ƒS |pD| j}|pN| j}d‰|dkrdˆdO ‰|dkrtˆdO ‰|dkr„ˆdO ‰|dkr”ˆd	O ‰|dkr¤ˆd
O ‰ttt	t
ttttttttdœ}zt|ˆ jd� |ˆ | ƒW S  tk
�r"   d‰ tdd ‡ ‡fdd„tdƒD ƒ¡ ƒd‚Y nX dS )aÇ  Instantiates and returns a cursor using C Extension

        By default, CMySQLCursor is returned. Depending on the options
        while connecting, a buffered and/or raw cursor is instantiated
        instead. Also depending upon the cursor options, rows can be
        returned as dictionary or named tuple.

        Dictionary and namedtuple based cursors are available with buffered
        output but not raw.

        It is possible to also give a custom cursor through the
        cursor_class parameter, but it needs to be a subclass of
        mysql.connector.cursor_cext.CMySQLCursor.

        Raises ProgrammingError when cursor_class is not a subclass of
        CMySQLCursor. Raises ValueError when cursor is not available.

        Returns instance of CMySQLCursor or subclass.

        :param buffered: Return a buffering cursor
        :param raw: Return a raw cursor
        :param prepared: Return a cursor which uses prepared statements
        :param cursor_class: Use a custom cursor class
        :param dictionary: Rows are returned as dictionary
        :param named_tuple: Rows are returned as named tuple
        :return: Subclass of CMySQLCursor
        :rtype: CMySQLCursor or subclass
        úMySQL Connection not available.Nz=Cursor class needs be to subclass of cursor_cext.CMySQLCursorr   Tr   é   râ   rã   é   )r   r   r  r^   râ   é   rã   rä   r  é   é   é   )Zcursor_name)r„   r…   r  r  r   z*Cursor not available with given criteria: z, c                    s$   g | ]}ˆd |> @ dkrˆ | ‘qS )r   r   rV   )r[   rÖ   ©rò   Zcursor_typerV   rW   r]   2  s      z+CMySQLConnection.cursor.<locals>.<listcomp>r  )r»   r½   r   Ú
issubclassr(   r   r�   rž   r)   r3   r,   r-   r*   r.   r+   r/   r2   r0   r1   r   Ú__name__ÚKeyErrorÚ
ValueErrorrD   Úrange)rS   r„   r…   r   r  r  r  ÚtypesrV   r  rW   ÚcursorÝ  sb    %

ÿ

ôÿÿÿýzCMySQLConnection.cursorc                 C   s   | j jstdƒ‚| j  ¡ S )z,Returns number of rows of current result setrá   )r@   rÄ   r   Únum_rowsrn   rV   rV   rW   r  5  s    zCMySQLConnection.num_rowsc                 C   s   | j s
dS | j  ¡ S )zReturns number of warningsr   )r@   ræ   rn   rV   rV   rW   ræ   =  s    zCMySQLConnection.warning_countc                 C   s   | j s
dS | j jS )z"Check if a result set is availableF)r@   rÄ   rn   rV   rV   rW   Úresult_set_availableE  s    z%CMySQLConnection.result_set_availablec                 C   s   | j S )z)Check if there are unread results or rows)r  rn   rV   rV   rW   rÌ   M  s    zCMySQLConnection.unread_resultc                 C   s
   | j  ¡ S )zCheck if there are more results)r@   Úmore_resultsrn   rV   rV   rW   r  R  s    zCMySQLConnection.more_results)Úparamsr;   c                    sÎ   g }t |ttfƒr:ˆ jr,‡ fdd„|D ƒ}qÊˆ jj|Ž }n�t |tƒr®i }ˆ jr†| ¡ D ],\}}ˆ j ˆ j 	ˆ j 
|¡ˆ j¡¡||< qVqÊ| ¡ D ]\}}ˆ j |¡d ||< qŽntdt|ƒj› d|› d�ƒ‚|S )z¬Prepare parameters for statements

        This method is use by cursors to prepared parameters found in the
        list (or tuple) params.

        Returns dict.
        c              	      s,   g | ]$}ˆ j  ˆ j  ˆ j  |¡ˆ j¡¡‘qS rV   )rM   ÚquoteÚescapeÚto_mysqlÚ	_sql_mode)r[   rr   rn   rV   rW   r]   d  s   û
 ÿÿz6CMySQLConnection.prepare_for_mysql.<locals>.<listcomp>r   zCould not process parameters: ú(z)), it must be of type list, tuple or dict)rª   rÍ   rÐ   rM   r@   Zconvert_to_mysqlÚdictÚitemsr  r  r  r  r   Útyper  )rS   r  Úresultr˜   rr   rV   rn   rW   Úprepare_for_mysqlW  s.    

ú	

 ÿÿÿz"CMySQLConnection.prepare_for_mysqlc                 C   s   | j  ¡  dS )zlConsume the current result

        This method consume the result by reading (consuming) all rows.
        N)r@   rÜ   rn   rV   rV   rW   Úconsume_results‚  s    z CMySQLConnection.consume_resultsÚ )
Úusernamer‰   r€   ri   rŠ   r‹   rŒ   r�   r‘   r;   c
              
   C   sš   z| j  ||||||||	¡ W n8 tk
rV }
 zt|
j|
j|
jd�|
‚W 5 d}
~
X Y nX |dk	rˆt|tƒsrt	dƒ‚|dk r‚t	dƒ‚|| _
|| _|  ¡  dS )z!Change the current logged in userrz   Nzcharset must be an integerr   z2charset should be either zero or a postive integer)r@   Zchange_userr'   r   r{   r|   r}   rª   rç   r  rœ   r    Ú_post_connection)rS   r#  r‰   r€   ri   rŠ   r‹   rŒ   r�   r‘   r   rV   rV   rW   Úcmd_change_user‰  s6    ø  ÿþ
z CMySQLConnection.cmd_change_userc                 C   s   | j  ¡ }|r|  ¡  |S )zÖResets the session state without re-authenticating

        Reset command only works on MySQL server 5.7.3 or later.
        The result is True for a successful reset otherwise False.

        Returns bool
        )r@   Zreset_connectionr$  )rS   ÚresrV   rV   rW   Úcmd_reset_connection²  s    
z%CMySQLConnection.cmd_reset_connection)Úoptionsr;   c              
   C   sZ   z|   ¡  | j |¡ W n8 tk
rP } zt|j|j|jd�|‚W 5 d}~X Y nX |  ¡ S )z,Send the Refresh command to the MySQL serverrz   N)	r»   r@   Zrefreshr'   r   r{   r|   r}   rí   )rS   r(  r   rV   rV   rW   Úcmd_refresh¿  s      ÿþzCMySQLConnection.cmd_refreshc                 C   s   |   ¡  dS )z,Close the current connection with the serverN)rR   rn   rV   rV   rW   Úcmd_quitË  s    zCMySQLConnection.cmd_quit)Úshutdown_typer;   c              
   C   s†   | j stdƒ‚|r*t |¡s$tdƒ‚|}ntj}z| j  |¡ W n8 tk
rx } zt|j	|j
|jd�|‚W 5 d}~X Y nX |  ¡  dS )z»Shut down the MySQL Server

        This method sends the SHUTDOWN command to the MySQL server.
        The `shutdown_type` is not used, and it's kept for backward compatibility.
        rï   zInvalid shutdown typerz   N)r@   r   r   r›   r   ZSHUTDOWN_DEFAULTÚshutdownr'   r   r{   r|   r}   rR   )rS   r+  Úlevelr   rV   rV   rW   Úcmd_shutdownÏ  s$    
  ÿþzCMySQLConnection.cmd_shutdownc              
   C   sf   |   ¡  z| j ¡ }tƒ j|dd�W S  ttfk
r` } zt|j|j	|j
d�|‚W 5 d}~X Y nX dS )z'Return statistics from the MySQL serverF)Zwith_headerrz   N)r»   r@   Ústatr   Zparse_statisticsr'   r   r   r{   r|   r}   )rS   r/  r   rV   rV   rW   Úcmd_statisticsç  s    
  ÿþzCMySQLConnection.cmd_statistics)Ú	mysql_pidr;   c                 C   s&   t |tƒstdƒ‚|  d|› �¡ dS )zKill a MySQL processzMySQL PID must be intzKILL N)rª   rç   r  rÿ   )rS   r1  rV   rV   rW   Úcmd_process_killó  s    
z!CMySQLConnection.cmd_process_killc                 C   s   t ‚dS )zSend the DEBUG commandN©ÚNotImplementedErrorrn   rV   rV   rW   Ú	cmd_debugù  s    zCMySQLConnection.cmd_debugc                 C   s   t ‚dS )zSend the PING commandNr3  rn   rV   rV   rW   Úcmd_pingý  s    zCMySQLConnection.cmd_ping)Ú
statementsr;   c                 C   s   t ‚dS )z/Send one or more statements to the MySQL serverNr3  )rS   r7  rV   rV   rW   Úcmd_query_iter  s    zCMySQLConnection.cmd_query_iter)rñ   Úparam_idÚdatar;   c                 C   s   t ‚dS )zSend data for a columnNr3  )rS   rñ   r9  r:  rV   rV   rW   Úcmd_stmt_send_long_data  s    z(CMySQLConnection.cmd_stmt_send_long_data)r   r;   c                 C   s4   |dkr| j n| j}| jr$|  ¡  n|r0tdƒ‚dS )z'Check whether there is an unread resultTrõ   N)rÒ   rÌ   Zcan_consume_resultsr!  r   )rS   r   rÌ   rV   rV   rW   r»     s
    
z%CMySQLConnection.handle_unread_result)Úuser_variablesÚsession_variablesr;   c                 C   sÚ   |   ¡ stdƒ‚|  ¡ sfz0|  | j| j| j| j| j| j	| j
| j| j¡	 W n tk
rd   |  ¡  Y nX |sn|rÖ|  ¡ }|r¢| ¡ D ]\}}| d|› d�|f¡ q‚|rÎ| ¡ D ]\}}| d|› d�|f¡ q®| ¡  dS )aÇ  Clears the current active session

        This method resets the session state, if the MySQL server is 5.7.3
        or later active session will be reset without re-authenticating.
        For other server versions session will be reset by re-authenticating.

        It is possible to provide a sequence of variables and their values to
        be set after clearing the session. This is possible for both user
        defined variables and session variables.
        This method takes two arguments user_variables and session_variables
        which are dictionaries.

        Raises OperationalError if not connected, InternalError if there are
        unread results and InterfaceError on errors.
        r  zSET @`z` = %szSET SESSION `N)r½   r   r'  r%  r    r¡   r¥   rœ   r¢   r£   r¤   r¨   r©   r   r¾   r  r  ÚexecuterR   )rS   r<  r=  Úcurr˜   rr   rV   rV   rW   Úreset_session  s4    ÷zCMySQLConnection.reset_session)T)Fr   r   )NFNNN)FNNN)N)NFF)NNNNNN)	r"  r"  r"  Nr"  r"  r"  NN)N)F)NN)Ur  Ú
__module__Ú__qualname__Ú__doc__r   rO   rf   ro   Úpropertyrç   rp   rZ   rq   r‚   ru   ry   Úsetterr€   rƒ   rµ   rR   Z
disconnectrº   r½   r¼   rÂ   r#   r   r!   rx   rÆ   r   r   r   r	   r   rÙ   rÛ   rÝ   r¸   rÞ   rß   rà   r   rÑ   rí   rü   rð   r6   r   rô   r÷   rø   rÿ   Z_execute_queryr
   r(   r  r  ræ   r  rÌ   r  r    r   r   r   r!  r%  r'  r)  r*  r.  r"   r0  r2  r   r5  r6  r8  r   r;  r»   r@  Ú__classcell__rV   rV   rT   rW   r9   x   s>  !	
	i     ú
ùS    û
ú
 ÿþ# þýý	   ûú(      ù
øXþ+	         öõ)û	
  ýür9   )LrC  rB   rJ   rd   r¶   Útypingr   r   r   r   r   r   r   r	   r
   r   r"  r   Z	abstractsr   r   Ú	constantsr   r   r   r   r   r   Ú
conversionr   Úerrorsr   r   r   r   r   rg   r   r  r   r   r   r    r!   r"   r#   Úutilsr$   r%   r&   r>   rG   r'   Zcursor_cextr(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   ÚImportErrorÚexcZopentelemetry.constantsr5   Z!opentelemetry.context_propagationr6   Zopentelemetry.instrumentationr7   r8   r9   rV   rV   rV   rW   Ú<module>   s<   0 $	8
ÿþ