compilers that apply binds in select precolumns can be out of sync with column-nested subqueries

Issue #3038 resolved
Mike Bayer repo owner created an issue

e.g. firebird, sql server, others:

from sqlalchemy import *
from sqlalchemy.sql import column, literal

s1 = select([column('x')]).select_from('a').limit(5).as_scalar()
s2 = select([s1]).limit(10)

from sqlalchemy.engine import default
from sqlalchemy.sql import compiler
class MyCompiler(compiler.SQLCompiler):
    def get_select_precolumns(self, select):
        result = ""
        if select._limit:
            result += "FIRST %s " % self.process(literal(select._limit))
        if select._offset:
            result += "SKIP %s " % self.process(literal(select._offset))
        return result

    def limit_clause(self, select):
        return ""


dialect = default.DefaultDialect()
dialect.statement_compiler = MyCompiler
dialect.paramstyle = 'qmark'
dialect.positional = True
compiled = s2.compile(dialect=dialect)
assert \
  [compiled.params[name] for name in compiled.positiontup] == [10, 5]

Comments (2)

  1. Mike Bayer reporter
    • Fixed bug where the combination of "limit" rendering as "SELECT FIRST n ROWS" using a bound parameter (only firebird has both), combined with column-level subqueries which also feature "limit" as well as "positional" bound parameters (e.g. qmark style) would erroneously assign the subquery-level positions before that of the enclosing SELECT, thus returning parameters which are out of order. Fixes #3038

    → <<cset 5da667e01727>>

  2. Mike Bayer reporter
    • Fixed bug where the combination of "limit" rendering as "SELECT FIRST n ROWS" using a bound parameter (only firebird has both), combined with column-level subqueries which also feature "limit" as well as "positional" bound parameters (e.g. qmark style) would erroneously assign the subquery-level positions before that of the enclosing SELECT, thus returning parameters which are out of order. Fixes #3038

    → <<cset 2a458680a493>>

  3. Log in to comment