o
    –¨ÊhÚy  ã                   @   sì  d Z ddlZddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZ d	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZG dd „ d eƒZG d!d"„ d"eƒZG d#d$„ d$eƒZG d%d&„ d&eƒZG d'd(„ d(eƒZG d)d*„ d*eƒZ G d+d,„ d,eƒZ!G d-d.„ d.eƒZ"G d/d0„ d0eƒZ#G d1d2„ d2eƒZ$G d3d4„ d4eƒZ%G d5d6„ d6eƒZ&G d7d8„ d8eƒZ'G d9d:„ d:eƒZ(G d;d<„ d<e(ƒZ)G d=d>„ d>e(ƒZ*G d?d@„ d@e*ƒZ+G dAdB„ dBe+ƒZ,G dCdD„ dDe*ƒZ-dS )Ez%Implementation of the Result classes.é    N)ÚdatetimeÚ	timedeltaé   )ÚDbDoc)ÚMYSQL_CHARACTER_SETS)ÚSTRING_TYPES)Údecode_from_bytesÚ
deprecatedc                 C   s²   t |ƒdkrd S z(tjttjttjttjt	tj
ttjttjttjttjttjttjti|  |ƒW S  tyX } ztj d |¡¡ tj d | d¡¡¡ W Y d }~d S d }~ww )Nr   ú{0}Úhex)ÚlenÚColumnProtoTypeÚSINTÚvarsint_from_protobufÚUINTÚvarint_from_protobufÚBYTESÚbytes_from_protobufÚDATETIMEÚdatetime_from_protobufÚTIMEÚtime_from_protobufÚFLOATÚfloat_from_protobufÚDOUBLEÚdouble_from_protobufÚBITÚSETÚset_from_protobufÚENUMÚDECIMALÚdecimal_from_protobufÚKeyErrorÚsysÚstderrÚwriteÚformatÚencode)Úcol_typeÚpayloadÚerr© r+   ú?/var/www/html/env/lib/python3.10/site-packages/mysqlx/result.pyÚfrom_protobuf,   s2   õôô€ýr-   c                 C   s   t | d d… ƒS )Néÿÿÿÿ)r   ©r)   r+   r+   r,   r   D   ó   r   c                 C   ó   t | ƒdksJ ‚t d| ¡S )Né   z<f©r   ÚstructÚunpackr/   r+   r+   r,   r   I   ó   r   c                 C   r1   )Né   z<dr3   r/   r+   r+   r,   r   N   r6   r   c                 C   s˜   t | ƒdkr
tdƒ‚d}d}d}| D ]5}t|tƒr|nt|ƒ}|d@ dk}|d@ }||K }||O }|r?|| |d d … f  S |d7 }|d7 }qtdƒ‚)Nr   zPayload is emptyé€   é   r   é   zPayload too short)r   Ú
ValueErrorÚ
isinstanceÚintÚordÚEOFError)r)   ÚcurÚiÚshiftÚitemÚcharÚeosÚcur_bitsr+   r+   r,   Úvarint_from_protobuf_streamS   s    
rG   c                 C   s$   t | ƒ\}} t| ƒdkrtdƒ‚|S )Nr   úPayload too long©rG   r   r;   ©r)   rA   r+   r+   r,   r   i   s   r   c                 C   sN   t | ƒ\}} t| ƒdkrtdƒ‚|d@ r!| }|d? }|dO }|S |d? }|S )Nr   rH   r   l            rI   rJ   r+   r+   r,   r   q   s   þr   c                 C   s˜   g }	 z=t | ƒ\}} t| ƒ|k r't| ƒdkr#|dkr#t|ƒdkr#g W S tdƒ‚| | d |… ¡ | |d … } t| ƒdkr?W |S W n
 tyJ   Y |S w q)NTr   r   zInvalid Set encoding)rG   r   r;   Úappend)r)   Úset_pbÚ	field_lenr+   r+   r,   r   �   s&    ûþòr   c                 C   s  g }d }t | d tƒr| d nt| d ƒ}| dd … } | D ]`}t |tƒr&|nt|ƒ}|d@ d? }|d@ }|dk r[| |¡ |dk rG| |¡ q|dkrOd} n/|dkrWd} n'td	ƒ‚|dkrid}|dksgJ ‚ n|dkrwd}|dksuJ ‚ ntd
 |¡ƒ‚t ||| f¡S )Nr   r   éð   r2   é   é
   é   é   zInvalid BCDzInvalid BCD: {0})r<   r=   r>   rK   r;   r&   ÚdecimalÚDecimal)r)   ÚdigitsÚsignÚscalerC   rD   Úhigh_bcdÚlow_bcdr+   r+   r,   r!   –   s:   "
r!   c                 C   s�   d}d}d}d}t | ƒ\}} t | ƒ\}} t | ƒ\}} zt | ƒ\}} t | ƒ\}} t | ƒ\}} t | ƒ\}} W n	 ty=   Y nw t|||||||ƒS )Nr   )rG   r;   r   )r)   ÚhourÚminutesÚsecondsÚusecondsÚyearÚmonthÚdayr+   r+   r,   r   º   s    ÿr   c                 C   sº   d}d}d}d}| d dk}| dd … } zt | ƒ\}} t | ƒ\}} t | ƒ\}} t | ƒ\}} W n	 ty7   Y nw |rU|rA|d9 }n|rH|d9 }n|rO|d9 }n|rU|d9 }t||||d�S )Nr   r   r.   )Úhoursr[   r\   Úmicroseconds)rG   r;   r   )r)   rZ   r[   r\   r]   Únegater+   r+   r,   r   Ï   s4   ÿ


ÿr   c                   @   ó   e Zd ZdZdS )Ú
Collationsé!   N)Ú__name__Ú
__module__Ú__qualname__ÚUTF8_GENERAL_CIr+   r+   r+   r,   re   ï   ó    re   c                   @   sø   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%e&d$d%„ ƒZ'e&d&d'„ ƒZ(e&d(d)„ ƒZ)e&d*d+„ ƒZ*e&d,d-„ ƒZ+e&d.d/„ ƒZ,e&d0d1„ ƒZ-e&d2d3„ ƒZ.d4S )5Ú
ColumnTyper   é   é   r2   é   é   r:   r7   é	   rP   é   rQ   rR   é   rO   é   é   é   é   é   é   é   é   é   é   é   é   é   é   é   é   é    rf   é"   é#   c                 C   s*   t | ƒ ¡ D ]\}}||kr|  S qd S ©N)ÚvarsÚitems)ÚclsÚneedleÚkeyÚvaluer+   r+   r,   Ú	to_string  s
   ÿzColumnType.to_stringc                 C   s   t | | ¡ d ƒS r‡   )ÚgetattrÚupper)rŠ   rŒ   r+   r+   r,   Úfrom_string  r0   zColumnType.from_stringc                 C   ó   || j | jfv S r‡   )ÚCHARÚVARCHAR©rŠ   r(   r+   r+   r,   Úis_char#  r0   zColumnType.is_charc                 C   r’   r‡   )ÚBINARYÚ	VARBINARYr•   r+   r+   r,   Ú	is_binary'  r0   zColumnType.is_binaryc                 C   s   || j | j| j| jfv S r‡   )ÚTEXTÚTINYTEXTÚ
MEDIUMTEXTÚLONGTEXTr•   r+   r+   r,   Úis_text+  s   ÿzColumnType.is_textc                 C   s   || j | j| j| j| jfv S r‡   )ÚREALr   r   r    ÚNUMERICr•   r+   r+   r,   Úis_decimals0  s   ÿzColumnType.is_decimalsc                 C   s    || j | j| j| j| j| jfv S r‡   )r   ÚTINYINTÚSMALLINTÚ	MEDIUMINTÚINTÚBIGINTr•   r+   r+   r,   Ú
is_numeric5  s   ÿzColumnType.is_numericc                 C   r’   r‡   )r   r   r•   r+   r+   r,   Úis_finite_set:  r0   zColumnType.is_finite_setN)/rg   rh   ri   r   r¢   r£   r¤   r¥   r¦   rŸ   r   r    r    r   ÚJSONÚSTRINGr   r   ÚDATEr   Ú	TIMESTAMPr   r   ÚGEOMETRYÚXMLÚYEARr“   r”   r—   r˜   ÚTINYBLOBÚBLOBÚ
MEDIUMBLOBÚLONGBLOBr›   rš   rœ   r�   ÚclassmethodrŽ   r‘   r–   r™   rž   r¡   r§   r¨   r+   r+   r+   r,   rl   ó   sh    






rl   c                   @   s8   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdS )r   r   rm   ro   rp   r:   rP   rQ   rO   rt   ru   rv   N)rg   rh   ri   r   r   r   r   r   r   r   r   r   r   r    r+   r+   r+   r,   r   ?  s    r   c                   @   s6   e Zd Zdd„ Zdd„ Zedd„ ƒZejdd„ ƒZdS )	ÚFlagsc                 C   sV   i | _ i | _| jj ¡ D ]\}}| d¡rqt|tƒr%|| j |< || j|< q|| _d S )NÚ__)	Ú_allowed_flagsÚ_flag_namesÚ	__class__Ú__dict__r‰   Ú
startswithr<   r=   Ú_value)Úselfr�   rŒ   Úvalr+   r+   r,   Ú__init__N  s   



€
zFlags.__init__c              	   C   sŽ   d}g }| j }tddƒD ]5}|dK }||@ }|rAz
| | j| ¡ W q ty@   tj d | j¡¡ tj d | j	j
¡¡ Y qw qd |¡S )Nr   r   é?   r
   ú,)r¼   ÚrangerK   r¸   r"   r#   r$   r%   r&   r¹   rº   Újoin)r½   ÚmaskÚ
flag_namesr�   Ú_Úflagr+   r+   r,   Ú__str__Y  s   þü
zFlags.__str__c                 C   ó   | j S r‡   ©r¼   ©r½   r+   r+   r,   r�   k  s   zFlags.valuec                 C   s
   || _ d S r‡   rÊ   )r½   r¾   r+   r+   r,   r�   o  s   
N)rg   rh   ri   r¿   rÈ   Úpropertyr�   Úsetterr+   r+   r+   r,   rµ   M  s    
rµ   c                   @   s    e Zd ZdZdZdZdZdZdS )ÚColumnFlagsrt   r„   é@   r8   é   N)rg   rh   ri   ÚNOT_NULLÚPRIMARY_KEYÚ
UNIQUE_KEYÚMULTIPLE_KEYÚAUTO_INCREMENTr+   r+   r+   r,   rÎ   t  s    rÎ   c                   @   rd   )ÚDatetimeColumnFlagsr   N)rg   rh   ri   r¬   r+   r+   r+   r,   rÖ   |  rk   rÖ   c                   @   rd   )ÚUIntColumnFlagsr   N)rg   rh   ri   ÚZEROFILLr+   r+   r+   r,   r×   €  rk   r×   c                   @   rd   )ÚDoubleColumnFlagsr   N©rg   rh   ri   ÚUNSIGNEDr+   r+   r+   r,   rÙ   „  rk   rÙ   c                   @   rd   )ÚFloatColumnFlagsr   NrÚ   r+   r+   r+   r,   rÜ   ˆ  rk   rÜ   c                   @   rd   )ÚBytesColumnFlagsr   N)rg   rh   ri   Ú	RIGHT_PADr+   r+   r+   r,   rÝ   Œ  rk   rÝ   c                   @   s   e Zd ZdZdZdZdS )ÚBytesContentTyper   rm   rn   N)rg   rh   ri   r­   r©   r®   r+   r+   r+   r,   rß   �  s    rß   c                   @   s:  e Zd ZdZ				dAdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd „ ƒZed!d"„ ƒZed#d$„ ƒZd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Z d;d<„ Z!d=d>„ Z"d?d@„ Z#dS )BÚColumna_  Represents meta data for a table column.

    Args:
        col_type (int): The column type.
        catalog (str): The catalog.
        schema (str): The schema name.
        table (str): The table name.
        original_table (str): The original table name.
        name (str): The column name.
        original_name (str): The original table name.
        length (int): The column length,
        collation (str): The collation name.
        fractional_digits (int): The fractional digits.
        flags (int): The flags.
        content_type (int): The content type.

    .. versionchanged:: 8.0.12
    Nc                 C   s  t |ƒ| _t |ƒ| _t |ƒ| _t |ƒ| _t |ƒ| _|| _d | _|| _|| _	|	| _
|
| _|| _|| _d| _d| _d| _d| _d | _d | _d | _| j
dkrt| j
ttƒkrZtd | j
¡ƒ‚t| j
 }|d | _|d | _d| jv prd| jv | _|  ¡  | jtjtjtjtjtjfv | _d S )NFr   z"No mapping found for collation {0}r   ÚbinaryÚ_bin) r   Ú_schemaÚ_nameÚ_original_nameÚ_tableÚ_original_tableÚ_proto_typeÚ	_col_typeÚ_catalogÚ_lengthÚ
_collationÚ_fractional_digitsÚ_flagsÚ_content_typeÚ_number_signedÚ
_is_paddedÚ
_is_binaryÚ	_is_bytesÚ_collation_nameÚ_character_set_nameÚ
_zero_fillr   r   r;   r&   Ú	_map_typerl   r­   r©   r®   r   rª   )r½   r(   ÚcatalogÚschemaÚtableÚoriginal_tableÚnameÚoriginal_nameÚlengthÚ	collationÚfractional_digitsÚflagsÚcontent_typeÚinfor+   r+   r,   r¿   ª  sH   





ÿ



ÿþzColumn.__init__c                 C   s   t | j| j| jt | jƒdœƒS )N)r(   rù   rú   r  )Ústrré   rã   ræ   rî   rË   r+   r+   r,   rÈ   Ñ  s   üzColumn.__str__c                 C   sj   | j tjkrtj| _n"| j tjkrtj| _n| j tjkr!tj| _n| jr)tj| _ntj	| _| j
d@ | _dS )z
Map bytes.r   N)rï   rß   r­   rl   ré   r©   r®   rò   r   rª   rî   rñ   rË   r+   r+   r,   Ú
_map_bytesÙ  s   



zColumn._map_bytesc                 C   sP   | j dkrtj| _dS | j dkrtj| _dS | jtj@ dkr$tj| _dS tdƒ‚)zMap datetime.rP   rw   r   z#Datetime mapping scenario unhandledN)	rë   rl   r«   ré   r   rî   rÖ   r¬   r;   rË   r+   r+   r,   Ú_map_datetimeç  s   

zColumn._map_datetimec                 C   sb   | j dkr
tj| _n"| j dkrtj| _n| j dkrtj| _n| j dkr(tj| _ntj| _d| _dS )zMap int type.r2   rp   rq   rr   TN)	rë   rl   r¢   ré   r£   r¤   r¥   r¦   rð   rË   r+   r+   r,   Ú_map_int_typeò  s   








zColumn._map_int_typec                 C   sh   | j dkr
tj| _n"| j dkrtj| _n| j dkrtj| _n| j dkr(tj| _ntj| _| jd@ | _	dS )zMap uint type.rn   ro   r7   rP   r   N)
rë   rl   r¢   ré   r£   r¤   r¥   r¦   rî   rö   rË   r+   r+   r,   Ú_map_uint_type   s   







zColumn._map_uint_typec                 C   sN  | j tjkr|  ¡  dS | j tjkr|  ¡  dS | j tjkr-tj| _| j	t
j@ dk| _dS | j tjkrBtj| _| j	t
j@ dk| _dS | j tjkrWtj| _| j	t
j@ dk| _dS | j tjkrc|  ¡  dS | j tjkrotj| _dS | j tjkr{|  ¡  dS | j tjkr‡tj| _dS | j tjkr“tj| _dS | j tjkrŸtj| _dS td | j ¡ƒ‚)z	Map type.r   zUnknown column type {0}N)rè   r   r   r  r   r  r   rl   ré   rî   rÜ   rÛ   Ú_is_number_signedr    r   r   r  r   r   r  r   r   r   r;   r&   rË   r+   r+   r,   r÷     s:   ÿÿÿzColumn._map_typec                 C   rÉ   )z@str: The schema name.

        .. versionadded:: 8.0.12
        ©rã   rË   r+   r+   r,   Úschema_name/  ó   zColumn.schema_namec                 C   ó   | j p| jS )z?str: The table name.

        .. versionadded:: 8.0.12
        ©rç   ræ   rË   r+   r+   r,   Ú
table_name7  ó   zColumn.table_namec                 C   r  )z@str: The table label.

        .. versionadded:: 8.0.12
        ©ræ   rç   rË   r+   r+   r,   Útable_label?  r  zColumn.table_labelc                 C   r  )z@str: The column name.

        .. versionadded:: 8.0.12
        ©rå   rä   rË   r+   r+   r,   Úcolumn_nameG  r  zColumn.column_namec                 C   r  )zAstr: The column label.

        .. versionadded:: 8.0.12
        ©rä   rå   rË   r+   r+   r,   Úcolumn_labelO  r  zColumn.column_labelc                 C   rÉ   )z@int: The column type.

        .. versionadded:: 8.0.12
        ©ré   rË   r+   r+   r,   ÚtypeW  r  zColumn.typec                 C   rÉ   )zBint. The column length.

        .. versionadded:: 8.0.12
        ©rë   rË   r+   r+   r,   rþ   _  r  zColumn.lengthc                 C   rÉ   )zMint: The column fractional digits.

        .. versionadded:: 8.0.12
        ©rí   rË   r+   r+   r,   r   g  r  zColumn.fractional_digitsc                 C   rÉ   )zCstr: The collation name.

        .. versionadded:: 8.0.12
        ©rô   rË   r+   r+   r,   Úcollation_nameo  r  zColumn.collation_namec                 C   rÉ   )zGstr: The character set name.

        .. versionadded:: 8.0.12
        ©rõ   rË   r+   r+   r,   Úcharacter_set_namew  r  zColumn.character_set_namec                 C   rÉ   )zUReturns the schema name.

        Returns:
            str: The schema name.
        r
  rË   r+   r+   r,   Úget_schema_name  r  zColumn.get_schema_namec                 C   r  )zSReturns the table name.

        Returns:
            str: The table name.
        r  rË   r+   r+   r,   Úget_table_name‡  r  zColumn.get_table_namec                 C   r  )zUReturns the table label.

        Returns:
            str: The table label.
        r  rË   r+   r+   r,   Úget_table_label�  r  zColumn.get_table_labelc                 C   r  )zUReturns the column name.

        Returns:
            str: The column name.
        r  rË   r+   r+   r,   Úget_column_name—  r  zColumn.get_column_namec                 C   r  )zWReturns the column label.

        Returns:
            str: The column label.
        r  rË   r+   r+   r,   Úget_column_labelŸ  r  zColumn.get_column_labelc                 C   rÉ   )zaReturns the column proto type.

        Returns:
            int: The column proto type.
        )rè   rË   r+   r+   r,   Úget_proto_type§  r  zColumn.get_proto_typec                 C   rÉ   )zUReturns the column type.

        Returns:
            int: The column type.
        r  rË   r+   r+   r,   Úget_type¯  r  zColumn.get_typec                 C   rÉ   )zYReturns the column length.

        Returns:
            int: The column length.
        r  rË   r+   r+   r,   Ú
get_length·  r  zColumn.get_lengthc                 C   rÉ   )zoReturns the column fractional digits.

        Returns:
            int: The column fractional digits.
        r  rË   r+   r+   r,   Úget_fractional_digits¿  r  zColumn.get_fractional_digitsc                 C   rÉ   )z[Returns the collation name.

        Returns:
            str: The collation name.
        r  rË   r+   r+   r,   Úget_collation_nameÇ  r  zColumn.get_collation_namec                 C   rÉ   )zcReturns the character set name.

        Returns:
            str: The character set name.
        r  rË   r+   r+   r,   Úget_character_set_nameÏ  r  zColumn.get_character_set_namec                 C   rÉ   )zxReturns `True` if is a number signed.

        Returns:
            bool: Returns `True` if is a number signed.
        )rð   rË   r+   r+   r,   Úis_number_signed×  r  zColumn.is_number_signedc                 C   rÉ   )zfReturns `True` if is padded.

        Returns:
            bool: Returns `True` if is padded.
        )rñ   rË   r+   r+   r,   Ú	is_paddedß  r  zColumn.is_paddedc                 C   rÉ   )zdReturns `True` if is bytes.

        Returns:
            bool: Returns `True` if is bytes.
        )ró   rË   r+   r+   r,   Úis_bytesç  r  zColumn.is_bytes)NNNNNNNNNNN)$rg   rh   ri   Ú__doc__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)  r*  r+  r,  r+   r+   r+   r,   rà   —  s^    
ý'!









rà   c                   @   s0   e Zd ZdZdd„ Zdd„ Zedƒdd„ ƒZd	S )
ÚRowz¶Represents a row element returned from a SELECT query.

    Args:
        rs (mysqlx.SqlResult or mysqlx.RowResult): The result set.
        fields (`list`): The list of fields.
    c                 C   s   || _ || _d S r‡   )Ú_fieldsÚ
_resultset)r½   ÚrsÚfieldsr+   r+   r,   r¿   ÷  s   
zRow.__init__c                 C   sb   t |tƒr| j |¡n|}|dkrt |tƒrtd |¡ƒ‚|t| jƒks(|dk r,tdƒ‚| j| S )z\Returns the value of a column by name or index.

        .. versionchanged:: 8.0.12
        r.   úColumn name '{0}' not foundr   zIndex out of range)	r<   r   r0  Úindex_ofr;   r&   r   r/  Ú
IndexError)r½   ÚindexÚ	int_indexr+   r+   r,   Ú__getitem__û  s   ÿÿ
zRow.__getitem__ú8.0.12c                 C   sF   | j  |¡}|t| jƒkrtdƒ‚|dkrtd |¡ƒ‚t| j| ƒS )zŽReturns the value using the column name.

        Args:
            str_index (str): The column name.

        .. deprecated:: 8.0.12
        zArgument out of ranger.   r3  )r0  r4  r   r/  r5  r;   r&   r  )r½   Ú	str_indexr7  r+   r+   r,   Ú
get_string  s   	zRow.get_stringN)rg   rh   ri   r-  r¿   r8  r	   r;  r+   r+   r+   r,   r.  ð  s    r.  c                   @   sX   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )Ú
BaseResultz‰Provides base functionality for result objects.

    Args:
        connection (mysqlx.connection.Connection): The Connection object.
    c                 C   sJ   || _ d| _d| _d| _g | _g | _|d u rd | _d S |j| _| ¡  d S ©NFr   r.   )	Ú_connectionÚ_closedÚ_rows_affectedÚ_generated_idÚ_generated_idsÚ	_warningsÚ	_protocolÚprotocolÚfetch_active_result©r½   Ú
connectionr+   r+   r,   r¿     s   
zBaseResult.__init__c                 C   rÉ   )z†Returns the number of affected items for the last operation.

        Returns:
            int: The number of affected items.
        ©r@  rË   r+   r+   r,   Úget_affected_items_count-  r  z#BaseResult.get_affected_items_countc                 C   rÉ   )zZReturns the warnings.

        Returns:
            `list`: The list of warnings.
        )rC  rË   r+   r+   r,   Úget_warnings5  r  zBaseResult.get_warningsc                 C   ó
   t | jƒS )zcReturns the number of warnings.

        Returns:
            int: The number of warnings.
        )r   rC  rË   r+   r+   r,   Úget_warnings_count=  ó   
zBaseResult.get_warnings_countc                 C   ó
   || _ dS )z)Sets if resultset fetch is done.
        N)r?  ©r½   rÇ   r+   r+   r,   Ú
set_closedE  ó   
zBaseResult.set_closedc                 C   s   | j  |||dœ¡ dS )z«Append a warning.

        Args:
            level (int): The warning level.
            code (int): The warning code.
            msg (str): The warning message.
        )ÚlevelÚcodeÚmsgN)rC  rK   )r½   rS  rT  rU  r+   r+   r,   Úappend_warningJ  s   zBaseResult.append_warningc                 C   rO  )z Sets the generated ids.
        N©rB  )r½   Úgenerated_idsr+   r+   r,   Úset_generated_idsT  rR  zBaseResult.set_generated_idsc                 C   rO  )z&Sets the generated insert id.
        N©rA  )r½   Úgenerated_idr+   r+   r,   Úset_generated_insert_idY  rR  z"BaseResult.set_generated_insert_idc                 C   rO  )z*Sets the number of rows affected.
        NrI  )r½   Útotalr+   r+   r,   Úset_rows_affected^  rR  zBaseResult.set_rows_affectedN)rg   rh   ri   r-  r¿   rJ  rK  rM  rQ  rV  rY  r\  r^  r+   r+   r+   r,   r<    s    
r<  c                       sR   e Zd ZdZd‡ fdd„	Zdd„ Zedƒdd	„ ƒZedƒd
d„ ƒZdd„ Z	‡  Z
S )ÚResulta  Allows retrieving information about non query operations performed on
    the database.

    Args:
        connection (mysqlx.connection.Connection): The Connection object.
                                                   ids (`list`): A list of IDs.
    Nc                    s2   t t| ƒ |¡ || _|d ur| j | ¡ d S d S r‡   )Úsuperr_  r¿   Ú_idsr>  Úclose_result)r½   rH  Úids©r¹   r+   r,   r¿   l  s
   ÿzResult.__init__c                 C   rÉ   )zjReturns the last insert id auto generated.

        Returns:
            int: The last insert id.
        rZ  rË   r+   r+   r,   Úget_autoincrement_values  r  zResult.get_autoincrement_valuer9  c                 C   s&   | j du st| j ƒdkrdS | j d S )zdReturns ID of the last document inserted into a collection.

        .. deprecated:: 8.0.12
        Nr   )ra  r   rË   r+   r+   r,   Úget_document_id{  s   
zResult.get_document_idc                 C   rÉ   )zIReturns the generated insert id.

        .. deprecated:: 8.0.12
        rZ  rË   r+   r+   r,   Úget_generated_insert_id…  r  zResult.get_generated_insert_idc                 C   rÉ   )z#Returns the generated ids.
        rW  rË   r+   r+   r,   Úget_generated_ids�  ó   zResult.get_generated_ids)NN)rg   rh   ri   r-  r¿   re  r	   rf  rg  rh  Ú__classcell__r+   r+   rd  r,   r_  d  s    
	
r_  c                       st   e Zd ZdZ‡ fdd„Zdd„ Zedd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚBufferingResultzãProvides base functionality for buffering result objects.

    Args:
        connection (mysqlx.connection.Connection): The Connection object.
                                                   ids (`list`): A list of IDs.
    c                    s@   t t| ƒ |¡ g | _d| _d| _g | _d| _d| _|  	¡  d S r=  )
r`  rk  r¿   Ú_columnsÚ	_has_dataÚ_has_more_resultsÚ_itemsÚ
_page_sizeÚ	_positionÚ_init_resultrG  rd  r+   r,   r¿   š  s   zBufferingResult.__init__c                 C   s
   | j | S r‡   )ro  )r½   r6  r+   r+   r,   r8  ¤  s   
zBufferingResult.__getitem__c                 C   rL  )zint: The total of items.)r   ro  rË   r+   r+   r,   Úcount§  rR  zBufferingResult.countc                 C   sX   | j  | ¡| _t| jƒdkrdnd| _g | _d| _d| _| j  | jr'| ¡ dS d¡ dS )zInitialize the result.r   TFrx   r.   N)	r>  Úget_column_metadatarl  r   Ú_has_more_dataro  rp  rq  Úset_active_resultrË   r+   r+   r,   rr  ¬  s   ÿzBufferingResult._init_resultc                 C   sr   | j  | ¡}|du rdS dgt|d ƒ }|s4tt|d ƒƒD ]}| j| }t| ¡ |d | ƒ||< qt| |ƒS )z•Read item.

        Args:
            dumping (bool): `True` for dumping.

        Returns:
            :class:`mysqlx.Row`: A `Row` object.
        NÚfield)r>  Úread_rowr   rÂ   rl  r-   r$  r.  )r½   ÚdumpingÚrowrC   rŒ   Úcolr+   r+   r,   Ú
_read_item¶  s   	


ÿ
zBufferingResult._read_itemc                 C   sN   | j rdS d}t| jƒD ]}|  d¡}|du r |S | j |¡ |d7 }q|S )zSReads the page items.

        Returns:
            int: Total items read.
        Fr   Nr   )r?  rÂ   rp  r|  ro  rK   )r½   rs  rÆ   rC   r+   r+   r,   Ú_page_in_itemsÊ  s   
þ
zBufferingResult._page_in_itemsc                 C   s0   d}| j D ]}| ¡ |kr|  S |d7 }qdS )zeReturns the index of the column.

        Returns:
            int: The index of the column.
        r   r   r.   )rl  r"  )r½   Úcol_namer6  r{  r+   r+   r,   r4  Ü  s   

zBufferingResult.index_ofc                 C   s   | j rdS |  d¡S )zuFetch one item.

        Returns:
            :class:`mysqlx.Row` or :class:`mysqlx.DbDoc`: one result item.
        NF)r?  r|  rË   r+   r+   r,   Ú	fetch_oneé  s   
zBufferingResult.fetch_onec                 C   s   	 |   ¡ s		 | jS q)z–Fetch all items.

        Returns:
            `list`: The list of items of :class:`mysqlx.DbDoc` or
                    :class:`mysqlx.Row`.
        )r}  ro  rË   r+   r+   r,   Ú	fetch_allô  s
   ýzBufferingResult.fetch_allc                 C   rO  )zdSets if result has data.

        Args:
            flag (bool): `True` if result has data.
        N©rm  rP  r+   r+   r,   Úset_has_data   rN  zBufferingResult.set_has_datac                 C   rO  )zfSets if has more results.

        Args:
            flag (bool): `True` if has more results.
        N)rn  rP  r+   r+   r,   Úset_has_more_results  rN  z$BufferingResult.set_has_more_results)rg   rh   ri   r-  r¿   r8  rÌ   rs  rr  r|  r}  r4  r  r€  r‚  rƒ  rj  r+   r+   rd  r,   rk  “  s    


rk  c                       s4   e Zd ZdZ‡ fdd„Zedd„ ƒZdd„ Z‡  ZS )Ú	RowResultz¡Allows traversing the Row objects returned by a Table.select operation.

    Args:
        connection (mysqlx.connection.Connection): The Connection object.
    c                    ó   t t| ƒ |¡ d S r‡   )r`  r„  r¿   rG  rd  r+   r,   r¿     ó   zRowResult.__init__c                 C   rÉ   )z`list`: The list of columns.©rl  rË   r+   r+   r,   Úcolumns  ri  zRowResult.columnsc                 C   rÉ   )z‚Returns the list of columns.

        Returns:
            `list`: The list of columns.

        .. versionadded:: 8.0.12
        r‡  rË   r+   r+   r,   Úget_columns  ó   zRowResult.get_columns)	rg   rh   ri   r-  r¿   rÌ   rˆ  r‰  rj  r+   r+   rd  r,   r„    s    
r„  c                       s8   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Z‡  ZS )
Ú	SqlResultzƒRepresents a result from a SQL statement.

    Args:
        connection (mysqlx.connection.Connection): The Connection object.
    c                    r…  r‡   )r`  r‹  r¿   rG  rd  r+   r,   r¿   0  r†  zSqlResult.__init__c                 C   rÉ   )zŒReturns the identifier for the last record inserted.

        Returns:
            str: The identifier of the last record inserted.
        rZ  rË   r+   r+   r,   re  3  r  z!SqlResult.get_autoincrement_valuec                 C   s   | j rdS d| _|  ¡  dS )zjProcess the next result.

        Returns:
            bool: Returns `True` if the fetch is done.
        FT)r?  rn  rr  rË   r+   r+   r,   Únext_result;  s
   zSqlResult.next_resultc                 C   rÉ   )z’Returns True if result has data.

        Returns:
            bool: Returns `True` if result has data.

        .. versionadded:: 8.0.12
        r�  rË   r+   r+   r,   Úhas_dataG  rŠ  zSqlResult.has_data)	rg   rh   ri   r-  r¿   re  rŒ  r�  rj  r+   r+   rd  r,   r‹  *  s    r‹  c                       s,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )Ú	DocResultzªAllows traversing the DbDoc objects returned by a Collection.find
    operation.

    Args:
        connection (mysqlx.connection.Connection): The Connection object.
    c                    r…  r‡   )r`  rŽ  r¿   rG  rd  r+   r,   r¿   X  r†  zDocResult.__init__c                    s,   t t| ƒ |¡}|du rdS tt|d ƒƒS )z™Read item.

        Args:
            dumping (bool): `True` for dumping.

        Returns:
            :class:`mysqlx.DbDoc`: A `DbDoc` object.
        Nr   )r`  rŽ  r|  r   r   )r½   ry  rz  rd  r+   r,   r|  [  s   	zDocResult._read_item)rg   rh   ri   r-  r¿   r|  rj  r+   r+   rd  r,   rŽ  Q  s    rŽ  ).r-  rS   r4   r#   r   r   Údbdocr   Úcharsetsr   Úcompatr   Úhelpersr   r	   r-   r   r   r   rG   r   r   r   r!   r   r   Úobjectre   rl   r   rµ   rÎ   rÖ   r×   rÙ   rÜ   rÝ   rß   rà   r.  r<  r_  rk  r„  r‹  rŽ  r+   r+   r+   r,   Ú<module>   sR   $ L'  [)K/~'