File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
lib/active_record/connection_adapters/sqlserver Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,27 @@ def add_limit_offset!(sql, options)
4949
5050 if limit && !offset
5151 sql
52- elsif limit || offset
52+ elsif !limit && offset
53+ sql
54+ else limit && offset
5355 sql
5456 end
5557
58+ # SELECT [_rnt].[id], [_rnt].[name] FROM
59+ # (SELECT ROW_NUMBER()
60+ # OVER (ORDER BY [users].[id]) AS [rn],
61+ # [users].[id], [users].[name]
62+ # FROM [users]) AS [_rnt]
63+ # WHERE [_rnt].[rn] > 4
64+
65+
66+ # http://github.com/kenglishhi/2000-2005-adapter/commit/476ac1f6dbd517ed090ef350e6d5855a581f6cbf
67+ # if options[:limit] and options[:offset]
68+ # sql.sub! /ORDER BY.*$/i, ''
69+ # sql.sub! /SELECT/i, "SELECT ROW_NUMBER() OVER (ORDER BY #{options[:order]}) AS [row_number], "
70+ # sql.replace "SELECT TOP (#{options[:limit]}) * FROM (#{sql}) as [row_number_table] WHERE [row_number_table].[row_number] > #{options[:offset]}"
71+ # end
72+
5673 # options[:offset] ||= 0
5774 # if options[:offset] > 0
5875 # options[:order] ||= if order_by = sql.match(/ORDER BY (.*$)/i)
You can’t perform that action at this time.
0 commit comments