Permalink
Browse files

Fix Dataset#limit on MSSQL 2000

This was broken when support to allow limit to be a bound variable
was added.  Now Sequel will use TOP(N) for MSSQL 2000, and TOP (N)
for MSSQL 2005+.  Tested on MSSQL 2000 and MSSQL 2008.
  • Loading branch information...
1 parent 2d25ecf commit dd1b39fd37e4ade5071f330be5fce77ebedeb833 @jeremyevans committed Mar 19, 2010
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/sequel/adapters/shared/mssql.rb
@@ -430,9 +430,14 @@ def select_into_sql(sql)
sql << " INTO #{table_ref(@opts[:into])}" if @opts[:into]
end
- # MSSQL uses TOP for limit
+ # MSSQL uses TOP N for limit. For MSSQL 2005+ TOP (N) is used
+ # to allow the limit to be a bound variable.
def select_limit_sql(sql)
- sql << " TOP (#{literal(@opts[:limit])})" if @opts[:limit]
+ if l = @opts[:limit]
+ l = literal(l)
+ l = "(#{l})" if server_version >= 9000000
+ sql << " TOP #{l}"
+ end
end
# Support different types of locking styles

0 comments on commit dd1b39f

Please sign in to comment.