From 40b0e4b424c87adedfdf3bf968f3ee6851743fc2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 10 May 2016 12:49:56 -0400 Subject: Fix label referencing in SQL Server OFFSET logic Fixed bug where by ROW_NUMBER OVER clause applied for OFFSET selects in SQL Server would inappropriately substitute a plain column from the local statement that overlaps with a label name used by the ORDER BY criteria of the statement. Change-Id: Ic2500c886cbfc83a1ad5a2681783f008b9f23838 Fixes: #3711 (cherry picked from commit a4be7c92393e08607dc46f318e97803519052a93) --- lib/sqlalchemy/sql/util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 16a1421f6..665814f84 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -173,6 +173,16 @@ def unwrap_order_by(clause): return cols +def unwrap_label_reference(element): + def replace(elem): + if isinstance(elem, (_label_reference, _textual_label_reference)): + return elem.element + + return visitors.replacement_traverse( + element, {}, replace + ) + + def clause_is_present(clause, search): """Given a target clause and a second to search within, return True if the target is plainly present in the search without any -- cgit v1.2.1