
    vdO                     $   d Z ddlZddl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lmZ dd	lmZ dd
lmZmZmZ  G d de          Zd Zd?dZd?dZd?dZd?dZ G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z  G d de          Z! G d d e          Z" G d! d"e          Z# G d# d$e          Z$ G d% d&e          Z% G d' d(e          Z& G d) d*e          Z' G d+ d,e          Z( G d- d.e          Z) G d/ d0e          Z* G d1 d2e          Z+ G d3 d4e+          Z, G d5 d6e          Z- G d7 d8e          Z. G d9 d:e.          Z/ G d; d<e/          Z0 G d= d>e          Z1dS )@zImplementation of Statements.    N   )ProgrammingError)
ExprParser)STRING_TYPES)
Algorithms
Securities)DbDoc)mysqlx_crud_pb2)	SqlResultResult
ColumnTypec                       e Zd Zd ZdS )Exprc                     || _         d S N)expr)selfr   s     L/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/mysqlx/statement.py__init__zExpr.__init__&   s    			    N)__name__
__module____qualname__r    r   r   r   r   %   s#            r   r   c                      t          |           dk    r*t          | d         t          t          f          r| d         S | S )Nr   r   )len
isinstancelisttuple)valuess    r   flexible_paramsr!   *   s9    
6{{aJvay4.AAayMr    c                     d|v r0| d         dk    r| d         dk    p| d         dk    o| d         dk    S | d         dk    o| d         dk    S )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   `"r   
identifiersql_modes     r   is_quoted_identifierr+   0   sn       A#%?*R.C*? AA#%?*R.C*?	B !}#=
2#(==r   c                     t          | |          r| S d|v r)d                    |                     dd                    S d                    |                     dd                    S )a  Quote the given identifier with backticks, converting backticks (`) in
    the identifier name with the correct escape sequence (``) unless the
    identifier is quoted (") as in sql_mode set to ANSI_QUOTES.

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

    Returns:
        A string with the identifier quoted with backticks.
    r$   z"{0}"r'   z""z`{0}`r%   z``)r+   formatreplacer(   s     r   quote_identifierr/   A   sk     J11   ~~j00d;;<<<~~j00d;;<<<r   c                 F    d                     fd| D                       S )a  Quote 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.
    .c                 0    g | ]}t          |          S r   r/   ).0r)   r*   s     r   
<listcomp>z.quote_multipart_identifier.<locals>.<listcomp>_   s3     4 4 4# &j(;; 4 4 4r   )join)identifiersr*   s    `r   quote_multipart_identifierr8   U   sA     88 4 4 4 4'24 4 4 5 5 5r   c                    d|v rdnd}||v rd                     |          nd}|                    |d          }t          |          du r| n|d                             |          |d                             |          fS )	Nr$   r'   r%   z.{0}r1   r   r   r&   )r-   splitr   strip)default_schema
table_namer*   quote	delimitertemps         r   parse_table_namerA   c   s     H,,CC#E(-(;(;e$$$IIq))D!$ii1nnNN$q'--2F2FHNN5!!$ $r   c                   L    e Zd ZdZddZed             Zed             Zd ZdS )		Statementa	  Provides 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.
    Tc                 B    || _         || _        |r|j        nd | _        d S r   )_target
_doc_based_connection)r   target	doc_baseds      r   r   zStatement.__init__s   s+    #17A6--Tr   c                     | j         S )z,object: The database object target.
        )rE   r   s    r   rH   zStatement.targetx   s     |r   c                     | j         j        S )z3:class:`mysqlx.Schema`: The Schema object.
        )rE   schemarK   s    r   rM   zStatement.schema~   s     |""r   c                     t           zqExecute the statement.

        Raises:
           NotImplementedError: This method must be implemented.
        NotImplementedErrorrK   s    r   executezStatement.execute   
     "!r   N)T)	r   r   r   __doc__r   propertyrH   rM   rR   r   r   r   rC   rC   k   s{         B B B B
   X
 # # X#
" " " " "r   rC   c                   \     e Zd ZdZd fd	Zd Zd ZddZd	 Zd
 Z	d Z
d Zd Zd Z xZS )FilterableStatementa  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.
    TNc                    t          t          |                               ||           d| _        d| _        d| _        d| _        d| _        d| _        d| _	        i | _
        g | _        ||                     |           d S d S )NrH   rI   F)superrW   r   _has_projection
_has_where
_has_limit	_has_sort_has_group_by_has_having_has_bindings_binding_map	_bindingswhere)r   rH   rI   	condition	__class__s       r   r   zFilterableStatement.__init__   s    !4((11<E 	2 	G 	G 	G$" " JJy!!!!! ! r   c                     d| _         || _        t          || j                   }|                                | _        |j        | _        | S )a  Sets the search condition to filter.

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

        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
        T)r\   _wherer   rF   r   _where_exprplaceholder_name_to_positionrb   )r   re   r   s      r   rd   zFilterableStatement.where   sF     )%89999;; =r   c                     t          | }d| _        d                    |          | _        t	          | j        | j                                                   | _        | S NT,)r!   r[   r6   _projection_strr   rF   parse_table_select_projection_projection_exprr   fieldss     r   _projectionzFilterableStatement._projection   s[     &)#"xx// *4+?!! !!!>!>!@!@ 	r   r   c                 0    d| _         || _        || _        | S )aE  Sets the maximum number of records or documents to be returned.

        Args:
            row_count (int): The maximum number of records or documents.
            offset (Optional[int]) The number of records or documents to skip.

        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
        T)r]   _limit_offset_limit_row_count)r   	row_countoffsets      r   limitzFilterableStatement.limit   s      # )r   c                     t          | }d| _        d                    |          | _        t	          | j        | j                                                   | _        | S )zSets the sorting criteria.

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

        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
        Trm   )r!   r^   r6   	_sort_strr   rF   parse_order_spec
_sort_expr)r   sort_clausess     r   sortzFilterableStatement.sort   sY     '5,//$T^)-%8: ::J:J:L:L 	r   c                     t          | }d| _        d                    |          | _        t	          | j        | j                                                   | _        d S rl   )r!   r_   r6   _grouping_strr   rF   parse_expr_list	_groupingrq   s     r   	_group_byzFilterableStatement._group_by   sX     &)! XXf--#D$6(,$79 99H9J9J 	r   c                 n    d| _         t          || j                                                   | _        d S NT)r`   r   rF   r   _havingr   re   s     r   r   zFilterableStatement._having   s0    !)-@AAFFHHr   c                     d| _         t          |          }|dk    r|                     |d                    n>|dk    rt          d          | j                            |d         |d         d           | S )a  Binds a value to a specific placeholder.

        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      z#Invalid number of arguments to bind)namevalue)ra   r   _bind_singler   rc   append)r   argscounts      r   bindzFilterableStatement.bind   s~     "D		A::d1g&&&&QYY"#HIIIN!!47T!W"E"EFFFr   c                 4   t          |t                    r$|                     t          |                     d S t          |t                    rGt          j        |          }|                                D ] }|                     |||                    d S d S r   )r   r	   r   strr   jsonloadskeys)r   objectdictkeys       r   r   z FilterableStatement._bind_single  s    fe$$ 	*IIc&kk"""""-- 	*:f%%Dyy{{ * *		#tCy))))	* 	** *r   c                     t           rO   rP   rK   s    r   rR   zFilterableStatement.execute
  rS   r   )TN)r   )r   r   r   rT   r   rd   rs   ry   r   r   r   r   r   rR   __classcell__rf   s   @r   rW   rW      s        	 	" " " " " "  "        K K KI I I  0* * *" " " " " " "r   rW   c                   (     e Zd ZdZ fdZd Z xZS )SqlStatementzA statement for SQL execution.

    Args:
        connection (mysqlx.connection.Connection): Connection object.
        sql (string): The sql statement to be executed.
    c                 x    t          t          |                               d d           || _        || _        d S NFrY   )rZ   r   r   rG   _sql)r   
connectionsqlrf   s      r   r   zSqlStatement.__init__  s9    lD!!**$%*HHH%			r   c                 h    | j                             | j                   t          | j                   S )zaExecute the statement.

        Returns:
            mysqlx.SqlResult: SqlResult object.
        )rG   send_sqlr   r   rK   s    r   rR   zSqlStatement.execute  s.     	!!$),,,)***r   r   r   r   rT   r   rR   r   r   s   @r   r   r     sQ             
+ + + + + + +r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )AddStatementzA statement for document addition on a collection.

    Args:
        collection (mysqlx.Collection): The Collection object.
    c                 v    t          t          |                               |           g | _        g | _        d S N)rH   )rZ   r   r   _values_idsr   
collectionrf   s     r   r   zAddStatement.__init__/  s6    lD!!****===			r   c                     t          | D ]Y}t          |t                    r| j                            |           2| j                            t          |                     Z| S )zAdds a list of documents into a collection.

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

        Returns:
            mysqlx.AddStatement: AddStatement object.
        )r!   r   r	   r   r   )r   r    vals      r   addzAddStatement.add4  sg     #F+ 	0 	0C#u%% 0##C((((##E#JJ////r   c                     t          | j                  dk    rt                      S | j        D ].}| j                            |                                           /| j                            |           S )[Execute the statement.

        Returns:
            mysqlx.Result: Result object.
        r   )r   r   r   r   r   	ensure_idrG   send_insert)r   docs     r   rR   zAddStatement.executeD  sk     t|!!88O< 	. 	.CIS]]__----++D111r   )r   r   r   rT   r   r   rR   r   r   s   @r   r   r   )  s`         
    
   2 2 2 2 2 2 2r   r   c                       e Zd ZddZd ZdS )
UpdateSpecNc                 H   |t           j        j        k    r|                     ||           d S || _        || _        t          |          dk    r|d         dk    r|dd          | _        t          | j        d                                          j	        | _        || _
        d S )Nr   $r   F)
MySQLxCrudUpdateOperationSET
_table_setupdate_typesourcer   r   document_fieldr)   r   )r   r   r   r   s       r   r   zUpdateSpec.__init__T  s    *4888OOFE******D DK6{{Q6!9#3#3$QRRj$T[%*, ,,:N,<,<Z KDJJJr   c                     t           j        j        | _        t	          |d                                          | _        || _        d S r   )r   r   r   r   r   parse_table_update_fieldr   r   )r   r   r   s      r   r   zUpdateSpec._table_set`  s8    %59 ..GGII


r   r   )r   r   r   r   r   r   r   r   r   r   S  s7        
 
 
 
    r   r   c                   H     e Zd ZdZd
 fd	Zd Zd Zd Zd Zd Z	d	 Z
 xZS )ModifyStatementa  A statement for document update operations on a Collection.

    Args:
        collection (mysqlx.Collection): The Collection object.
        condition (Optional[str]): Sets the search condition to identify the
                                   documents to be updated.
    Nc                 j    t          t          |                               ||           g | _        d S )N)rH   re   )rZ   r   r   _update_opsr   r   re   rf   s      r   r   zModifyStatement.__init__n  s@    ot$$--Z8A 	. 	C 	C 	Cr   c                 v    | j                             t          t          j        j        ||                     | S )a2  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.
        )r   r   r   r   r   ITEM_SETr   doc_pathr   s      r   setzModifyStatement.sets  s<     	z1:HeLL	N 	N 	Nr   c                 v    | j                             t          t          j        j        ||                     | S )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.
        )r   r   r   r   r   ITEM_REPLACEr   s      r   changezModifyStatement.change  s@     	z1> 	 	 	 r   c                 \    | j                             d t          | D                        | S )a  Removes attributes from documents in a collection.

        Args:
            doc_path (string): The document path of the attribute to be
                               removed.

        Returns:
            mysqlx.ModifyStatement: ModifyStatement object.
        c                 L    g | ]!}t          t          j        j        |          "S r   )r   r   r   ITEM_REMOVE)r4   xs     r   r5   z)ModifyStatement.unset.<locals>.<listcomp>  s8     !2 !2 !2 z1=qAA!2 !2 !2r   )r   extendr!   )r   	doc_pathss     r   unsetzModifyStatement.unset  sG     	 !2 !2$i0!2 !2 !2 	3 	3 	3 r   c                 v    | j                             t          t          j        j        ||                     | S )a  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.
        )r   r   r   r   r   ARRAY_INSERTr   fieldr   s      r   array_insertzModifyStatement.array_insert  s<     	z1>uMM	O 	O 	Or   c                 v    | j                             t          t          j        j        ||                     | S )a  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.
        )r   r   r   r   r   ARRAY_APPENDr   s      r   array_appendzModifyStatement.array_append  s@     	z1> 	 	 	 r   c                 6    | j                             |           S r   rG   updaterK   s    r   rR   zModifyStatement.execute       &&t,,,r   r   )r   r   r   rT   r   r   r   r   r   r   rR   r   r   s   @r   r   r   f  s              
            $- - - - - - -r   r   c                   <     e Zd ZdZd fd	Zd Zd Zd Zd Z xZ	S )	FindStatementa  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.
    Nc                 \    t          t          |                               |d|           d S r   )rZ   r   r   r   s      r   r   zFindStatement.__init__  s+    mT""++JiHHHHHr   c                      | j         | S )zSets a document field filter.

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

        Returns:
            mysqlx.FindStatement: FindStatement object.
        )rs   rq   s     r   rr   zFindStatement.fields  s      t((r   c                      | j         |  | S )zSets a grouping criteria for the resultset.

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

        Returns:
            mysqlx.FindStatement: FindStatement object.
        r   rq   s     r   group_byzFindStatement.group_by       	r   c                 0    |                      |           | S )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.FindStatement: FindStatement object.
        r   r   s     r   havingzFindStatement.having       	Yr   c                 6    | j                             |           S )zaExecute the statement.

        Returns:
            mysqlx.DocResult: DocResult object.
        rG   findrK   s    r   rR   zFindStatement.execute       $$T***r   r   )
r   r   r   rT   r   rr   r   r   rR   r   r   s   @r   r   r     s         I I I I I I
) 
) 
)
 
 
  + + + + + + +r   r   c                   :     e Zd ZdZ fdZd Zd Zd Zd Z xZ	S )SelectStatementzA statement for record retrieval operations on a Table.

    Args:
        table (mysqlx.Table): The Table object.
        *fields: The fields to be retrieved.
    c                 n    t          t          |                               |d            | j        |  d S NF)rZ   r   r   rs   r   tablerr   rf   s      r   r   zSelectStatement.__init__  s9    ot$$--eU;;;&!!!!r   c                      | j         |  | S )zSets a grouping criteria for the resultset.

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

        Returns:
            mysqlx.SelectStatement: SelectStatement object.
        r   rq   s     r   r   zSelectStatement.group_by  r   r   c                 0    |                      |           | S )a;  Sets a condition for records to be considered in agregate function
        operations.

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

        Returns:
            mysqlx.SelectStatement: SelectStatement object.
        r   r   s     r   r   zSelectStatement.having  r   r   c                 6    | j                             |           S )zaExecute the statement.

        Returns:
            mysqlx.RowResult: RowResult object.
        r   rK   s    r   rR   zSelectStatement.execute,  r   r   c           
         | j         rd                    | j                  nd}| j        rd                    | j                  nd}| j        rd                    | j                  nd}| j        rd                    | j                  nd}| j	        r d                    | j
        | j                  nd}d                    t          | dd	          | j        j        | j        j        |||||
          }|S )Nz
 WHERE {0}r"   z GROUP BY {0}z HAVING {0}z ORDER BY {0}z LIMIT {0} OFFSET {1}zISELECT {select} FROM {schema}.{table}{where}{group}{having}{order}{limit}rn   *)selectrM   r   ry   rd   groupr   order)r\   r-   rh   r_   r   r`   r   r^   r{   r]   rv   ru   getattrrM   r   rH   )r   rd   r   r   order_byry   stmts          r   get_sqlzSelectStatement.get_sql4  s   48OK##DK000'?))$*<===$& 	7;7GO%%dl333R=A^ ?))$.999 	 $(?;'..t/D     8: 	!!'t%6<<{'t{/?u8F( "( "L "L 	 r   )
r   r   r   rT   r   r   r   rR   r  r   r   s   @r   r   r     s~         " " " " "
 
 
  + + +      r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )InsertStatementzA statement for insert operations on Table.

    Args:
        table (mysqlx.Table): The Table object.
        *fields: The fields to be inserted.
    c                     t          t          |                               |d           t          | | _        g | _        d S r   )rZ   r  r   r!   _fieldsr   r   s      r   r   zInsertStatement.__init__M  s=    ot$$--Ue-LLL&/r   c                 b    | j                             t          t          |                      | S )zSet the values to be inserted.

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

        Returns:
            mysqlx.InsertStatement: InsertStatement object.
        )r   r   r   r!   r   r    s     r   r    zInsertStatement.valuesR  s,     	D&!9::;;;r   c                 6    | j                             |           S r   )rG   r   rK   s    r   rR   zInsertStatement.execute^  s     ++D111r   )r   r   r   rT   r   r    rR   r   r   s   @r   r  r  F  s`             

 
 
2 2 2 2 2 2 2r   r  c                   .     e Zd ZdZ fdZd Zd Z xZS )UpdateStatementzA statement for record update operations on a Table.

    Args:
        table (mysqlx.Table): The Table object.
        *fields: The fields to be updated.
    c                 j    t          t          |                               |d           g | _        d S r   )rZ   r  r   r   r   s      r   r   zUpdateStatement.__init__n  s4    ot$$--Ue-LLLr   c                 v    | j                             t          t          j        j        ||                     | S )a  Updates 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.
        )r   r   r   r   r   r   r   s      r   r   zUpdateStatement.setr  s<     	z15ueDD	F 	F 	Fr   c                 6    | j                             |           S )zZExecute the statement.

        Returns:
            mysqlx.Result: Result object
        r   rK   s    r   rR   zUpdateStatement.execute  r   r   )r   r   r   rT   r   r   rR   r   r   s   @r   r  r  g  s`               - - - - - - -r   r  c                   (     e Zd ZdZ fdZd Z xZS )RemoveStatementzA statement for document removal from a collection.

    Args:
        collection (mysqlx.Collection): The Collection object.
    c                 Z    t          t          |                               |           d S r   )rZ   r  r   r   s     r   r   zRemoveStatement.__init__  s*    ot$$--Z-@@@@@r   c                 6    | j                             |           S r   rG   deleterK   s    r   rR   zRemoveStatement.execute  r   r   r   r   s   @r   r  r    sV         
A A A A A- - - - - - -r   r  c                   *     e Zd ZdZd fd	Zd Z xZS )DeleteStatementzA statement that drops a table.

    Args:
        table (mysqlx.Table): The Table object.
        condition (Optional[str]): The string with the filter expression of
                                   the rows to be deleted.
    Nc                 ^    t          t          |                               ||d           d S )NF)rH   re   rI   )rZ   r  r   )r   r   re   rf   s      r   r   zDeleteStatement.__init__  s<    ot$$--U8A8= 	. 	? 	? 	? 	? 	?r   c                 6    | j                             |           S r   r  rK   s    r   rR   zDeleteStatement.execute  r   r   r   r   r   s   @r   r  r    sV         ? ? ? ? ? ?
- - - - - - -r   r  c                   .     e Zd ZdZ fdZd Zd Z xZS )CreateCollectionIndexStatementzA statement that creates an index on a collection.

    Args:
        collection (mysqlx.Collection): Collection.
        index_name (string): Index name.
        is_unique (bool): `True` if the index is unique.
    c                     t          t          |                               |           || _        || _        g | _        d S r   )rZ   r  r   _index_name
_is_uniquer
  )r   r   
index_name	is_uniquerf   s       r   r   z'CreateCollectionIndexStatement.__init__  s?    ,d33<<J<OOO%#r   c                 @    | j                             |||f           | S )a  Add the field specification to this index creation statement.

        Args:
            document_path (string): The document path.
            column_type (string): The column type.
            is_required (bool): `True` if the field is required.

        Returns:
            mysqlx.CreateCollectionIndexStatement:                                    CreateCollectionIndexStatement object.
        )r
  r   )r   document_pathcolumn_typeis_requireds       r   r   z$CreateCollectionIndexStatement.field  s&     	]KFGGGr   c           	          d | j         D             } | j        j        ddd| j        j        j        | j        j        | j        | j        g|R  S )r   c                     g | ]	}|D ]}|
S r   r   )r4   sublistitems      r   r5   z:CreateCollectionIndexStatement.execute.<locals>.<listcomp>  s%    GGG7wGGt$GGGGr   xplugincreate_collection_indexT)r
  rG   execute_nonqueryrE   rM   r   r   r!  rq   s     r   rR   z&CreateCollectionIndexStatement.execute  sg     HGdlGGG0t00$L$dl&79IO& %& & & 	&r   )r   r   r   rT   r   r   rR   r   r   s   @r   r  r    s`               
& 
& 
& 
& 
& 
& 
&r   r  c                   (     e Zd ZdZ fdZd Z xZS )DropCollectionIndexStatementzA statement that drops an index on a collection.

    Args:
        collection (mysqlx.Collection): The Collection object.
        index_name (string): The index name.
    c                 h    t          t          |                               |           || _        d S r   )rZ   r0  r   r   )r   r   r"  rf   s      r   r   z%DropCollectionIndexStatement.__init__  s3    *D11::*:MMM%r   c                 |    | j                             ddd| j        j        j        | j        j        | j                  S )r   r,  drop_collection_indexT)rG   r.  rE   rM   r   r   rK   s    r   rR   z$DropCollectionIndexStatement.execute  sA     00.L$dl&79IK K 	Kr   r   r   s   @r   r0  r0    sX         & & & & &K K K K K K Kr   r0  c                   "    e Zd ZdZdZd Zd ZdS )
TableIndexr   r   c                 0    || _         || _        || _        d S r   )_name_index_type_columns)r   r   
index_typecolumnss       r   r   zTableIndex.__init__  s    
%r   c                     d}| j         t          j        u r|dz  }|dz  }|                    | j        d                    | j                            S )Nr"   zUNIQUE zINDEX {0} ({1})rm   )r8  r5  UNIQUE_INDEXr-   r7  r6   r9  )r   r  s     r   r  zTableIndex.get_sql  sQ    z666ID!!{{4:sxx'>'>???r   N)r   r   r   r=  INDEXr   r  r   r   r   r5  r5    sA        LE     
@ @ @ @ @r   r5  c                   N     e Zd ZdZd fd	Zd Zd Zd Zd Zd Z	d	 Z
d
 Z xZS )CreateViewStatementzA statement for creating views.

    Args:
        view (mysqlx.View): The View object.
        replace (Optional[bool]): `True` to add replace.
    Fc                 $   t          t          |                               |d           || _        |j        | _        |j        | _        || _        g | _	        t          j        | _        t          j        | _        d | _        d | _        d | _        d S r   )rZ   r@  r   _viewrM   _schemar   r7  _replacer9  r   	UNDEFINED
_algorithmr   DEFINER	_security_definer_defined_as_check_option)r   viewr.   rf   s      r   r   zCreateViewStatement.__init__  s    !4((111OOO
{Y
$.#+!r   c                 (    d |D             | _         | S )zSets the column names.

        Args:
            columns (list): The list of column names.

        Returns:
            mysqlx.CreateViewStatement: CreateViewStatement object.
        c                 ,    g | ]}t          |          S r   r3   )r4   cols     r   r5   z/CreateViewStatement.columns.<locals>.<listcomp>  s!    BBB3)#..BBBr   )r9  )r   r;  s     r   r;  zCreateViewStatement.columns  s     CB'BBBr   c                     || _         | S )zSets the algorithm.

        Args:
            mysqlx.constants.ALGORITHMS: The algorithm.

        Returns:
            mysqlx.CreateViewStatement: CreateViewStatement object.
        )rF  )r   	algorithms     r   rQ  zCreateViewStatement.algorithm!       $r   c                     || _         | S )zSets the SQL security mode.

        Args:
            mysqlx.constants.SECURITIES: The SQL security mode.

        Returns:
            mysqlx.CreateViewStatement: CreateViewStatement object.
        )rH  )r   securitys     r   rT  zCreateViewStatement.security-  s     "r   c                     || _         | S )zSets the definer.

        Args:
            definer (string): The definer.

        Returns:
            mysqlx.CreateViewStatement: CreateViewStatement object.
        )rI  )r   definers     r   rV  zCreateViewStatement.definer9        r   c                     || _         | S )zSets the SelectStatement statement for describing the view.

        Args:
            mysqlx.SelectStatement: SelectStatement object.

        Returns:
            mysqlx.CreateViewStatement: CreateViewStatement object.
        )rJ  )r   	statements     r   
defined_aszCreateViewStatement.defined_asE  s     %r   c                     || _         | S )zSets the check option.

        Args:
            mysqlx.constants.CHECK_OPTIONS: The check option.

        Returns:
            mysqlx.CreateViewStatement: CreateViewStatement object.
        )rK  )r   check_options     r   with_check_optionz%CreateViewStatement.with_check_optionQ  s     *r   c           
         | j         rdnd}| j        rd                    | j                  nd}| j        r-d                    d                    | j                            nd}t          | j        j        | j        f          }| j	        rd                    | j	                  nd}d                    || j
        || j        ||| j        |          }| j                            d	|           | j        S )
zhExecute the statement to create a view.

        Returns:
            mysqlx.View: View object.
        z OR REPLACEr"    DEFINER = {0} ({0}),  WITH {0} CHECK OPTIONzCREATE{replace} ALGORITHM = {algorithm}{definer} SQL SECURITY {security} VIEW {view_name}{columns} AS {defined_as}{check_option})r.   rQ  rV  rT  	view_namer;  rZ  r\  r   )rD  rI  r-   r9  r6   r8   rC  r   r7  rK  rF  rH  rJ  rG   r.  rB  )r   r.   rV  r;  rc  r\  r   s          r   rR   zCreateViewStatement.execute]  s    $(=8--b]+"))$-888(* 	 ]+(//$))DM":":;;;(* 	.0A4:/NOO	,5/66t7IJJJ24 	 &DO!(4>#,g$($4&2	  4 4 	 	))%555zr   )F)r   r   r   rT   r   r;  rQ  rT  rV  rZ  r]  rR   r   r   s   @r   r@  r@    s         " " " " " "
 
 

 
 

 
 

 
 

 
 

 
 
      r   r@  c                   (     e Zd ZdZ fdZd Z xZS )AlterViewStatementzYA statement for alter views.

    Args:
        view (mysqlx.View): The View object.
    c                 X    t          t          |                               |           d S r   )rZ   re  r   )r   rL  rf   s     r   r   zAlterViewStatement.__init__~  s(     $''0066666r   c           	         | j         rd                    | j                   nd}| j        r-d                    d                    | j                            nd}t	          | j        j        | j        f          }| j        rd                    | j                  nd}d                    | j	        || j
        ||| j        |          }| j                            d|           | j        S )	zgExecute the statement to alter a view.

        Returns:
            mysqlx.View: View object.
        r_  r"   r`  ra  rb  zvALTER ALGORITHM = {algorithm}{definer} SQL SECURITY {security} VIEW {view_name}{columns} AS {defined_as}{check_option})rQ  rV  rT  rc  r;  rZ  r\  r   )rI  r-   r9  r6   r8   rC  r   r7  rK  rF  rH  rJ  rG   r.  rB  )r   rV  r;  rc  r\  r   s         r   rR   zAlterViewStatement.execute  s     ]+"))$-888(* 	 ]+(//$))DM":":;;;(* 	.0A4:/NOO	,5/66t7IJJJ24 	 &4?G"&.I!(T5E&2  4 4 	 	))%555zr   r   r   s   @r   re  re  x  sQ         
7 7 7 7 7      r   re  c                        e Zd ZdZ ej        dej                  Z fdZe	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 xZS )CreateTableStatementzA statement that creates a new table if it doesn't exist already.

    Args:
        collection (mysqlx.Schema): The Schema object.
        table_name (string): The name for the new table.
    z$(from\s+)([`\"].+[`\"]|[^\.]+)(\s|$)c                 p   t          t          |                               |           d | _        d | _        d | _        d | _        d | _        d| _        g | _	        g | _
        g | _        g | _        g | _        d| _        || _        d                    | j                                                  | _        d S )NFr   z
\1{0}.\2\3)rZ   ri  r   _charset
_collation_comment_as_like_tempr9  _f_keys_indices_p_keys
_u_indices	_auto_incr7  r-   rM   get_name	_tbl_repl)r   rM   r=   rf   s      r   r   zCreateTableStatement.__init__  s    "D))226:::


&--dk.B.B.D.DEEr   c                 Z    t          t          | j        j        | j                            S )z7string: The fully qualified name of the Table.
        )r8   rA   rM   r   r7  rK   s    r   r=   zCreateTableStatement.table_name  s/     **:Kdj+* +* + + 	+r   c                 \   g }|                     d           | j        r|                     d           | j        r|                     d           | j        r|                     d           d                    |          }|                    | j        | j        | j        | j                  S )NzAUTO_INCREMENT = {inc}z!DEFAULT CHARACTER SET = {charset}zDEFAULT COLLATE = {collation}zCOMMENT = '{comment}'rm   )inccharset	collationcomment)r   rk  rl  rm  r6   r-   ru  )r   options
table_optss      r   _get_table_optsz$CreateTableStatement._get_table_opts  s    /000= 	@NN>???? 	<NN:;;;= 	4NN2333XXg&&
  T^T]ot} ! > > 	>r   c                 F   g }| j         r@|                    d                    d                    | j                                        | j        D ])}|                    |                                           *| j        D ])}|                    |                                           *| j        D ])}|                    |                                           *| j        D ])}|                    |                                           *d                    |          S )NzPRIMARY KEY ({0})rm   )	rs  r   r-   r6   r9  r  rq  rr  rt  )r   defsrO  r   indexs        r   _get_create_defz$CreateTableStatement._get_create_def  s	   < 	LKK+22388DL3I3IJJKKK= 	' 	'CKK&&&&< 	' 	'CKK&&&&] 	) 	)EKK((((_ 	) 	)EKK((((xx~~r   c                 ^    t          t          | j        j        |                    | _        | S )zCreate table with the definition of another existing Table.

        Args:
            table_name (string): Name of the source table.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        )r8   rA   rM   r   ro  )r   r=   s     r   likezCreateTableStatement.like  s,     0T[-z::< <
r   c                     t          |t                    r+t          j                            | j        |          | _        n.t          |t                    r|                                | _        | S )a.  Create the Table and fill it with values from a Select Statement.

        Args:
            select (object): Select Statement. Can be a string or an instance of
            :class`mysqlx.SelectStatement`.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        )	r   r   ri  tbl_frmtsubrw  rn  r   r  )r   r   s     r   	as_selectzCreateTableStatement.as_select  s\     fl++ 	(+488PPDHH00 	(~~''DHr   c                     |                     | j                                                   | j                            |           | S )zAdd a Column to the Table.

        Args:
            column_def (MySQLx.ColumnDef): Column Definition object.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        )
set_schemarM   rv  r9  r   )r   
column_defs     r   
add_columnzCreateTableStatement.add_column  sA     	dk2244555Z(((r   c                 L    t          | }| j                            |           | S )zAdd multiple Primary Keys to the Table.

        Args:
            *keys: Fields to be used as Primary Keys.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        )r!   rs  r   )r   r   s     r   add_primary_keyz$CreateTableStatement.add_primary_key  s)     %D!!!r   c           	      z    | j                             t          |t          j        t	          |                      | S )zAdds an Index to the Table.

        Args:
            index_name (string): Name of the Index.
            *cols: Fields to be used as an Index.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        )rr  r   r5  r>  r!   r   r"  colss      r   	add_indexzCreateTableStatement.add_index  s>     	Z
J4DT"$ $ 	% 	% 	%r   c           	      z    | j                             t          |t          j        t	          |                      | S )a  Adds a Unique Index to the Table.

        Args:
            index_name (string): Name of the Unique Index.
            *cols: Fields to be used as a Unique Index.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        )rt  r   r5  r=  r!   r  s      r   add_unique_indexz%CreateTableStatement.add_unique_index  s>     	z*j6MT" $  $ 	% 	% 	%r   c                     |                     | j                                                   |                    |           | j                            |           | S )zAdds a Foreign Key to the Table.

        Args:
            key (MySQLx.ForeignKeyDef): The Foreign Key Definition object.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        )r  rM   rv  set_namerq  r   )r   r   r   s      r   add_foreign_keyz$CreateTableStatement.add_foreign_key*  sQ     	t{++--...TC   r   c                     || _         | S )zSet the initial Auto Increment value for the table.

        Args:
            inc (int): The initial AUTO_INCREMENT value for the table.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        ru  )r   rz  s     r   set_initial_auto_incrementz/CreateTableStatement.set_initial_auto_increment8  s     r   c                     || _         | S )zSets the default Charset type for the Table.

        Args:
            charset (string): Charset type.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        rk  r   r{  s     r   set_default_charsetz(CreateTableStatement.set_default_charsetD  rW  r   c                     || _         | S )zSets the default Collation type for the Table.

        Args:
            collation (string): Collation type.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        rl  r   r|  s     r   set_default_collationz*CreateTableStatement.set_default_collationP  rR  r   c                     || _         | S )zAdd a comment to the Table.

        Args:
            comment (string): Comment to be added to the Table.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        rm  r   r}  s     r   set_commentz CreateTableStatement.set_comment\  rW  r   c                     d| _         | S )zSet the Table to be Temporary.

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        T)rp  rK   s    r   	temporaryzCreateTableStatement.temporaryh  s     
r   c                 p   d                     | j        | j        rdnd          }| j        rd}nd}|                     || j        p| j        pd|                                 |                                           }| j                            d	|d
           | j	        
                    | j                  S )zYExecute the statement.

        Returns:
            mysqlx.Table: Table object.
        zCREATE {table_type} {name}zTEMPORARY TABLETABLE)r   
table_typez{create} LIKE {query}z,{create} ({create_def}) {table_opts} {query}r"   )createquery
create_defr  r   F)r-   r=   rp  ro  rn  r  r  rG   r.  rM   	get_tabler7  )r   r  r  s      r   rR   zCreateTableStatement.executeq  s     .44$/,0JC((G 5 E E: 	B*DDAD{{*..B++--++--	  / / 	))%u==={$$TZ000r   )r   r   r   rT   recompile
IGNORECASEr  r   rU   r=   r  r  r  r  r  r  r  r  r  r  r  r  r  r  rR   r   r   s   @r   ri  ri    s[         rzA2=QQHF F F F F$ + + X+> > >                 
 
 

 
 

 
 

 
 
  1 1 1 1 1 1 1r   ri  c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	ColumnDefBasezA Base class defining the basic parameters required to define a column.

    Args:
        name (string): Name of the column.
        type (MySQLx.ColumnType): Type of the column.
        size (int): Size of the column.
    c                 v    d | _         d| _        d| _        d| _        || _        || _        d| _        || _        d S )NFr"   )_default_schema	_not_null_p_key_u_indexr7  _sizerm  _type)r   r   typesizes       r   r   zColumnDefBase.__init__  s?    #




r   c                     d| _         | S )zwDisable NULL values for this column.

        Returns:
            mysqlx.ColumnDefBase: ColumnDefBase object.
        T)r  rK   s    r   not_nullzColumnDefBase.not_null       r   c                     d| _         | S )zwSet current column as a Unique Index.

        Returns:
            mysqlx.ColumnDefBase: ColumnDefBase object.
       T)r  rK   s    r   unique_indexzColumnDefBase.unique_index  s     r   c                     || _         | S )zAdd a comment to the column.

        Args:
            comment (string): Comment to be added to the column.

        Returns:
            mysqlx.ColumnDefBase: ColumnDefBase object.
        r  r  s     r   r}  zColumnDefBase.comment  rW  r   c                     d| _         | S )ztSets the Column as a Primary Key.

        Returns:
            mysqlx.ColumnDefBase: ColumnDefBase object.
        T)r  rK   s    r   primaryzColumnDefBase.primary  s     r   c                     || _         d S r   r  r   rM   s     r   r  zColumnDefBase.set_schema      %r   N)
r   r   r   rT   r   r  r  r}  r  r  r   r   r   r  r    sx               
 
 
  & & & & &r   r  c                   l     e Zd ZdZd f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 xZS )	ColumnDefzClass containing the complete definition of the Column.

    Args:
        name (string): Name of the column.
        type (MySQL.ColumnType): Type of the column.
        size (int): Size of the column.
    Nc                     t          t          |                               |||           d | _        d | _        d | _        d | _        d| _        d| _        d| _	        g | _
        g | _        d | _        d | _        d S r   )rZ   r  r   _ref_default	_decimals
_ref_table_binaryru  	_unsignedr   _ref_fieldsrk  rl  )r   r   r  r  rf   s       r   r   zColumnDef.__init__  sw    i''dD999	r   c                 D   d}| j         rft          j        | j                  s2t          j        | j                  st          j        | j                  rd                    | j                   }nt          j        | j                  r*| j         r#d                    | j         | j        pd          }nFt          j	        | j                  r-d                    d
                    | j                            }| j        rd                    |          }| j        rd                    |          }| j        rd                    || j                  }| j        rd	                    || j                  }d
                    t          j        | j                  |          S )Nr"   z({0})z
({0}, {1})r   rm   z{0} UNSIGNEDz
{0} BINARYz{0} CHARACTER SET {1}z{0} COLLATE {1}{0} {1})r  r   
is_numericr  is_char	is_binaryr-   is_decimalsr  is_finite_setr6   r   r  r  rk  rl  	to_string)r   type_defs     r   
_data_typezColumnDef._data_type  sw   : 	>:0<< 	>tz**	>.8.B4:.N.N	>~~dj11HH#DJ// 	>DJ 	>#**4:t~7JKKHH%dj11 	>~~chht|&<&<==H> 	7%,,X66H< 	5#**844H= 	O.55hNNH? 	K(//$/JJH
 4TZ @ @(KKKr   c                 ,   | j         rdnd}| j        rdnd}| j        rdnd}| j        rdnd}d                    |                                 ||||          }| j        rd                    |          }n| j        rd	                    |          }| j        r]| j	        rVt          t          | j        | j                            }d
                    ||d                    | j	                            }|                    | j        | j                  S )Nz	 NOT NULLz NULLz AUTO_INCREMENTr"   z DEFAULT {default}z COMMENT '{comment}'z{0}{1}{2}{3}{4}z{0} PRIMARY KEYz{0} UNIQUE KEYz{0} REFERENCES {1} ({2})rm   )defaultr}  )r  ru  r  rm  r-   r  r  r  r  r  r8   rA   r  r6   )r   nullauto_incr  r}  defn	ref_tables          r   _col_definitionzColumnDef._col_definition  s1   "n9{{'(,>$$B*.-?&&R,0MA((r ''(9(94g  ; 	1$++D11DD] 	1#**400D? 	,t/ 	,23C$do47 47 8 8I-44T9)**, ,D {{4=$-{HHHr   c                     t          |t                    r|j        | _        n|d| _        nt	          |          | _        | S )zSets the default value of this Column.

        Args:
            default_val (object): The default value of the Column. Can be a
            string, number or :class`MySQLx.Expr`.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        NNULL)r   r   r   r  repr)r   default_vals     r   set_defaultzColumnDef.set_default  sE     k4(( 	.',DMM "DMM --DMr   c                     d| _         | S )zlSet the Column to Auto Increment.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        Tr  rK   s    r   auto_incrementzColumnDef.auto_increment  r  r   c                 0    t          | | _        || _        | S )zSets the Column as a Foreign Key.

        Args:
            name (string): Name of the referenced Table.
            *refs: Fields this Column references.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        )r!   r  r  r   r   refss      r   foreign_keyzColumnDef.foreign_key$  s     +D1r   c                     d| _         | S )zfSet the Column as unsigned.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        T)r  rK   s    r   unsignedzColumnDef.unsigned2  r  r   c                     || _         | S )zSet the size of the decimal Column.

        Args:
            size (int): Size of the decimal.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        )r  )r   r  s     r   decimalszColumnDef.decimals;  s     r   c                     || _         | S )zSet the Charset type of the Column.

        Args:
            charset (string): Charset type.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        r  r  s     r   r{  zColumnDef.charsetG  rW  r   c                     || _         | S )zSet the Collation type of the Column.

        Args:
            collation (string): Collation type.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        r  r  s     r   r|  zColumnDef.collationS  rR  r   c                     d| _         | S )zqSet the current column to binary type.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        T)r  rK   s    r   binaryzColumnDef.binary_       r   c                 H    t          t          t          |           | _        | S )zSet the Enum/Set values.

        Args:
            *values: Values for Enum/Set type Column.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        )mapr  r!   r   r  s     r   r    zColumnDef.valuesh  s     4&!9::r   c                 \    d                     | j        |                                           S )Nr  )r-   r7  r  rK   s    r   r  zColumnDef.get_sqlt  s&    
D,@,@,B,BCCCr   r   )r   r   r   rT   r   r  r  r  r  r  r  r  r{  r|  r  r    r  r   r   s   @r   r  r    s             "L L L*I I I*  &      
 
 

 
 

 
 
  
 
 
D D D D D D Dr   r  c                   2     e Zd ZdZ fdZd Z fdZ xZS )GeneratedColumnDefzClass used to describe a Generated Column.

    Args:
        name: Name of the column.
        col_type: Type of the column.
        expr: The Expression used to generate the value of this column.
    c                     t          t          |                               ||           t          |t                    sJ d| _        |j        | _        d S r   )rZ   r  r   r   r   _storedr   _expr)r   r   col_typer   rf   s       r   r   zGeneratedColumnDef.__init__  sN     $''00x@@@$%%%%%Y


r   c                     d| _         | S )zSet the Generated Column to be stored.

        Returns:
            mysqlx.GeneratedColumnDef: GeneratedColumnDef object.
        T)r  rK   s    r   storedzGeneratedColumnDef.stored  r  r   c                     d                     t          t          |                                           | j        | j        rdnd          S )Nz {0} GENERATED ALWAYS AS ({1}){2}z STOREDr"   )r-   rZ   r  r  r  r  )r   rf   s    r   r  zGeneratedColumnDef.get_sql  sG    188$d++3355JT\9		r; ; 	;r   )r   r   r   rT   r   r  r  r   r   s   @r   r  r  x  sj               ; ; ; ; ; ; ; ; ;r   r  c                   X    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S )ForeignKeyDefzClass describing a Foreign Key.r   r         c                     g | _         g | _        d | _        d | _        d | _        |                     t          j                  | _        |                     t          j                  | _	        d S r   )
r
  	_f_fieldsr7  _f_tabler  _actionr  	NO_ACTION_update_action_delete_actionrK   s    r   r   zForeignKeyDef.__init__  sZ    
#"ll=+BCC"ll=+BCCr   c                 f    |t           j        u rdS |t           j        u rdS |t           j        u rdS dS )NRESTRICTCASCADEzSET NULLz	NO ACTION)r  r  r  SET_NULLr   actions     r   r  zForeignKeyDef._action  s@    ]+++:},,,9}---:{r   c                     || _         d S r   )r7  )r   r   s     r   r  zForeignKeyDef.set_name  s    


r   c                     || _         d S r   r  r  s     r   r  zForeignKeyDef.set_schema  r  r   c                 "    t          | | _        | S )zAdd a list of fields in the parent table.

        Args:
            *fields: Fields in the given table which constitute the Foreign Key.

        Returns:
            mysqlx.ForeignKeyDef: ForeignKeyDef object.
        )r!   r
  rq   s     r   rr   zForeignKeyDef.fields  s     '/r   c                 0    t          | | _        || _        | S )zAdd the child table name and the fields.

        Args:
            name (string): Name of the referenced table.
            *refs: A list fields in the referenced table.

        Returns:
            mysqlx.ForeignKeyDef: ForeignKeyDef object.
        )r!   r  r  r  s      r   	refers_tozForeignKeyDef.refers_to  s     )$/r   c                 :    |                      |          | _        | S )a  Define the action on updating a Foreign Key.

        Args:
            action (int): Action to be performed on updating the reference.
                          Can be any of the following values:
                          1. ForeignKeyDef.NO_ACTION
                          2. ForeignKeyDef.RESTRICT
                          3. ForeignKeyDef.CASCADE
                          4. ForeignKeyDef.SET_NULL

        Returns:
            mysqlx.ForeignKeyDef: ForeignKeyDef object.
        )r  r  r  s     r   	on_updatezForeignKeyDef.on_update  s     #ll622r   c                 :    |                      |          | _        | S )a  Define the action on deleting a Foreign Key.

        Args:
            action (int): Action to be performed on updating the reference.
                          Can be any of the following values:
                          1. ForeignKeyDef.NO_ACTION
                          2. ForeignKeyDef.RESTRICT
                          3. ForeignKeyDef.CASCADE
                          4. ForeignKeyDef.SET_NULL

        Returns:
            mysqlx.ForeignKeyDef: ForeignKeyDef object.
        )r  r  r  s     r   	on_deletezForeignKeyDef.on_delete  s     #ll622r   c           
      |   d                     | j                  }d                     | j                  }d                     | j        d                    | j                  t          t          | j        | j	                            d                    | j
                            }d                     |||          S )NzON UPDATE {0}zON DELETE {0}z)FOREIGN KEY {0}({1}) REFERENCES {2} ({3})rm   z{0} {1} {2})r-   r  r  r7  r6   r
  r8   rA   r  r  r  )r   r   r  r   s       r   r  zForeignKeyDef.get_sql  s     ''(;<< ''(;<<9@@J..0JT14=AA1C 1CHHT^$$& & ##C888r   N)r   r   r   rT   r  r  r  r  r   r  r  r  rr   r  r  r   r  r   r   r   r  r    s        ))IHGHD D D    & & &
 
 
    $  "9 9 9 9 9r   r  )r"   )2rT   r   r  errorsr   r   r   compatr   	constantsr   r   dbdocr	   protobufr
   r   resultr   r   r   r   r   r!   r+   r/   r8   rA   rC   rW   r   r   r   r   r   r   r  r  r  r  r  r0  r5  r@  re  ri  r  r  r  r  r   r   r   <module>r(     s=  0 $ #  				 $ $ $ $ $ $                   - - - - - - - -       3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1    6   
  > > > >"= = = =(5 5 5 5$ $ $ $" " " " " " " "DC" C" C" C" C") C" C" C"L+ + + + +9 + + +,'2 '2 '2 '2 '29 '2 '2 '2T       &b- b- b- b- b-) b- b- b-J9+ 9+ 9+ 9+ 9+' 9+ 9+ 9+x= = = = =) = = =~2 2 2 2 2i 2 2 2B- - - - -) - - -D- - - - -) - - -$- - - - -) - - -,'& '& '& '& '&Y '& '& '&TK K K K K9 K K K,@ @ @ @ @ @ @ @ t t t t t) t t tn    ,   Bl1 l1 l1 l1 l19 l1 l1 l1^:& :& :& :& :&F :& :& :&zpD pD pD pD pD pD pD pDf; ; ; ; ; ; ; ;:c9 c9 c9 c9 c9F c9 c9 c9 c9 c9r   