@@ -11,44 +11,6 @@ class SQLServer < const_defined?(:MSSQL) ? MSSQL : ToSql
11
11
12
12
private
13
13
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
-
52
14
# @private
53
15
MAX_LIMIT_VALUE = 9_223_372_036_854_775_807
54
16
@@ -60,14 +22,6 @@ def visit_Arel_Nodes_UpdateStatement(*args) # [o] AR <= 4.0 [o, a] on 4.1
60
22
super
61
23
end
62
24
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
-
71
25
def visit_Arel_Nodes_Top o , a = nil
72
26
# `top` wouldn't really work here:
73
27
# User.select("distinct first_name").limit(10)
@@ -76,29 +30,6 @@ def visit_Arel_Nodes_Top o, a = nil
76
30
a || ''
77
31
end
78
32
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
-
102
33
private
103
34
104
35
def self . possibly_private_method_defined? ( name )
@@ -140,25 +71,7 @@ def do_visit_columns(colls, a, sql)
140
71
visit ( x , sql ) ; sql << ', ' unless i == last
141
72
end
142
73
sql . value
143
- end if ArJdbc ::AR42
144
-
145
- def do_visit_columns ( colls , a , sql )
146
- non_simple_order = /\s ASC|\s DESC|\s CASE|\s COLLATE|[\. ,\[ \( ]/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
162
75
163
76
def over_row_num order_by
164
77
"ROW_NUMBER() OVER (#{ order_by } ) as _row_num"
@@ -174,20 +87,6 @@ def table_from_select_core core
174
87
end
175
88
end
176
89
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
-
191
90
def primary_key_from_table t
192
91
return unless t
193
92
return t . primary_key if t . primary_key
@@ -219,7 +118,7 @@ class SQLServer2000 < SQLServer
219
118
include ArJdbc ::MSSQL ::LimitHelpers ::SqlServer2000ReplaceLimitOffset
220
119
end
221
120
222
- load 'arel/visitors/sql_server/ng42.rb' if ArJdbc :: AR42
121
+ load 'arel/visitors/sql_server/ng42.rb'
223
122
224
123
end
225
124
end
0 commit comments