
    -h                       S SK Jr  S SKrS SKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  S	S
KJr  S	SKJr  S	SKJr  S	SKJr  S	SKJr  S	SKJr   \R$                  " 5       r " S S\5      r " S S\5      r " S S\
5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\\R6                  5      r " S S \5      r " S! S"\\5      r\\l         g)#    )with_statementN   )Connectable)ExceptionContext)_distill_params)_distill_params_20)TransactionalContext   )exc)
inspection)log)util)compilerc                      \ rS rSrSrSrSrSr       SPS jr\	R                  S 5       rS rS	 r\S
 5       rS rS rS rS rS rS rS r\S 5       r\S 5       r\S 5       rS r\S 5       rS rS r\S 5       r\S 5       r\	R@                  " S5      SQS j5       r!SRS jr"S r#S r$S  r%S! r&SRS" jr'S# r(SQS$ jr)SQS% jr*S& r+S' r,S( r-S) r.S* r/S+ r0S, r1SQS- jr2SRS. jr3S/ r4S0 r5S1 r6S2 r7S3 r8S4 r9S5 r:S6 r;S7 r<S8 r=S9 r>S: r?S; r@\A4S< jrBS= rCS> rDS? rE\A4S@ jrFSA rGS\A4SB jrH SSSC jrISD rJSRSE jrKSF rLSrMSrNSG rO\PSH 5       rQSI rR\	R                  " SJSK5      SL 5       rT\	R                  " SJSM5      SN 5       rUSOrVg)T
Connection    a  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	                    Xl         UR                  U l        X@l        U(       aK  UR                  b   eX l        XPl        UR
                  U l        SU l        X`l        UR                  U l        OUb  UOUR                  5       U l        S=U l
        U l        SU l        SU l        X0l        Xl        U R                   R                  5       U l        Uc*  U R                  R!                  UR                  5      U l        U=(       d    USL =(       a    UR                  U l        U(       a   eUR                  U l        U R                  (       d  U R                   R                  (       a  U R                  R#                  XSL5        gg)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	            kC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/engine/base.py__init__Connection.__init__C   sU    ~~)--555%/"&8#%++DJ,1D)%M+77D ) **, " <@?D 8#$D #DO,=)#4 557DJ" !% 3 3FOO D*  t#:(:(:  *))&,&?&?D#t{{66MM((4/GH  7    c                 P   ^ SU R                   ;   a  U R                   S   mU4S j$ g )Nlogging_tokenc                    > ST< SU < 3$ )N[z]  )msgtokens    r,   <lambda>/Connection._message_formatter.<locals>.<lambda>~   s
    E37r/   r   )r&   r6   s    @r,   _message_formatterConnection._message_formatterz   s*    d555++O<E77r/   c                     U R                   nU(       a  U" U5      n[        R                  (       a  S[        R                  -   US'   U R                  R
                  R                  " U/UQ70 UD6  g Nr   
stacklevel)r:   r   
STACKLEVELSTACKLEVEL_OFFSETr   loggerinfor&   messageargkwfmts        r,   	_log_infoConnection._log_info   sW    %%'lG>> 3#8#88B|4#44r/   c                     U R                   nU(       a  U" U5      n[        R                  (       a  S[        R                  -   US'   U R                  R
                  R                  " U/UQ70 UD6  g r=   )r:   r   r?   r@   r   rA   debugrC   s        r,   
_log_debugConnection._log_debug   sW    %%'lG>> 3#8#88B|  535"5r/   c                 :    U R                   R                  SS 5      $ )Nschema_translate_map)r   getr&   s    r,   _schema_translate_map Connection._schema_translate_map   s    &&**+A4HHr/   c                     UR                   nU R                  R                  SS5      nU(       a  X#;   a  UR                  (       a  X2   $ U$ )zdReturn the schema name for the given schema item taking into
account current schema translate map.

rO   N)schemar   rP   _use_schema_map)r&   objnamerO   s       r,   schema_for_objectConnection.schema_for_object   sK     zz#66::"D 

 !,##'--Kr/   c           	          U R                   R                  U R                   U R                  U R                  (       a  U R                  OU U R                  U R
                  U R                  S9$ )a
  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   rQ   s    r,   _branchConnection._branch   s\    ( {{**KK""/3/A/A++t#66((mm + 
 	
r/   c                     U R                   (       a  U $ U R                  R                  U R                  5      nU R                  R	                  5       Ul        U$ )z@define connection method chaining behavior for execution_options)
_is_future	__class____new____dict__copy)r&   cs     r,   _generate_for_options Connection._generate_for_options   sA     ??K&&t~~6A++-AJHr/   c                     U $ Nr4   rQ   s    r,   	__enter__Connection.__enter__   s    r/   c                 $    U R                  5         g ri   )closer&   type_value	tracebacks       r,   __exit__Connection.__exit__       

r/   c                 *   U R                  5       nUR                  R                  U5      Ul        U R                  (       d  U R                  R                  (       a  U R
                  R                  X!5        U R                  R                  X!5        U$ )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`


)rf   r   unionr   r   r    set_connection_execution_optionsr   )r&   optre   s      r,   execution_optionsConnection.execution_options   sj    z &&( 3399#>t{{66MM::1B55a=r/   c                     U R                   $ )zGet the non-SQL options which will take effect during execution.

.. versionadded:: 1.3

.. seealso::

    :meth:`_engine.Connection.execution_options`
r9   rQ   s    r,   get_execution_options Connection.get_execution_options       &&&r/   c                 N    U R                   SL =(       a    U R                  (       + $ )z)Return True if this connection is closed.N)r   r"   rQ   s    r,   closedConnection.closed  s#     %%-Jd6J6J2JJr/   c                     U R                   (       a  U R                   R                  $ U R                  SL =(       a    U R                  (       + $ )z/Return True if this connection was invalidated.N)r   invalidatedr   r   rQ   s    r,   r   Connection.invalidated  s;     %%111%%-Adkk/Ar/   c                     U R                   c   U R                  5       $ U R                   $ ! [        R                  [        R                  4 a    e [
         a  nU R                  USSSS5         SnAgSnAff = f)a  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'   Connection.connection  s|      !!)H2244 ))) ,,c.E.EF   H,,QdD$GGHs   + .A8A33A8c                      U R                   R                  U R                  5      $ ! [         a  nU R	                  USSSS5         SnAgSnAff = f)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'   r   r   r   s     r,   r   Connection.get_isolation_level!  sM    N	D<<33DOODD 	D((D$dCC	Ds   $' 
AAAc                 .    U R                   R                  $ )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_levelrQ   s    r,   r   "Connection.default_isolation_levelM  s    : ||333r/   c                     U R                   (       a'  [        R                  " SU R                  b  SOS-  SS9eU R                  (       a   e[        R                  " SU R                  b  SOS-  SS9e)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)r   r   r   r   r`   rQ   s    r,   _invalid_transactionConnection._invalid_transactionl  s    ** //; ! 	 	 &&**= //; ! 	 	r/   c                 V   U R                   (       a  U R                   R                  5       $ U R                  (       aX  U R                  (       aG  U R                  b  U R                  5         U R                  R                  U S9U l        U R                  $ [        R                  " S5      e)N)_connectionThis Connection is closed)r   r   r"   r   r   r   r   r   r   r   r   rQ   s    r,   r   !Connection._revalidate_connection  s    %%<<>>D$4$4  ,))+%)[[%?%?  &@ &D" )))%%&ABBr/   c                 Z    U R                   S L=(       a    [        U R                   SS5      $ )Nis_validF)r   getattrrQ   s    r,   )_still_open_and_dbapi_connection_is_valid4Connection._still_open_and_dbapi_connection_is_valid  s.    %%T1 
g""J7
 	
r/   c                 .    U R                   R                  $ )ak  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'   rB   rQ   s    r,   rB   Connection.info  s     ###r/   z:meth:`.Connection.connect`c                 "    U R                  5       $ )aT  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.

)r]   r&   r(   s     r,   connectConnection.connect  s     ||~r/   c                 0   U R                   (       a  U R                   R                  US9$ U R                  (       a  gU R                  (       a  [        R
                  " S5      eU R                  (       a  U R                  R                  U5        SU l        g)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   
invalidater   r   r   r   r   r   )r&   r   s     r,   r   Connection.invalidate  sr    \ %%0090EE;;))*EFF99""--i8!%r/   c                 8    U R                   R                  5         g)a  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   detachrQ   s    r,   r   Connection.detach  s    4 	%%'r/   c                 $    U R                  5         g ri   )beginrQ   s    r,   
_autobeginConnection._autobegin  rt   r/   c                 |   U R                   (       a  U R                  (       a   eO+U R                  (       a  U R                  R                  5       $ U R                  (       a  gU R                  c  [        U 5      U l        U R                  $ U R                   (       a  [        R                  " S5      e[        U 5      $ )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.)	r`   r   r   r!   r   RootTransactionr   InvalidRequestErrorMarkerTransactionrQ   s    r,   r   Connection.begin  s    f ??)))))%%++--?? & / 5D$$$--'  )..r/   c                 `   U R                   (       a  U R                  (       a   eO+U R                  (       a  U R                  R                  5       $ U R                  cG  U R                   (       d&  [        R
                  " S5        U R                  5       $ U R                  5         [        U 5      $ )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().)	r`   r   begin_nestedr   r   warn_deprecated_20r   r   NestedTransactionrQ   s    r,   r   Connection.begin_nested\  s    ` ??)))))%%2244$??''1 zz|#! &&r/   c                     U R                   (       a  U R                   R                  US9$ U R                  b  [        R                  " S5      eUc$  U R
                  R                  R                  5       n[        X5      $ )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   Connection.begin_twophase  su    ( %%444==())*  ;++%%002C"4--r/   c                 L    U R                   R                  R                  U 5      $ ri   )r   r   do_recover_twophaserQ   s    r,   recover_twophaseConnection.recover_twophase  s    {{""66t<<r/   c                 L    U R                   R                  R                  XUS9  g N)recover)r   r   do_rollback_twophaser&   r   r   s      r,   rollback_preparedConnection.rollback_prepared  s    00G0Lr/   c                 L    U R                   R                  R                  XUS9  g r   )r   r   do_commit_twophaser   s      r,   commit_preparedConnection.commit_prepared  s    ..t'.Jr/   c                     U R                   b  U R                   R                  5       $ U R                  SL=(       a    U R                  R                  $ z,Return True if a transaction is in progress.N)r   in_transactionr   	is_activerQ   s    r,   r   Connection.in_transaction  sE    )%%4466  ,L1B1B1L1LLr/   c                     U R                   b  U R                   R                  5       $ U R                  SL=(       a    U R                  R                  $ r   )r   in_nested_transactionr   r   rQ   s    r,   r    Connection.in_nested_transaction  sL    )%%;;== $$D0 3((22	
r/   c                     U R                   R                  SS 5      n[        US:H  =(       d/    US L =(       a$    [        U R                  R
                  SS 5      S:H  5      $ )Nisolation_level
AUTOCOMMIT)r   rP   boolr   r   r   )r&   opt_isos     r,   _is_autocommit_isolation#Connection._is_autocommit_isolation  s`    ))--.?F|# 4  DKK//1BDI 	
 	
r/   c                 h    U R                   b  U R                   R                  5       $ U R                  $ )zQReturn the current root transaction in progress, if any.

.. versionadded:: 1.4

)r   get_transactionr   rQ   s    r,   r   Connection.get_transaction  s1     )%%5577   r/   c                 h    U R                   b  U R                   R                  5       $ U R                  $ )zSReturn the current nested transaction in progress, if any.

.. versionadded:: 1.4

)r   get_nested_transactionr   rQ   s    r,   r   !Connection.get_nested_transaction  s1     )%%<<>>'''r/   c                 6   U R                   (       a   eU R                  (       a8  U R                  5       (       a  U R                  S5        OU R                  S5        SU l        U R
                  (       d  U R                  R
                  (       a  U R                  R                  U 5         U R                  R                  R                  U R                  5        SU l        g ! [         a  nU R                  US S S S 5         S nAN,S nAff = f! SU l        f = f)Nz?BEGIN (implicit; DBAPI should not BEGIN due to autocommit mode)zBEGIN (implicit)TF)r   r   r   rH   r!   r   r   r   r   r   do_beginr'   r   r   r&   transactionr   s      r,   _begin_implConnection._begin_impl  s    %%%%::,,..'
 12t{{66MM%	$KK((9 $DO  	D((D$dCC	D $DOs*   ,/C# #
D-DD DD 	Dc                 &   U R                   (       a   eU R                  (       d  U R                  R                  (       a  U R                  R	                  U 5        U R
                  (       az  U R                  (       a8  U R                  5       (       a  U R                  S5        OU R                  S5         U R                  R                  R                  U R                  5        g g ! [         a  nU R                  US S S S 5         S nAg S nAff = f)NzVROLLBACK using DBAPI connection.rollback(), DBAPI should ignore due to autocommit modeROLLBACK)r   r   r   r   rollbackr   r   r   rH   r   do_rollbackr'   r   r   r   s     r,   _rollback_implConnection._rollback_impl  s    %%%%t{{66MM""4(99zz0022NNE
 NN:.H##//@ : ! H,,QdD$GGHs   6/C' '
D1DDc                 f   U R                   (       a   eU(       a+  U R                  5       (       d  [        R                  " S5        U R                  (       d  U R
                  R                  (       a  U R                  R                  U 5        U R                  (       a8  U R                  5       (       a  U R                  S5        OU R                  S5         U R
                  R                  R                  U R                  5        g ! [         a  nU R                  US S S S 5         S nAg S nAff = f)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   rH   r   	do_commitr'   r   r   )r&   
autocommitr   s      r,   _commit_implConnection._commit_impl*  s    %%%% d;;==##J t{{66MM  &::,,..A
 x(	DKK))$//: 	D((D$dCC	Ds   /D 
D0D++D0c                 v   U R                   (       a   eU R                  (       d  U R                  R                  (       a  U R                  R	                  X5        Uc$  U =R
                  S-  sl        SU R
                  -  nU R                  (       a'  U R                  R                  R                  X5        U$ g )Nr   zsa_savepoint_%s)	r   r   r   r   	savepointr    r   r   do_savepointr&   rX   s     r,   _savepoint_implConnection._savepoint_implJ  s    %%%%t{{66MM##D/<  A% $t';';;D99KK,,T8K :r/   c                 (   U R                   (       a   eU R                  (       d  U R                  R                  (       a  U R                  R	                  XS 5        U R
                  (       a&  U R                  R                  R                  X5        g g ri   )r   r   r   r   rollback_savepointr   r   do_rollback_to_savepointr   s     r,   _rollback_to_savepoint_impl&Connection._rollback_to_savepoint_implW  s`    %%%%t{{66MM,,T>99KK88D :r/   c                 (   U R                   (       a   eU R                  (       d  U R                  R                  (       a  U R                  R	                  XS 5        U R
                  (       a&  U R                  R                  R                  X5        g g ri   )r   r   r   r   release_savepointr   r   do_release_savepointr   s     r,   _release_savepoint_impl"Connection._release_savepoint_impl`  s`    %%%%t{{66MM++D=99KK44T@ :r/   c                     U R                   (       a   eU R                  (       a  U R                  S5        U R                  (       d  U R                  R                  (       a%  U R
                  R                  XR                  5        U R                  (       a?  SU l	         U R                  R                  R                  XR                  5        SU l	        g g ! [         a  nU R                  US S S S 5         S nAN-S nAff = f! SU l	        f = f)NzBEGIN TWOPHASE (implicit)TF)r   r   rH   r   r   r   r   r   r   r!   r   do_begin_twophaser   r   r   s      r,   _begin_twophase_implConnection._begin_twophase_impli  s    %%%%::NN67t{{66MM((?99"DO(##55dOOL #( : ! H,,QdD$GGH #(s*    /C 
D"C<7D <DD 	Dc                    U R                   (       a   eU R                  (       d  U R                  R                  (       a  U R                  R	                  X5        U R
                  (       aH  [        U R                  [        5      (       d   e U R                  R                  R                  X5        g g ! [         a  nU R                  US S S S 5         S nAg S nAff = fri   )r   r   r   r   prepare_twophaser   
isinstancer   r   r   do_prepare_twophaser   r   )r&   r   r   s      r,   _prepare_twophase_impl!Connection._prepare_twophase_implz  s    %%%%t{{66MM**4599d//1DEEEEH##77B : ! H,,QdD$GGHs   %B5 5
C?CCc                    U R                   (       a   eU R                  (       d  U R                  R                  (       a  U R                  R	                  XU5        U R
                  (       aI  [        U R                  [        5      (       d   e U R                  R                  R                  XU5        g g ! [         a  nU R                  US S S S 5         S nAg S nAff = fri   )r   r   r   r   rollback_twophaser   r  r   r   r   r   r   r   r&   r   is_preparedr   s       r,   _rollback_twophase_impl"Connection._rollback_twophase_impl  s    %%%%t{{66MM++D{C99d//1DEEEEH##88{ : ! H,,QdD$GGH   &B7 7
C CC c                    U R                   (       a   eU R                  (       d  U R                  R                  (       a  U R                  R	                  XU5        U R
                  (       aI  [        U R                  [        5      (       d   e U R                  R                  R                  XU5        g g ! [         a  nU R                  US S S S 5         S nAg S nAff = fri   )r   r   r   r   commit_twophaser   r  r   r   r   r   r   r   r  s       r,   _commit_twophase_impl Connection._commit_twophase_impl  s    %%%%t{{66MM))$[A99d//1DEEEEH##66t+N : ! H,,QdD$GGHr  c                     U R                   (       a  U R                   R                  5         U R                  5       (       d  U R                  5         g g ri   )r   _autorollbackr   r   rQ   s    r,   r"  Connection._autorollback  s=    ,,.""$$! %r/   c                 0    [         R                  " S5        g )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   rQ   s    r,   _warn_for_legacy_exec_format'Connection._warn_for_legacy_exec_format  s    *	
r/   c                    U R                   (       a8  U R                  (       a   e[        R                  " S5        SU l        SU l        gU R                  (       a  U R                  R                  5         SnOSnU R                  b:  U R                  nU(       a  UR                  SS9  OUR                  5         SU l        SU l        g)a  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   r`   r   r   r   r"   r   rm   _close_special)r&   
skip_resetconns      r,   rm   Connection.close  s    ( &&##I &*D"#(D ##%JJ!!-))D ##d#;

 &*D"$r/   c                 J    U R                   " U/UQ70 UD6R                  5       $ )zrExecutes and returns the first column of the first row.

The underlying result/cursor is closed after execution.

executescalarr&   object_multiparamsparamss       r,   r0  Connection.scalar  s&     ||G<k<V<CCEEr/   c                 J    U R                   " U/UQ70 UD6R                  5       $ )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/  scalarsr1  s       r,   r7  Connection.scalars  s&     ||G<k<V<DDFFr/   c                 P   [        U[        R                  5      (       a-  [        R                  " S5        U R	                  UUU[
        SS9$  UR                  nU" XU[
        5      $ ! [         a3  n[        R                  " [        R                  " U5      US9   SnAgSnAff = f)a	  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&   	statementr3  r4  metherrs         r,   r/  Connection.execute  s    V i!2!233##+ ((% )  	J33D 63HII  	KK,,Y7	s   A( (
B%2)B  B%c                 D    U R                  UR                  5       X#U5      $ )z%Execute a sql.FunctionElement object.)_execute_clauseelementselect)r&   funcr3  r4  ry   s        r,   _execute_functionConnection._execute_functionk  s%     **KKM;0A
 	
r/   c                 
   U R                   R                  U5      n[        XU5      nU R                  (       d  U R                  R                  (       a  U R                  XU5      u  nnnn U R                  n	U	c  U R                  5       n	U R                  n
U
R                  R                  XX5      nWR!                  SUS5      nU R"                  (       a  U R%                  5         U R                  (       d  U R                  R                  (       a   U R&                  R)                  U UWWUU5        U$ ! [        R                  [        R                  4 a    e [         a  nU R                  USSSS5         SnANSnAff = f)z&Execute a schema.ColumnDefault object.N)r   
merge_withr   r   r   _invoke_before_exec_eventr   r   r   execution_ctx_cls_init_defaultr   r   r   r   r   _exec_defaultr   rm   r   after_execute)r&   defaultr3  r4  ry   distilled_parametersdistilled_paramsevent_multiparamsevent_paramsr+  r   ctxr   rets                 r,   _execute_defaultConnection._execute_defaultr  sb    !33>>
  /t&It{{66 ../@ !
	D))D|224llG++99tC gt4((JJLt{{66MM''!! 
' ((#*A*AB 	 	D((D$dCC	Ds   ,AD5 5.F#E==Fc                 l   UR                   R                  U R                   U5      n[        XU5      nU R                  (       d  U R                  R                  (       a  U R                  XU5      u  nnnnU R                   R                  U5      n	U	R                  SS5      n
U R                  nUR                  XS9nU R                  UUR                  R                  USUU5      nU R                  (       d  U R                  R                  (       a   U R                  R                  U UWWUU5        U$ )zExecute a schema.DDL object.rO   N)r   rO   )r   rP  r   r   r   rQ  rP   r   compile_execute_contextrR  	_init_ddlr   rU  )r&   ddlr3  r4  ry   rW  rX  rY  rZ  	exec_optsrO   r   compiledr\  s                 r,   _execute_ddlConnection._execute_ddl  s.     22==##%6
  /t&It{{66 ..+< !
 ++667HI	(}}-CTJ,,;;  
 ##%%//
 t{{66MM''!! 
r/   c                    [        U5      S:X  a  / US   pTOU0 pTU R                  R                   H  nU" U UUUU5      u  pnM     U(       a)  [        U5      nU(       a  [        R
                  " S5      eOU(       a  U/nO/ nXXE4$ )Nr   r   zLEvent handler can't return non-empty multiparams and params at the same time)lenr   before_executelistr   r   )r&   elemrX  ry   rY  rZ  fns          r,   rQ  $Connection._invoke_before_exec_event  s      A%.02B12E|.>|--..B46!!51D\ / #$56--2  
  ,~!'8FFr/   c                    UR                   R                  U R                   U5      n[        XU5      nU R                  =(       d    U R                  R                  nU(       a  U R                  XU5      u  nnnnU(       a  [        US   5      n	[        U5      S:  n
O/ n	Sn
U R                  nUR                  SS5      nUR                  SU R                  R                  5      nUR                  UUU	U
UU R                  R                  [        R                  -  S9u  pnU R                  UUR                   R"                  UUUUUUUUS9
nU(       a   U R$                  R'                  U UWWUU5        U$ )	z#Execute a sql.ClauseElement object.r   r   FrO   Ncompiled_cache)r   rp  column_keysfor_executemanyrO   linting)	cache_hit)r   rP  r   r   r   rQ  sortedri  r   rP   _compiled_cache_compile_w_cachecompiler_lintingr   WARN_LINTINGra  rR  _init_compiledr   rU  )r&   rl  r3  r4  ry   rX  
has_eventsrY  rZ  keysrr  r   rO   rp  compiled_sqlextracted_paramsrt  r\  s                     r,   rJ  !Connection._execute_clauseelement  s   
 !33>>##%6
 +4f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                    UR                   R                  U R                  U5      n[        XU5      nU R                  (       d  U R
                  R                  (       a  U R                  XU5      u  nnnnU R                  n	U R                  U	U	R                  R                  UUUUUSS5	      n
U R                  (       d  U R
                  R                  (       a   U R                  R                  U UWWUU
5        U
$ )zYExecute a sql.Compiled object.

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

N)ry   rP  r   r   r   r   rQ  r   ra  rR  rz  r   rU  )r&   re  r3  r4  ry   rW  rX  rY  rZ  r   r\  s              r,   _execute_compiledConnection._execute_compiled@  s     %66AA##%6
  /t&It{{66 ..0A !
 ,,##%%44  

 t{{66MM''!! 
r/   c           	         U R                   R                  U5      n[        XU5      nU(       dC  U R                  (       d  U R                  R                  (       a  U R                  XU5      u  nnnn	U R                  n
U R                  U
U
R                  R                  UUUUU5      nU(       dL  U R                  (       d  U R                  R                  (       a   U R                  R                  U UWW	UU5        U$ ri   )r   rP  r   r   r   rQ  r   ra  rR  _init_statementr   rU  )r&   rE  r3  r4  ry   r;  rW  rX  rY  rZ  r   r\  s               r,   r?  Connection._exec_driver_sqlt  s     !33>>
  /t&I4;;#:#: 225F$% 
 ,,##%%55  
 4;;#:#:++% % 
r/   c                     [        U5      u  pE UR                  nU" XXS5      $ ! [         a3  n[        R                  " [
        R                  " U5      US9   S nAg S nAff = f)Nr<  )r   rA  rB  r   rC  r   rD  )r&   rE  
parametersry   args_10stylekwargs_10stylerF  rG  s           r,   _execute_20Connection._execute_20  s_     (:*'E$	O33D NNN  	KK,,Y7	s   $ 
A!)AA!c                 B    [        U5      u  pEU R                  UUUUSS9$ )a7  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&   rE  r  ry   r  r  s         r,   exec_driver_sqlConnection.exec_driver_sql  s9    p (:*'E$$$ % 
 	
r/   c           
         U nU R                   (       a  U R                   n U(       a-  UR                  SS5      n	U	(       a  UR                  SU	S.5      n U R                  n
U
c  U R	                  5       n
U" XX/UQ70 UD6nU R                  (       a  U R                  R                  (       a,  U R                  (       a,  U R                  R                  (       d  U R                  5         O'U R                   (       a  ["        R$                  " U 5        U R&                  (       a  U R                  c  U R)                  5         WR+                  5         UR,                  (       a  UR/                  5         UR0                  UR2                  UR4                  pCnUR6                  (       d  US   nU R8                  (       d  U R:                  R8                  (       a6  U R<                  R>                   H  nU" U UUUUUR6                  5      u  p4M     U R@                  (       a  U RC                  U5        URE                  5       nU R:                  RF                  (       d2  U RC                  SU[H        RJ                  " USUR6                  S95        OU RC                  S	U< S
35        Sn UR6                  (       ay  U RL                  R8                  (       a9  U RL                  R<                  RN                   H  nU" XXK5      (       d  M  Sn  O   U(       d  U RL                  RO                  XXK5        GOU(       d  URP                  (       ax  U RL                  R8                  (       a9  U RL                  R<                  RR                   H  nU" XU5      (       d  M  Sn  O   U(       d  U RL                  RS                  XU5        OwU RL                  R8                  (       a9  U RL                  R<                  RT                   H  nU" XXK5      (       d  M  Sn  O   U(       d  U RL                  RU                  XXK5        U R8                  (       d  U R:                  R8                  (       a*  U R<                  RW                  U UUUUUR6                  5        URY                  5         UR[                  5       nU R&                  (       d  UR\                  nUR^                  (       d  U(       a  SUl0        U R                  c   URb                  (       a  U Re                  SS9  U(       a4  UR^                  (       a#  U R&                  (       a   eURg                  5         U$ ! [
        R                  [
        R                  4 a    e [         a4  nU R                  U[        R                  " U5      USS5         SnAGN,SnAff = f! [         a  nU R                  XXMU5         SnAW$ SnAff = f)z\Create an :class:`.ExecutionContext` and execute, returning
a :class:`_engine.CursorResult`.	yield_perNT)stream_resultsmax_row_bufferr   z[%s] %r
   )batchesismultir3   z5] [SQL parameters hidden due to hide_parameters=True]F)r   )4r   rP   rv   r   r   r   r   r   r   r   r   	text_typer   r   r   r   _trans_context_managerr	   _trans_ctx_checkr`   r   pre_execuse_setinputsizes_set_input_sizescursorrE  r  executemanyr   r   r   before_cursor_executer   rH   _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   rm   )r&   r   constructorrE  r  ry   argsrF   branchedypr+  contextr   r  rm  statsevt_handledresultr   s                      r,   ra  Connection._execute_context  s     %%D"&&{D9B$5$;$;'+rB%!	))D|224!t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fEE*.K! C #LL//:  G$9$9<<++"ll33HHf99*.K! I #LL557 <<++"ll33>>fEE*.K! ? #LL++: 4;;#:#:22'' 002F??+3+L+L(**/G37F0
 %%-11%%%6
 ,0D0D#.. NN$ a ((#*A*AB 	 	((4>>),j$ 	R  	((j'  	sF   ,U #AV5 BV5 A4V5 EV5 .V2>)V--V25
W?WWc           	         U R                   (       d  U R                  R                   (       a*  U R                  R                   H  nU" XX#US5      u  p#M     U R                  (       a#  U R                  U5        U R                  SU5         U R                  R                   (       d  SOU R                  R                  R                   H  nU" XX45      (       d  M    O   U R                  R                  XX45         U R                   (       d  U R                  R                   (       a  U R                  R                  XX#US5        gg! [         a  nU R                  XbX1U5         SnANnSnAff = f)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] %rr4   N)r   r   r   r  r   rH   r   r  r   r   r  )r&   r  rE  r  r  rm  r   s          r,   _cursor_executeConnection._cursor_execute  s.    t{{66mm99(*)%)%	: :
 ::NN9%NN>:6	 ||// \\**556 
 f==6 '':O t{{66MM..iWe  7  	((j' 	s%   AE	 E	 E	 	
E0E++E0c                      UR                  5         g! [         a1    U R                  R                  R                  R                  SSS9   gf = f)zLClose the given cursor, catching exceptions
and turning into log warnings.

zError closing cursorT)exc_infoN)rm   	Exceptionr   poolrA   error)r&   r  s     r,   _safe_close_cursorConnection._safe_close_cursor  sG    
	LLN 	KK##))& * 	s    8AAc                 D   [         R                  " 5       n[        R                  " U5      nU R                  (       d  [        XR                  R                  R                  5      =(       aR    U R                  (       + =(       a:    U R                  R                  UU R                  (       d  U R                  OS U5      =(       d    U=(       a    U R                  (       + U l        U(       + nU R                  (       a  [        R                  " [        R                   R#                  UUUU R                  R                  R                  U R$                  R&                  U R                  Ub  UR(                  OS S9US   US9  SU l         [        XR                  R                  R                  5      =(       d    US L=(       a    US L =(       a    U(       + n	U	(       az  [        R                   R#                  UUUU R                  R                  R                  U R$                  R&                  U R                  U R                  Ub  UR(                  OS S9n
OS n
S nU R*                  (       d  U R$                  R*                  (       a  U R,                  R/                  SS5      (       d  [1        UU
U R$                  U UUUUU R                  U5
      nU R2                  R4                   H  n U" U5      nUb  U=Ul        nM  M     U R                  UR                  :w  a)  UR                  U l        U
(       a  UR                  U
l        UR<                  nU	(       a  U(       a  UR?                  U5        U R                  (       dE  U(       a  U RA                  U5        [        RB                  " SS9   U RE                  5         S S S 5        U(       a  [        R                  " XS   US9  O;U	(       a  [        R                  " XS   US9  O[        R                  " US	   US   S
9  U ?U R                  (       a]  U ?U R                  (       dJ  U R                  nU(       a&  U R$                  RF                  RI                  UU5        U RK                  U5        U RL                  (       a$  U RN                  (       a   eU RQ                  5         g g ! [8         a  nUn S nA  GM  S nAff = f! , (       d  f       GN,= f! U ?U R                  (       a]  U ?U R                  (       dJ  U R                  nU(       a&  U R$                  RF                  RI                  UU5        U RK                  U5        U RL                  (       a$  U RN                  (       a   eU RQ                  5         f f = f)N)r  r   r  r
   with_tracebackfrom_T)r  connection_invalidatedr   r  skip_user_error_eventsF)	warn_onlyr   r  ))sysr  r   is_exit_exception_is_disconnectr  r   dbapiErrorr   is_disconnectr   r   _reentrant_errorrC  r   
DBAPIErrorinstancer   r  r  r   r   rP   ExceptionContextImplr   handle_errorchained_exceptionr  r  invalidate_pool_on_disconnecthandle_dbapi_exceptionr  safe_reraiser"  r  _invalidater   r   r`   rm   )r&   r   rE  r  r  r  r  r  r  should_wrapsqlalchemy_exceptionnewraiser[  rm  per_fn_raiseddbapi_conn_wrappers                    r,   r   "Connection._handle_dbapi_exception  s    <<> 2215""1ll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4B	 "$C!-?EEC1H . 5 &&#*;*;;*-*;*;D'+-- -C 55 . w..q1&&++F3&&6&&( 7 Ha[J(!A HQKD %""''')-)?)?&4((445GKOOA&,,??**

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

 -sR   
E S8 +S
?B1S8 0S&A#S8 

S#SS8 S##S8 &
S50S8 8B'Vc                    [         R                  " 5       nUR                  US S 5      n[        XR                  R
                  5      nU(       aA  [        R                  R                  S S UUR                  R
                  UR                  US9nOS nS nUR                  (       aq  [        UUUS S S S S US5
      n	UR                  R                   H  n
 U
" U	5      nUb  U=U	l        nM  M     U(       a"  XYR                  :w  a  U	R                  =Ul        nU(       a  ["        R$                  " XS   US9  g U(       a  ["        R$                  " XtS   US9  g ["        R$                  " US   US   S9  g ! [         a  nUn S nA  M  S nAff = f)N)r  r  Tr
   r  r   r  )r  r  r  r  r  r  r   r  r  r  r   r  r   r  r  r  r  r   rC  )clsr   r   r   r  r  r  r  r  r[  rm  r  r  s                r,   $_handle_dbapi_exception_noconnection/Connection._handle_dbapi_exception_noconnectioni  sz   <<>--at< MM$7$78#&>>#:#:## & 6 6'4 $; $  $( &$C oo22	  WF);AA- * 3 $9J9J(J %%&$;! KK!AFKK$a[ KKHQK@# ! &Hs   E22
F
<FF
c                 J    U" U R                   U 40 UD6R                  U5        g)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_visitor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                    SUS'   U R                  5       n U R                  " U/UQ70 UD6nUR                  5         U$ !   [        R                  " 5          UR                  5         SSS5         g! , (       d  f        g= f= f)a  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_r  r  transr\  s         r,   r   Connection.transaction  ss    b &*!"

	!##I???CLLNJ	!""$  %$$$s'   '? BA1'B1
B 	;B B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                     U" U /UQ70 UD6$ )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.

r4   )r&   r  r  r  s       r,   r  Connection.run_callable  s    ( ////r/   )__branch_from__can_reconnect
__in_begin__savepoint_seqr   r   r   r   r  r   r  r   r   r   r   r   )NFNNNNTFri   NN)W__name__
__module____qualname____firstlineno____doc__r`   _sqla_logger_namespacer  r-   r   memoized_propertyr:   rH   rL   propertyrR   rY   r]   rf   rj   rr   ry   r|   r   r   r'   r   r   r   r   r   rB   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%  rm   r0  r7  r/  rM  r@  r]  rf  rQ  rJ  r  r?  r  r  ra  r  r  r  r  r   classmethodr  r  
deprecatedr   r  __static_attributes__r4   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 
 

 $ $ 
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 
__	#2!2!h 
__	,00r/   r   c                       \ rS rSrSrS rSrg)r  i	  z3Implement the :class:`.ExceptionContext` interface.c                 p    X0l         X@l        X l        Xl        Xl        X`l        Xpl        Xl        Xl        g ri   )	r   r'   r  original_exceptionexecution_contextrE  r  r  r  )r&   r   r  r   r'   r  rE  r  r  r  r  s              r,   r-   ExceptionContextImpl.__init__	  s6     $$8!"+!("$*-J*r/   )	r'   r   r  r  r  r  r  r  rE  N)r  r  r  r  r  r-   r  r4   r/   r,   r  r  	  s    =Kr/   r  c                       \ rS rSrSrSrSrS rS r\	S 5       r
S rS	 rS
 r\	S 5       rS rS rS rS rS rS rS rSrg)Transactioni	  a  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
r4   Fc                     [        5       eri   NotImplementedErrorr&   r'   s     r,   r-   Transaction.__init__E	      !##r/   c                     [        5       e)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  rQ   s    r,   _do_deactivateTransaction._do_deactivateH	  s     "##r/   c                     [        5       e)zsTrue if this transaction is totally deactivated from the connection
and therefore can no longer affect its state.

r  rQ   s    r,   _deactivated_from_connection(Transaction._deactivated_from_connectionY	  s     "##r/   c                     [        5       eri   r  rQ   s    r,   	_do_closeTransaction._do_closea	  r  r/   c                     [        5       eri   r  rQ   s    r,   _do_rollbackTransaction._do_rollbackd	  r  r/   c                     [        5       eri   r  rQ   s    r,   
_do_commitTransaction._do_commitg	  r  r/   c                 ^    U R                   =(       a    U R                  R                  (       + $ ri   )r   r'   r   rQ   s    r,   r   Transaction.is_validj	  s    ~~Adoo&A&A"AAr/   c                 |     U R                  5         U R                  (       a   eg! U R                  (       a   ef = f)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   rQ   s    r,   rm   Transaction.closen	  s0    	&NN~~%%~t~~%%~   & ;c                 |     U R                  5         U R                  (       a   eg! U R                  (       a   ef = f)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   rQ   s    r,   r   Transaction.rollback~	  s2    "	&~~%%~t~~%%~r%  c                 |     U R                  5         U R                  (       a   eg! U R                  (       a   ef = f)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   rQ   s    r,   r   Transaction.commit	  s0     	&OO~~%%~t~~%%~r%  c                     U R                   $ ri   )r'   rQ   s    r,   _get_subjectTransaction._get_subject	  s    r/   c                     U R                   $ ri   r   rQ   s    r,   _transaction_is_active"Transaction._transaction_is_active	  s    ~~r/   c                 $    U R                   (       + $ ri   )r  rQ   s    r,   _transaction_is_closed"Transaction._transaction_is_closed	  s    4444r/   c                     gNTr4   rQ   s    r,   _rollback_can_be_called#Transaction._rollback_can_be_called	  s    
 r/   N)r  r  r  r  r  	__slots___is_rootr-   r  r   r  r  r  r  r   rm   r   r   r+  r/  r2  r6  r  r4   r/   r,   r  r  	  sz    "H IH$$" $ $$$$ B B& &,&*5r/   r  c                   Z    \ rS rSrSrSrS r\S 5       r\S 5       r	S r
S rS	 rS
 rSrg)r   i	  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                    UR                   c   eUR                   R                  (       d  [        R                  " S5      eUR                  (       a   e[
        R                  " S5        Xl        UR                  (       a  [        R                  " U5        UR                  b  UR                  U l         OUR                   U l         SU l        g )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   r`   r   r   r'   r  r	   r  r   r;  r  s     r,   r-   MarkerTransaction.__init__	  s    &&222&&00))1 
 ((((,	
 %,, 11*=))5 * > >D * 7 7Dr/   c                 $    U R                   (       + $ ri   r.  rQ   s    r,   r  .MarkerTransaction._deactivated_from_connection	  s    >>!!r/   c                 T    U R                   =(       a    U R                  R                  $ ri   )r;  r   r   rQ   s    r,   r   MarkerTransaction.is_active	  s    >4#4#4#>#>>r/   c                     SU l         g NF)r;  rQ   s    r,   _deactivateMarkerTransaction._deactivate	  s	    r/   c                 $    U R                  5         g ri   rD  rQ   s    r,   r  MarkerTransaction._do_close	  s    r/   c                     U R                   (       a,   U R                  R                  5         U R                  5         g g ! U R                  5         f = fri   )r;  r   r  rD  rQ   s    r,   r  MarkerTransaction._do_rollback	  sA    ??#!!002  "	    "s	   ? Ac                 $    U R                  5         g ri   rG  rQ   s    r,   r  MarkerTransaction._do_commit	      r/   )r;  r   r'   N)r  r  r  r  r  r8  r-   r   r  r   rD  r  r  r  r  r4   r/   r,   r   r   	  sO     =I8 " " ? ? #r/   r   c                   p    \ rS rSrSrSrSrS rS r\	S 5       r
S rS	 rS
 rS rSS jrS rS rS rSrg)r   i	  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                     UR                   b   eUR                  (       a  [        R                  " U5        Xl        U R                  5         Xl         SU l        g r5  )r   r  r	   r  r'   _connection_begin_implr   r  s     r,   r-   RootTransaction.__init__
  sI    &&...,, 11*=$##%"&r/   c                     U R                   (       a#  U R                  R                  U L d   eSU l         g U R                  R                  U La  [        R                  " S5        g g )NFz0transaction already deassociated from connection)r   r'   r   r   warnrQ   s    r,   _deactivate_from_connection+RootTransaction._deactivate_from_connection
  sL    >>??//4777"DN__))5IIHI 6r/   c                 2    U R                   R                  U L$ ri   )r'   r   rQ   s    r,   r  ,RootTransaction._deactivated_from_connection&
  s    ++477r/   c                    U R                   R                  U L d   eU R                  (       a  U R                  5         U R                   R                  (       a$  U R                   R                  R                  5         U R                  5         g ri   )r'   r   r   _connection_rollback_implr   _cancelrT  rQ   s    r,   r  RootTransaction._do_deactivate*
  s`     ++t333>>**,
 ??..OO//779((*r/   c                 :    U R                   R                  U 5        g ri   )r'   r   rQ   s    r,   rP  &RootTransaction._connection_begin_impl?
  s    ##D)r/   c                 8    U R                   R                  5         g ri   )r'   r   rQ   s    r,   rY  )RootTransaction._connection_rollback_implB
  s    &&(r/   c                 8    U R                   R                  5         g ri   )r'   r   rQ   s    r,   _connection_commit_impl'RootTransaction._connection_commit_implE
  s    $$&r/   c                 v    U R                   (       a  U R                  5         U R                  R                  (       a$  U R                  R                  R	                  5         U R                   (       d  U(       a  U R                  5         U R                  R                  U L a  S U R                  l        U R                   (       a   eU R                  R                  U Ld   eg ! U R                   (       d  U(       a  U R                  5         U R                  R                  U L a  S U R                  l        f f = fri   )r   rY  r'   r   rZ  rT  r   )r&   try_deactivates     r,   _close_impl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D8c                 $    U R                  5         g ri   re  rQ   s    r,   r  RootTransaction._do_closeX
  rM  r/   c                 "    U R                  SS9  g )NT)rd  rh  rQ   s    r,   r  RootTransaction._do_rollback[
  s    -r/   c                    U R                   (       a  U R                  R                  U L d   e U R                  5         U R                  R                  (       a$  U R                  R                  R                  5         U R                  5         S U R                  l        OJU R                  R                  U L a  U R                  R                  5         O[        R                  " S5      eU R                   (       a   eU R                  R                  U Ld   eg ! U R                  R                  (       a$  U R                  R                  R                  5         U R                  5         f = f)NThis transaction is inactive)
r   r'   r   ra  r   rZ  rT  r   r   r   rQ   s    r,   r  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  r9  r8  r-   rT  r   r  r  rP  rY  ra  re  r  r  r  r  r4   r/   r,   r   r   	  sZ    * H+IJ 8 8+**)'8 .8r/   r   c                   `    \ rS rSrSrSrS rSS jr\S 5       r	S r
S rS	 rS
 rS rS rSrg)r   i{
  aP  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                     UR                   c   eUR                  (       a  [        R                  " U5        Xl        U R                  R                  5       U l        SU l        UR                  U l	        Xl        g r5  )
r   r  r	   r  r'   r   rp  r   r   rq  r  s     r,   r-   NestedTransaction.__init__
  s_    &&222,, 11*=$//99; * > >)-&r/   c                     U R                   R                  U L a  U R                  U R                   l        g U(       a  [        R                  " S5        g g )Nz7nested transaction already deassociated from connection)r'   r   rq  r   rS  )r&   rS  s     r,   rT  -NestedTransaction._deactivate_from_connection
  s=    ??..$6262G2GDOO/III r/   c                 2    U R                   R                  U L$ ri   )r'   r   rQ   s    r,   r  .NestedTransaction._deactivated_from_connection
  s    22$>>r/   c                     SU l         U R                  5         U R                  (       a  U R                  R                  5         g g rC  )r   rT  rq  rZ  rQ   s    r,   rZ  NestedTransaction._cancel
  s7     ((*  !!))+ !r/   c                     U R                   (       aJ  U R                  R                  R                   (       a%  U R                  R                  U R                  5        SU l         U(       a  U R                  US9  U R                   (       a   eU(       a  U R                  R                  U Ld   eg g ! SU l         U(       a  U R                  US9  f f = f)NF)rS  )r   r'   r   r  rp  rT  r   )r&   deactivate_from_connectionwarn_already_deactives      r,   re  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B1 1 Cc                 (    U R                  SS5        g rC  rh  rQ   s    r,   r   NestedTransaction._do_deactivate
  s    &r/   c                 (    U R                  SS5        g )NTFrh  rQ   s    r,   r  NestedTransaction._do_close
  s    u%r/   c                 (    U R                  SS5        g r5  rh  rQ   s    r,   r  NestedTransaction._do_rollback
  s    t$r/   c                 L   U R                   (       a>   U R                  R                  U R                  5        SU l         U R	                  5         g U R                  R
                  U L a  U R                  R                  5         g [        R                  " S5      e! SU l         f = f)NFz#This nested transaction is inactive)	r   r'   r
  rp  rT  r   r   r   r   rQ   s    r,   r  NestedTransaction._do_commit
  s~    >>'77H
 "' ,,.22d:446--9  "'s   %B 	B#)rq  rp  r'   r   NT)r  r  r  r  r  r8  r-   rT  r   r  rZ  re  r  r  r  r  r  r4   r/   r,   r   r   {
  sL    > NI. ? ?,C'&%r/   r   c                   H   ^  \ rS rSrSrSrU 4S jrS rS rS r	S r
S	rU =r$ )
r   i
  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                 F   > SU l         X l        [        [        U ]  U5        g rC  )r  r   superr   r-   )r&   r'   r   ra   s      r,   r-   TwoPhaseTransaction.__init__
  s     !!41*=r/   c                     U R                   (       d  [        R                  " S5      eU R                  R	                  U R
                  5        SU l        g)zaPrepare this :class:`.TwoPhaseTransaction`.

After a PREPARE, the transaction can be committed.

rm  TN)r   r   r   r'   r  r   r  rQ   s    r,   prepareTwoPhaseTransaction.prepare
  s;     ~~))*HII..txx8 r/   c                 :    U R                   R                  U 5        g ri   )r'   r  rQ   s    r,   rP  *TwoPhaseTransaction._connection_begin_impl  s    ,,T2r/   c                 d    U R                   R                  U R                  U R                  5        g ri   )r'   r  r   r  rQ   s    r,   rY  -TwoPhaseTransaction._connection_rollback_impl  s     //$:K:KLr/   c                 d    U R                   R                  U R                  U R                  5        g ri   )r'   r  r   r  rQ   s    r,   ra  +TwoPhaseTransaction._connection_commit_impl  s     --dhh8I8IJr/   )r  r   )r  r  r  r  r  r8  r-   r  rP  rY  ra  r  __classcell__)ra   s   @r,   r   r   
  s1     CI>
	!3MK Kr/   r   c                      \ rS rSrSr\rSr\r	Sr
SrSr     S.S jrS r\S 5       rS	 rS
 rS rS r\S 5       r\S 5       r\R0                  " 5       rS rS/S jrS\R:                  4S jr\R@                  S0S j5       r! " S S\"5      r#S1S jr$\RJ                  " SS5      S 5       r&\RJ                  " SS5      S 5       r'S r(\RR                  " SSS9S  5       r*\RR                  " S!S"S9S# 5       r+SS\4S$ jr,\4S% jr-S1S& jr.\RJ                  " SS'5      S2S( j5       r/\RJ                  " SS)5      S0S* j5       r0S+ r1S0S, jr2S-r3g)3Enginei  a	  
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	                    Xl         X0l        X l        U(       a  X@l        XPl        Xl        US:w  a$  [        R                  " X`R                  S9U l	        OS U l	        [        R                  " XS9  U(       a  U R                  " S0 UD6  g g )Nr   )
size_alertechoflagr4   )r  urlr   logging_nameechor  r   LRUCache_lru_size_alertrv  r   instance_loggerupdate_execution_options)	r&   r  r   r  r  r  query_cache_sizery   r  s	            r,   r-   Engine.__init__,  s{     	 ,	.q #'== -A-A$D  $(D D0))>,=> r/   c                     U R                   (       a1  U R                  R                  S[        U5      UR                  5        g g )NziCompiled cache size pruning from %d items to %d.  Increase cache size to reduce the frequency of pruning.)r#   rA   rB   ri  capacity)r&   caches     r,   r  Engine._lru_size_alertH  s6      KKJE
	 !r/   c                     U $ ri   r4   rQ   s    r,   r   Engine.engineQ  s    r/   c                 \    U R                   (       a  U R                   R                  5         gg)aX  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)rv  clearrQ   s    r,   clear_compiled_cacheEngine.clear_compiled_cacheU  s$       &&(  r/   c                     U R                   R                  U5      U l         U R                  R                  X5        U R                  R                  X5        g)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   rv   r   set_engine_execution_optionsr   r&   rx   s     r,   r  Engine.update_execution_optionsc  sA    " #'"9"9"?"?"D224=11$<r/   c                 $    U R                  X5      $ )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_clsr  s     r,   ry   Engine.execution_optionsx  s    T **r/   c                     U R                   $ )zGet the non-SQL options which will take effect during execution.

.. versionadded: 1.3

.. seealso::

    :meth:`_engine.Engine.execution_options`
r9   rQ   s    r,   r|   Engine.get_execution_options  r~   r/   c                 .    U R                   R                  $ )zaString name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
in use by this :class:`Engine`.)r   rX   rQ   s    r,   rX   Engine.name  s    
 ||   r/   c                 .    U R                   R                  $ )zaDriver name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
in use by this :class:`Engine`.)r   driverrQ   s    r,   r  Engine.driver  s    
 ||"""r/   c                 $    SU R                   < S3$ )NzEngine())r  rQ   s    r,   __repr__Engine.__repr__  s    #xx))r/   c                     U(       a  U R                   R                  5         U R                   R                  5       U l         U R                  R	                  U 5        g)aA  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&   rm   s     r,   r  Engine.dispose  s>    J IIII&&(	%%d+r/   r4   c                 |    U R                  5        nUR                  XU5      sS S S 5        $ ! , (       d  f       g = fri   )r   r]  )r&   rV  r3  r4  r+  s        r,   r]  Engine._execute_default  s)     \\^t((vF ^^s   -
;c              #   x   #    Uc  U R                  5        nUv   S S S 5        g Uv   g ! , (       d  f       g = f7fri   )r   )r&   r'   r+  s      r,   _optional_conn_ctx_manager!Engine._optional_conn_ctx_manager  s1     4
     s   :):
7:c                   &    \ rS rSrS rS rS rSrg)Engine._trans_ctxi  c                 (    Xl         X l        X0l        g ri   )r+  r   r(   )r&   r+  r   r(   s       r,   r-   Engine._trans_ctx.__init__  s    I*%6"r/   c                 N    U R                   R                  5         U R                  $ ri   )r   rj   r+  rQ   s    r,   rj   Engine._trans_ctx.__enter__   s    &&(99r/   c                      U R                   R                  XU5        U R                  (       d  U R                  R	                  5         g g ! U R                  (       d  U R                  R	                  5         f f = fri   )r   rr   r(   r+  rm   rn   s       r,   rr   Engine._trans_ctx.__exit__$  sV    &  ))%	B--IIOO% .t--IIOO% .s   A .A9)r(   r+  r   N)r  r  r  r  r-   rj   rr   r  r4   r/   r,   
_trans_ctxr    s    	7
		&r/   r  c                 X   U R                   R                  (       a  U R                  5       nOU R                  US9n UR                  5       n[        R                  UWU5      $ !   [        R
                  " 5          UR                  5         SSS5         MJ  ! , (       d  f        NY= f= f)a  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)	r\   r`   r   r   r   r  rm   r  r  )r&   r(   r+  r  s       r,   r   Engine.begin+  s    F **<<>D<<2C<DD	JJLE   u.?@@	""$

 %$$$s)   A$ $B);B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                     SUS'   U R                  5        nUR                  " U/UQ70 UD6sSSS5        $ ! , (       d  f       g= f)aL  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  r  r  r+  s        r,   r   Engine.transactionY  s=    ^ &*!"\\^t##I??? ^^	   6
A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                     SUS'   U R                  5        nUR                  " U/UQ70 UD6sSSS5        $ ! , (       d  f       g= f)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  r  s        r,   r  Engine.run_callable  s<    ( &*!"\\^t$$Y@@@ ^^r  c                 ~    U R                  5        nUR                  " X40 UD6  S S S 5        g ! , (       d  f       g = fri   )r   r  )r&   r  r  r  r+  s        r,   r  Engine._run_ddl_visitor  s*    ZZ\T!!/EfE \\s   .
<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                 L    U R                  SS9nUR                  " U/UQ70 UD6$ )ag  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.

Tr  )r   r/  )r&   rE  r3  r4  r'   s        r,   r/  Engine.execute  s/    4 \\D\9
!!)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    U R                   " U/UQ70 UD6R                  5       $ )zqExecutes and returns the first column of the first row.

The underlying result/cursor is closed after execution.
r.  )r&   rE  r3  r4  s       r,   r0  Engine.scalar  s&     ||I>>v>EEGGr/   c                 D    U R                  SS9nUR                  XX45      $ NTr  )r   rJ  )r&   rl  r3  r4  ry   r'   s         r,   rJ  Engine._execute_clauseelement  s,     \\D\9
00v
 	
r/   c                 D    U R                  SS9nUR                  XX45      $ r  )r   r  )r&   re  r3  r4  ry   r'   s         r,   r  Engine._execute_compiled  s,     \\D\9
++6
 	
r/   c                      U R                  XS9$ )a4  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`.

r  )r\   r   s     r,   r   Engine.connect  s     ##D#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                     U R                  U5       n[        R                  " U5      nUR                  U5      sSSS5        $ ! , (       d  f       g= f)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)r  r   inspectget_table_names)r&   rU   r'   r+  insps        r,   table_namesEngine.table_names  s>     ,,Z8D%%d+D''/ 988s   '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                     U R                  S5       n[        R                  " U5      nUR                  XS9sSSS5        $ ! , (       d  f       g= f)a0  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)rU   )r  r   r  	has_table)r&   
table_namerU   r+  r  s        r,   r  Engine.has_table  s>    & ,,T2d%%d+D>>*>< 322s   %A
Ac                 6   U R                   n U" 5       $ ! UR                  R                   ai  nUc  [        R	                  XCU 5         S nAg [
        R                  " [        R                  " 5       S   [        R                  " 5       S   S9   S nAg S nAff = f)Nr   r
   r  )	r   r  r  r   r  r   rC  r  r  )r&   rm  r'   r   r   s        r,   _wrap_pool_connectEngine._wrap_pool_connect(  sx    ,,
	4K}}"" 	!??  LLN1%cllnQ6G	s    BBABBc                 N    U R                  U R                  R                  U5      $ )a  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   Engine.raw_connection6  s!    , &&tyy'8'8+FFr/   )rv  r   r   r  r  r  r  r  )NNi  NFr  ri   r  r  )4r  r  r  r  r  r@  r   r   r   r\   r  r`   rR   r-   r  r   r   r  r  ry   r|   rX   r  r   echo_propertyr  r  r  r   
EMPTY_DICTr]  
contextlibcontextmanagerr  objectr  r   r  r   r  r  r  r/  r0  rJ  r  r   r  r  r  r   r  r4   r/   r,   r  r    s   ( /K O7J  ?8  )=*J+X	' ! ! # # D*(,V $&dooG  &V &",A\ 
__	)@)@V 
__	#AA"F 
(EE* 
'*	H	H /

" 0

O" 
__	9	0	0 
__	3== Gr/   r  c                   Z    \ rS rSrSrS rS rS r\" \\5      r	S r
S r\" \
\5      rSrg	)
OptionEngineMixiniO  Fc                    Xl         UR                  U l        UR                  U l        UR                  U l        UR                  U l        UR
                  U l        UR                  U l        [        R                  " X R                  S9  U R                  R                  UR                  5      U l	        UR                  U l        U R                  " S0 UD6  g )Nr  r4   )_proxiedr  r   r  r  rv  r  r   r  r   r$   r   r  )r&   proxiedry   s      r,   r-   OptionEngineMixin.__init__R  s    ;;#00LL	&66&66D995 ++G,<,<=")"<"<%%:(9:r/   c                 .    U R                   R                  $ ri   r  r  rQ   s    r,   	_get_poolOptionEngineMixin._get_poolm  s    }}!!!r/   c                 $    XR                   l        g ri   r  )r&   r  s     r,   	_set_poolOptionEngineMixin._set_poolp  s    !r/   c                 t    U R                   R                  =(       d    U R                  R                  SS5      $ )Nr   F)r  r   rc   rP   rQ   s    r,   _get_has_events!OptionEngineMixin._get_has_eventsu  s/    }}(( 
DMM,=,=5-
 	
r/   c                      XR                   S'   g )Nr   )rc   )r&   rp   s     r,   _set_has_events!OptionEngineMixin._set_has_eventsz  s    ',m$r/   )	rv  r   r  r   r   r  r  r  r  N)r  r  r  r  _sa_propagate_class_eventsr-   r  r
  r   r  r  r  r   r  r4   r/   r,   r   r   O  s=    !&;6"" Iy)D

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