summaryrefslogtreecommitdiff
path: root/test/engine/test_execute.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-08-23 15:40:09 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-08-23 15:40:09 -0400
commit28bfc3d5dfdaae57a94f660959aaaeb83a5e2132 (patch)
tree43d42adce27ce2d606e8f1fae4849b722f0d8bd3 /test/engine/test_execute.py
parent16d66d35644eaa6609fdc5c8f805314f7cf4d0fc (diff)
downloadsqlalchemy-28bfc3d5dfdaae57a94f660959aaaeb83a5e2132.tar.gz
- [feature] The before_cursor_execute event
fires off for so-called "_cursor_execute" events, which are usually special-case executions of primary-key bound sequences and default-generation SQL phrases that invoke separately when RETURNING is not used with INSERT. [ticket:2459]
Diffstat (limited to 'test/engine/test_execute.py')
-rw-r--r--test/engine/test_execute.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py
index a23f8d05a..85b03e0e9 100644
--- a/test/engine/test_execute.py
+++ b/test/engine/test_execute.py
@@ -1,4 +1,5 @@
-from test.lib.testing import eq_, assert_raises, assert_raises_message, config
+from test.lib.testing import eq_, assert_raises, assert_raises_message, \
+ config, is_
import re
from test.lib.util import picklers
from sqlalchemy.interfaces import ConnectionProxy
@@ -1253,6 +1254,33 @@ class EngineEventsTest(fixtures.TestBase):
canary, ['execute', 'cursor_execute']
)
+ @testing.requires.sequences
+ @testing.provide_metadata
+ def test_cursor_execute(self):
+ canary = []
+ def tracker(name):
+ def go(conn, cursor, statement, parameters, context, executemany):
+ canary.append((statement, context))
+ return go
+ engine = engines.testing_engine()
+
+
+ t = Table('t', self.metadata,
+ Column('x', Integer, Sequence('t_id_seq'), primary_key=True),
+ implicit_returning=False
+ )
+ self.metadata.create_all(engine)
+ with engine.begin() as conn:
+ event.listen(conn, 'before_cursor_execute', tracker('cursor_execute'))
+ conn.execute(t.insert())
+ # we see the sequence pre-executed in the first call
+ assert "t_id_seq" in canary[0][0]
+ assert "INSERT" in canary[1][0]
+ # same context
+ is_(
+ canary[0][1], canary[1][1]
+ )
+
def test_transactional(self):
canary = []
def tracker(name):