o
    g                     @  sB  d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	 ddl
mZmZmZmZmZmZ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" ddl#m#Z# ddl$m%Z%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 erddl1m2Z2 dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:G dd dZ;dS )z,Implements the MySQL Client/Server protocol.    )annotationsN)deque)DecimalDecimalException)	TYPE_CHECKINGAnyDequeDictListOptionalSequenceTupleUnion   )utils)PARAMETER_COUNT_AVAILABLE
ClientFlag	FieldFlag	FieldType	ServerCmd)MySQLConverter)DatabaseErrorInterfaceErrorProgrammingErrorget_exception)logger)MySQLAuthPluginget_auth_plugin)"MySQLCachingSHA2PasswordAuthPlugin)BinaryProtocolTypeDescriptionTypeEofPacketTypeHandShakeTypeOkPacketTypeStatsPacketType
StrOrBytes)MySQLSocket
            -   i   @c                   @  s  e Zd ZdZedddZeddd	Zedd
dZedddZedddZ	e			ddd#d$Z
eded%eddddddf
dd,d-Zeed%efdd.d/Zeddd3d4Zeddd8d9Zedd;d<Zedd>d?ZeddAdBZedddFdGZddIdJZedddNdOZ	5	dddWdXZedd[d\Zedd^d_Ze	`dddbdcZeddfdgZeddidjZ	CdddndoZ	5	C	dddrdsZeddudvZeddydzZ edd|d}Z!edddZ"edddZ#			%		`		ddddZ$dS )MySQLProtocolzRImplements MySQL client/server protocol

    Create and parses MySQL packets.
    pktbytesreturnc                 C  s    | d t ks
td| dd S )a  Parse a MySQL auth more data packet.

        Args:
            pkt: Packet representing an `auth more data` response.

        Returns:
            auth_data: Authentication method data (see [1]).

        Raises:
            InterfaceError: If packet's status tag doesn't
                            match `protocol.EXCHANGE_FURTHER_STATUS`.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_auth_more_data.html
           z"Failed parsing AuthMoreData packet   N)EXCHANGE_FURTHER_STATUSr   )r-    r3   R/var/www/html/api-tag/env/lib/python3.10/site-packages/mysql/connector/protocol.pyparse_auth_more_data\   s   z"MySQLProtocol.parse_auth_more_dataTuple[str, bytes]c                 C  sV   | d t kr
tdtj| dd dd\} }| r%| d dkr%| dd } | | fS )	a|  Parse a MySQL auth switch request packet.

        Args:
            pkt: Packet representing an `auth switch request` response.

        Returns:
            plugin_name: Name of the client authentication plugin to switch to.
            plugin_provided_data: Plugin provided data (see [1]).

        Raises:
            InterfaceError: If packet's status tag doesn't
                            match `protocol.AUTH_SWITCH_STATUS`.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/                latest/page_protocol_connection_phase_packets_protocol_
                auth_switch_request.html
        r0   z'Failed parsing AuthSwitchRequest packetr1   N    endr   )AUTH_SWITCH_STATUSr   r   read_stringdecode)r-   plugin_namer3   r3   r4   parse_auth_switch_requestr   s   z'MySQLProtocol.parse_auth_switch_requestc                 C  sF   t | dd d\} }|tkrtdt j| dd\} }| | fS )a  Parse a MySQL auth next factor packet.

        Args:
            pkt: Packet representing an `auth next factor` response.

        Returns:
            plugin_name: Name of the client authentication plugin.
            plugin_provided_data: Initial authentication data for that
                                  client plugin (see [1]).

        Raises:
            InterfaceError: If packet's packet type doesn't
                            match `protocol.MFA_STATUS`.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_auth_                next_factor_request.html
        r0   Nr   z.Failed parsing AuthNextFactor packet (invalid)r7   r8   )r   read_int
MFA_STATUSr   r<   r=   )r-   statusr>   r3   r3   r4   parse_auth_next_factor   s
   z$MySQLProtocol.parse_auth_next_factor
conn_attrsDict[str, str]c              	     s    D ]} | du rd |< qt  fdd D t   t   }td|g} D ]*}|tdt| ||  |tdt |  | |   q/d|S )az  Encode the connection attributes.

        Args:
            conn_attrs: Connection attributes.

        Returns:
            serialized_conn_attrs: Serialized connection attributes as per [1].

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_handshake_response.html
        N c                 3  s$    | ]}t |t  |  V  qd S N)len).0xrD   r3   r4   	<genexpr>   s   " z0MySQLProtocol.make_conn_attrs.<locals>.<genexpr><B    )	sumrH   keysvaluesstructpackappendencodejoin)rD   	attr_nameconn_attrs_lenconn_attrs_packetr3   rK   r4   make_conn_attrs   s"   


zMySQLProtocol.make_conn_attrsclient_flagsintdatabaseOptional[str]c                 C  s   | t j@ r|r| d S dS )a  Prepare database string for handshake response.

        Args:
            client_flags: Integer representing client capabilities flags.
            database: Initial database name for the connection.

        Returns:
            serialized_database: Serialized database name as per [1].

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_handshake_response.html
        r7   )r   CONNECT_WITH_DBrU   )r[   r]   r3   r3   r4   connect_with_db   s   zMySQLProtocol.connect_with_dbNF	auth_datausernamestrpasswordauth_pluginauth_plugin_classssl_enabledboolplugin_configOptional[Dict[str, Any]]Tuple[bytes, MySQLAuthPlugin]c           
   
   C  s   |s|dkrdt |||dfS |du ri }zt|||||d}|j| fi |}W n ttfy@ }	 ztd|	 |	d}	~	ww |du rMtd|j tt|| }||fS )a  Prepare the first authentication response.

        Args:
            auth_data: Authorization data from initial handshake.
            username: Account's username.
            password: Account's password.
            client_flags: Integer representing client capabilities flags.
            auth_plugin: Authorization plugin name.
            auth_plugin_class: Authorization plugin class (has higher precedence
                               than the authorization plugin name).
            ssl_enabled: Whether SSL is enabled or not.
            plugin_config: Custom configuration to be passed to the auth plugin
                           when invoked. The parameters defined here will override
                           the ones defined in the auth plugin itself.

        Returns:
            auth_response: Authorization plugin response.
            auth_strategy: Authorization plugin instance created based
                           on the provided `auth_plugin` and `auth_plugin_class`
                           parameters.

        Raises:
            InterfaceError: If authentication fails or when got a NULL auth response.
        rF   r7   )rg   NzFailed authentication: z8Got NULL auth response while authenticating with plugin )	r   r   auth_response	TypeErrorr   namer   lc_intrH   )
ra   rb   rd   re   rf   rg   ri   auth_strategyrl   errr3   r3   r4   auth_plugin_first_response   s.   "z(MySQLProtocol.auth_plugin_first_responser   	handshaker"   charsetmax_allowed_packetOptional[Dict[str, str]]is_change_user_requestc              
   C  s  |  }g }|
rtd td | du rtdd| ddu r'tddz|p-| d }W n ttfyF } z	td| d	dd}~ww td
| |
ra|t	dt
| dtj| nd}|t	d| t
| d|||| tj| d ||||||d\}}|| |t|| |
r|t	d| |tj@ r||  d  |tj@ r|	dur|t|	 d||fS )a  Make a MySQL Authentication packet.

        Args:
            handshake: Initial handshake.
            username: Account's username.
            password: Account's password.
            database: Initial database name for the connection
            charset: Client charset (see [2]), only the lower 8-bits.
            client_flags: Integer representing client capabilities flags.
            max_allowed_packet: Maximum packet size.
            auth_plugin: Authorization plugin name.
            auth_plugin_class: Authorization plugin class (has higher precedence
                               than the authorization plugin name).
            conn_attrs: Connection attributes.
            is_change_user_request: Whether is a `change user request` operation or not.
            ssl_enabled: Whether SSL is enabled or not.
            plugin_config: Custom configuration to be passed to the auth plugin
                           when invoked. The parameters defined here will override
                           the one defined in the auth plugin itself.

        Returns:
            handshake_response: Handshake response as per [1].
            auth_strategy: Authorization plugin instance created based
                           on the provided `auth_plugin` and `auth_plugin_class`.

        Raises:
            ProgrammingError: Handshake misses authentication info.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_handshake_response.html

            [2]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_basic_character_set.html#a_protocol_character_set
        zGot a `change user` requestzStarting authorization phaseNzGot a NULL handshakera   z$Handshake misses authentication infore   z-Handshake misses authentication plugin info ()z#The provided initial strategy is %srM   sxxxxxxxxxxxxxxxxxxxxxxxxz<IIB)ra   rb   rd   re   rf   rg   ri   <Hr7   rN   )rU   r   debugr   getrm   KeyErrorrT   rR   rS   rH   r   CHANGE_USERr,   rr   r`   r   PLUGIN_AUTHCONNECT_ARGSrZ   rV   )rs   rb   rd   r]   rt   r[   ru   re   rf   rD   rw   rg   ri   
b_usernameresponse_payloadrq   fillerrl   rp   r3   r3   r4   	make_auth  sp   3






	
zMySQLProtocol.make_authc                 C  s$   d t|t|t| dgS )a  Make a SSL authentication packet (see [1]).

        Args:
            charset: Client charset (see [2]), only the lower 8-bits.
            client_flags: Integer representing client capabilities flags.
            max_allowed_packet: Maximum packet size.

        Returns:
            ssl_request_pkt: SSL connection request packet.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_ssl_request.html

            [2]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_basic_character_set.html#a_protocol_character_set
        rN   s                          )rV   r   	int4store	int1store)rt   r[   ru   r3   r3   r4   make_auth_ssl  s   zMySQLProtocol.make_auth_sslcommandargumentOptional[bytes]c                 C  s   t | }|du r|S || S )z(Make a MySQL packet containing a commandN)r   r   )r   r   datar3   r3   r4   make_command  s   
zMySQLProtocol.make_commandr   statement_idrowsc                 C  s   t | t | S )z0Make a MySQL packet with Fetch Statement command)r   r   )r   r   r3   r3   r4   make_stmt_fetch  s   zMySQLProtocol.make_stmt_fetchpacketc           	   	   C  s  i }t d| dd d |d< |d tkr"td|d  dt tj| dd dd	\} |d
< t d| dd \|d< }}|d< |d< }}|d
  |d
< | dd } t|| }d}|tj	@ r|rmt
d|d nd}| d| }| |d } |d dkr|dd }|tj@ rd| vr|d
 drd| } |d< ntj| dd	\} |d< |d d|d< nd|d< || |d< ||d< |S )zParse a MySQL Handshake-packet.<xxxxBr   r1   protocolz$Protocol mismatch; server version = z, client version = Nr7   r8   server_version_originalz<I8sx2sBH2sBxxxxxxxxxx   server_threadidrt   server_statusrN         r:   z5.5.8re   utf-8mysql_native_passwordra   capabilities)rR   unpackPROTOCOL_VERSIONr   r   r<   r=   intreadr   SECURE_CONNECTIONminr   
startswith)	r   res
auth_data1capabilities1capabilities2auth_data_lengthr   
auth_data2sizer3   r3   r4   parse_handshake  sR   

zMySQLProtocol.parse_handshaker#   c              
   C  s   | d dks
t di }zTtd| dd d |d< t| dd \} |d< t| \} |d	< td
| dd \|d< |d< | dd } | r^t| \} |d< |d d|d< W |S W |S  tyq } zt d|d}~ww )zParse a MySQL OK-packetr0   r   z#Failed parsing OK packet (invalid).r   r1   field_countNaffected_rows	insert_idz<HHstatus_flagwarning_countinfo_msgr   zFailed parsing OK packet.)r   rR   r   r   read_lc_intread_lc_stringr=   
ValueError)r   	ok_packetrq   r3   r3   r4   parse_ok  s,   
zMySQLProtocol.parse_okOptional[int]c              
   C  sF   zt | dd d }|W S  tjtfy" } ztd|d}~ww )z=Parse a MySQL packet with the number of columns in result setr0   Nr   zFailed parsing column count)r   r   rR   errorr   r   )r   countrq   r3   r3   r4   parse_column_count
  s   
z MySQLProtocol.parse_column_countr   encodingr    c              	   C  s   t | dd \} }t | \} }t | \} }t | \} }t | \} }t | \} }ztd| \}}}}}W n tjyH   tddw |||dddd| tj@ ||f	S )zParse a MySQL column-packet.r0   Nz	<xHIBHBxxz!Failed parsing column information)	r   r   rR   r   r   r   r=   r   NOT_NULL)r   r   _rn   rt   column_typeflagsr3   r3   r4   parse_column  s6   


zMySQLProtocol.parse_columnr!   c              
   C  s   |d dkr|  |S d}i }ztd|}W n tjy) } zt||d}~ww |d dkr6t|dks:t||d	 |d
< |d |d< |S )zParse a MySQL EOF-packetr0   r   zFailed parsing EOF packet.z<xxxBBHHNr   r(   	   r)   r      r   )r   rR   r   r   r   rH   )selfr   err_msgr   unpackedrq   r3   r3   r4   	parse_eof4  s   

zMySQLProtocol.parse_eofTwith_headerr$   c           	      C  s  d}i }dg}d}|r| dd  d}n|  d}|D ]c}zdd | dd	D \}}W n ty> } zt||d}~ww |d
}zt|||< W q ttfy   zt|d
||< W n ty| } zt| d| dt| d|d}~ww Y qw |S )zParse the statistics packetz)Failed getting COM_STATISTICS informationrN   r0   Ns     c                 S  s   g | ]}|  qS r3   )strip)rI   vr3   r3   r4   
<listcomp>V      z2MySQLProtocol.parse_statistics.<locals>.<listcomp>   :r)   r   z (:rx   )	splitr   r   r=   r\   r~   r   r   repr)	r   r   errmsgr   pairslblpairvalrq   r3   r3   r4   parse_statisticsH  s6   


 zMySQLProtocol.parse_statisticssockr&   versionTuple[int, ...]r   read_timeoutATuple[List[Tuple[Optional[bytes], ...]], Optional[EofPacketType]]c                 C  s,  |}g }d}d}d}		 |s|	|kr	 ||fS | |}
|
drV|
dd g}| |}
|
drD||
dd  | |}
|
ds1||
dd  td|}n!|
d dkrj|
d dk rj| |
}d}nd}tt|
dd }|du r|dur|| n|du r|du rt|
|	d	7 }	q)
zRead MySQL text result

        Reads all or given number of rows from the socket.

        Returns a tuple with 2 elements: a list with all rows and
        the EOF packet.
        Nr   Ts   r0   rN   r(      r   )	recvr   rT   r   read_lc_string_listrV   r   r.   r   )r   r   r   r   r   r   r   eofrowdatair   datasr3   r3   r4   read_text_resulte  s<   






zMySQLProtocol.read_text_resultfieldTuple[bytes, int]c                 C  s   |d t jkrd}d}n+|d t jkrd}d}n|d t jt jfv r'd}d}n|d t jkr3d}d}ntd	|d
 tj@ rB|	 }| |d t
|| d| d fS )z%Parse an integer from a binary packetr   <b<hr)   <ir0   <qr   zUnknown integer typer   Nr   )r   TINYSHORTINT24LONGLONGLONGr   r   UNSIGNEDupperrR   r   )r   r   format_lengthr3   r3   r4   _parse_binary_integer  s    $z#MySQLProtocol._parse_binary_integerTuple[bytes, float]c                 C  sD   |d t jkrd}d}nd}d}| |d t|| d| d fS )z)Parse a float/double from a binary packetr   r   <dr0   z<fNr   )r   DOUBLErR   r   )r   r   r   r   r3   r3   r4   _parse_binary_float  s   $z!MySQLProtocol._parse_binary_floatutf8Tuple[bytes, Decimal]c                 C  s    t | \} }| t||fS )z(Parse a New Decimal from a binary packet)r   r   r   r=   )r   rt   valuer3   r3   r4   _parse_binary_new_decimal  s   z'MySQLProtocol._parse_binary_new_decimal
field_type?Tuple[bytes, Optional[Union[datetime.date, datetime.datetime]]]c              	   C  s   | d }d}|dkr8t d| dd d }| d }| d }|tjtjfv r/tj|||d}nAtj|||d}n8|dkrpd}|d	krPt d
| d|d  d }tjt d| dd d | d | d | d | d | d |d}| |d d |fS )z&Parse a timestamp from a binary packetr   Nr0   r{   r   r   )yearmonthdayr      <Ir   r1      )r   r   r   hourminutesecondmicrosecond)rR   r   r   DATETIME	TIMESTAMPdatetimedate)r   r   r   r   r   r   r   mcsr3   r3   r4   _parse_binary_timestamp  s.   
z%MySQLProtocol._parse_binary_timestamp Tuple[bytes, datetime.timedelta]c                 C  s   | d }|s| dd t  fS | d|d  }d}|dkr*td|dd d }td|dd d }|d dkr@|d9 }t j||d ||d	 |d d
}| |d d |fS )z'Parse a time value from a binary packetr   r   Nr   r   r1   r:   r   r  )dayssecondsmicrosecondsminuteshours)r  	timedeltarR   r   )r   r   r   r
  r  tmpr3   r3   r4   _parse_binary_time  s$   z MySQLProtocol._parse_binary_timefieldsList[DescriptionType]Tuple[BinaryProtocolType, ...]c           
   	   C  s&  t |d d d }dd |d| D }||d }g }d}t|D ]\}}	|t|d d  d|d d > @ r?|d q#|	d tjtjtjtjtj	fv r]| 
||	\}}|| q#|	d tjtjfv ru| ||	\}}|| q#|	d tjtjfv r| ||\}}|| q#|	d tjtjtjfv r| ||	d \}}|| q#|	d tjkr| |\}}|| q#|	d tjkrt|\}}|t| q#|	d tjks|	d d	krt|\}}|| q#t|\}}z
||| W q# ty   || Y q#w t |S )
z(Parse values from a binary result packetr   r)   r   c                 S  s   g | ]}t |qS r3   )r\   )rI   r   r3   r3   r4   r     r   z6MySQLProtocol._parse_binary_values.<locals>.<listcomp>r   Nr   ?   )!rH   	enumerater\   rT   r   r   r   r   r   r   r   r   FLOATr   DECIMAL
NEWDECIMALr   r  DATEr  r  TIMEr  VECTORr   r   r   _vector_to_pythonr   BINARYr=   UnicodeDecodeErrortuple)
r   r  r   rt   null_bitmap_lengthnull_bitmaprQ   r   posr   r3   r3   r4   _parse_binary_values  s^   $
z"MySQLProtocol._parse_binary_valuescolumnsDTuple[List[Tuple[BinaryProtocolType, ...]], Optional[EofPacketType]]c                 C  s   g }d}d}d}		 |dur	 ||fS |	|kr	 ||fS t ||}
|
d dkr0| |
}d}n|
d dkrCd}| ||
dd |}|du rQ|durQ|| n|du r]|du r]t|
|	d7 }	q	)zwRead MySQL binary protocol result

        Reads all or given number of binary resultset rows from the socket.
        Nr   Tr0   r(   r1   r   )r.   r   r   r'  rT   r   )r   r   r(  r   rt   r   r   r   rQ   r   r   r3   r3   r4   read_binary_result6  s0   
z MySQLProtocol.read_binary_resultDict[str, int]c              
   C  s   | d dks
t di }z5t| dd d\} |d< t| d\} |d< t| d\} |d	< | d
d } t| d\} |d< W |S  tyR } zt d|d}~ww )z(Parse a MySQL Binary Protocol OK packet.r0   r   zFailed parsing Binary OK packetr1   Nr   r)   num_columns
num_paramsr   r   )r   r   r@   r   )r   ok_pktrq   r3   r3   r4   parse_binary_prepare_ok\  s   
z%MySQLProtocol.parse_binary_prepare_okr   Tuple[bytes, int, int]c                 C  s   d}d}| dk r,| dkrd}t j}n?| dkrd}t j}n5| dkr&d}t j}n+d	}t j}n%d
}| dkr8d}t j}n| dkrBd}t j}n| dkrLd}t j}nt j}d}t|| ||fS )z0Prepare an integer for the MySQL binary protocolNr   ir   i r   i   r   r      r*   rM   i  r{   l    r   z<Q)r   r   r   r   r   rR   rS   )r   r   r   r   r3   r3   r4   prepare_binary_integern  s6   z$MySQLProtocol.prepare_binary_integer'Union[datetime.date, datetime.datetime]c                 C  s   t | tjr
tj}nt | tjrtj}ntdt| j	t
| jt
| jg}t | tjrQ|t
| jt
| jt
| jg | jdkrQ|t| j d|}t
t|| |fS )a  Prepare a timestamp object for the MySQL binary protocol

        This method prepares a timestamp of type datetime.datetime or
        datetime.date for sending over the MySQL binary protocol.
        A tuple is returned with the prepared value and field type
        as elements.

        Raises ValueError when the argument value is of invalid type.

        Returns a tuple.
        z2Argument must a datetime.datetime or datetime.dater   rN   )
isinstancer  r   r  r	  r  r   r   	int2storer   r   r   r   extendr  r  r  r  rT   r   rV   rH   )r   r   chunkspackedr3   r3   r4   prepare_binary_timestamp  s(   







z&MySQLProtocol.prepare_binary_timestamp(Union[datetime.timedelta, datetime.time]c           
      C  s  t | tjtjfstdtj}d}d}tg }t | tjrP| jdk r%d}t	| j
d\}}t	|d\}}|tt| jt|t|t|g | j}n|tdt| jt| jt| jg | j}|ru|t| |t| d|}	tt|	|	 |fS )a  Prepare a time object for the MySQL binary protocol

        This method prepares a time object of type datetime.timedelta or
        datetime.time for sending over the MySQL binary protocol.
        A tuple is returned with the prepared value and field type
        as elements.

        Raises ValueError when the argument value is of invalid type.

        Returns a tuple.
        z3Argument must a datetime.timedelta or datetime.timer   Nr   i  <   rN   )r4  r  r  timer   r   r  r   r  divmodr  r6  r   r   absr   r  r  r  r  r  rT   
appendleftrV   rH   )
r   r   negativer
  r7  r  	remainderminssecsr8  r3   r3   r4   prepare_binary_time  s@   




z!MySQLProtocol.prepare_binary_time	statementparamr   c                 C  s   d t| t||gS )zMPrepare long data for prepared statements

        Returns a string.
        rN   )rV   r   r   r5  )rE  rF  r   r3   r3   r4   prepare_stmt_send_long_data  s   z)MySQLProtocol.prepare_stmt_send_long_datar3   Sequence[BinaryProtocolType]
parametersr   r   long_data_used Optional[Dict[int, Tuple[bool]]]query_attrs.Optional[List[Tuple[str, BinaryProtocolType]]]converter_str_fallbackc	              	   C  s  d}	dgt |d d  }
g }g }d}t |}g }|s|n|t }|dkr'd}|du r-i }|rJt|}|D ]	\}}|| q5dgt |d d  }
|sO|r|t |krYtd	t|D ]-\}}d}|du r|
|d   d|d > O  < |ttj	t|  q]||v r|| d rtj
}ntj}nt|tr| |\}}}|| nt|tr||}|tt ||  tj}nt|tr|tt ||  tj}nt|tr|tt t||t||  tj}net|tr|td
| tj}nRt|tjtjfr"| |\}}|| n;t|tjtjfr9| |\}}|| n$|rSt||}|tt ||  tj}n
td|j j! d|t|t|  |r|d |kr|||  d |}|tt ||  q]t"|t|t"|	g}|dur|t | }n|}|r|dur|t| |#dd |
D  |td d}|D ]'}|| |dur|d |kr||||   n|d |d7 }q|D ]}|| qd$|S )z6Make a MySQL packet with the Statement Execute commandr   r   r   r   rN   utf8mb4r   NzTFailed executing prepared statement: data values does not match number of parametersr   z&MySQL binary protocol can not handle 'z	' objectsc                 S  s   g | ]}t d |qS )B)rR   rS   )rI   bitr3   r3   r4   r   l  s    z3MySQLProtocol.make_stmt_execute.<locals>.<listcomp>r7   )%rH   r   listrT   r   r  r   r   r   NULLBLOBSTRINGr4  r\   r2  rc   rU   ro   r.   r   r  floatrR   rS   r   r  r	  r9  r  r<  rD  r   	__class____name__r   r6  rV   )r   r   r   rI  r   rJ  rt   rL  rN  iteration_countr%  rQ   typesr8  data_lenquery_attr_namesr   attr_valr&  r   _flagsr   rn   r   parameter_countr   a_typea_valuer3   r3   r4   make_stmt_execute  s   











zMySQLProtocol.make_stmt_execute)r-   r.   r/   r.   )r-   r.   r/   r6   )rD   rE   r/   r.   )r[   r\   r]   r^   r/   r.   )NFN)ra   r.   rb   rc   rd   rc   re   rc   rf   r^   rg   rh   ri   rj   r/   rk   )rs   r"   rb   rc   rd   rc   r]   r^   rt   r\   r[   r\   ru   r\   re   r^   rf   r^   rD   rv   rw   rh   rg   rh   ri   rj   r/   rk   )rt   r\   r[   r\   ru   r\   r/   r.   rG   )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   )r   r.   r   rc   r/   r    )r   r.   r/   r!   )T)r   r.   r   rh   r/   r$   )r   N)
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.   rt   rc   r/   r   )r   r.   r   r\   r/   r   )r   r.   r/   r  )r  r  r   r.   rt   rc   r/   r  )r   r   N)r   r&   r(  r  r   r\   rt   rc   r   r   r/   r)  )r   r.   r/   r+  )r   r\   r/   r0  )r   r3  r/   r   )r   r:  r/   r   )rE  r\   rF  r\   r   r.   r/   r.   )r3   r3   r   Nr   NF)r   r\   r   rH  rI  r   r   r\   rJ  rK  rt   rc   rL  rM  rN  rh   r/   r.   )%rX  
__module____qualname____doc__staticmethodr5   r?   rC   rZ   r`   rr   DEFAULT_CHARSET_IDDEFAULT_MAX_ALLOWED_PACKETr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r'  r*  r/  r2  r9  rD  rG  rb  r3   r3   r3   r4   r,   V   s    <y 3
  0>&!*7
r,   )<re  
__future__r   r  rR   collectionsr   decimalr   r   typingr   r   r   r	   r
   r   r   r   r   rF   r   	constantsr   r   r   r   r   
conversionr   errorsr   r   r   r   r   pluginsr   r   plugins.caching_sha2_passwordr   rZ  r   r    r!   r"   r#   r$   r%   networkr&   r   r;   r2   	OK_STATUSrA   
ERR_STATUSrg  rh  r,   r3   r3   r3   r4   <module>   s4   ,$
