
    :?hc                       S r SSKJr  SSKrSSKrSSKrSSKJrJrJ	r	J
r
JrJrJr  SSKJr  SSKJr  SSKJrJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJrJr  SSK J!r!J"r"J#r#J$r$J%r%J&r&  Sr' " S S5      r(S4S jr)S5S6S jjr*S5S7S jjr+S5S8S jjr, S5       S9S jjr- " S S5      r. " S S\.5      r/ " S S\.5      r0 " S S\.5      r1 " S S\15      r2 " S  S!5      r3 " S" S#\/5      r4 " S$ S%\/5      r5 " S& S'\55      r6 " S( S)\55      r7 " S* S+\15      r8 " S, S-\/5      r9 " S. S/\/5      r: " S0 S1\/5      r; " S2 S3\.5      r<g):zImplementation of Statements.    )annotationsN)AnyDictIterableListOptionalTupleUnion   )LockContention)DbDoc)NotSupportedErrorProgrammingError)
ExprParser)
deprecated)mysqlxpb_enum)	DocResultResult	RowResult	SqlResult)ConnectionTypeDatabaseTargetTypeMessageTypeProtobufMessageCextTypeProtobufMessageType
SchemaTypez&The given index name "{}" is not validc                  "    \ rS rSrSrSS jrSrg)Expr<   zExpression wrapper.c                    Xl         g Nexpr)selfr#   s     X/var/www/ev-aguas/ev-aguas-proceso/venv/lib/python3.13/site-packages/mysqlx/statement.py__init__Expr.__init__?   s    	    r"   N)r#   r   returnNone)__name__
__module____qualname____firstlineno____doc__r&   __static_attributes__ r(   r%   r   r   <   s
    r(   r   c                 j    [        U 5      S:X  a#  [        U S   [        [        45      (       a  U S   $ U $ )zParse flexible parameters.r   r   )len
isinstancelisttuple)valuess    r%   flexible_paramsr8   C   s1    
6{aJvay4-@@ayMr(   c                    SU;   a5  U S   S:H  =(       a    U S   S:H  =(       d    U S   S:H  =(       a    U S   S:H  $ U S   S:H  =(       a    U S   S:H  $ )zCheck if the given identifier is quoted.

Args:
    identifier (string): Identifier to check.
    sql_mode (Optional[string]): SQL mode.

Returns:
    `True` if the identifier has backtick quotes, and False otherwise.
ANSI_QUOTESr   `"r1   )
identifiersql_modes     r%   is_quoted_identifierr@   J   si      1$>B3)> 
qMS :Z^s%:	
 a=C9JrNc$99r(   c                    [        U 5      S:X  a  gSU;   a  U R                  SS5      nSU S3$ U R                  SS5      nSU S3$ )a$  Quote the given identifier with backticks, converting backticks (`) in
the identifier name with the correct escape sequence (``).

Args:
    identifier (string): Identifier to quote.
    sql_mode (Optional[string]): SQL mode.

Returns:
    A string with the identifier quoted with backticks.
r   z``r:   r=   z""r;   )r3   replace)r>   r?   quoteds      r%   quote_identifierrD   [   s[     :! ##C.6(!}T*Fvha=r(   c           	     `    SR                  U  Vs/ sH  n[        X!5      PM     sn5      $ s  snf )zQuote the given multi-part identifier with backticks.

Args:
    identifiers (iterable): List of identifiers to quote.
    sql_mode (Optional[string]): SQL mode.

Returns:
    A string with the multi-part identifier quoted with backticks.
.)joinrD   )identifiersr?   r>   s      r%   quote_multipart_identifierrI   o   s0     88BMN+J	*	/+N Ns   +c                    SU;   a  SOSnX1;   a  SU 3OSnUR                  US5      n[        U5      S:X  a  U OUS   R                  U5      US   R                  U5      4$ )zParse table name.

Args:
    default_schema (str): The default schema.
    table_name (str): The table name.
    sql_mode(Optional[str]): The SQL mode.

Returns:
    str: The parsed table name.
r:   r=   r;   rF   r   r   r<   )splitr3   strip)default_schema
table_namer?   quote	delimitertemps         r%   parse_table_namerR   ~   sl     !H,C#E$2!E7IIq)Dd)q.d1gmmE.BRu r(   c                     \ rS rSrSrSSS jjr\SS j5       r\SS j5       r\SS j5       r	\	R                  SS j5       r	\SS j5       r\SS	 j5       r\R                  SS
 j5       r\SS j5       r\R                  SS j5       r\SS j5       r\SS j5       r\R                  SS j5       rSS jrSS jrSS jrSS jrSrg) 	Statement   zProvides base functionality for statement objects.

Args:
    target (object): The target database object, it can be
                     :class:`mysqlx.Collection` or :class:`mysqlx.Table`.
    doc_based (bool): `True` if it is document based.
c                    Xl         X l        U(       a  UR                  5       OS U l        S U l        SU l        SU l        SU l        SU l        g )Nr   TF)	_target
_doc_basedget_connection_connection_stmt_id_exec_counter_changed	_prepared_deallocate_prepare_execute)r$   target	doc_baseds      r%   r&   Statement.__init__   sK    +1 )'-F!!#4 	 (,"#"$16(r(   c                    U R                   $ )z#object: The database object target.)rW   r$   s    r%   r`   Statement.target   s     ||r(   c                .    U R                   R                  $ )z*:class:`mysqlx.Schema`: The Schema object.)rW   schemard   s    r%   rg   Statement.schema   s     ||"""r(   c                    U R                   $ )z@Returns this statement ID.

Returns:
    int: The statement ID.
r[   rd   s    r%   stmt_idStatement.stmt_id   s     }}r(   c                    Xl         g r!   rj   r$   values     r%   rk   rl          r(   c                    U R                   $ )z5int: The number of times this statement was executed.r\   rd   s    r%   exec_counterStatement.exec_counter   s     !!!r(   c                    U R                   $ )z+bool: `True` if this statement has changes.r]   rd   s    r%   changedStatement.changed   s     }}r(   c                    Xl         g r!   rv   rn   s     r%   rw   rx      rp   r(   c                    U R                   $ )z1bool: `True` if this statement has been prepared.r^   rd   s    r%   preparedStatement.prepared   s     ~~r(   c                    Xl         g r!   r{   rn   s     r%   r|   r}      s    r(   c                     U R                   S:  $ )z;bool: `True` if this statement was executed more than once.r   rr   rd   s    r%   repeatedStatement.repeated   s     !!A%%r(   c                    U R                   $ )z9bool: `True` to deallocate + prepare + execute statement.r_   rd   s    r%   deallocate_prepare_execute$Statement.deallocate_prepare_execute   s     ///r(   c                    Xl         g r!   r   rn   s     r%   r   r      s    +0(r(   c                    U R                   $ )zSCheck if it is document based.

Returns:
    bool: `True` if it is document based.
)rX   rd   s    r%   is_doc_basedStatement.is_doc_based   s     r(   c                .    U =R                   S-  sl         g)z@Increments the number of times this statement has been executed.r   Nrr   rd   s    r%   increment_exec_counter Statement.increment_exec_counter   s    ar(   c                    SU l         g)z<Resets the number of times this statement has been executed.r   Nrr   rd   s    r%   reset_exec_counterStatement.reset_exec_counter   s
    r(   c                    [         ezYExecute the statement.

Raises:
   NotImplementedError: This method must be implemented.
NotImplementedErrorrd   s    r%   executeStatement.execute   
     "!r(   )r]   rZ   r_   rX   r\   r^   r[   rW   NTr`   r   ra   boolr)   r*   )r)   r   )r)   r   r)   int)ro   r   r)   r*   r)   r   )ro   r   r)   r*   )r)   r*   r)   r   )r+   r,   r-   r.   r/   r&   propertyr`   rg   rk   setterrs   rw   r|   r   r   r   r   r   r   r0   r1   r(   r%   rT   rT      s"   
7   # #   ^^  " "   ^^    __  & & 0 0  &&1 '1 "r(   rT   c                  \  ^  \ rS rSrSr  S       SU 4S jjjrSS jrSS jrSS jrS S jr	S!S jr
S"S	 jrS#S
 jrS$S jrS%S jrS&S jrS'S jrS'S jrS&S jr  S%S jr  S%S jr\" S5      SS j5       r\" S5      SS j5       r S(     S)S jjrS*S jrS+S jrS,S jrSrU =r$ )-FilterableStatement   a  A statement to be used with filterable statements.

Args:
    target (object): The target database object, it can be
                     :class:`mysqlx.Collection` or :class:`mysqlx.Table`.
    doc_based (Optional[bool]): `True` if it is document based
                                (default: `True`).
    condition (Optional[str]): Sets the search condition to filter
                               documents or records.
c                j  > [         TU ]  XS9  0 U l        0 U l        S U l        SU l        S U l        SU l        S U l        SU l	        S U l
        SU l        S U l        SU l        S U l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        U(       a  U R-                  U5        g g )Nr`   ra    r   F)superr&   _binding_map	_bindings_having_grouping_str	_grouping_limit_offset_limit_row_count_projection_str_projection_expr	_sort_str
_sort_expr
_where_str_where_exprhas_bindings	has_limithas_group_by
has_havinghas_projectionhas_sort	has_where
_set_wherer$   r`   ra   	condition	__class__s       r%   r&   FilterableStatement.__init__
  s     	<,.68.2"$  	 #$%)$&  	 !  	  "(,"'$"' %$)#$OOI& r(   c                "   [        U[        5      (       a)  U R                  [        U5      R	                  5       5        g[        U[        5      (       a   U R                  UR	                  5       5        g[        U[
        5      (       a_   [        R                  " U5      n[        U[        5      (       d  [        e UR                  5        H  nU R                  XBU   5        M     g[        S5      e! [         a  n[        S5      UeSnAff = f)zBind single object.

Args:
    obj (:class:`mysqlx.DbDoc` or str): DbDoc or JSON string object.

Raises:
    :class:`mysqlx.ProgrammingError`: If invalid JSON string to bind.
    ValueError: If JSON loaded is not a dictionary.
zInvalid JSON string to bindNz%Invalid JSON string or object to bind)r4   dictbindr   as_strstrjsonloads
ValueErrorr   keys)r$   objreserrkeys        r%   _bind_single FilterableStatement._bind_single.  s     c4  IIeCj'')*U##IIcjjl#S!!Ojjo!#t,,$$ - xxz		#3x( " ##JKK  O&'DE3NOs   
1C3 3
D=D		Dc                    SU l         SR                  [        U6 5      U l        [	        U R                  U R
                  (       + 5      R                  5       U l        SU l        U $ )zSets the sorting criteria.

Args:
    *clauses: The expression strings defining the sort criteria.

Returns:
    mysqlx.FilterableStatement: FilterableStatement object.
T,)	r   rG   r8   r   r   rX   parse_order_specr   r]   r$   clausess     r%   _sortFilterableStatement._sortH  sV     /7";<$NN/



 	 r(   c                    SU l         Xl         [        XR                  (       + 5      nUR	                  5       U l        UR                  U l	        SU l
        U $ ! [         a  n[        S5      UeSnAff = f)zSets the search condition to filter.

Args:
    condition (str): Sets the search condition to filter documents or
                     records.

Returns:
    mysqlx.FilterableStatement: FilterableStatement object.
TzInvalid conditionN)r   r   r   rX   r#   r   r   r   placeholder_name_to_positionr   r]   )r$   r   r#   r   s       r%   r   FilterableStatement._set_whereY  ss     #	Ai__)<=D#yy{D !==	  	A"#67S@	As   /A 
A3"A..A3c                    [        U6 nSU l        SR                  U5      U l        [	        U R                  U R
                  (       + 5      R                  5       U l        SU l        g)z2Set group by.

Args:
    *fields: List of fields.
Tr   N)	r8   r   rG   r   r   rX   parse_expr_listr   r]   r$   fieldss     r%   _set_group_by!FilterableStatement._set_group_byn  sY     !&)  XXf-#DOO 3

/
 	 r(   c                z    SU l         [        XR                  (       + 5      R                  5       U l        SU l        g)z7Set having.

Args:
    condition (str): The condition.
TN)r   r   rX   r#   r   r]   r$   r   s     r%   _set_havingFilterableStatement._set_having|  s.     !)-@AFFHr(   c                    [        U6 nSU l        SR                  U5      U l        [	        U R                  U R
                  (       + 5      R                  5       U l        SU l        U $ )zySet the projection.

Args:
    *fields: List of fields.

Returns:
    :class:`mysqlx.FilterableStatement`: Returns self.
Tr   )	r8   r   rG   r   r   rX   parse_table_select_projectionr   r]   r   s     r%   _set_projection#FilterableStatement._set_projection  s`     !&)""xx/ *  doo"5!

'
'
) 	 r(   c                    U R                   $ zTReturns the binding map dictionary.

Returns:
    dict: The binding map dictionary.
r   rd   s    r%   get_binding_map#FilterableStatement.get_binding_map          r(   c                    U R                   $ zDReturns the bindings list.

Returns:
    `list`: The bindings list.
r   rd   s    r%   get_bindings FilterableStatement.get_bindings       ~~r(   c                    U R                   $ )zZReturns the grouping expression list.

Returns:
    `list`: The grouping expression list.
)r   rd   s    r%   get_grouping FilterableStatement.get_grouping  r   r(   c                    U R                   $ )zLReturns the having expression.

Returns:
    object: The having expression.
)r   rd   s    r%   
get_havingFilterableStatement.get_having       ||r(   c                    U R                   $ )zEReturns the limit row count.

Returns:
    int: The limit row count.
)r   rd   s    r%   get_limit_row_count'FilterableStatement.get_limit_row_count  s     $$$r(   c                    U R                   $ )z?Returns the limit offset.

Returns:
    int: The limit offset.
)r   rd   s    r%   get_limit_offset$FilterableStatement.get_limit_offset  s     !!!r(   c                    U R                   $ )zJReturns the where expression.

Returns:
    object: The where expression.
)r   rd   s    r%   get_where_expr"FilterableStatement.get_where_expr       r(   c                    U R                   $ )zTReturns the projection expression.

Returns:
    object: The projection expression.
)r   rd   s    r%   get_projection_expr'FilterableStatement.get_projection_expr  s     $$$r(   c                    U R                   $ )zHReturns the sort expression.

Returns:
    object: The sort expression.
)r   rd   s    r%   get_sort_expr!FilterableStatement.get_sort_expr  s     r(   8.0.12c                $    U R                  U5      $ )zSets the search condition to filter.

Args:
    condition (str): Sets the search condition to filter documents or
                     records.

Returns:
    mysqlx.FilterableStatement: FilterableStatement object.

.. deprecated:: 8.0.12
r   r   s     r%   whereFilterableStatement.where  s     y))r(   c                     U R                   " U6 $ )zSets the sorting criteria.

Args:
    *clauses: The expression strings defining the sort criteria.

Returns:
    mysqlx.FilterableStatement: FilterableStatement object.

.. deprecated:: 8.0.12
r   r   s     r%   sortFilterableStatement.sort  s     zz7##r(   c                f   [        U[        5      (       a  US:  a  [        S5      eU R                  (       d;  [	        U R
                  S:H  5      U l        [	        U R
                  S:X  + 5      U l        Xl        SU l        U(       a*  U R                  U5        [        R                  " S[        S9  U $ )a<  Sets the maximum number of items to be returned.

Args:
    row_count (int): The maximum number of items.

Returns:
    mysqlx.FilterableStatement: FilterableStatement object.

Raises:
    ValueError: If ``row_count`` is not a positive integer.

.. versionchanged:: 8.0.12
   The usage of ``offset`` was deprecated.
r   z0The 'row_count' value must be a positive integerTzh'limit(row_count, offset)' is deprecated, please use 'offset(offset)' to set the number of items to skip)category)r4   r   r   r   r   r\   r]   r_   r   offsetwarningswarnDeprecationWarning)r$   	row_countr  s      r%   limitFilterableStatement.limit  s    " )S))Y]OPP~~ !3!3q!89DM/38J8Ja4O/PD, )KKMM ,	 r(   c                ^    [        U[        5      (       a  US:  a  [        S5      eXl        U $ )zSets the number of items to skip.

Args:
    offset (int): The number of items to skip.

Returns:
    mysqlx.FilterableStatement: FilterableStatement object.

Raises:
    ValueError: If ``offset`` is not a positive integer.

.. versionadded:: 8.0.12
r   z-The 'offset' value must be a positive integer)r4   r   r   r   )r$   r  s     r%   r  FilterableStatement.offset$  s.     &#&&&1*LMM#r(   c                    SU l         [        U5      nUS:X  a  U R                  US   5        U $ US:X  a  US   U R                  US   '   U $ [	        S5      e)a`  Binds value(s) to a specific placeholder(s).

Args:
    *args: The name of the placeholder and the value to bind.
           A :class:`mysqlx.DbDoc` object or a JSON string
           representation can be used.

Returns:
    mysqlx.FilterableStatement: FilterableStatement object.

Raises:
    ProgrammingError: If the number of arguments is invalid.
Tr   r      #Invalid number of arguments to bind)r   r3   r   r   r   )r$   argscounts      r%   r   FilterableStatement.bind7  si     !D	A:d1g&
 	 aZ&*1gDNN47#  ##HIIr(   c                    [         er   r   rd   s    r%   r   FilterableStatement.executeO  r   r(   )r   r   r]   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   TNr`   r   ra   r   r   Optional[str]r)   r*   )r   z!Union[DbDoc, Dict[str, Any], str]r)   r*   )r   r   r)   r   )r   r   r)   r   )r   r   r)   r*   )r   r   r)   r*   )r   r   r)   r   r)   Dict[str, Any])r)   zUnion[Dict[str, Any], List])r)   z9List[Union[ProtobufMessageType, ProtobufMessageCextType]])r)   r   r   r!   )r  r   r  zOptional[int]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  r   r   r0   __classcell__r   s   @r%   r   r      s   	 #'	"'""' "' !	"'
 
"' "'HL4"*$!%" %	B%	B * * $ $ 7;!!&3!	!F&0" "r(   r   c                  l   ^  \ rS rSrSrS
U 4S jjr\SS j5       rSS jrSS jr	SS jr
SS jrS	rU =r$ )SqlStatementiX  zA statement for SQL execution.

Args:
    connection (mysqlx.connection.Connection): Connection object.
    sql (string): The sql statement to be executed.
c                r   > [         TU ]  S SS9  Xl        X l        S U l        / U l        SU l        SU l        g NFr   )r   r&   rZ   _sqlr   r   r   r   )r$   
connectionsqlr   s      r%   r&   SqlStatement.__init__`  s>    6+5	6:-/"'$r(   c                    U R                   $ )zstring: The SQL text statement.)r1  rd   s    r%   r3  SqlStatement.sqli  s     yyr(   c                    U R                   $ r   r   rd   s    r%   r   SqlStatement.get_binding_mapn  r   r(   c                    U R                   $ r   r   rd   s    r%   r   SqlStatement.get_bindingsv  r   r(   c                    [        U5      S:X  a  [        S5      eSU l        [        U6 n[	        U[
        [        45      (       a  X l        U $ U R                  R                  U5        U $ )zBinds value(s) to a specific placeholder(s).

Args:
    *args: The value(s) to bind.

Returns:
    mysqlx.SqlStatement: SqlStatement object.
r   r   T)	r3   r   r   r8   r4   r5   r6   r   append)r$   r!  bindingss      r%   r   SqlStatement.bind~  sc     t9>"#HII "D)hu..%N  NN!!(+r(   c                8    U R                   R                  U 5      $ )zIExecute the statement.

Returns:
    mysqlx.SqlResult: SqlResult object.
)rZ   send_sqlrd   s    r%   r   SqlStatement.execute  s     ((..r(   )r   r   rZ   r1  r   r   )r2  r   r3  r   r)   r*   r)   r   r)  )r)   zUnion[Tuple, List])r!  r   r)   r.  )r)   r   )r+   r,   r-   r.   r/   r&   r   r3  r   r   r   r   r0   r+  r,  s   @r%   r.  r.  X  s:    %  !&/ /r(   r.  c                  H   ^  \ rS rSrSrSU 4S jjr  SS jrS	S jrSrU =r	$ )
WriteStatementi  z*Provide common write operation attributes.c                2   > [         TU ]  X5        / U l        g r!   )r   r&   _values)r$   r`   ra   r   s      r%   r&   WriteStatement.__init__  s    +  	r(   c                    U R                   $ )zFReturns the list of values.

Returns:
    `list`: The list of values.
rF  rd   s    r%   
get_valuesWriteStatement.get_values  s      ||r(   c                    [         er   r   rd   s    r%   r   WriteStatement.execute  r   r(   rI  r   )r)   zpList[Union[int, str, DbDoc, Dict[str, Any], List[Optional[Union[str, int, float, ExprParser, Dict[str, Any]]]]]]r   )
r+   r,   r-   r.   r/   r&   rJ  r   r0   r+  r,  s   @r%   rD  rD    s$    4

$" "r(   rD  c                  \   ^  \ rS rSrSrS	U 4S jjrS
S jrSSS jjrSS jrSS jr	Sr
U =r$ )AddStatementi  zuA statement for document addition on a collection.

Args:
    collection (mysqlx.Collection): The Collection object.
c                B   > [         TU ]  US5        SU l        / U l        g )NTF)r   r&   _upsertids)r$   
collectionr   s     r%   r&   AddStatement.__init__  s     T*"r(   c                    U R                   $ )zPReturns `True` if it's an upsert.

Returns:
    bool: `True` if it's an upsert.
rQ  rd   s    r%   	is_upsertAddStatement.is_upsert  r   r(   c                    Xl         U $ )zSets the upset flag to the boolean of the value provided.
Setting of this flag allows updating of the matched rows/documents
with the provided value.

Args:
    value (optional[bool]): Set or unset the upsert flag.
rV  rn   s     r%   upsertAddStatement.upsert  s     r(   c                    [        U6  HY  n[        U[        5      (       a  U R                  R	                  U5        M5  U R                  R	                  [        U5      5        M[     U $ )zAdds a list of documents into a collection.

Args:
    *values: The documents to be added into the collection.

Returns:
    mysqlx.AddStatement: AddStatement object.
)r8   r4   r   rF  r<  )r$   r7   vals      r%   addAddStatement.add  sO     #F+C#u%%##C(##E#J/	 ,
 r(   c                ~    [        U R                  5      S:X  a
  [        5       $ U R                  R	                  U 5      $ )CExecute the statement.

Returns:
    mysqlx.Result: Result object.
r   )r3   rF  r   rZ   send_insertrd   s    r%   r   AddStatement.execute  s3     t||!8O++D11r(   )rQ  rR  )rS  r   r)   r*   r   r   )ro   r   r)   rO  )r7   r   r)   rO  r)   r   )r+   r,   r-   r.   r/   r&   rW  rZ  r^  r   r0   r+  r,  s   @r%   rO  rO    s&    
	 	2 	2r(   rO  c                  0    \ rS rSrSrSSS jjrS	S jrSrg)

UpdateSpeci  zUpdate specification class implementation.

Args:
    update_type (int): The update type.
    source (str): The source.
    value (Optional[str]): The value.

Raises:
    ProgrammingError: If `source` is invalid.
Nc                    U[        S5      :X  a  U R                  X#5        g Xl         [        US5      R	                  5       R
                  U l        X0l	        g ! [         a  n[        U 5      UeS nAff = f)N*Mysqlx.Crud.UpdateOperation.UpdateType.SETF)
r   
_table_setupdate_typer   document_fieldr>   sourcer   r   ro   )r$   rj  rl  ro   r   s        r%   r&   UpdateSpec.__init__  sl    -(TUUOOF*$/:#-fe#<#K#K#M#X#X $J  :&#0c9:s   )A 
A5#A00A5c                n    [        S5      U l        [        US5      R                  5       U l        X l        g)zLTable set.

Args:
    source (str): The source.
    value (str): The value.
rh  TN)r   rj  r   parse_table_update_fieldrl  ro   )r$   rl  ro   s      r%   ri  UpdateSpec._table_set  s.     ))UV .GGI
r(   )rl  rj  ro   r!   )rj  r   rl  r   ro   r   r)   r*   )rl  r   ro   r   r)   r*   )r+   r,   r-   r.   r/   r&   ri  r0   r1   r(   r%   rf  rf    s    		$	r(   rf  c                     ^  \ rS rSrSrSU 4S jjrSS jrSS jrSS jr\	" S5      SS j5       r
SS	 jrSS
 jrSS jrSS jrSS jrSrU =r$ )ModifyStatementi"  a9  A statement for document update operations on a Collection.

Args:
    collection (mysqlx.Collection): The Collection object.
    condition (str): Sets the search condition to identify the documents
                     to be modified.

.. versionchanged:: 8.0.12
   The ``condition`` parameter is now mandatory.
c                .   > [         TU ]  XS9  0 U l        g N)r`   r   r   r&   _update_opsr$   rS  r   r   s      r%   r&   ModifyStatement.__init__.  s    
@+-r(   c                     U R                   " U6 $ )zSets the sorting criteria.

Args:
    *clauses: The expression strings defining the sort criteria.

Returns:
    mysqlx.ModifyStatement: ModifyStatement object.
r  r   s     r%   r  ModifyStatement.sort2       zz7##r(   c                    U R                   $ z\Returns the list of update operations.

Returns:
    `list`: The list of update operations.
rv  rd   s    r%   get_update_opsModifyStatement.get_update_ops=  r  r(   c                Z    [        [        S5      UU5      U R                  U'   SU l        U $ )a  Sets or updates attributes on documents in a collection.

Args:
    doc_path (string): The document path of the item to be set.
    value (string): The value to be set on the specified attribute.

Returns:
    mysqlx.ModifyStatement: ModifyStatement object.
z/Mysqlx.Crud.UpdateOperation.UpdateType.ITEM_SETTrf  r   rv  r]   r$   doc_pathro   s      r%   setModifyStatement.setE  s6     &0KL&
"
 r(   r
  c                Z    [        [        S5      UU5      U R                  U'   SU l        U $ )aJ  Add an update to the statement setting the field, if it exists at
the document path, to the given value.

Args:
    doc_path (string): The document path of the item to be set.
    value (object): The value to be set on the specified attribute.

Returns:
    mysqlx.ModifyStatement: ModifyStatement object.

.. deprecated:: 8.0.12
z3Mysqlx.Crud.UpdateOperation.UpdateType.ITEM_REPLACETr  r  s      r%   changeModifyStatement.changeW  s6     &0OP&
"
 r(   c                v    [        U6  H%  n[        [        S5      U5      U R                  U'   M'     SU l        U $ )zRemoves attributes from documents in a collection.

Args:
    doc_paths (list): The list of document paths of the attributes to be
                      removed.

Returns:
    mysqlx.ModifyStatement: ModifyStatement object.
z2Mysqlx.Crud.UpdateOperation.UpdateType.ITEM_REMOVET)r8   rf  r   rv  r]   )r$   	doc_pathsitems      r%   unsetModifyStatement.unsetm  sB     $Y/D%/RS&DT" 0
 r(   c                Z    [        [        S5      UU5      U R                  U'   SU l        U $ )aD  Insert a value into the specified array in documents of a
collection.

Args:
    field (string): A document path that identifies the array attribute
                    and position where the value will be inserted.
    value (object): The value to be inserted.

Returns:
    mysqlx.ModifyStatement: ModifyStatement object.
z3Mysqlx.Crud.UpdateOperation.UpdateType.ARRAY_INSERTTr  r$   fieldro   s      r%   array_insertModifyStatement.array_insert  s6     #-OP#

 r(   c                Z    [        [        S5      UU5      U R                  U'   SU l        U $ )ax  Inserts a value into a specific position in an array attribute in
documents of a collection.

Args:
    doc_path (string): A document path that identifies the array
                       attribute and position where the value will be
                       inserted.
    value (object): The value to be inserted.

Returns:
    mysqlx.ModifyStatement: ModifyStatement object.
z3Mysqlx.Crud.UpdateOperation.UpdateType.ARRAY_APPENDTr  r  s      r%   array_appendModifyStatement.array_append  s6     &0OP&
"
 r(   c                   Uc  Sn[        U[        [        [        [        45      (       d  [        S5      e[        [        S5      S[        U[        5      (       a  UR                  5       OU5      U R                  S'   SU l
        U $ )ab  Takes a :class:`mysqlx.DbDoc`, string JSON format or a dict with the
changes and applies it on all matching documents.

Args:
    doc (object): A generic document (DbDoc), string in JSON format or
                  dict, with the changes to apply to the matching
                  documents.

Returns:
    mysqlx.ModifyStatement: ModifyStatement object.
r   z>Invalid data for update operation on document collection tablez2Mysqlx.Crud.UpdateOperation.UpdateType.MERGE_PATCH$patchT)r4   r   r   r   r   r   rf  r   r#   rv  r]   )r$   docs     r%   r  ModifyStatement.patch  s|     ;C#
D%=>>"P  %/NO$S*55CHHJ3%
!
 r(   c                p    U R                   (       d  [        S5      eU R                  R                  U 5      $ )|Execute the statement.

Returns:
    mysqlx.Result: Result object.

Raises:
    ProgrammingError: If condition was not set.
z!No condition was found for modifyr   r   rZ   send_updaterd   s    r%   r   ModifyStatement.execute  .     ~~"#FGG++D11r(   r]   rv  rS  r   r   r   r)   r*   )r   r   r)   rr  r)  )r  r   ro   r   r)   rr  )r  r   r)   rr  )r  r   ro   r   r)   rr  )r  z#Union[Dict, DbDoc, ExprParser, str]r)   rr  rd  )r+   r,   r-   r.   r/   r&   r  r  r  r   r  r  r  r  r  r   r0   r+  r,  s   @r%   rr  rr  "  sS    	.	$ $  *$(*42 2r(   rr  c                     ^  \ rS rSrSr  S       SU 4S jjjr\SS j5       rSS jrSS jr	SS jr
\R                  4   SS jjr\R                  4   SS	 jjrSS
 jrSS jrSS jrSrU =r$ )ReadStatementi  a  Provide base functionality for Read operations

Args:
    target (object): The target database object, it can be
                     :class:`mysqlx.Collection` or :class:`mysqlx.Table`.
    doc_based (Optional[bool]): `True` if it is document based
                                (default: `True`).
    condition (Optional[str]): Sets the search condition to filter
                               documents or records.
c                l   > [         TU ]  XU5        SU l        SU l        [        R
                  U l        g NF)r   r&   _lock_exclusive_lock_sharedr   DEFAULT_lock_contentionr   s       r%   r&   ReadStatement.__init__  s2     	I6%*"'0>0F0Fr(   c                    U R                   $ )z::class:`mysqlx.LockContention`: The lock contention value.)r  rd   s    r%   lock_contentionReadStatement.lock_contention  s     $$$r(   c                x     [        UR                  5      nXl        g! [         a  n[        S5      UeSnAff = f)zSet the lock contention.

Args:
    lock_contention (:class:`mysqlx.LockContention`): Lock contention.

Raises:
    ProgrammingError: If is an invalid lock contention value.
z;Invalid lock contention mode. Use 'NOWAIT' or 'SKIP_LOCKED'N)r   ro   r   r   r  )r$   r  _r   s       r%   _set_lock_contention"ReadStatement._set_lock_contention  sD    	445A
 !0	  	"M	s    
949c                    U R                   $ )zZReturns `True` if is `EXCLUSIVE LOCK`.

Returns:
    bool: `True` if is `EXCLUSIVE LOCK`.
)r  rd   s    r%   is_lock_exclusiveReadStatement.is_lock_exclusive  s     ###r(   c                    U R                   $ )zTReturns `True` if is `SHARED LOCK`.

Returns:
    bool: `True` if is `SHARED LOCK`.
)r  rd   s    r%   is_lock_sharedReadStatement.is_lock_shared  r   r(   c                D    SU l         SU l        U R                  U5        U $ )zExecute a read operation with `SHARED LOCK`. Only one lock can be
   active at a time.

Args:
    lock_contention (:class:`mysqlx.LockContention`): Lock contention.
FTr  r  r  r$   r  s     r%   lock_sharedReadStatement.lock_shared  s'      % !!/2r(   c                D    SU l         SU l        U R                  U5        U $ )zExecute a read operation with `EXCLUSIVE LOCK`. Only one lock can be
   active at a time.

Args:
    lock_contention (:class:`mysqlx.LockContention`): Lock contention.
TFr  r  s     r%   lock_exclusiveReadStatement.lock_exclusive  s'      $!!!/2r(   c                $    U R                   " U6   U $ )zSets a grouping criteria for the resultset.

Args:
    *fields: The string expressions identifying the grouping criteria.

Returns:
    mysqlx.ReadStatement: ReadStatement object.
)r   r   s     r%   group_byReadStatement.group_by*  s     	F#r(   c                (    U R                  U5        U $ )a  Sets a condition for records to be considered in agregate function
operations.

Args:
    condition (string): A condition on the agregate functions used on
                        the grouping criteria.

Returns:
    mysqlx.ReadStatement: ReadStatement object.
)r   r   s     r%   havingReadStatement.having6  s     	#r(   c                8    U R                   R                  U 5      $ ra  )rZ   	send_findrd   s    r%   r   ReadStatement.executeD  s     ))$//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)   zUnion[DocResult, RowResult])r+   r,   r-   r.   r/   r&   r   r  r  r  r  r   r  r  r  r  r  r   r0   r+  r,  s   @r%   r  r    s    	 #'		G"	G 	G !		G
 
	G 	G % %0$$! 1?0F0F-	 1?0F0F-	
0 0r(   r  c                  T   ^  \ rS rSrSr S     SU 4S jjjrS	S jrS
S jrSrU =r	$ )FindStatementiM  a  A statement document selection on a Collection.

Args:
    collection (mysqlx.Collection): The Collection object.
    condition (Optional[str]): An optional expression to identify the
                               documents to be retrieved. If not specified
                               all the documents will be included on the
                               result unless a limit is set.
c                (   > [         TU ]  USU5        g )NTr   r&   rw  s      r%   r&   FindStatement.__init__X  s     	T95r(   c                     U R                   " U6 $ )zSets a document field filter.

Args:
    *fields: The string expressions identifying the fields to be
             extracted.

Returns:
    mysqlx.FindStatement: FindStatement object.
)r   r   s     r%   r   FindStatement.fields]  s     ##V,,r(   c                     U R                   " U6 $ zSets the sorting criteria.

Args:
    *clauses: The expression strings defining the sort criteria.

Returns:
    mysqlx.FindStatement: FindStatement object.
r  r   s     r%   r  FindStatement.sorti  r{  r(   r1   r!   )rS  r   r   r(  r)   r*   )r   r   r)   r  )r   r   r)   r  )
r+   r,   r-   r.   r/   r&   r   r  r0   r+  r,  s   @r%   r  r  M  s@     JN6,69F6	6 6

-	$ 	$r(   r  c                  N   ^  \ rS rSrSrSU 4S jjrS	S jrS
S jrSS jrSr	U =r
$ )SelectStatementiu  zA statement for record retrieval operations on a Table.

Args:
    table (mysqlx.Table): The Table object.
    *fields: The fields to be retrieved.
c                D   > [         TU ]  US5        U R                  " U6   g r  )r   r&   r   r$   tabler   r   s      r%   r&   SelectStatement.__init__}  s     &f%r(   c                $    U R                  U5      $ )zSets the search condition to filter.

Args:
    condition (str): Sets the search condition to filter records.

Returns:
    mysqlx.SelectStatement: SelectStatement object.
r  r   s     r%   r  SelectStatement.where       y))r(   c                     U R                   " U6 $ )zSets the order by criteria.

Args:
    *clauses: The expression strings defining the order by criteria.

Returns:
    mysqlx.SelectStatement: SelectStatement object.
r  r   s     r%   order_bySelectStatement.order_by  r{  r(   c                   U R                   (       a  SU R                   3OSnU R                  (       a  SU R                   3OSnU R                  (       a  SU R
                   3OSnU R                  (       a  SU R                   3OSnU R                  (       a  SU R                   SU R                   3OSnSU R                  =(       d    S	 S
U R                  R                   SU R                  R                   U U U U U 3nU$ )zAReturns the generated SQL.

Returns:
    str: The generated SQL.
z WHERE r   z
 GROUP BY z HAVING z
 ORDER BY z LIMIT z OFFSET zSELECT *z FROM rF   )r   r   r   r   r   r   r   r   r   r   r   r   rg   namer`   )r$   r  r  r  r  r  stmts          r%   get_sqlSelectStatement.get_sql  s     04~~'$//*+28<8I8IZ 2 234r.2oo8DLL>*248MMZ/0r ~~ d++,HT5G5G4HI 	 d**1c2 3KK$$%Qt{{'7'7&8ghZxz%: 	
 r(   r1   )r  r   r   r   r)   r*   )r   r   r)   r  )r   r   r)   r  rB  )r+   r,   r-   r.   r/   r&   r  r  r  r0   r+  r,  s   @r%   r  r  u  s!    &	*	$ r(   r  c                  D   ^  \ rS rSrSrSU 4S jjrSS jrS	S jrSrU =r	$ )
InsertStatementi  zA statement for insert operations on Table.

Args:
    table (mysqlx.Table): The Table object.
    *fields: The fields to be inserted.
c                @   > [         TU ]  US5        [        U6 U l        g r  )r   r&   r8   _fieldsr  s      r%   r&   InsertStatement.__init__  s    &+:F+Cr(   c                Z    U R                   R                  [        [        U6 5      5        U $ )zSet the values to be inserted.

Args:
    *values: The values of the columns to be inserted.

Returns:
    mysqlx.InsertStatement: InsertStatement object.
)rF  r<  r5   r8   )r$   r7   s     r%   r7   InsertStatement.values  s%     	D&!9:;r(   c                8    U R                   R                  U 5      $ r  )rZ   rb  rd   s    r%   r   InsertStatement.execute  s     ++D11r(   )r  )r  r   r   r   r)   r*   )r7   r   r)   r  rd  )
r+   r,   r-   r.   r/   r&   r7   r   r0   r+  r,  s   @r%   r  r    s    D
2 2r(   r  c                  b   ^  \ rS rSrSrS
U 4S jjrSS jrSS jrSS jrSS jr	SS jr
S	rU =r$ )UpdateStatementi  zA statement for record update operations on a Table.

Args:
    table (mysqlx.Table): The Table object.

.. versionchanged:: 8.0.12
   The ``fields`` parameters were removed.
c                0   > [         TU ]  USS9  0 U l        g r0  ru  r$   r  r   s     r%   r&   UpdateStatement.__init__  s    7+-r(   c                $    U R                  U5      $ )zSets the search condition to filter.

Args:
    condition (str): Sets the search condition to filter records.

Returns:
    mysqlx.UpdateStatement: UpdateStatement object.
r  r   s     r%   r  UpdateStatement.where  r  r(   c                     U R                   " U6 $ )zSets the order by criteria.

Args:
    *clauses: The expression strings defining the order by criteria.

Returns:
    mysqlx.UpdateStatement: UpdateStatement object.
r  r   s     r%   r  UpdateStatement.order_by  r{  r(   c                    U R                   $ r}  r~  rd   s    r%   r  UpdateStatement.get_update_ops  r  r(   c                Z    [        [        S5      UU5      U R                  U'   SU l        U $ )zUpdates the column value on records in a table.

Args:
    field (string): The column name to be updated.
    value (object): The value to be set on the specified column.

Returns:
    mysqlx.UpdateStatement: UpdateStatement object.
rh  Tr  r  s      r%   r  UpdateStatement.set  s6     #-FG#

 r(   c                p    U R                   (       d  [        S5      eU R                  R                  U 5      $ )z{Execute the statement.

Returns:
    mysqlx.Result: Result object

Raises:
    ProgrammingError: If condition was not set.
z!No condition was found for updater  rd   s    r%   r   UpdateStatement.execute  r  r(   r  r  r   r)   r*   )r   r   r)   r  )r   r   r)   r  r)  )r  r   ro   r   r)   r  rd  )r+   r,   r-   r.   r/   r&   r  r  r  r  r   r0   r+  r,  s   @r%   r  r    s+    .	*	$ $2 2r(   r  c                  D   ^  \ rS rSrSrSU 4S jjrSS jrS	S jrSrU =r	$ )
RemoveStatementi  a)  A statement for document removal from a collection.

Args:
    collection (mysqlx.Collection): The Collection object.
    condition (str): Sets the search condition to identify the documents
                     to be removed.

.. versionchanged:: 8.0.12
   The ``condition`` parameter was added.
c                    > [         TU ]  XS9  g rt  r  rw  s      r%   r&   RemoveStatement.__init__'  s    
@r(   c                     U R                   " U6 $ r  r  r   s     r%   r  RemoveStatement.sort*  r{  r(   c                p    U R                   (       d  [        S5      eU R                  R                  U 5      $ )r  z!No condition was found for remover   r   rZ   send_deleterd   s    r%   r   RemoveStatement.execute5  r  r(   r1   r  )r   r   r)   r  rd  )
r+   r,   r-   r.   r/   r&   r  r   r0   r+  r,  s   @r%   r  r    s    	A	$2 2r(   r  c                  N   ^  \ rS rSrSrSU 4S jjrS	S jrS
S jrSS jrSr	U =r
$ )DeleteStatementiC  zA statement that drops a table.

Args:
    table (mysqlx.Table): The Table object.

.. versionchanged:: 8.0.12
   The ``condition`` parameter was removed.
c                "   > [         TU ]  USS9  g r0  r  r  s     r%   r&   DeleteStatement.__init__M  s    7r(   c                $    U R                  U5      $ )zSets the search condition to filter.

Args:
    condition (str): Sets the search condition to filter records.

Returns:
    mysqlx.DeleteStatement: DeleteStatement object.
r  r   s     r%   r  DeleteStatement.whereP  r  r(   c                     U R                   " U6 $ )zSets the order by criteria.

Args:
    *clauses: The expression strings defining the order by criteria.

Returns:
    mysqlx.DeleteStatement: DeleteStatement object.
r  r   s     r%   r  DeleteStatement.order_by[  r{  r(   c                p    U R                   (       d  [        S5      eU R                  R                  U 5      $ )r  z!No condition was found for deleter  rd   s    r%   r   DeleteStatement.executef  r  r(   r1   r   )r   r   r)   r  )r   r   r)   r  rd  )r+   r,   r-   r.   r/   r&   r  r  r   r0   r+  r,  s   @r%   r  r  C  s!    8	*	$2 2r(   r  c                  J   ^  \ rS rSrSr        SU 4S jjrSS jrSrU =r$ )CreateCollectionIndexStatementit  a  A statement that creates an index on a collection.

Args:
    collection (mysqlx.Collection): Collection.
    index_name (string): Index name.
    index_desc (dict): A dictionary containing the fields members that
                       constraints the index to be created. It must have
                       the form as shown in the following::

                           {"fields": [{"field": member_path,
                                        "type": member_type,
                                        "required": member_required,
                                        "collation": collation,
                                        "options": options,
                                        "srid": srid},
                                        # {... more members,
                                        #      repeated as many times
                                        #      as needed}
                                        ],
                            "type": type}
c                   > [         TU ]  US9  [        R                  " U5      U l        X l        U R                  R                  S/ 5      U l        g )N)r`   r   )r   r&   copydeepcopy_index_desc_index_namepop_fields_desc)r$   rS  
index_name
index_descr   s       r%   r&   'CreateCollectionIndexStatement.__init__  sH     	
++/==+D *262B2B2F2FxQS2Tr(   c                	   U R                   c(  [        [        R                  U R                   5      5      e [	        U R                   5      R                  5       R                  5       n[        U[        5      (       a;  US   [        S5      :w  a(  [        [        R                  U R                   5      5      eOBUR                  [        S5      :w  a(  [        [        R                  U R                   5      5      e U R                  (       d  [        SU R                   35      e[        U R                  [        5      (       d  [        S5      e0 nU R                   US'   U R                   R"                  US'   U R                   R$                  R"                  US'   SU R                  ;   a  U R                  R'                  S5      US'   OS	US'   U R                  R'                  S
S5      US
'   US
   (       a  [)        S5      e/ US'   U R                  (       a  [        SU R                   35      e U R                   GH  n0 nUR'                  S5      US'   UR'                  S5      US'   UR'                  SS5      US'   UR'                  SS5      US'   [        US   [*        5      (       d  [-        S5      e[        US   [*        5      (       d  [-        S5      eUS   R/                  5       S:X  a  US   (       d  [        S5      eUS   R/                  5       S	:X  a  US   S:X  a  [        S5      eSU;   a[  US   R/                  5       R1                  S5      (       d   [        SUS   R/                  5        S35      eUR'                  S5      US'   SU;   a6  US   R/                  5       S:w  a  [        S5      eUR'                  S5      US'   SU;   a6  US   R/                  5       S:w  a  [        S 5      eUR'                  S5      US'   US   R3                  U5        GM     U R                   H  nU(       d  M  [        S#U 35      e   U R6                  R9                  S$S%S&U5      $ ! [        [        4 a.  n[        [        R                  U R                   5      5      UeSnAff = f! [4         a  n[        S!U S"W 35      UeSnAff = f)'ra  NtypezMysqlx.Expr.Expr.Type.IDENTzCRequired member 'fields' not found in the given index description: z,Required member 'fields' must contain a listr  rS  rg   INDEXuniqueFz!Unique indexes are not supported.
constraintzUnidentified fields: r  memberrequiredarrayz'Field member 'required' must be Booleanz$Field member 'array' must be BooleanSPATIALzQField member 'required' must be set to 'True' when index type is set to 'SPATIAL'GEOJSONzIIndex 'type' must be set to 'SPATIAL' when field type is set to 'GEOJSON'	collationTEXTzCThe 'collation' member can only be used when field type is set to ''optionszIThe 'options' member can only be used when index type is set to 'GEOJSON'sridzFThe 'srid' member can only be used when index type is set to 'GEOJSON'zRequired inner member z not found in constraint: zUnidentified inner fields: mysqlxcreate_collection_indexT)r  r   ERR_INVALID_INDEX_NAMEformatr   r#   get_messager4   r   r   r"  r   AttributeErrorr  r  r5   rW   r  rg   r  r   r   	TypeErrorupper
startswithr<  KeyErrorrZ   execute_nonquery)r$   parsed_identr   r!  
field_descr%  s         r%   r   &CreateCollectionIndexStatement.execute  s    #"#9#@#@AQAQ#RSS	%d&6&67<<>JJLL ,--'=9V+WW*.55d6F6FG  X
  $$6S(TT*.55d6F6FG  U   "  $ 0 013 
 $++T22"#QRR!''V!\\..\,,11XT%%%++//7DL"DL))--h>X>#$GHH\"%:4;K;K:L#MNN1	"//

'1~~g'>
8$%/^^F%;
6")3
E)J
:&&0nnWe&D
7#!*Z"8$??#$MNN!*W"5t<<#$JKK<%%'94Z
=S*9  <%%'72z&7IY7V*3  *,%f-335@@HH.  *6 2 8 8 :;1> 
 /9nn[.IJ{+ 
*!&)//1Y>.=  -7NN9,EJy)Z'!&)//1Y>.7  *4)?Jv&\"))*5Y 0d ++Jz&)DZL'QRR , 00/t
 	
m N+ 	"&--d.>.>?	Z  	"(-G
|T	s8   B Q* 8AQ* 1G3R+ *R(:)R##R(+
S5SS)r  r  r  )rS  r   r  r   r  r*  r)   r*   rd  )	r+   r,   r-   r.   r/   r&   r   r0   r+  r,  s   @r%   r  r  t  sD    ,	U&	U 	U #		U
 
	Up
 p
r(   r  )r7   r   r)   zUnion[List, Tuple])r   )r>   r   r?   r   r)   r   )r>   r   r?   r   r)   r   )rH   zIterable[str]r?   r   r)   r   )rM   r   rN   r   r?   r   r)   zTuple[str, str])=r/   
__future__r   r  r   r  typingr   r   r   r   r   r	   r
   	constantsr   dbdocr   errorsr   r   r#   r   helpersr   protobufr   resultr   r   r   r   typesr   r   r   r   r   r   r2  r   r8   r@   rD   rI   rR   rT   r   r.  rD  rO  rf  rr  r  r  r  r  r  r  r  r  r1   r(   r%   <module>rG     sa  > $ "    D D D %  7   # ; ;  B  :"(  ;=%(47,g" g"TW") W"t
?/9 ?/D'"Y '"T82> 82v   Fk2) k2\z0' z0z%$M %$P6m 6r2n 2BI2) I2X%2) %2P.2) .2bR
Y R
r(   