a
    lJhȡ                  
   @   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rd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dee	e	dd-d.d/Zedd0d1d2Zeee d3d4d5Z eee	 dd6d7Z!dee	 eee"e#  ee ee$ ee%e"e ee& f d8d9d:Z'de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-de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Z7e3deee eeeee4e&e.f  dYdZd[Z8e8Z9de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ZFde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ZKdee	 ddydzd{ZLeMdd|d}ZNe	dd~ddZOePdddZQePdddZReeePdddZSe$e	eTeePdddZUdeddddZVdeeDeef  eeDeef  dddd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   |rz| jf i | W n ty   |    Y n0 dS )	ZInitializationz0MySQL Connector/Python C Extension not availableNmysqlvendor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__ Q/var/www/shaz/venv/lib/python3.9/site-packages/mysql/connector/connection_cext.pyrM   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 rT   )str).0xrT   rT   rU   
<listcomp>       z<CMySQLConnection._add_default_conn_attrs.<locals>.<listcomp>   )Z_connector_nameZ_connector_licenseZ_connector_versionZ_source_hostN)	r   LICENSEsplit_conn_attrsupdaterB   VERSIONsocketgethostname)rQ   Zlicense_chunksZclient_licenserT   rT   rU   _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capabilitiesrg   )
r>   Zget_proto_infoZget_server_info	thread_idZst_server_capabilitiesZ
_handshakeZ_check_server_versionZ_server_version_character_setZset_mysql_versionrQ   rT   rT   rU   _do_handshake   s    zCMySQLConnection._do_handshakec                 C   s
   | j  S )z6Returns the server status attribute of MYSQL structure)r>   Zst_server_statusrm   rT   rT   rU   _server_status   s    zCMySQLConnection._server_status)rA   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)rQ   rA   rT   rT   rU   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_unicoderK   Zset_unicoderQ   rq   rT   rT   rU   rs      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_queryrt   rT   rT   rU   
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>   rw   Z_autocommitr'   hasattrr   rx   rz   r{   r   rX   rQ   rq   errrT   rT   rU   rw      s    

c                 C   s   | j S rr   )_read_timeoutrm   rT   rT   rU   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   rQ   r   rT   rT   rU   r      s    c                 C   s   | j S rr   )_write_timeoutrm   rT   rT   rU   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   rT   rT   rU   r      s    c                 C   s   |  dd S )zGet the current databasezSELECT DATABASE()r   ru   rm   rT   rT   rU   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 databaserx   ry   N
r>   Z	select_dbr'   r|   r   rx   rz   r{   r   rX   r}   rT   rT   rU   r      s    
c                 C   s   t | jtj@ S )z'MySQL session has started a transaction)boolro   r   ZSTATUS_IN_TRANSrm   rT   rT   rU   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!rt"| 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pd| j&'dpd| j*d	 t,j-dkr| j.dkrd|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*st5| jdrt<| jj=r| j= }t>| j&'dg D ]}t?| t@|| qd S )Nr   )bufferedrawcharset_nameZconnection_timeoutrs   rj   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_gssapirx   ry   get_ssl_cipher)Arl   get_info_charset_idrE   MySQL	_buffered_rawZ_connection_timeoutrs   Z_auth_pluginrG   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_callbackrX   r$   Z_openid_token_filer   r   _sslgetsortrB   Z_ssl_disabledra   r@   nameZ_auth_plugin_classrN   _converter_str_fallbackconverter_str_fallbackrK   Zstr_fallbackr'   r|   r   rx   rz   r{   r   rn   callabler   setr&   r%   )	rQ   r   Z
cnx_kwargsr   Zssl_ciphersuitesr   r~   cipherZtls_versionrT   rT   rU   _open_connection  s    







$

	
z!CMySQLConnection._open_connectionc              
   C   s   | j r$| j  r$t| j t d  | js.d S zz|   | j  W nb ty } zJt	rft| j | t
|drt|j|j|jd|tt||W Y d }~n
d }~0 0 W t	rt| j  nt	rt| j  0 d S )Nr   rx   ry   )Z_spanZis_recordingr4   sysexc_infor>   free_resultrP   r'   r1   r|   r   rx   rz   r{   r   rX   r3   )rQ   r~   rT   rT   rU   rP   }  s*    
&zCMySQLConnection.closec                 C   s   | j   S )z8Return True if the connection to MySQL Server is closed.)r>   	connectedrm   rT   rT   rU   	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pingrm   rT   rT   rU   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   )rQ   r   r   r   r   rT   rT   rU   r     s    zCMySQLConnection.ping)rh   r7   c                 C   s   | j | dS )z;Sets the default character set name for current connection.N)r>   Zset_character_set)rQ   rh   rT   rT   rU   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 rowrT   z'Query should not return more than 1 rowrx   ry   N)r>   r   have_result_set	fetch_rowr   r   r'   r|   r   rx   rz   r{   rX   )rQ   r   	first_rowr~   rT   rT   rU   rv     s$    



$zCMySQLConnection.info_queryc                 C   s$   z| j  W S  ty   Y n0 dS )zMySQL connection IDN)r>   rk   r'   rm   rT   rT   rU   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|st
| jD ](\}}|d tjkrt|| ||< 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	rt|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   eofFrx   ry   )r   unread_resultr>   r   r   r   r   rK   r   list	enumerater?   r   ZVECTORr   Z_vector_to_pythonZ	to_pythonappendtuplefetch_eof_columnsr   _unread_resultr'   r|   r   rx   rz   r{   r   rX   )rQ   r   r   r   r   r   r6   r   rowscounterr   rowiZdsc__eofr~   rT   rT   rU   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)rQ   r   r   r   r   r6   r   r   rT   rT   rU   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_resultrm   rT   rT   rU   r   M  s    

zCMySQLConnection.next_resultc                 C   s   | j r| j   dS )zFrees the resultN)r>   r   rm   rT   rT   rU   r   T  s    zCMySQLConnection.free_resultc                 C   s   | j r|   | j   dS )zCommit current transactionN)r>   r   commitrm   rT   rT   rU   r   Y  s    zCMySQLConnection.commitc                 C   s   | j r| j   | j   dS )zRollback current transactionN)r>   r   rollbackrm   rT   rT   rU   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 databaserx   ry   Nr   )rQ   r   r~   rT   rT   rU   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_NULLro   st_warning_count)rQ   r   r   fieldscolrT   rT   rU   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_rowsri   N)r>   r   Zst_field_countr   r   ro   rm   rT   rT   rU   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 availablerx   ry   N)r>   r   Zstmt_preparer   r   r   r'   r|   r   rx   rz   r{   r   rX   )rQ   r   r6   stmtr~   rT   rT   rU   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sd| _|  S d| _| |S )zExecutes the prepared statementquery_attrsrx   ry   NFT)Zstmt_executer   r'   r|   r   rx   rz   r{   r   rX   r?   r   r   r   r   )rQ   r   r   r6   r~   rT   rT   rU   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 foundrx   ry   N)r   r   Z
stmt_closer'   r|   r   rx   rz   r{   r   rX   rQ   r   r6   r~   rT   rT   rU   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   rx   ry   N)r   r   Z
stmt_resetr'   r|   r   rx   rz   r{   r   rX   r   rT   rT   rU   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rt|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   rx   ry   :i  zConnection not available.)rx   values)r   r   r   bytesencodeZ_queryZ_local_infile_filenamesr>   r   r   r'   r|   r   rx   rz   r{   r   rX   r   r   r   r   r   r?   r   r   r   )rQ   r   r   r   r  r6   r~   addrrT   rT   rU   	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   rT   )rY   r   r   Zcursor_typerT   rU   r[   t  r\   z+CMySQLConnection.cursor.<locals>.<listcomp>)r   r   r   warningswarnWarning
issubclassr(   r   r   r   r)   r/   r+   r,   r*   r-   r.   KeyError
ValueErrorrB   range)	rQ   r   r   r
  r  r  r   r   typesrT   r  rU   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_rowsrm   rT   rT   rU   r  w  s    zCMySQLConnection.num_rowsc                 C   s   | j s
dS | j  S )zReturns number of warningsr   )r>   r   rm   rT   rT   rU   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   rm   rT   rT   rU   result_set_available  s    z%CMySQLConnection.result_set_availablec                 C   s   | j S )z)Check if there are unread results or rows)r  rm   rT   rT   rU   r     s    zCMySQLConnection.unread_resultc                 C   s
   | j  S )zCheck if there are more results)r>   more_resultsrm   rT   rT   rU   r    s    zCMySQLConnection.more_results)paramsr7   c                    s   g }t |ttfr: jr, fdd|D }q҈ jj| }nt |tri } jr| D ]0\}} j j	 j
| j|| < qVq| D ] \}} j|d || < qntdt|j d| d|S )zPrepare 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 rT   )rK   quoteescapeto_mysql	_sql_mode)rY   rq   rm   rT   rU   r[     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   rK   r>   Zconvert_to_mysqldictitemsr!  r"  r#  r$  r  r   type__name__)rQ   r   resultr   rq   rT   rm   rU   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   rm   rT   rT   rU   consume_results  s    z CMySQLConnection.consume_results )usernamer   r   rh   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rt
|tstd|dk rtd|| _|| _|   dS )z!Change the current logged in userrx   ry   Nzcharset must be an integerr   z2charset should be either zero or a postive integer)r>   Zchange_userr'   r|   r   rx   rz   r{   r   rX   r   r   r  r   r   _post_connection)rQ   r.  r   r   rh   r   r   r   r   r   r   r~   rT   rT   rU   cmd_change_user  s8    
$
z CMySQLConnection.cmd_change_userc                 C   s   | j  }|r|   |S )zResets 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/  )rQ   resrT   rT   rU   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 )Nrx   ry   )r   r>   refreshr'   r|   r   rx   rz   r{   r   rX   r   )rQ   r3  r~   rT   rT   rU   cmd_refresh  s    
$zCMySQLConnection.cmd_refreshc                 C   s   |    dS )z,Close the current connection with the serverN)rP   rm   rT   rT   rU   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 )zShut 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 typerx   ry   N)r>   r   r   r   r   ZSHUTDOWN_DEFAULTshutdownr'   r|   r   rx   rz   r{   rX   rP   )rQ   r7  levelr~   rT   rT   rU   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_headerrx   ry   N)r   r>   statr   Zparse_statisticsr'   r   r|   r   rx   rz   r{   rX   )rQ   r;  r~   rT   rT   rU   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	  )rQ   r=  rT   rT   rU   cmd_process_kill?  s    
z!CMySQLConnection.cmd_process_killc                 C   s   t dS )zSend the DEBUG commandNNotImplementedErrorrm   rT   rT   rU   	cmd_debugE  s    zCMySQLConnection.cmd_debugc                 C   s   t dS )zSend the PING commandNr?  rm   rT   rT   rU   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?  )rQ   rC  r6   rT   rT   rU   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?  )rQ   r   rE  rF  r6   rT   rT   rU   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   )rQ   r
  r   rT   rT   rU   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   r2  r0  r   r   r   r   r   r   r   r   r   r   r   r  r'  executerP   )rQ   rH  rI  curr   rq   rT   rT   rU   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   rM   re   rn   propertyr   ro   rX   rp   r   rs   setterr   rw   r   r   r   r   r   r   rP   Z
disconnectr   r   r   r   r#   r!   rv   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,  r0  r2  r   r5  r6  r:  r"   r<  r>  r   rA  rB  rD  r   rG  r   rL  __classcell__rT   rT   rR   rU   r5   o   sn  !	n     
V    
 #   /       
U+	          -

  r5   )JrO  r@   rH   rc   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   rf   r   r  r   r   r   r    r!   r"   r#   utilsr$   r%   r&   r<   rE   r'   Zcursor_cextr(   r)   r*   r+   r,   r-   r.   r/   ImportErrorexcZopentelemetry.constantsr1   Z!opentelemetry.context_propagationr2   Zopentelemetry.instrumentationr3   r4   r5   rT   rT   rT   rU   <module>   s@   0$	(
