self.post_process_text(textclause.text))
)
- def visit_text_as_from(self, taf, iswrapper=False,
- compound_index=0, force_result_map=False,
+ def visit_text_as_from(self, taf,
+ compound_index=None, force_result_map=False,
asfrom=False,
parens=True, **kw):
toplevel = not self.stack
entry = self._default_stack_entry if toplevel else self.stack[-1]
- populate_result_map = force_result_map or (
- compound_index == 0 and (
- toplevel or
- entry['iswrapper']
- )
- )
+ populate_result_map = force_result_map or \
+ toplevel or \
+ (compound_index == 0 and entry.get(
+ 'need_result_map_for_compound', False))
if populate_result_map:
self._ordered_columns = False
parens=True, compound_index=0, **kwargs):
toplevel = not self.stack
entry = self._default_stack_entry if toplevel else self.stack[-1]
+ need_result_map = toplevel or \
+ (compound_index == 0
+ and entry.get('need_result_map_for_compound', False))
self.stack.append(
{
'correlate_froms': entry['correlate_froms'],
- 'iswrapper': toplevel,
'asfrom_froms': entry['asfrom_froms'],
- 'selectable': cs
+ 'selectable': cs,
+ 'need_result_map_for_compound': need_result_map
})
keyword = self.compound_keywords.get(cs.keyword)
or cs._offset_clause is not None) and \
self.limit_clause(cs, **kwargs) or ""
- if self.ctes and \
- compound_index == 0 and toplevel:
+ if self.ctes and toplevel:
text = self._render_cte_clause() + text
self.stack.pop(-1)
]
_default_stack_entry = util.immutabledict([
- ('iswrapper', False),
('correlate_froms', frozenset()),
('asfrom_froms', frozenset())
])
return froms
def visit_select(self, select, asfrom=False, parens=True,
- iswrapper=False, fromhints=None,
+ fromhints=None,
compound_index=0,
force_result_map=False,
nested_join_translation=False,
+ _select_wraps=None,
**kwargs):
needs_nested_translation = \
select)
text = self.visit_select(
transformed_select, asfrom=asfrom, parens=parens,
- iswrapper=iswrapper, fromhints=fromhints,
+ fromhints=fromhints,
compound_index=compound_index,
force_result_map=force_result_map,
nested_join_translation=True, **kwargs
toplevel = not self.stack
entry = self._default_stack_entry if toplevel else self.stack[-1]
- populate_result_map = force_result_map or (
- compound_index == 0 and (
- toplevel or
- entry['iswrapper']
+ populate_result_map = force_result_map or \
+ toplevel or (
+ compound_index == 0 and entry.get(
+ 'need_result_map_for_compound', False)
)
- )
if needs_nested_translation:
if populate_result_map:
select, transformed_select)
return text
- froms = self._setup_select_stack(select, entry, asfrom, iswrapper)
+ froms = self._setup_select_stack(select, entry, asfrom)
column_clause_args = kwargs.copy()
column_clause_args.update({
# the actual list of columns to print in the SELECT column list.
inner_columns = [
c for c in [
- self._label_select_column(select,
- column,
- populate_result_map, asfrom,
- column_clause_args,
- name=name)
+ self._label_select_column(
+ select,
+ column,
+ populate_result_map, asfrom,
+ column_clause_args,
+ name=name)
for name, column in select._columns_plus_names
]
if c is not None
]
+ if populate_result_map and _select_wraps is not None:
+ # if this select is a compiler-generated wrapper,
+ # rewrite the targeted columns in the result map
+ wrapped_inner_columns = set(_select_wraps.inner_columns)
+ translate = dict(
+ (outer, inner.pop()) for outer, inner in [
+ (
+ outer,
+ outer.proxy_set.intersection(wrapped_inner_columns))
+ for outer in select.inner_columns
+ ] if inner
+ )
+ self._result_columns = [
+ (key, name, tuple(translate.get(o, o) for o in obj), type_)
+ for key, name, obj, type_ in self._result_columns
+ ]
+
text = self._compose_select_body(
text, select, inner_columns, froms, byfrom, kwargs)
if per_dialect:
text += " " + self.get_statement_hint_text(per_dialect)
- if self.ctes and \
- compound_index == 0 and toplevel:
+ if self.ctes and toplevel:
text = self._render_cte_clause() + text
if select._suffixes:
hint_text = self.get_select_hint_text(byfrom)
return hint_text, byfrom
- def _setup_select_stack(self, select, entry, asfrom, iswrapper):
+ def _setup_select_stack(self, select, entry, asfrom):
correlate_froms = entry['correlate_froms']
asfrom_froms = entry['asfrom_froms']
new_entry = {
'asfrom_froms': new_correlate_froms,
- 'iswrapper': iswrapper,
'correlate_froms': all_correlate_froms,
'selectable': select,
}
def visit_insert(self, insert_stmt, **kw):
self.stack.append(
{'correlate_froms': set(),
- "iswrapper": False,
"asfrom_froms": set(),
"selectable": insert_stmt})
def visit_update(self, update_stmt, **kw):
self.stack.append(
{'correlate_froms': set([update_stmt.table]),
- "iswrapper": False,
"asfrom_froms": set([update_stmt.table]),
"selectable": update_stmt})
def visit_delete(self, delete_stmt, **kw):
self.stack.append({'correlate_froms': set([delete_stmt.table]),
- "iswrapper": False,
"asfrom_froms": set([delete_stmt.table]),
"selectable": delete_stmt})
self.isdelete = True
"SELECT TOP 0 t.x, t.y FROM t WHERE t.x = :x_1 ORDER BY t.y",
checkparams={'x_1': 5}
)
+ c = s.compile(dialect=mssql.MSDialect())
+ eq_(len(c._result_columns), 2)
+ assert t.c.x in set(c.result_map['x'][1])
def test_offset_using_window(self):
t = table('t', column('x', Integer), column('y', Integer))
- s = select([t]).where(t.c.x==5).order_by(t.c.y).offset(20)
+ s = select([t]).where(t.c.x == 5).order_by(t.c.y).offset(20)
# test that the select is not altered with subsequent compile
# calls
checkparams={'param_1': 20, 'x_1': 5}
)
+ c = s.compile(dialect=mssql.MSDialect())
+ eq_(len(c._result_columns), 2)
+ assert t.c.x in set(c.result_map['x'][1])
+
def test_limit_offset_using_window(self):
t = table('t', column('x', Integer), column('y', Integer))
"WHERE mssql_rn > :param_1 AND mssql_rn <= :param_2 + :param_1",
checkparams={'param_1': 20, 'param_2': 10, 'x_1': 5}
)
+ c = s.compile(dialect=mssql.MSDialect())
+ eq_(len(c._result_columns), 2)
+ assert t.c.x in set(c.result_map['x'][1])
+ assert t.c.y in set(c.result_map['y'][1])
def test_limit_offset_with_correlated_order_by(self):
t1 = table('t1', column('x', Integer), column('y', Integer))
checkparams={'param_1': 20, 'param_2': 10, 'x_1': 5}
)
+ c = s.compile(dialect=mssql.MSDialect())
+ eq_(len(c._result_columns), 2)
+ assert t1.c.x in set(c.result_map['x'][1])
+ assert t1.c.y in set(c.result_map['y'][1])
+
def test_limit_zero_offset_using_window(self):
t = table('t', column('x', Integer), column('y', Integer))
checkparams={'param_1': 10, 'param_2': 20})
c = s.compile(dialect=oracle.OracleDialect())
+ eq_(len(c._result_columns), 2)
assert t.c.col1 in set(c.result_map['col1'][1])
- s = select([s.c.col1, s.c.col2])
- self.assert_compile(s,
+
+ s2 = select([s.c.col1, s.c.col2])
+ self.assert_compile(s2,
'SELECT col1, col2 FROM (SELECT col1, col2 '
'FROM (SELECT col1, col2, ROWNUM AS ora_rn '
'FROM (SELECT sometable.col1 AS col1, '
':param_2)',
checkparams={'param_1': 10, 'param_2': 20})
- self.assert_compile(s,
+ self.assert_compile(s2,
'SELECT col1, col2 FROM (SELECT col1, col2 '
'FROM (SELECT col1, col2, ROWNUM AS ora_rn '
'FROM (SELECT sometable.col1 AS col1, '
'sometable.col2 AS col2 FROM sometable) '
'WHERE ROWNUM <= :param_1 + :param_2) WHERE ora_rn > '
':param_2)')
+ c = s2.compile(dialect=oracle.OracleDialect())
+ eq_(len(c._result_columns), 2)
+ assert s.c.col1 in set(c.result_map['col1'][1])
s = select([t]).limit(10).offset(20).order_by(t.c.col2)
self.assert_compile(s,
':param_1 + :param_2) WHERE ora_rn > :param_2',
checkparams={'param_1': 10, 'param_2': 20}
)
+ c = s.compile(dialect=oracle.OracleDialect())
+ eq_(len(c._result_columns), 2)
+ assert t.c.col1 in set(c.result_map['col1'][1])
s = select([t], for_update=True).limit(10).order_by(t.c.col2)
self.assert_compile(s,