Skip to content

Commit 6317303

Browse files
committed
Remove more old AR version checks
1 parent ce5431d commit 6317303

File tree

3 files changed

+4
-137
lines changed

3 files changed

+4
-137
lines changed

lib/arel/visitors/h2.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,7 @@ class H2 < Arel::Visitors::HSQLDB
77
def visit_Arel_Nodes_SelectStatement(o, *)
88
o.limit ||= Arel::Nodes::Limit.new(-1) if o.offset
99
super
10-
end if ArJdbc::AR42
11-
12-
def limit_offset sql, o
13-
offset = o.offset || 0
14-
offset = offset.expr unless (offset.nil? || offset == 0)
15-
if limit = o.limit
16-
"SELECT LIMIT #{offset} #{limit_for(limit)} #{sql[7..-1]}"
17-
elsif offset > 0
18-
"SELECT LIMIT #{offset} -1 #{sql[7..-1]}" # removes "SELECT "
19-
else
20-
sql
21-
end
22-
end unless ArJdbc::AR42
10+
end
2311
end
2412
end
2513
end

lib/arel/visitors/hsqldb.rb

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,7 @@ class HSQLDB < Arel::Visitors::ToSql
66
def visit_Arel_Nodes_SelectStatement(o, *)
77
o.limit ||= Arel::Nodes::Limit.new(0) if o.offset
88
super
9-
end if ArJdbc::AR42
10-
11-
def visit_Arel_Nodes_SelectStatement o, a = nil
12-
sql = limit_offset(o.cores.map { |x| do_visit_select_core x, a }.join, o)
13-
sql << " ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}" unless o.orders.empty?
14-
sql
15-
end unless ArJdbc::AR42
16-
17-
private
18-
19-
def limit_offset sql, o
20-
offset = o.offset || 0
21-
offset = offset.expr unless (offset.nil? || offset == 0)
22-
if limit = o.limit
23-
"SELECT LIMIT #{offset} #{limit_for(limit)} #{sql[7..-1]}"
24-
elsif offset > 0
25-
"SELECT LIMIT #{offset} 0 #{sql[7..-1]}" # removes "SELECT "
26-
else
27-
sql
28-
end
29-
end unless ArJdbc::AR42
9+
end
3010
end
3111
end
3212
end

lib/arel/visitors/sql_server.rb

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,6 @@ class SQLServer < const_defined?(:MSSQL) ? MSSQL : ToSql
1111

1212
private
1313

14-
def visit_Arel_Nodes_SelectStatement(*args) # [o] AR <= 4.0 [o, a] on 4.1
15-
o, a = args.first, args.last
16-
17-
return _visit_Arel_Nodes_SelectStatement(*args) if ! o.limit && ! o.offset
18-
19-
unless o.orders.empty?
20-
select_order_by = do_visit_columns o.orders, a, 'ORDER BY '
21-
end
22-
23-
select_count = false; sql = ''
24-
o.cores.each do |x|
25-
x = x.dup
26-
core_order_by = select_order_by || determine_order_by(x, a)
27-
if select_count? x
28-
x.projections = [
29-
Arel::Nodes::SqlLiteral.new(core_order_by ? over_row_num(core_order_by) : '*')
30-
]
31-
select_count = true
32-
else
33-
# NOTE: this should really be added here and we should built the
34-
# wrapping SQL but than #replace_limit_offset! assumes it does that
35-
# ... MS-SQL adapter code seems to be 'hacked' by a lot of people
36-
#x.projections << Arel::Nodes::SqlLiteral.new over_row_num(order_by)
37-
end
38-
sql << do_visit_select_core(x, a)
39-
end
40-
41-
#sql = "SELECT _t.* FROM (#{sql}) as _t WHERE #{get_offset_limit_clause(o)}"
42-
select_order_by ||= "ORDER BY #{@connection.determine_order_clause(sql)}"
43-
replace_limit_offset!(sql, limit_for(o.limit), o.offset && o.offset.value.to_i, select_order_by)
44-
45-
sql = "SELECT COUNT(*) AS count_id FROM (#{sql}) AS subquery" if select_count
46-
47-
add_lock!(sql, :lock => o.lock && true)
48-
49-
sql
50-
end unless ArJdbc::AR42
51-
5214
# @private
5315
MAX_LIMIT_VALUE = 9_223_372_036_854_775_807
5416

@@ -60,14 +22,6 @@ def visit_Arel_Nodes_UpdateStatement(*args) # [o] AR <= 4.0 [o, a] on 4.1
6022
super
6123
end
6224

63-
def visit_Arel_Nodes_Lock o, a = nil
64-
# MS-SQL doesn't support "SELECT...FOR UPDATE". Instead, it needs
65-
# WITH(ROWLOCK,UPDLOCK) specified after each table in the FROM clause.
66-
#
67-
# we return nothing here and add the appropriate stuff with #add_lock!
68-
#do_visit o.expr, a
69-
end unless ArJdbc::AR42
70-
7125
def visit_Arel_Nodes_Top o, a = nil
7226
# `top` wouldn't really work here:
7327
# User.select("distinct first_name").limit(10)
@@ -76,29 +30,6 @@ def visit_Arel_Nodes_Top o, a = nil
7630
a || ''
7731
end
7832

79-
def visit_Arel_Nodes_Limit o, a = nil
80-
"TOP (#{do_visit o.expr, a})"
81-
end unless ArJdbc::AR42
82-
83-
def visit_Arel_Nodes_Ordering o, a = nil
84-
expr = do_visit o.expr, a
85-
if o.respond_to?(:direction)
86-
"#{expr} #{o.ascending? ? 'ASC' : 'DESC'}"
87-
else
88-
expr
89-
end
90-
end unless ArJdbc::AR42
91-
92-
def visit_Arel_Nodes_Bin o, a = nil
93-
expr = o.expr; sql = do_visit expr, a
94-
if expr.respond_to?(:val) && expr.val.is_a?(Numeric)
95-
sql
96-
else
97-
sql << " #{::ArJdbc::MSSQL.cs_equality_operator} "
98-
sql
99-
end
100-
end unless ArJdbc::AR42
101-
10233
private
10334

10435
def self.possibly_private_method_defined?(name)
@@ -140,25 +71,7 @@ def do_visit_columns(colls, a, sql)
14071
visit(x, sql); sql << ', ' unless i == last
14172
end
14273
sql.value
143-
end if ArJdbc::AR42
144-
145-
def do_visit_columns(colls, a, sql)
146-
non_simple_order = /\sASC|\sDESC|\sCASE|\sCOLLATE|[\.,\[\(]/i # MIN(width)
147-
148-
last = colls.size - 1
149-
colls.each_with_index do |x, i|
150-
coll = do_visit(x, a)
151-
152-
if coll !~ non_simple_order && coll.to_i == 0
153-
sql << @connection.quote_column_name(coll)
154-
else
155-
sql << coll
156-
end
157-
158-
sql << ', ' unless i == last
159-
end
160-
sql
161-
end if Arel::VERSION < '4.0.0'
74+
end
16275

16376
def over_row_num order_by
16477
"ROW_NUMBER() OVER (#{order_by}) as _row_num"
@@ -174,20 +87,6 @@ def table_from_select_core core
17487
end
17588
end
17689

177-
def table_from_select_core core
178-
table_finder = lambda do |x|
179-
case x
180-
when Arel::Table
181-
x
182-
when Arel::Nodes::SqlLiteral
183-
Arel::Table.new(x, @engine)
184-
when Arel::Nodes::Join
185-
table_finder.call(x.left)
186-
end
187-
end
188-
table_finder.call(core.froms)
189-
end if ActiveRecord::VERSION::STRING < '3.2'
190-
19190
def primary_key_from_table t
19291
return unless t
19392
return t.primary_key if t.primary_key
@@ -219,7 +118,7 @@ class SQLServer2000 < SQLServer
219118
include ArJdbc::MSSQL::LimitHelpers::SqlServer2000ReplaceLimitOffset
220119
end
221120

222-
load 'arel/visitors/sql_server/ng42.rb' if ArJdbc::AR42
121+
load 'arel/visitors/sql_server/ng42.rb'
223122

224123
end
225124
end

0 commit comments

Comments
 (0)