
    Ki                     f    d Z ddlmZ ddlmZ ddlmZ ddlmZ ededee         fd            Z	d	S )
zAtomic 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         }|                                 }d}	 |rd| _         |V  |                                  n7# t          $ r* d}	 |                                  n# t          $ r Y nw xY w w xY w	 || _         	 |                                 dS # t          $ r |s Y dS w xY w# || _         	 |                                 w # t          $ r |s Y w w xY wxY 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       X/var/www/html/analyses/venv/lib/python3.11/site-packages/mysql/ai/utils/atomic_cursor.pyatomic_transactionr   *   sR     . _N[[]]F 	$#DO 	 	 		MMOOOO 	 	 	D	
 		 	 )	LLNNNNN 	 	 	#   		 )	LLNNNN 	 	 	#  	sw   !A B- A7A%$A7%
A2/A71A22A77B- B B*)B*-C6C
CCCCCN)
__doc__
contextlibr   typingr   mysql.connector.abstractsr   mysql.connector.cursorr   r        r   <module>r      s   :  & % % % % %       = = = = = = 6 6 6 6 6 6 3
!3!"3 3 3 3 3 3r   