diff options
| author | Matt Lewellyn <guruofgentoo@gmail.com> | 2019-04-03 18:39:15 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-04 10:52:29 -0400 |
| commit | 97d4d15fde7999eba29c9708b65e11d82623f686 (patch) | |
| tree | a9195f899a63bfddd631452d50ea09d471162350 /lib/sqlalchemy/dialects/mssql | |
| parent | b90f9b5f367b16ddc1a2d5b06b12649c3fa9efdd (diff) | |
| download | sqlalchemy-97d4d15fde7999eba29c9708b65e11d82623f686.tar.gz | |
MSSQL: only compile ORDER BY if it will be rendered
Fixed issue in SQL Server dialect where if a bound parameter were present in
an ORDER BY expression that would ultimately not be rendered in the SQL
Server version of the statement, the parameters would still be part of the
execution parameters, leading to DBAPI-level errors. Pull request courtesy
Matt Lewellyn.
Fixes: #4587
Closes: #4588
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4588
Pull-request-sha: 2992a473e0f6d4fc27794cfd949ba20a81fad2ca
Change-Id: Ie709aefdb1babf810bb81526289448f8cc7a4cb1
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 992b97188..507fcfdcb 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -1753,10 +1753,16 @@ class MSSQLCompiler(compiler.SQLCompiler): return "" def order_by_clause(self, select, **kw): + # MSSQL only allows ORDER BY in subqueries if there is a LIMIT + if self.is_subquery() and not select._limit: + # avoid processing the order by clause if we won't end up + # using it, because we don't want all the bind params tacked + # onto the positional list if that is what the dbapi requires + return "" + order_by = self.process(select._order_by_clause, **kw) - # MSSQL only allows ORDER BY in subqueries if there is a LIMIT - if order_by and (not self.is_subquery() or select._limit): + if order_by: return " ORDER BY " + order_by else: return "" |
