✏️ 正在编辑: atomic_cursor.cpython-312.pyc
路径:
/var/opt/nydus/ops/mysql/ai/utils/__pycache__/atomic_cursor.cpython-312.pyc
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
� ��'j� � �X � d Z ddlmZ ddlmZ ddlmZ ddlmZ ededee fd�� Z y ) z�Atomic transaction context manager utilities for MySQL Connector/Python. Provides context manager atomic_transaction() that ensures commit on success and rollback on error without obscuring the original exception. � )�contextmanager)�Iterator)�MySQLConnectionAbstract)�MySQLCursorAbstract�conn�returnc # � K � | j }| j � }d} |rd| _ |�� | j � || _ |j � y# t $ r$ d} | j � � # t $ r Y � w xY ww xY w# t $ r |s� Y yw xY w# || _ |j � w # t $ r |s� Y w w xY wxY w�w)a� Context manager that wraps a MySQL database cursor and ensures transaction rollback in case of exception. NOTE: DDL statements such as CREATE TABLE cause implicit commits. These cannot be managed by a cursor object. Changes made at or before a DDL statement will be committed and not rolled back. Callers are responsible for any cleanup of this type. This class acts as a robust, PEP 343-compliant context manager for handling database cursor operations on a MySQL connection. It ensures that all operations executed within the context block are part of the same transaction, and automatically calls `connection.rollback()` if an exception occurs, helping to maintain database integrity. On normal completion (no exception), it simply closes the cursor after use. Exceptions are always propagated to the caller. Args: conn: A MySQLConnectionAbstract instance. FTN)� autocommit�cursor�commit� Exception�rollback�close)r �old_autocommitr �exception_raiseds �M/opt/nydus/tmp/pip-target-k0fmikie/lib/python/mysql/ai/utils/atomic_cursor.py�atomic_transactionr * s� � �� �. �_�_�N� �[�[�]�F�����#�D�O������ � )��� ��L�L�N�� � ��� ��M�M�O� �� � �� � �� �� � �#�� $� �� )��� ��L�L�N��� �#�� $� �s� �C �A � C �B �C �B�%A6�5B�6 B�?B�B�B�B � B�C �B�C �C�$B5�4C�5C�C�C�C�C N) �__doc__� contextlibr �typingr �mysql.connector.abstractsr �mysql.connector.cursorr r � � r �<module>r sB ��:� &� � =� 6� �3� !�3� �!�"�3� �3r
💾 保存文件
← 返回文件管理器