summaryrefslogtreecommitdiff
path: root/test/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-03-19 13:03:44 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-03-19 13:03:44 -0400
commit2a1a79b6ce53f2e1dc4cd48bbca5c5a148b8b285 (patch)
tree40acfcb869ba3747e531c172627d2bccd13d18f4 /test/engine
parent89a8e0d187b8967c9b8291bcdc3078335704dbfa (diff)
downloadsqlalchemy-2a1a79b6ce53f2e1dc4cd48bbca5c5a148b8b285.tar.gz
- The :meth:`.ConnectionEvents.after_cursor_execute` event is now
emitted for the "_cursor_execute()" method of :class:`.Connection`; this is the "quick" executor that is used for things like when a sequence is executed ahead of an INSERT statement, as well as for dialect startup checks like unicode returns, charset, etc. the :meth:`.ConnectionEvents.before_cursor_execute` event was already invoked here. The "executemany" flag is now always set to False here, as this event always corresponds to a single execution. Previously the flag could be True if we were acting on behalf of an executemany INSERT statement.
Diffstat (limited to 'test/engine')
-rw-r--r--test/engine/test_execute.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py
index d3bd3c2cd..6efcdcb89 100644
--- a/test/engine/test_execute.py
+++ b/test/engine/test_execute.py
@@ -1235,6 +1235,48 @@ class EngineEventsTest(fixtures.TestBase):
canary.be1.assert_call_count(2)
canary.be2.assert_call_count(2)
+ def test_cursor_events_ctx_execute_scalar(self):
+ canary = Mock()
+ e1 = testing_engine(config.db_url)
+
+ event.listen(e1, "before_cursor_execute", canary.bce)
+ event.listen(e1, "after_cursor_execute", canary.ace)
+
+ stmt = str(select([1]).compile(dialect=e1.dialect))
+
+ with e1.connect() as conn:
+ dialect = conn.dialect
+
+ ctx = dialect.execution_ctx_cls._init_statement(
+ dialect, conn, conn.connection, stmt, {})
+
+ ctx._execute_scalar(stmt, Integer())
+
+ eq_(canary.bce.mock_calls,
+ [call(conn, ctx.cursor, stmt, ctx.parameters[0], ctx, False)])
+ eq_(canary.ace.mock_calls,
+ [call(conn, ctx.cursor, stmt, ctx.parameters[0], ctx, False)])
+
+ def test_cursor_events_execute(self):
+ canary = Mock()
+ e1 = testing_engine(config.db_url)
+
+ event.listen(e1, "before_cursor_execute", canary.bce)
+ event.listen(e1, "after_cursor_execute", canary.ace)
+
+ stmt = str(select([1]).compile(dialect=e1.dialect))
+
+ with e1.connect() as conn:
+
+ result = conn.execute(stmt)
+
+ ctx = result.context
+ eq_(canary.bce.mock_calls,
+ [call(conn, ctx.cursor, stmt, ctx.parameters[0], ctx, False)])
+ eq_(canary.ace.mock_calls,
+ [call(conn, ctx.cursor, stmt, ctx.parameters[0], ctx, False)])
+
+
def test_argument_format_execute(self):
def before_execute(conn, clauseelement, multiparams, params):
assert isinstance(multiparams, (list, tuple))