a
    ’éiÈ¡  ã                
   @   sÐ  d Z ddl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 ddlmZ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% ddl&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2m3Z3 dZ4zDddl5Z5ddl5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? dZ4W n8 e@�yŒ ZA ze@deA› d�ƒeA‚W Y dZA[An
dZA[A0 0 ddlBmCZC ddlDmEZE eC�r¼ddlFmGZGmHZH G dd„ deƒZIdS )z'Connection class using the C Extension.é    N)
ÚAnyÚBinaryIOÚDictÚListÚNoReturnÚOptionalÚSequenceÚTupleÚTypeÚUnioné   )Úversion)Úcmd_refresh_verify_options)ÚCMySQLPrepStmtÚMySQLConnectionAbstract)Ú
ClientFlagÚ	FieldFlagÚ	FieldTypeÚ
ServerFlagÚShutdownType)Ú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ÚCMySQLCursorBufferedRawÚCMySQLCursorDictÚCMySQLCursorPreparedÚCMySQLCursorPreparedDictÚ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ejjeddœdd„ƒZeedœdd„ƒZejeddœdd„ƒZeee	 dœdd„ƒZeje	ddœdd„ƒZe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d0œd1d2„Zeee d3œd4d5„Z eee	 dœd6d7„ƒZ!d’ee	 eee"e#  ee ee$ ee%e"e ee& f d8œd9d:„Z'd“eee"e#  ee ee$ ee%ee ee& f d;œd<d=„Z(ee dœd>d?„Z)ddœd@dA„Z*ddœdBdC„Z+ddœdDdE„Z,eddFœdGdH„Z-d”ee$ e.dIœdJdK„Z/ee& dœdLdM„Z0e1ee$dNœdOdP„Z2e3e$eeee4e&e.f  dQœdRdS„ƒZ5e$eddTœdUdV„Z6e$eddTœdWdX„Z7e3d•eee eeeee4e&e.f  dYœdZd[„ƒZ8e8Z9d–ee ee ee ee:e;  ee ee	 ee	 e;d\œd]d^„Z<ee	dœd_d`„ƒZ=ee	dœdadb„ƒZ>eedœdcdd„ƒZ?eedœdedf„ƒZ@eedœdgdh„ƒZAeBe4eCe1 eDe1e1f f diœdjdk„ZEddœdldm„ZFd—eeeee	 eeeee ee ee ddoœdpdq„ZGedœdrds„ZHeIƒ e	ee& dtœdudv„ƒZJddœdwdx„ZKd˜ee	 ddyœdzd{„ZLeMdœd|d}„ZNe	dd~œdd€„ZOePdœd�d‚„ZQePdœdƒd„„ZReeePd…œd†d‡„ZSe$e	eTeePdˆœd‰dŠ„ZUd™edd‹œdŒd�„ZVdšeeDeef  eeDeef  ddŽœd�d�„ZW‡  ZXS )›Ú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 i |¤Ž W n ty²   |  ¡  ‚ Y n0 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)Úselfr6   ©Ú	__class__© úO/home/Claro/venv/lib/python3.9/site-packages/mysql/connector/connection_cext.pyrK   r   s2    þü
ÿý
zCMySQLConnection.__init__)r7   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 rR   )Ústr)Ú.0ÚxrR   rR   rS   Ú
<listcomp>Ÿ   ó    z<CMySQLConnection._add_default_conn_attrs.<locals>.<listcomp>é   )Z_connector_nameZ_connector_licenseZ_connector_versionZ_source_hostN)	r   ÚLICENSEÚsplitÚ_conn_attrsÚupdater@   ÚVERSIONÚsocketÚgethostname)rO   Zlicense_chunksZclient_licenserR   rR   rS   Ú_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capabilitiesre   )
r<   Zget_proto_infoZget_server_infoÚ	thread_idZst_server_capabilitiesZ
_handshakeZ_check_server_versionZ_server_versionÚ_character_setZset_mysql_version©rO   rR   rR   rS   Ú_do_handshake¤   s    øÿzCMySQLConnection._do_handshakec                 C   s
   | j  ¡ S )z6Returns the server status attribute of MYSQL structure)r<   Zst_server_statusrk   rR   rR   rS   Ú_server_status¶   s    zCMySQLConnection._server_status)r?   r7   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)rO   r?   rR   rR   rS   Úset_allow_local_infile_in_path»   s    z/CMySQLConnection.set_allow_local_infile_in_path)Úvaluer7   c                 C   s.   || _ | jr| j |¡ | jr*| j |¡ d S ©N)Z_use_unicoder<   Úuse_unicoderI   Zset_unicode©rO   ro   rR   rR   rS   rq   Ä   s
    zCMySQLConnection.use_unicodec                 C   s   |   d¡d }|dkS )z#Get whether autocommit is on or offzSELECT @@session.autocommitr   r   ©Ú
info_queryrr   rR   rR   rS   Ú
autocommitÌ   s    zCMySQLConnection.autocommitc              
   C   sn   z| j  |¡ || _W nR tyh } z:t|dƒrFt|j|j|jd�|‚t	t
|ƒƒ|‚W Y d}~n
d}~0 0 dS )zToggle autocommitÚerrno©ÚmsgÚsqlstateN)r<   ru   Z_autocommitr'   Úhasattrr   rv   rx   ry   r   rV   ©rO   ro   ÚerrrR   rR   rS   ru   Ò   s    

ÿþc                 C   s   | j S rp   )Ú_read_timeoutrk   rR   rR   rS   Úread_timeoutß   s    zCMySQLConnection.read_timeout)Útimeoutr7   c                 C   s   t dƒ‚d S )Nz‰
            The use of read_timeout after the connection has been established is unsupported
            in the C-Extension
            ©r   ©rO   r   rR   rR   rS   r~   ã   s    ÿc                 C   s   | j S rp   )Ú_write_timeoutrk   rR   rR   rS   Úwrite_timeoutì   s    zCMySQLConnection.write_timeoutc                 C   s   t dƒ‚d S )NzŠ
            Changes in write_timeout after the connection has been established is unsupported
            in the C-Extension
            r€   r�   rR   rR   rS   rƒ   ð   s    ÿc                 C   s   |   d¡d S )zGet the current databasezSELECT DATABASE()r   rs   rk   rR   rR   rS   Údatabaseù   s    zCMySQLConnection.databasec              
   C   sh   z| j  |¡ W nR tyb } z:t|dƒr@t|j|j|jd�|‚tt	|ƒƒ|‚W Y d}~n
d}~0 0 dS )zSet the current databaserv   rw   N©
r<   Z	select_dbr'   rz   r   rv   rx   ry   r   rV   r{   rR   rR   rS   r„   þ   s    
ÿþc                 C   s   t | jtj@ ƒS )z'MySQL session has started a transaction)Úboolrm   r   ZSTATUS_IN_TRANSrk   rR   rR   rS   Ú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 | j#| j$rº| j$nd| j%rÈ| j%nddœ}| j& 'd¡}|d urú|j(dd� d )|¡}| j& 'd¡d u�r4| j& 'd¡d �p d }| j& 'd¡d	 }nd }d }|d u�rZd
|v �rZ|�sZd}| j*�s¶| +| j& 'd¡| j& 'd¡| j& 'd¡|||| j& 'd¡�pšd| j& 'd¡�pªd| j*dœ	¡ t,j-dk�rÖ| j.dk�rÖd|d< z2| jj/f i |¤Ž | j0| j_1| j2�r| j0| j2_3W nV t4�y^ } z<t5|dƒ�r<t6|j7|j8|j9d�|‚t:t!|ƒƒ|‚W Y d }~n
d }~0 0 |  ;¡  | j*�sÂt5| jdƒ�rÂt<| jj=ƒ�rÂ| j =¡ }t>| j& 'dg ¡ƒD ]}t?|ƒ t@||ƒ �q¨d S )Nr   )ÚbufferedÚrawÚcharset_nameZconnection_timeoutrq   rh   Z
plugin_dirT)ÚhostÚuserÚpasswordÚ	password1Ú	password2Ú	password3r„   ÚportÚclient_flagsZunix_socketÚcompressÚssl_disabledZ
conn_attrsZlocal_infileZload_data_local_dirÚoci_config_fileÚoci_config_profileZwebauthn_callbackÚopenid_token_filer~   rƒ   Ú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_gssapirv   rw   Úget_ssl_cipher)Arj   Úget_infoÚ_charset_idrC   ZMySQLÚ	_bufferedÚ_rawZ_connection_timeoutrq   Z_auth_pluginrE   r<   Zisset_client_flagr   ZCONNECT_ARGSr^   Ú_hostÚ_userÚ	_passwordÚ
_password1Ú
_password2Ú
_password3Ú	_databaseÚ_portr’   Ú_unix_socketZ	_compressZ_allow_local_infileZ_allow_local_infile_in_pathÚ_oci_config_fileÚ_oci_config_profileÚ
isinstanceZ_webauthn_callbackrV   r$   Z_openid_token_filer}   r‚   Ú_sslÚgetÚsortr@   Z_ssl_disabledr_   r>   ÚnameZ_auth_plugin_classrL   Ú_converter_str_fallbackÚconverter_str_fallbackrI   Zstr_fallbackr'   rz   r   rv   rx   ry   r   rl   Úcallabler    Úsetr&   r%   )	rO   rŠ   Z
cnx_kwargsr˜   Zssl_ciphersuitesr›   r|   ÚcipherZtls_versionrR   rR   rS   Ú_open_connection  s¼    ù

ÿç
ÿ
ÿÿþý


÷ÿ
ÿþ$ÿ
þ
ý	
z!CMySQLConnection._open_connectionc              
   C   sÐ   | j r$| j  ¡ r$t| j t ¡ d ƒ | js.d S zŒz|  ¡  | j ¡  W nb ty¨ } zJt	rft| j |ƒ t
|dƒr†t|j|j|jd�|‚tt|ƒƒ|‚W Y d }~n
d }~0 0 W t	rÌt| j ƒ nt	rÊt| j ƒ 0 d S )Nr   rv   rw   )Z_spanZis_recordingr4   ÚsysÚexc_infor<   Úfree_resultrN   r'   r1   rz   r   rv   rx   ry   r   rV   r3   )rO   r|   rR   rR   rS   rN   }  s*    
ÿþ&ÿzCMySQLConnection.closec                 C   s   | j  ¡  S )z8Return True if the connection to MySQL Server is closed.)r<   Ú	connectedrk   rR   rR   rS   Ú	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Úpingrk   rR   rR   rS   Úis_connectedš  s    
zCMySQLConnection.is_connectedFr   r   )Ú	reconnectÚattemptsÚdelayr7   c                 C   sR   |   ¡  z| j ¡ }W n ty(   Y n
0 |r2dS |rF| 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   )rO   rÃ   rÄ   rÅ   r¾   rR   rR   rS   rÁ   ¢  s    zCMySQLConnection.ping)rf   r7   c                 C   s   | j  |¡ dS )z;Sets the default character set name for current connection.N)r<   Zset_character_set)rO   rf   rR   rR   rS   Úset_character_set_name¿  s    z'CMySQLConnection.set_character_set_name)Úqueryr7   c              
   C   s¤   d}zH| j  |¡ | j jr@| j  ¡ }| j  ¡ r@| j  ¡  tdƒ‚| j  ¡  W nR tyž } z:t|dƒr|t|j	|j
|jd�|‚tt|ƒƒ|‚W Y d}~n
d}~0 0 |S )z%Send a query which only returns 1 rowrR   z'Query should not return more than 1 rowrv   rw   N)r<   rÈ   Úhave_result_setÚ	fetch_rowr½   r   r'   rz   r   rv   rx   ry   rV   )rO   rÈ   Z	first_rowr|   rR   rR   rS   rt   Ã  s$    



ÿþ$zCMySQLConnection.info_queryc                 C   s$   z| j  ¡ W S  ty   Y n0 dS )zMySQL connection IDN)r<   ri   r'   rk   rR   rR   rS   Úconnection_id×  s
    zCMySQLConnection.connection_id)ÚcountÚbinaryÚcolumnsr‰   Ú	prep_stmtr6   r7   c              
   K   sø  |r
|j n| j}| jr|s"tdƒ‚|du r0| j}g }|durL|dkrLtdƒ‚d}	�z.|r^|jn| jj}
| jsp|r|| j d¡ |
ƒ }|�rFt	|ƒ}| 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>�qF|
ƒ }q‚|�sz|  |¡d }|�rp| ¡  d| _n|  ¡  nd}W nn t�yî } zT|�r¢| ¡  n|  ¡  t|d	ƒ�rÌt|j|j|jd
�|‚tt|ƒƒ|‚W Y d}~n
d}~0 0 ||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   ÚeofFrv   rw   )rÉ   Úunread_resultr<   r   r¤   rÆ   rÊ   rI   r‰   ÚlistÚ	enumerater=   r   ZVECTORr   Z_vector_to_pythonZ	to_pythonÚappendÚtupleÚfetch_eof_columnsr½   Ú_unread_resultr'   rz   r   rv   rx   ry   r   rV   )rO   rÌ   rÍ   rÎ   r‰   rÏ   r6   rÑ   ÚrowsÚcounterrÊ   ÚrowÚiZdscÚ_Ú_eofr|   rR   rR   rS   Úget_rowsá  sd    



ÿ

ÿþ$zCMySQLConnection.get_rows)rÍ   rÎ   r‰   rÏ   r6   r7   c                 K   sN   z4| j d||||d�\}}|r,|d |fW S d|fW S  tyH   Y dS 0 dS )z.Get the next rows returned by the MySQL serverr   )rÌ   rÍ   rÎ   r‰   rÏ   r   N)NN)rÞ   Ú
IndexError)rO   rÍ   rÎ   r‰   rÏ   r6   rØ   rÐ   rR   rR   rS   Úget_row5  s    	û

zCMySQLConnection.get_rowc                 C   s   | j r| j  ¡  | j  ¡ S dS )zReads the next resultN)r<   Úconsume_resultÚnext_resultrk   rR   rR   rS   râ   M  s    

zCMySQLConnection.next_resultc                 C   s   | j r| j  ¡  dS )zFrees the resultN)r<   r½   rk   rR   rR   rS   r½   T  s    zCMySQLConnection.free_resultc                 C   s   | j r|  ¡  | j  ¡  dS )zCommit current transactionN)r<   rÀ   Úcommitrk   rR   rR   rS   rã   Y  s    zCMySQLConnection.commitc                 C   s   | j r| j  ¡  | j  ¡  dS )zRollback current transactionN)r<   rá   Úrollbackrk   rR   rR   rS   rä   _  s    
zCMySQLConnection.rollback)r„   r7   c              
   C   sh   z| j  |¡ W nR tyb } z:t|dƒr@t|j|j|jd�|‚tt	|ƒƒ|‚W Y d}~n
d}~0 0 dS )zChange the current databaserv   rw   Nr…   )rO   r„   r|   rR   rR   rS   Úcmd_init_dbe  s    
ÿþzCMySQLConnection.cmd_init_db)rÏ   r7   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_fieldsr=   rÔ   Úintr   ZNOT_NULLrm   Úst_warning_count)rO   rÏ   rÉ   ÚfieldsÚcolrR   rR   rS   rÖ   p  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_rowsrg   N)r<   rí   Zst_field_countrð   rñ   rm   rk   rR   rR   rS   Úfetch_eof_status“  s    ûz!CMySQLConnection.fetch_eof_status)Ú	statementr6   r7   c              
   K   s„   | j stdƒ‚z| j  |¡}| j|_t|ƒW S  ty~ } z:t|dƒr\t|j	|j
|jd�|‚tt|ƒƒ|‚W Y d}~n
d}~0 0 dS )zPrepares the SQL statementúMySQL Connection not availablerv   rw   N)r<   r   Zstmt_preparerµ   r¶   r   r'   rz   r   rv   rx   ry   r   rV   )rO   ró   r6   Ústmtr|   rR   rR   rS   Úcmd_stmt_prepare   s    

ÿþz!CMySQLConnection.cmd_stmt_prepare)Ústatement_idÚargsr6   r7   c              
   O   s”   z|j |d| jiŽ W nR tyh } z:t|dƒrFt|j|j|jd�|‚tt	|ƒƒ|‚W Y d}~n
d}~0 0 g | _
|js„d| _|  ¡ S d| _|  |¡S )zExecutes the prepared statementÚquery_attrsrv   rw   NFT)Zstmt_executerù   r'   rz   r   rv   rx   ry   r   rV   r=   rÉ   r×   rò   rÖ   )rO   r÷   rø   r6   r|   rR   rR   rS   Úcmd_stmt_execute´  s     
ÿþ$z!CMySQLConnection.cmd_stmt_execute)r÷   r6   r7   c              
   K   sr   | j rtdƒ‚z| ¡  W nR tyl } z:t|dƒrJt|j|j|jd�|‚t	t
|ƒƒ|‚W Y d}~n
d}~0 0 dS )zCloses the prepared statementúUnread result foundrv   rw   N)r×   r   Z
stmt_closer'   rz   r   rv   rx   ry   r   rV   ©rO   r÷   r6   r|   rR   rR   rS   Úcmd_stmt_closeÎ  s    
ÿþzCMySQLConnection.cmd_stmt_closec              
   K   sr   | j rtdƒ‚z| ¡  W nR tyl } z:t|dƒrJt|j|j|jd�|‚t	t
|ƒƒ|‚W Y d}~n
d}~0 0 dS )zResets the prepared statementrû   rv   rw   N)r×   r   Z
stmt_resetr'   rz   r   rv   rx   ry   r   rV   rü   rR   rR   rS   Úcmd_stmt_resetß  s    
ÿþzCMySQLConnection.cmd_stmt_reset)rÈ   r‰   rˆ   Úraw_as_stringr6   r7   c              
   K   s  |   ¡  |d u r| j}z<t|tƒs,| d¡}|| _d | _| jj||||| j	d� W n¤ t
y¤ } z:t|dƒr‚t|j|j|jd�|‚tt|ƒƒ|‚W Y d }~n\d }~0  työ } z<| jr¾| jn| j› d| j› �}td|dfd�|‚W Y d }~n
d }~0 0 g | _| jj�s|  ¡ S |  ¡ S )	Nzutf-8)r‰   rˆ   rÿ   rù   rv   rw   ú:i  zConnection not available.)rv   Úvalues)rÀ   r¤   r°   ÚbytesÚencodeZ_queryZ_local_infile_filenamesr<   rÈ   rù   r'   rz   r   rv   rx   ry   r   rV   rÆ   r­   r¥   r¬   r   r=   rÉ   rò   rÖ   )rO   rÈ   r‰   rˆ   rÿ   r6   r|   ÚaddrrR   rR   rS   Ú	cmd_queryð  sF    	

û

ÿþ"ÿÿþ
zCMySQLConnection.cmd_query)rˆ   r‰   ÚpreparedÚcursor_classÚ
dictionaryr~   rƒ   r7   c           	   
      s  |   |¡ |  ¡ stdƒ‚|s"|r0tjdtd� |durRt|tƒsJtdƒ‚|| ƒS |pZ| j	}|pd| j
}d‰|du rzˆdO ‰|du rŠˆd	O ‰|du ršˆd
O ‰|du rªˆdO ‰ttttttttdœ}z|ˆ | ƒW S  t�y   d‰ tdd ‡ ‡fdd„td
ƒD ƒ¡ ƒd‚Y n0 dS )ay  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 a dictionary or a tuple.

        Dictionary 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
        :return: Subclass of CMySQLCursor
        :rtype: CMySQLCursor or subclass
        úMySQL Connection not available.zsThe use of read_timeout after the connection has been established is unsupported
                in the C-Extension)ÚcategoryNz=Cursor class needs be to subclass of cursor_cext.CMySQLCursorr   Tr   é   rç   é   )r   r   r  r[   rç   é   r  é   )rˆ   r‰   r  r  z*Cursor not available with given criteria: z, c                    s$   g | ]}ˆd |> @ dkrˆ | ‘qS )r   r   rR   )rW   rÛ   ©rø   Zcursor_typerR   rS   rY   t  rZ   z+CMySQLConnection.cursor.<locals>.<listcomp>)rÀ   rÂ   r   ÚwarningsÚwarnÚWarningÚ
issubclassr(   r   r£   r¤   r)   r/   r+   r,   r*   r-   r.   ÚKeyErrorÚ
ValueErrorr@   Úrange)	rO   rˆ   r‰   r  r  r  r~   rƒ   ÚtypesrR   r  rS   Úcursor"  sZ    %
ý
ÿ

ø
ÿÿý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_rowsrk   rR   rR   rS   r  w  s    zCMySQLConnection.num_rowsc                 C   s   | j s
dS | j  ¡ S )zReturns number of warningsr   )r<   rë   rk   rR   rR   rS   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É   rk   rR   rR   rS   Úresult_set_available‡  s    z%CMySQLConnection.result_set_availablec                 C   s   | j S )z)Check if there are unread results or rows)r  rk   rR   rR   rS   rÑ   �  s    zCMySQLConnection.unread_resultc                 C   s
   | j  ¡ S )zCheck if there are more results)r<   Úmore_resultsrk   rR   rR   rS   r  ”  s    zCMySQLConnection.more_results)Úparamsr7   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 ]0\}}ˆ 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 rR   )rI   ÚquoteÚescapeÚto_mysqlÚ	_sql_mode)rW   ro   rk   rR   rS   rY   ¦  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Õ   rI   r<   Zconvert_to_mysqlÚdictÚitemsr  r  r  r   r  r   ÚtypeÚ__name__)rO   r  Úresultrž   ro   rR   rk   rS   Úprepare_for_mysql™  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á   rk   rR   rR   rS   Úconsume_resultsÄ  s    z CMySQLConnection.consume_resultsÚ )Úusernamer�   r„   rf   rŽ   r�   r�   r•   r–   r—   r7   c                 C   s¶   z | j  ||||||||	|
¡	 W nR tyr } z:t|dƒrPt|j|j|jd�|‚tt	|ƒƒ|‚W Y d}~n
d}~0 0 |dur¤t
|tƒsŽtdƒ‚|dk ržtdƒ‚|| _|| _|  ¡  dS )z!Change the current logged in userrv   rw   Nzcharset must be an integerr   z2charset should be either zero or a postive integer)r<   Zchange_userr'   rz   r   rv   rx   ry   r   rV   r°   rì   r  r¢   r¦   Ú_post_connection)rO   r*  r�   r„   rf   rŽ   r�   r�   r•   r–   r—   r|   rR   rR   rS   Úcmd_change_userË  s8    ÷
ÿþ$
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+  )rO   ÚresrR   rR   rS   Úcmd_reset_connectionø  s    
z%CMySQLConnection.cmd_reset_connection)Úoptionsr7   c              
   C   st   z|   ¡  | j |¡ W nR tyj } z:t|dƒrHt|j|j|jd�|‚t	t
|ƒƒ|‚W Y d }~n
d }~0 0 |  ¡ S )Nrv   rw   )rÀ   r<   Zrefreshr'   rz   r   rv   rx   ry   r   rV   rò   )rO   r/  r|   rR   rR   rS   Úcmd_refresh  s    
ÿþ$zCMySQLConnection.cmd_refreshc                 C   s   |   ¡  dS )z,Close the current connection with the serverN)rN   rk   rR   rR   rS   Úcmd_quit  s    zCMySQLConnection.cmd_quit)Úshutdown_typer7   c              
   C   s    | j stdƒ‚|r*t |¡s$tdƒ‚|}ntj}z| j  |¡ W nR ty’ } z:t|dƒrpt	|j
|j|jd�|‚tt|ƒƒ|‚W Y d}~n
d}~0 0 |  ¡  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 typerv   rw   N)r<   r   r   r¡   r   ZSHUTDOWN_DEFAULTÚshutdownr'   rz   r   rv   rx   ry   rV   rN   )rO   r2  Úlevelr|   rR   rR   rS   Úcmd_shutdown  s$    

ÿþ$zCMySQLConnection.cmd_shutdownc              
   C   s€   |   ¡  z| j ¡ }tƒ j|dd�W S  ttfyz } z:t|dƒrXt|j	|j
|jd�|‚tt|ƒƒ|‚W Y d}~n
d}~0 0 dS )z'Return statistics from the MySQL serverF)Zwith_headerrv   rw   N)rÀ   r<   Ústatr   Zparse_statisticsr'   r   rz   r   rv   rx   ry   rV   )rO   r6  r|   rR   rR   rS   Úcmd_statistics1  s    

ÿþzCMySQLConnection.cmd_statistics)Ú	mysql_pidr7   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  )rO   r8  rR   rR   rS   Úcmd_process_kill?  s    
z!CMySQLConnection.cmd_process_killc                 C   s   t ‚dS )zSend the DEBUG commandN©ÚNotImplementedErrorrk   rR   rR   rS   Ú	cmd_debugE  s    zCMySQLConnection.cmd_debugc                 C   s   t ‚dS )zSend the PING commandNr:  rk   rR   rR   rS   Úcmd_pingI  s    zCMySQLConnection.cmd_ping)Ú
statementsr6   r7   c                 K   s   t ‚dS )z/Send one or more statements to the MySQL serverNr:  )rO   r>  r6   rR   rR   rS   Úcmd_query_iterM  s    zCMySQLConnection.cmd_query_iter)r÷   Úparam_idÚdatar6   r7   c                 K   s   t ‚dS )zSend data for a columnNr:  )rO   r÷   r@  rA  r6   rR   rR   rS   Úcmd_stmt_send_long_dataQ  s    z(CMySQLConnection.cmd_stmt_send_long_data)r  r7   c                 C   s4   |du 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   )rO   r  rÑ   rR   rR   rS   rÀ   [  s
    
z%CMySQLConnection.handle_unread_result)Úuser_variablesÚsession_variablesr7   c                 C   sØ   |   ¡ stdƒ‚|  ¡ sdz0|  | j| j| j| j| j| j	| j
| j| j¡	 W n tyb   |  ¡  Y n0 |sl|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#  ÚexecuterN   )rO   rC  rD  Úcurrž   ro   rR   rR   rS   Úreset_sessionc  s4    ÷zCMySQLConnection.reset_session)Fr   r   )NFNNN)FNNN)N)NFF)NNNNNNN)
r)  r)  r)  Nr)  r)  r)  NNN)N)F)NN)Yr%  Ú
__module__Ú__qualname__Ú__doc__r   rK   rc   rl   Úpropertyrì   rm   rV   rn   r   rq   Úsetterr†   ru   r   r~   rƒ   r„   r‡   rº   rN   Z
disconnectr¿   rÂ   rÁ   rÇ   r#   r!   rt   rË   r   r   r   r	   r   rÞ   rà   râ   r½   rã   rä   rå   r   rÖ   rò   r  rö   r2   r   rú   rý   rþ   r  Z_execute_queryr
   r(   r  r  rë   r  rÑ   r  r    r   r   r'  r(  r,  r.  r   r0  r1  r5  r"   r7  r9  r   r<  r=  r?  r   rB  rÀ   rG  Ú__classcell__rR   rR   rP   rS   r5   o   sn  !	n     ú
øV    û
ù ÿþ#üûüü   ûù/       ø
÷Uþ+	          õô-ú

  ýür5   )JrJ  r>   rF   ra   r»   r  Útypingr   r   r   r   r   r   r   r	   r
   r   r)  r   Z_decoratingr   Z	abstractsr   r   Ú	constantsr   r   r   r   r   Ú
conversionr   Úerrorsr   r   r   r   r   rd   r   r  r   r   r   r    r!   r"   r#   Úutilsr$   r%   r&   r:   rC   r'   Zcursor_cextr(   r)   r*   r+   r,   r-   r.   r/   ÚImportErrorÚexcZopentelemetry.constantsr1   Z!opentelemetry.context_propagationr2   Zopentelemetry.instrumentationr3   r4   r5   rR   rR   rR   rS   Ú<module>   s@   0$	(
ÿþ