U eO@sdZddlZddlZddlmZddlmZddlmZddl m Z m Z ddl m Z dd lmZdd lmZmZmZGd d d eZd dZdDddZdEddZdFddZdGddZGdddeZGdddeZGdddeZGdddeZGd d!d!eZ Gd"d#d#eZ!Gd$d%d%eZ"Gd&d'd'eZ#Gd(d)d)eZ$Gd*d+d+eZ%Gd,d-d-eZ&Gd.d/d/eZ'Gd0d1d1eZ(Gd2d3d3eZ)Gd4d5d5eZ*Gd6d7d7eZ+Gd8d9d9e+Z,Gd:d;d;eZ-Gdd?d?e.Z/Gd@dAdAe/Z0GdBdCdCeZ1dS)HzImplementation of Statements.N)ProgrammingError) ExprParser) STRING_TYPES) Algorithms Securities)DbDoc)mysqlx_crud_pb2) SqlResultResult ColumnTypec@seZdZddZdS)ExprcCs ||_dSN)expr)selfrre/opt/hc_python/lib64/python3.8/site-packages/../../../lib/python3.8/site-packages/mysqlx/statement.py__init__&sz Expr.__init__N)__name__ __module__ __qualname__rrrrrr %sr cGs*t|dkr&t|dttfr&|dS|S)Nrr)len isinstancelisttuple)valuesrrrflexible_params*srcCsTd|kr8|ddkr |ddkp6|ddko6|ddkS|ddkoN|ddkSdS)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`"Nr identifiersql_moderrris_quoted_identifier0s r%cCs>t||r|Sd|kr(d|ddSd|ddSdS) aQuote 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. rz"{0}"r!z""z`{0}`rz``N)r%formatreplacer"rrrquote_identifierAs r(csdfdd|DS)aQuote 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. .csg|]}t|qSrr().0r#r$rr _sz.quote_multipart_identifier..)join)Z identifiersr$rr,rquote_multipart_identifierUs r/cCs^d|kr dnd}||kr"d|nd}||d}t|dkrB|n |d||d|fS) Nrr!rz.{0}r)rrr )r&splitrstrip)Zdefault_schema table_namer$quote delimitertemprrrparse_table_namecs   r6c@s:eZdZdZd ddZeddZeddZd d Zd 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. TcCs ||_||_|r|jnd|_dSr)_target _doc_based _connection)rtarget doc_basedrrrrsszStatement.__init__cCs|jS)z,object: The database object target. )r8rrrrr;xszStatement.targetcCs|jjS)z3:class:`mysqlx.Schema`: The Schema object. )r8schemar=rrrr>~szStatement.schemacCstdSzqExecute the statement. Raises: NotImplementedError: This method must be implemented. NNotImplementedErrorr=rrrexecuteszStatement.executeN)T) rrr__doc__rpropertyr;r>rBrrrrr7ks   r7csleZdZdZdfdd ZddZdd Zdd d Zd dZddZ ddZ ddZ ddZ ddZ ZS)FilterableStatementaA 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. TNcs`tt|j||dd|_d|_d|_d|_d|_d|_d|_ i|_ g|_ |dk r\| |dS)Nr;r<F) superrEr_has_projection _has_where _has_limit _has_sort _has_group_by _has_having _has_bindings _binding_map _bindingswhere)rr;r< condition __class__rrrs zFilterableStatement.__init__cCs0d|_||_t||j }||_|j|_|S)aSets the search condition to filter. Args: condition (str): Sets the search condition to filter documents or records. Returns: mysqlx.FilterableStatement: FilterableStatement object. T)rI_whererr9rZ _where_exprZplaceholder_name_to_positionrO)rrRrrrrrQs  zFilterableStatement.wherecGs4t|}d|_d||_t|j|j |_|SNT,)rrHr._projection_strrr9Zparse_table_select_projectionZ_projection_exprrfieldsrrr _projections  zFilterableStatement._projectionrcCsd|_||_||_|S)aESets 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)rJ _limit_offset_limit_row_count)r row_countoffsetrrrlimits zFilterableStatement.limitcGs4t|}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. TrW)rrKr. _sort_strrr9Zparse_order_specZ _sort_expr)rZ sort_clausesrrrsorts   zFilterableStatement.sortcGs4t|}d|_d||_t|j|j |_dSrV)rrLr. _grouping_strrr9Zparse_expr_listZ _groupingrYrrr _group_bys  zFilterableStatement._group_bycCsd|_t||j |_dSNT)rMrr9r_havingrrRrrrrfszFilterableStatement._havingcGsVd|_t|}|dkr&||dn,|dkr8tdn|j|d|dd|S)aBinds 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. Trrz#Invalid number of arguments to bind)namevalue)rNr _bind_singlerrPappend)rargscountrrrbinds zFilterableStatement.bindcCsPt|tr|t|n2t|trLt|}|D]}||||q6dSr)rrrostrrjsonloadskeys)robjectdictkeyrrrrks     z FilterableStatement._bind_singlecCstdSr?r@r=rrrrB szFilterableStatement.execute)TN)r)rrrrCrrQr[r`rbrdrfrorkrB __classcell__rrrSrrEs  rEcs(eZdZdZfddZddZZS) SqlStatementzA statement for SQL execution. Args: connection (mysqlx.connection.Connection): Connection object. sql (string): The sql statement to be executed. cs$tt|jddd||_||_dSNFrF)rGrxrr:_sql)r connectionsqlrSrrrszSqlStatement.__init__cCs|j|jt|jS)zaExecute the statement. Returns: mysqlx.SqlResult: SqlResult object. )r:Zsend_sqlrzr r=rrrrBszSqlStatement.executerrrrCrrBrwrrrSrrxs rxcs0eZdZdZfddZddZddZZS) AddStatementzA statement for document addition on a collection. Args: collection (mysqlx.Collection): The Collection object. cs"tt|j|dg|_g|_dSN)r;)rGr~r_values_idsr collectionrSrrr/szAddStatement.__init__cGs:t|D],}t|tr$|j|q|jt|q|S)zAdds a list of documents into a collection. Args: *values: The documents to be added into the collection. Returns: mysqlx.AddStatement: AddStatement object. )rrrrrl)rrvalrrradd4s  zAddStatement.addcCs<t|jdkrtS|jD]}|j|q|j|S)[Execute the statement. Returns: mysqlx.Result: Result object. r)rrr rrlZ ensure_idr: send_insert)rdocrrrrBDs  zAddStatement.execute)rrrrCrrrBrwrrrSrr~)s r~c@seZdZdddZddZdS) UpdateSpecNcCsj|tjjkr|||nL||_||_t|dkrL|ddkrL|dd|_t|jdj |_||_ dS)Nr$rF) MySQLxCrudUpdateOperationSET _table_set update_typesourcerrZdocument_fieldr#rj)rrrrjrrrrTs  zUpdateSpec.__init__cCs$tjj|_t|d|_||_dSre)rrrrrZparse_table_update_fieldrrj)rrrjrrrr`s zUpdateSpec._table_set)N)rrrrrrrrrrSs rcsReZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ Z S)ModifyStatementaA 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. Ncstt|j||dg|_dS)N)r;rR)rGrr _update_opsrrrRrSrrrns zModifyStatement.__init__cCs|jttjj|||S)a2Sets 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. )rrlrrrZITEM_SETrZdoc_pathrjrrrsetss zModifyStatement.setcCs|jttjj|||S)ajAdd 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. )rrlrrrZ ITEM_REPLACErrrrchanges  zModifyStatement.changecGs|jddt|D|S)aRemoves attributes from documents in a collection. Args: doc_path (string): The document path of the attribute to be removed. Returns: mysqlx.ModifyStatement: ModifyStatement object. cSsg|]}ttjj|qSr)rrrZ ITEM_REMOVE)r+xrrrr-sz)ModifyStatement.unset..)rextendr)rZ doc_pathsrrrunsets zModifyStatement.unsetcCs|jttjj|||S)aInsert 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. )rrlrrrZ ARRAY_INSERTrfieldrjrrr array_inserts zModifyStatement.array_insertcCs|jttjj|||S)aInserts 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. )rrlrrrZ ARRAY_APPENDrrrr array_appends  zModifyStatement.array_appendcCs |j|Srr:updater=rrrrBszModifyStatement.execute)N) rrrrCrrrrrrrBrwrrrSrrfsrcsBeZdZdZd fdd ZddZddZd d Zd d ZZ S) FindStatementaA 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. Ncstt||d|dSre)rGrrrrSrrrszFindStatement.__init__cGs |j|S)zSets a document field filter. Args: *fields: The string expressions identifying the fields to be extracted. Returns: mysqlx.FindStatement: FindStatement object. )r[rYrrrrZs zFindStatement.fieldscGs|j||S)zSets a grouping criteria for the resultset. Args: *fields: The string expressions identifying the grouping criteria. Returns: mysqlx.FindStatement: FindStatement object. rdrYrrrgroup_bys zFindStatement.group_bycCs|||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. rfrgrrrhavings zFindStatement.havingcCs |j|S)zaExecute the statement. Returns: mysqlx.DocResult: DocResult object. r:findr=rrrrBszFindStatement.execute)N) rrrrCrrZrrrBrwrrrSrrs    rcs@eZdZdZfddZddZddZdd Zd d ZZ S) SelectStatementzA statement for record retrieval operations on a Table. Args: table (mysqlx.Table): The Table object. *fields: The fields to be retrieved. cs tt||d|j|dSNF)rGrrr[rtablerZrSrrrszSelectStatement.__init__cGs|j||S)zSets a grouping criteria for the resultset. Args: *fields: The fields identifying the grouping criteria. Returns: mysqlx.SelectStatement: SelectStatement object. rrYrrrrs zSelectStatement.group_bycCs|||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. rrgrrrrs zSelectStatement.havingcCs |j|S)zaExecute the statement. Returns: mysqlx.RowResult: RowResult object. rr=rrrrB,szSelectStatement.executec Cs|jrd|jnd}|jr(d|jnd}|jr>d|jnd}|jrTd|jnd}|j rnd|j |j nd}djt |dd |j j|jj|||||d }|S) Nz WHERE {0}rz 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}rX*)selectr>rr`rQgrouprorder)rIr&rUrLrcrMrfrKrarJr]r\getattrr>rir;)rrQrrZorder_byr`stmtrrrget_sql4s4  zSelectStatement.get_sql) rrrrCrrrrBrrwrrrSrrs   rcs0eZdZdZfddZddZddZZS)InsertStatementzA statement for insert operations on Table. Args: table (mysqlx.Table): The Table object. *fields: The fields to be inserted. cs(tt|j|ddt||_g|_dSry)rGrrr_fieldsrrrSrrrMs zInsertStatement.__init__cGs|jtt||S)zSet the values to be inserted. Args: *values: The values of the columns to be inserted. Returns: mysqlx.InsertStatement: InsertStatement object. )rrlrrrrrrrrRs zInsertStatement.valuescCs |j|Sr)r:rr=rrrrB^szInsertStatement.execute)rrrrCrrrBrwrrrSrrFs  rcs0eZdZdZfddZddZddZZS)UpdateStatementzA statement for record update operations on a Table. Args: table (mysqlx.Table): The Table object. *fields: The fields to be updated. cstt|j|ddg|_dSry)rGrrrrrSrrrnszUpdateStatement.__init__cCs|jttjj|||S)aUpdates 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. )rrlrrrrrrrrrrs zUpdateStatement.setcCs |j|S)zZExecute the statement. Returns: mysqlx.Result: Result object rr=rrrrBszUpdateStatement.execute)rrrrCrrrBrwrrrSrrgs rcs(eZdZdZfddZddZZS)RemoveStatementzA statement for document removal from a collection. Args: collection (mysqlx.Collection): The Collection object. cstt|j|ddSr)rGrrrrSrrrszRemoveStatement.__init__cCs |j|Srr:deleter=rrrrBszRemoveStatement.executer}rrrSrrs rcs*eZdZdZdfdd ZddZZS)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. Ncstt|j||dddS)NF)r;rRr<)rGrr)rrrRrSrrrs zDeleteStatement.__init__cCs |j|Srrr=rrrrBszDeleteStatement.execute)Nr}rrrSrrsrcs0eZdZdZfddZddZddZZS)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. cs(tt|j|d||_||_g|_dSr)rGrr _index_name _is_uniquer)rr index_nameZ is_uniquerSrrrsz'CreateCollectionIndexStatement.__init__cCs|j|||f|S)aAdd 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. )rrl)rZ document_pathZ column_typeZ is_requiredrrrrs z$CreateCollectionIndexStatement.fieldcCs<dd|jD}|jjddd|jjj|jj|j|jf|S)rcSsg|]}|D]}|q qSrr)r+Zsublistitemrrrr-sz:CreateCollectionIndexStatement.execute..xpluginZcreate_collection_indexT)rr:execute_nonqueryr8r>rirrrYrrrrBsz&CreateCollectionIndexStatement.execute)rrrrCrrrBrwrrrSrrs rcs(eZdZdZfddZddZZS)DropCollectionIndexStatementzA statement that drops an index on a collection. Args: collection (mysqlx.Collection): The Collection object. index_name (string): The index name. cstt|j|d||_dSr)rGrrr)rrrrSrrrsz%DropCollectionIndexStatement.__init__cCs"|jddd|jjj|jj|jS)rrZdrop_collection_indexT)r:rr8r>rirr=rrrrBsz$DropCollectionIndexStatement.executer}rrrSrrs rc@s$eZdZdZdZddZddZdS) TableIndexrrhcCs||_||_||_dSr)_name _index_type_columns)rriZ index_typecolumnsrrrrszTableIndex.__init__cCs6d}|jtjkr|d7}|d7}||jd|jS)NrzUNIQUE zINDEX {0} ({1})rW)rr UNIQUE_INDEXr&rr.r)rrrrrrs  zTableIndex.get_sqlN)rrrrINDEXrrrrrrrsrcsZeZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ ddZ Z S)CreateViewStatementzA statement for creating views. Args: view (mysqlx.View): The View object. replace (Optional[bool]): `True` to add replace. Fcs\tt|j|dd||_|j|_|j|_||_g|_ t j |_ t j|_d|_d|_d|_dSry)rGrr_viewr>_schemarir_replacerr UNDEFINED _algorithmrZDEFINER _security_definer _defined_as _check_option)rviewr'rSrrrszCreateViewStatement.__init__cCsdd|D|_|S)zSets the column names. Args: columns (list): The list of column names. Returns: mysqlx.CreateViewStatement: CreateViewStatement object. cSsg|] }t|qSrr*)r+colrrrr-sz/CreateViewStatement.columns..)r)rrrrrrs zCreateViewStatement.columnscCs ||_|S)zSets the algorithm. Args: mysqlx.constants.ALGORITHMS: The algorithm. Returns: mysqlx.CreateViewStatement: CreateViewStatement object. )r)r algorithmrrrr!s zCreateViewStatement.algorithmcCs ||_|S)zSets the SQL security mode. Args: mysqlx.constants.SECURITIES: The SQL security mode. Returns: mysqlx.CreateViewStatement: CreateViewStatement object. )r)rsecurityrrrr-s zCreateViewStatement.securitycCs ||_|S)zSets the definer. Args: definer (string): The definer. Returns: mysqlx.CreateViewStatement: CreateViewStatement object. )r)rdefinerrrrr9s zCreateViewStatement.definercCs ||_|S)zSets the SelectStatement statement for describing the view. Args: mysqlx.SelectStatement: SelectStatement object. Returns: mysqlx.CreateViewStatement: CreateViewStatement object. )r)rZ statementrrr defined_asEs zCreateViewStatement.defined_ascCs ||_|S)zSets the check option. Args: mysqlx.constants.CHECK_OPTIONS: The check option. Returns: mysqlx.CreateViewStatement: CreateViewStatement object. )r)r check_optionrrrwith_check_optionQs z%CreateViewStatement.with_check_optionc Cs|jr dnd}|jr d|jnd}|jrget_name _tbl_repl)rr>r2rSrrrszCreateTableStatement.__init__cCstt|jj|jS)z7string: The fully qualified name of the Table. )r/r6r>rirr=rrrr2szCreateTableStatement.table_namecCsbg}|d|jr|d|jr.|d|jr>|dd|}|j|j|j|j|jdS)NzAUTO_INCREMENT = {inc}z!DEFAULT CHARACTER SET = {charset}zDEFAULT COLLATE = {collation}zCOMMENT = '{comment}'rW)inccharset collationcomment)rlrrrr.r&r)roptions table_optsrrr_get_table_optss      z$CreateTableStatement._get_table_optscCsg}|jr"|dd|j|jD]}||q(|jD]}||qB|jD]}||q\|jD]}||qvd|S)NzPRIMARY KEY ({0})rW) rrlr&r.rrrrr)rZdefsrrvindexrrr_get_create_defs    z$CreateTableStatement._get_create_defcCstt|jj||_|S)zCreate table with the definition of another existing Table. Args: table_name (string): Name of the source table. Returns: mysqlx.CreateTableStatement: CreateTableStatement object. )r/r6r>rir)rr2rrrlikes  zCreateTableStatement.likecCs6t|trtj|j||_nt|tr2||_|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. ) rrrtbl_frmtsubrrrr)rrrrr as_selects   zCreateTableStatement.as_selectcCs ||j|j||S)zAdd a Column to the Table. Args: column_def (MySQLx.ColumnDef): Column Definition object. Returns: mysqlx.CreateTableStatement: CreateTableStatement object. ) set_schemar>rrrl)rZ column_defrrr add_columns  zCreateTableStatement.add_columncGst|}|j||S)zAdd multiple Primary Keys to the Table. Args: *keys: Fields to be used as Primary Keys. Returns: mysqlx.CreateTableStatement: CreateTableStatement object. )rrr)rrsrrradd_primary_keys  z$CreateTableStatement.add_primary_keycGs|jt|tjt||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. )rrlrrrrrcolsrrr add_indexs zCreateTableStatement.add_indexcGs|jt|tjt||S)aAdds 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. )rrlrrrrrrradd_unique_indexs z%CreateTableStatement.add_unique_indexcCs*||j|||j||S)zAdds a Foreign Key to the Table. Args: key (MySQLx.ForeignKeyDef): The Foreign Key Definition object. Returns: mysqlx.CreateTableStatement: CreateTableStatement object. )rr>rset_namerrl)rrirvrrradd_foreign_key*s   z$CreateTableStatement.add_foreign_keycCs ||_|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. r)rrrrrset_initial_auto_increment8s z/CreateTableStatement.set_initial_auto_incrementcCs ||_|S)zSets the default Charset type for the Table. Args: charset (string): Charset type. Returns: mysqlx.CreateTableStatement: CreateTableStatement object. rrrrrrset_default_charsetDs z(CreateTableStatement.set_default_charsetcCs ||_|S)zSets the default Collation type for the Table. Args: collation (string): Collation type. Returns: mysqlx.CreateTableStatement: CreateTableStatement object. rrrrrrset_default_collationPs z*CreateTableStatement.set_default_collationcCs ||_|S)zAdd a comment to the Table. Args: comment (string): Comment to be added to the Table. Returns: mysqlx.CreateTableStatement: CreateTableStatement object. rrrrrr set_comment\s z CreateTableStatement.set_commentcCs d|_|S)zSet the Table to be Temporary. Returns: mysqlx.CreateTableStatement: CreateTableStatement object. T)rr=rrr temporaryhszCreateTableStatement.temporarycCsndj|j|jrdndd}|jr&d}nd}|j||jp>|jp>d||d}|jd |d |j |j S) zYExecute the statement. Returns: mysqlx.Table: Table object. zCREATE {table_type} {name}zTEMPORARY TABLEZTABLE)riZ table_typez{create} LIKE {query}z,{create} ({create_def}) {table_opts} {query}r)createqueryZ create_defrr|F) r&r2rrrrrr:rr>Z get_tabler)rrrrrrrBqs zCreateTableStatement.execute)rrrrCrecompile IGNORECASErrrDr2rrrrrrrrrrr r rrrBrwrrrSrrs(          rc@s@eZdZdZddZddZddZdd Zd d Zd d Z dS) 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. cCs4d|_d|_d|_d|_||_||_d|_||_dS)NFr)_default_schema _not_null_p_key_u_indexr_sizer_typerritypesizerrrrszColumnDefBase.__init__cCs d|_|S)zwDisable NULL values for this column. Returns: mysqlx.ColumnDefBase: ColumnDefBase object. T)rr=rrrnot_nullszColumnDefBase.not_nullcCs d|_|S)zwSet current column as a Unique Index. Returns: mysqlx.ColumnDefBase: ColumnDefBase object. T)rr=rrr unique_indexszColumnDefBase.unique_indexcCs ||_|S)zAdd a comment to the column. Args: comment (string): Comment to be added to the column. Returns: mysqlx.ColumnDefBase: ColumnDefBase object. rrrrrrs zColumnDefBase.commentcCs d|_|S)ztSets the Column as a Primary Key. Returns: mysqlx.ColumnDefBase: ColumnDefBase object. T)rr=rrrprimaryszColumnDefBase.primarycCs ||_dSrrrr>rrrrszColumnDefBase.set_schemaN) rrrrCrr!r"rr#rrrrrrs     rcseZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZZS) 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. NcsZtt||||d|_d|_d|_d|_d|_d|_d|_ g|_ g|_ d|_ d|_ dSr)rGr&rZ_ref_default _decimals _ref_table_binaryr _unsignedr _ref_fieldsrrrrSrrrszColumnDef.__init__cCsd}|jrg|_g|_d|_d|_d|_|tj|_|tj|_ dSr) r _f_fieldsr_f_tabler_actionrB NO_ACTION_update_action_delete_actionr=rrrrszForeignKeyDef.__init__cCs.|tjkrdS|tjkrdS|tjkr*dSdS)NRESTRICTCASCADEzSET NULLz NO ACTION)rBrKrLSET_NULLractionrrrrGs   zForeignKeyDef._actioncCs ||_dSr)r)rrirrrrszForeignKeyDef.set_namecCs ||_dSrr$r%rrrrszForeignKeyDef.set_schemacGst||_|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. )rrrYrrrrZs zForeignKeyDef.fieldscGst||_||_|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. )rrErFr6rrr refers_tos zForeignKeyDef.refers_tocCs|||_|S)aDefine 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. )rGrIrNrrr on_updates zForeignKeyDef.on_updatecCs|||_|S)aDefine 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. )rGrJrNrrr on_deletes zForeignKeyDef.on_deletecCsVd|j}d|j}d|jd|jtt|j|j d|j }d|||S)Nz ON UPDATE {0}z ON DELETE {0}z)FOREIGN KEY {0}({1}) REFERENCES {2} ({3})rWz {0} {1} {2}) r&rIrJrr.rr/r6rrFrE)rrrrvrrrrs     zForeignKeyDef.get_sqlN)rrrrCrHrKrLrMrrGrrrZrPrQrRrrrrrrBs   rB)r)r)r)r)2rCrqrerrorsrrrcompatr constantsrrZdbdocrprotobufr rresultr r r rtr rr%r(r/r6r7rErxr~rrrrrrrrrrrrrrrr&r=rBrrrrsP         "*e<?!"*w!p=4