From 60793cc27f4e930c3139d4ab296c5df443c0623c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 9 Feb 2006 21:42:29 +0000 Subject: SQLServer: more compatible limit/offset emulation. Closes #3779. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3564 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ .../lib/active_record/connection_adapters/sqlserver_adapter.rb | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index c3bae2c841..32f71130d6 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* SQLServer: more compatible limit/offset emulation. #3779 [Tom Ward] + * Polymorphic join support for has_one associations (has_one :foo, :as => :bar) #3785 [Rick Olson] * PostgreSQL: correctly parse negative integer column defaults. #3776 [bellis@deepthought.org] diff --git a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb index 9d7174007c..708ec086fd 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb @@ -375,7 +375,9 @@ module ActiveRecord sql << " ) AS tmp2" end elsif sql !~ /^\s*SELECT (@@|COUNT\()/i - sql.sub!(/^\s*SELECT/i, "SELECT TOP #{options[:limit]}") unless options[:limit].nil? + sql.sub!(/^\s*SELECT([\s]*distinct)?/i) do + "SELECT#{$1} TOP #{options[:limit]}" + end unless options[:limit].nil? end end -- cgit v1.2.3