
    G)fЌ                        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 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- dZ.	 ddl/Z/ddl/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= dZ.ddl@mAZA ddlBmCZC eArddlDmEZEmFZF  G d de      ZGy# e>$ rZ? e>de? d      e?dZ?[?ww xY w)z'Connection class using the C Extension.    N)
AnyBinaryIODictListNoReturnOptionalSequenceTupleTypeUnion   )version)CMySQLPrepStmtMySQLConnectionAbstract)
ClientFlag	FieldFlag
ServerFlagShutdownType)MySQLConverter)InterfaceErrorInternalErrorOperationalErrorProgrammingErrorget_mysql_exception)MySQLProtocol)CextEofPacketTypeCextResultTypeDescriptionTypeParamsSequenceOrDictTypeRowTypeStatsPacketType
StrOrBytes)import_objectF)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                       e Zd ZdZdeddf fdZdadZdadZede	fd       Z
d	eddfd
ZdbdeddfdZedefd       Zej                   deddfd       Zedefd       Zej                   deddfd       Zedefd       ZdadZdadZeZdefdZdefdZdcdede	de	ddfdZdeddfdZdedee   fdZedee	   fd       Z	 	 	 	 	 dddee	   d ed!eee       d"ee   d#ee!   de"ee   ee#   f   fd$Z$	 	 	 	 ded ed!eee       d"ee   d#ee!   de"ee   ee#   f   f
d%Z%dee   fd&Z&dad'Z'dad(Z(dad)Z)d*eddfd+Z*	 dfd#ee!   de+fd,Z,dee#   fd-Z-d.e.de!fd/Z/e0d0e!d1edee1e#e+f      fd2       Z2d0e!ddfd3Z3d0e!ddfd4Z4e0	 	 	 dgded"ee   d5ed6edee1e#e+f      f
d7       Z5e5Z6	 	 	 	 	 	 dhd5ee   d"ee   d8ee   d9ee7e8      d:ee   d;ee   de8fd<Z9ede	fd=       Z:ede	fd>       Z;edefd?       Z<edefd@       Z=edefdA       Z>dBe?de1e@e.   eAee.f   f   fdCZBdadDZC	 	 	 	 	 	 	 	 	 didEedFed*ede	dGedHedIedJee   dKee   ddfdLZDdefdMZEdNe	dee#   fdOZFdadPZGdfdQee	   ddfdRZHdeIfdSZJdTe	ddfdUZKdeLfdVZMdeLfdWZNdXedeLfdYZOd0e!dZe	d[ePdeLfd\ZQdjd8eddfd]ZR	 	 dkd^eeAeef      d_eeAeef      ddfd`ZS xZTS )lCMySQLConnectionz6Class initiating a MySQL Connection using Connector/C.kwargsreturnNc                    t         st        d      d| _        g | _        t        j
                  j                  t        j
                  j                  t        j
                  j                  t        j                              ddd      | _        t        j                         dk(  rQt        j
                  j                  | j                        s(t        j
                  j                  d      rdnd| _        d| _        t         | E          |r	  | j$                  d	i | yy# t&        $ r | j)                           w xY w)
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)selfr8   	__class__s     \/var/www/html/flask-app/venv/lib/python3.12/site-packages/mysql/connector/connection_cext.pyrR   zCMySQLConnection.__init__p   s   QRR  	 02 "GGOOBGGOO,<,E,EFG	!
 ??'77>>$"2"23 ww~~&?@ .0   48&v&   

s   D$ $D?c                 8   t         j                  j                  d      }|d   dk(  rd}nd}| j                  j	                  d|dj                  t         j                  dd D cg c]  }t        |       c}      t        j                         d	       y
c c}w )z!Add default connection attributes r   GPLv2zGPL-2.0
Commercialzmysql-connector-python.   )_connector_name_connector_license_connector_version_source_hostN)
r   LICENSEsplit_conn_attrsupdaterG   VERSIONstrsocketgethostname)rV   license_chunksclient_licensexs       rX   _add_default_conn_attrsz(CMySQLConnection._add_default_conn_attrs   s     ..s3!'&N)N#;&4&)hhPQRS@T/U1A/U&V & 2 2 4		
 0Vs   $Bc           	      t   | j                   j                         | j                   j                         | j                   j                         dddd| j                   j	                         d| _        | j                  | j
                  d         | _        | j                  j                  | j                         y)z<Gather information of the MySQL server before authenticationN)protocolserver_version_originalserver_threadidcharsetserver_statusauth_plugin	auth_datacapabilitiesrq   )
rC   get_proto_infoget_server_info	thread_idst_server_capabilities
_handshake_check_server_version_server_version_character_setset_mysql_versionrV   s    rX   _do_handshakezCMySQLConnection._do_handshake   s     335'+||'C'C'E#||557! LL??A	
  $99OO56 
 	--d.B.BC    c                 6    | j                   j                         S )z6Returns the server status attribute of MYSQL structure)rC   st_server_statusr   s    rX   _server_statuszCMySQLConnection._server_status   s     ||,,..r   rF   c                 T    | j                   r| j                   j                  |       yy)zJset local_infile_in_path

        Set allow_local_infile_in_path.
        N)rC   !set_load_data_local_infile_option)rV   rF   s     rX   set_allow_local_infile_in_pathz/CMySQLConnection.set_allow_local_infile_in_path   s"     <<LL::4@ r   valuec                     || _         | j                  r| j                  j                  |       | j                  r| j                  j	                  |       yy)zuToggle unicode mode

        Set whether we return string fields as unicode or not.
        Default is True.
        N)_use_unicoderC   use_unicoderP   set_unicoderV   r   s     rX   r   zCMySQLConnection.set_unicode   sC     "<<LL$$U+>>NN&&u- r   c                 4    | j                  d      d   }|dk(  S )z#Get whether autocommit is on or offzSELECT @@session.autocommitr   r   
info_queryr   s     rX   
autocommitzCMySQLConnection.autocommit   s"      =>qAzr   c                     	 | j                   j                  |       || _        y# t        $ r2}t	        |j
                  |j                  |j                        |d}~ww xY w)zToggle autocommitmsgerrnosqlstateN)rC   r   _autocommitr$   r   r   r   r   rV   r   errs      rX   r   zCMySQLConnection.autocommit   sT    	LL##E*$D" 	%GG399s||	s   "% 	A -AA c                 *    | j                  d      d   S )zGet the current databasezSELECT DATABASE()r   r   r   s    rX   databasezCMySQLConnection.database   s     23A66r   c                     	 | j                   j                  |       y# t        $ r2}t        |j                  |j
                  |j                        |d}~ww xY w)zSet the current databaser   NrC   	select_dbr$   r   r   r   r   r   s      rX   r   zCMySQLConnection.database   sL    	LL""5)" 	%GG399s||	    	A-AAc                 N    t        | j                  t        j                  z        S )z'MySQL session has started a transaction)boolr   r   STATUS_IN_TRANSr   s    rX   in_transactionzCMySQLConnection.in_transaction   s      D''**D*DDEEr   c                    | j                   j                  | j                        d   }t        j                  | j
                  | j                  || j                  xs d| j                  | j                  | j                        | _        | j                  t        j                        si | _        | j                   xs | j"                  }i d| j$                  d| j&                  d| j(                  d| j*                  d| j,                  d| j.                  d	| j0                  d
| j2                  d| j4                  d| j6                  d| j8                  ddd| j                  d| j:                  d| j<                  d| j>                  d| j@                  dtC        |tD              rtG        |      n|i}| jH                  jK                  d      }|#|jM                  d       djO                  |      }| jH                  jK                  d      =| jH                  jK                  d      d   }| jH                  jK                  d      d   }nd }d }|d|v r|sd}| jP                  s|jS                  | jH                  jK                  d      | jH                  jK                  d      | jH                  jK                  d      |||| jH                  jK                  d       xs d!| jH                  jK                  d"      xs d!| jP                  d#	       tT        jV                  d$k(  r| jX                  d%k(  rd|d&<   	  | j                  jZ                  d(i | | j\                  | j                  _/        | j`                  r| j\                  | j`                  _1        | jo                          y # td        $ r2}tg        |jh                  |jj                  |jl                  '      |d }~ww xY w))Nr   )bufferedrawcharset_nameconnection_timeoutr   ru   
plugin_dirhostuserpassword	password1	password2	password3r   portclient_flagsunix_socketcompressssl_disabledT
conn_attrslocal_infileload_data_local_diroci_config_fileoci_config_profilefido_callbacktls_versions)reverse,tls_ciphersuitesr   zTLSv1.3TLS_AES_256_GCM_SHA384cacertkeyverify_certFverify_identity)	ssl_cassl_certssl_keyssl_cipher_suitesr   tls_cipher_suitesssl_verify_certssl_verify_identityr   ntMySQLKerberosAuthPluginuse_kerberos_gssapir   r@   )8r   get_info_charset_idrJ   MySQL	_buffered_raw_connection_timeoutr   _auth_pluginrL   rC   isset_client_flagr   CONNECT_ARGSre   _webauthn_callback_fido_callback_host_user	_password
_password1
_password2
_password3	_database_port_client_flags_unix_socket	_compress_allow_local_infile_allow_local_infile_in_path_oci_config_file_oci_config_profile
isinstancerh   r#   _sslgetsortrG   _ssl_disabledrf   rE   name_auth_plugin_classrS   _converter_str_fallbackconverter_str_fallbackrP   str_fallbackr$   r   r   r   r   r   )rV   r   r   
cnx_kwargsr   ssl_ciphersuitesr   r   s           rX   _open_connectionz!CMySQLConnection._open_connection   s   **33D4D4DEaH'--^^		% $ 8 8 =A))))''
 %%j&=&=>!D//F43F3F
DJJ
DJJ
 
 	

 
 
 
 DJJ
 D..
 4,,
 
 D
 $**
 D44
 "4#C#C
  t44!
" !$":":#
$ mS1 m,"+

2 yy}}^4#d+88L1L99==+,8#yy}}-?@   $yy}}-?@   $#$\)$7!!"iimmD1 $		f 5#yy}}U3)9$0)9'+yy}}]'C'Lu+/99==9J+K+Tu$($6$6
 77d?t66:SS04J,-	 DLL  .:.262N2NDLL/~~.2.J.J+ 	 # 	%GG399s||	s   AN1 1	O,:-O''O,c                 F   | j                   rE| j                   j                         r+t        | j                   t        j                         d          | j
                  sy	 | j                          | j
                  j                          	 t        rt        | j                          yy# t        $ rN}t        rt        | j                   |       t        |j                  |j                  |j                        |d}~ww xY w# t        rt        | j                          w w xY w)z Disconnect from the MySQL serverr   Nr   )_spanis_recordingr5   sysexc_inforC   free_resultrU   r$   r2   r   r   r   r   r4   )rV   r   s     rX   rU   zCMySQLConnection.closeN  s    ::$**113"4::s||~a/@A||	%LL  $  # 	&tzz37%GG399s||	 $ s%    *B( (	C?1A	C::C??D D c                 8    | j                   j                          S )z8Return True if the connection to MySQL Server is closed.)rC   	connectedr   s    rX   	is_closedzCMySQLConnection.is_closede  s    <<))+++r   c                 p    | j                   r*| j                          | j                   j                         S y)z;Reports whether the connection to MySQL Server is availableF)rC   handle_unread_resultpingr   s    rX   is_connectedzCMySQLConnection.is_connectedi  s+    <<%%'<<$$&&r   	reconnectattemptsdelayc                     | j                          	 | j                  j                         }|ry|r| j	                  ||       yt        d      # t        $ r Y ,w xY w)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  rC   r  AttributeErrorr  r   )rV   r  r  r  r   s        rX   r  zCMySQLConnection.pingq  sb     	!!#	))+I NNHEN: !GHH  		s   A 	AArs   c                 :    | j                   j                  |       y)z;Sets the default character set name for current connection.N)rC   set_character_set)rV   rs   s     rX   set_character_set_namez'CMySQLConnection.set_character_set_name  s    &&w/r   queryc                    d}	 | j                   j                  |       | j                   j                  rY| j                   j                         }| j                   j                         r%| j                   j	                          t        d      | j                   j	                          |S # t        $ r2}t        |j                  |j                  |j                        |d}~ww xY w)z%Send a query which only returns 1 rowr@   z'Query should not return more than 1 rowr   N)rC   r  have_result_set	fetch_rowr   r   r$   r   r   r   r   )rV   r  	first_rowr   s       rX   r   zCMySQLConnection.info_query  s    		LLu%||++ LL224	<<))+LL,,.()RSSLL$$&  # 	%GG399s||	s   B$B* *	C%3-C  C%c                 V    	 | j                   j                         S # t        $ r Y yw xY w)zMySQL connection IDN)rC   rz   r$   r   s    rX   connection_idzCMySQLConnection.connection_id  s/    	<<))++" 		s    	((countbinarycolumnsr   	prep_stmtc                    |r|j                   n| j                  }| j                  r|st        d      || j                  }g }||dk  rt        d      d}	 |r|j                  n| j                  j                  }	| j                  r| j                  j                  d        |	       }
|
r| j                  sg| j                  r[t        |
      }
t        |
      D ]7  \  }}|r	| j                  j                  | j                  |   |
|         |
|<   9 t        |
      }
|j                  |
       |dz  }|r||k(  rn
 |	       }
|
r|
s?| j                  |      d   }|r|j!                          d| _        n| j!                          nd}||fS # t$        $ ri}|r%|j!                          t'        t)        |            || j!                          t+        |j,                  |j.                  |j0                  	      |d}~ww xY w)
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   eofFr   )r  unread_resultrC   r   r   r	  r  rP   r   list	enumerate	to_pythonrD   tupleappendfetch_eof_columnsr   _unread_resultr$   r   rh   r   r   r   r   )rV   r  r  r  r   r  r  rowscounterr  rowi__eofr   s                  rX   get_rowszCMySQLConnection.get_rows  s    6?	11DDVDV 9::;))C! !GHH&	/8	++dll>T>TI~~   &+CyyT^^s)C )# X1"%)^^%=%=dmmA>NPSTUPV%WCFX  *CC 1W-k  484J4J94U5 ))+*/D'$$& Tz # 	%%'$SX.C7%GG399s||	s(   B
F $A#F AF 	HA$G<<Hc                 n    	 | j                  d||||      \  }}|r|d   |fS d|fS # t        $ r Y yw xY w)z.Get the next rows returned by the MySQL serverr   )r  r  r  r   r  r   NNN)r(  
IndexError)rV   r  r  r   r  r"  r  s          rX   get_rowzCMySQLConnection.get_row  s\    	 # & ID# Q~%#; 	 	 s   !( ( 	44c                     | j                   r4| j                   j                          | j                   j                         S y)zReads the next resultN)rC   consume_resultnext_resultr   s    rX   r/  zCMySQLConnection.next_result  s/    <<LL'')<<++--r   c                 R    | j                   r| j                   j                          yy)zFrees the resultN)rC   r   r   s    rX   r   zCMySQLConnection.free_result  s    <<LL$$& r   c                 r    | j                   r+| j                          | j                   j                          yy)zCommit current transactionN)rC   r  commitr   s    rX   r2  zCMySQLConnection.commit  s*    <<%%'LL! r   c                     | j                   r5| j                   j                          | j                   j                          yy)zRollback current transactionN)rC   r.  rollbackr   s    rX   r4  zCMySQLConnection.rollback  s.    <<LL'')LL!!# r   r   c                     	 | j                   j                  |       y# t        $ r2}t        |j                  |j
                  |j                        |d}~ww xY w)zChange the current databaser   Nr   )rV   r   r   s      rX   cmd_init_dbzCMySQLConnection.cmd_init_db  sL    	LL""8," 	%GG399s||	r   c                    |r|j                   n| j                  j                   }|st        d      |r|j                         n| j                  j                         }g | _        |D ]k  }| j                  j                  |d   t        |d         ddddt        |d          t        j                  z  t        |d         t        |d         f	       m | j                  | j                  j                         d| j                  dS )	z Fetch EOF and column informationNo result set      N	      )status_flagwarning_count)r  r  )r  rC   r   fetch_fieldsrD   r  intr   NOT_NULLr   st_warning_count)rV   r  r  fieldscols        rX   r   z"CMySQLConnection.fetch_eof_columns%  s    
 *3I%%8T8T 	  11-6'')DLL<U<U<W 	CMM  FAKQ[L9#5#55AKAK
	"  $22!%!>!>!@ }}
 	
r   c                     | j                   rr| j                   j                         | j                   j                         | j                   j                         | j                   j	                         | j
                  dS y)z Fetch EOF and status information)r>  field_count	insert_idaffected_rowsrt   N)rC   rB  st_field_countrG  rH  r   r   s    rX   fetch_eof_statusz!CMySQLConnection.fetch_eof_statusH  sa    <<!%!>!>!@#||::<!\\335!%!;!;!=!%!4!4  r   	statementc                     | j                   st        d      	 | j                   j                  |      }| j                  |_        t        |      S # t        $ r}t        t        |            |d}~ww xY w)zPrepares the SQL statementMySQL Connection not availableN)	rC   r   stmt_preparer   r   r   r$   r   rh   )rV   rK  stmtr   s       rX   cmd_stmt_preparez!CMySQLConnection.cmd_stmt_prepareU  sh    ||"#CDD	4<<,,Y7D*.*F*FD'!$''" 	4 S*3	4s   6A 	A3A..A3statement_idargsc                    	  |j                   |d| j                  i g | _        |j                  sd| _        | j                         S d| _        | j                  |      S # t        $ r}t        t	        |            |d}~ww xY w)zExecutes the prepared statementquery_attrsNFT)
stmt_executerT  r$   r   rh   rD   r  r!  rJ  r   )rV   rQ  rR  r   s       rX   cmd_stmt_executez!CMySQLConnection.cmd_stmt_executea  s    
	4%L%%tJ9I9IJ ++"'D((**"%%l33 # 	4 S*3	4s   A   	B)A>>Bc                 R    | j                   rt        d      |j                          y)zCloses the prepared statementUnread result foundN)r!  r   
stmt_closerV   rQ  s     rX   cmd_stmt_closezCMySQLConnection.cmd_stmt_closet  %    
  566!r   c                 R    | j                   rt        d      |j                          y)zResets the prepared statementrX  N)r!  r   
stmt_resetrZ  s     rX   cmd_stmt_resetzCMySQLConnection.cmd_stmt_reset}  r\  r   r   raw_as_stringc                 j   | j                          || j                  }	 t        |t              s|j	                  d      }| j
                  j                  ||||| j                         g | _        | j
                  j&                  s| j)                         S | j+                         S # t        $ r2}t        |j                  |j                  |j                        |d}~wt        $ rH}| j                  r| j                  n| j                   d| j                    }t#        d|df      |d}~ww xY w)	z Send a query to the MySQL serverNzutf-8)r   r   r`  rT  )r   r   :i  zConnection not available.)r   values)r  r   r   bytesencoderC   r  rT  r$   r   r   r   r   r	  r   r   r   r   rD   r  rJ  r   )rV   r  r   r   r`  r   addrs          rX   	cmd_queryzCMySQLConnection.cmd_query  s#    	!!#;))C	eU+W-LL!+ ,,  & ||++((**%%''# # 	%		sww  	%)%6%6!!tzzl!DJJ<<X  #D*E#F		s%   AB( (	D21-CD2*AD--D2preparedcursor_class
dictionarynamed_tuplec                    | j                  |       | j                         st        d      |#t        |t              st        d       ||       S |xs | j                  }|xs | j                  }d}|du r|dz  }|du r|dz  }|du r|dz  }|du r|d	z  }|du r|d
z  }t        t        t        t        t        t        t        t        t        t         t"        t$        d}	  ||   |       S # t&        $ rM d}	t)        ddj+                  t-        d      D 
cg c]  }
|d|
z  z  dk7  s|	|
    nc c}
w c}
      z         dw xY w)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
        CursorBase. 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      r9  r:     )r   r   rn  r^   r9     r:  r;  ro           )r   r   rj  rk  rh  z*Cursor not available with given criteria: z, rp  )r  r  r   
issubclassr%   r   r   r   r&   r0   r)   r*   r'   r+   r(   r,   r/   r-   r.   KeyError
ValueErrorrG   range)rV   r   r   rh  ri  rj  rk  cursor_typetypesrR  r%  s              rX   cursorzCMySQLConnection.cursor  sx   J 	!!(+  ""#DEE#lL9&S  !$''-t~~TYYt1K$;1K1K$1Kt2K #&'%-$'(.
	&E+&-- 	OD<))eAhV+a:PTU:UT!WVVWX 	s   !
C, ,)ED.&D.-Ec                 x    | j                   j                  st        d      | j                   j                         S )z,Returns number of rows of current result setr8  )rC   r  r   num_rowsr   s    rX   r|  zCMySQLConnection.num_rows  s/     ||++ 11||$$&&r   c                 P    | j                   sy| j                   j                         S )zReturns number of warningsr   )rC   r>  r   s    rX   r>  zCMySQLConnection.warning_count  s!     ||||))++r   c                 H    | j                   sy| j                   j                  S )z"Check if a result set is availableF)rC   r  r   s    rX   result_set_availablez%CMySQLConnection.result_set_available  s     ||||+++r   c                     | j                   S )z)Check if there are unread results or rows)r  r   s    rX   r  zCMySQLConnection.unread_result  s     (((r   c                 6    | j                   j                         S )zCheck if there are more results)rC   more_resultsr   s    rX   r  zCMySQLConnection.more_results#  s     ||((**r   paramsc           
      >   g }t        |t        t        f      r| j                  rg|D cg c]Z  }| j                  j	                  | j                  j                  | j                  j                  |      | j                              \ }}|S  | j                  j                  | }|S t        |t              ri }| j                  ru|j                         D ]`  \  }}| j                  j	                  | j                  j                  | j                  j                  |      | j                              ||<   b |S |j                         D ]&  \  }}| j                  j                  |      d   ||<   ( |S t        dt        |      j                   d| d      c c}w )zPrepare parameters for statements

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

        Returns dict.
        r   zCould not process parameters: (z)), it must be of type list, tuple or dict)r   r  r  rP   quoteescapeto_mysql	_sql_moderC   convert_to_mysqldictitemsr   type__name__)rV   r  resultr   r   s        rX   prepare_for_mysqlz"CMySQLConnection.prepare_for_mysql(  s    46ftUm,~~ "(  NN((-- NN33E:DNN 8 ' 766?& % %F~~"(,,. JC"&.."6"6-- NN33E:DNN#F3K  #),,. JJC"&,,"?"?"Fq"IF3KJ  #0f1F1F0Gq Q: : /s   AFc                 8    | j                   j                          y)zlConsume the current result

        This method consume the result by reading (consuming) all rows.
        N)rC   r.  r   s    rX   consume_resultsz CMySQLConnection.consume_resultsS  s    
 	##%r   usernamer   r   r   r   r   r   c
           
         	 | j                   j                  ||||||||	       || _        || _        | j                          y# t        $ r2}
t        |
j                  |
j
                  |
j                        |
d}
~
ww xY w)z!Change the current logged in userr   N)
rC   change_userr$   r   r   r   r   r   r   _post_connection)rV   r  r   r   rs   r   r   r   r   r   r   s              rX   cmd_change_userz CMySQLConnection.cmd_change_userZ  s    	LL$$"	  #
 # 	%GG399s||	s   "A 	A>-A99A>c                 ^    | j                   j                         }|r| j                          |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
        )rC   reset_connectionr  )rV   ress     rX   cmd_reset_connectionz%CMySQLConnection.cmd_reset_connection|  s*     ll++-!!#
r   optionsc                     	 | j                          | j                  j                  |       | j                         S # t        $ r2}t	        |j
                  |j                  |j                        |d}~ww xY w)z,Send the Refresh command to the MySQL serverr   N)	r  rC   refreshr$   r   r   r   r   rJ  )rV   r  r   s      rX   cmd_refreshzCMySQLConnection.cmd_refresh  sk    	%%'LL  ) $$&& # 	%GG399s||	s   += 	A8-A33A8c                 $    | j                          y)z,Close the current connection with the serverN)rU   r   s    rX   cmd_quitzCMySQLConnection.cmd_quit  s    

r   shutdown_typec                 p   | j                   st        d      |r#t        j                  |      st	        d      |}nt        j
                  }	 | j                   j                  |       | j                          y# t        $ r2}t        |j                  |j                  |j                        |d}~ww xY w)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.
        rM  zInvalid shutdown typer   N)rC   r   r   r   r   SHUTDOWN_DEFAULTshutdownr$   r   r   r   r   rU   )rV   r  levelr   s       rX   cmd_shutdownzCMySQLConnection.cmd_shutdown  s     ||"#CDD((7$%<==!E 11E	LL!!%(
 	

	 # 	%GG399s||	s   A: :	B5-B00B5c                    | j                          	 | j                  j                         }t               j	                  |d      S # t
        t        f$ r2}t        |j                  |j                  |j                        |d}~ww xY w)z'Return statistics from the MySQL serverF)with_headerr   N)r  rC   statr   parse_statisticsr$   r   r   r   r   r   )rV   r  r   s      rX   cmd_statisticszCMySQLConnection.cmd_statistics  su    !!#	<<$$&D ?33De3LL#^4 	%GG399s||	s   4A B-BB	mysql_pidc                 b    t        |t              st        d      | j                  d|        y)zKill a MySQL processzMySQL PID must be intzKILL N)r   r@  rv  rg  )rV   r  s     rX   cmd_process_killz!CMySQLConnection.cmd_process_kill  s+    )S)455yk*+r   c                     t         )zSend the DEBUG commandNotImplementedErrorr   s    rX   	cmd_debugzCMySQLConnection.cmd_debug      !!r   c                     t         )zSend the PING commandr  r   s    rX   cmd_pingzCMySQLConnection.cmd_ping  r  r   
statementsc                     t         )z/Send one or more statements to the MySQL serverr  )rV   r  s     rX   cmd_query_iterzCMySQLConnection.cmd_query_iter  r  r   param_iddatac                     t         )zSend data for a columnr  )rV   rQ  r  r  s       rX   cmd_stmt_send_long_dataz(CMySQLConnection.cmd_stmt_send_long_data  s
     "!r   c                     |du r| j                   n| j                  }| j                  r| j                          y|rt	        d      y)z'Check whether there is an unread resultTrX  N)r!  r  can_consume_resultsr  r   )rV   rh  r  s      rX   r  z%CMySQLConnection.handle_unread_result  sE    /74/?++TEWEW##  " 566 r   user_variablessession_variablesc                    | j                         st        d      | j                         st	 | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  	       |s|r| j                         }|r/|j!                         D ]  \  }}|j#                  d| d|f        |r/|j!                         D ]  \  }}|j#                  d| d|f        |j%                          yy# t        $ r | j                          Y w xY w)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.
        rm  zSET @`z` = %szSET SESSION `N)r  r   r  r  r   r   r   r   r   r   r   r   r   r   r  rz  r  executerU   )rV   r  r  curr   r   s         rX   reset_sessionzCMySQLConnection.reset_session  s0   (   ""#DEE((*!$$JJNNNN$$OOOOOO)),,
 .++-C"0"6"6"8 @JCKK&V 4uh?@ "3"9"9"; GJCKK-uF ;eXFGIIK / $ ! !s   A3D( (EE)r9   N)T)Fr   r   )NFNNN)FNNN)N)NFF)NNNNNN)	 r  r  -   r  r  r  NN)Fr*  )Ur  
__module____qualname____doc__r   rR   rn   r   propertyr@  r   rh   r   r   r   r   setterr   r   r   rU   
disconnectr   r  r  r  r"   r   r    r   r  r   r   r   r
   r   r(  r,  r/  r   r2  r4  r6  r   r   rJ  rd  rP  r3   r   rV  r[  r_  rg  _execute_queryr   r%   rz  r|  r>  r  r  r  r   r	   r   r  r  r  r  r  r  r  r!   r  r  r   r  r  r  r   r  r  r  __classcell__)rW   s   @rX   r7   r7   m   s   @  B
"D$ / / /A3 A4 A
. 
. 
. D  
     7# 7 7 __c d   F F FYv%* J,4 ,d Id Ic Ic IRV I:0c 0d 0
 x/@ $ x}    $37".2=}= = $/0	=
 d^= N+= 
tG}h'899	:=B 37".2   $/0  d^	 
 N+  
x (+<"==	> .Xd^ '
"$C D  59!
!.1!
	!
F(+<"= 
4% 
4N 
4 4*4364	%)>9:	;4 4$"$" 
""$" 
"  ##&(&( d^&( 	&(
 &( 
%)>9:	;&( &(P N $("#'59%)&*S4.S d^S 4.	S
 tL12S TNS d^S 
Sj '# ' ' ,s , , ,d , , )t ) ) +d + +).)	xS%Z 00	1)V& )-,0        	  
             "#   %SM   
  Dd 
'3 
'84E+F 
'(3- 4 0
 
,# ,$ ,"8 ""( "" " ""$" " 	"
 
"7T 7d 7 486:/ c3h0/ $DcN3/ 
	/r   r7   )Hr  rE   rM   ri   r   typingr   r   r   r   r   r   r	   r
   r   r   r  r   	abstractsr   r   	constantsr   r   r   r   
conversionr   errorsr   r   r   r   r   rp   r   ry  r   r   r   r   r    r!   r"   utilsr#   rA   rJ   r$   cursor_cextr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   ImportErrorexcopentelemetry.constantsr2   !opentelemetry.context_propagationr3   opentelemetry.instrumentationr4   r5   r7   r@   r   rX   <module>r     s   > . 	   
    > F F &  $   !4    K 2 GOb. b  

<SECs   :(C C	CC