/
opt
/
alt
/
python27
/
lib64
/
python2.7
/
site-packages
/
sqlalchemy
/
engine
/
up file
home
� 1��fc @ s� d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d e j f d � � YZ d e j f d � � YZ d S( i ( t Engine( t Connectable( t Dialecti ( t event( t exct ConnectionEventsc B s" e Z d Z d Z e Z e e d � � Z e j d d d d d g d � � d � � Z e j d d d d d d g d � � d � � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z RS( s@ Available events for :class:`.Connectable`, which includes :class:`_engine.Connection` and :class:`_engine.Engine`. The methods here define the name of an event as well as the names of members that are passed to listener functions. An event listener can be associated with any :class:`.Connectable` class or instance, such as an :class:`_engine.Engine`, e.g.:: from sqlalchemy import event, create_engine def before_cursor_execute(conn, cursor, statement, parameters, context, executemany): log.info("Received statement: %s", statement) engine = create_engine('postgresql://scott:tiger@localhost/test') event.listen(engine, "before_cursor_execute", before_cursor_execute) or with a specific :class:`_engine.Connection`:: with engine.begin() as conn: @event.listens_for(conn, 'before_cursor_execute') def before_cursor_execute(conn, cursor, statement, parameters, context, executemany): log.info("Received statement: %s", statement) When the methods are called with a `statement` parameter, such as in :meth:`.after_cursor_execute` or :meth:`.before_cursor_execute`, the statement is the exact SQL string that was prepared for transmission to the DBAPI ``cursor`` in the connection's :class:`.Dialect`. The :meth:`.before_execute` and :meth:`.before_cursor_execute` events can also be established with the ``retval=True`` flag, which allows modification of the statement and parameters to be sent to the database. The :meth:`.before_cursor_execute` event is particularly useful here to add ad-hoc string transformations, such as comments, to all executions:: from sqlalchemy.engine import Engine from sqlalchemy import event @event.listens_for(Engine, "before_cursor_execute", retval=True) def comment_sql_calls(conn, cursor, statement, parameters, context, executemany): statement = statement + " -- some comment" return statement, parameters .. note:: :class:`_events.ConnectionEvents` can be established on any combination of :class:`_engine.Engine`, :class:`_engine.Connection`, as well as instances of each of those classes. Events across all four scopes will fire off for a given instance of :class:`_engine.Connection`. However, for performance reasons, the :class:`_engine.Connection` object determines at instantiation time whether or not its parent :class:`_engine.Engine` has event listeners established. Event listeners added to the :class:`_engine.Engine` class or to an instance of :class:`_engine.Engine` *after* the instantiation of a dependent :class:`_engine.Connection` instance will usually *not* be available on that :class:`_engine.Connection` instance. The newly added listeners will instead take effect for :class:`_engine.Connection` instances created subsequent to those event listeners being established on the parent :class:`_engine.Engine` class or instance. :param retval=False: Applies to the :meth:`.before_execute` and :meth:`.before_cursor_execute` events only. When True, the user-defined event function must have a return value, which is a tuple of parameters that replace the given statement and parameters. See those methods for a description of specific return arguments. t SomeEnginec s� | j | j | j } } } t | _ | s� | d k rV | � � f d � } | } q� | d k r� | � � f d � } | } q� n$ | r� | d k r� t j d � � n | j | � j � d S( Nt before_executec s# � | | | | | � | | | f S( N( ( t connt clauseelementt multiparamst paramst execution_options( t orig_fn( sK /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/events.pyt wrap_before_executem s t before_cursor_executec s# � | | | | | | � | | f S( N( ( R t cursort statementt parameterst contextt executemany( R ( sK /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/events.pyt wrap_before_cursor_execute} s t handle_errors Only the 'before_execute', 'before_cursor_execute' and 'handle_error' engine event listeners accept the 'retval=True' argument.( R R R ( t dispatch_targett identifiert _listen_fnt Truet _has_eventsR t ArgumentErrort with_wrappert base_listen( t clst event_keyt retvalt targetR t fnR R ( ( R sK /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/events.pyt _listen_ s( s 1.4R R R R c C s | | | | f S( N( ( R R R R R ( ( sK /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/events.pyt <lambda>� s c C s d S( s[ Intercept high level execute() events, receiving uncompiled SQL constructs and other objects prior to rendering into SQL. This event is good for debugging SQL compilation issues as well as early manipulation of the parameters being sent to the database, as the parameter lists will be in a consistent format here. This event can be optionally established with the ``retval=True`` flag. The ``clauseelement``, ``multiparams``, and ``params`` arguments should be returned as a three-tuple in this case:: @event.listens_for(Engine, "before_execute", retval=True) def before_execute(conn, clauseelement, multiparams, params): # do something with clauseelement, multiparams, params return clauseelement, multiparams, params :param conn: :class:`_engine.Connection` object :param clauseelement: SQL expression construct, :class:`.Compiled` instance, or string statement passed to :meth:`_engine.Connection.execute`. :param multiparams: Multiple parameter sets, a list of dictionaries. :param params: Single parameter set, a single dictionary. :param execution_options: dictionary of execution options passed along with the statement, if any. This is a merge of all options that will be used, including those of the statement, the connection, and those passed in to the method itself for the 2.0 style of execution. .. versionadded: 1.4 .. seealso:: :meth:`.before_cursor_execute` N( ( t selfR R R R R ( ( sK /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/events.pyR � t t resultc C s | | | | | f S( N( ( R R R R R R( ( ( sK /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/events.pyR% � s c C s d S( sg Intercept high level execute() events after execute. :param conn: :class:`_engine.Connection` object :param clauseelement: SQL expression construct, :class:`.Compiled` instance, or string statement passed to :meth:`_engine.Connection.execute`. :param multiparams: Multiple parameter sets, a list of dictionaries. :param params: Single parameter set, a single dictionary. :param execution_options: dictionary of execution options passed along with the statement, if any. This is a merge of all options that will be used, including those of the statement, the connection, and those passed in to the method itself for the 2.0 style of execution. .. versionadded: 1.4 :param result: :class:`_engine.CursorResult` generated by the execution. N( ( R&