We're updating the issue view to help you get more done. 

SQLServer2005LimitHandler uncapable of handle subquery in column list

Description

Hi guys,

I just stumbled across the default SQLServer2005LimitHandler which is the default limit handler for SQL server. We have queries with a subquery in the column list like this one:

1 2 3 4 5 6 7 8 9 10 11 select alias1.someColumn1 as col_0_0_, alias1.someColumn2 as col_1_0_, alias1.someColumn3 as col_2_0_, alias1.someColumn4 as col_3_0_, (select case when count(alias2.someColumn1)>0 then 'ADDED' else 'UNMODIFIED' end from Table1 alias2 where (alias2.someColumn1 in (?)) and alias2.someColumn=alias1.someColumn1) as col_4_0_ from Table1 alias1 where (...) order by alias1.someColumn2 ASC

When the limit handler trys to get the position of the FROM-clause (in method fillAliasInSelectClause) it uses a regular expression:

1 (\bfrom)(?![^\(]*\))

to determine the actual column aliases in the select. This will match the first FROM-clause in the subquery thus yielding to a wrong select list of the limit clause like this for the example above:

1 col_0_0_, col_1_0_, col_2_0_, col_3_0_, end

Environment

None

Status

Assignee

Chris Cranford

Reporter

Sebastian Götz

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.0.11
5.1.3
5.2.5

Priority

Major