
    +h                       d dl m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	 ddlm
Z
 d	d
lmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ 	  ej$                         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ej6                        Z G d d e      Z G d! d"ee      Zee_         y)#    )with_statementN   )Connectable)ExceptionContext)_distill_params)_distill_params_20)TransactionalContext   )exc)
inspection)log)util)compilerc                      e Zd ZdZdZdZdZ	 	 	 	 	 	 	 dNdZej                  d        Z
d Zd Zed	        Zd
 Zd Zd Zd Zd Zd Zd Zed        Zed        Zed        Zd Zed        Zd Zd Zed        Zed        Z ej>                  d      dOd       Z dPdZ!d Z"d Z#d Z$d  Z%dPd!Z&d" Z'dOd#Z(dOd$Z)d% Z*d& Z+d' Z,d( Z-d) Z.d* Z/d+ Z0dOd,Z1dPd-Z2d. Z3d/ Z4d0 Z5d1 Z6d2 Z7d3 Z8d4 Z9d5 Z:d6 Z;d7 Z<d8 Z=d9 Z>d: Z?e@fd;ZAd< ZBd= ZCd> ZDe@fd?ZEd@ ZFde@fdAZG	 dQdBZHdC ZIdPdDZJdE ZKdZLdZMdF ZNeOdG        ZPdH ZQ ej                  dIdJ      dK        ZS ej                  dIdL      dM        ZTy)R
Connectiona  Provides high-level functionality for a wrapped DB-API connection.

    **This is the SQLAlchemy 1.x.x version** of the :class:`_engine.Connection`
    class.   For the :term:`2.0 style` version, which features some API
    differences, see :class:`_future.Connection`.

    The :class:`_engine.Connection` object is procured by calling
    the :meth:`_engine.Engine.connect` method of the :class:`_engine.Engine`
    object, and provides services for execution of SQL statements as well
    as transaction control.

    The Connection object is **not** thread-safe.  While a Connection can be
    shared among threads using properly synchronized access, it is still
    possible that the underlying DBAPI connection may not support shared
    access between threads.  Check the DBAPI documentation for details.

    The Connection object represents a single DBAPI connection checked out
    from the connection pool. In this state, the connection pool has no affect
    upon the connection, including its expiration or timeout state. For the
    connection pool to properly manage connections, connections should be
    returned to the connection pool (i.e. ``connection.close()``) whenever the
    connection is not in use.

    .. index::
      single: thread safety; Connection

    Fzsqlalchemy.engine.ConnectionNc	                    || _         |j                  | _        || _        |rM|j                  J || _        || _        |j
                  | _        d| _        || _        |j                  | _        n||n|j                         | _        dx| _
        | _        d| _        d| _        || _        || _        | j                   j                         | _        |*| j                  j!                  |j                        | _        |xs |du xr |j                  | _        |rJ |j                  | _        | j                  s| j                   j                  r| j                  j#                  | |du       yy)zConstruct a new Connection.NFr   )enginedialect_Connection__branch_from_dbapi_connection_execution_options_echoshould_close_with_resultdispatch_has_eventsraw_connection_transaction_nested_transaction_Connection__savepoint_seq_Connection__in_begin_Connection__can_reconnect_should_log_info_joinengine_connect)	selfr   
connectionclose_with_result_branch_fromr   	_dispatchr   _allow_revalidates	            I/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py__init__zConnection.__init__C   se    ~~)--555%/D"&8D#%++DJ,1D)%DM+77D ) **, " <@?D 8#$D #DO,=D)#4D 557DJ" !% 3 3FOO D*  t#:(:(:  *))&,&?&?D#t{{66MM((|4/GH  7    c                 J    d| j                   v r| j                   d   fdS y )Nlogging_tokenc                     dd| S )N[z]  )msgtokens    r+   <lambda>z/Connection._message_formatter.<locals>.<lambda>~   s    E37 r-   r   )r%   r4   s    @r+   _message_formatterzConnection._message_formatterz   s*    d555++O<E77r-   c                     | j                   }|r ||      }t        j                  rdt        j                  z   |d<    | j                  j
                  j                  |g|i | y Nr   
stacklevel)r7   r   
STACKLEVELSTACKLEVEL_OFFSETr   loggerinfor%   messageargkwfmts        r+   	_log_infozConnection._log_info   sY    %%'lG>> 3#8#88B|4#44r-   c                     | j                   }|r ||      }t        j                  rdt        j                  z   |d<    | j                  j
                  j                  |g|i | y r9   )r7   r   r;   r<   r   r=   debugr?   s        r+   
_log_debugzConnection._log_debug   sY    %%'lG>> 3#8#88B|   535"5r-   c                 :    | j                   j                  dd       S )Nschema_translate_map)r   getr%   s    r+   _schema_translate_mapz Connection._schema_translate_map   s    &&**+A4HHr-   c                     |j                   }| j                  j                  dd      }|r||v r|j                  r||   S |S )ztReturn the schema name for the given schema item taking into
        account current schema translate map.

        rI   N)schemar   rJ   _use_schema_map)r%   objnamerI   s       r+   schema_for_objectzConnection.schema_for_object   sP     zz#66::"D 

 !,,##'--Kr-   c                     | j                   j                  | j                   | j                  | j                  r| j                  n| | j                  | j
                  | j                        S )az  Return a new Connection which references this Connection's
        engine and connection; but does not have close_with_result enabled,
        and also whose close() method does nothing.

        .. deprecated:: 1.4 the "branching" concept will be removed in
           SQLAlchemy 2.0 as well as the "Connection.connect()" method which
           is the only consumer for this.

        The Core uses this very sparingly, only in the case of
        custom SQL default functions that are to be INSERTed as the
        primary key of a row where we need to get the value back, so we have
        to invoke it distinctly - this is a very uncommon case.

        Userland code accesses _branch() when the connect()
        method is called.  The branched connection
        acts as much as possible like the parent, except that it stays
        connected when a close() event occurs.

        )r(   r   r   r)   )r   _connection_clsr   r   r   r   r   rK   s    r+   _branchzConnection._branch   s\    ( {{**KK""/3/A/A++t#66((mm + 
 	
r-   c                     | j                   r| S | j                  j                  | j                        }| j                  j	                         |_        |S )z@define connection method chaining behavior for execution_options)
_is_future	__class____new____dict__copy)r%   cs     r+   _generate_for_optionsz Connection._generate_for_options   sA     ??K&&t~~6A++-AJHr-   c                     | S Nr2   rK   s    r+   	__enter__zConnection.__enter__   s    r-   c                 $    | j                          y r_   )closer%   type_value	tracebacks       r+   __exit__zConnection.__exit__       

r-   c                    | j                         }|j                  j                  |      |_        | j                  s| j                  j                  r| j
                  j                  ||       | j                  j                  ||       |S )a.   Set non-SQL options for the connection which take effect
        during execution.

        For a "future" style connection, this method returns this same
        :class:`_future.Connection` object with the new options added.

        For a legacy connection, this method returns a copy of this
        :class:`_engine.Connection` which references the same underlying DBAPI
        connection, but also defines the given execution options which will
        take effect for a call to
        :meth:`execute`. As the new :class:`_engine.Connection` references the
        same underlying resource, it's usually a good idea to ensure that
        the copies will be discarded immediately, which is implicit if used
        as in::

            result = connection.execution_options(stream_results=True).\
                                execute(stmt)

        Note that any key/value can be passed to
        :meth:`_engine.Connection.execution_options`,
        and it will be stored in the
        ``_execution_options`` dictionary of the :class:`_engine.Connection`.
        It
        is suitable for usage by end-user schemes to communicate with
        event listeners, for example.

        The keywords that are currently recognized by SQLAlchemy itself
        include all those listed under :meth:`.Executable.execution_options`,
        as well as others that are specific to :class:`_engine.Connection`.

        :param autocommit: Available on: Connection, statement.
          When True, a COMMIT will be invoked after execution
          when executed in 'autocommit' mode, i.e. when an explicit
          transaction is not begun on the connection.   Note that this
          is **library level, not DBAPI level autocommit**.  The DBAPI
          connection will remain in a real transaction unless the
          "AUTOCOMMIT" isolation level is used.

          .. deprecated:: 1.4  The "autocommit" execution option is deprecated
             and will be removed in SQLAlchemy 2.0.  See
             :ref:`migration_20_autocommit` for discussion.

        :param compiled_cache: Available on: Connection.
          A dictionary where :class:`.Compiled` objects
          will be cached when the :class:`_engine.Connection`
          compiles a clause
          expression into a :class:`.Compiled` object.  This dictionary will
          supersede the statement cache that may be configured on the
          :class:`_engine.Engine` itself.   If set to None, caching
          is disabled, even if the engine has a configured cache size.

          Note that the ORM makes use of its own "compiled" caches for
          some operations, including flush operations.  The caching
          used by the ORM internally supersedes a cache dictionary
          specified here.

        :param logging_token: Available on: :class:`_engine.Connection`,
          :class:`_engine.Engine`.

          Adds the specified string token surrounded by brackets in log
          messages logged by the connection, i.e. the logging that's enabled
          either via the :paramref:`_sa.create_engine.echo` flag or via the
          ``logging.getLogger("sqlalchemy.engine")`` logger. This allows a
          per-connection or per-sub-engine token to be available which is
          useful for debugging concurrent connection scenarios.

          .. versionadded:: 1.4.0b2

          .. seealso::

            :ref:`dbengine_logging_tokens` - usage example

            :paramref:`_sa.create_engine.logging_name` - adds a name to the
            name used by the Python logger object itself.

        :param isolation_level: Available on: :class:`_engine.Connection`.

          Set the transaction isolation level for the lifespan of this
          :class:`_engine.Connection` object.
          Valid values include those string
          values accepted by the :paramref:`_sa.create_engine.isolation_level`
          parameter passed to :func:`_sa.create_engine`.  These levels are
          semi-database specific; see individual dialect documentation for
          valid levels.

          The isolation level option applies the isolation level by emitting
          statements on the  DBAPI connection, and **necessarily affects the
          original Connection object overall**, not just the copy that is
          returned by the call to :meth:`_engine.Connection.execution_options`
          method.  The isolation level will remain at the given setting until
          the DBAPI connection itself is returned to the connection pool, i.e.
          the :meth:`_engine.Connection.close` method on the original
          :class:`_engine.Connection` is called,
          where  an event handler will emit
          additional statements on the DBAPI connection in order to revert the
          isolation level change.

          .. warning::  The ``isolation_level`` execution option should
             **not** be used when a transaction is already established, that
             is, the :meth:`_engine.Connection.begin`
             method or similar has been
             called.  A database cannot change the isolation level on a
             transaction in progress, and different DBAPIs and/or
             SQLAlchemy dialects may implicitly roll back or commit
             the transaction, or not affect the connection at all.

          .. note:: The ``isolation_level`` execution option is implicitly
             reset if the :class:`_engine.Connection` is invalidated, e.g. via
             the :meth:`_engine.Connection.invalidate` method, or if a
             disconnection error occurs.  The new connection produced after
             the invalidation will not have the isolation level re-applied
             to it automatically.

          .. seealso::

                :paramref:`_sa.create_engine.isolation_level`
                - set per :class:`_engine.Engine` isolation level

                :meth:`_engine.Connection.get_isolation_level`
                - view current actual level

                :ref:`SQLite Transaction Isolation <sqlite_isolation_level>`

                :ref:`PostgreSQL Transaction Isolation <postgresql_isolation_level>`

                :ref:`MySQL Transaction Isolation <mysql_isolation_level>`

                :ref:`SQL Server Transaction Isolation <mssql_isolation_level>`

                :ref:`session_transaction_isolation` - for the ORM

        :param no_parameters: When ``True``, if the final parameter
          list or dictionary is totally empty, will invoke the
          statement on the cursor as ``cursor.execute(statement)``,
          not passing the parameter collection at all.
          Some DBAPIs such as psycopg2 and mysql-python consider
          percent signs as significant only when parameters are
          present; this option allows code to generate SQL
          containing percent signs (and possibly other characters)
          that is neutral regarding whether it's executed by the DBAPI
          or piped into a script that's later invoked by
          command line tools.

        :param stream_results: Available on: Connection, statement.
          Indicate to the dialect that results should be
          "streamed" and not pre-buffered, if possible.  For backends
          such as PostgreSQL, MySQL and MariaDB, this indicates the use of
          a "server side cursor" as opposed to a client side cursor.
          Other backends such as that of Oracle may already use server
          side cursors by default.

          The usage of
          :paramref:`_engine.Connection.execution_options.stream_results` is
          usually combined with setting a fixed number of rows to to be fetched
          in batches, to allow for efficient iteration of database rows while
          at the same time not loading all result rows into memory at once;
          this can be configured on a :class:`_engine.Result` object using the
          :meth:`_engine.Result.yield_per` method, after execution has
          returned a new :class:`_engine.Result`.   If
          :meth:`_engine.Result.yield_per` is not used,
          the :paramref:`_engine.Connection.execution_options.stream_results`
          mode of operation will instead use a dynamically sized buffer
          which buffers sets of rows at a time, growing on each batch
          based on a fixed growth size up until a limit which may
          be configured using the
          :paramref:`_engine.Connection.execution_options.max_row_buffer`
          parameter.

          When using the ORM to fetch ORM mapped objects from a result,
          :meth:`_engine.Result.yield_per` should always be used with
          :paramref:`_engine.Connection.execution_options.stream_results`,
          so that the ORM does not fetch all rows into new ORM objects at once.

          For typical use, the
          :paramref:`_engine.Connection.execution_options.yield_per` execution
          option should be preferred, which sets up both
          :paramref:`_engine.Connection.execution_options.stream_results` and
          :meth:`_engine.Result.yield_per` at once. This option is supported
          both at a core level by :class:`_engine.Connection` as well as by the
          ORM :class:`_engine.Session`; the latter is described at
          :ref:`orm_queryguide_yield_per`.

          .. seealso::

            :ref:`engine_stream_results` - background on
            :paramref:`_engine.Connection.execution_options.stream_results`

            :paramref:`_engine.Connection.execution_options.max_row_buffer`

            :paramref:`_engine.Connection.execution_options.yield_per`

            :ref:`orm_queryguide_yield_per` - in the :ref:`queryguide_toplevel`
            describing the ORM version of ``yield_per``

        :param max_row_buffer: Available on: :class:`_engine.Connection`,
          :class:`_sql.Executable`.  Sets a maximum
          buffer size to use when the
          :paramref:`_engine.Connection.execution_options.stream_results`
          execution option is used on a backend that supports server side
          cursors.  The default value if not specified is 1000.

          .. seealso::

            :paramref:`_engine.Connection.execution_options.stream_results`

            :ref:`engine_stream_results`


        :param yield_per: Available on: :class:`_engine.Connection`,
          :class:`_sql.Executable`.  Integer value applied which will
          set the :paramref:`_engine.Connection.execution_options.stream_results`
          execution option and invoke :meth:`_engine.Result.yield_per`
          automatically at once.  Allows equivalent functionality as
          is present when using this parameter with the ORM.

          .. versionadded:: 1.4.40

          .. seealso::

            :ref:`engine_stream_results` - background and examples
            on using server side cursors with Core.

            :ref:`orm_queryguide_yield_per` - in the :ref:`queryguide_toplevel`
            describing the ORM version of ``yield_per``

        :param schema_translate_map: Available on: :class:`_engine.Connection`,
          :class:`_engine.Engine`, :class:`_sql.Executable`.

        :param schema_translate_map: Available on: Connection, Engine.
          A dictionary mapping schema names to schema names, that will be
          applied to the :paramref:`_schema.Table.schema` element of each
          :class:`_schema.Table`
          encountered when SQL or DDL expression elements
          are compiled into strings; the resulting schema name will be
          converted based on presence in the map of the original name.

          .. versionadded:: 1.1

          .. seealso::

            :ref:`schema_translating`

        .. seealso::

            :meth:`_engine.Engine.execution_options`

            :meth:`.Executable.execution_options`

            :meth:`_engine.Connection.get_execution_options`


        )r]   r   unionr   r   r    set_connection_execution_optionsr   )r%   optr\   s      r+   execution_optionszConnection.execution_options   sn    z &&( 3399#>t{{66MM::1cB55a=r-   c                     | j                   S )zGet the non-SQL options which will take effect during execution.

        .. versionadded:: 1.3

        .. seealso::

            :meth:`_engine.Connection.execution_options`
        r6   rK   s    r+   get_execution_optionsz Connection.get_execution_options       &&&r-   c                 <    | j                   du xr | j                   S )z)Return True if this connection is closed.N)r   r!   rK   s    r+   closedzConnection.closed  s#     %%-Jd6J6J2JJr-   c                     | j                   r| j                   j                  S | j                  du xr | j                   S )z/Return True if this connection was invalidated.N)r   invalidatedr   rr   rK   s    r+   rt   zConnection.invalidated  s;     %%111%%-Adkk/Ar-   c                     | j                   	 | j                         S | j                   S # t        j                  t        j                  f$ r  t
        $ r}| j                  |dddd       Y d}~yd}~ww xY w)aV  The underlying DB-API connection managed by this Connection.

        This is a SQLAlchemy connection-pool proxied connection
        which then has the attribute
        :attr:`_pool._ConnectionFairy.dbapi_connection` that refers to the
        actual driver connection.

        .. seealso::


            :ref:`dbapi_connections`

        N)r   _revalidate_connectionr   PendingRollbackErrorResourceClosedErrorBaseException_handle_dbapi_exceptionr%   es     r+   r&   zConnection.connection  s|      !!)H2244 ))) ,,c.E.EF   H,,QdD$GGHs   * ,A5A00A5c                     	 | j                   j                  | j                        S # t        $ r}| j	                  |dddd       Y d}~yd}~ww xY w)a  Return the current **actual** isolation level that's present on
        the database within the scope of this connection.

        This attribute will perform a live SQL operation against the database
        in order to procure the current isolation level, so the value returned
        is the actual level on the underlying DBAPI connection regardless of
        how this state was set. This will be one of the four actual isolation
        modes ``READ UNCOMMITTED``, ``READ COMMITTED``, ``REPEATABLE READ``,
        ``SERIALIZABLE``. It will **not** include the ``AUTOCOMMIT`` isolation
        level setting. Third party dialects may also feature additional
        isolation level settings.

        .. note::  This method **will not report** on the ``AUTOCOMMIT``
          isolation level, which is a separate :term:`dbapi` setting that's
          independent of **actual** isolation level.  When ``AUTOCOMMIT`` is
          in use, the database connection still has a "traditional" isolation
          mode in effect, that is typically one of the four values
          ``READ UNCOMMITTED``, ``READ COMMITTED``, ``REPEATABLE READ``,
          ``SERIALIZABLE``.

        Compare to the :attr:`_engine.Connection.default_isolation_level`
        accessor which returns the isolation level that is present on the
        database at initial connection time.

        .. versionadded:: 0.9.9

        .. seealso::

            :attr:`_engine.Connection.default_isolation_level`
            - view default level

            :paramref:`_sa.create_engine.isolation_level`
            - set per :class:`_engine.Engine` isolation level

            :paramref:`.Connection.execution_options.isolation_level`
            - set per :class:`_engine.Connection` isolation level

        N)r   get_isolation_levelr&   ry   rz   r{   s     r+   r~   zConnection.get_isolation_level!  sM    N	D<<33DOODD 	D((D$dCC	Ds   $' 	AA

Ac                 .    | j                   j                  S )a  The initial-connection time isolation level associated with the
        :class:`_engine.Dialect` in use.

        This value is independent of the
        :paramref:`.Connection.execution_options.isolation_level` and
        :paramref:`.Engine.execution_options.isolation_level` execution
        options, and is determined by the :class:`_engine.Dialect` when the
        first connection is created, by performing a SQL query against the
        database for the current isolation level before any additional commands
        have been emitted.

        Calling this accessor does not invoke any new SQL queries.

        .. versionadded:: 0.9.9

        .. seealso::

            :meth:`_engine.Connection.get_isolation_level`
            - view current actual isolation level

            :paramref:`_sa.create_engine.isolation_level`
            - set per :class:`_engine.Engine` isolation level

            :paramref:`.Connection.execution_options.isolation_level`
            - set per :class:`_engine.Connection` isolation level

        )r   default_isolation_levelrK   s    r+   r   z"Connection.default_isolation_levelM  s    : ||333r-   c                     | j                   r(t        j                  d| j                  dndz  d      | j                  rJ t        j                  d| j                  dndz  d      )Nz;Can't reconnect until invalid %stransaction is rolled back.z
savepoint  8s2b)codez\This connection is on an inactive %stransaction.  Please rollback() fully before proceeding.8s2a)rt   r   rw   r   rW   rK   s    r+   _invalid_transactionzConnection._invalid_transactionl  s    ** //; ! 	 	 &&**= //; ! 	 	r-   c                 :   | j                   r| j                   j                         S | j                  rU| j                  rI| j                  | j                          | j                  j                  |       | _        | j                  S t        j                  d      )N)_connectionThis Connection is closed)r   rv   r!   rt   r   r   r   r   r   r   rx   rK   s    r+   rv   z!Connection._revalidate_connection  s    %%<<>>D$4$4  ,))+%)[[%?%?  &@ &D" )))%%&ABBr-   c                 P    | j                   d uxr t        | j                   dd      S )Nis_validF)r   getattrrK   s    r+   )_still_open_and_dbapi_connection_is_validz4Connection._still_open_and_dbapi_connection_is_valid  s.    %%T1 
g""J7
 	
r-   c                 .    | j                   j                  S )a  Info dictionary associated with the underlying DBAPI connection
        referred to by this :class:`_engine.Connection`, allowing user-defined
        data to be associated with the connection.

        The data here will follow along with the DBAPI connection including
        after it is returned to the connection pool and used again
        in subsequent instances of :class:`_engine.Connection`.

        )r&   r>   rK   s    r+   r>   zConnection.info  s     ###r-   z:meth:`.Connection.connect`c                 "    | j                         S )a  Returns a branched version of this :class:`_engine.Connection`.

        The :meth:`_engine.Connection.close` method on the returned
        :class:`_engine.Connection` can be called and this
        :class:`_engine.Connection` will remain open.

        This method provides usage symmetry with
        :meth:`_engine.Engine.connect`, including for usage
        with context managers.

        )rU   r%   r'   s     r+   connectzConnection.connect  s     ||~r-   c                    | j                   r| j                   j                  |      S | j                  ry| j                  rt	        j
                  d      | j                  r| j                  j                  |       d| _        y)a  Invalidate the underlying DBAPI connection associated with
        this :class:`_engine.Connection`.

        An attempt will be made to close the underlying DBAPI connection
        immediately; however if this operation fails, the error is logged
        but not raised.  The connection is then discarded whether or not
        close() succeeded.

        Upon the next use (where "use" typically means using the
        :meth:`_engine.Connection.execute` method or similar),
        this :class:`_engine.Connection` will attempt to
        procure a new DBAPI connection using the services of the
        :class:`_pool.Pool` as a source of connectivity (e.g.
        a "reconnection").

        If a transaction was in progress (e.g. the
        :meth:`_engine.Connection.begin` method has been called) when
        :meth:`_engine.Connection.invalidate` method is called, at the DBAPI
        level all state associated with this transaction is lost, as
        the DBAPI connection is closed.  The :class:`_engine.Connection`
        will not allow a reconnection to proceed until the
        :class:`.Transaction` object is ended, by calling the
        :meth:`.Transaction.rollback` method; until that point, any attempt at
        continuing to use the :class:`_engine.Connection` will raise an
        :class:`~sqlalchemy.exc.InvalidRequestError`.
        This is to prevent applications from accidentally
        continuing an ongoing transactional operations despite the
        fact that the transaction has been lost due to an
        invalidation.

        The :meth:`_engine.Connection.invalidate` method,
        just like auto-invalidation,
        will at the connection pool level invoke the
        :meth:`_events.PoolEvents.invalidate` event.

        :param exception: an optional ``Exception`` instance that's the
         reason for the invalidation.  is passed along to event handlers
         and logging functions.

        .. seealso::

            :ref:`pool_connection_invalidation`

        )	exceptionNr   )r   
invalidatert   rr   r   rx   r   r   )r%   r   s     r+   r   zConnection.invalidate  sr    \ %%0090EE;;))*EFF99""--i8!%r-   c                 8    | j                   j                          y)a2  Detach the underlying DB-API connection from its connection pool.

        E.g.::

            with engine.connect() as conn:
                conn.detach()
                conn.execute(text("SET search_path TO schema1, schema2"))

                # work with connection

            # connection is fully closed (since we used "with:", can
            # also call .close())

        This :class:`_engine.Connection` instance will remain usable.
        When closed
        (or exited from a context manager context as above),
        the DB-API connection will be literally closed and not
        returned to its originating pool.

        This method can be used to insulate the rest of an application
        from a modified state on a connection (such as a transaction
        isolation level or similar).

        N)r   detachrK   s    r+   r   zConnection.detach  s    4 	%%'r-   c                 $    | j                          y r_   )beginrK   s    r+   
_autobeginzConnection._autobegin  rh   r-   c                 D   | j                   r| j                  r(J | j                  r| j                  j                         S | j                  ry| j                  t        |       | _        | j                  S | j                   rt        j                  d      t        |       S )a  Begin a transaction and return a transaction handle.

        The returned object is an instance of :class:`.Transaction`.
        This object represents the "scope" of the transaction,
        which completes when either the :meth:`.Transaction.rollback`
        or :meth:`.Transaction.commit` method is called.

        .. tip::

            The :meth:`_engine.Connection.begin` method is invoked when using
            the :meth:`_engine.Engine.begin` context manager method as well.
            All documentation that refers to behaviors specific to the
            :meth:`_engine.Connection.begin` method also apply to use of the
            :meth:`_engine.Engine.begin` method.

        Legacy use: nested calls to :meth:`.begin` on the same
        :class:`_engine.Connection` will return new :class:`.Transaction`
        objects that represent an emulated transaction within the scope of the
        enclosing transaction, that is::

            trans = conn.begin()   # outermost transaction
            trans2 = conn.begin()  # "nested"
            trans2.commit()        # does nothing
            trans.commit()         # actually commits

        Calls to :meth:`.Transaction.commit` only have an effect
        when invoked via the outermost :class:`.Transaction` object, though the
        :meth:`.Transaction.rollback` method of any of the
        :class:`.Transaction` objects will roll back the
        transaction.

        .. tip::

            The above "nesting" behavior is a legacy behavior specific to
            :term:`1.x style` use and will be removed in SQLAlchemy 2.0. For
            notes on :term:`2.0 style` use, see
            :meth:`_future.Connection.begin`.


        .. seealso::

            :meth:`_engine.Connection.begin_nested` - use a SAVEPOINT

            :meth:`_engine.Connection.begin_twophase` -
            use a two phase /XID transaction

            :meth:`_engine.Engine.begin` - context manager available from
            :class:`_engine.Engine`

        NzThis connection has already initialized a SQLAlchemy Transaction() object via begin() or autobegin; can't call begin() here unless rollback() or commit() is called first.)	rW   r   r   r    r   RootTransactionr   InvalidRequestErrorMarkerTransactionrK   s    r+   r   zConnection.begin  s    f ??))))%%++--?? & / 5D$$$--'  )..r-   c                 2   | j                   r| j                  r(J | j                  r| j                  j                         S | j                  A| j                   s%t	        j
                  d       | j                         S | j                          t        |       S )a  Begin a nested transaction (i.e. SAVEPOINT) and return a
        transaction handle, assuming an outer transaction is already
        established.

        Nested transactions require SAVEPOINT support in the
        underlying database.  Any transaction in the hierarchy may
        ``commit`` and ``rollback``, however the outermost transaction
        still controls the overall ``commit`` or ``rollback`` of the
        transaction of a whole.

        The legacy form of :meth:`_engine.Connection.begin_nested` method has
        alternate behaviors based on whether or not the
        :meth:`_engine.Connection.begin` method was called previously. If
        :meth:`_engine.Connection.begin` was not called, then this method will
        behave the same as the :meth:`_engine.Connection.begin` method and
        return a :class:`.RootTransaction` object that begins and commits a
        real transaction - **no savepoint is invoked**. If
        :meth:`_engine.Connection.begin` **has** been called, and a
        :class:`.RootTransaction` is already established, then this method
        returns an instance of :class:`.NestedTransaction` which will invoke
        and manage the scope of a SAVEPOINT.

        .. tip::

            The above mentioned behavior of
            :meth:`_engine.Connection.begin_nested` is a legacy behavior
            specific to :term:`1.x style` use. In :term:`2.0 style` use, the
            :meth:`_future.Connection.begin_nested` method instead autobegins
            the outer transaction that can be committed using
            "commit-as-you-go" style; see
            :meth:`_future.Connection.begin_nested` for migration details.

        .. versionchanged:: 1.4.13 The behavior of
           :meth:`_engine.Connection.begin_nested`
           as returning a :class:`.RootTransaction` if
           :meth:`_engine.Connection.begin` were not called has been restored
           as was the case in 1.3.x versions; in previous 1.4.x versions, an
           outer transaction would be "autobegun" but would not be committed.


        .. seealso::

            :meth:`_engine.Connection.begin`

            :ref:`session_begin_nested` - ORM support for SAVEPOINT

        a(  Calling Connection.begin_nested() in 2.0 style use will return a NestedTransaction (SAVEPOINT) in all cases, that will not commit the outer transaction.  For code that is cross-compatible between 1.x and 2.0 style use, ensure Connection.begin() is called before calling Connection.begin_nested().)	rW   r   begin_nestedr   r   warn_deprecated_20r   r   NestedTransactionrK   s    r+   r   zConnection.begin_nested\  s    ` ??))))%%2244$??''1 zz|#! &&r-   c                     | j                   r| j                   j                  |      S | j                  t        j                  d      |$| j
                  j                  j                         }t        | |      S )a'  Begin a two-phase or XA transaction and return a transaction
        handle.

        The returned object is an instance of :class:`.TwoPhaseTransaction`,
        which in addition to the methods provided by
        :class:`.Transaction`, also provides a
        :meth:`~.TwoPhaseTransaction.prepare` method.

        :param xid: the two phase transaction id.  If not supplied, a
          random id will be generated.

        .. seealso::

            :meth:`_engine.Connection.begin`

            :meth:`_engine.Connection.begin_twophase`

        )xidzOCannot start a two phase transaction when a transaction is already in progress.)	r   begin_twophaser   r   r   r   r   
create_xidTwoPhaseTransaction)r%   r   s     r+   r   zConnection.begin_twophase  sw    ( %%444==())*  ;++%%002C"4--r-   c                 L    | j                   j                  j                  |       S r_   )r   r   do_recover_twophaserK   s    r+   recover_twophasezConnection.recover_twophase  s    {{""66t<<r-   c                 T    | j                   j                  j                  | ||       y N)recover)r   r   do_rollback_twophaser%   r   r   s      r+   rollback_preparedzConnection.rollback_prepared  s!    00sG0Lr-   c                 T    | j                   j                  j                  | ||       y r   )r   r   do_commit_twophaser   s      r+   commit_preparedzConnection.commit_prepared  s!    ..tS'.Jr-   c                     | j                   | j                   j                         S | j                  duxr | j                  j                  S z,Return True if a transaction is in progress.N)r   in_transactionr   	is_activerK   s    r+   r   zConnection.in_transaction  sE    )%%4466  ,L1B1B1L1LLr-   c                     | j                   | j                   j                         S | j                  duxr | j                  j                  S r   )r   in_nested_transactionr   r   rK   s    r+   r   z Connection.in_nested_transaction  sL    )%%;;== $$D0 3((22	
r-   c                     | j                   j                  dd       }t        |dk(  xs* |d u xr$ t        | j                  j
                  dd       dk(        S )Nisolation_level
AUTOCOMMIT)r   rJ   boolr   r   r   )r%   opt_isos     r+   _is_autocommit_isolationz#Connection._is_autocommit_isolation  s`    ))--.?F|# 4  DKK//1BDI 	
 	
r-   c                 f    | j                   | j                   j                         S | j                  S )zaReturn the current root transaction in progress, if any.

        .. versionadded:: 1.4

        )r   get_transactionr   rK   s    r+   r   zConnection.get_transaction  s1     )%%5577   r-   c                 f    | j                   | j                   j                         S | j                  S )zcReturn the current nested transaction in progress, if any.

        .. versionadded:: 1.4

        )r   get_nested_transactionr   rK   s    r+   r   z!Connection.get_nested_transaction  s1     )%%<<>>'''r-   c                    | j                   rJ | j                  r3| j                         r| j                  d       n| j                  d       d| _        | j
                  s| j                  j
                  r| j                  j                  |        	 | j                  j                  j                  | j                         d| _        y # t        $ r}| j                  |d d d d        Y d }~+d }~ww xY w# d| _        w xY w)Nz?BEGIN (implicit; DBAPI should not BEGIN due to autocommit mode)zBEGIN (implicit)TF)r   r   r   rD   r    r   r   r   r   r   do_beginr&   ry   rz   r%   transactionr|   s      r+   _begin_implzConnection._begin_impl  s    %%%%::,,.'
 12t{{66MM%	$KK((9 $DO  	D((D$dCC	D $DOs*   /C
 
	C2C-(C5 -C22C5 5	C>c                    | j                   rJ | j                  s| j                  j                  r| j                  j	                  |        | j
                  rp| j                  r3| j                         r| j                  d       n| j                  d       	 | j                  j                  j                  | j                         y y # t        $ r}| j                  |d d d d        Y d }~y d }~ww xY w)NzVROLLBACK using DBAPI connection.rollback(), DBAPI should ignore due to autocommit modeROLLBACK)r   r   r   r   rollbackr   r   r   rD   r   do_rollbackr&   ry   rz   r{   s     r+   _rollback_implzConnection._rollback_impl  s    %%%%t{{66MM""4(99zz002NNE
 NN:.H##//@ : ! H,,QdD$GGHs   /C	 		C1C,,C1c                    | j                   rJ |r%| j                         st        j                  d       | j                  s| j
                  j                  r| j                  j                  |        | j                  r3| j                         r| j                  d       n| j                  d       	 | j
                  j                  j                  | j                         y # t        $ r}| j                  |d d d d        Y d }~y d }~ww xY w)NzThe current statement is being autocommitted using implicit autocommit, which will be removed in SQLAlchemy 2.0. Use the .begin() method of Engine or Connection in order to use an explicit transaction for DML and DDL statements.zRCOMMIT using DBAPI connection.commit(), DBAPI should ignore due to autocommit modeCOMMIT)r   r   r   r   r   r   r   commitr   rD   r   	do_commitr&   ry   rz   )r%   
autocommitr|   s      r+   _commit_implzConnection._commit_impl*  s    %%%% d;;=##J t{{66MM  &::,,.A
 x(	DKK))$//: 	D((D$dCC	Ds   3/C# #	D,DDc                 P   | j                   rJ | j                  s| j                  j                  r| j                  j	                  | |       |$| xj
                  dz  c_        d| j
                  z  }| j                  r(| j                  j                  j                  | |       |S y )Nr   zsa_savepoint_%s)	r   r   r   r   	savepointr   r   r   do_savepointr%   rQ   s     r+   _savepoint_implzConnection._savepoint_implJ  s    %%%%t{{66MM##D$/<  A% $t';';;D99KK,,T48K :r-   c                    | j                   rJ | j                  s| j                  j                  r| j                  j	                  | |d        | j
                  r'| j                  j                  j                  | |       y y r_   )r   r   r   r   rollback_savepointr   r   do_rollback_to_savepointr   s     r+   _rollback_to_savepoint_implz&Connection._rollback_to_savepoint_implW  sd    %%%%t{{66MM,,T4>99KK88tD :r-   c                    | j                   rJ | j                  s| j                  j                  r| j                  j	                  | |d        | j
                  r'| j                  j                  j                  | |       y y r_   )r   r   r   r   release_savepointr   r   do_release_savepointr   s     r+   _release_savepoint_implz"Connection._release_savepoint_impl`  sd    %%%%t{{66MM++D$=99KK44T4@ :r-   c                    | j                   rJ | j                  r| j                  d       | j                  s| j                  j                  r&| j
                  j                  | |j                         | j                  r@d| _	        	 | j                  j                  j                  | |j                         d| _	        y y # t        $ r}| j                  |d d d d        Y d }~,d }~ww xY w# d| _	        w xY w)NzBEGIN TWOPHASE (implicit)TF)r   r   rD   r   r   r   r   r   r   r    r   do_begin_twophasery   rz   r   s      r+   _begin_twophase_implzConnection._begin_twophase_impli  s    %%%%::NN67t{{66MM(({?99"DO(##55dKOOL #( : ! H,,QdD$GGH #(s*   0C 	C)
C$C, $C))C, ,	C5c                    | j                   rJ | j                  s| j                  j                  r| j                  j	                  | |       | j
                  rDt        | j                  t              sJ 	 | j                  j                  j                  | |       y y # t        $ r}| j                  |d d d d        Y d }~y d }~ww xY wr_   )r   r   r   r   prepare_twophaser   
isinstancer   r   r   do_prepare_twophasery   rz   )r%   r   r|   s      r+   _prepare_twophase_implz!Connection._prepare_twophase_implz  s    %%%%t{{66MM**4599d//1DEEEH##77cB : ! H,,QdD$GGHs   6&B 	C'CCc                    | j                   rJ | j                  s| j                  j                  r| j                  j	                  | ||       | j
                  rEt        | j                  t              sJ 	 | j                  j                  j                  | ||       y y # t        $ r}| j                  |d d d d        Y d }~y d }~ww xY wr_   )r   r   r   r   rollback_twophaser   r   r   r   r   r   ry   rz   r%   r   is_preparedr|   s       r+   _rollback_twophase_implz"Connection._rollback_twophase_impl  s    %%%%t{{66MM++D#{C99d//1DEEEH##88#{ : ! H,,QdD$GGH   7'B   	C)CCc                    | j                   rJ | j                  s| j                  j                  r| j                  j	                  | ||       | j
                  rEt        | j                  t              sJ 	 | j                  j                  j                  | ||       y y # t        $ r}| j                  |d d d d        Y d }~y d }~ww xY wr_   )r   r   r   r   commit_twophaser   r   r   r   r   r   ry   rz   r   s       r+   _commit_twophase_implz Connection._commit_twophase_impl  s    %%%%t{{66MM))$[A99d//1DEEEH##66tS+N : ! H,,QdD$GGHr   c                     | j                   r| j                   j                          | j                         s| j                          y y r_   )r   _autorollbackr   r   rK   s    r+   r   zConnection._autorollback  s:    ,,.""$! %r-   c                 .    t        j                  d       y )Na	  The connection.execute() method in SQLAlchemy 2.0 will accept parameters as a single dictionary or a single sequence of dictionaries only. Parameters passed as keyword arguments, tuples or positionally oriented dictionaries and/or tuples will no longer be accepted.)r   r   rK   s    r+   _warn_for_legacy_exec_formatz'Connection._warn_for_legacy_exec_format  s    *	
r-   c                 l   | j                   r2| j                  rJ t        j                  d       d| _        d| _        y| j                  r| j                  j                          d}nd}| j                  8| j                  }|r|j                  d       n|j                          d| _        d| _        y)af  Close this :class:`_engine.Connection`.

        This results in a release of the underlying database
        resources, that is, the DBAPI connection referenced
        internally. The DBAPI connection is typically restored
        back to the connection-holding :class:`_pool.Pool` referenced
        by the :class:`_engine.Engine` that produced this
        :class:`_engine.Connection`. Any transactional state present on
        the DBAPI connection is also unconditionally released via
        the DBAPI connection's ``rollback()`` method, regardless
        of any :class:`.Transaction` object that may be
        outstanding with regards to this :class:`_engine.Connection`.

        After :meth:`_engine.Connection.close` is called, the
        :class:`_engine.Connection` is permanently in a closed state,
        and will allow no further operations.

        zThe .close() method on a so-called 'branched' connection is deprecated as of 1.4, as are 'branched' connections overall, and will be removed in a future release.  If this is a default-handling function, don't close the connection.NFT)transaction_reset)	r   rW   r   r   r   r!   r   rb   _close_special)r%   
skip_resetconns      r+   rb   zConnection.close  s    ( &&##I &*D"#(D ##%JJ!!-))D ##d#;

 &*D"$r-   c                 J     | j                   |g|i |j                         S )zExecutes and returns the first column of the first row.

        The underlying result/cursor is closed after execution.

        executescalarr%   object_multiparamsparamss       r+   r   zConnection.scalar  s(     t||G<k<V<CCEEr-   c                 J     | j                   |g|i |j                         S )a  Executes and returns a scalar result set, which yields scalar values
        from the first column of each row.

        This method is equivalent to calling :meth:`_engine.Connection.execute`
        to receive a :class:`_result.Result` object, then invoking the
        :meth:`_result.Result.scalars` method to produce a
        :class:`_result.ScalarResult` instance.

        :return: a :class:`_result.ScalarResult`

        .. versionadded:: 1.4.24

        )r   scalarsr   s       r+   r  zConnection.scalars  s(     t||G<k<V<DDFFr-   c                 L   t        |t        j                        r/t        j                  d       | j	                  |||t
        d      S 	 |j                  } || ||t
              S # t        $ r4}t        j                  t        j                  |      |       Y d}~yd}~ww xY w)aY  Executes a SQL statement construct and returns a
        :class:`_engine.CursorResult`.

        :param statement: The statement to be executed.  May be
         one of:

         * a plain string (deprecated)
         * any :class:`_expression.ClauseElement` construct that is also
           a subclass of :class:`.Executable`, such as a
           :func:`_expression.select` construct
         * a :class:`.FunctionElement`, such as that generated
           by :data:`.func`, will be automatically wrapped in
           a SELECT statement, which is then executed.
         * a :class:`.DDLElement` object
         * a :class:`.DefaultGenerator` object
         * a :class:`.Compiled` object

         .. deprecated:: 2.0 passing a string to
            :meth:`_engine.Connection.execute` is
            deprecated and will be removed in version 2.0.  Use the
            :func:`_expression.text` construct with
            :meth:`_engine.Connection.execute`, or the
            :meth:`_engine.Connection.exec_driver_sql`
            method to invoke a driver-level
            SQL string.

        :param \*multiparams/\**params: represent bound parameter
         values to be used in the execution.   Typically,
         the format is either a collection of one or more
         dictionaries passed to \*multiparams::

             conn.execute(
                 table.insert(),
                 {"id":1, "value":"v1"},
                 {"id":2, "value":"v2"}
             )

         ...or individual key/values interpreted by \**params::

             conn.execute(
                 table.insert(), id=1, value="v1"
             )

         In the case that a plain SQL string is passed, and the underlying
         DBAPI accepts positional bind parameters, a collection of tuples
         or individual values in \*multiparams may be passed::

             conn.execute(
                 "INSERT INTO table (id, value) VALUES (?, ?)",
                 (1, "v1"), (2, "v2")
             )

             conn.execute(
                 "INSERT INTO table (id, value) VALUES (?, ?)",
                 1, "v1"
             )

         Note above, the usage of a question mark "?" or other
         symbol is contingent upon the "paramstyle" accepted by the DBAPI
         in use, which may be any of "qmark", "named", "pyformat", "format",
         "numeric".   See `pep-249
         <https://www.python.org/dev/peps/pep-0249/>`_ for details on
         paramstyle.

         To execute a textual SQL statement which uses bound parameters in a
         DBAPI-agnostic way, use the :func:`_expression.text` construct.

         .. deprecated:: 2.0 use of tuple or scalar positional parameters
            is deprecated. All params should be dicts or sequences of dicts.
            Use :meth:`.exec_driver_sql` to execute a plain string with
            tuple or scalar positional parameters.

        zPassing a string to Connection.execute() is deprecated and will be removed in version 2.0.  Use the text() construct, or the Connection.exec_driver_sql() method to invoke a driver-level SQL string.Ffuturereplace_contextN)r   r   string_typesr   _exec_driver_sql_EMPTY_EXECUTION_OPTS_execute_on_connectionAttributeErrorraise_r   ObjectNotExecutableError)r%   	statementr   r  metherrs         r+   r   zConnection.execute  s    V i!2!23##+ ((% )  	J33D k63HII  	KK,,Y7 	s   A& &	B#/*BB#c                 F    | j                  |j                         |||      S )z%Execute a sql.FunctionElement object.)_execute_clauseelementselect)r%   funcr   r  rm   s        r+   _execute_functionzConnection._execute_functionk  s'     **KKM;0A
 	
r-   c                    | j                   j                  |      }t        | ||      }| j                  s| j                  j                  r| j                  |||      \  }}}}	 | j                  }	|	| j                         }	| j                  }
|
j                  j                  |
| |	|      }j!                  d|d      }| j"                  r| j%                          | j                  s| j                  j                  r | j&                  j)                  | |||       |S # t        j                  t        j                  f$ r  t        $ r}| j                  |dddd       Y d}~d}~ww xY w)z&Execute a schema.ColumnDefault object.N)r   
merge_withr   r   r   _invoke_before_exec_eventr   rv   r   execution_ctx_cls_init_defaultr   rw   rx   ry   rz   _exec_defaultr   rb   r   after_execute)r%   defaultr   r  rm   distilled_parametersdistilled_paramsevent_multiparamsevent_paramsr   r   ctxr|   rets                 r+   _execute_defaultzConnection._execute_defaultr  sl    !33>>
  /t[&It{{66 ..-/@ !
	D))D|224llG++99t%6C gt4((JJLt{{66MM''!! 
' ((#*A*AB 	 	D((D$dCC	Ds   $AD ,E*E%%E*c                 P   |j                   j                  | j                   |      }t        | ||      }| j                  s| j                  j                  r| j                  |||      \  }}}}| j                   j                  |      }	|	j                  dd      }
| j                  }|j                  ||
      }| j                  ||j                  j                  |d||      }| j                  s| j                  j                  r | j                  j                  | |||       |S )zExecute a schema.DDL object.rI   N)r   rI   )r   r  r   r   r   r  rJ   r   compile_execute_contextr  	_init_ddlr   r  )r%   ddlr   r  rm   r   r!  r"  r#  	exec_optsrI   r   compiledr%  s                 r+   _execute_ddlzConnection._execute_ddl  s6     22==##%6
  /t[&It{{66 ..)+< !
 ++667HI	(}}-CTJ,,;;2F  
 ##%%//
 t{{66MM''!! 
r-   c                     t        |      dk(  rg |d   }}n|i }}| j                  j                  D ]  } || ||||      \  }}} |r"t        |      }|rt	        j
                  d      |r|g}ng }||||fS )Nr   r   zLEvent handler can't return non-empty multiparams and params at the same time)lenr   before_executelistr   r   )r%   elemr!  rm   r"  r#  fns          r+   r  z$Connection._invoke_before_exec_event  s      A%.02B12E|.>|--.. 	B46!!51D#\	 #$56--2   ,~!%'8,FFr-   c                    |j                   j                  | j                   |      }t        | ||      }| j                  xs | j                  j                  }|r| j                  |||      \  }}}}|rt        |d         }	t        |      dkD  }
ng }	d}
| j                  }|j                  dd      }|j                  d| j                  j                        }|j                  |||	|
|| j                  j                  t        j                  z        \  }}}| j                  ||j                   j"                  ||||||||
      }|r | j$                  j'                  | |||       |S )	z#Execute a sql.ClauseElement object.r   r   FrI   Ncompiled_cache)r   r6  column_keysfor_executemanyrI   linting)	cache_hit)r   r  r   r   r   r  sortedr0  r   rJ   _compiled_cache_compile_w_cachecompiler_lintingr   WARN_LINTINGr)  r  _init_compiledr   r  )r%   r3  r   r  rm   r!  
has_eventsr"  r#  keysr8  r   rI   r6  compiled_sqlextracted_paramsr:  r%  s                     r+   r  z!Connection._execute_clauseelement  s   
 !33>>##%6
 +4fE%%@)@)@
 ..&(9 !
  *1-.D!"23a7OD#O,,044"D 
 +..dkk99
 594I4I)+!5LL11H4I4II 5J 5
1&	 ##%%44 $ 
 MM''!! 
r-   c                    |j                   j                  | j                  |      }t        | ||      }| j                  s| j
                  j                  r| j                  |||      \  }}}}| j                  }	| j                  |	|	j                  j                  |||||dd	      }
| j                  s| j
                  j                  r | j                  j                  | |||
       |
S )ziExecute a sql.Compiled object.

        TODO: why do we have this?   likely deprecate or remove

        N)rm   r  r   r   r   r   r  r   r)  r  r@  r   r  )r%   r-  r   r  rm   r   r!  r"  r#  r   r%  s              r+   _execute_compiledzConnection._execute_compiled@  s     %66AA##%6
  /t[&It{{66 ...0A !
 ,,##%%44  

 t{{66MM''!! 
r-   c           	         | j                   j                  |      }t        | ||      }|s:| j                  s| j                  j                  r| j                  |||      \  }}}}	| j                  }
| j                  |
|
j                  j                  |||||      }|sB| j                  s| j                  j                  r | j                  j                  | |	||       |S r_   )r   r  r   r   r   r  r   r)  r  _init_statementr   r  )r%   r  r   r  rm   r  r   r!  r"  r#  r   r%  s               r+   r
  zConnection._exec_driver_sqlt  s     !33>>
  /t[&I4;;#:#: 2235F$% 
 ,,##%%55  
 4;;#:#:++% % 
r-   c                     t        |      \  }}	 |j                  } || |||      S # t        $ r4}t        j                  t        j                  |      |       Y d }~y d }~ww xY w)Nr  )r   r  r  r   r  r   r  )r%   r  
parametersrm   args_10stylekwargs_10styler  r  s           r+   _execute_20zConnection._execute_20  sk     (:*'E$n	O33D lN<MNN  	KK,,Y7 	s   ' 	A$*AA$c                 J    t        |      \  }}| j                  ||||d      S )aW  Executes a string SQL statement on the DBAPI cursor directly,
        without any SQL compilation steps.

        This can be used to pass any string directly to the
        ``cursor.execute()`` method of the DBAPI in use.

        :param statement: The statement str to be executed.   Bound parameters
         must use the underlying DBAPI's paramstyle, such as "qmark",
         "pyformat", "format", etc.

        :param parameters: represent bound parameter values to be used in the
         execution.  The format is one of:   a dictionary of named parameters,
         a tuple of positional parameters, or a list containing either
         dictionaries or tuples for multiple-execute support.

        :return: a :class:`_engine.CursorResult`.

         E.g. multiple dictionaries::


             conn.exec_driver_sql(
                 "INSERT INTO table (id, value) VALUES (%(id)s, %(value)s)",
                 [{"id":1, "value":"v1"}, {"id":2, "value":"v2"}]
             )

         Single dictionary::

             conn.exec_driver_sql(
                 "INSERT INTO table (id, value) VALUES (%(id)s, %(value)s)",
                 dict(id=1, value="v1")
             )

         Single tuple::

             conn.exec_driver_sql(
                 "INSERT INTO table (id, value) VALUES (?, ?)",
                 (1, 'v1')
             )

         .. note:: The :meth:`_engine.Connection.exec_driver_sql` method does
             not participate in the
             :meth:`_events.ConnectionEvents.before_execute` and
             :meth:`_events.ConnectionEvents.after_execute` events.   To
             intercept calls to :meth:`_engine.Connection.exec_driver_sql`, use
             :meth:`_events.ConnectionEvents.before_cursor_execute` and
             :meth:`_events.ConnectionEvents.after_cursor_execute`.

         .. seealso::

            :pep:`249`

        Tr  )r   r
  )r%   r  rJ  rm   rK  rL  s         r+   exec_driver_sqlzConnection.exec_driver_sql  s;    p (:*'E$n$$ % 
 	
r-   c           	      `
   | }| j                   r| j                   } |r(|j                  dd      }	|	r|j                  d|	d      }	 | j                  }
|
| j	                         }
 ||| |
|g|i |}| j                  r| j                  j                  r"| j                  r'| j                  j                  s| j                          n!| j                   rt#        j$                  |        | j&                  r| j                  | j)                          j+                          |j,                  r|j/                          |j0                  |j2                  |j4                  }}}|j6                  s|d   }| j8                  s| j:                  j8                  r5| j<                  j>                  D ]  } || |||||j6                        \  }} | j@                  r| jC                  |       |jE                         }| j:                  jF                  s4| jC                  d|tI        jJ                  |d|j6                               n| jC                  d	|d
       d}	 |j6                  rl| jL                  j8                  r4| jL                  j<                  jN                  D ]  } |||||      sd} n |s | jL                  jO                  ||||       n|su|jP                  ri| jL                  j8                  r3| jL                  j<                  jR                  D ]  } ||||      sd} n |s| jL                  jS                  |||       nj| jL                  j8                  r4| jL                  j<                  jT                  D ]  } |||||      sd} n |s| jL                  jU                  ||||       | j8                  s| j:                  j8                  r*| j<                  jW                  | |||||j6                         |jY                          |j[                         }| j&                  sw|j\                  }|j^                  s	|rd|_0        | j                  |jb                  r| je                  d       |r*|j^                  r| j&                  rJ |jg                          |S # t
        j                  t
        j                  f$ r  t        $ r3}| j                  |t        j                  |      |dd       Y d}~d}~ww xY w# t        $ r }| j                  |||||       Y d}~S d}~ww xY w)zdCreate an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.CursorResult`.	yield_perNT)stream_resultsmax_row_bufferr   z[%s] %r
   )batchesismultir1   z5] [SQL parameters hidden due to hide_parameters=True]F)r   )4r   rJ   rj   r   rv   r   rw   rx   ry   rz   r   	text_typer   r   r   r   _trans_context_managerr	   _trans_ctx_checkrW   r   pre_execuse_setinputsizes_set_input_sizescursorr  rJ  executemanyr   r   r   before_cursor_executer   rD   _get_cache_statshide_parameterssql_util_repr_paramsr   do_executemanyno_parametersdo_execute_no_params
do_executeafter_cursor_execute	post_exec_setup_result_proxyr   _soft_closed_autoclose_connectionshould_autocommitr   rb   )r%   r   constructorr  rJ  rm   argsrB   branchedypr   contextr|   r]  r4  statsevt_handledresultr   s                      r+   r)  zConnection._execute_context  s     %%D"&&{D9B$5$;$;'+rB%!	))D|224!t%69=ACG %%//((00:: %%'(( 11$7??t008OO$$$$& NN &	 ""#AJt{{66mm99 (*'')%	: ::NN9%,,.E;;..))"B8K8K 
 I	""<<++"ll33BB "fiWE*.K!" #LL//	:w  G$9$9<<++"ll33HH "fi9*.K!" #LL55	7 <<++"ll33>> "fiWE*.K!" #LL++	:w 4;;#:#:22'' 002F??+3+L+L(**/G37F0
 %%-11%%%6
 ,0D0D#.. NN$ a ((#*A*AB 	 	((4>>),j$ 	R  	((9j&'  	sF   -R" AT )A8T "A)T DT ",T(S<<T	T-T((T-c           	         | j                   s| j                  j                   r+| j                  j                  D ]  } || ||||d      \  }} | j                  r#| j                  |       | j                  d|       	 | j                  j                   sdn| j                  j                  j                  D ]  } |||||      s n | j                  j                  ||||       | j                   s| j                  j                   r!| j                  j                  | ||||d       yy# t        $ r}| j                  |||||       Y d}~gd}~ww xY w)a_  Execute a statement + params on the given cursor.

        Adds appropriate logging and exception handling.

        This method is used by DefaultDialect for special-case
        executions, such as for sequences and column defaults.
        The path of statement execution in the majority of cases
        terminates at _execute_context().

        Fz[raw sql] %rr2   N)r   r   r   r_  r   rD   r   rg  ry   rz   rh  )r%   r]  r  rJ  rr  r4  r|   s          r+   _cursor_executezConnection._cursor_execute  sC    t{{66mm99 (*&)Z%)%	:
 ::NN9%NN>:6	 ||// \\**55P
 fiW=P ''	:wO t{{66MM..fiWe  7  	((9j&' 	s   >AD* !D* *	E3EEc                     	 |j                          y# t        $ r4 | j                  j                  j                  j                  dd       Y yw xY w)z\Close the given cursor, catching exceptions
        and turning into log warnings.

        zError closing cursorT)exc_infoN)rb   	Exceptionr   poolr=   error)r%   r]  s     r+   _safe_close_cursorzConnection._safe_close_cursor  sG    
	LLN 	KK##))& * 	s    :AAc                 	   t        j                         }t        j                  |      }| j                  st        || j                  j                  j                        xrD | j                   xr5 | j                  j                  || j                  s| j                  nd |      xs |xr | j                   | _        | }| j                  rt        j                  t        j                   j#                  |||| j                  j                  j                  | j$                  j&                  | j                  ||j(                  nd       |d   |       d| _        	 t        || j                  j                  j                        xs |d uxr	 |d u xr | }	|	r|t        j                   j#                  |||| j                  j                  j                  | j$                  j&                  | j                  | j                  ||j(                  nd       }
nd }
d }| j*                  s| j$                  j*                  r| j,                  j/                  dd      st1        ||
| j$                  | ||||| j                  |
      }| j2                  j4                  D ]  }	  ||      }|	|x|_        } | j                  |j                  k7  r$|j                  | _        |
r|j                  |
_        |j<                  }|	r|r|j?                  |       | j                  sB|r| jA                  |       t        jB                  d      5  | jE                          d d d        |rt        j                  ||d   |       n;|	rt        j                  |
|d   |       nt        j                  |d	   |d   
       | `| j                  rS| `| j                  sE| j                  }|r&| j$                  jF                  jI                  ||       | jK                  |       | jL                  r| jN                  rJ | jQ                          y y # t8        $ r}|}Y d }~ d }~ww xY w# 1 sw Y   
xY w# | `| j                  rS| `| j                  sE| j                  }|r&| j$                  jF                  jI                  ||       | jK                  |       | jL                  r| jN                  rJ | jQ                          w w xY w)N)ra  r   rV  r
   with_tracebackfrom_T)ra  connection_invalidatedr   rV  skip_user_error_eventsF)	warn_onlyr   r  ))sysry  r   is_exit_exception_is_disconnectr   r   dbapiErrorrr   is_disconnectrt   r   _reentrant_errorr  r   
DBAPIErrorinstancer   ra  r^  r   r   rJ   ExceptionContextImplr   handle_errorchained_exceptionrz  r  invalidate_pool_on_disconnecthandle_dbapi_exceptionr}  safe_reraiser   r{  _invalidater   r   rW   rb   )r%   r|   r  rJ  r]  rr  ry  r  r  should_wrapsqlalchemy_exceptionnewraiser$  r4  per_fn_raiseddbapi_conn_wrappers                    r+   rz   z"Connection._handle_dbapi_exception  s    <<> 2215""1dll00667 OLL..262B2BD**#9 $7DKK  ->(=%  KK''LL&&,,$(KK$?$? LL* $// ( 
  ({ !%c	 %Q(:(:(@(@A % *tO*))  '*~~'>'>LL&&,,$(KK$?$?+/+>+> LL* $// (? ($ (,$H   DKK$;$;--11(% +(KK''1 --44 
B	 "$C!-?EEC1H
 &&#*;*;;*-*;*;D'+-- -C 55 . w..q1&&++F3&&6 )&&() HXa[J(!A HQKD %""''')-)?)?&4((445GKOOA&,,??**

 -[ % #*0) ) %""''')-)?)?&4((445GKOOA&,,??**

 -sR   D<Q) Q.BQ) QA!Q) 	QQQ) QQ) Q&!Q) )BS7c                    t        j                         }|j                  |d d       }t        ||j                  j
                        }|rDt        j                  j                  d d ||j                  j
                  |j                  |      }nd }d }|j                  rgt        |||d d d d d |d
      }	|j                  j                  D ]  }
	  |
|	      }|	|x|	_        } |r"||	j                  k7  r|	j                  x|_        }|rt#        j$                  ||d   |       y |rt#        j$                  ||d   |       y t#        j$                  |d   |d          y # t        $ r}|}Y d }~ d }~ww xY w)N)ra  r  Tr
   r  r   r  )r  ry  r  r   r  r  r   r  r  ra  r   r  r   r  r  rz  r  r   r  )clsr|   r   r   ry  r  r  r  r  r$  r4  r  r  s                r+   $_handle_dbapi_exception_noconnectionz/Connection._handle_dbapi_exception_noconnectioni  s   <<>--at< GMM$7$78#&>>#:#:## & 6 6'4 $; $  $( &$C oo22 
	  WF);AA-
 $9J9J(J %%&$;! KK!AFKK$Xa[ KKHQK@# ! &Hs   E	E5(E00E5c                 J     || j                   | fi |j                  |       y)zrun a DDL visitor.

        This method is only here so that the MockConnection can change the
        options given to the visitor so that "checkfirst" is skipped.

        N)r   traverse_single)r%   visitorcallableelementkwargss       r+   _run_ddl_visitorzConnection._run_ddl_visitor  s"     	d5f5EEgNr-   1.4zThe :meth:`_engine.Connection.transaction` method is deprecated and will be removed in a future release.  Use the :meth:`_engine.Engine.begin` context manager instead.c                     d|d<   | j                         }	  | j                  |g|i |}|j                          |S #  t        j                         5  |j                          ddd       Y y# 1 sw Y   Y yxY wxY w)at  Execute the given function within a transaction boundary.

        The function is passed this :class:`_engine.Connection`
        as the first argument, followed by the given \*args and \**kwargs,
        e.g.::

            def do_something(conn, x, y):
                conn.execute(text("some statement"), {'x':x, 'y':y})

            conn.transaction(do_something, 5, 10)

        The operations inside the function are all invoked within the
        context of a single :class:`.Transaction`.
        Upon success, the transaction is committed.  If an
        exception is raised, the transaction is rolled back
        before propagating the exception.

        .. note::

           The :meth:`.transaction` method is superseded by
           the usage of the Python ``with:`` statement, which can
           be used with :meth:`_engine.Connection.begin`::

               with conn.begin():
                   conn.execute(text("some statement"), {'x':5, 'y':10})

           As well as with :meth:`_engine.Engine.begin`::

               with engine.begin() as conn:
                   conn.execute(text("some statement"), {'x':5, 'y':10})

        .. seealso::

            :meth:`_engine.Engine.begin` - engine-level transactional
            context

            :meth:`_engine.Engine.transaction` - engine-level version of
            :meth:`_engine.Connection.transaction`

        T_sa_skip_warningN)r   run_callabler   r   r  r   )r%   	callable_ro  r  transr%  s         r+   r   zConnection.transaction  s{    b &*!"

	!#$##I???CLLNJ	!""$ ! ! ! !s'   '? A=A0&A=0A:	5A=:A=zThe :meth:`_engine.Connection.run_callable` method is deprecated and will be removed in a future release.  Invoke the callable function directly, passing the Connection.c                      || g|i |S )a  Given a callable object or function, execute it, passing
        a :class:`_engine.Connection` as the first argument.

        The given \*args and \**kwargs are passed subsequent
        to the :class:`_engine.Connection` argument.

        This function, along with :meth:`_engine.Engine.run_callable`,
        allows a function to be run with a :class:`_engine.Connection`
        or :class:`_engine.Engine` object without the need to know
        which one is being dealt with.

        r2   )r%   r  ro  r  s       r+   r  zConnection.run_callable  s    ( ////r-   )NFNNNNTFr_   NN)U__name__
__module____qualname____doc__rW   _sqla_logger_namespacerX  r,   r   memoized_propertyr7   rD   rG   propertyrL   rR   rU   r]   r`   rg   rm   ro   rr   rt   r&   r~   r   r   rv   r   r>   deprecated_20r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rb   r   r  r   r  r  r&  r.  r  r  rF  r
  rM  rO  r)  rw  r}  r  r  rz   classmethodr  r  
deprecatedr   r  r2   r-   r+   r   r       s   8 J; "
 5In 
 	5	6 I I(
:BH	' K K B B" * *2*DX 4 4<2
C 
 

 $ $ T56 79&v(8K/ZC'J.@=MKM
	

!
($0H(D@EA("HHH"	
5%nFG"cJJ
 06p,\G@FZ 02h*^ /	O" =A@
Dsj&P NHT :A :AxO T__	#2!2!h T__	,00r-   r   c                       e Zd ZdZd Zy)r  z3Implement the :class:`.ExceptionContext` interface.c                     || _         || _        || _        || _        || _        || _        || _        |	| _        |
| _        y r_   )	r   r&   r  original_exceptionexecution_contextr  rJ  r  r  )r%   r   r  r   r&   r]  r  rJ  rr  r  r  s              r+   r,   zExceptionContextImpl.__init__	  sH     $$8!"+!("$*-J*r-   N)r  r  r  r  r,   r2   r-   r+   r  r  	  s    =Kr-   r  c                       e Zd ZdZdZdZd Zd Zed        Z	d Z
d Zd	 Zed
        Zd Zd Zd Zd Zd Zd Zd Zy)Transactionat  Represent a database transaction in progress.

    The :class:`.Transaction` object is procured by
    calling the :meth:`_engine.Connection.begin` method of
    :class:`_engine.Connection`::

        from sqlalchemy import create_engine
        engine = create_engine("postgresql://scott:tiger@localhost/test")
        connection = engine.connect()
        trans = connection.begin()
        connection.execute(text("insert into x (a, b) values (1, 2)"))
        trans.commit()

    The object provides :meth:`.rollback` and :meth:`.commit`
    methods in order to control transaction boundaries.  It
    also implements a context manager interface so that
    the Python ``with`` statement can be used with the
    :meth:`_engine.Connection.begin` method::

        with connection.begin():
            connection.execute(text("insert into x (a, b) values (1, 2)"))

    The Transaction object is **not** threadsafe.

    .. seealso::

        :meth:`_engine.Connection.begin`

        :meth:`_engine.Connection.begin_twophase`

        :meth:`_engine.Connection.begin_nested`

    .. index::
      single: thread safety; Transaction
    r2   Fc                     t               r_   NotImplementedErrorr%   r&   s     r+   r,   zTransaction.__init__E	      !##r-   c                     t               )a  do whatever steps are necessary to set this transaction as
        "deactive", however leave this transaction object in place as far
        as the connection's state.

        for a "real" transaction this should roll back the transaction
        and ensure this transaction is no longer a reset agent.

        this is used for nesting of marker transactions where the marker
        can set the "real" transaction as rolled back, however it stays
        in place.

        for 2.0 we hope to remove this nesting feature.

        r  rK   s    r+   _do_deactivatezTransaction._do_deactivateH	  s     "##r-   c                     t               )zTrue if this transaction is totally deactivated from the connection
        and therefore can no longer affect its state.

        r  rK   s    r+   _deactivated_from_connectionz(Transaction._deactivated_from_connectionY	  s     "##r-   c                     t               r_   r  rK   s    r+   	_do_closezTransaction._do_closea	  r  r-   c                     t               r_   r  rK   s    r+   _do_rollbackzTransaction._do_rollbackd	  r  r-   c                     t               r_   r  rK   s    r+   
_do_commitzTransaction._do_commitg	  r  r-   c                 L    | j                   xr | j                  j                   S r_   )r   r&   rt   rK   s    r+   r   zTransaction.is_validj	  s    ~~Adoo&A&A"AAr-   c                 h    	 | j                          | j                  rJ y# | j                  rJ w xY w)a;  Close this :class:`.Transaction`.

        If this transaction is the base transaction in a begin/commit
        nesting, the transaction will rollback().  Otherwise, the
        method returns.

        This is used to cancel a Transaction without affecting the scope of
        an enclosing transaction.

        N)r  r   rK   s    r+   rb   zTransaction.closen	  s0    	&NN~~%%~t~~%%~   ! 1c                 h    	 | j                          | j                  rJ y# | j                  rJ w xY w)a  Roll back this :class:`.Transaction`.

        The implementation of this may vary based on the type of transaction in
        use:

        * For a simple database transaction (e.g. :class:`.RootTransaction`),
          it corresponds to a ROLLBACK.

        * For a :class:`.NestedTransaction`, it corresponds to a
          "ROLLBACK TO SAVEPOINT" operation.

        * For a :class:`.TwoPhaseTransaction`, DBAPI-specific methods for two
          phase transactions may be used.


        N)r  r   rK   s    r+   r   zTransaction.rollback~	  s2    "	&~~%%~t~~%%~r  c                 h    	 | j                          | j                  rJ y# | j                  rJ w xY w)a  Commit this :class:`.Transaction`.

        The implementation of this may vary based on the type of transaction in
        use:

        * For a simple database transaction (e.g. :class:`.RootTransaction`),
          it corresponds to a COMMIT.

        * For a :class:`.NestedTransaction`, it corresponds to a
          "RELEASE SAVEPOINT" operation.

        * For a :class:`.TwoPhaseTransaction`, DBAPI-specific methods for two
          phase transactions may be used.

        N)r  r   rK   s    r+   r   zTransaction.commit	  s0     	&OO~~%%~t~~%%~r  c                     | j                   S r_   )r&   rK   s    r+   _get_subjectzTransaction._get_subject	  s    r-   c                     | j                   S r_   r   rK   s    r+   _transaction_is_activez"Transaction._transaction_is_active	  s    ~~r-   c                     | j                    S r_   )r  rK   s    r+   _transaction_is_closedz"Transaction._transaction_is_closed	  s    4444r-   c                      yNTr2   rK   s    r+   _rollback_can_be_calledz#Transaction._rollback_can_be_called	  s    
 r-   N)r  r  r  r  	__slots___is_rootr,   r  r  r  r  r  r  r   rb   r   r   r  r  r  r  r2   r-   r+   r  r  	  sz    "H IH$$" $ $$$$ B B& &,&*5r-   r  c                   R    e Zd ZdZdZd Zed        Zed        Zd Z	d Z
d Zd	 Zy
)r   zA 'marker' transaction that is used for nested begin() calls.

    .. deprecated:: 1.4 future connection for 2.0 won't support this pattern.

    )r&   
_is_activer   c                    |j                   J |j                   j                  st        j                  d      |j                  rJ t        j                  d       || _        |j                  rt        j                  |       |j                  |j                  | _         d| _        y |j                   | _         d| _        y )NzWthe current transaction on this connection is inactive.  Please issue a rollback first.zCalling .begin() when a transaction is already begun, creating a 'sub' transaction, is deprecated and will be removed in 2.0.  See the documentation section 'Migrating from the nesting pattern' for background on how to migrate from this pattern.T)r   r   r   r   rW   r   r   r&   rX  r	   rY  r   r  r  s     r+   r,   zMarkerTransaction.__init__	  s    &&222&&00))1 
 ((((,	
 %,, 11*=))5 * > >D  !+ 7 7Dr-   c                     | j                    S r_   r  rK   s    r+   r  z.MarkerTransaction._deactivated_from_connection	  s    >>!!r-   c                 J    | j                   xr | j                  j                  S r_   )r  r   r   rK   s    r+   r   zMarkerTransaction.is_active	  s    >4#4#4#>#>>r-   c                     d| _         y NF)r  rK   s    r+   _deactivatezMarkerTransaction._deactivate	  s	    r-   c                 $    | j                          y r_   r  rK   s    r+   r  zMarkerTransaction._do_close	  s    r-   c                     | j                   r,	 | j                  j                          | j                          y y # | j                          w xY wr_   )r  r   r  r  rK   s    r+   r  zMarkerTransaction._do_rollback	  sA    ??#!!002  "	    "s	   : Ac                 $    | j                          y r_   r  rK   s    r+   r  zMarkerTransaction._do_commit	      r-   N)r  r  r  r  r  r,   r  r  r   r  r  r  r  r2   r-   r+   r   r   	  sO     =I8 " " ? ? #r-   r   c                   f    e Zd ZdZdZdZd Zd Zed        Z	d Z
d Zd	 Zd
 ZddZd Zd Zd Zy)r   a  Represent the "root" transaction on a :class:`_engine.Connection`.

    This corresponds to the current "BEGIN/COMMIT/ROLLBACK" that's occurring
    for the :class:`_engine.Connection`. The :class:`_engine.RootTransaction`
    is created by calling upon the :meth:`_engine.Connection.begin` method, and
    remains associated with the :class:`_engine.Connection` throughout its
    active span. The current :class:`_engine.RootTransaction` in use is
    accessible via the :attr:`_engine.Connection.get_transaction` method of
    :class:`_engine.Connection`.

    In :term:`2.0 style` use, the :class:`_future.Connection` also employs
    "autobegin" behavior that will create a new
    :class:`_engine.RootTransaction` whenever a connection in a
    non-transactional state is used to emit commands on the DBAPI connection.
    The scope of the :class:`_engine.RootTransaction` in 2.0 style
    use can be controlled using the :meth:`_future.Connection.commit` and
    :meth:`_future.Connection.rollback` methods.


    T)r&   r   c                     |j                   J |j                  rt        j                  |       || _        | j                          | |_         d| _        y r  )r   rX  r	   rY  r&   _connection_begin_implr   r  s     r+   r,   zRootTransaction.__init__
  sM    &&...,, 11*=$##%"&
r-   c                     | j                   r"| j                  j                  | u sJ d| _         y | j                  j                  | urt        j                  d       y y )NFz0transaction already deassociated from connection)r   r&   r   r   warnrK   s    r+   _deactivate_from_connectionz+RootTransaction._deactivate_from_connection
  sL    >>??//4777"DN__))5IIHI 6r-   c                 2    | j                   j                  | uS r_   )r&   r   rK   s    r+   r  z,RootTransaction._deactivated_from_connection&
  s    ++477r-   c                    | j                   j                  | u sJ | j                  r| j                          | j                   j                  r$| j                   j                  j                          | j                          y r_   )r&   r   r   _connection_rollback_implr   _cancelr  rK   s    r+   r  zRootTransaction._do_deactivate*
  s`     ++t333>>**,
 ??..OO//779((*r-   c                 :    | j                   j                  |        y r_   )r&   r   rK   s    r+   r  z&RootTransaction._connection_begin_impl?
  s    ##D)r-   c                 8    | j                   j                          y r_   )r&   r   rK   s    r+   r  z)RootTransaction._connection_rollback_implB
  s    &&(r-   c                 8    | j                   j                          y r_   )r&   r   rK   s    r+   _connection_commit_implz'RootTransaction._connection_commit_implE
  s    $$&r-   c                 ,   	 | j                   r| j                          | j                  j                  r$| j                  j                  j	                          | j                   s|r| j                          | j                  j                  | u rd | j                  _        	 | j                   rJ | j                  j                  | usJ y # | j                   s|r| j                          | j                  j                  | u rd | j                  _        w w xY wr_   )r   r  r&   r   r  r  r   )r%   try_deactivates     r+   _close_implzRootTransaction._close_implH
  s    
	4~~..02233;;=~~002++t3/3,>>!!++4777 ~~002++t3/3, 4s   AC	 	A
Dc                 $    | j                          y r_   r  rK   s    r+   r  zRootTransaction._do_closeX
  r  r-   c                 (    | j                  d       y )NT)r  r  rK   s    r+   r  zRootTransaction._do_rollback[
  s    -r-   c                    | j                   r| j                  j                  | u sJ 	 | j                          | j                  j                  r$| j                  j                  j                          | j                          d | j                  _        nH| j                  j                  | u r| j                  j                          nt        j                  d      | j                   rJ | j                  j                  | usJ y # | j                  j                  r$| j                  j                  j                          | j                          w xY w)NThis transaction is inactive)
r   r&   r   r  r   r  r  r   r   r   rK   s    r+   r  zRootTransaction._do_commit^
  s    >>??//4777	3,,.
 ??66OO77??A002
 ,0DOO(++t3446--.LMM>>!!++4777! ??66OO77??A002s   D AENr  )r  r  r  r  r  r  r,   r  r  r  r  r  r  r  r  r  r  r  r2   r-   r+   r   r   	  sZ    * H+IJ 8 8+**)'8 .8r-   r   c                   V    e Zd ZdZdZd ZddZed        Zd Z	d Z
d Zd	 Zd
 Zd Zy)r   a  Represent a 'nested', or SAVEPOINT transaction.

    The :class:`.NestedTransaction` object is created by calling the
    :meth:`_engine.Connection.begin_nested` method of
    :class:`_engine.Connection`.

    When using :class:`.NestedTransaction`, the semantics of "begin" /
    "commit" / "rollback" are as follows:

    * the "begin" operation corresponds to the "BEGIN SAVEPOINT" command, where
      the savepoint is given an explicit name that is part of the state
      of this object.

    * The :meth:`.NestedTransaction.commit` method corresponds to a
      "RELEASE SAVEPOINT" operation, using the savepoint identifier associated
      with this :class:`.NestedTransaction`.

    * The :meth:`.NestedTransaction.rollback` method corresponds to a
      "ROLLBACK TO SAVEPOINT" operation, using the savepoint identifier
      associated with this :class:`.NestedTransaction`.

    The rationale for mimicking the semantics of an outer transaction in
    terms of savepoints so that code may deal with a "savepoint" transaction
    and an "outer" transaction in an agnostic way.

    .. seealso::

        :ref:`session_begin_nested` - ORM version of the SAVEPOINT API.

    )r&   r   
_savepoint_previous_nestedc                     |j                   J |j                  rt        j                  |       || _        | j                  j                         | _        d| _        |j                  | _	        | |_        y r  )
r   rX  r	   rY  r&   r   r  r   r   r  r  s     r+   r,   zNestedTransaction.__init__
  sc    &&222,, 11*=$//99; * > >)-
&r-   c                     | j                   j                  | u r| j                  | j                   _        y |rt        j                  d       y y )Nz7nested transaction already deassociated from connection)r&   r   r  r   r  )r%   r  s     r+   r  z-NestedTransaction._deactivate_from_connection
  s=    ??..$6262G2GDOO/III r-   c                 2    | j                   j                  | uS r_   )r&   r   rK   s    r+   r  z.NestedTransaction._deactivated_from_connection
  s    22$>>r-   c                     d| _         | j                          | j                  r| j                  j                          y y r  )r   r  r  r  rK   s    r+   r  zNestedTransaction._cancel
  s7     ((*  !!))+ !r-   c                 x   	 | j                   rE| j                  j                  j                   r%| j                  j                  | j                         d| _         |r| j                  |       	 | j                   rJ |r| j                  j                  | usJ y y # d| _         |r| j                  |       w w xY w)NF)r  )r   r&   r   r   r  r  r   )r%   deactivate_from_connectionwarn_already_deactives      r+   r  zNestedTransaction._close_impl
  s    	M~~$//">">"H"H;;DOOL"DN)006K0L>>!!%??66dBBB & #DN)006K0L *s   AB B9c                 (    | j                  dd       y r  r  rK   s    r+   r  z NestedTransaction._do_deactivate
  s    &r-   c                 (    | j                  dd       y )NTFr  rK   s    r+   r  zNestedTransaction._do_close
  s    u%r-   c                 (    | j                  dd       y r  r  rK   s    r+   r  zNestedTransaction._do_rollback
  s    t$r-   c                 >   | j                   r>	 | j                  j                  | j                         d| _         | j	                          y | j                  j
                  | u r| j                  j                          y t        j                  d      # d| _         w xY w)NFz#This nested transaction is inactive)	r   r&   r   r  r  r   r   r   r   rK   s    r+   r  zNestedTransaction._do_commit
  s~    >>'77H
 "' ,,.22d:446--9  "'s   %B 	BNT)r  r  r  r  r  r,   r  r  r  r  r  r  r  r  r  r2   r-   r+   r   r   {
  sL    > NI. ? ?,C'&%r-   r   c                   >     e Zd ZdZdZ fdZd Zd Zd Zd Z	 xZ
S )r   a  Represent a two-phase transaction.

    A new :class:`.TwoPhaseTransaction` object may be procured
    using the :meth:`_engine.Connection.begin_twophase` method.

    The interface is the same as that of :class:`.Transaction`
    with the addition of the :meth:`prepare` method.

    )r&   r   r   _is_preparedc                 H    d| _         || _        t        t        |   |       y r  )r  r   superr   r,   )r%   r&   r   rX   s      r+   r,   zTwoPhaseTransaction.__init__
  s"    !!41*=r-   c                     | j                   st        j                  d      | j                  j	                  | j
                         d| _        y)zqPrepare this :class:`.TwoPhaseTransaction`.

        After a PREPARE, the transaction can be committed.

        r   TN)r   r   r   r&   r   r   r  rK   s    r+   preparezTwoPhaseTransaction.prepare
  s;     ~~))*HII..txx8 r-   c                 :    | j                   j                  |        y r_   )r&   r   rK   s    r+   r  z*TwoPhaseTransaction._connection_begin_impl  s    ,,T2r-   c                 d    | j                   j                  | j                  | j                         y r_   )r&   r   r   r  rK   s    r+   r  z-TwoPhaseTransaction._connection_rollback_impl  s     //$:K:KLr-   c                 d    | j                   j                  | j                  | j                         y r_   )r&   r   r   r  rK   s    r+   r  z+TwoPhaseTransaction._connection_commit_impl  s     --dhh8I8IJr-   )r  r  r  r  r  r,   r  r  r  r  __classcell__)rX   s   @r+   r   r   
  s+     CI>
	!3MKr-   r   c                      e Zd ZdZeZdZeZdZ	dZ
dZ	 	 	 	 	 d,dZd Zed        Zd Zd	 Zd
 Zd Zed        Zed        Z ej.                         Zd Zd-dZdej8                  fdZej>                  d.d       Z  G d de!      Z"d/dZ# ejH                  dd      d        Z% ejH                  dd      d        Z&d Z' ejP                  dd      d        Z) ejP                  d d!      d"        Z*ddefd#Z+efd$Z,d/d%Z- ejH                  dd&      d0d'       Z. ejH                  dd(      d.d)       Z/d* Z0d.d+Z1y)1Enginea9  
    Connects a :class:`~sqlalchemy.pool.Pool` and
    :class:`~sqlalchemy.engine.interfaces.Dialect` together to provide a
    source of database connectivity and behavior.

    This is the **SQLAlchemy 1.x version** of :class:`_engine.Engine`.  For
    the :term:`2.0 style` version, which includes  some API differences,
    see :class:`_future.Engine`.

    An :class:`_engine.Engine` object is instantiated publicly using the
    :func:`~sqlalchemy.create_engine` function.

    .. seealso::

        :doc:`/core/engines`

        :ref:`connections_toplevel`

    Fzsqlalchemy.engine.EngineNc	                    || _         || _        || _        |r|| _        || _        || _        |dk7  r't        j                  || j                        | _	        nd | _	        t        j                  | |       |r | j                  di | y y )Nr   )
size_alertechoflagr2   )r{  urlr   logging_nameechora  r   LRUCache_lru_size_alertr<  r   instance_loggerupdate_execution_options)	r%   r{  r   r   r!  r"  query_cache_sizerm   ra  s	            r+   r,   zEngine.__init__,  s     	 ,D	.q #'== T-A-A$D  $(D D40)D))>,=> r-   c                 ~    | j                   r1| j                  j                  dt        |      |j                         y y )NziCompiled cache size pruning from %d items to %d.  Increase cache size to reduce the frequency of pruning.)r"   r=   r>   r0  capacity)r%   caches     r+   r$  zEngine._lru_size_alertH  s6      KKJE
	 !r-   c                     | S r_   r2   rK   s    r+   r   zEngine.engineQ  s    r-   c                 R    | j                   r| j                   j                          yy)a  Clear the compiled cache associated with the dialect.

        This applies **only** to the built-in cache that is established
        via the :paramref:`_engine.create_engine.query_cache_size` parameter.
        It will not impact any dictionary caches that were passed via the
        :paramref:`.Connection.execution_options.query_cache` parameter.

        .. versionadded:: 1.4

        N)r<  clearrK   s    r+   clear_compiled_cachezEngine.clear_compiled_cacheU  s$       &&(  r-   c                     | j                   j                  |      | _         | j                  j                  | |       | j                  j                  | |       y)a  Update the default execution_options dictionary
        of this :class:`_engine.Engine`.

        The given keys/values in \**opt are added to the
        default execution options that will be used for
        all connections.  The initial contents of this dictionary
        can be sent via the ``execution_options`` parameter
        to :func:`_sa.create_engine`.

        .. seealso::

            :meth:`_engine.Connection.execution_options`

            :meth:`_engine.Engine.execution_options`

        N)r   rj   r   set_engine_execution_optionsr   r%   rl   s     r+   r&  zEngine.update_execution_optionsc  sE    " #'"9"9"?"?"D224=11$<r-   c                 &    | j                  | |      S )a  Return a new :class:`_engine.Engine` that will provide
        :class:`_engine.Connection` objects with the given execution options.

        The returned :class:`_engine.Engine` remains related to the original
        :class:`_engine.Engine` in that it shares the same connection pool and
        other state:

        * The :class:`_pool.Pool` used by the new :class:`_engine.Engine`
          is the
          same instance.  The :meth:`_engine.Engine.dispose`
          method will replace
          the connection pool instance for the parent engine as well
          as this one.
        * Event listeners are "cascaded" - meaning, the new
          :class:`_engine.Engine`
          inherits the events of the parent, and new events can be associated
          with the new :class:`_engine.Engine` individually.
        * The logging configuration and logging_name is copied from the parent
          :class:`_engine.Engine`.

        The intent of the :meth:`_engine.Engine.execution_options` method is
        to implement "sharding" schemes where multiple :class:`_engine.Engine`
        objects refer to the same connection pool, but are differentiated
        by options that would be consumed by a custom event::

            primary_engine = create_engine("mysql://")
            shard1 = primary_engine.execution_options(shard_id="shard1")
            shard2 = primary_engine.execution_options(shard_id="shard2")

        Above, the ``shard1`` engine serves as a factory for
        :class:`_engine.Connection`
        objects that will contain the execution option
        ``shard_id=shard1``, and ``shard2`` will produce
        :class:`_engine.Connection`
        objects that contain the execution option ``shard_id=shard2``.

        An event handler can consume the above execution option to perform
        a schema switch or other operation, given a connection.  Below
        we emit a MySQL ``use`` statement to switch databases, at the same
        time keeping track of which database we've established using the
        :attr:`_engine.Connection.info` dictionary,
        which gives us a persistent
        storage space that follows the DBAPI connection::

            from sqlalchemy import event
            from sqlalchemy.engine import Engine

            shards = {"default": "base", shard_1: "db1", "shard_2": "db2"}

            @event.listens_for(Engine, "before_cursor_execute")
            def _switch_shard(conn, cursor, stmt,
                    params, context, executemany):
                shard_id = conn._execution_options.get('shard_id', "default")
                current_shard = conn.info.get("current_shard", None)

                if current_shard != shard_id:
                    cursor.execute("use %s" % shards[shard_id])
                    conn.info["current_shard"] = shard_id

        .. seealso::

            :meth:`_engine.Connection.execution_options`
            - update execution options
            on a :class:`_engine.Connection` object.

            :meth:`_engine.Engine.update_execution_options`
            - update the execution
            options for a given :class:`_engine.Engine` in place.

            :meth:`_engine.Engine.get_execution_options`


        )_option_clsr1  s     r+   rm   zEngine.execution_optionsx  s    T c**r-   c                     | j                   S )zGet the non-SQL options which will take effect during execution.

        .. versionadded: 1.3

        .. seealso::

            :meth:`_engine.Engine.execution_options`
        r6   rK   s    r+   ro   zEngine.get_execution_options  rp   r-   c                 .    | j                   j                  S )ziString name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
        in use by this :class:`Engine`.)r   rQ   rK   s    r+   rQ   zEngine.name  s    
 ||   r-   c                 .    | j                   j                  S )ziDriver name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
        in use by this :class:`Engine`.)r   driverrK   s    r+   r7  zEngine.driver  s    
 ||"""r-   c                 "    d| j                   dS )NzEngine())r   rK   s    r+   __repr__zEngine.__repr__  s    #xx))r-   c                     |r| j                   j                          | j                   j                         | _         | j                  j	                  |        y)a  Dispose of the connection pool used by this
        :class:`_engine.Engine`.

        A new connection pool is created immediately after the old one has been
        disposed. The previous connection pool is disposed either actively, by
        closing out all currently checked-in connections in that pool, or
        passively, by losing references to it but otherwise not closing any
        connections. The latter strategy is more appropriate for an initializer
        in a forked Python process.

        :param close: if left at its default of ``True``, has the
         effect of fully closing all **currently checked in**
         database connections.  Connections that are still checked out
         will **not** be closed, however they will no longer be associated
         with this :class:`_engine.Engine`,
         so when they are closed individually, eventually the
         :class:`_pool.Pool` which they are associated with will
         be garbage collected and they will be closed out fully, if
         not already closed on checkin.

         If set to ``False``, the previous connection pool is de-referenced,
         and otherwise not touched in any way.

        .. versionadded:: 1.4.33  Added the :paramref:`.Engine.dispose.close`
            parameter to allow the replacement of a connection pool in a child
            process without interfering with the connections used by the parent
            process.


        .. seealso::

            :ref:`engine_disposal`

            :ref:`pooling_multiprocessing`

        N)r{  disposerecreater   engine_disposed)r%   rb   s     r+   r<  zEngine.dispose  s>    J IIII&&(	%%d+r-   r2   c                 t    | j                         5 }|j                  |||      cd d d        S # 1 sw Y   y xY wr_   )r   r&  )r%   r  r   r  r   s        r+   r&  zEngine._execute_default  s:     \\^ 	Gt((+vF	G 	G 	Gs   .7c              #   l   K   || j                         5 }| d d d        y | y # 1 sw Y   y xY wwr_   )r   )r%   r&   r   s      r+   _optional_conn_ctx_managerz!Engine._optional_conn_ctx_manager  s=      4
   s   4(414c                       e Zd Zd Zd Zd Zy)Engine._trans_ctxc                 .    || _         || _        || _        y r_   )r   r   r'   )r%   r   r   r'   s       r+   r,   zEngine._trans_ctx.__init__  s    DI*D%6D"r-   c                 N    | j                   j                          | j                  S r_   )r   r`   r   rK   s    r+   r`   zEngine._trans_ctx.__enter__   s    &&(99r-   c                     	 | j                   j                  |||       | j                  s| j                  j	                          y y # | j                  s| j                  j	                          w w xY wr_   )r   rg   r'   r   rb   rc   s       r+   rg   zEngine._trans_ctx.__exit__$  sX    &  ))%	B--IIOO% .t--IIOO% .s   A )A0N)r  r  r  r,   r`   rg   r2   r-   r+   
_trans_ctxrC    s    	7
		&r-   rG  c                 F   | j                   j                  r| j                         }n| j                  |      }	 |j                         }t        j                  ||      S #  t	        j
                         5  |j                          ddd       n# 1 sw Y   nxY wY UxY w)aX  Return a context manager delivering a :class:`_engine.Connection`
        with a :class:`.Transaction` established.

        E.g.::

            with engine.begin() as conn:
                conn.execute(
                    text("insert into table (x, y, z) values (1, 2, 3)")
                )
                conn.execute(text("my_special_procedure(5)"))

        Upon successful operation, the :class:`.Transaction`
        is committed.  If an error is raised, the :class:`.Transaction`
        is rolled back.

        Legacy use only: the ``close_with_result`` flag is normally ``False``,
        and indicates that the :class:`_engine.Connection` will be closed when
        the operation is complete. When set to ``True``, it indicates the
        :class:`_engine.Connection` is in "single use" mode, where the
        :class:`_engine.CursorResult` returned by the first call to
        :meth:`_engine.Connection.execute` will close the
        :class:`_engine.Connection` when that :class:`_engine.CursorResult` has
        exhausted all result rows.

        .. seealso::

            :meth:`_engine.Engine.connect` - procure a
            :class:`_engine.Connection` from
            an :class:`_engine.Engine`.

            :meth:`_engine.Connection.begin` - start a :class:`.Transaction`
            for a particular :class:`_engine.Connection`.

        r'   N)	rT   rW   r   r   r   r  rb   r  rG  )r%   r'   r   r  s       r+   r   zEngine.begin+  s    F **<<>D<<2C<DD	JJLE   u.?@@	""$ 

  s#   A" "B 8B		B B	B r  zThe :meth:`_engine.Engine.transaction` method is deprecated and will be removed in a future release.  Use the :meth:`_engine.Engine.begin` context manager instead.c                     d|d<   | j                         5 } |j                  |g|i |cddd       S # 1 sw Y   yxY w)a  Execute the given function within a transaction boundary.

        The function is passed a :class:`_engine.Connection` newly procured
        from :meth:`_engine.Engine.connect` as the first argument,
        followed by the given \*args and \**kwargs.

        e.g.::

            def do_something(conn, x, y):
                conn.execute(text("some statement"), {'x':x, 'y':y})

            engine.transaction(do_something, 5, 10)

        The operations inside the function are all invoked within the
        context of a single :class:`.Transaction`.
        Upon success, the transaction is committed.  If an
        exception is raised, the transaction is rolled back
        before propagating the exception.

        .. note::

           The :meth:`.transaction` method is superseded by
           the usage of the Python ``with:`` statement, which can
           be used with :meth:`_engine.Engine.begin`::

               with engine.begin() as conn:
                   conn.execute(text("some statement"), {'x':5, 'y':10})

        .. seealso::

            :meth:`_engine.Engine.begin` - engine-level transactional
            context

            :meth:`_engine.Connection.transaction`
            - connection-level version of
            :meth:`_engine.Engine.transaction`

        Tr  N)r   r   r%   r  ro  r  r   s        r+   r   zEngine.transactionY  sN    ^ &*!"\\^ 	@t#4##I???	@ 	@ 	@   6?zThe :meth:`_engine.Engine.run_callable` method is deprecated and will be removed in a future release.  Use the :meth:`_engine.Engine.begin` context manager instead.c                     d|d<   | j                         5 } |j                  |g|i |cddd       S # 1 sw Y   yxY w)a  Given a callable object or function, execute it, passing
        a :class:`_engine.Connection` as the first argument.

        The given \*args and \**kwargs are passed subsequent
        to the :class:`_engine.Connection` argument.

        This function, along with :meth:`_engine.Connection.run_callable`,
        allows a function to be run with a :class:`_engine.Connection`
        or :class:`_engine.Engine` object without the need to know
        which one is being dealt with.

        Tr  N)r   r  rK  s        r+   r  zEngine.run_callable  sM    ( &*!"\\^ 	At$4$$Y@@@	A 	A 	ArL  c                 v    | j                         5 } |j                  ||fi | d d d        y # 1 sw Y   y xY wr_   )r   r  )r%   r  r  r  r   s        r+   r  zEngine._run_ddl_visitor  s=    ZZ\ 	FT!D!!/7EfE	F 	F 	Fs   /8z:meth:`_engine.Engine.execute`zAll statement execution in SQLAlchemy 2.0 is performed by the :meth:`_engine.Connection.execute` method of :class:`_engine.Connection`, or in the ORM by the :meth:`.Session.execute` method of :class:`.Session`.)alternativec                 R    | j                  d      } |j                  |g|i |S )a  Executes the given construct and returns a
        :class:`_engine.CursorResult`.

        The arguments are the same as those used by
        :meth:`_engine.Connection.execute`.

        Here, a :class:`_engine.Connection` is acquired using the
        :meth:`_engine.Engine.connect` method, and the statement executed
        with that connection. The returned :class:`_engine.CursorResult`
        is flagged
        such that when the :class:`_engine.CursorResult` is exhausted and its
        underlying cursor is closed, the :class:`_engine.Connection`
        created here
        will also be closed, which allows its associated DBAPI connection
        resource to be returned to the connection pool.

        TrI  )r   r   )r%   r  r   r  r&   s        r+   r   zEngine.execute  s1    4 \\D\9
!z!!)DkDVDDr-   z:meth:`_engine.Engine.scalar`a'  All statement execution in SQLAlchemy 2.0 is performed by the :meth:`_engine.Connection.execute` method of :class:`_engine.Connection`, or in the ORM by the :meth:`.Session.execute` method of :class:`.Session`; the :meth:`_future.Result.scalar` method can then be used to return a scalar result.c                 J     | j                   |g|i |j                         S )zExecutes and returns the first column of the first row.

        The underlying result/cursor is closed after execution.
        r   )r%   r  r   r  s       r+   r   zEngine.scalar  s(     t||I>>v>EEGGr-   c                 N    | j                  d      }|j                  ||||      S NTrI  )r   r  )r%   r3  r   r  rm   r&   s         r+   r  zEngine._execute_clauseelement  s1     \\D\9
00+v'8
 	
r-   c                 N    | j                  d      }|j                  ||||      S rS  )r   rF  )r%   r-  r   r  rm   r&   s         r+   rF  zEngine._execute_compiled  s1     \\D\9
++k6+<
 	
r-   c                 (    | j                  | |      S )a  Return a new :class:`_engine.Connection` object.

        The :class:`_engine.Connection` object is a facade that uses a DBAPI
        connection internally in order to communicate with the database.  This
        connection is procured from the connection-holding :class:`_pool.Pool`
        referenced by this :class:`_engine.Engine`. When the
        :meth:`_engine.Connection.close` method of the
        :class:`_engine.Connection` object
        is called, the underlying DBAPI connection is then returned to the
        connection pool, where it may be used again in a subsequent call to
        :meth:`_engine.Engine.connect`.

        rI  )rT   r   s     r+   r   zEngine.connect  s     ##D<M#NNr-   zThe :meth:`_engine.Engine.table_names` method is deprecated and will be removed in a future release.  Please refer to :meth:`_reflection.Inspector.get_table_names`.c                     | j                  |      5 }t        j                  |      }|j                  |      cddd       S # 1 sw Y   yxY w)zReturn a list of all table names available in the database.

        :param schema: Optional, retrieve names from a non-default schema.

        :param connection: Optional, use a specified connection.
        N)rA  r   inspectget_table_names)r%   rN   r&   r   insps        r+   table_nameszEngine.table_names  sG     ,,Z8 	0D%%d+D''/	0 	0 	0s   &AAzThe :meth:`_engine.Engine.has_table` method is deprecated and will be removed in a future release.  Please refer to :meth:`_reflection.Inspector.has_table`.c                     | j                  d      5 }t        j                  |      }|j                  ||      cddd       S # 1 sw Y   yxY w)a`  Return True if the given backend has a table of the given name.

        .. seealso::

            :ref:`metadata_reflection_inspector` - detailed schema inspection
            using the :class:`_reflection.Inspector` interface.

            :class:`.quoted_name` - used to pass quoting information along
            with a schema identifier.

        N)rN   )rA  r   rW  	has_table)r%   
table_namerN   r   rY  s        r+   r\  zEngine.has_table  sI    & ,,T2 	=d%%d+D>>*V><	= 	= 	=s   (AAc                 6   | j                   }	  |       S # |j                  j                  $ rj}|t        j	                  |||        nFt        j                  t        j                         d   t        j                         d          Y d }~y Y d }~y d }~ww xY w)Nr   r
   r  )	r   r  r  r   r  r   r  r  ry  )r%   r4  r&   r   r|   s        r+   _wrap_pool_connectzEngine._wrap_pool_connect(  s    ,,
	4K}}"" 	!??w LLN1%cllnQ6G 		s    BABBc                 N    | j                  | j                  j                  |      S )aC  Return a "raw" DBAPI connection from the connection pool.

        The returned object is a proxied version of the DBAPI
        connection object used by the underlying driver in use.
        The object will have all the same behavior as the real DBAPI
        connection, except that its ``close()`` method will result in the
        connection being returned to the pool, rather than being closed
        for real.

        This method provides direct DBAPI connection access for
        special situations when the API provided by
        :class:`_engine.Connection`
        is not needed.   When a :class:`_engine.Connection` object is already
        present, the DBAPI connection is available using
        the :attr:`_engine.Connection.connection` accessor.

        .. seealso::

            :ref:`dbapi_connections`

        )r_  r{  r   )r%   r   s     r+   r   zEngine.raw_connection6  s!    , &&tyy'8'8+FFr-   )NNi  NFr  r_   r  r  )2r  r  r  r  r  r   r   r   rT   r  rW   rL   r,   r$  r  r   r.  r&  rm   ro   rQ   r7  r   echo_propertyr"  r:  r<  r   
EMPTY_DICTr&  
contextlibcontextmanagerrA  objectrG  r   r  r   r  r  r  r   r   r  rF  r   rZ  r\  r_  r   r2   r-   r+   r  r    s   ( /K O7J  ?8  )=*J+X	' ! ! # # 3D*(,V $&dooG  &V &",A\ T__	)@)@V T__	#AA"F T(EE* T'*	H	H /

" 0

O" T__	9	0	0 T__	3== Gr-   r  c                   R    e Zd ZdZd Zd Zd Z eee      Zd Z	d Z
 ee	e
      Zy)OptionEngineMixinFc                    || _         |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j
                  | _        |j                  | _        t        j                  | | j                         | j                  j                  |j                        | _	        |j                  | _         | j                  di | y )Nr  r2   )_proxiedr   r   r!  r"  r<  ra  r   r%  r   r#   r   r&  )r%   proxiedrm   s      r+   r,   zOptionEngineMixin.__init__R  s    ;;#00LL	&66&66D4995 ++G,<,<=")"<"<%%%:(9:r-   c                 .    | j                   j                  S r_   ri  r{  rK   s    r+   	_get_poolzOptionEngineMixin._get_poolm  s    }}!!!r-   c                 &    || j                   _        y r_   rl  )r%   r{  s     r+   	_set_poolzOptionEngineMixin._set_poolp  s    !r-   c                 j    | j                   j                  xs | j                  j                  dd      S )Nr   F)ri  r   rZ   rJ   rK   s    r+   _get_has_eventsz!OptionEngineMixin._get_has_eventsu  s/    }}(( 
DMM,=,=5-
 	
r-   c                 "    || j                   d<   y )Nr   )rZ   )r%   re   s     r+   _set_has_eventsz!OptionEngineMixin._set_has_eventsz  s    ',m$r-   N)r  r  r  _sa_propagate_class_eventsr,   rm  ro  r  r{  rq  rs  r   r2   r-   r+   rg  rg  O  s=    !&;6"" Iy)D

- ?O<Kr-   rg  c                       e Zd Zy)OptionEngineN)r  r  r  r2   r-   r+   rv  rv    s    r-   rv  )!
__future__r   rc  r  
interfacesr   r   r   r   r   r	   r   r   r   r   sqlr   rb  immutabledictr  r   r  r  r   r   r   r   
Identifiedr  re  rg  rv  r3  r2   r-   r+   <module>r|     s    &  
 # ( ! $ &      " +**, ^#0 ^#0BGK+ K6[& [|= =@~8k ~8Bj jZ$K/ $KN}G[#.. }G@.= .=b	$f 	 " r-   