
    G)f                        d Z dgZddlZddlZddl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 ddlmZ ddlmZmZ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m Z m!Z!m"Z"m#Z# dd
l$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m?Z? ddl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZL ddlMmMZM ddlNmOZOmPZP  G d de<      ZQy)zDImplemention of the communication with MySQL servers in pure Python.MySQLConnection    N)Decimal)IOBase)AnyAsyncGeneratorBinaryIOCallableDictListMappingOptionalSequenceTupleTypeUnion   )version)
ClientFlag	FieldTypeRefreshOption	ServerCmd
ServerFlagflag_is_set)DatabaseErrorErrorInterfaceErrorInternalErrorNotSupportedErrorOperationalErrorProgrammingErrorget_exception)BinaryProtocolTypeDescriptionTypeEofPacketTypeOkPacketType
ResultTypeRowTypeStatsPacketType
StrOrBytes)get_platform	int1store	int4storelc_int   )MySQLConnectionAbstractMySQLCursorAbstract
ServerInfo)charsets)MySQLCursorMySQLCursorBufferedMySQLCursorBufferedDictMySQLCursorBufferedNamedTupleMySQLCursorBufferedRawMySQLCursorDictMySQLCursorNamedTupleMySQLCursorPreparedMySQLCursorPreparedDictMySQLCursorPreparedNamedTupleMySQLCursorPreparedRawMySQLCursorRaw)logger)MySQLTcpSocketMySQLUnixSocketc                      e Zd ZU dZdZeed<   edee   fd       Z	d^dZ
d^dZd	edefd
Zd^dZd^dZdedefdZdeddfdZdedefdZdedefdZdedefdZdedeeef   fdZdedeeeeee   ef   f   fdZ	 	 	 	 	 d_dedee   dedee   de dedee!   fdZ"	 d`de#de de!fdZ$de fd Z%de fd!Z&	 dad"e d#ed$eddfd%Z'd^d&Z(d^d'Z)e)Z*e+g e,f   ed(<   	 	 	 	 	 	 dbd)ee    d*ee    d+ee    d,ee-e.      d-ee    d.ee    de/fd/Z0	 	 	 dcd0e d1eee      d*ee    deee1   ee   f   fd2Z2	 	 	 	 	 ddd3ee   d0e d1eee      d*ee    d4e,deee1   ee   f   fd5Z3d^d6Z4d^d7Z5de fd8Z6d9edefd:Z7	 	 	 ded	e8d*e d)e d;e def
d<Z9d=e8de:edf   fd>Z;dfd?ed@eddfdAZ<dBede=eeeee   f   f   fdCZ>	 	 	 dgd?edDe?e@   dEe?e,   dedeeeeee   ef   f   f
dFZAd?eddfdGZBd?eddfdHZCdIedefdJZDd?edKedDe#defdLZEdefdMZFdhdNee   ddfdOZGdeHfdPZIdQedefdRZJdefdSZKdefdTZL	 	 	 	 	 	 	 	 	 didUedVed9edWedXedYedZed[ed\edee   fd]ZMy)jr   z3Implementation of the pure Python MySQL connection.r.   _mfa_nfactorreturnc                 R    | j                   r| j                   j                  d      S y)zMySQL connection ID.server_threadidN)
_handshakegetselfs    [/var/www/html/flask-app/venv/lib/python3.12/site-packages/mysql/connector/aio/connection.pyconnection_idzMySQLConnection.connection_idt   s$     ????&&'899    Nc                 x  K   	 | j                   r/t        j                  dk(  rt        | j                         | _        n&t        | j                  | j                        | _        t        j                  | j                  j                         | j                         d {    | j                          d {    | j                          d {    | j$                  t&        j(                  z  r| j                  j+                          	 | j-                  | j.                         | j5                          d {    y 7 7 7 t# t        j                  t        j                  f$ r  t         $ r% | j                  j#                          d {  7    w xY w# t0        $ r}t3        d      |d }~ww xY w7 |w)Nposix)unix_socket)hostportzFConverter classA should be a subclass of conversion.MySQLConverterBase)_unix_socketosnamerA   _socketr@   _host_portasynciowait_foropen_connection_connection_timeout_do_handshake_do_authCancelledErrorTimeoutError	Exceptionclose_connection_client_flagsr   COMPRESSswitch_to_compressed_modeset_converter_class_converter_class	TypeErrorAttributeError_post_connection)rJ   errs     rK   connectzMySQLConnection.connect{   sm    	  RWW%7.4;L;LM-4::DJJO"",,.0H0H   $$&&&--/!! 
 3 33LL224	$$T%:%:; ##%%%3 '!&&(<(<= 	 	,,//111	  	 0 	 	&s   F:BE  E!E 8E9E EE 7F:F (F:;F8<F:E E E A	FFFF:	F5$F00F55F:c                    t               }t        j                  j                  d      }|d   dk(  rd}nd}t	        t        j                               |d   t        j                         d|dj                  t        j                  dd	 D cg c]  }t	        |       c}      |d
   d}| j                  j                  |       yc c}w )z&Add the default connection attributes. r   GPLv2zGPL-2.0
Commercialarchzmysql-connector-python.   r   )_pid	_platform_source_host_client_name_client_license_client_version_osN)r*   r   LICENSEsplitstrrT   getpidsocketgethostnamejoinVERSION_connection_attrsupdate)rJ   platformlicense_chunksclient_licensexdefault_conn_attrss         rK   _add_default_conn_attrsz'MySQLConnection._add_default_conn_attrs   s    > ..s3!'&N)N		$!&)"..04-"xx19M(NAQ(NOI&
 	%%'9;	 )Os   Cqueryc                 t   K   | j                          d{    | j                  |       d{   S 7 7 w)zExecute a query.

        This method simply calls cmd_query() after checking for unread result. If there
        are still unread result, an InterfaceError is raised. Otherwise whatever
        cmd_query() returns is returned.
        N)handle_unread_result	cmd_query)rJ   r   s     rK   _execute_queryzMySQLConnection._execute_query   s5      '')))^^E*** 	**s   848688c                   K   | j                   j                          d{   }t        j                  d|       |d   dk(  rt	        |      | j
                  j                  |      | _        t        | j                  d   | j                  d   | j                  d   | j                  d   | j                  d	   | j                  d
   | j                  d   | j                  d         | _	        t        j                  | j                  j                  d          t        j                  d| j                  j                         | j                  r<| j                  r0t        j                   | j                  | j                        | _        n| j                  r@t        j$                  | j                        | _        | j"                  j&                  | _        n| j                  r@t        j(                  | j                        | _        | j"                  j*                  | _        nPt        j,                  d      | _        | j"                  j*                  | _        | j"                  j&                  | _        | j                  d   t.        j0                  z  sd| j2                  dk(  r| j4                  st7        d      | j8                  rt7        dd      | xj:                  t.        j0                   z  c_        n/| j<                  s#| xj:                  t.        j0                  z  c_        | j                  d   t.        j>                  z  r | jA                  t.        j>                  g       | j                  d   t.        jB                  z  r1d| j                  _"        | jA                  t.        jB                  g       | j                  d   t.        jF                  z  r!| jA                  t.        jF                  g       yy7 ڭw)z(Get the handshake from the MySQL server.NzProtocol::Handshake packet: %s      protocolserver_version_originalrF   charsetserver_statusauth_plugin	auth_datacapabilities)r   r   	thread_idr   status_flagsr   r   r   r   zProtocol::Handshake charset: %s-   mysql_clear_passwordzEClear password authentication is not supported over insecure channelsz1SSL is required but the server doesn't support iti  )errnoT)$rV   readr?   debugr!   	_protocolparse_handshakerG   r1   _server_infor2   set_mysql_major_versionversion_tupler   _charset_name_charset_collationget_by_name_and_collation_charsetget_by_name	collationget_by_collationrU   	get_by_idr   SSL_auth_plugin	is_securer   _ssl_verify_certrc   _ssl_disabledPLUGIN_AUTHset_client_flagsCLIENT_QUERY_ATTRIBUTESquery_attrs_is_supportedMULTI_FACTOR_AUTHENTICATIONrJ   packets     rK   r]   zMySQLConnection._do_handshake   s    ||((**5v>!9''..88@&__Z0OO$=>oo&78OOI.96ook28	
 	(():):)H)H)KL68I8I8Q8QR $"9"9$>>""D$;$;DM $001C1CDDM&*mm&=&=D#$$$55d6M6MNDM!%!3!3D
 %..r2DM!%!3!3D&*mm&=&=D#~.?  $::4>>$(  $$$G  :>>/1##*..0??>*Z-C-CC!!:#9#9":;??>*Z-O-OO9=D6!!:#E#E"FG??>*Z-S-SS!!:#I#I"JK T +s   O=O:OO=c                   K   | j                   r| j                   j                  d      s:| j                   r~| j                   j                  d      rct        j                  dk(  rP| j                  sDt        j                         | _        t        j                  d| j                  | j                          | j                  r%| j                  | j                  k7  r| j                  n| j                  }d| _        | j                  s| j                  t        j                  z  r| j                   j#                  | j$                  | j&                  | j(                  | j*                  | j,                  | j.                  | j0                        }| j2                  j5                  | j6                  j8                  | j                        }| j                   j;                  |       d{    | j                   j=                  |       d{    d	| _        | j>                  jA                  | j                   | jB                  | j                  || jD                  | jF                  | jH                  | j6                  j8                  | j                  | j                   | jJ                  | jL                  | jN                  | jP                  | jR                  | jT                  | jV                  
       d{   }| jY                  |       | j                  t        jZ                  z  s1| jH                  r$| j]                  | jH                         d{    yyy7 m7 M7 j7 w)af  Authenticate with the MySQL server.

        Authentication happens in two parts. We first send a response to the
        handshake. The MySQL server will then send either an AuthSwitchRequest
        or an error packet.

        Raises NotSupportedError when we get the old, insecure password
        reply back. Raises any error coming from MySQL.
        authentication_ociauthentication_kerberosntz4MySQL user is empty, OS user: %s will be used for %sF)ssl_cassl_certssl_keyssl_verify_certssl_verify_identitytls_versionstls_cipher_suites)r   client_flagsNT)sock	handshakeusername	password1	password2	password3databaser   r   r   auth_plugin_class
conn_attrskrb_service_principaloci_config_fileoci_config_profilewebauthn_callbackfido_callback)/r   
startswithrT   rU   _usergetpassgetuserr?   r   
_password1	_password_ssl_activer   rc   r   r   rV   build_ssl_context_ssl_ca	_ssl_cert_ssl_keyr   _ssl_verify_identity_tls_versions_tls_ciphersuitesr   make_auth_sslr   
charset_idwriteswitch_to_ssl_authenticatorauthenticaterG   
_password2
_password3	_database_auth_plugin_classr   _krb_service_principal_oci_config_file_oci_config_profile_webauthn_callback_fido_callback
_handle_okCONNECT_WITH_DBcmd_init_db)rJ   passwordssl_contextr   ok_pkts        rK   r^   zMySQLConnection._do_auth   s     !!,,-AB!!%%001JKGGtO** *DJLLF

!! 4>>T__#D OO 	 !!!t'9'9JNN'J,,88|| $ 5 5$($=$=!//"&"8"8 9 K !NN8800t?Q?Q 9 F ,,$$V,,,,,,,[999#D**77ooZZoooo^^MM,,++))"55--"&"="= 11#77"55--# 8 
 
& 	""Z%?%??T^^""4>>222 FT?3 -9
, 3sJ   G!M#M$"MMC$M+M,AMM	MMMMr   c                     |d   dk(  r1| j                   j                  |      }| j                  |d          |S |d   dk(  rt        |      t	        d      )zHandle a MySQL OK packet.

        This method handles a MySQL OK packet. When the packet is found to be an Error
        packet, an error will be raised. If the packet is neither an OK or an Error
        packet, InterfaceError will be raised.
        r   r   status_flagr   zExpected OK packet)r   parse_ok_handle_server_statusr!   r   )rJ   r   r   s      rK   r   zMySQLConnection._handle_okH  s^     !9>^^,,V4F&&vm'<=M!9''122rM   flagsc                     t        t        j                  |      | _        t        t        j                  |      | _        y)a  Handle the server flags found in MySQL packets.

        This method handles the server flags send by MySQL OK and EOF packets.
        It, for example, checks whether there exists more result sets or whether there
        is an ongoing transaction.
        N)r   r   MORE_RESULTS_EXISTS_have_next_resultSTATUS_IN_TRANS_in_transaction)rJ   r   s     rK   r   z%MySQLConnection._handle_server_statusW  s.     "-Z-K-KU!S*:+E+EuMrM   c                     |d   dk(  r1| j                   j                  |      }| j                  |d          |S |d   dk(  rt        |      t	        d      )a   Handle a MySQL EOF packet.

        This method handles a MySQL EOF packet. When the packet is found to be an Error
        packet, an error will be raised. If the packet is neither and OK or an Error
        packet, InterfaceError will be raised.
        r      r   r   zExpected EOF packet)r   	parse_eofr   r!   r   )rJ   r   eofs      rK   _handle_eofzMySQLConnection._handle_eofa  s_     !9..**62C&&s='9:J!9''233rM   filenamec                 6  K   t         j                  j                  |      }t         j                  j                  |      rt	        d      | j
                  s| j                  st        d      | j
                  s{| j                  rot         j                  j                  | j                        }d}	 t         j                  j                  ||g      }||k7  rd}t        |j                  ||            	 t        |d      }| j                  | j                  |d       d{         	 |j!                          S # t        $ r-}d}t        |j                  t        |      ||            |d}~ww xY w7 R# t"        t$        f$ r Y S w xY w# t"        $ rT 	 | j&                  j)                  d	       d{  7   n# t*        $ r}t	        d
      |d}~ww xY wt        d| d      dw xY w# 	 j!                          w # t"        t$        f$ r Y w w xY wxY ww)z(Handle a LOAD DATA INFILE LOCAL request.z#Use of symbolic link is not allowedKLOAD DATA LOCAL INFILE file request rejected due to restrictions on access.NzL{} while loading file `{}` and path `{}` given in allow_local_infile_in_pathzEThe file `{}` is not found in the given allow_local_infile_in_path {}rbT)send_empty_packetrM   MySQL Connection not availablezFile 'z' could not be read)rT   pathabspathislinkr   _allow_local_infile_allow_local_infile_in_pathr   
commonpath
ValueErrorr   formatr}   openr   
_send_datacloseIOError	NameErrorrV   r   ri   )rJ   r  	file_nameinfile_pathc_pathrk   err_msg	data_files           rK   _handle_load_data_infilez(MySQLConnection._handle_load_data_infilep  s    GGOOH-	77>>)$"#HII''0P0P*  ''D,L,L''//$*J*JKKF	++[),DE $4  $GNN9k$JKK	Y-I??ooi4oHH!=  5  %NN3s8YD& I Y'   	TRll((---! R&'GHcQR 6)4G!HItS	T!Y' s   B0H3!D> "H7-F $E7%F -E9=H>	E4(E//E44H7F 9FH
FH	G+F=6F97F=<G+=	GGGG++G. .H0H HHHHHHc                   K   |rt        |      dk  rt        d      |d   dk(  r| j                  |      S |d   dk(  r,|dd j                         }| j	                  |       d{   S |d   dk(  r| j                  |      S |d   dk(  rt        |      | j                  j                  |      }|rt        |t              st        d	      dg|z  | _        t        d|      D ]U  }| j                  j                  | j                  j                          d{   | j                         | j                  |<   W | j                  | j                  j                          d{         }d
| _        | j                  |dS 7 7 l7 #w)au  Handle a MySQL Result.

        This method handles a MySQL result, for example, after sending the query
        command. OK and EOF packets will be handled and returned.
        If the packet is an Error packet, an Error-exception will be raised.

        The dictionary returned of:
        - columns: column information
        - eof: the EOF-packet information
        r   Empty responser         Nr  r   zIllegal result setT)columnsr  )lenr   r   decoder  r  r!   r   parse_column_count
isinstanceint_columns_descrangeparse_columnrV   r   python_charsetunread_result)rJ   r   r  column_countir  s         rK   _handle_resultzMySQLConnection._handle_result  s     Vq !122!9>??6**!9abz((*H66x@@@!9##F++!9'' ~~88@:lC#@ !566 
 q,' 	A$(NN$?$?ll''))4+>+>%Dq!	
 T\\%6%6%889!--c::+ A  *  9s8   A$F&F'B4FF
A
F&F
'FF
Fc                     |d   dk(  r| j                   j                  |      S |d   dk(  rt        |      t        d      )a>  Handle a MySQL Binary Protocol OK packet

        This method handles a MySQL Binary Protocol OK packet. When the
        packet is found to be an Error packet, an error will be raised. If
        the packet is neither an OK or an Error packet, InterfaceError
        will be raised.

        Returns a dict()
        r   r   r   zExpected Binary OK packet)r   parse_binary_prepare_okr!   r   r   s     rK   _handle_binary_okz!MySQLConnection._handle_binary_ok  sG     !9>>>99&AA!9''899rM   c                 n  K   |rt        |      dk  rt        d      |d   dk(  r| j                  |      S |d   dk(  r| j                  |      S |d   dk(  rt	        |      | j
                  j                  |      }|rt        |t              st        d      dg|z  }t        d|      D ]K  }| j
                  j                  | j                  j                          d{   | j                        ||<   M | j                  | j                  j                          d{         }|||fS 7 N7 w)a  Handle a MySQL Result

        This method handles a MySQL result, for example, after sending the
        query command. OK and EOF packets will be handled and returned. If
        the packet is an Error packet, an Error exception will be raised.

        The tuple returned by this method consist of:
        - the number of columns in the result,
        - a list of tuples with information about the columns,
        - the EOF packet information as a dictionary.

        Returns tuple() or dict()
        r   r   r   r  r   zIllegal result set.N)r$  r   r   r  r!   r   r&  r'  r(  r*  r+  rV   r   r,  )rJ   r   r.  r#  r/  r  s         rK   _handle_binary_resultz%MySQLConnection._handle_binary_result  s,      Vq !122!9>??6**!9##F++!9'' ~~88@:lC#@ !677*.,)>q,' 	A44ll''))4+>+>GAJ	
 T\\%6%6%889gs++	 *  9s%   C D5"D1
#A D5#D3$D53D5commandargumentpacket_numberexpect_responsecompressed_packet_numberc                 R  K   | j                          d{    	 | j                  j                  | j                  j	                  ||xs |      ||       d{    |sy| j                  j                          d{   S 7 m7 +# t
        $ r}t        d      |d}~ww xY w7 %w)a  Send a command to the MySQL server.

        This method sends a command with an optional argument.
        If packet is not None, it will be sent and the argument will be ignored.

        The packet_number is optional and should usually not be used.

        Some commands might not result in the MySQL server returning a response. If a
        command does not return anything, you should set expect_response to False.
        The _send_cmd method will then return None instead of a MySQL packet.
        Nr  )r   rV   r   r   make_commandri   r   r   )rJ   r6  r7  r8  r   r9  r:  rk   s           rK   	_send_cmdzMySQLConnection._send_cmd  s     ( '')))	N,,$$++GV5GxH(   \\&&((( 	*
  	N"#CD#M	N
 )sP   B'BB'>B BB  B'?B% B'B 	B"BB""B'r  r
  c                 &  K   | j                          d{    t        |d      st        d      d}	 |j                  |dz
        }|r:| j                  j                  |       d{    |j                  |dz
        }|r:|r$	 | j                  j                  d       d{    | j                  j                          d{   }|S 7 7 g# t        $ r}t        d      |d}~ww xY w7 I# t        $ r}t        d      |d}~ww xY w7 Fw)a4  Send data to the MySQL server

        This method accepts a file-like object and sends its data
        as is to the MySQL server. If the send_empty_packet is
        True, it will send an extra empty package (for example
        when using LOAD LOCAL DATA INFILE).

        Returns a MySQL packet.
        Nr   zexpecting a file-like object      r  rM   )r   hasattrr  r   rV   r   ri   r   )rJ   r  r
  
chunk_sizebufrk   ress          rK   r  zMySQLConnection._send_data$  s     '')))y&);<<
	N..b1Cll((---nnZ"_5  Rll((--- LL%%''
+ 	* . 	N"#CD#M	N
 .! R&'GHcQR (s   DCD4C )C*C DC2 &C0'C2 +DD	DC 	C-C((C--D0C2 2	D;DDDc                 d    t        | j                  xr | j                  j                               S )zReports whether the socket is connected.

        Instead of ping the server like ``is_connected()``, it only checks if the
        socket connection flag is set.
        )boolrV   is_connectedrI   s    rK   is_socket_connectedz#MySQLConnection.is_socket_connectedG  s%     DLL@T\\%>%>%@AArM   c                 `   K   	 | j                          d{    y7 # t        $ r Y yw xY ww)a  Reports whether the connection to MySQL Server is available.

        This method checks whether the connection to MySQL is available.
        It is similar to ``ping()``, but unlike the ``ping()`` method, either `True`
        or `False` is returned and no exception is raised.
        NFT)cmd_pingr   rI   s    rK   rG  zMySQLConnection.is_connectedO  s5     	--/!!  " 		s(   .  . 	+.+.	reconnectattemptsdelayc                    K   	 | j                          d{    y7 # t        $ r5}|r| j                  ||       d{  7   nt        d      |Y d}~yd}~ww xY w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)rL  rM  z$Connection to MySQL is not available)rJ  r   rK  r   )rJ   rK  rL  rM  rk   s        rK   pingzMySQLConnection.ping\  sZ     "	V--/!! 	VnnhenDDD$%KLRUU E	VsB   A   A  	AA AAA AA c                    K   | j                   sy	 | j                   j                          d{    y7 # t        $ r Y yw xY ww)ah  Shut down connection to MySQL Server.

        This method closes the socket. It raises no exceptions.

        Unlike `disconnect()`, `shutdown()` closes the client connection without
        attempting to send a QUIT command to the server first. Thus, it will not
        block if the connection is disrupted for some reason such as network failure.
        N)rV   rb   ra   rI   s    rK   shutdownzMySQLConnection.shutdownu  s>      ||	,,//111 		s0   A6 46 A6 	AAAAc                   K   | j                   D ]  }|j                          d{     | j                   j                          | j                  rT| j                  j	                         r:t        j                  t              5  | j                          d{    ddd       | j                  r"| j                  j                          d{    d| _        y7 7 D# 1 sw Y   CxY w7 w)a  Close the connection.

        It closes any opened cursor associated to this connection, and closes the
        underling socket connection.

        `MySQLConnection.close()` is a synonymous for `MySQLConnection.disconnect()`
        method name and more commonly used.

        This method tries to send a `QUIT` command and close the socket. It raises
        no exceptions.
        N)
_cursorsr  clearrV   rG  
contextlibsuppressr   cmd_quitrb   )rJ   cursors     rK   r  zMySQLConnection.close  s      mm 	!F,,.  	!<<DLL557$$U+ &mmo%%& <<,,//111 !
 && & 2sF   #C.CAC.C CC 1C.C,C.C  C)%C.
disconnectbufferedrawpreparedcursor_class
dictionarynamed_tuplec                   K   | j                   r| j                   j                         st        d      | j                          d{    |#t	        |t
              st        d       ||       S ||n| j                  }||n| 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 7 # t(        $ rO d}	dj+                  t-        d      D 
cg c]  }
|d|
z  z  dk7  s|	|
    nc c}
w c}
      }t/        d|       dw xY ww)a  Instantiate and return a cursor.

        By default, MySQLCursor 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.

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

        Raises:
            ProgrammingError: When cursor_class is not a subclass of
                              CursorBase.
            ValueError: When cursor is not available.
        r  Nz8Cursor class needs be to subclass of MySQLCursorAbstractr   Tr.   r   r      r@  )r   r.   r   rs   r   r"  ra  	   r@           )rZ  r[  r^  r_  r\  z, r"  z*Cursor not available with given criteria: )rV   rG  r   r   
issubclassr3   r    	_buffered_rawr4   r>   r7   r8   r5   r9   r6   r:   r=   r;   r<   KeyErrorr   r*  r  )rJ   rZ  r[  r\  r]  r^  r_  cursor_typetypesargsr/  criterias               rK   rX  zMySQLConnection.cursor  s    2 ||4<<#<#<#>"#CDD'')))#lK8&N  !$'''38_c$))t1K$;1K1K$1Kt2K "%&$,#&'-
		&E+&--O 	*P  	ODyy"'(JQkQ!V.D.IaJJH <XJG	s=   AE(DB7E( 
D 
E(#E%0E	
E	
E%%E(binaryr#  c                 h   K   | j                  d|||       d{   \  }}|r|d   |fS d|fS 7 w)a3  Get the next rows returned by the MySQL server.

        This method gets one row from the result set after sending, for example, the
        query command. The result is a tuple consisting of the row and the EOF packet.
        If no row was available in the result set, the row data will be None.
        r.   )countrn  r#  r[  Nr   )get_rows)rJ   rn  r#  r[  rowsr  s         rK   get_rowzMySQLConnection.get_row  sO      --FG ( 
 
	c GS>!c{
s   202rp  	prep_stmtc                   K   || j                   }| j                  st        d      g df}	 |rD| j                  }|dk(  rd}| j                  j                  | j                  |||       d{   }nD| j                  j                  | j                  | j                  j                  |       d{   }|\  }}	|sR|sP| j                  D|rBt        | d      r6| j                  j                  }
|D cg c]  } |
|| j                         }}|	$| j                  d|	v r|	d   n|	d	          d| _        ||	fS 7 7 # t        $ r}d| _        |d}~ww xY wc c}w w)
zGet all rows returned by the MySQL server.

        This method gets all rows returned by the MySQL server after sending, for
        example, the query command. The result is a tuple consisting of a list of rows
        and the EOF packet.
        NzNo result set availableutf8mb4utf8)rp  F	converterr   r   )rh  r-  r   r   r   read_binary_resultrV   read_text_resultr   r   r   r)  rA  rx  row_to_pythonr   )rJ   rp  rn  r#  r[  rt  rr  r   rk   eof_pr{  rows               rK   rq  zMySQLConnection.get_rows   sx     ;))C!! 9::GI4j	,,i'$G!^^>>LL'5'  "^^<<LL$"3"3";";5 =   e3"".k* NN88MFJKsM#t'9'9:KDK&& E) m$?+
 "'DU{;  	!&DI	 LsZ   *EA D> -D:.AD> 2D<3D> 7=E4E,E:D> <D> >	E	EEEc                 B   K   | j                  d       d{    y7 w)zCommit current transaction.COMMITN)r   rI   s    rK   commitzMySQLConnection.commit9  s     !!(+++   c                    K   | j                   r| j                          d{    | j                  d       d{    y7 7 w)zRollback current transaction.NROLLBACK)r-  rq  r   rI   s    rK   rollbackzMySQLConnection.rollback=  s;     --/!!!!*--- "-s    AAAAAAc                    K   	 | j                  | j                  t        j                         d{          | j	                          d{    y7 !7 # t
        t        f$ r Y yw xY ww)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.
        NTF)r   r=  r   RESET_CONNECTIONrj   r   r   rI   s    rK   cmd_reset_connectionz$MySQLConnection.cmd_reset_connectionC  s_     	OO$..1K1K"LLM''))) M)!#34 		sJ   A,-A AA AA A,A A A)&A,(A))A,r   c                    K   | j                  | j                  t        j                  |j	                  d             d{         S 7 w)zChange the current database.

        This method changes the current (default) database by sending the INIT_DB
        command. The result is a dictionary containing the OK packet infawaitormation.
        zutf-8N)r   r=  r   INIT_DBencode)rJ   r   s     rK   r   zMySQLConnection.cmd_init_dbP  s<      ..!2!2HOOG4LMM
 	
Ms   >A A		Araw_as_stringc                   K   t        |t              s+t        |t              r|j                         }t        |      }| j                  j
                  dk7  r| j                  j
                  nd}t               }| j                  j                  s'| j                  rt        j                  dt               | j                  t        j                  z  rUg }g }g }	dgt        | j                        dz   dz  z  }
t!        | j                        D ]2  \  }}|d   }d}|K|
|dz  xx   d|dz  z  z  cc<   |j#                  t%        t&        j(                        t%        |      z          [t        |t*              r2| j,                  j/                  |      \  }}}|	j#                  |       n6t        |t              rI|j                  |      }|	j#                  t1        t        |            |z          t&        j2                  }nt        |t4              r8|	j#                  t1        t        |            |z          t&        j6                  }nt        |t8              rh|	j#                  t1        t        t        |      j                  |                  t        |      j                  |      z          t&        j:                  }nt        |t<              r6|	j#                  t?        j@                  d
|             t&        jB                  }nt        |tD        jD                  tD        jF                  f      r0| j,                  jI                  |      \  }}|	j#                  |       n}t        |tD        jJ                  tD        jL                  f      r0| j,                  jO                  |      \  }}|	j#                  |       n#tQ        d|jR                  jT                   d      |j#                  t%        |      t%        |      z          |d   j                  |      }|j#                  t1        t        |            |z          5 |jW                  t1        t        | j                                     |jW                  t1        d             |	r|jW                  djY                  |
D cg c]  }t?        j@                  d|       c}      t%        d      z          t[        ||      D ]'  \  }}|jW                  |       |jW                  |       ) |	D ]  }|jW                  |        |jW                  |       t5        |      }	 | j]                  | j_                  t`        jb                  |       d	{          d	{   }| jj                  rtm        d      |S c c}w 7 .7 $# tP        $ r1}|jd                  dk(  rd|jf                  v rd}ti        |      | d	}~ww xY ww)a  Send a query to the MySQL server.

        This method send the query to the MySQL server and returns the result.

        If there was a text result, a tuple will be returned consisting of the number
        of columns and a list containing information about these columns.

        When the query doesn't return a text result, the OK or EOF packet information
        as dictionary will be returned. In case the result was an error, exception
        Error will be raised.
        rv  rw  <This version of the server does not support Query Attributescategoryr      ra  r.   Nz<dz&MySQL binary protocol can not handle 'z	' objectsrM   Bil  zLoading local data is disabledr  z8Use cmd_query_iter for statements with multiple queries.)7r'  	bytearrayr}   r  r   rU   r   r   _query_attrswarningswarnWarningrc   r   r   r$  	enumerateappendr+   r   NULLr(  r   prepare_binary_integerr-   VARCHARbytesBLOBr   DECIMALfloatstructpackDOUBLEdatetimedateprepare_binary_timestamp	timedeltatimeprepare_binary_timer    	__class____name__extendr   zipr0  r=  r   QUERYr   msgr   r   r   )rJ   r   r[  rZ  r  r   r   namesrk  valuesnull_bitmappos
attr_tuplevaluer   packed
field_typerU   bit_typeresultrk   r  s                          rK   r   zMySQLConnection.cmd_queryZ  s    $ %+%%e$E(,(:(:i(G$--$$V  99d>O>OMMN  
 B BBEE"$F##d&7&7"81"<!BCK#,T->->#? .7Z"1=+qS1W~=+LL9>>!:Yu=M!MNeS)
 ==eD	"MM&)s+!LL1EMM&U"4u"<=!*!2!2Ju-MM&U"4u"<=!*Jw/MMs3u:#4#4W#=>?e*++G45 "+!2!2Ju-MM&++dE":;!*!1!1J(9(98=='IJ ??F"MM&)(:(:HMM'JK+/>>+M+Me+T(VZMM&)*!OO445Y@  Yz2Yu5EEF!!}++G4VCI.56].7b MM&T%6%6!789 MM&)$HH{Kfkk#s3KLl# $'ue#4 (KE4MM%(MM$'( $ )EMM%() 	ef	..nnY__e<< F !! J  ; L =   	yyD %E%P1  $G,#5	s[   R%W$'VBW$.V' 4V#5V'  V%V' W$#V' %V' '	W!0,WW!!W$
statementsc                  K   t               }t        |t               s,t        |t              r|j                  d      }t        |      }| j                  t
        j                  z  r4|j                  t        d             |j                  t        d             |j                  |       t        |      }| j                  | j                  t        j                  |       d{          d{    | j                  rb| j                          d{    | j                  | j                   j#                          d{          d{    | j                  rayy7 7 x7 S7 (7 w)ac  Send one or more statements to the MySQL server.

        Similar to the cmd_query method, but instead returns a generator
        object to iterate through results. It sends the statements to the
        MySQL server and through the iterator you can get the results.

        statement = 'SELECT 1; INSERT INTO t1 VALUES (); SELECT 2'
        for result in await cnx.cmd_query(statement, iterate=True):
            if 'columns' in result:
                columns = result['columns']
                rows = await cnx.get_rows()
            else:
                # do something useful with INSERT result
        rw  r   r.   N)r  r'  r}   r  rc   r   r   r  r-   r  r0  r=  r   r  r   r   rV   r   )rJ   r  r   r   s       rK   cmd_query_iterzMySQLConnection.cmd_query_iter  s    " *i0*c*'..v6
":.J
 B BBMM&)$ MM&)$j!f''dnnY__e.T(TUUU $$++---++$,,2C2C2E,EFFF $$ )UU .,EFs`   C"E1$E'%E10E)1&E1E+,E1E-E1E/E1%E1)E1+E1-E1/E1statement_idrr  c                    K   | j                   j                  ||      }d| _        | j                  t        j
                  |d       d{    d| _        y7 w)zFetch a MySQL statement Result Set.

        This method will send the FETCH command to MySQL together with the given
        statement id and the number of rows to fetch.
        Fr9  NT)r   make_stmt_fetchr-  r=  r   
STMT_FETCH)rJ   r  rr  r   s       rK   cmd_stmt_fetchzMySQLConnection.cmd_stmt_fetch  sR      //dC"nnY1165nQQQ! 	Rs   A	AAA	statementc                 >  K   | j                  t        j                  |       d{   }| j                  |      }g |d<   g |d<   |d   dkD  rt	        d|d         D ]Z  }|d   j                  | j                  j                  | j                  j                          d{   | j                               \ | j                  | j                  j                          d{          |d   dkD  rt	        d|d         D ]Z  }|d   j                  | j                  j                  | j                  j                          d{   | j                               \ | j                  | j                  j                          d{          |S 7 l7 7 7 S7 w)zPrepare a MySQL statement.

        This method will send the PREPARE command to MySQL together with the given
        statement.
        Nr#  
parameters
num_paramsr   num_columns)r=  r   STMT_PREPAREr3  r*  r  r   r+  rV   r   r,  r  )rJ   r  r   r  _s        rK   cmd_stmt_preparez MySQLConnection.cmd_stmt_prepare  sx     ~~i&<&<iHH''/y!|,!#1f\23 |$++NN//"ll//1143F3F 4<<#4#4#667- 1$1f]34 y!((NN//"ll//1143F3F 4<<#4#4#667- I 2 7
 2 7s[   $FFA9F F!AF"F#A"FFAFFFFFFFdatar  c           
      N  K   t        |      }i }|r_t        |      D ]Q  \  }}t        ||   t              sd}	 d||   j                  v}| j                  ||||          d{    |f||<   S | j                  s'| j                  rt        j                  dt               | j                  t        j                  z  rJ| j                  j!                  ||t#        |      ||| j$                  | j                  | j&                        }	n?| j                  j!                  ||t#        |      ||| j$                  | j&                        }	| j)                  t*        j,                  |	       d{   }
| j/                  |
       d{   }|S # t
        $ r Y Ow xY w7 :7 27 w)z#Execute a prepared MySQL statement.TbNr  r  )converter_str_fallback)r   )listr  r'  r   moderi   cmd_stmt_send_long_data_query_attrs_supportedr  r  r  r  rc   r   r   r   make_stmt_executetupler   _converter_str_fallbackr=  r   STMT_EXECUTEr5  )rJ   r  r  r  r   long_data_usedparam_idr  rn  execute_packetr   r  s               rK   cmd_stmt_executez MySQLConnection.cmd_stmt_execute&  s     *%
(4 
9!d8nf5!F!$DN,?,?!? 66$hX   17yN8,
9 **t/@/@MMN  
 B BB!^^==j!!!,,	N "^^==j!'+'C'C > N ~~i&<&<^~TT11&99E * < U9s^   4F%F%FF%$F%D	F%.F!/F%F#F%	FF%FF%!F%#F%c                    K   | j                  | j                  t        j                  t	        |             d{          y7 	w)z}Reset data for prepared statement sent as long data.

        The result is a dictionary with OK packet information.
        N)r   r=  r   
STMT_RESETr,   rJ   r  s     rK   cmd_stmt_resetzMySQLConnection.cmd_stmt_reset[  s3     
 	..!5!5y7NOO	
Os   8AA
Ac                 v   K   | j                  t        j                  t        |      d       d{    y7 w)zDeallocate a prepared MySQL statement.

        This method deallocates the prepared statement using the statement_id.
        Note that the MySQL server does not return anything.
        Fr  N)r=  r   
STMT_CLOSEr,   r  s     rK   cmd_stmt_closezMySQLConnection.cmd_stmt_closed  s7      nn  l#!  
 	
 	
s   /979optionsc                 R  K   |t         j                  t         j                  z  t         j                  z  t         j                  z  t         j
                  z  t         j                  z  z  st        d      |t         j                  z  r| j                  d       d{   }|t         j                  z  r| j                  d       d{   }|t         j                  z  r| j                  d       d{   }|t         j                  z  r| j                  d       d{   }|t         j
                  z  r| j                  d       d{   }|t         j                  z  r4| j                  | j                  j                  dk  rd	nd
       d{   }S 7 7 7 7 7 U7 w)a  Send the Refresh command to the MySQL server.

        This method sends the Refresh command to the MySQL server. The options
        argument should be a bitwise value using constants.RefreshOption.

        Usage example:
           RefreshOption = mysql.connector.RefreshOption
           refresh = RefreshOption.LOG | RefreshOption.INFO
           cnx.cmd_refresh(refresh)
        zInvalid command REFRESH optionzFLUSH PRIVILEGESNz
FLUSH LOGSzFLUSH TABLESz,TRUNCATE TABLE performance_schema.host_cachezFLUSH STATUS)ra  r      zRESET SLAVEzRESET REPLICA)r   GRANTLOGTABLESHOSTSTATUSREPLICAr  r   r   r   )rJ   r  rD  s      rK   cmd_refreshzMySQLConnection.cmd_refreshp  so      ""#   ! ""	#
 ##$
 =>>]((('9::C]&&&|44C])))~66C]''''UVVC])))~66C]***$$22Z? $ C 
! ;46V6sm   BF'F+F'	F
+F'5F6+F'!F!"+F'F#AF'F%F'F'F'!F'#F'%F'r  c                 N  K   d}d}	 |j                  |      }|ri| j                  j                  |||      }| j                  t        j
                  |d       d{    |t        |      z  }|j                  |      }|ri|S 7 (# t        $ r}t        d      |d}~ww xY ww)a  Send data for a column.

        This methods send data for a column (for example BLOB) for statement identified
        by statement_id. The param_id indicate which parameter the data belongs too.
        The data argument should be a file-like object.

        Since MySQL does not send anything back, no error is raised. When the MySQL
        server is not reachable, an OperationalError is raised.

        cmd_stmt_send_long_data should be called before cmd_stmt_execute.

        The total bytes send is returned.
        r?  r   F)r   r9  Nr  )	r   r   prepare_stmt_send_long_datar=  r   STMT_SEND_LONG_DATAr$  ri   r   )	rJ   r  r  r  rB  
total_sentrC  r   rk   s	            rK   r  z'MySQLConnection.cmd_stmt_send_long_data  s       

	N))J'CCC (C nn11!$) %   
 c#h&
ii
+    	N"#CD#M	Ns;   B%AB B%B B%B 	B"BB""B%c                    K   | j                          d{    | j                  j                  t        j                        }| j
                  j                  |       d{    |S 7 R7 w)zClose the current connection with the server.

        Send the QUIT command to the MySQL server, closing the current connection.
        N)r   r   r<  r   QUITrV   r   r   s     rK   rW  zMySQLConnection.cmd_quit  sX     
 ''))),,Y^^<ll  ((( 	*(s"   A-A)AA-"A+#A-+A-shutdown_typec                 B   K   | j                  d       d{    y7 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.
        SHUTDOWNN)r   )rJ   r  s     rK   cmd_shutdownzMySQLConnection.cmd_shutdown  s      nnZ(((r  c                 X  K   | j                          d{    | j                  j                  t        j                        }| j
                  j                  |dd       d{    | j                  j                  | j
                  j                          d{         S 7 7 A7 w)zSend the statistics command to the MySQL Server.

        This method sends the STATISTICS command to the MySQL server. The result is a
        dictionary with various statistical information.
        Nr   )	r   r   r<  r   
STATISTICSrV   r   parse_statisticsr   r   s     rK   cmd_statisticszMySQLConnection.cmd_statistics  s      ''))),,Y-A-ABll  A...~~..T\\5F5F5H/HII	 	* 	//Hs4   B*B$AB*$B&%6B*B(	B*&B*(B*	mysql_pidc                 |   K   t        |t              st        d      | j                  d|        d{   S 7 w)zKill a MySQL process.

        This method send the PROCESS_KILL command to the server along with the
        process ID. The result is a dictionary with the OK packet information.
        zMySQL PID must be intzKILL N)r'  r(  r  r   )rJ   r  s     rK   cmd_process_killz MySQLConnection.cmd_process_kill  s:      )S)455^^eI;$78888s   3<:<c                 z   K   | j                  | j                  t        j                         d{         S 7 w)a-  Send the DEBUG command.

        This method sends the DEBUG command to the MySQL server, which requires the
        MySQL user to have SUPER privilege. The output will go to the MySQL server
        error log and the result of this method is a dictionary with EOF packet
        information.
        N)r  r=  r   DEBUGrI   s    rK   	cmd_debugzMySQLConnection.cmd_debug  s,      dnnY__&E EFF E   .;9	;c                 z   K   | j                  | j                  t        j                         d{         S 7 w)zSend the PING command.

        This method sends the PING command to the MySQL server. It is used to check
        if the the connection is still valid. The result of this method is dictionary
        with OK packet information.
        N)r   r=  r   PINGrI   s    rK   rJ  zMySQLConnection.cmd_ping  s*      T^^INN%CCDDCr   userr   r   r   r   r   r   r   c
                 f  K   t        |t              st        d      |dk  rt        d      d| _        || _        || _        || _        || _        || _        | j                  r|| j                  k7  r| j                  }| j                          d{    | j                  rt        d      |r|| _        |	| _        | j                  j                  | j                   | j                  | j
                  | j"                  || j$                  | j&                  | j(                  | j*                  | j,                  
      }
t/        j0                  d|
       | j2                  j5                  |
d          d{    | j7                  | j2                  j9                          d{         }| j$                  t:        j<                  z  s|r| j?                  |       d{    tA        jB                  |      | _"        | jD                  jF                  | _$        | j7                  |      S 7 7 7 7 Qw)	zChange the current logged in user.

        This method allows to change the current logged in user information.
        The result is a dictionary with OK packet information.
        zcharset must be an integerr   z2charset should be either zero or a postive integerr.   Nz-Change user is not supported with compression)
r   r   r   r   r   r   ssl_enabledr   r   r   z&Protocol::HandshakeResponse packet: %s)%r'  r(  r  rC   r   r   r   r   r   r   	_compressr   r   r   r   	make_authrG   r   rc   r   r   r   r   r?   r   rV   r   r   r   r   r   r   r2   r   r   rU   r   )rJ   r  r   r   r   r   r   r   r   r   r   	ok_packets               rK   cmd_change_userzMySQLConnection.cmd_change_user  s    " '3'9::Q;QRR
!###??x4??:H'')))>>#$STT$3D!#5 ))ooZZ^^^^++(())--"55 * 
 	=vFll  +++OO$,,*;*;*=$=>	""Z%?%??X""8,,, **73!]]// y))E 	*. 	,$= -sJ   BH1H(C!H14H+5,H1!H-";H1H/AH1+H1-H1/H1)rD   N)Nr   NTr   )F)Fr.   r   )NNNNNN)FNN)NFNNN)FFF)r.   ) r
  r   )N)	 r  r  r   r  r  r  r  r  )Nr  
__module____qualname____doc__rC   r(  __annotations__propertyr   rL   rl   r   r}   r&   r   r]   r^   r  r%   r   r   r$   r  r  r0  r
   r3  r   r   r   r#   r5  rF  r  r=  r   r  rH  rG  rO  rQ  r  rY  r	   r   r   r0   r3   rX  r'   rs  rq  r  r  r  r   r)   r   r   r  r  r   r  r   r"   r  r  r  r  r  rW  r  r(   r  r  r  rJ  r	  r
  rM   rK   r   r   o   s   =L#x}  &B<(+# +* +BLHH3T3 3< 3N3 N4 N4% 4M 40s 0| 0d&;5 &;Z &;P: :$sCx. : %,%,	|U3_(=}#LMM	N%,T %)"& $()!)!) 5/!) 	!)
 !) !) #&!) 
)	!)H >C!!!6:!	!FBT BD  HIVV14VADV	V2"0 %*JS!) $("#'<@%)&*K4.K d^K 4.	K
 t$789K TNK d^K 
K^ 37"	 $/0 d^	
 
x (="99	:*  $37"7}7 7 $/0	7
 d^7 7 
tG}h}55	67r,.D 
# 
, 
 #ww w 	w
 w 
wr&G$&G	
D(	)&GP	" 	"C 	" 	"	eCo!6677	8F .0$&33 )*3 SM	3
 3 
|U3_(=}#LMM	N3j
 
 


 

 

& & &P""+."6>"	"H ) ) )
Jo 
J9 9 9G GE E !"$B*B* B* 	B*
 B* B* B* B* B*  B* 
,	B*rM   )Rr  __all__rY   rU  r  r   rT   r   r  r  decimalr   ior   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r  r   	constantsr   r   r   r   r   r   errorsr   r   r   r   r   r   r    r!   rk  r"   r#   r$   r%   r&   r'   r(   r)   utilsr*   r+   r,   r-   	abstractsr/   r0   r1   r2   rX  r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   networkr@   rA   r   r
  rM   rK   <module>r     s   > K
     	          	 	 		 	 	 ? > O O      4J*- J*rM   