Skip to content

Commit e609ae9

Browse files
committed
Allow :limit/:offset to be used with fully qualified table and column in :select.
1 parent e849c7a commit e609ae9

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
* 3.1.1 *
3+
4+
* Allow :limit/:offset to be used with fully qualified table and column in :select.
5+
6+
27
* 3.1.0 *
38

49
* Add support/test around handling of float/real column types [Lucas Maxwell]

activerecord-sqlserver-adapter.gemspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# -*- encoding: utf-8 -*-
2+
$:.push File.expand_path("../lib", __FILE__)
3+
require "active_record/connection_adapters/sqlserver/version"
14

25
Gem::Specification.new do |s|
36
s.platform = Gem::Platform::RUBY
47
s.name = "activerecord-sqlserver-adapter"
5-
s.version = "3.1.0"
8+
s.version = ActiveRecord::ConnectionAdapters::Sqlserver::Version::VERSION
69
s.summary = "SQL Server 2005 and 2008 Adapter For ActiveRecord."
710
s.description = "SQL Server 2005 and 2008 Adapter For ActiveRecord"
811

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module ActiveRecord
2+
module ConnectionAdapters
3+
module Sqlserver
4+
module Version
5+
6+
VERSION = '3.1.1'.freeze
7+
8+
end
9+
end
10+
end
11+
end

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require 'active_record/connection_adapters/sqlserver/errors'
88
require 'active_record/connection_adapters/sqlserver/schema_statements'
99
require 'active_record/connection_adapters/sqlserver/quoting'
10+
require 'active_record/connection_adapters/sqlserver/version'
1011
require 'active_support/core_ext/kernel/requires'
1112
require 'active_support/core_ext/string'
1213
require 'base64'
@@ -165,9 +166,9 @@ class SQLServerAdapter < AbstractAdapter
165166
include Sqlserver::SchemaStatements
166167
include Sqlserver::DatabaseLimits
167168
include Sqlserver::Errors
169+
include Sqlserver::Version
168170

169171
ADAPTER_NAME = 'SQLServer'.freeze
170-
VERSION = '3.1.0'.freeze
171172
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
172173
SUPPORTED_VERSIONS = [2005,2008,2010,2011].freeze
173174

lib/arel/visitors/sqlserver.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -329,20 +329,10 @@ def rowtable_projections(o)
329329
core.projections.map do |x|
330330
Arel.sql visit(x).split(',').map{ |y| y.split(' AS ').last.strip }.join(', ')
331331
end
332-
elsif function_select_statement?(o)
333-
[Arel.star]
334332
elsif select_primary_key_sql?(o)
335333
[Arel.sql("[__rnt].#{quote_column_name(core.projections.first.name)}")]
336334
else
337-
core.projections.map do |x|
338-
if x.respond_to?(:relation)
339-
x = x.dup
340-
x.relation = x.relation.dup
341-
x.relation.instance_variable_set :@table_alias, Arel.sql('[__rnt].*')
342-
else
343-
x
344-
end
345-
end
335+
[Arel.sql('[__rnt].*')]
346336
end
347337
end
348338

test/cases/offset_and_limit_test_sqlserver.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class OffsetAndLimitTestSqlserver < ActiveRecord::TestCase
2828

2929
context 'When selecting with limit and offset' do
3030

31+
should 'work with fully qualified table and columns in select' do
32+
books = Book.all :select => 'books.id, books.name', :limit => 3, :offset => 5
33+
assert_equal Book.all[5,3].map(&:id), books.map(&:id)
34+
end
35+
3136
should 'allow sql literal for offset' do
3237
assert_sql(/WHERE \[__rnt\]\.\[__rn\] > \(3-2\)/) { Book.limit(10).offset(Arel.sql('3-2')).all }
3338
assert_sql(/WHERE \[__rnt\]\.\[__rn\] > \(SELECT 8 AS \[count\]\)/) do

0 commit comments

Comments
 (0)