activerecord-sqlserver-adapter 3.0.9 → 3.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +11 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +2 -1
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +14 -5
- data/lib/arel/visitors/sqlserver.rb +13 -29
- metadata +10 -5
data/CHANGELOG
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
|
2
|
+
* 3.0.10 *
|
3
|
+
|
4
|
+
* Fix #rowtable_orders visitor helper to use first column if no pk column was found.
|
5
|
+
|
6
|
+
* Flatten sp_helpconstraint when looking for constraints just in case fks are present. Issue #64.
|
7
|
+
|
8
|
+
* Start to support 2011 code named "Denali".
|
9
|
+
|
10
|
+
* Limit and Offset can take SqlLiteral objects now.
|
11
|
+
|
12
|
+
|
2
13
|
* 3.0.9 *
|
3
14
|
|
4
15
|
* Fix array literal parsing bug for ruby 1.9.
|
@@ -242,7 +242,8 @@ module ActiveRecord
|
|
242
242
|
end
|
243
243
|
|
244
244
|
def remove_default_constraint(table_name, column_name)
|
245
|
-
|
245
|
+
# If their are foreign keys in this table, we could still get back a 2D array, so flatten just in case.
|
246
|
+
select_all("EXEC sp_helpconstraint '#{quote_string(table_name)}','nomsg'").flatten.select do |row|
|
246
247
|
row['constraint_type'] == "DEFAULT on column #{column_name}"
|
247
248
|
end.each do |row|
|
248
249
|
do_execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{row['constraint_name']}"
|
@@ -164,9 +164,9 @@ module ActiveRecord
|
|
164
164
|
include Sqlserver::Errors
|
165
165
|
|
166
166
|
ADAPTER_NAME = 'SQLServer'.freeze
|
167
|
-
VERSION = '3.0.
|
168
|
-
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})
|
169
|
-
SUPPORTED_VERSIONS = [2005,2008].freeze
|
167
|
+
VERSION = '3.0.10'.freeze
|
168
|
+
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
|
169
|
+
SUPPORTED_VERSIONS = [2005,2008,2011].freeze
|
170
170
|
|
171
171
|
attr_reader :database_version, :database_year,
|
172
172
|
:connection_supports_native_types
|
@@ -180,11 +180,16 @@ module ActiveRecord
|
|
180
180
|
connect
|
181
181
|
super(@connection, logger)
|
182
182
|
@database_version = info_schema_query { select_value('SELECT @@version') }
|
183
|
-
@database_year =
|
183
|
+
@database_year = begin
|
184
|
+
year = DATABASE_VERSION_REGEXP.match(@database_version)[1]
|
185
|
+
year == "Denali" ? 2011 : year.to_i
|
186
|
+
rescue
|
187
|
+
0
|
188
|
+
end
|
184
189
|
initialize_sqlserver_caches
|
185
190
|
use_database
|
186
191
|
unless SUPPORTED_VERSIONS.include?(@database_year)
|
187
|
-
raise NotImplementedError, "Currently, only #{SUPPORTED_VERSIONS.to_sentence} are supported."
|
192
|
+
raise NotImplementedError, "Currently, only #{SUPPORTED_VERSIONS.to_sentence} are supported. We got back #{@database_version}."
|
188
193
|
end
|
189
194
|
end
|
190
195
|
|
@@ -285,6 +290,10 @@ module ActiveRecord
|
|
285
290
|
@database_year == 2008
|
286
291
|
end
|
287
292
|
|
293
|
+
def sqlserver_2011?
|
294
|
+
@database_year == 2011
|
295
|
+
end
|
296
|
+
|
288
297
|
def version
|
289
298
|
self.class::VERSION
|
290
299
|
end
|
@@ -6,21 +6,6 @@ module Arel
|
|
6
6
|
class LockWithSQLServer < Arel::Nodes::Unary
|
7
7
|
end
|
8
8
|
|
9
|
-
# In versions of ActiveRecord prior to v3.0.3 limits and offset were always integers via
|
10
|
-
# a #to_i. Somewhere between ActiveRecord and ARel this is not happening anymore nor are they
|
11
|
-
# in agreement which should be responsible. Since we need to make sure that these are visited
|
12
|
-
# correctly and that we can do math with them, these are here to cast to integers.
|
13
|
-
class Limit < Arel::Nodes::Unary
|
14
|
-
def initialize expr
|
15
|
-
@expr = expr.to_i
|
16
|
-
end
|
17
|
-
end
|
18
|
-
class Offset < Arel::Nodes::Unary
|
19
|
-
def initialize expr
|
20
|
-
@expr = expr.to_i
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
9
|
# Extending the Ordering class to be comparrison friendly which allows us to call #uniq on a
|
25
10
|
# collection of them. See SelectManager#order for more details.
|
26
11
|
class Ordering < Arel::Nodes::Binary
|
@@ -49,19 +34,18 @@ module Arel
|
|
49
34
|
@ast.orders.concat(exprs.map{ |x|
|
50
35
|
case x
|
51
36
|
when Arel::Attributes::Attribute
|
52
|
-
|
53
|
-
|
54
|
-
expr = Arel::Nodes::SqlLiteral.new "#{c.quote_table_name(tn)}.#{c.quote_column_name(x.name)}"
|
37
|
+
table = Arel::Table.new(x.relation.table_alias || x.relation.name)
|
38
|
+
expr = table[x.name]
|
55
39
|
Arel::Nodes::Ordering.new expr
|
56
40
|
when String
|
57
41
|
x.split(',').map do |s|
|
58
42
|
expr, direction = s.split
|
59
|
-
expr = Arel
|
43
|
+
expr = Arel.sql(expr)
|
60
44
|
direction = direction =~ /desc/i ? :desc : :asc
|
61
45
|
Arel::Nodes::Ordering.new expr, direction
|
62
46
|
end
|
63
47
|
else
|
64
|
-
expr = Arel
|
48
|
+
expr = Arel.sql(x.to_s)
|
65
49
|
Arel::Nodes::Ordering.new expr
|
66
50
|
end
|
67
51
|
}.flatten)
|
@@ -99,7 +83,7 @@ module Arel
|
|
99
83
|
end
|
100
84
|
|
101
85
|
def visit_Arel_Nodes_Offset(o)
|
102
|
-
"WHERE [__rnt].[__rn] > #{visit o.expr}"
|
86
|
+
"WHERE [__rnt].[__rn] > (#{visit o.expr})"
|
103
87
|
end
|
104
88
|
|
105
89
|
def visit_Arel_Nodes_Limit(o)
|
@@ -136,7 +120,7 @@ module Arel
|
|
136
120
|
groups = projections.map { |x| projection_without_expression(x) }
|
137
121
|
projections = projections.map { |x| projection_without_expression(x) }
|
138
122
|
orders = orders.map do |x|
|
139
|
-
expr = Arel
|
123
|
+
expr = Arel.sql projection_without_expression(x.expr)
|
140
124
|
x.descending? ? Arel::Nodes::Max.new([expr]) : Arel::Nodes::Min.new([expr])
|
141
125
|
end
|
142
126
|
end
|
@@ -166,7 +150,7 @@ module Arel
|
|
166
150
|
|
167
151
|
def visit_Arel_Nodes_SelectStatementForComplexCount(o)
|
168
152
|
core = o.cores.first
|
169
|
-
o.limit.expr = o.limit.expr +
|
153
|
+
o.limit.expr = Arel.sql("#{o.limit.expr} + #{o.offset ? o.offset.expr : 0}") if o.limit
|
170
154
|
orders = rowtable_orders(o)
|
171
155
|
[ "SELECT COUNT([count]) AS [count_id]",
|
172
156
|
"FROM (",
|
@@ -301,11 +285,11 @@ module Arel
|
|
301
285
|
end
|
302
286
|
elsif join_in_select_statement?(o) && all_projections_aliased_in_select_statement?(o)
|
303
287
|
core.projections.map do |x|
|
304
|
-
Arel
|
288
|
+
Arel.sql x.split(',').map{ |y| y.split(' AS ').last.strip }.join(', ')
|
305
289
|
end
|
306
290
|
elsif function_select_statement?(o)
|
307
291
|
# TODO: [ARel 2.2] Use Arel.star
|
308
|
-
[Arel
|
292
|
+
[Arel.sql('*')]
|
309
293
|
else
|
310
294
|
tn = table_from_select_statement(o).name
|
311
295
|
core.projections.map { |x| x.gsub /\[#{tn}\]\./, '[__rnt].' }
|
@@ -316,16 +300,16 @@ module Arel
|
|
316
300
|
core = o.cores.first
|
317
301
|
if !o.orders.empty?
|
318
302
|
o.orders
|
319
|
-
elsif join_in_select_statement?(o)
|
320
|
-
[table_from_select_statement(o).primary_key.asc]
|
321
303
|
else
|
322
|
-
|
304
|
+
t = table_from_select_statement(o)
|
305
|
+
c = t.primary_key || t.columns.first
|
306
|
+
[c.asc]
|
323
307
|
end.uniq
|
324
308
|
end
|
325
309
|
|
326
310
|
# TODO: We use this for grouping too, maybe make Grouping objects vs SqlLiteral.
|
327
311
|
def projection_without_expression(projection)
|
328
|
-
Arel
|
312
|
+
Arel.sql(projection.split(',').map do |x|
|
329
313
|
x.strip!
|
330
314
|
x.sub!(/^(COUNT|SUM|MAX|MIN|AVG)\s*(\((.*)\))?/,'\3')
|
331
315
|
x.sub!(/^DISTINCT\s*/,'')
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-sqlserver-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 3
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 3.0.
|
9
|
+
- 10
|
10
|
+
version: 3.0.10
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Ken Collins
|
@@ -18,7 +19,7 @@ autorequire:
|
|
18
19
|
bindir: bin
|
19
20
|
cert_chain: []
|
20
21
|
|
21
|
-
date: 2011-01
|
22
|
+
date: 2011-03-01 00:00:00 -05:00
|
22
23
|
default_executable:
|
23
24
|
dependencies:
|
24
25
|
- !ruby/object:Gem::Dependency
|
@@ -29,6 +30,7 @@ dependencies:
|
|
29
30
|
requirements:
|
30
31
|
- - ~>
|
31
32
|
- !ruby/object:Gem::Version
|
33
|
+
hash: 1
|
32
34
|
segments:
|
33
35
|
- 3
|
34
36
|
- 0
|
@@ -44,6 +46,7 @@ dependencies:
|
|
44
46
|
requirements:
|
45
47
|
- - ~>
|
46
48
|
- !ruby/object:Gem::Version
|
49
|
+
hash: 1
|
47
50
|
segments:
|
48
51
|
- 2
|
49
52
|
- 0
|
@@ -89,6 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
92
|
requirements:
|
90
93
|
- - ">="
|
91
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
92
96
|
segments:
|
93
97
|
- 0
|
94
98
|
version: "0"
|
@@ -97,13 +101,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
101
|
requirements:
|
98
102
|
- - ">="
|
99
103
|
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
100
105
|
segments:
|
101
106
|
- 0
|
102
107
|
version: "0"
|
103
108
|
requirements: []
|
104
109
|
|
105
110
|
rubyforge_project: activerecord-sqlserver-adapter
|
106
|
-
rubygems_version: 1.
|
111
|
+
rubygems_version: 1.5.0
|
107
112
|
signing_key:
|
108
113
|
specification_version: 3
|
109
114
|
summary: SQL Server 2005 and 2008 Adapter For ActiveRecord.
|