
    DhO                        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. d/e      Z* G d0 d1e      Z+ G d2 d3e+      Z, G d4 d5e      Z- G d6 d7e      Z. G d8 d9e.      Z/ G d: d;e/      Z0 G d< d=e      Z1y)?zImplementation of Statements.    N   )ProgrammingError)
ExprParser)STRING_TYPES)
Algorithms
Securities)DbDoc)mysqlx_crud_pb2)	SqlResultResult
ColumnTypec                       e Zd Zd Zy)Exprc                     || _         y N)expr)selfr   s     P/var/www/html/civilisation/venv/lib/python3.12/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!   *   s.    
6{aJvay4.AayMr   c                 z    d|v r&| d   dk(  xr | d   dk(  xs | d   dk(  xr | d   dk(  S | d   dk(  xr | 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   sk      A#%?*R.C*? AA#%?*R.C*?	B !}#=
2#(==r   c                     t        | |      r| S d|v r!dj                  | j                  dd            S dj                  | j                  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   sT     J1 ~~j00d;<<~~j00d;<<r   c           	      ^    dj                  | D cg c]  }t        ||       c}      S c c}w )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.
    .)joinr.   )identifiersr)   r(   s      r   quote_multipart_identifierr3   U   s7     88'24# &j(; 4 5 5 4s   *c                     d|v rdnd}||v rdj                  |      nd}|j                  |d      }t        |      du r| n|d   j                  |      |d   j                  |      fS )	Nr#   r&   r$   z.{0}r0   r   r   r%   )r,   splitr   strip)default_schema
table_namer)   quote	delimitertemps         r   parse_table_namer<   c   so     H,C#E(-(;e$IIq)D!$i1nN$q'--2FHNN5!$ $r   c                   >    e Zd ZdZddZed        Zed        Zd Zy)	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.
    c                 V    || _         || _        |r|j                  | _        y d | _        y r   )_target
_doc_based_connection)r   target	doc_baseds      r   r   zStatement.__init__s   s'    #176--Tr   c                     | j                   S )z,object: The database object target.
        )r@   r   s    r   rC   zStatement.targetx   s     ||r   c                 .    | j                   j                  S )z3:class:`mysqlx.Schema`: The Schema object.
        )r@   schemarF   s    r   rH   zStatement.schema~   s     ||"""r   c                     t         zqExecute the statement.

        Raises:
           NotImplementedError: This method must be implemented.
        NotImplementedErrorrF   s    r   executezStatement.execute   
     "!r   N)T)	r   r   r   __doc__r   propertyrC   rH   rM   r   r   r   r>   r>   k   s:    B
  
 # #
"r   r>   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.
    c                     t         t        |   ||       d| _        d| _        d| _        d| _        d| _        d| _        d| _	        i | _
        g | _        || j                  |       y y )NrC   rD   F)superrR   r   _has_projection
_has_where
_has_limit	_has_sort_has_group_by_has_having_has_bindings_binding_map	_bindingswhere)r   rC   rD   	condition	__class__s       r   r   zFilterableStatement.__init__   sy    !41<E 	2 	G$" " JJy! !r   c                     d| _         || _        t        || j                         }|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)rW   _wherer   rA   r   _where_exprplaceholder_name_to_positionr]   )r   r`   r   s      r   r_   zFilterableStatement.where   sF     )%8999; ==r   c                     t        | }d| _        dj                  |      | _        t	        | j                  | j
                         j                         | _        | S NT,)r!   rV   r1   _projection_strr   rA   parse_table_select_projection_projection_exprr   fieldss     r   _projectionzFilterableStatement._projection   sU     &)#"xx/ *4+?+?!!!>!>!@ 	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)rX   _limit_offset_limit_row_count)r   	row_countoffsets      r   limitzFilterableStatement.limit   s      # )r   c                     t        | }d| _        dj                  |      | _        t	        | j                  | j
                         j                         | _        | S )zSets the sorting criteria.

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

        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
        Trh   )r!   rY   r1   	_sort_strr   rA   parse_order_spec
_sort_expr)r   sort_clausess     r   sortzFilterableStatement.sort   sR     '5,/$T^^)-%8::J:J:L 	r   c                     t        | }d| _        dj                  |      | _        t	        | j                  | j
                         j                         | _        y rg   )r!   rZ   r1   _grouping_strr   rA   parse_expr_list	_groupingrl   s     r   	_group_byzFilterableStatement._group_by   sN     &)! XXf-#D$6$6(,$799H9J 	r   c                 f    d| _         t        || j                         j                         | _        y NT)r[   r   rA   r   _havingr   r`   s     r   r   zFilterableStatement._having   s(    !)-@AFFHr   c                     d| _         t        |      }|dk(  r| j                  |d          | S |dkD  rt        d      | j                  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)r\   r   _bind_singler   r^   append)r   argscounts      r   bindzFilterableStatement.bind   sn     "D	A:d1g&
 	 QY"#HIINN!!47T!W"EFr   c                     t        |t              r| j                  t        |             y t        |t              r@t        j                  |      }|j                         D ]  }| j                  |||           y y r   )r   r	   r   strr   jsonloadskeys)r   objectdictkeys       r   r   z FilterableStatement._bind_single  s`    fe$IIc&k"-::f%Dyy{ *		#tCy)* .r   c                     t         rJ   rK   rF   s    r   rM   zFilterableStatement.execute
  rN   r   )TN)r   )r   r   r   rO   r   r_   rn   rt   rz   r   r   r   r   rM   __classcell__ra   s   @r   rR   rR      s<    	"" KI0*"r   rR   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                 L    t         t        |   d d       || _        || _        y NFrT   )rU   r   r   rB   _sql)r   
connectionsqlra   s      r   r   zSqlStatement.__init__  s&    lD*$%*H%	r   c                 v    | j                   j                  | j                         t        | j                         S )zaExecute the statement.

        Returns:
            mysqlx.SqlResult: SqlResult object.
        )rB   send_sqlr   r   rF   s    r   rM   zSqlStatement.execute  s-     	!!$)),))**r   r   r   r   rO   r   rM   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 )AddStatementzA statement for document addition on a collection.

    Args:
        collection (mysqlx.Collection): The Collection object.
    c                 J    t         t        |   |       g | _        g | _        y N)rC   )rU   r   r   _values_idsr   
collectionra   s     r   r   zAddStatement.__init__/  s#    lD***=	r   c                     t        | D ]R  }t        |t              r| j                  j	                  |       /| j                  j	                  t        |             T | 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  sQ     #F+ 	0C#u%##C(##E#J/		0
 r   c                     t        | j                        dk(  r
t               S | j                  D ]+  }| j                  j	                  |j                                - | j                  j                  |       S )[Execute the statement.

        Returns:
            mysqlx.Result: Result object.
        r   )r   r   r   r   r   	ensure_idrB   send_insert)r   docs     r   rM   zAddStatement.executeD  s`     t||!8O<< 	.CIIS]]_-	. ++D11r   )r   r   r   rO   r   r   rM   r   r   s   @r   r   r   )  s    

 2r   r   c                       e Zd ZddZd Zy)
UpdateSpecNc                 4   |t         j                  j                  k(  r| j                  ||       y || _        || _        t        |      dkD  r|d   dk(  r
|dd  | _        t        | j
                  d      j                         j                  | _        || _
        y )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4888OOFE**D DK6{Q6!9#3$QRj$T[[%*,,:N,<ZZ KDJr   c                     t         j                  j                  | _        t	        |d      j                         | _        || _        y r   )r   r   r   r   r   parse_table_update_fieldr   r   )r   r   r   s      r   r   zUpdateSpec._table_set`  s4    %5599 .GGI
r   r   )r   r   r   r   r   r   r   r   r   r   S  s    
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.
    c                 >    t         t        |   ||       g | _        y )N)rC   r`   )rU   r   r   _update_opsr   r   r`   ra   s      r   r   zModifyStatement.__init__n  s%    ot-Z8A 	. 	Cr   c                     | j                   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  s6     	z11::HeL	Nr   c                     | j                   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1>>	 r   c           	          | j                   j                  t        | D cg c]&  }t        t        j
                  j                  |      ( c}       | S c c}w )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.
        )r   extendr!   r   r   r   ITEM_REMOVE)r   	doc_pathsxs      r   unsetzModifyStatement.unset  sR     	$i0!2 z11==qA!2 	3 !2s   +Ac                     | j                   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  s6     	z11>>uM	Or   c                     | j                   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1>>	 r   c                 8    | j                   j                  |       S r   rB   updaterF   s    r   rM   zModifyStatement.execute       &&t,,r   r   )r   r   r   rO   r   r   r   r   r   r   rM   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.
    c                 0    t         t        |   |d|       y r   )rU   r   r   r   s      r   r   zFindStatement.__init__  s    mT+Ji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.
        )rn   rl   s     r   rm   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   rl   s     r   group_byzFindStatement.group_by       	r   c                 (    | j                  |       | 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                 8    | j                   j                  |       S )zaExecute the statement.

        Returns:
            mysqlx.DocResult: DocResult object.
        rB   findrF   s    r   rM   zFindStatement.execute       $$T**r   r   )
r   r   r   rO   r   rm   r   r   rM   r   r   s   @r   r   r     s"    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                 L    t         t        |   |d        | j                  |  y NF)rU   r   r   rn   r   tablerm   ra   s      r   r   zSelectStatement.__init__  s$    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   rl   s     r   r   zSelectStatement.group_by  r   r   c                 (    | j                  |       | 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                 8    | j                   j                  |       S )zaExecute the statement.

        Returns:
            mysqlx.RowResult: RowResult object.
        r   rF   s    r   rM   zSelectStatement.execute,  r   r   c           
      N   | j                   rdj                  | j                        nd}| j                  rdj                  | j                        nd}| j
                  rdj                  | j                        nd}| j                  rdj                  | j                        nd}| j                  r&dj                  | j                  | j                        nd}dj                  t        | dd	      | j                  j                  | j                  j                  |||||
      }|S )Nz
 WHERE {0} 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}ri   *)selectrH   r   rt   r_   groupr   order)rW   r,   rc   rZ   r|   r[   r   rY   rv   rX   rq   rp   getattrrH   r   rC   )r   r_   r   r   order_byrt   stmts          r   get_sqlzSelectStatement.get_sql4  s   48OO##DKK0 #))$*<*<=$& 	7;7G7G%%dll3R=A^^?))$..9 	 $(?? (..t/D/D 8: 	!!'t%6<{{''t{{/?/?u8F( "( "L 	 r   )
r   r   r   rO   r   r   r   rM   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                 X    t         t        |   |d       t        | | _        g | _        y r   )rU   r  r   r!   _fieldsr   r   s      r   r   zInsertStatement.__init__M  s*    ot-Ue-L&/r   c                 Z    | j                   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                 8    | j                   j                  |       S r   )rB   r   rF   s    r   rM   zInsertStatement.execute^  s     ++D11r   )r   r   r   rO   r   r    rM   r   r   s   @r   r  r  F  s    

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                 >    t         t        |   |d       g | _        y r   )rU   r
  r   r   r   s      r   r   zUpdateStatement.__init__n  s    ot-Ue-Lr   c                     | j                   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  s6     	z1155ueD	Fr   c                 8    | j                   j                  |       S )zZExecute the statement.

        Returns:
            mysqlx.Result: Result object
        r   rF   s    r   rM   zUpdateStatement.execute  r   r   )r   r   r   rO   r   r   rM   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                 .    t         t        |   |       y r   )rU   r  r   r   s     r   r   zRemoveStatement.__init__  s    ot-Z-@r   c                 8    | j                   j                  |       S r   rB   deleterF   s    r   rM   zRemoveStatement.execute  r   r   r   r   s   @r   r  r    s    
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.
    c                 2    t         t        |   ||d       y )NF)rC   r`   rD   )rU   r  r   )r   r   r`   ra   s      r   r   zDeleteStatement.__init__  s    ot-U8A8= 	. 	?r   c                 8    | j                   j                  |       S r   r  rF   s    r   rM   zDeleteStatement.execute  r   r   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 )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                 X    t         t        |   |       || _        || _        g | _        y r   )rU   r  r   _index_name
_is_uniquer  )r   r   
index_name	is_uniquera   s       r   r   z'CreateCollectionIndexStatement.__init__  s,    ,d<J<O%#r   c                 B    | j                   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r   c           	      $   | j                   D cg c]  }|D ]  }|  }}} | j                  j                  ddd| j                  j                  j
                  | j                  j
                  | j                  | j                  g| S c c}}w )r   xplugincreate_collection_indexT)r  rB   execute_nonqueryr@   rH   r   r  r  )r   sublistitemrm   s       r   rM   z&CreateCollectionIndexStatement.execute  s     '+llG7wGt$G$GG0t000$LL$$dll&7&79I9IOO& %& 	& Hs   B)r   r   r   rO   r   r   rM   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                 <    t         t        |   |       || _        y r   )rU   r*  r   r  )r   r   r  ra   s      r   r   z%DropCollectionIndexStatement.__init__  s    *D:*:M%r   c                     | j                   j                  ddd| j                  j                  j                  | j                  j                  | j
                        S )r   r$  drop_collection_indexT)rB   r&  r@   rH   r   r  rF   s    r   rM   z$DropCollectionIndexStatement.execute  sN     00.LL$$dll&7&79I9IK 	Kr   r   r   s   @r   r*  r*    s    &Kr   r*  c                        e Zd ZdZdZd Zd Zy)
TableIndexr   r   c                 .    || _         || _        || _        y 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                  | j                  dj                  | j                              S )Nr   zUNIQUE zINDEX {0} ({1})rh   )r2  r/  UNIQUE_INDEXr,   r1  r1   r3  )r   r   s     r   r  zTableIndex.get_sql  sR    z666ID!!{{4::sxx'>??r   N)r   r   r   r7  INDEXr   r  r   r   r   r/  r/    s    LE 
@r   r/  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.
    c                    t         t        |   |d       || _        |j                  | _        |j                  | _        || _        g | _	        t        j                  | _        t        j                  | _        d | _        d | _        d | _        y r   )rU   r:  r   _viewrH   _schemar   r1  _replacer3  r   	UNDEFINED
_algorithmr   DEFINER	_security_definer_defined_as_check_option)r   viewr-   ra   s      r   r   zCreateViewStatement.__init__  st    !411O
{{YY
$..#++!r   c                 L    |D cg c]  }t        |       c}| _        | S c c}w )zSets the column names.

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

        Returns:
            mysqlx.CreateViewStatement: CreateViewStatement object.
        )r.   r3  )r   r5  cols      r   r5  zCreateViewStatement.columns  s(     ;BB3)#.B Cs   !c                     || _         | S )zSets the algorithm.

        Args:
            mysqlx.constants.ALGORITHMS: The algorithm.

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

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

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

        Args:
            definer (string): The definer.

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

        Args:
            mysqlx.SelectStatement: SelectStatement object.

        Returns:
            mysqlx.CreateViewStatement: CreateViewStatement object.
        )rD  )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.
        )rE  )r   check_options     r   with_check_optionz%CreateViewStatement.with_check_optionQ  s     *r   c           
      J   | j                   rdnd}| j                  rdj                  | j                        nd}| j                  r*dj                  dj	                  | j                              nd}t        | j                  j                  | j                  f      }| j                  rdj                  | j                        nd}dj                  || j                  || 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-   rJ  rO  rM  	view_namer5  rS  rU  r   )r>  rC  r,   r3  r1   r3   r=  r   r1  rE  r@  rB  rD  rB   r&  r<  )r   r-   rO  r5  r\  rU  r   s          r   rM   zCreateViewStatement.execute]  s    $(==-b]] #))$--8(* 	 ]] //$))DMM":;(* 	.0A0A4::/NO	,, 066t7I7IJ24 	 &DOO!(4>>#,g$($4$4&2	  4 	 	))%5zzr   )F)r   r   r   rO   r   r5  rJ  rM  rO  rS  rV  rM   r   r   s   @r   r:  r:    s0    "





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                 ,    t         t        |   |       y r   )rU   r^  r   )r   rF  ra   s     r   r   zAlterViewStatement.__init__~  s     $06r   c           	      (   | j                   rdj                  | j                         nd}| j                  r*dj                  dj                  | j                              nd}t	        | j
                  j                  | j                  f      }| j                  rdj                  | j                        nd}dj                  | j                  || j                  ||| j                  |      }| j                  j                  d|       | j                  S )	zgExecute the statement to alter a view.

        Returns:
            mysqlx.View: View object.
        rX  r   rY  rZ  r[  zvALTER ALGORITHM = {algorithm}{definer} SQL SECURITY {security} VIEW {view_name}{columns} AS {defined_as}{check_option})rJ  rO  rM  r\  r5  rS  rU  r   )rC  r,   r3  r1   r3   r=  r   r1  rE  r@  rB  rD  rB   r&  r<  )r   rO  r5  r\  rU  r   s         r   rM   zAlterViewStatement.execute  s     ]] #))$--8(* 	 ]] //$))DMM":;(* 	.0A0A4::/NO	,, 066t7I7IJ24 	 &4??G"&..I!(T5E5E&2  4 	 	))%5zzr   r   r   s   @r   r^  r^  x  s    
7r   r^  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                 >   t         t        |   |       d | _        d | _        d | _        d | _        d | _        d| _        g | _	        g | _
        g | _        g | _        g | _        d| _        || _        dj!                  | j"                  j%                               | _        y )NFr   z
\1{0}.\2\3)rU   rb  r   _charset
_collation_comment_as_like_tempr3  _f_keys_indices_p_keys
_u_indices	_auto_incr1  r,   rH   get_name	_tbl_repl)r   rH   r8   ra   s      r   r   zCreateTableStatement.__init__  s    "D26:


&--dkk.B.B.DEr   c                 h    t        t        | j                  j                  | j                              S )z7string: The fully qualified name of the Table.
        )r3   r<   rH   r   r1  rF   s    r   r8   zCreateTableStatement.table_name  s,     **:KKdjj+* + 	+r   c                 r   g }|j                  d       | j                  r|j                  d       | j                  r|j                  d       | j                  r|j                  d       dj	                  |      }|j                  | j                  | j                  | j                  | j                        S )NzAUTO_INCREMENT = {inc}z!DEFAULT CHARACTER SET = {charset}zDEFAULT COLLATE = {collation}zCOMMENT = '{comment}'rh   )inccharset	collationcomment)r   rd  re  rf  r1   r,   rn  )r   options
table_optss      r   _get_table_optsz$CreateTableStatement._get_table_opts  s    /0==NN>???NN:;==NN23XXg&
  T^^T]]oot}} ! > 	>r   c                 2   g }| j                   r9|j                  dj                  dj                  | j                                      | j                  D ]!  }|j                  |j                                # | j                  D ]!  }|j                  |j                                # | j                  D ]!  }|j                  |j                                # | j                  D ]!  }|j                  |j                                # dj                  |      S )NzPRIMARY KEY ({0})rh   )	rl  r   r,   r1   r3  r  rj  rk  rm  )r   defsrH  r   indexs        r   _get_create_defz$CreateTableStatement._get_create_def  s    <<KK+22388DLL3IJK== 	'CKK&	'<< 	'CKK&	']] 	)EKK(	)__ 	)EKK(	) xx~r   c                 b    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.
        )r3   r<   rH   r   rh  )r   r8   s     r   likezCreateTableStatement.like  s)     0T[[--z:<
r   c                     t        |t              r1t        j                  j	                  | j
                  |      | _        | S t        |t              r|j                         | _        | 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   rb  tbl_frmtsubrp  rg  r   r  )r   r   s     r   	as_selectzCreateTableStatement.as_select  sR     fl++4488PDH  0~~'DHr   c                     |j                  | j                  j                                | j                  j	                  |       | S )zAdd a Column to the Table.

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

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

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

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        )r!   rl  r   )r   r   s     r   add_primary_keyz$CreateTableStatement.add_primary_key  s%     %D!r   c           	      z    | j                   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.
        )rk  r   r/  r8  r!   r   r  colss      r   	add_indexzCreateTableStatement.add_index  s4     	Z
J4D4DT"$ 	%r   c           	      z    | j                   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.
        )rm  r   r/  r7  r!   r  s      r   add_unique_indexz%CreateTableStatement.add_unique_index  s4     	z*j6M6MT" $ 	%r   c                     |j                  | j                  j                                |j                  |       | 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  rH   ro  set_namerj  r   )r   r   r   s      r   add_foreign_keyz$CreateTableStatement.add_foreign_key*  s@     	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.
        rn  )r   rs  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.
        rd  r   rt  s     r   set_default_charsetz(CreateTableStatement.set_default_charsetD  rP  r   c                     || _         | S )zSets the default Collation type for the Table.

        Args:
            collation (string): Collation type.

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

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

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

        Returns:
            mysqlx.CreateTableStatement: CreateTableStatement object.
        T)ri  rF   s    r   	temporaryzCreateTableStatement.temporaryh  s     
r   c                    dj                  | j                  | j                  rdnd      }| j                  rd}nd}|j                  || j                  xs | j                  xs d| j                         | j                               }| j                  j                  d	|d
       | j                  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_defrx  r   F)r,   r8   ri  rh  rg  r}  ry  rB   r&  rH   	get_tabler1  )r   r  r   s      r   rM   zCreateTableStatement.executeq  s     .44$//,0JJ(G 5 E::*DAD{{**..B++-++-	  / 	))%u={{$$TZZ00r   )r   r   r   rO   recompile
IGNORECASEr  r   rP   r8   ry  r}  r  r  r  r  r  r  r  r  r  r  r  r  rM   r   r   s   @r   rb  rb    s     rzzA2==QHF$ + +> 



1r   rb  c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	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                 t    d | _         d| _        d| _        d| _        || _        || _        d| _        || _        y )NFr   )_default_schema	_not_null_p_key_u_indexr1  _sizerf  _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  rF   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  rF   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   rv  zColumnDefBase.comment  rP  r   c                     d| _         | S )ztSets the Column as a Primary Key.

        Returns:
            mysqlx.ColumnDefBase: ColumnDefBase object.
        T)r  rF   s    r   primaryzColumnDefBase.primary  s     r   c                     || _         y r   r  r   rH   s     r   r  zColumnDefBase.set_schema  
    %r   N)
r   r   r   rO   r   r  r  rv  r  r  r   r   r   r  r    s%    
&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.
    c                     t         t        |   |||       d | _        d | _        d | _        d | _        d| _        d| _        d| _	        g | _
        g | _        d | _        d | _        y r   )rU   r  r   _ref_default	_decimals
_ref_table_binaryrn  	_unsignedr   _ref_fieldsrd  re  )r   r   r  r  ra   s       r   r   zColumnDef.__init__  sd    i'dD9	r   c                    d}| j                   ryt        j                  | j                        s>t        j                  | j                        st        j
                  | j                        rdj                  | j                         }nt        j                  | j                        r7| j                   r+dj                  | j                   | j                  xs d      }nIt        j                  | j                        r*dj                  dj                  | j                              }| j                  rdj                  |      }| j                  rdj                  |      }| j                  rdj                  || j                        }| j                  rd	j                  || j                        }d
j                  t        j                   | j                        |      S )Nr   z({0})z
({0}, {1})r   rh   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_setr1   r   r  r  rd  re  	to_string)r   type_defs     r   
_data_typezColumnDef._data_type  sB   :::00<tzz*j.B.B4::.N~~djj1H##DJJ/DJJ#**4::t~~7JKH%%djj1~~chht||&<=H>>%,,X6H<<#**84H==.55hNH??(//$//JH
 4 4TZZ @(KKr   c                 f   | j                   rdnd}| j                  rdnd}| j                  rdnd}| j                  rdnd}dj	                  | j                         ||||      }| j                  rdj	                  |      }n| j                  rd	j	                  |      }| j                  ra| j                  rUt        t        | j                  | j                              }d
j	                  ||dj                  | j                              }|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})rh   )defaultrv  )r  rn  r  rf  r,   r  r  r  r  r  r3   r<   r  r1   )r   nullauto_incr  rv  defn	ref_tables          r   _col_definitionzColumnDef._col_definition  s    "nn{'(,$B*.--&R,0MM(r ''(94g ;;$++D1D]]#**40D??t//23C$$doo47 8I-44T9))*,D {{4==$--{HHr   c                     t        |t              r|j                  | _        | S |	d| _        | S 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.
        NULL)r   r   r   r  repr)r   default_vals     r   set_defaultzColumnDef.set_default  sK     k4(',,DM   "DM  !-DMr   c                     d| _         | S )zlSet the Column to Auto Increment.

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        Tr  rF   s    r   auto_incrementzColumnDef.auto_increment  r  r   c                 .    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  rF   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   rt  zColumnDef.charsetG  rP  r   c                     || _         | S )zSet the Collation type of the Column.

        Args:
            collation (string): Collation type.

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

        Returns:
            mysqlx.ColumnDef: ColumnDef object.
        T)r  rF   s    r   binaryzColumnDef.binary_       r   c                 <    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                 V    dj                  | j                  | j                               S )Nr  )r,   r1  r  rF   s    r   r  zColumnDef.get_sqlt  s"    

D,@,@,BCCr   r   )r   r   r   rO   r   r  r  r  r  r  r  r  rt  ru  r  r    r  r   r   s   @r   r  r    sL    "L*I*&



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                  | _        y r   )rU   r  r   r   r   _storedr   _expr)r   r   col_typer   ra   s       r   r   zGeneratedColumnDef.__init__  s7     $0x@$%%%YY
r   c                     d| _         | S )zSet the Generated Column to be stored.

        Returns:
            mysqlx.GeneratedColumnDef: GeneratedColumnDef object.
        T)r  rF   s    r   storedzGeneratedColumnDef.stored  r  r   c                     dj                  t        t        |          | j                  | j
                  rd      S d      S )Nz {0} GENERATED ALWAYS AS ({1}){2}z STOREDr   )r,   rU   r  r  r  r  )r   ra   s    r   r  zGeneratedColumnDef.get_sql  s@    188$d35JJT\\	; 	;79; 	;r   )r   r   r   rO   r   r  r  r   r   s   @r   r  r  x  s    ; ;r   r  c                   V    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y)ForeignKeyDefzClass describing a Foreign Key.r   r         c                     g | _         g | _        d | _        d | _        d | _        | j                  t        j                        | _        | j                  t        j                        | _	        y r   )
r  	_f_fieldsr1  _f_tabler  _actionr  	NO_ACTION_update_action_delete_actionrF   s    r   r   zForeignKeyDef.__init__  sT    
#"ll=+B+BC"ll=+B+BCr   c                 v    |t         j                  u ry|t         j                  u ry|t         j                  u ryy)NRESTRICTCASCADEzSET NULLz	NO ACTION)r  r  r  SET_NULLr   actions     r   r  zForeignKeyDef._action  s8    ]+++},,,}---r   c                     || _         y r   )r1  )r   r   s     r   r  zForeignKeyDef.set_name  s	    
r   c                     || _         y 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  rl   s     r   rm   zForeignKeyDef.fields  s     '/r   c                 .    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                 2    | j                  |      | _        | 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r   c                 2    | j                  |      | _        | 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r   c           
         dj                  | j                        }dj                  | j                        }dj                  | j                  dj	                  | j
                        t        t        | j                  | j                              dj	                  | j                              }dj                  |||      S )NzON UPDATE {0}zON DELETE {0}z)FOREIGN KEY {0}({1}) REFERENCES {2} ({3})rh   z{0} {1} {2})r,   r	  r
  r1  r1   r  r3   r<   r  r  r  )r   r   r  r   s       r   r  zForeignKeyDef.get_sql  s     ''(;(;< ''(;(;<9@@JJ.0JT114==A1CHHT^^$& ##C88r   N)r   r   r   rO   r  r  r  r  r   r  r  r  rm   r  r  r  r  r   r   r   r  r    sG    )IHGHD&
$"9r   r  )r   )2rO   r   r  errorsr   r   r   compatr   	constantsr   r   dbdocr	   protobufr
   r   resultr   r   r   r   r   r!   r*   r.   r3   r<   r>   rR   r   r   r   r   r   r   r  r
  r  r  r  r*  r/  r:  r^  rb  r  r  r  r  r   r   r   <module>r!     s|  0 $  	 $    -  3 1 16 
>"=(5$" "DC") C"L+9 +,'29 '2T &b-) b-J9+' 9+x=) =~2i 2B-) -D-) -$-) -,'&Y '&TK9 K,@ @ t) tn, Bl19 l1^:&F :&zpD pDf; ;:c9F c9r   