HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/Python311/Lib/site-packages/mysqlx/__pycache__/crud.cpython-311.pyc
�

�nc�b��0�dZddlZddlZddlmZddlmZmZmZm	Z	ddl
mZmZm
Z
ddlmZmZmZddlmZmZmZmZmZmZmZmZmZd	Zd
ZdZdZd
Z Gd�d��Z!Gd�de!��Z"Gd�de!��Z#Gd�de!��Z$Gd�de$��Z%dS)z,Implementation of the CRUD database objects.�N�)�DbDoc)�ER_NO_SUCH_TABLE�ER_TABLE_EXISTS_ERROR�ER_X_CMD_NUM_ARGUMENTS�ER_X_INVALID_ADMIN_COMMAND)�NotSupportedError�OperationalError�ProgrammingError)�
deprecated�escape�quote_identifier)	�AddStatement�CreateCollectionIndexStatement�DeleteStatement�
FindStatement�InsertStatement�ModifyStatement�RemoveStatement�SelectStatement�UpdateStatementz_SELECT COUNT(*) FROM information_schema.views WHERE table_schema = '{0}' AND table_name = '{1}'z`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{0}' AND table_name = '{1}'zJSELECT COUNT(*) FROM information_schema.schemata WHERE schema_name = '{0}'zSELECT COUNT(*) FROM {0}.{1}zDROP TABLE IF EXISTS {0}.{1}c���eZdZdZd�Zed���Zed���Zed���Zd�Z	d�Z
d�Zd	�Zd
�Z
edd��d
���Zedd��d���ZdS)�DatabaseObjectz�Provides base functionality for database objects.

    Args:
        schema (mysqlx.Schema): The Schema object.
        name (str): The database object name.
    c���||_t|t��r|���n||_|j���|_|j���|_dS�N)	�_schema�
isinstance�bytes�decode�_name�get_session�_session�get_connection�_connection)�self�schema�names   �-D:\Python311\Lib\site-packages\mysqlx/crud.py�__init__zDatabaseObject.__init__Ns\�����&0��u�&=�&=�G�T�[�[�]�]�]�4��
���0�0�2�2��
��=�7�7�9�9�����c��|jS)z,:class:`mysqlx.Session`: The Session object.�r"�r%s r(�sessionzDatabaseObject.sessionTs���}�r*c��|jS)z*:class:`mysqlx.Schema`: The Schema object.�rr-s r(r&zDatabaseObject.schemaYs���|�r*c��|jS)z&str: The name of this database object.�r r-s r(r'zDatabaseObject.name^s���z�r*c��|jS)z~Returns the underlying connection.

        Returns:
            mysqlx.connection.Connection: The connection object.
        )r$r-s r(r#zDatabaseObject.get_connectioncs
����r*c��|jS)zwReturns the session of this database object.

        Returns:
            mysqlx.Session: The Session object.
        r,r-s r(r!zDatabaseObject.get_sessionks���}�r*c��|jS)z{Returns the Schema object of this database object.

        Returns:
            mysqlx.Schema: The Schema object.
        r0r-s r(�
get_schemazDatabaseObject.get_schemass���|�r*c��|jS)zwReturns the name of this database object.

        Returns:
            str: The name of this database object.
        r2r-s r(�get_namezDatabaseObject.get_name{s���z�r*c��t�)z�Verifies if this object exists in the database.

        Returns:
            bool: `True` if object exists in database.

        Raises:
           NotImplementedError: This method must be implemented.
        )�NotImplementedErrorr-s r(�exists_in_databasez!DatabaseObject.exists_in_database�s
��"�!r*z8.0.12z)Use 'exists_in_database()' method insteadc�*�|���S)a+Verifies if this object exists in the database.

        Returns:
            bool: `True` if object exists in database.

        Raises:
           NotImplementedError: This method must be implemented.

        .. deprecated:: 8.0.12
           Use ``exists_in_database()`` method instead.
        )r;r-s r(�	am_i_realzDatabaseObject.am_i_real�s���&�&�(�(�(r*zUse 'get_name()' method insteadc�*�|���S)z�Returns the name of this database object.

        Returns:
            str: The name of this database object.

        .. deprecated:: 8.0.12
           Use ``get_name()`` method instead.
        )r8r-s r(�who_am_izDatabaseObject.who_am_i�s���}�}���r*N)�__name__�
__module__�__qualname__�__doc__r)�propertyr.r&r'r#r!r6r8r;rr=r?�r*r(rrFs��������:�:�:�����X������X������X�� � � ����������	"�	"�	"��Z��E�F�F�)�)�G�F�)��Z��;�<�<�	�	�=�<�	�	�	r*rc�j��eZdZdZ�fd�Zd�Zd�Zdd�Zd�Zdd�Z	dd	�Z
dd
�Zd�Zdd
�Z
dd�Z�xZS)�Schemaz�A client-side representation of a database schema. Provides access to
    the schema contents.

    Args:
        session (mysqlx.XSession): Session object.
        name (str): The Schema name.
    c�Z��||_t���||��dSr)r"�superr))r%r.r'�	__class__s   �r(r)zSchema.__init__�s*�����
�
������t�$�$�$�$�$r*c��t�t|j����}|j�|��dkS�z�Verifies if this object exists in the database.

        Returns:
            bool: `True` if object exists in database.
        r)�_COUNT_SCHEMAS_QUERY�formatr
r r$�execute_sql_scalar�r%�sqls  r(r;zSchema.exists_in_database�s=��#�)�)�&���*<�*<�=�=����2�2�3�7�7�1�<�<r*c�@�|j�dd|ji��}|���g}|D]b}|ddkr�	t	||d��}n&#t
$rt	||d��}YnwxYw|�|���c|S)zyReturns a list of collections for this schema.

        Returns:
            `list`: List of Collection objects.
        �list_objectsr&�type�
COLLECTION�
TABLE_NAMEr')r$�get_row_resultr �	fetch_all�
Collection�
ValueError�append)r%�rows�collections�row�
collections     r(�get_collectionszSchema.get_collections�s�����.�.�~��$�*�?U�V�V�����������	+�	+�C��6�{�l�*�
��
;�'��c�,�.?�@�@�
�
���
;�
;�
;�'��c�&�k�:�:�
�
�
�
;�������z�*�*�*�*��s�A"�" B�BFc�.�|�||��S)zuReturns a a table object for the given collection

        Returns:
            mysqlx.Table: Table object.

        )�	get_table)r%r'�check_existences   r(�get_collection_as_tablezSchema.get_collection_as_table�s���~�~�d�O�4�4�4r*c�>�|j�dd|ji��}|���g}d}|D]_}|d|vrS	t	||d��}n&#t
$rt	||d��}YnwxYw|�|���`|S)zoReturns a list of tables for this schema.

        Returns:
            `list`: List of Table objects.
        rSr&)�TABLE�VIEWrTrVr')r$rWr rX�TablerZr[)r%r\�tables�object_typesr^�tables      r(�
get_tableszSchema.get_tables�s�����.�.�~��$�*�?U�V�V����������
���	%�	%�C��6�{�l�*�
%�5�!�$��L�(9�:�:�E�E��!�5�5�5�!�$��F��4�4�E�E�E�5�����
�
�e�$�$�$���
s�
A!�! B�Bc�p�t||��}|r#|���std���|S)zwReturns the table of the given name for this schema.

        Returns:
            mysqlx.Table: Table object.
        zTable does not exist)rhr;r)r%r'rcrks    r(rbzSchema.get_table�sC���d�D�!�!���	?��+�+�-�-�
?�&�'=�>�>�>��r*c�p�t||��}|r#|���std���|S)ztReturns the view of the given name for this schema.

        Returns:
            mysqlx.View: View object.
        zView does not exist)�Viewr;r)r%r'rc�views    r(�get_viewzSchema.get_view�sC���D�$�����	>��*�*�,�,�
>�&�'<�=�=�=��r*c�p�t||��}|r#|���std���|S)z�Returns the collection of the given name for this schema.

        Returns:
            mysqlx.Collection: Collection object.
        zCollection does not exist)rYr;r)r%r'rcr_s    r(�get_collectionzSchema.get_collection
sF�� ��d�+�+�
��	D��0�0�2�2�
D�&�'B�C�C�C��r*c	��|j�dt�t	|j��t	|����d��dS)zmDrops a collection.

        Args:
            name (str): The name of the collection to be dropped.
        rQFN)r$�execute_nonquery�_DROP_TABLE_QUERYrNrr )r%r's  r(�drop_collectionzSchema.drop_collections\��	
��)�)���$�$� ���,�,�.>�t�.D�.D�
�
�
�	
�	
�	
�	
�	
r*Nc���|std���d|vr"tjdt��|d}t	||��}|j|d�}|��
t
|t��r|std���d}|D]}||vrtd|������g}	d	|vrC|d	}
t
|
t��std
���|	�	d	|
f��d|vrs|d}t
|ttf��std���|	�	dt
|t��rtj|��n|f��d
|	f|d<	|j�
ddd|��ny#t$rl}|jt krt#d��|�|jt$kr|std|�d���|�nt|j|j��|�Yd}~nd}~wwxYw|S)aJCreates in the current schema a new collection with the specified
        name and retrieves an object representing the new collection created.

        Args:
            name (str): The name of the collection.
            reuse_existing (bool): `True` to reuse an existing collection.
            validation (Optional[dict]): A dict, containing the keys `level`
                                         with the validation level and `schema`
                                         with a dict or a string representation
                                         of a JSON schema specification.

        Returns:
            mysqlx.Collection: Collection object.

        Raises:
            :class:`mysqlx.ProgrammingError`: If ``reuse_existing`` is False
                                              and collection exists or the
                                              collection name is invalid.
            :class:`mysqlx.NotSupportedError`: If schema validation is not
                                               supported by the server.

        .. versionchanged:: 8.0.21
        �Collection name is invalid�reusezG'reuse' is deprecated since 8.0.21. Please use 'reuse_existing' instead)r&r'N�Invalid value for 'validation'��levelr&� Invalid option in 'validation': r}�Invalid value for 'level'r&�Invalid value for 'schema'�
validation�options�mysqlx�create_collectionT�lYour MySQL server does not support the requested operation. Please update to MySQL 8.0.19 or a later version�Collection 'z' already exists)r�warnings�warn�DeprecationWarningrYr r�dict�strr[�json�dumpsr$rur
�errnorr	r�msg)
r%r'�reuse_existingr��kwargsr_�fields�
valid_options�optionr�r}r&�errs
             r(r�zSchema.create_collection$s���0�	A�"�#?�@�@�@��f��	-��M�6�"�
�
�
�
$�G�_�N���d�+�+�
� �J��5�5���	8��j�$�/�/�
I�z�
I�&�'G�H�H�H�/�M�$�
X�
X����.�X�*�+V�f�+V�+V�W�W�W�X��G��*�$�
1�"�7�+��!�%��-�-�H�*�+F�G�G�G������/�0�0�0��:�%�	
�#�H�-��!�&�3��+�6�6�I�*�+G�H�H�H���� �.8���.F�.F�R��
�6�*�*�*�F�����".�w� 7�F�9��	D���-�-��-�t�V�
�
�
�
�� �
	D�
	D�
	D��y�2�2�
�'�����	�
�y�1�1�
D�%��*�=�t�=�=�=������
'�s�w��	�:�:��C����������
	D�����s� E>�>
G4�A"G/�/G4c��|std���t|t��r|std���d}|D]}||vrtd|������g}d|vrC|d}t|t��std���|�d|f��d|vrs|d}t|ttf��std���|�dt|t��rtj|��n|f��|j|d	|fd
�}	|j�	ddd
|��dS#t$r@}	|	jtkrtd��|	�t|	j|	j��|	�d}	~	wwxYw)a
Modifies a collection using a JSON schema validation.

        Args:
            name (str): The name of the collection.
            validation (Optional[dict]): A dict, containing the keys `level`
                                         with the validation level and `schema`
                                         with a dict or a string representation
                                         of a JSON schema specification.

        Raises:
            :class:`mysqlx.ProgrammingError`: If the collection name or
                                              validation is invalid.
            :class:`mysqlx.NotSupportedError`: If schema validation is not
                                               supported by the server.

        .. versionadded:: 8.0.21
        ryr{r|r~r}rr&r�r�)r&r'r�r��modify_collection_optionsTr�N)rrr�r�r[r�r�r r$rur
r�rr	r�)
r%r'r�r�r�r�r}r&r�r�s
          r(�modify_collectionzSchema.modify_collection}s��$�	A�"�#?�@�@�@��*�d�+�+�	E�:�	E�"�#C�D�D�D�+�
� �	T�	T�F��]�*�
T�&�'R�&�'R�'R�S�S�S�
T����j� �	-��w�'�E��e�S�)�)�
D�&�'B�C�C�C��N�N�G�U�+�,�,�,��z�!�		���)�F��f�s�D�k�2�2�
E�&�'C�D�D�D��N�N��*4�V�T�*B�*B�N�D�J�v�&�&�&���
�
�
��j��$�g�.�
�
��	@���-�-��5�t�V�
�
�
�
�
�� �	@�	@�	@��y�6�6�
�'�����	�
#�3�7�C�I�6�6�C�?�����	@���s�#E�
F�;F�F)F)FNr)r@rArBrCr)r;r`rdrlrbrqrsrwr�r��
__classcell__)rJs@r(rGrG�s���������%�%�%�%�%�=�=�=����&5�5�5�5����,
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�W�W�W�W�r@@�@@�@@�@@�@@�@@�@@�@@r*rGc�\�eZdZdZd�Zdd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�ZdS)rYz�Represents a collection of documents on a schema.

    Args:
        schema (mysqlx.Schema): The Schema object.
        name (str): The collection name.
    c���t�t|jj��t|j����}|j�|��dkSrL��_COUNT_TABLES_QUERYrNr
rr'r r$rOrPs  r(r;zCollection.exists_in_database��L��"�(�(����0A�)B�)B�F�4�:�DV�DV�W�W����2�2�3�7�7�1�<�<r*Nc�b�t||��}|j���|_|S)z�Retrieves documents from a collection.

        Args:
            condition (Optional[str]): The string with the filter expression of
                                       the documents to be retrieved.
        )rr$�get_next_statement_id�stmt_id�r%�	condition�stmts   r(�findzCollection.find�s.���T�9�-�-���'�=�=�?�?����r*c�0�t|��j|�S)z�Adds a list of documents to a collection.

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

        Returns:
            mysqlx.AddStatement: AddStatement object.
        )r�add)r%�valuess  r(r�zCollection.add�s��&�|�D�!�!�%�v�.�.r*c�b�t||��}|j���|_|S)apRemoves documents based on the ``condition``.

        Args:
            condition (str): The string with the filter expression of the
                             documents to be removed.

        Returns:
            mysqlx.RemoveStatement: RemoveStatement object.

        .. versionchanged:: 8.0.12
           The ``condition`` parameter is now mandatory.
        )rr$r�r�r�s   r(�removezCollection.remove��.���t�Y�/�/���'�=�=�?�?����r*c�b�t||��}|j���|_|S)arModifies documents based on the ``condition``.

        Args:
            condition (str): The string with the filter expression of the
                             documents to be modified.

        Returns:
            mysqlx.ModifyStatement: ModifyStatement object.

        .. versionchanged:: 8.0.12
           The ``condition`` parameter is now mandatory.
        )rr$r�r�r�s   r(�modifyzCollection.modify�r�r*c�X�t�t|jj��t|j����}	|j�|��}nI#t$r<}|j	tkr&td|j�d|jj�d���|��d}~wwxYw|S)z}Counts the documents in the collection.

        Returns:
            int: The total of documents in the collection.
        r��' does not exist in schema '�'N��_COUNT_QUERYrNrrr'r r$rOr
r�r�r%rQ�resr�s    r(�countzCollection.count	s����!�!��T�\�.�/�/�1A�$�*�1M�1M�
�
��	��"�5�5�c�:�:�C�C���	�	�	��y�,�,�
�&�-�4�:�-�-���)�-�-�-�����
�����
	�����
��A!�!
B'�+7B"�"B'c�$�t|||��S)abCreates a collection index.

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

                                   {"fields": [{"field": member_path,
                                                "type": member_type,
                                                "required": member_required,
                                                "array": array,
                                                "collation": collation,
                                                "options": options,
                                                "srid": srid},
                                                # {... more members,
                                                #      repeated as many times
                                                #      as needed}
                                                ],
                                    "type": type}
        )r)r%�
index_name�fields_descs   r(�create_indexzCollection.create_indexs��,.�d�J��L�L�Lr*c	�f�|j�ddd|jj|j|d���dS)z[Drops a collection index.

        Args:
            index_name (str): Index name.
        r��drop_collection_indexF)r&r_r'N)r$rurr'r )r%r�s  r(�
drop_indexzCollection.drop_index5sL��	
��)�)��#���,�+�"�j�"�
�
�			
�		
�		
�		
�		
r*c���d|vr|d|krtd���|�d���d|���d|�����S)z�Replaces the Document matching the document ID with a new document
        provided.

        Args:
            doc_id (str): Document ID
            doc (:class:`mysqlx.DbDoc` or `dict`): New Document
        �_id�KReplacement document has an _id that is different than the matched document�	_id = :id�$�id)rr��set�bind�execute�r%�doc_id�docs   r(�replace_onezCollection.replace_oneFsw���C�<�	�C��J�&�0�	�"�#���
��{�{�;�'�'�+�+�C��5�5�:�:�4��H�H�P�P�R�R�Rr*c�"�d|vr|d|krtd���t|t��st|��}|�|�|�����d�����S)z�Upserts the Document matching the document ID with a new document
        provided.

        Args:
            doc_id (str): Document ID
            doc (:class:`mysqlx.DbDoc` or dict): New Document
        r�r�T)rrrr��copy�upsertr�r�s   r(�add_or_replace_onezCollection.add_or_replace_oneUs����C�<�	�C��J�&�0�	�"�#���
��#�u�%�%�	���*�*�C��x�x�����(�(�)�)�0�0��6�6�>�>�@�@�@r*c���|�d���d|�����}|���}|j���|S)z�Returns a Document matching the Document ID.

        Args:
            doc_id (str): Document ID

        Returns:
            mysqlx.DbDoc: The Document matching the Document ID.
        r�r�)r�r�r��	fetch_oner$�fetch_active_result)r%r��resultr�s    r(�get_onezCollection.get_onefs\�����;�'�'�,�,�T�6�:�:�B�B�D�D����� � ����,�,�.�.�.��
r*c�x�|�d���d|�����S)z�Removes a Document matching the Document ID.

        Args:
            doc_id (str): Document ID

        Returns:
            mysqlx.Result: Result object.
        r�r�)r�r�r�)r%r�s  r(�
remove_onezCollection.remove_onets2���{�{�;�'�'�,�,�T�6�:�:�B�B�D�D�Dr*r)r@rArBrCr;r�r�r�r�r�r�r�r�r�r�r�rEr*r(rYrY�s���������=�=�=�	�	�	�	�	/�	/�	/����"���"���(M�M�M�0
�
�
�"
S�
S�
S�A�A�A�"���	E�	E�	E�	E�	Er*rYc�<�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	S)
rhz�Represents a database table on a schema.

    Provides access to the table through standard INSERT/SELECT/UPDATE/DELETE
    statements.

    Args:
        schema (mysqlx.Schema): The Schema object.
        name (str): The table name.
    c���t�t|jj��t|j����}|j�|��dkSrLr�rPs  r(r;zTable.exists_in_database�r�r*c�\�t|g|�R�}|j���|_|S)z�Creates a new :class:`mysqlx.SelectStatement` object.

        Args:
            *fields: The fields to be retrieved.

        Returns:
            mysqlx.SelectStatement: SelectStatement object
        )rr$r�r��r%r�r�s   r(�selectzTable.select��4���t�-�f�-�-�-���'�=�=�?�?����r*c�\�t|g|�R�}|j���|_|S)z�Creates a new :class:`mysqlx.InsertStatement` object.

        Args:
            *fields: The fields to be inserted.

        Returns:
            mysqlx.InsertStatement: InsertStatement object
        )rr$r�r�r�s   r(�insertzTable.insert�r�r*c�`�t|��}|j���|_|S)z�Creates a new :class:`mysqlx.UpdateStatement` object.

        Returns:
            mysqlx.UpdateStatement: UpdateStatement object
        )rr$r�r��r%r�s  r(�updatezTable.update�s,���t�$�$���'�=�=�?�?����r*c�`�t|��}|j���|_|S)z�Creates a new :class:`mysqlx.DeleteStatement` object.

        Returns:
            mysqlx.DeleteStatement: DeleteStatement object

        .. versionchanged:: 8.0.12
           The ``condition`` parameter was removed.
        )rr$r�r�r�s  r(�deletezTable.delete�s,���t�$�$���'�=�=�?�?����r*c�X�t�t|jj��t|j����}	|j�|��}nI#t$r<}|j	tkr&td|j�d|jj�d���|��d}~wwxYw|S)ziCounts the rows in the table.

        Returns:
            int: The total of rows in the table.
        zTable 'r�r�Nr�r�s    r(r�zTable.count�s����!�!��T�\�.�/�/�1A�$�*�1M�1M�
�
��	��"�5�5�c�:�:�C�C���	�	�	��y�,�,�
�&�-�d�j�-�-���)�-�-�-�����
�����
	�����
r�c���t�t|jj��t|j����}|j�|��dkS)z�Determine if the underlying object is a view or not.

        Returns:
            bool: `True` if the underlying object is a view.
        r��_COUNT_VIEWS_QUERYrNr
rr'r r$rOrPs  r(�is_viewz
Table.is_view��L��!�'�'��t�|�/@�(A�(A�6�$�*�CU�CU�V�V����2�2�3�7�7�1�<�<r*N)r@rArBrCr;r�r�r�r�r�r�rEr*r(rhrh�s���������=�=�=����������������(=�=�=�=�=r*rhc��eZdZdZd�ZdS)roz�Represents a database view on a schema.

    Provides a mechanism for creating, alter and drop views.

    Args:
        schema (mysqlx.Schema): The Schema object.
        name (str): The table name.
    c���t�t|jj��t|j����}|j�|��dkSrLr�rPs  r(r;zView.exists_in_database�r�r*N)r@rArBrCr;rEr*r(roro�s-��������=�=�=�=�=r*ro)&rCr�r��dbdocr�	errorcoderrrr�errorsr	r
r�helpersrr
r�	statementrrrrrrrrrr�r�rMr�rvrrGrYrhrorEr*r(�<module>r�sT��:3�2���������������������������J�I�I�I�I�I�I�I�I�I�9�9�9�9�9�9�9�9�9�9�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�8��
8��
Q��.��2��a�a�a�a�a�a�a�a�HS@�S@�S@�S@�S@�^�S@�S@�S@�l}E�}E�}E�}E�}E��}E�}E�}E�@`=�`=�`=�`=�`=�N�`=�`=�`=�F=�=�=�=�=�5�=�=�=�=�=r*