diff options
Diffstat (limited to 'lib/sqlalchemy/interfaces.py')
-rw-r--r-- | lib/sqlalchemy/interfaces.py | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/sqlalchemy/interfaces.py b/lib/sqlalchemy/interfaces.py index f9c21d246..dfceffe44 100644 --- a/lib/sqlalchemy/interfaces.py +++ b/lib/sqlalchemy/interfaces.py @@ -108,20 +108,37 @@ class PoolListener(object): class ConnectionProxy(object): """Allows interception of statement execution by Connections. - Subclass ``ConnectionProxy``, overriding either or both of - ``execute()`` and ``cursor_execute()`` The default behavior is provided, - which is to call the given executor function with the remaining - arguments. The proxy is then connected to an engine via - ``create_engine(url, proxy=MyProxy())`` where ``MyProxy`` is - the user-defined ``ConnectionProxy`` class. + Either or both of the ``execute()`` and ``cursor_execute()`` + may be implemented to intercept compiled statement and + cursor level executions, e.g.:: + + class MyProxy(ConnectionProxy): + def execute(self, conn, execute, clauseelement, *multiparams, **params): + print "compiled statement:", clauseelement + return execute(clauseelement, *multiparams, **params) + + def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): + print "raw statement:", statement + return execute(cursor, statement, parameters, context) + + The ``execute`` argument is a function that will fulfill the default + execution behavior for the operation. The signature illustrated + in the example should be used. + + The proxy is installed into an :class:`~sqlalchemy.engine.Engine` via + the ``proxy`` argument:: + + e = create_engine('someurl://', proxy=MyProxy()) """ def execute(self, conn, execute, clauseelement, *multiparams, **params): - """""" + """Intercept high level execute() events.""" + return execute(clauseelement, *multiparams, **params) def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): - """""" + """Intercept low-level cursor execute() events.""" + return execute(cursor, statement, parameters, context) |