"zA|ddlmZddlZddlZddlmZddlmZddlmZddl m Z dd l mZdd l m Z dd l mZdd l m Z dd l mZ Gd deZGddeZGddeZGddeZGddeZGddeZGddee jZGddeZdS))with_statementN) Connectable)ExceptionContext)_distill_params)exc) interfaces)log)util)schemac>eZdZdZejdZ d=dZdZe dZ dZ dZ d Z d Zd Ze d Ze d Ze dZdZe dZdZe dZe dZe dZdZdZd>dZdZdZdZd>dZdZ d?dZ!d?dZ"dZ#d Z$d!Z%d?d"Z&d>d#Z'd$Z(d%Z)d&Z*d'Z+d(Z,d)Z-d*Z.d+Z/d,Z0d-Z1d.Z2d/Z3d0Z4d1Z5d2Z6d3Z7d4Z8d5Z9d>d6Z:d7Z;dZe?d9Z@d:ZAd;ZBd<ZCdS)@ ConnectionaIProvides high-level functionality for a wrapped DB-API connection. Provides execution support for string-based SQL statements as well as :class:`_expression.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 NFc||_|j|_||_|du|_|rA||_||_|j|_d|_||_|j |_ |j |_ n||n| |_d|_ d|_ ||_d|_d|_|j|_|$|j|j|_|p |duo|j |_ |rJ|j|_|j s |jj r"|j||jdSdS)zConstruct a new Connection. The constructor here is not public and is only called only by an :class:`_engine.Engine`. See :meth:`_engine.Engine.connect` and :meth:`_engine.Engine.contextual_connect` methods. NFrT)enginedialect_Connection__branch_from_Connection__branch_Connection__connection_execution_options_echoshould_close_with_resultdispatch _has_eventsschema_for_objectraw_connection_Connection__transaction_Connection__savepoint_seq_Connection__invalid_Connection__can_reconnect_should_log_info_joinengine_connect)selfr connectionclose_with_result _branch_fromr _dispatchrs /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py__init__zConnection.__init__Fsr" ~ )$D0  @ *D &8D #%+DJ,1D )%DM+7D %1%CD " ") **,,   "&D #$D ,=D )"DN#'D 5577DJ"!% 3 3FO D D * t#:(:  * ) ))&,&?D #   >t{6 > M ( (t} = = = = = > >c|jr|jS|j|j|j||j|j|jS)aReturn 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()r_branchr_connection_clsrrrrr$s r)r-zConnection._branchsb   %--// /;.. !!#'#: ,- / r+c"|jr|jS|S)zReturn the 'root' connection. Returns 'self' if this connection is not a branch, else returns the root connection from which we ultimately branched. )rr/s r)_rootzConnection._roots   % %Kr+c|j|j}|j|_|S)z)Create a shallow copy of this Connection.) __class____new____dict__copy)r$cs r)_clonezConnection._clones5 N " "4> 2 2]'')) r+c|SNr/s r) __enter__zConnection.__enter__ r+c.|dSr:)closer$type_value tracebacks r)__exit__zConnection.__exit__s r+c |}|j||_|js |jjr|j|||j|||S)a Set non-SQL options for the connection which take effect during execution. The 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 library-level "autocommit" feature is being removed in favor of database driver "autocommit" which is now widely available. See the section :ref:`dbapi_autocommit`. :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. 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:`_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 level :ref:`SQLite Transaction Isolation ` :ref:`PostgreSQL Transaction Isolation ` :ref:`MySQL Transaction Isolation ` :ref:`SQL Server Transaction Isolation ` :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. This is a limitation of many DBAPIs. The flag is currently understood only by the psycopg2, mysqldb and pymysql dialects. :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` )r8runionrrr set_connection_execution_optionsr)r$optr7s r)execution_optionszConnection.execution_optionssyx KKMM 399#>>   Ct{6 C M : :1c B B B 55a===r+c|jS)zGet the non-SQL options which will take effect during execution. .. versionadded:: 1.3 .. seealso:: :meth:`_engine.Connection.execution_options` rr/s r)get_execution_optionsz Connection.get_execution_optionsZ &&r+c$d|jvo|j S)z)Return True if this connection is closed.r)r5r r/s r)closedzConnection.closedes! &T] : )(( r+c|jjS)z/Return True if this connection was invalidated.)r1rr/s r) invalidatedzConnection.invalidatednsz##r+c |jS#t$rYnwxYw |S#t$r$}||ddddYd}~dSd}~wwxYw)zThe underlying DB-API connection managed by this Connection. .. seealso:: :ref:`dbapi_connections` N)rAttributeError_revalidate_connection BaseException_handle_dbapi_exceptionr$es r)r%zConnection.connectionts $ $    D  D..00 0 D D D  ( (D$d C C C C C C C C C Ds  . AAAc |j|jS#t$r$}||ddddYd}~dSd}~wwxYw)aReturn the current isolation level assigned to this :class:`_engine.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:`_engine.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:`_engine.Connection.default_isolation_level` accessor which returns the dialect-level setting without performing a SQL query. .. 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)rget_isolation_levelr%rUrVrWs r)rZzConnection.get_isolation_levelsr@ D<33DODD D D D D  ( (D$d C C C C C C C C C Ds! AA  Ac|jjS)aCThe default isolation level assigned to this :class:`_engine.Connection`. This is the isolation level setting that the :class:`_engine.Connection` has when first procured via the :meth:`_engine.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:`_engine.Connection` basis. Unlike :meth:`_engine.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:`_engine.Connection.get_isolation_level` - view current 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 )rdefault_isolation_levelr/s r)r\z"Connection.default_isolation_levels>|33r+c|jr|jS|jrP|jrI|jt jd|j||_ d|_|j St j d)Nz8Can't reconnect until invalid transaction is rolled back) _connectionFThis Connection is closed) rrTr rrr InvalidRequestErrorrrrResourceClosedErrorr/s r)rTz!Connection._revalidate_connections   ?%<<>> >   %DN %!--1!% : :t : L LD "DN$ $%&ABBBr+c.t|jddSNis_validF)getattrrr/s r)_connection_is_validzConnection._connection_is_valids t(*e<<$$ >):u== r+c|jjS)aInfo 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%infor/s r)rjzConnection.infos##r+c*|S)aReturns 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/s r)connectzConnection.connects||~~r+c *|Sr:rlr$kwargss r)_contextual_connectzConnection._contextual_connect s||~~r+c|jrdS|jrtjd|jjr|jj||j`d|j_dS)aInvalidate the underlying DBAPI connection associated with this :class:`_engine.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:`_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. .. seealso:: :ref:`pool_connection_invalidation` Nr_T) rQrOr rar1rfr invalidater)r$ exceptions r)rszConnection.invalidatespR    F ; G)*EFF F : * : J # . .y 9 9 9 J ## r+c8|jdS)a,Detach 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:`_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)rdetachr/s r)rvzConnection.detachBs4   """""r+c|jr|jS|jt||_|jSt ||jS)aWBegin 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:`_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. .. 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` )rbeginrRootTransaction Transactionr/s r)rxzConnection.begin^sZF   .%++-- -   %!0!6!6D % %tT%788 8r+c|jr|jS|jt||_nt ||j|_|jS)a9Begin 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. .. seealso:: :meth:`_engine.Connection.begin` :meth:`_engine.Connection.begin_twophase` )r begin_nestedrryNestedTransactionr/s r)r|zConnection.begin_nesteds^$   5%2244 4   %!0!6!6D  !249K!L!LD !!r+c|jr|j|S|jtjd||jj}t|||_|jS)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` )xidNzOCannot start a two phase transaction when a transaction is already in progress.) rbegin_twophaserr r`rr create_xidTwoPhaseTransactionr$rs r)rzConnection.begin_twophases(   >%444== =   ))*  ;+%0022C0s;;!!r+c@|jj|Sr:)rrdo_recover_twophaser/s r)recover_twophasezConnection.recover_twophases{"66t<<t |jtsJ|jj ||dSdSr:) rrrrprepare_twophaserh isinstancerrrdo_prepare_twophasers r)_prepare_twophase_implz!Connection._prepare_twophase_implHs%%%%   6t{6 6 M * *4 5 5 5  3 ?d02EFF F FF K  3 3D# > > > > > ? ?r+c|jrJ|js |jjr|j||||jrt |jtsJ |jj ||||j j |jur d|j _ d|_dS#|j j |jur d|j _ d|_wxYwd|_dSr:) rrrrrollback_twophaserhrrrrrr%rr$r is_prepareds r)_rollback_twophase_implz"Connection._rollback_twophase_implRs%%%%   Dt{6 D M + +D#{ C C C  3 &d02EFF F FF * #88#{?/43EEE37DO0%)"""?/43EEE37DO0%)"))))!%D    !B&&(Cc|jrJ|js |jjr|j||||jrt |jtsJ |jj ||||j j |jur d|j _ d|_dS#|j j |jur d|j _ d|_wxYwd|_dSr:) rrrrcommit_twophaserhrrrrrr%rrs r)_commit_twophase_implz Connection._commit_twophase_imples%%%%   Bt{6 B M ) )$[ A A A  3 &d02EFF F FF * #66tS+NNN?/43EEE37DO0%)"""?/43EEE37DO0%)"))))!%D   rcn|js|jdSdSr:)r1rrr/s r) _autorollbackzConnection._autorollbackvs<z((** ( J % % ' ' ' ' ' ( (r+c|jr, |`n#t$rYnwxYwd|_dS#d|_YdSxYw |j}||j|jurd|_|js|`n#t$rYnwxYwd|_d|_dS)afClose 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. FN)rrrSr r?rrr)r$conns r)r?zConnection.closezs&    %%!    (-$(-$ &$D JJLLL D$666$(! > &%    D  %!s- % %% 1A// A<;A<cH|j|g|Ri|S)zExecutes and returns the first column of the first row. The underlying result/cursor is closed after execution. executescalar)r$object_ multiparamsparamss r)rzConnection.scalars2 t|G`_ 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. r)replace_contextN) rr string_types _execute_text_execute_on_connectionrSraise_r ObjectNotExecutableError)r$rrrmetherrs r)rzConnection.executesv gt03 4 4 D%%g{FCC C 31D 4k622 2     K,W55s           sA B (BB cT||||S)z%Execute a sql.FunctionElement object.)_execute_clauseelementselect)r$funcrrs r)_execute_functionzConnection._execute_functions$**4;;==+vNNNr+c@|js |jjr!|jjD]}|||||\}}} |j}n#t $rd}YnwxYw||}|j}|j |||}n0#t$r#}| |ddddYd}~nd}~wwxYw| d|d} |j r||js |jjr|j||||| | S)z&Execute a schema.ColumnDefault object.N)rrrbefore_executerrSrTrexecution_ctx_cls _init_defaultrUrV _exec_defaultrr? after_execute) r$defaultrrfnrrctxrXrets r)_execute_defaultzConnection._execute_defaults   t{6 m2  /1r';00,ff D (!    |2244lG+99'4NNCC D D D  ( (D$d C C C C C C C C Dgt44  (  JJLLL   t{6  M ' 'g{FC    s2?B A B A<< +,,q0-8&T%;%; (L##   % 4          Nt{6 N M ' 'dK M M M r+cF|js |jjr!|jjD]}|||||\}}}|j}t ||}|||jj||||}|js |jjr|j ||||||S)zExecute a sql.Compiled object.) rrrrrrrrrr)r$rrrrr parametersrs r)_execute_compiledzConnection._execute_compiledps   t{6 m2  02(K11-+vv,$[&99 ##   % 4          t{6  M ' 'h VS    r+cF|js |jjr!|jjD]}|||||\}}}|j}t ||}|||jj||||}|js |jjr|j ||||||S)zExecute a string SQL statement.) rrrrrrrr_init_statementr)r$ statementrrrrrrs r)rzConnection._execute_texts   t{6 m2  13)[&22. ;,$[&99 ##   % 5          t{6  M ' 'ifc    r+c v |j}n#t$rd}YnwxYw||}||||g|R}nB#t$r5}||t j||ddYd}~nd}~wwxYw|jr||j |j |j }}} |j s|d}|j s |jj r'|jjD]} | || ||||j \}}|jr|jj||jjs;|jjdt+j|d|j n|jjdd} |j rR|jj r&|jjjD]} | | |||rd} n| s|j| |||n|sW|jrP|jj r%|jjjD]} | | ||rd} n| s|j| ||nQ|jj r&|jjjD]} | | |||rd} n| s|j| ||||j s |jj r$|j|| ||||j |jr||js|jr| } n/|!} | j"| #|j$r'|j%j&|j%'d |j(r#| j)r|*nd| _+n0#t$r#}||||| |Yd}~nd}~wwxYw| S) zmCreate an :class:`.ExecutionContext` and execute, returning a :class:`_engine.ResultProxy`. Nr%r )batchesismultiz3[SQL parameters hidden due to hide_parameters=True]FT)r),rrSrTrUrVr text_typerpre_execcursorr r executemanyrrrbefore_cursor_executerrrjhide_parameterssql_util _repr_paramsrdo_executemany no_parametersdo_execute_no_params do_executeafter_cursor_execute post_execis_crudis_text_setup_crud_result_proxyget_result_proxy _metadata _soft_closeshould_autocommitr1rrr _soft_closedr?_autoclose_connection) r$r constructorr rargsrrrXrr evt_handledresults r)rzConnection._execute_contexts(  (!    |2244!k'4====GG     ( (4>),,j$                   N    &  " '#AJ   t{6 m9  (*' ))% :: :  K  # #I . . .;.  "'')"B8K "''I F " <+""l3B""2fiWEE"*.K!E"#L// :w  G$9 <+""l3H""2fi99"*.K!E"#L55 7<+""l3>""2fiWEE"*.K!E"#L++ :w 4;#:  22'  $!!### )'/ ) 99;; 1133#+&&(((( 9TZ-E-M ''4'888, 8&8JJLLLL48F0     ( (9j&'           sB ? ?$? A> +A99A> G?N N6N11N6c f|js |jjr"|jjD]}||||||d\}}|jr?|jj||jjd| |jjsdn|jjjD]}|||||rn|j||||n0#t$r#}| |||||Yd}~nd}~wwxYw|js |jjr!|j |||||ddSdS)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(). Fr r;N) rrrrrrrjrrrUrVr)r$rr rrrrXs r)_cursor_executezConnection._cursor_execute*s   t{6 m9  (*&)Z%))% :: : 6 K  # #I . . . K  # #D* 5 5 5 |/6\*5 P P 2fiW==E '' :wOOO     ( (9j&'            t{6  M . .fiWe       s=AC C:C55C:c |dS#t$r*|jjjddYdSwxYw)z\Close the given cursor, catching exceptions and turning into log warnings. zError closing cursorT)exc_infoN)r? Exceptionrpoolrerror)r$rs r)_safe_close_cursorzConnection._safe_close_cursorRsl   LLNNNNN    K  # ) )& *       s0A  A c tj}|r|j||_t|t }|jsnt||jjjo1|j o)|j ||j s|j nd|p |o|j |_|r |j|_ | }|j rhtjt j||||jjj|jj|j||jnd|d|d|_ t||jjjp |duo|duo| } | rTt j||||jjj|jj|j|j||jnd} nd} d} |js |jjr|jdds| r!|r|j||||||t7|| |j||||||j| } |jjD]3} | | }| |x| _} #t$r }|} Yd}~nd}~wwxYw|j| j kr| j |_| r | j | _| j}| r|r| ||jsX|r|!|tj"d5|#dddn #1swxYwY| rtj| |d|nB| rtj| |d|n"tj|d |d |` |jrG|`|j s>|j }|r |jj$%|||&||j'r|(dSdS#|` |jrG|`|j s>|j }|r |jj$%|||&||j'r|(wwxYw) N)rrrrwith_tracebackfrom_T)rconnection_invalidatedrrskip_user_error_eventsF) warn_onlyrr4))sysr-rtrr._is_disconnectrdbapiErrorrO is_disconnectrQr_reentrant_errorr rr DBAPIErrorinstancerrrrrrr dbapi_errorExceptionContextImpl handle_errorchained_exceptionr6invalidate_pool_on_disconnecthandle_dbapi_exceptionr1 safe_reraiserr/ _invalidatersrr?)r$rXr rrrr-is_exit_exceptionrF should_wrapsqlalchemy_exceptionnewraiserrper_fn_raiseddbapi_conn_wrappers r)rVz"Connection._handle_dbapi_exceptionbs<>>  "w(0 !G  *1i 8 88" <1dl0677 OL..-1-=GD%%4#9$7DK   <(,(;%,=(=%    K''L&,$(K$? L*$//(   ({    !%i %Q (:(@AA%*tO*))   ,'*~'>'>L&,$(K$?+/+> L*$//(? ( ($$(,$H 0 $(K$;0 -11(%0  7M--fiWa +(K'1  -4  B "$C!-?EEC1H$#* &#*;;;*-*;D'+--C5. 2w 2..q111& )4++F333&666))&&((())))))))))))))) E HXa[JJJJJ E (!A HQK DDDD%" '''')-):&4L (445GKKKOOA&&&,    %" '''')-):&4L (445GKKKOOA&&&,   s^)DO/IO IIOIBOK>2 O>LOLA%OA.Qc tj}||dd}t||jj}|r5t jdd||jj|j |}nd}d}|j rst|||ddddd|d } |j j D]3} | | } | | x| _}#t$r } | }Yd} ~ nd} ~ wwxYw|r|| jkr| jx|_}|rt#j||d|dS|rt#j||d|dSt#j|d|ddS)N)rr6Trr3rr9)r:r-r>rr<r=r r@rArrrCrrDrEr.r6r r) clsrXrrr-r>rKrLrMrrrNrOs r)$_handle_dbapi_exception_noconnectionz/Connection._handle_dbapi_exception_noconnections<>>--at<<  GM$788  (#&>#:#: # & 6'4 $;$$ $(    &&$  Co2    RWWF);AA- &HEEEEE $ & 9J(J(J%&$;!  A K!A F F F F F F  A K$Xa[       K HQK @ @ @ @ @ @s.C CCCc |} |j|g|Ri|}||S#tj5|dddYdS#1swxYwYYdSxYw)abExecute 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("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("some statement", {'x':5, 'y':10}) As well as with :meth:`_engine.Engine.begin`:: with engine.begin() as conn: conn.execute("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` N)rx run_callablerr rHr)r$ callable_r'rprrs r)rzConnection.transaction5sT  !#$#I??????C LLNNNJ !"$$ ! !    ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s-&=BA5' B5A9 9B<A9 =Bc||g|Ri|S)aGiven 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. r;)r$rVr'rps r)rUzConnection.run_callablehs$y///////r+c J||j|fi||dSr:)rtraverse_single)r$visitorcallableelementrps r) _run_visitorzConnection._run_visitorws2 d55f55EEgNNNNNr+)NFNNNNr:F)D__name__ __module__ __qualname____doc__r _schema_getterrr*r-propertyr1r8r<rDrIrLrOrQr%rZr\rTrfrhrjrmrqrsrvrxr|rrrrrrrrrrrrrrrrrr?rrrrrrrrrr+r1r?r;rV classmethodrSrrUr\r;r+r)rrs2.-d33 $8>8>8>8>t8  X aaaF ' ' '  X $$X$ DDXD*#D#D#DJ44X4@ C C C==X=  X  $ $X $   2$2$2$2$h###8*9*9*9X"""6""""B===MMMMKKKK444DDD &&&.&&&&(     6 6 6%%%%%% ; ; ;???&&&&&&&"(((+"+"+"ZFFFD3D3D3LOOO !!!F4777r22FFFP&&&&P   NTTTl:A:A[:Ax1!1!1!f 0 0 0OOOOOr+rceZdZdZdZdS)rCz3Implement the :class:`.ExceptionContext` interface.c ||_||_||_||_||_||_||_| |_| |_dSr:) rr%rLoriginal_exceptionexecution_contextr rr>rF) r$rtrLrr%rr rrr>rFs r)r*zExceptionContextImpl.__init__~sN $$8!"+!("$*-J***r+N)r^r_r`rar*r;r+r)rCrC{s.==KKKKKr+rCcXeZdZdZdZedZdZdZdZ dZ dZ d Z d Z d S) rzahRepresent 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("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("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 c0||_||_d|_dS)NT)r%_actual_parent is_active)r$r%parents r)r*zTransaction.__init__s$$r+c|jp|Sr:)rkr/s r)rzTransaction._parents"*d*r+c|jjr|j|ur||j|dS)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)rrlrr%rr/s r)r?zTransaction.closesF < ! dld&:&: MMOOO ,,T22222r+cX|jjr|d|_dSdS)z%Roll back this :class:`.Transaction`.FN)rrl _do_rollbackr/s r)rzTransaction.rollbacks6 < ! #      "DNNN # #r+c8|jdSr:)rrr/s r)rqzTransaction._do_rollbacks r+c||jjstjd|d|_dS)z"Commit this :class:`.Transaction`.This transaction is inactiveFN)rrlr r` _do_commitr/s r)rzTransaction.commits?|% J)*HII I r+cdSr:r;r/s r)ruzTransaction._do_commits r+c|Sr:r;r/s r)r<zTransaction.__enter__r=r+c|h|jra |dS#tj5|dddn#1swxYwYYdSYdSxYw|dSr:)rlrr rHrr@s r)rDzTransaction.__exit__s =T^= $  $&(($$MMOOO$$$$$$$$$$$$$$$$$$$$$ MMOOOOOs,!A(A A(A A(A A(N)r^r_r`rar*rcrr?rrqrrur<rDr;r+r)rzrzs""H ++X+333 ###       r+rzc*eZdZfdZdZdZxZS)ryctt||d|j|dSr:)superryr*r%r)r$r%r3s r)r*zRootTransaction.__init__s? ot$$--j$??? ##D)))))r+cJ|jr|jdSdSr:)rlr%rr/s r)rqzRootTransaction._do_rollbacks0 > - O * * , , , , , - -r+cJ|jr|jdSdSr:)rlr%rr/s r)ruzRootTransaction._do_commits0 > + O ( ( * * * * * + +r+)r^r_r`r*rqru __classcell__r3s@r)ryrysV*****---+++++++r+ryc.eZdZdZfdZdZdZxZS)r}zRepresent a 'nested', or SAVEPOINT transaction. A new :class:`.NestedTransaction` object may be procured using the :meth:`_engine.Connection.begin_nested` method. The interface is the same as that of :class:`.Transaction`. ctt||||j|_dSr:)r{r}r*r%r _savepoint)r$r%rmr3s r)r*zNestedTransaction.__init__s= &&// FCCC/99;;r+cb|jr'|j|j|jdSdSr:)rlr%rrrr/s r)rqzNestedTransaction._do_rollbacksC >  O 7 7       r+cb|jr'|j|j|jdSdSr:)rlr%rrrr/s r)ruzNestedTransaction._do_commitsC >  O 3 3       r+)r^r_r`rar*rqrur~rs@r)r}r}s`<<<<< r+r}c4eZdZdZfdZdZdZdZxZS)raRepresent 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. ctt||dd|_||_|j|dS)NF)r{rr* _is_preparedrr%r)r$r%rr3s r)r*zTwoPhaseTransaction.__init__*sO !4((11*dCCC! ,,T22222r+c|jjstjd|j|jd|_dS)zqPrepare this :class:`.TwoPhaseTransaction`. After a PREPARE, the transaction can be committed. rtTN)rrlr r`r%rrrr/s r)preparezTwoPhaseTransaction.prepare0sJ |% J)*HII I ..tx888 r+cP|j|j|jdSr:)r%rrrr/s r)rqz TwoPhaseTransaction._do_rollback;s% //$:KLLLLLr+cP|j|j|jdSr:)r%rrrr/s r)ruzTwoPhaseTransaction._do_commit>s% --dh8IJJJJJr+) r^r_r`rar*rrqrur~rs@r)rrsy33333 ! ! !MMMKKKKKKKr+rceZdZdZejZdZeZ e j dZ d"dZ edZdZdZdZed Zed ZejZd Zd Zd Zejd#dZ d#dZGddeZ d$dZ!dZ"dZ#dZ$dZ%d%dZ&dZ'dZ(ej)ddd$dZ*d$dZ+d%dZ,d#dZ-d Z.d#d!Z/dS)&Enginea 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.Engine` object is instantiated publicly using the :func:`~sqlalchemy.create_engine` function. .. seealso:: :doc:`/core/engines` :ref:`connections_toplevel` FNc ||_||_||_|r||_||_||_t j|||r tj |||r|j di|dSdSN)echoflagr;) r/urlr logging_nameechorr instance_loggerr ConnectionProxy_adapt_listenerupdate_execution_options) r$r/rrrrproxyrIrs r)r*zEngine.__init__gs   - ,D  . D40000  D  & 6 6tU C C C  ? )D ) > >,= > > > > > ? ?r+c|Sr:r;r/s r)rz Engine.engines r+c |j||_|j|||j||dS)aUpdate 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)rrFrset_engine_execution_optionsrr$rHs r)rzEngine.update_execution_optionssS"#'"9"?"?"D"D 224=== 11$<<<< >>>v>>EEGGGr+c\|d}||||SNTr)rqr)r$rrrr%s r)rzEngine._execute_clauseelements0---EE 00{FKKKr+c\|d}||||Sr)rqr)r$rrrr%s r)rzEngine._execute_compileds0---EE ++Hk6JJJr+c |j|fi|S)aReturn 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.ros r)rmzEngine.connects$t#D33F333r+z1.3a The :meth:`_engine.Engine.contextual_connect` method is deprecated. This method is an artifact of the threadlocal engine strategy which is also to be deprecated. For explicit connections from an :class:`_engine.Engine`, use the :meth:`_engine.Engine.connect` method.c |jdd|i|S)aReturn a :class:`_engine.Connection` object which may be part of some ongoing context. By default, this method does the same thing as :meth:`_engine.Engine.connect`. Subclasses of :class:`_engine.Engine` may override this method to provide contextual behavior. :param close_with_result: When True, the first :class:`_engine.ResultProxy` created by the :class:`_engine.Connection` will call the :meth:`_engine.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.Engine.execute` method. r&r;rr$r&rps r)contextual_connectzEngine.contextual_connects0<(t'  / 39   r+c `|j|||jjdfd|i|S)Nr&)r._wrap_pool_connectr/rmrs r)rqzEngine._contextual_connectsM#t#   # #DI$5t < <  0     r+c||5}|j||cdddS#1swxYwYdS)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)rrget_table_names)r$r r%rs r) table_nameszEngine.table_names s , ,Z 8 8 >D<//f== > > > > > > > > > > > > > > > > > >s>AAcD||jj||S)a`Return True if the given backend has a table of the given name. .. seealso:: :ref:`metadata_reflection_inspector` - detailed schema inspection using the :class:`_reflection.Inspector` interface. :class:`.quoted_name` - used to pass quoting information along with a schema identifier. )rUr has_table)r$ table_namer s r)rzEngine.has_table s!  !7VLLLr+c2|j} |S#|jj$rt}|t|||nJt jtjdtjdYd}~dSYd}~dSd}~wwxYw)Nrrr9) rr<r=rrSr rr:r-)r$rr%rrXs r)rzEngine._wrap_pool_connect s, 244K}"   !??w LNN1%clnnQ6G  s BA#BBcB||jj|S)aCReturn 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` )rr/unique_connection)r$r^s r)rzEngine.raw_connection+ s&,&& I '   r+)NNNNFr:r])NN)0r^r_r`rar immutabledictrrrr.r rbrr*rcrrrIrLrrr echo_propertyrrrr contextlibcontextmanagerrr\objectrrxrrUrrrrrm deprecatedrrqrrrrr;r+r)rrBs ,+--K O--d33 ( ????0X===*J'J'J'X ' ' '!!X! ##X# 3   D''',,,::::48BBBB """""V""""'A'A'A'AR)@)@)@VAAA EEE.HHHLLLLKKK444"T_      2     > > > > M M M M         r+rc`eZdZdZdZdZdZeeeZdZ dZ ee e Z dS)rFc<||_|j|_|j|_|j|_|j|_|j|_t j||j|j |j|_|j |_ |j di|dSr) _proxiedrrrrrr rrr"rr)r$proxiedrIs r)r*zOptionEngine.__init__I s ; #0L &6 D495555 ++G,<== ")"<%%::(9:::::r+c|jjSr:rr/r/s r) _get_poolzOptionEngine._get_poolc s }!!r+c||j_dSr:r)r$r/s r) _set_poolzOptionEngine._set_poolf s! r+cP|jjp|jddS)NrF)rrr5rr/s r)_get_has_eventszOptionEngine._get_has_eventsk s-}( DM,=,= 5- -  r+c||jd<dS)Nr)r5)r$rBs r)_set_has_eventszOptionEngine._set_has_eventsp s', m$$$r+N) r^r_r`_sa_propagate_class_eventsr*rrrcr/rrrr;r+r)rrF s!&;;;4"""""" 8Iy ) )D   ---(?O<rsh&%%%%% ######((((((!!!!!!"""""" \O\O\O\O\O\O\O\O~2KKKKK+KKK6]]]]]&]]]@ + + + + +k + + + 6 K K K K K+ K K KFA A A A A [#.A A A H-=-=-=-=-=6-=-=-=-=-=r+