Files
Home-AssistantConfig/deps/sqlalchemy/engine/__pycache__/base.cpython-34.pyc

987 lines
68 KiB
Plaintext
Raw Normal View History

2016-10-11 16:42:06 +00:00
<EFBFBD>
}<7D><>W#6<00>@s:ddlmZddlZddlmZmZmZmZddlmZ ddlm
Z
m Z ddlm Z ddl Z Gd d
<00>d
e
<00>ZGd d <00>d e <00>ZGd d<00>de<00>ZGdd<00>de<00>ZGdd<00>de<00>ZGdd<00>de<00>ZGdd<00>de
ej<00>ZGdd<00>de<00>ZdS)<19>)<01>with_statementN<74>)<04>exc<78>util<69>log<6F>
interfaces)r<00>)<02> Connectable<6C>ExceptionContext)<01>_distill_paramsc@seZdZdZdddddddd<00>Zdd<00>Zedd <00><00>Zd
d <00>Zd d <00>Z dd<00>Z
dd<00>Z edd<00><00>Z edd<00><00>Z edd<00><00>Zdd<00>Zedd<00><00>Zdd<00>Zedd<00><00>Zed d!<00><00>Zed"d#<00><00>Zd$d%<00>Zd&d'<00>Zdd(d)<00>Zd*d+<00>Zd,d-<00>Zd.d/<00>Zdd0d1<00>Zd2d3<00>Zdd4d5<00>Zdd6d7<00>Zd8d9<00>Zd:d;<00>Z d<d=<00>Z!dd>d?<00>Z"dd@dA<00>Z#dBdC<00>Z$dDdE<00>Z%dFdG<00>Z&dHdI<00>Z'dJdK<00>Z(dLdM<00>Z)dNdO<00>Z*dPdQ<00>Z+dRdS<00>Z,dTdU<00>Z-dVdW<00>Z.dXdY<00>Z/dZd[<00>Z0d\d]<00>Z1d^d_<00>Z2d`da<00>Z3dbdc<00>Z4dddde<00>Z5dfdg<00>Z6dZ7dZ8dhdi<00>Z9e:djdk<00><00>Z;dldm<00>Z<dndo<00>Z=dpdq<00>Z>drds<00>Z?dS)t<>
Connectiona:Provides high-level functionality for a wrapped DB-API connection.
Provides execution support for string-based SQL statements as well as
:class:`.ClauseElement`, :class:`.Compiled` and :class:`.DefaultGenerator`
objects. Provides a :meth:`begin` method to return :class:`.Transaction`
objects.
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
NFcCsb||_|j|_||_|dk |_|rr||_||_|j|_d|_||_|j |_ n<>|dk r<>|n |j
<00>|_d|_ d|_ ||_d|_ d|_|jj<00>|_|dkr<>|jj|j<00>|_n|p|dko|j |_ | s$t<00>|j|_|j sE|jj r^|jj||j<00>ndS)z<>Construct a new Connection.
The constructor here is not public and is only called only by an
:class:`.Engine`. See :meth:`.Engine.connect` and
:meth:`.Engine.contextual_connect` methods.
NFrT)<13>engine<6E>dialect<63>_Connection__branch_fromZ_Connection__branch<63>_Connection__connection<6F>_execution_options<6E>_echo<68>should_close_with_result<6C>dispatch<63> _has_events<74>raw_connection<6F>_Connection__transaction<6F>_Connection__savepoint_seq<65>_Connection__invalid<69>_Connection__can_reconnectZ_should_log_info<66>_join<69>AssertionErrorZengine_connect)<08>selfr <00>
connection<EFBFBD>close_with_result<6C> _branch_fromr<00> _dispatchr<00>r"<00></tmp/pip-build-zkr322cu/sqlalchemy/sqlalchemy/engine/base.py<70>__init__/s4        !        zConnection.__init__c CsT|jr|jj<00>S|jj|j|jd|d|jd|jd|j<00>SdS)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.
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() or
contextual_connect() methods are called. The branched connection
acts as much as possible like the parent, except that it stays
connected when a close() event occurs.
r rrr!N)r<00>_branchr <00>_connection_clsrrrr)rr"r"r#r%^s      zConnection._branchcCs|jr|jS|SdS)z<>return the 'root' connection.
Returns 'self' if this connection is not a branch, else
returns the root connection from which we ultimately branched.
N)r)rr"r"r#<00>_rootys zConnection._rootcCs+|jj|j<00>}|jj<00>|_|S)z3Create a shallow copy of this Connection.
)<04> __class__<5F>__new__<5F>__dict__<5F>copy)r<00>cr"r"r#<00>_clone<6E>szConnection._clonecCs|S)Nr")rr"r"r#<00> __enter__<5F>szConnection.__enter__cCs|j<00>dS)N)<01>close)r<00>type<70>value<75> tracebackr"r"r#<00>__exit__<5F>szConnection.__exit__cKsc|j<00>}|jj|<00>|_|js6|jjrL|jj||<00>n|jj||<00>|S)a$ Set non-SQL options for the connection which take effect
during execution.
The method returns a copy of this :class:`.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:`.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:`.Connection.execution_options`, and it will be stored in the
``_execution_options`` dictionary of the :class:`.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:`.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 DBAPI
connections by default are always in a transaction - SQLAlchemy uses
rules applied to different kinds of statements to determine if
COMMIT will be invoked in order to provide its "autocommit" feature.
Typically, all INSERT/UPDATE/DELETE statements as well as
CREATE/DROP statements have autocommit behavior enabled; SELECT
constructs do not. Use this option when invoking a SELECT or other
specific SQL construct where COMMIT is desired (typically when
calling stored procedures and such), and an explicit
transaction is not in progress.
:param compiled_cache: Available on: Connection.
A dictionary where :class:`.Compiled` objects
will be cached when the :class:`.Connection` compiles a clause
expression into a :class:`.Compiled` object.
It is the user's responsibility to
manage the size of this dictionary, which will have keys
corresponding to the dialect, clause element, the column
names within the VALUES or SET clause of an INSERT or UPDATE,
as well as the "batch" mode for an INSERT or UPDATE statement.
The format of this dictionary is not guaranteed to stay the
same in future releases.
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 isolation_level: Available on: :class:`.Connection`.
Set the transaction isolation level for
the lifespan of this :class:`.Connection` object (*not* the
underyling DBAPI connection, for which the level is reset
to its original setting upon termination of this
:class:`.Connection` object).
Valid values include
those string values accepted by the
:paramref:`.create_engine.isolation_level`
parameter passed to :func:`.create_engine`. These levels are
semi-database specific; see individual dialect documentation for
valid levels.
Note that this option necessarily affects the underlying
DBAPI connection for the lifespan of the originating
:class:`.Connection`, and is not per-execution. This
setting is not removed until the underlying DBAPI connection
is returned to the connection pool, i.e.
the :meth:`.Connection.close` method is called.
.. warning:: The ``isolation_level`` execution option should
**not** be used when a transaction is already established, that
is, the :meth:`.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.
.. versionchanged:: 0.9.9 A warning is emitted when the
``isolation_level`` execution option is used after a
transaction has been started with :meth:`.Connection.begin`
or similar.
.. note:: The ``isolation_level`` execution option is implicitly
reset if the :class:`.Connection` is invalidated, e.g. via
the :meth:`.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:`.create_engine.isolation_level`
- set per :class:`.Engine` isolation level
:meth:`.Connection.get_isolation_level` - view current level
:ref:`SQLite Transaction Isolation <sqlite_isolation_level>`
:ref:`Postgresql Transaction Isolation <postgresql_isolation_level>`
:ref:`MySQL Transaction Isolation <mysql_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.
.. versionadded:: 0.7.6
:param stream_results: Available on: Connection, statement.
Indicate to the dialect that results should be
"streamed" and not pre-buffered, if possible. This is a limitation
of many DBAPIs. The flag is currently understood only by the
psycopg2 dialect.
)r-r<00>unionrr rZ set_connection_execution_optionsr)r<00>optr,r"r"r#<00>execution_options<6E>s <00> zConnection.execution_optionscCsd|jko|j S)z)Return True if this connection is closed.r)r*r)rr"r"r#<00>closed szConnection.closedcCs
|jjS)z/Return True if this connection was invalidated.)r'r)rr"r"r#<00> invalidated'szConnection.invalidatedcCssy |jSWnatk
rny|j<00>SWn>tk
ri}z|j|dddd<00>WYdd}~XnXYnXdS)z<>The underlying DB-API connection managed by this Connection.
.. seealso::
:ref:`dbapi_connections`
N)r<00>AttributeError<6F>_revalidate_connection<6F> Exception<6F>_handle_dbapi_exception)r<00>er"r"r#r-s   zConnection.connectioncCs\y|jj|j<00>SWn>tk
rW}z|j|dddd<00>WYdd}~XnXdS)a<>Return the current isolation level assigned to this
:class:`.Connection`.
This will typically be the default isolation level as determined
by the dialect, unless if the
:paramref:`.Connection.execution_options.isolation_level`
feature has been used to alter the isolation level on a
per-:class:`.Connection` basis.
This attribute will typically perform a live SQL operation 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. Compare to the
:attr:`.Connection.default_isolation_level` accessor
which returns the dialect-level setting without performing a SQL
query.
.. versionadded:: 0.9.9
.. seealso::
:attr:`.Connection.default_isolation_level` - view default level
:paramref:`.create_engine.isolation_level`
- set per :class:`.Engine` isolation level
:paramref:`.Connection.execution_options.isolation_level`
- set per :class:`.Connection` isolation level
N)r<00>get_isolation_levelrr;r<)rr=r"r"r#r>@szConnection.get_isolation_levelcCs
|jjS)a<>The default isolation level assigned to this :class:`.Connection`.
This is the isolation level setting that the :class:`.Connection`
has when first procured via the :meth:`.Engine.connect` method.
This level stays in place until the
:paramref:`.Connection.execution_options.isolation_level` is used
to change the setting on a per-:class:`.Connection` basis.
Unlike :meth:`.Connection.get_isolation_level`, this attribute is set
ahead of time from the first connection procured by the dialect,
so SQL query is not invoked when this accessor is called.
.. versionadded:: 0.9.9
.. seealso::
:meth:`.Connection.get_isolation_level` - view current level
:paramref:`.create_engine.isolation_level`
- set per :class:`.Engine` isolation level
:paramref:`.Connection.execution_options.isolation_level`
- set per :class:`.Connection` isolation level
)r<00>default_isolation_level)rr"r"r#r?dsz"Connection.default_isolation_levelcCs<>|jr|jj<00>S|jrq|jrq|jdk rItjd<00><00>n|jjd|<00>|_ d|_|j Stj
d<00><00>dS)Nz8Can't reconnect until invalid transaction is rolled back<63> _connectionFzThis Connection is closed) rr:rrrr<00>InvalidRequestErrorr rr<00>ResourceClosedError)rr"r"r#r:<00>s    z!Connection._revalidate_connectioncCst|jdd<00>S)N<>is_validF)<02>getattrr)rr"r"r#<00>_connection_is_valid<69>szConnection._connection_is_validcCs'|j o&|j o&t|jdd<00>S)NrCF)r7r8rDr)rr"r"r#<00>#_still_open_and_connection_is_valid<69>s

z.Connection._still_open_and_connection_is_validcCs
|jjS)a<>Info dictionary associated with the underlying DBAPI connection
referred to by this :class:`.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:`.Connection`.
)r<00>info)rr"r"r#rG<00>s zConnection.infocCs
|j<00>S)aiReturns a branched version of this :class:`.Connection`.
The :meth:`.Connection.close` method on the returned
:class:`.Connection` can be called and this
:class:`.Connection` will remain open.
This method provides usage symmetry with
:meth:`.Engine.connect`, including for usage
with context managers.
)r%)rr"r"r#<00>connect<63>s zConnection.connectcKs
|j<00>S)atReturns a branched version of this :class:`.Connection`.
The :meth:`.Connection.close` method on the returned
:class:`.Connection` can be called and this
:class:`.Connection` will remain open.
This method provides usage symmetry with
:meth:`.Engine.contextual_connect`, including for usage
with context managers.
)r%)r<00>kwargsr"r"r#<00>contextual_connect<63>s zConnection.contextual_connectcCsc|jr dS|jr(tjd<00><00>n|jjrJ|jjj|<00>n|j`d|j_dS)a<>Invalidate the underlying DBAPI connection associated with
this :class:`.Connection`.
The underlying DBAPI connection is literally closed (if
possible), and is discarded. Its source connection pool will
typically lazily create a new connection to replace it.
Upon the next use (where "use" typically means using the
:meth:`.Connection.execute` method or similar),
this :class:`.Connection` will attempt to
procure a new DBAPI connection using the services of the
:class:`.Pool` as a source of connectivty (e.g. a "reconnection").
If a transaction was in progress (e.g. the
:meth:`.Connection.begin` method has been called) when
:meth:`.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:`.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:`.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:`.Connection.invalidate` method, just like auto-invalidation,
will at the connection pool level invoke the
:meth:`.PoolEvents.invalidate` event.
.. seealso::
:ref:`pool_connection_invalidation`
NzThis Connection is closedT) r8r7rrBr'rEr<00>
invalidater)r<00> exceptionr"r"r#rK<00>s'    zConnection.invalidatecCs|jj<00>dS)aDetach the underlying DB-API connection from its connection pool.
E.g.::
with engine.connect() as conn:
conn.detach()
conn.execute("SET search_path TO schema1, schema2")
# work with connection
# connection is fully closed (since we used "with:", can
# also call .close())
This :class:`.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<00>detach)rr"r"r#rM<00>szConnection.detachcCsO|jr|jj<00>S|jdkr;t|<00>|_|jSt||j<00>SdS)aBegin 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.
Nested calls to :meth:`.begin` on the same :class:`.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.
See also:
:meth:`.Connection.begin_nested` - use a SAVEPOINT
:meth:`.Connection.begin_twophase` - use a two phase /XID transaction
:meth:`.Engine.begin` - context manager available from
:class:`.Engine`.
N)r<00>beginr<00>RootTransaction<6F> Transaction)rr"r"r#rNs "  zConnection.begincCsS|jr|jj<00>S|jdkr7t|<00>|_nt||j<00>|_|jS)aBegin a nested transaction and return a transaction handle.
The returned object is an instance of :class:`.NestedTransaction`.
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.
See also :meth:`.Connection.begin`,
:meth:`.Connection.begin_twophase`.
N)r<00> begin_nestedrrO<00>NestedTransaction)rr"r"r#rQAs   zConnection.begin_nestedcCsw|jr|jjd|<00>S|jdk r=tjd<00><00>n|dkr^|jjj<00>}nt||<00>|_|jS)aBegin 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.
See also :meth:`.Connection.begin`,
:meth:`.Connection.begin_twophase`.
<20>xidNzOCannot start a two phase transaction when a transaction is already in progress.) r<00>begin_twophaserrrAr rZ
create_xid<EFBFBD>TwoPhaseTransaction)rrSr"r"r#rTXs   zConnection.begin_twophasecCs|jjj|<00>S)N)r rZdo_recover_twophase)rr"r"r#<00>recover_twophaseuszConnection.recover_twophasecCs |jjj||d|<00>dS)N<>recover)r r<00>do_rollback_twophase)rrSrWr"r"r#<00>rollback_preparedxszConnection.rollback_preparedcCs |jjj||d|<00>dS)NrW)r r<00>do_commit_twophase)rrSrWr"r"r#<00>commit_prepared{szConnection.commit_preparedcCs|jjdk S)z,Return True if a transaction is in progress.N)r'r)rr"r"r#<00>in_transaction~szConnection.in_transactioncCs<>|j st<00>|jr/|jjjd<00>n|jsD|jjrW|jj|<00>ny;|jj j
|j <00>|j j dkr<>||j _ nWn>t k
r<>}z|j|dddd<00>WYdd}~XnXdS)NzBEGIN (implicit))rrrr <00>loggerrGrrrNrZdo_beginr<00> _reset_agentr;r<)r<00> transactionr=r"r"r#<00> _begin_impl<70>s zConnection._begin_implcCs
|j st<00>|js%|jjr8|jj|<00>n|jr<>|jr`|jjj d<00>nz_y|jj
j |j <00>Wn>t k
r<>}z|j|dddd<00>WYdd}~XnXWd|j r<>|j j|jkr<>d|j _nd|_Xn d|_dS)NZROLLBACK)rrrr r<00>rollbackrFrr]rGrZ do_rollbackrr;r<rr^r)rr=r"r"r#<00>_rollback_impl<70>s  0
 zConnection._rollback_implcCs<>|j st<00>|js%|jjr8|jj|<00>n|jrW|jjjd<00>nz_y|jj j
|j <00>Wn>t k
r<>}z|j |dddd<00>WYdd}~XnXWd|j r<>|j j|jkr<>d|j _nd|_XdS)NZCOMMIT)rrrr r<00>commitrr]rGrZ do_commitrr;r<rr^r)r<00>
autocommitr=r"r"r#<00> _commit_impl<70>s 0
zConnection._commit_implcCs<>|j st<00>|js%|jjr;|jj||<00>n|dkrf|jd7_d|j}n|jr<>|jjj ||<00>|SdS)Nrzsa_savepoint_%s)
rrrr rZ savepointrrFrZ do_savepoint)r<00>namer"r"r#<00>_savepoint_impl<70>s  zConnection._savepoint_implcCsm|j st<00>|js%|jjr>|jj|||<00>n|jr`|jjj||<00>n||_ dS)N)
rrrr rZrollback_savepointrFrZdo_rollback_to_savepointr)rrf<00>contextr"r"r#<00>_rollback_to_savepoint_impl<70>s  z&Connection._rollback_to_savepoint_implcCsm|j st<00>|js%|jjr>|jj|||<00>n|jr`|jjj||<00>n||_ dS)N)
rrrr rZrelease_savepointrFrZdo_release_savepointr)rrfrhr"r"r#<00>_release_savepoint_impl<70>s  z"Connection._release_savepoint_implcCs<>|j st<00>|jr/|jjjd<00>n|jsD|jjr]|jj||j <00>n|j
r<>|jj j ||j <00>|j jdkr<>||j _q<>ndS)NzBEGIN TWOPHASE (implicit))rrrr r]rGrrrTrSrFrZdo_begin_twophaserr^)rr_r"r"r#<00>_begin_twophase_impl<70>s  zConnection._begin_twophase_implcCsy|j st<00>|js%|jjr;|jj||<00>n|jrut|jt <00>s\t<00>|jj
j ||<00>ndS)N) rrrr rZprepare_twophaserF<00>
isinstancerrUrZdo_prepare_twophase)rrSr"r"r#<00>_prepare_twophase_impl<70>s  z!Connection._prepare_twophase_implc Cs<>|j st<00>|js%|jjr>|jj|||<00>n|jr<>t|jt <00>s_t<00>z|jj
j |||<00>Wd|j j |jkr<>d|j _ nd|_Xn d|_dS)N)rrrr rZrollback_twophaserFrlrrUrrXrr^)rrS<00> is_preparedr"r"r#<00>_rollback_twophase_impl<70>s   z"Connection._rollback_twophase_implc Cs<>|j st<00>|js%|jjr>|jj|||<00>n|jr<>t|jt <00>s_t<00>z|jj
j |||<00>Wd|j j |jkr<>d|j _ nd|_Xn d|_dS)N)rrrr rZcommit_twophaserFrlrrUrrZrr^)rrSrnr"r"r#<00>_commit_twophase_impls  z Connection._commit_twophase_implcCs#|jj<00>s|jj<00>ndS)N)r'r\rb)rr"r"r#<00> _autorollbackszConnection._autorollbackcCs<>|jr@z#y
|`Wntk
r*YnXWdd|_dSXny |j}Wntk
raYn;X|j<00>|j|jkr<>d|_n|js<>|`nd|_d|_dS)a8Close this :class:`.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` referenced
by the :class:`.Engine` that produced this
:class:`.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:`.Connection`.
After :meth:`~.Connection.close` is called, the
:class:`.Connection` is permanently in a closed state,
and will allow no further operations.
NF)rrr9rr/r^rr)r<00>connr"r"r#r/s$ 
     
    zConnection.closecOs|j|||<00>j<00>S)z<>Executes and returns the first column of the first row.
The underlying result/cursor is closed after execution.
)<02>execute<74>scalar)r<00>object<63> multiparams<6D>paramsr"r"r#rtFszConnection.scalarc Osxt|tjd<19>r)|j|||<00>Sy |j}Wn+tk
rctjdt|<00><16><00>YnX||||<00>SdS)a<>Executes a SQL statement construct and returns a
:class:`.ResultProxy`.
:param object: The statement to be executed. May be
one of:
* a plain string
* any :class:`.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
: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 <http://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.
rzUnexecutable object type: %sN) rlr<00> string_types<65> _execute_textZ_execute_on_connectionr9rrAr0)rrurvrw<00>methr"r"r#rsNs;  zConnection.executecCs|j|j<00>||<00>S)z%Execute a sql.FunctionElement object.)<02>_execute_clauseelement<6E>select)r<00>funcrvrwr"r"r#<00>_execute_function<6F>szConnection._execute_functionc
CsA|js|jjrMx5|jjD]$}|||||<00>\}}}q"WnySy |j}Wntk
r}|j<00>}YnX|j}|jj |||<00>}Wn>t
k
r<>}z|j |dddd<00>WYdd}~XnX|j |d<00>} |j r |j<00>n|js|jjr=|jj||||| <00>n| S)z&Execute a schema.ColumnDefault object.N)rr r<00>before_executerr9r:r<00>execution_ctx_clsZ _init_defaultr;r<Z _exec_defaultrr/<00> after_execute)
r<00>defaultrvrw<00>fnrrr<00>ctxr=<00>retr"r"r#<00>_execute_default<6C>s(%    ,   zConnection._execute_defaultcCs<>|js|jjrMx5|jjD]$}|||||<00>\}}}q"Wn|j}|jd|<00>}|j||jj|d|<00>}|js<>|jjr<>|jj |||||<00>n|S)zExecute a schema.DDL object.rN)
rr rrr<00>compile<6C>_execute_contextr<74>Z _init_ddlr<6C>)rZddlrvrwr<>r<00>compiledr<64>r"r"r#<00> _execute_ddl<64>s%    zConnection._execute_ddlc Cs<>|js|jjrMx5|jjD]$}|||||<00>\}}}q"Wnt||<00>}|ru|dj<00>}ng}|j}d|jkr ||tt |<00><00>t
|<00>dkf}|jdj |<00>} | dkrJ|j d|d|dt
|<00>dk<00>} | |jd|<qJn*|j d|d|dt
|<00>dk<00>} |j ||jj| || |<00>}
|js<>|jjr<>|jj|||||
<00>n|
S)z#Execute a sql.ClauseElement object.rZcompiled_cacherNrZ column_keys<79>inline)rr rrr <00>keysrr<00>tuple<6C>sorted<65>len<65>getr<74>r<>r<><00>_init_compiledr<64>) r<00>elemrvrwr<>Zdistilled_paramsr<73>r<00>keyZ compiled_sqlr<6C>r"r"r#r{<00>s:% *        z!Connection._execute_clauseelementcCs<>|js|jjrMx5|jjD]$}|||||<00>\}}}q"Wn|j}t||<00>}|j||jj||||<00>}|js<>|jjr<>|jj |||||<00>n|S)zExecute a sql.Compiled object.)
rr rrrr r<>r<>r<>r<>)rr<>rvrwr<>r<00>
parametersr<EFBFBD>r"r"r#<00>_execute_compiled<65>s%    zConnection._execute_compiledcCs<>|js|jjrMx5|jjD]$}|||||<00>\}}}q"Wn|j}t||<00>}|j||jj||||<00>}|js<>|jjr<>|jj |||||<00>n|S)zExecute a string SQL statement.)
rr rrrr r<>r<>Z_init_statementr<74>)r<00> statementrvrwr<>rr<>r<>r"r"r#rys%    zConnection._execute_textc #GsyGy |j}Wntk
r0|j<00>}YnX|||||<00>}WnGtk
r<>}z'|j|tj|<00>|dd<00>WYdd}~XnX|jr<>|j<00>n|j |j
|j } }}|j s<>|d}n|j s<>|jj r-x;|jjD]*}
|
|| ||||j <00>\}}q<>Wn|jrq|jjj|<00>|jjjdtj|dd<00><01>nd} y[|j r<>|jj r<>x9|jjjD]%}
|
| |||<00>r<>d} Pq<50>q<>Wn| s<>|jj| |||<00>q<>n<>| rg|jrg|jj rEx6|jjjD]"}
|
| ||<00>rd} PqqWn| s<>|jj| ||<00>q<>nj|jj r<>x9|jjjD]%}
|
| |||<00>r<>d} Pq<50>q<>Wn| s<>|jj| |||<00>nWn>tk
r}z|j|||| |<00>WYdd}~XnX|j s(|jj rM|jj|| ||||j <00>n|jrc|j<00>n|jsu|jr<>|j<00>} n.|j <00>} | j!dkr<>| j"dd<00>n|j#r<>|j$j%dkr<>|j$j&d d<00>n| j'r|j(r|j)<00>n| S)
z\Create an :class:`.ExecutionContext` and execute, returning
a :class:`.ResultProxy`.Nrz%rZbatches<65>
FTZ_autoclose_connectionrd)*rr9r:r;r<r<00> text_typer<65>Zpre_exec<65>cursorr<72>r<>Z executemanyrr r<00>before_cursor_executerr]rG<00>sql_utilZ _repr_paramsrZdo_executemanyZ no_parametersZdo_execute_no_params<6D>
do_execute<EFBFBD>after_cursor_executeZ post_execZis_crudZis_textZ_setup_crud_result_proxyZget_result_proxyZ _metadataZ _soft_closeZshould_autocommitr'rreZ _soft_closedrr/) rr<00> constructorr<72>r<><00>argsrrrhr=r<>r<>Z evt_handled<65>resultr"r"r#r<>%s<>                         zConnection._execute_contextcCsc|js|jjrPx8|jjD]'}||||||d<00>\}}q"Wn|jr<>|jjj|<00>|jjjd|<00>nybx[|jjs<>fn |jjjD]}|||||<00>r<>Pq<50>q<>W|jj||||<00>Wn>t k
r'}z|j
|||||<00>WYdd}~XnX|js=|jjr_|jj |||||d<00>ndS)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%rN) rr rr<>rr]rGrr<>r;r<r<>)rr<>r<>r<>rhr<>r=r"r"r#<00>_cursor_execute<74>s>    zConnection._cursor_executec CsCy|j<00>Wn.tk
r>|jjjjddd<00>YnXdS)z\Close the given cursor, catching exceptions
and turning into log warnings.
zError closing cursor<6F>exc_infoTN)r/r;r <00>poolr]<00>error)rr<>r"r"r#<00>_safe_close_cursor<6F>s
 zConnection._safe_close_cursorcCs<>tj<00>}|r-|jdkr-||_n|js<>t||jjj<00>o|j o|jj ||j
sv|j nd|<00>|_|r<>|j|_ q<>nd}|j r<>t jtjj||||jjjd|j<00>|<00>nd|_ z5t||jjj<00>p|dk o|dk}|ratjj||||jjjd|jd|j<00>} nd} d}
|js<>|jjr<>|jjdd<00> r<>|r<>|r<>|jj||||||<00>nt|| |j||||||j<00> } xo|jjD]a} y,| | <00>} | dk r.| | _}
nWq<57>tk
r]}z |}
PWYdd}~Xq<58>Xq<58>W| r<>|j| j kr<>| j | _|_n| j}n|r<>|r<>|j|<00>n|js<>|r<>|j|<00>n|j <00>n|
r<>t j|
|<00>n&|rt j| |<00>n t j!|<00>Wd|` |jr<>|`|j
s<>|j }|rm|jj"j#||<00>n|j$|<00>q<>n|j%r<>|j&<00>nXdS)NTr<00>connection_invalidatedZskip_user_error_eventsF)'<27>sysr<73>rL<00>_is_disconnectrlr<00>dbapi<70>Errorr7<00> is_disconnectr8r<00>_reentrant_errorr<00>raise_from_causer<00>
DBAPIError<EFBFBD>instancerr rr<>rZ dbapi_error<6F>ExceptionContextImpl<70> handle_error<6F>chained_exceptionr;r<><00>invalidate_pool_on_disconnectZhandle_dbapi_exceptionr<6E>rq<00>reraiser<65>Z _invalidaterKrr/)rr=r<>r<>r<>rhr<>r<><00> should_wrap<61>sqlalchemy_exception<6F>newraiser<65>r<><00>per_fn<66>_raisedZdbapi_conn_wrapperr"r"r#r<<00>s<>   
     
       
        
    z"Connection._handle_dbapi_exceptionc Cstj<00>}|j|dd<00>}t||jj<00>}|rftjjdd||jjd|<00>}nd}d}|j r<t
|||ddddd|<00> } xo|j j D]a}
y,|
| <00>} | dk r<>| | _ }nWq<57>tk
r } z | }PWYdd} ~ Xq<58>Xq<58>W|r<|| jkr<| j|_}q<n|rUtj||<00>n&|rntj||<00>n tj|<00>dS)Nr<4E>)r<>r<>r<>rlr<>r<>rr<>r<>rr<>rr<>r<>r;r<>rr<>r<>) <0A>clsr=rr r<>r<>r<>r<>r<>r<>r<>r<>r<>r"r"r#<00>$_handle_dbapi_exception_noconnectionNsD       
z/Connection._handle_dbapi_exception_noconnectioncCs|jjj|<00>S)N)r rZget_default_schema_name)rr"r"r#<00>default_schema_name<6D>szConnection.default_schema_namecOs_|j<00>}y'|j|||<00>}|j<00>|SWn%tj<00><00>|j<00>WdQXYnXdS)a5Execute the given function within a transaction boundary.
The function is passed this :class:`.Connection`
as the first argument, followed by the given \*args and \**kwargs,
e.g.::
def do_something(conn, x, y):
conn.execute("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:`.Connection.begin`::
with conn.begin():
conn.execute("some statement", {'x':5, 'y':10})
As well as with :meth:`.Engine.begin`::
with engine.begin() as conn:
conn.execute("some statement", {'x':5, 'y':10})
See also:
:meth:`.Engine.begin` - engine-level transactional
context
:meth:`.Engine.transaction` - engine-level version of
:meth:`.Connection.transaction`
N)rN<00> run_callablercr<00> safe_reraisera)r<00> callable_r<5F>rI<00>transr<73>r"r"r#r_<00>s* 
 zConnection.transactioncOs||||<00>S)a<>Given a callable object or function, execute it, passing
a :class:`.Connection` as the first argument.
The given \*args and \**kwargs are passed subsequent
to the :class:`.Connection` argument.
This function, along with :meth:`.Engine.run_callable`,
allows a function to be run with a :class:`.Connection`
or :class:`.Engine` object without the need to know
which one is being dealt with.
r")rr<>r<>rIr"r"r#r<><00>s zConnection.run_callablecKs ||j||<00>j|<00>dS)N)rZtraverse_single)r<00>visitorcallable<6C>elementrIr"r"r#<00> _run_visitor<6F>szConnection._run_visitor)@<40>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__r$r%<00>propertyr'r-r.r3r6r7r8rr>r?r:rErFrGrHrJrKrMrNrQrTrVrYr[r\r`rbrergrirjrkrmrorprqr/rtrsr~r<>r<>r{r<>ryr<>r<>r<>r<>r<>r<<00> classmethodr<64>r<>r_r<>r<>r"r"r"r#r s| ,     <0C> $   2  +     

   -  F    *   p/  {4  3 r c@s"eZdZdZdd<00>ZdS)r<>z3Implement the :class:`.ExceptionContext` interface.c
CsL||_||_||_||_||_||_||_| |_dS)N)r rr<>Zoriginal_exceptionZexecution_contextr<74>r<>r<>)
rrLr<>r rr<>r<>r<>rhr<>r"r"r#r$<00>s       zExceptionContextImpl.__init__N)r<>r<>r<>r<>r$r"r"r"r#r<><00>s r<>c@s<>eZdZdZdd<00>Zedd<00><00>Zdd<00>Zdd <00>Zd
d <00>Z d d <00>Z
dd<00>Z dd<00>Z dd<00>Z dS)rPa)Represent a database transaction in progress.
The :class:`.Transaction` object is procured by
calling the :meth:`~.Connection.begin` method of
:class:`.Connection`::
from sqlalchemy import create_engine
engine = create_engine("postgresql://scott:tiger@localhost/test")
connection = engine.connect()
trans = connection.begin()
connection.execute("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:`.Connection.begin` method::
with connection.begin():
connection.execute("insert into x (a, b) values (1, 2)")
The Transaction object is **not** threadsafe.
See also: :meth:`.Connection.begin`, :meth:`.Connection.begin_twophase`,
:meth:`.Connection.begin_nested`.
.. index::
single: thread safety; Transaction
cCs||_||_d|_dS)NT)r<00>_actual_parent<6E> is_active)rr<00>parentr"r"r#r$<00>s  zTransaction.__init__cCs |jp |S)N)r<>)rr"r"r#<00>_parentszTransaction._parentcCs0|jjsdS|j|kr,|j<00>ndS)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<>ra)rr"r"r#r/s zTransaction.closecCs'|jjsdS|j<00>d|_dS)z/Roll back this :class:`.Transaction`.
NF)r<>r<><00> _do_rollback)rr"r"r#ras 
zTransaction.rollbackcCs|jj<00>dS)N)r<>ra)rr"r"r#r<>szTransaction._do_rollbackcCs5|jjstjd<00><00>n|j<00>d|_dS)z"Commit this :class:`.Transaction`.zThis transaction is inactiveFN)r<>r<>rrA<00>
_do_commit)rr"r"r#rc!s 
zTransaction.commitcCsdS)Nr")rr"r"r#r<>)szTransaction._do_commitcCs|S)Nr")rr"r"r#r.,szTransaction.__enter__cCs\|dkrN|jrNy|j<00>WqXtj<00><00>|j<00>WdQXYqXXn
|j<00>dS)N)r<>rcrr<>ra)rr0r1r2r"r"r#r3/s zTransaction.__exit__N)r<>r<>r<>r<>r$r<>r<>r/rar<>rcr<>r.r3r"r"r"r#rP<00>s       rPcs:eZdZ<00>fdd<00>Zdd<00>Zdd<00>Z<00>S)rOcs-tt|<00>j|d<00>|jj|<00>dS)N)<05>superrOr$rr`)rr)r(r"r#r$;szRootTransaction.__init__cCs|jr|jj<00>ndS)N)r<>rrb)rr"r"r#r<>?s zRootTransaction._do_rollbackcCs|jr|jj<00>ndS)N)r<>rre)rr"r"r#r<>Cs zRootTransaction._do_commit)r<>r<>r<>r$r<>r<>r"r")r(r#rO:s  rOcs@eZdZdZ<00>fdd<00>Zdd<00>Zdd<00>Z<00>S)rRz<>Represent a 'nested', or SAVEPOINT transaction.
A new :class:`.NestedTransaction` object may be procured
using the :meth:`.Connection.begin_nested` method.
The interface is the same as that of :class:`.Transaction`.
cs/tt|<00>j||<00>|jj<00>|_dS)N)r<>rRr$rrg<00>
_savepoint)rrr<>)r(r"r#r$RszNestedTransaction.__init__cCs)|jr%|jj|j|j<00>ndS)N)r<>rrir<>r<>)rr"r"r#r<>Vs  zNestedTransaction._do_rollbackcCs)|jr%|jj|j|j<00>ndS)N)r<>rrjr<>r<>)rr"r"r#r<>[s  zNestedTransaction._do_commit)r<>r<>r<>r<>r$r<>r<>r"r")r(r#rRHs  rRcsLeZdZdZ<00>fdd<00>Zdd<00>Zdd<00>Zdd <00>Z<00>S)
rUaRepresent a two-phase transaction.
A new :class:`.TwoPhaseTransaction` object may be procured
using the :meth:`.Connection.begin_twophase` method.
The interface is the same as that of :class:`.Transaction`
with the addition of the :meth:`prepare` method.
cs?tt|<00>j|d<00>d|_||_|jj|<00>dS)NF)r<>rUr$<00> _is_preparedrSrrk)rrrS)r(r"r#r$ls  zTwoPhaseTransaction.__init__cCs>|jjstjd<00><00>n|jj|j<00>d|_dS)zqPrepare this :class:`.TwoPhaseTransaction`.
After a PREPARE, the transaction can be committed.
zThis transaction is inactiveTN)r<>r<>rrArrmrSr<>)rr"r"r#<00>preparers zTwoPhaseTransaction.preparecCs|jj|j|j<00>dS)N)rrorSr<>)rr"r"r#r<>}sz TwoPhaseTransaction._do_rollbackcCs|jj|j|j<00>dS)N)rrprSr<>)rr"r"r#r<><00>szTwoPhaseTransaction._do_commit)r<>r<>r<>r<>r$r<>r<>r<>r"r")r(r#rUas
 rUc@s<>eZdZdZej<00>ZdZeZ dddddd<00>Z
dd<00>Z dd <00>Z e d
d <00><00>Ze d d <00><00>Zej<00>Zdd<00>Zdd<00>Zdd<00>Zejddd<00><00>Zddd<00>ZGdd<00>de<00>Zddd<00>Zdd<00>Zdd<00>Zd d!<00>Zd"d#<00>Z ddd$d%<00>Z!d&d'<00>Z"d(d)<00>Z#dd*d+<00>Z$ddd,d-<00>Z%dd.d/<00>Z&d0d1<00>Z'dd2d3<00>Z(dS)4<>Engineap
Connects a :class:`~sqlalchemy.pool.Pool` and
:class:`~sqlalchemy.engine.interfaces.Dialect` together to provide a
source of database connectivity and behavior.
An :class:`.Engine` object is instantiated publicly using the
:func:`~sqlalchemy.create_engine` function.
See also:
:doc:`/core/engines`
:ref:`connections_toplevel`
FNcCs<>||_||_||_||j_|r9||_n||_||_tj|d|<00>|rzt j
j ||<00>n|r<>|j |<00>ndS)N<>echoflag) r<><00>urlrZ_dialect<63> logging_name<6D>echor r<00>instance_loggerrZConnectionProxyZ_adapt_listener<65>update_execution_options)rr<>rr<>r<>r<><00>proxyr6r"r"r#r$<00>s       zEngine.__init__cKs?|jj|<00>|_|jj||<00>|jj||<00>dS)a<>Update the default execution_options dictionary
of this :class:`.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:`.create_engine`.
.. seealso::
:meth:`.Connection.execution_options`
:meth:`.Engine.execution_options`
N)rr4rZset_engine_execution_optionsr)rr5r"r"r#r<><00>szEngine.update_execution_optionscKs t||<00>S)a<> Return a new :class:`.Engine` that will provide
:class:`.Connection` objects with the given execution options.
The returned :class:`.Engine` remains related to the original
:class:`.Engine` in that it shares the same connection pool and
other state:
* The :class:`.Pool` used by the new :class:`.Engine` is the
same instance. The :meth:`.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`
inherits the events of the parent, and new events can be associated
with the new :class:`.Engine` individually.
* The logging configuration and logging_name is copied from the parent
:class:`.Engine`.
The intent of the :meth:`.Engine.execution_options` method is
to implement "sharding" schemes where multiple :class:`.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:`.Connection` objects that will contain the execution option
``shard_id=shard1``, and ``shard2`` will produce :class:`.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:`.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
.. versionadded:: 0.8
.. seealso::
:meth:`.Connection.execution_options` - update execution options
on a :class:`.Connection` object.
:meth:`.Engine.update_execution_options` - update the execution
options for a given :class:`.Engine` in place.
)<01> OptionEngine)rr5r"r"r#r6<00>sAzEngine.execution_optionscCs
|jjS)ziString name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
in use by this :class:`Engine`.)rrf)rr"r"r#rfsz Engine.namecCs
|jjS)ziDriver name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
in use by this :class:`Engine`.)r<00>driver)rr"r"r#r<> sz Engine.drivercCs d|jS)Nz
Engine(%r))r<>)rr"r"r#<00>__repr__szEngine.__repr__cCs3|jj<00>|jj<00>|_|jj|<00>dS)a<>Dispose of the connection pool used by this :class:`.Engine`.
This 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`, so when they are closed individually,
eventually the :class:`.Pool` which they are associated with will
be garbage collected and they will be closed out fully, if
not already closed on checkin.
A new connection pool is created immediately after the old one has
been disposed. This new pool, like all SQLAlchemy connection pools,
does not make any actual connections to the database until one is
first requested, so as long as the :class:`.Engine` isn't used again,
no new connections will be made.
.. seealso::
:ref:`engine_disposal`
N)r<><00>disposeZrecreaterZengine_disposed)rr"r"r#r<>s zEngine.disposec Cs,|j<00><00>}|j|fi<00>SWdQXdS)N)rJr<>)rr<>rrr"r"r#r<>1szEngine._execute_defaultccs2|dkr)|j<00><00> }|VWdQXn|VdS)N)rJ)rrrrr"r"r#<00>_optional_conn_ctx_manager5s z!Engine._optional_conn_ctx_managerc Ks/|j|<00><00>}|j|||<00>WdQXdS)N)r<>r<>)rr<>r<>rrIrrr"r"r#r<>=szEngine._run_visitorc@s4eZdZdd<00>Zdd<00>Zdd<00>ZdS)zEngine._trans_ctxcCs||_||_||_dS)N)rrr_r)rrrr_rr"r"r#r$Cs  zEngine._trans_ctx.__init__cCs|jS)N)rr)rr"r"r#r.HszEngine._trans_ctx.__enter__cCsF|dk r|jj<00>n |jj<00>|jsB|jj<00>ndS)N)r_rarcrrrr/)rr0r1r2r"r"r#r3Ks
   zEngine._trans_ctx.__exit__N)r<>r<>r<>r$r.r3r"r"r"r#<00>
_trans_ctxBs   r<>cCs]|jd|<00>}y|j<00>}Wn%tj<00><00>|j<00>WdQXYnXtj|||<00>S)a<>Return a context manager delivering a :class:`.Connection`
with a :class:`.Transaction` established.
E.g.::
with engine.begin() as conn:
conn.execute("insert into table (x, y, z) values (1, 2, 3)")
conn.execute("my_special_procedure(5)")
Upon successful operation, the :class:`.Transaction`
is committed. If an error is raised, the :class:`.Transaction`
is rolled back.
The ``close_with_result`` flag is normally ``False``, and indicates
that the :class:`.Connection` will be closed when the operation
is complete. When set to ``True``, it indicates the
:class:`.Connection` is in "single use" mode, where the
:class:`.ResultProxy` returned by the first call to
:meth:`.Connection.execute` will close the :class:`.Connection` when
that :class:`.ResultProxy` has exhausted all result rows.
.. versionadded:: 0.7.6
See also:
:meth:`.Engine.connect` - procure a :class:`.Connection` from
an :class:`.Engine`.
:meth:`.Connection.begin` - start a :class:`.Transaction`
for a particular :class:`.Connection`.
rN)rJrNrr<>r/r<>r<>)rrrrr<>r"r"r#rNSs! z Engine.beginc Os,|j<00><00>}|j|||<00>SWdQXdS)a<>Execute the given function within a transaction boundary.
The function is passed a :class:`.Connection` newly procured
from :meth:`.Engine.contextual_connect` as the first argument,
followed by the given \*args and \**kwargs.
e.g.::
def do_something(conn, x, y):
conn.execute("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.begin`::
with engine.begin() as conn:
conn.execute("some statement", {'x':5, 'y':10})
See also:
:meth:`.Engine.begin` - engine-level transactional
context
:meth:`.Connection.transaction` - connection-level version of
:meth:`.Engine.transaction`
N)rJr_)rr<>r<>rIrrr"r"r#r_|s'zEngine.transactionc Os,|j<00><00>}|j|||<00>SWdQXdS)a<>Given a callable object or function, execute it, passing
a :class:`.Connection` as the first argument.
The given \*args and \**kwargs are passed subsequent
to the :class:`.Connection` argument.
This function, along with :meth:`.Connection.run_callable`,
allows a function to be run with a :class:`.Connection`
or :class:`.Engine` object without the need to know
which one is being dealt with.
N)rJr<>)rr<>r<>rIrrr"r"r#r<><00>s zEngine.run_callablecOs%|jdd<00>}|j|||<00>S)a<>Executes the given construct and returns a :class:`.ResultProxy`.
The arguments are the same as those used by
:meth:`.Connection.execute`.
Here, a :class:`.Connection` is acquired using the
:meth:`~.Engine.contextual_connect` method, and the statement executed
with that connection. The returned :class:`.ResultProxy` is flagged
such that when the :class:`.ResultProxy` is exhausted and its
underlying cursor is closed, the :class:`.Connection` created here
will also be closed, which allows its associated DBAPI connection
resource to be returned to the connection pool.
rT)rJrs)rr<>rvrwrr"r"r#rs<00>szEngine.executecOs|j|||<00>j<00>S)N)rsrt)rr<>rvrwr"r"r#rt<00>sz Engine.scalarcCs%|jdd<00>}|j|||<00>S)NrT)rJr{)rr<>rvrwrr"r"r#r{<00>szEngine._execute_clauseelementcCs%|jdd<00>}|j|||<00>S)NrT)rJr<>)rr<>rvrwrr"r"r#r<><00>szEngine._execute_compiledcKs|j||<00>S)aOReturn a new :class:`.Connection` object.
The :class:`.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`
referenced by this :class:`.Engine`. When the
:meth:`~.Connection.close` method of the :class:`.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.connect`.
)r&)rrIr"r"r#rH<00>szEngine.connectcKs+|j||j|jjd<00>d||<00>S)a<>Return a :class:`.Connection` object which may be part of some
ongoing context.
By default, this method does the same thing as :meth:`.Engine.connect`.
Subclasses of :class:`.Engine` may override this method
to provide contextual behavior.
:param close_with_result: When True, the first :class:`.ResultProxy`
created by the :class:`.Connection` will call the
:meth:`.Connection.close` method of that connection as soon as any
pending result rows are exhausted. This is used to supply the
"connectionless execution" behavior provided by the
:meth:`.Engine.execute` method.
Nr)r&<00>_wrap_pool_connectr<74>rH)rrrIr"r"r#rJ<00>s
zEngine.contextual_connectc
CsD|j|<00><00>/}|s'|jj}n|jj||<00>SWdQXdS)aReturn 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. Default is
the ``contextual_connect`` for this ``Engine``.
N)r<>rr<>Zget_table_names)r<00>schemarrrr"r"r#<00> table_names<65>s zEngine.table_namescCs|j|jj||<00>S)aUReturn True if the given backend has a table of the given name.
.. seealso::
:ref:`metadata_reflection_inspector` - detailed schema inspection
using the :class:`.Inspector` interface.
:class:`.quoted_name` - used to pass quoting information along
with a schema identifier.
)r<>r<00> has_table)rZ
table_namer<EFBFBD>r"r"r#r<> s zEngine.has_tablecCs{|j}y |<00>SWn`|jjk
rv}z:|dkrQtj|||<00>ntjtj<00><00>WYdd}~XnXdS)N) rr<>r<>r r<>rr<>r<>r<>)rr<>rrr=r"r"r#r<>s   zEngine._wrap_pool_connectcCs|j|jj|<00>S)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:`.Connection`
is not needed. When a :class:`.Connection` object is already
present, the DBAPI connection is available using
the :attr:`.Connection.connection` accessor.
.. seealso::
:ref:`dbapi_connections`
)r<>r<>Zunique_connection)rr@r"r"r#r"szEngine.raw_connection))r<>r<>r<>r<>rZ immutabledictrrr r&r$r<>r6r<>rfr<>rZ echo_propertyr<79>r<>r<>r<><00>
contextlib<EFBFBD>contextmanagerr<72>r<>rur<>rNr_r<>rsrtr{r<>rHrJr<>r<>r<>rr"r"r"r#r<><00>s>     C    ) *      r<>c@sjeZdZdd<00>Zdd<00>Zdd<00>Zeee<00>Zdd<00>Zd d
<00>Z eee <00>Z
d S) r<>cCs<>||_|j|_|j|_|j|_|j|_tj|d|j<00>|jj|j<00>|_|j |_ |j
|<00>dS)Nr<4E>) <0B>_proxiedr<64>rr<>r<>rr<>rrrr<>)rZproxiedr6r"r"r#r$<s      zOptionEngine.__init__cCs
|jjS)N)r<>r<>)rr"r"r#<00> _get_poolGszOptionEngine._get_poolcCs||j_dS)N)r<>r<>)rr<>r"r"r#<00> _set_poolJszOptionEngine._set_poolcCs|jjp|jjdd<00>S)NrF)r<>rr*r<>)rr"r"r#<00>_get_has_eventsOs zOptionEngine._get_has_eventscCs||jd<dS)Nr)r*)rr1r"r"r#<00>_set_has_eventsSszOptionEngine._set_has_eventsN) r<>r<>r<>r$r<>r<>r<>r<>r<>r<>rr"r"r"r#r<>;s     r<>)<18>
__future__rr<><00>rrrrZsqlr<6C>r r
r r<>r r<>rurPrOrRrUZ
Identifiedr<EFBFBD>r<>r"r"r"r#<00><module>s( " <16><00><00><00><00><00>^#<1C><00>