summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-03-08 12:33:38 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-03-08 12:33:38 -0400
commit4ba715f80a003a621f107c374b118754ba760cb7 (patch)
treed93e24d77211419ef95c2185b623aaeab79cfdb2 /test/sql
parent9854114f578833aee49b65e440319a0ec26daab6 (diff)
downloadsqlalchemy-4ba715f80a003a621f107c374b118754ba760cb7.tar.gz
- rename _select_wraps
- replace force_result_map with a mini-API for nested result sets, add coverage
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_compiler.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 73c1402f6..4b143c150 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -3466,3 +3466,64 @@ class ResultMapTest(fixtures.TestBase):
comp._create_result_map(),
{'a': ('a', (aint, 'a', 'a'), aint.type)}
)
+
+ def test_nested_api(self):
+ from sqlalchemy.engine.result import ResultMetaData
+ stmt2 = select([table2])
+
+ stmt1 = select([table1]).select_from(stmt2)
+
+ contexts = {}
+
+ int_ = Integer()
+
+ class MyCompiler(compiler.SQLCompiler):
+ def visit_select(self, stmt, *arg, **kw):
+
+ if stmt is stmt2:
+ with self._nested_result() as nested:
+ contexts[stmt2] = nested
+ text = super(MyCompiler, self).visit_select(stmt2)
+ self._add_to_result_map("k1", "k1", (1, 2, 3), int_)
+ else:
+ text = super(MyCompiler, self).visit_select(
+ stmt, *arg, **kw)
+ self._add_to_result_map("k2", "k2", (3, 4, 5), int_)
+ return text
+
+ comp = MyCompiler(default.DefaultDialect(), stmt1)
+
+ eq_(
+ ResultMetaData._create_result_map(contexts[stmt2][0]),
+ {
+ 'otherid': (
+ 'otherid',
+ (table2.c.otherid, 'otherid', 'otherid'),
+ table2.c.otherid.type),
+ 'othername': (
+ 'othername',
+ (table2.c.othername, 'othername', 'othername'),
+ table2.c.othername.type),
+ 'k1': ('k1', (1, 2, 3), int_)
+ }
+ )
+ eq_(
+ comp._create_result_map(),
+ {
+ 'myid': (
+ 'myid',
+ (table1.c.myid, 'myid', 'myid'), table1.c.myid.type
+ ),
+ 'k2': ('k2', (3, 4, 5), int_),
+ 'name': (
+ 'name', (table1.c.name, 'name', 'name'),
+ table1.c.name.type),
+ 'description': (
+ 'description',
+ (table1.c.description, 'description', 'description'),
+ table1.c.description.type)}
+ )
+
+
+
+