Skip to content

Commit b249e16

Browse files
committed
Adding a limit of zero now works.
1 parent bc3d2f5 commit b249e16

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,12 @@ def add_limit_offset!(sql, options)
338338
else
339339
sql << ") AS tmp2"
340340
end
341-
elsif sql !~ /^\s*SELECT (@@|COUNT\()/i
342-
unless options[:limit].nil? || options[:limit] < 1
343-
if md = sql.match(/^(\s*SELECT)(\s+DISTINCT)?(.*)/im)
344-
sql.replace "#{md[1]}#{md[2]} TOP #{options[:limit]}#{md[3]}"
345-
else
346-
# Account for building SQL fragments without SELECT yet. See #update_all and #limited_update_conditions.
347-
sql.replace "TOP #{options[:limit]} #{sql}"
348-
end
341+
elsif options[:limit] && sql !~ /^\s*SELECT (@@|COUNT\()/i
342+
if md = sql.match(/^(\s*SELECT)(\s+DISTINCT)?(.*)/im)
343+
sql.replace "#{md[1]}#{md[2]} TOP #{options[:limit]}#{md[3]}"
344+
else
345+
# Account for building SQL fragments without SELECT yet. See #update_all and #limited_update_conditions.
346+
sql.replace "TOP #{options[:limit]} #{sql}"
349347
end
350348
end
351349
end

0 commit comments

Comments
 (0)