activerecord-sqlserver-adapter 2.2.18 → 2.2.19
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/README.rdoc +3 -4
- data/Rakefile +1 -1
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +2 -2
- data/lib/core_ext/active_record.rb +18 -0
- data/test/cases/adapter_test_sqlserver.rb +32 -0
- metadata +4 -6
data/CHANGELOG
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
|
2
2
|
MASTER
|
3
3
|
|
4
|
+
* 2.2.19 * (June 19th, 2009)
|
5
|
+
|
6
|
+
* Leave quoted column names as is. Resolves ticket #36 [Vince Puzzella]
|
7
|
+
|
8
|
+
* Changing add_limit! in ActiveRecord::Base for SQLServer so that it passes through any scoped :order
|
9
|
+
parameters. Resolves ticket #35 [Murray Steele]
|
10
|
+
|
4
11
|
|
5
12
|
* 2.2.18 * (June 5th, 2009)
|
6
13
|
|
data/README.rdoc
CHANGED
@@ -134,13 +134,13 @@ It should be noted that this version of the adapter was developed using both the
|
|
134
134
|
|
135
135
|
$ gem install dbi --version 0.4.1
|
136
136
|
$ gem install dbd-odbc --version 0.2.4
|
137
|
-
$ gem install
|
137
|
+
$ gem install activerecord-sqlserver-adapter
|
138
138
|
|
139
139
|
Optionally configure your gem dependencies in your rails environment.rb file.
|
140
140
|
|
141
141
|
config.gem 'dbi', :version => '0.4.1'
|
142
142
|
config.gem 'dbd-odbc', :version => '0.2.4', :lib => 'dbd/ODBC'
|
143
|
-
config.gem '
|
143
|
+
config.gem 'activerecord-sqlserver-adapter', :version => 'x.x.xx'
|
144
144
|
|
145
145
|
Here are some external links for libraries and/or tutorials on how to install any other additional components to use this adapter. If you know of a good one that we can include here, just let us know.
|
146
146
|
|
@@ -150,10 +150,9 @@ Here are some external links for libraries and/or tutorials on how to install an
|
|
150
150
|
|
151
151
|
== Contributing
|
152
152
|
|
153
|
-
If you’d like to contribute a feature or bugfix, thanks! To make sure your fix/feature has a high chance of being added, please read the following guidelines. First, ask on the Google list, IRC, or post a ticket
|
153
|
+
If you’d like to contribute a feature or bugfix, thanks! To make sure your fix/feature has a high chance of being added, please read the following guidelines. First, ask on the Google list, IRC, or post a ticket on github issues. Second, make sure there are tests! We will not accept any patch that is not tested. Please read the RUNNING_UNIT_TESTS file for the details of how to run the unit tests.
|
154
154
|
|
155
155
|
* Github: http://github.com/rails-sqlserver
|
156
|
-
* Lighthouse: http://rails-sqlserver.lighthouseapp.com/projects/20277-sql-server-05-adapter/tickets
|
157
156
|
* Google Group: http://groups.google.com/group/rails-sqlserver-adapter
|
158
157
|
* IRC Room: #rails-sqlserver on irc.freenode.net
|
159
158
|
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rake'
|
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'echoe'
|
5
5
|
|
6
|
-
Echoe.new('activerecord-sqlserver-adapter','2.2.
|
6
|
+
Echoe.new('activerecord-sqlserver-adapter','2.2.19') do |p|
|
7
7
|
p.summary = "SQL Server 2000, 2005 and 2008 Adapter For Rails."
|
8
8
|
p.description = "SQL Server 2000, 2005 and 2008 Adapter For Rails."
|
9
9
|
p.author = ["Ken Collins","Murray Steele","Shawn Balestracci","Joe Rafaniello","Tom Ward"]
|
@@ -183,7 +183,7 @@ module ActiveRecord
|
|
183
183
|
class SQLServerAdapter < AbstractAdapter
|
184
184
|
|
185
185
|
ADAPTER_NAME = 'SQLServer'.freeze
|
186
|
-
VERSION = '2.2.
|
186
|
+
VERSION = '2.2.19'.freeze
|
187
187
|
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
|
188
188
|
SUPPORTED_VERSIONS = [2000,2005,2008].freeze
|
189
189
|
LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].freeze
|
@@ -309,7 +309,7 @@ module ActiveRecord
|
|
309
309
|
end
|
310
310
|
|
311
311
|
def quote_column_name(column_name)
|
312
|
-
column_name.to_s.split('.').map{ |name| "[#{name}]" }.join('.')
|
312
|
+
column_name.to_s.split('.').map{ |name| name =~ /^\[.*\]$/ ? name : "[#{name}]" }.join('.')
|
313
313
|
end
|
314
314
|
|
315
315
|
def quote_table_name(table_name)
|
@@ -9,6 +9,7 @@ module ActiveRecord
|
|
9
9
|
class << klass
|
10
10
|
alias_method_chain :reset_column_information, :sqlserver_cache_support
|
11
11
|
alias_method_chain :add_order!, :sqlserver_unique_checking
|
12
|
+
alias_method_chain :add_limit!, :sqlserver_order_checking
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -45,6 +46,23 @@ module ActiveRecord
|
|
45
46
|
|
46
47
|
private
|
47
48
|
|
49
|
+
def add_limit_with_sqlserver_order_checking!(sql, options, scope = :auto)
|
50
|
+
if connection.respond_to?(:sqlserver?)
|
51
|
+
scope = scope(:find) if :auto == scope
|
52
|
+
if scope
|
53
|
+
options = options.dup
|
54
|
+
scoped_order = scope[:order]
|
55
|
+
order = options[:order]
|
56
|
+
if order && scoped_order
|
57
|
+
options[:order] = add_order_with_sqlserver_unique_checking!('', order, scope).gsub(/^ ORDER BY /,'')
|
58
|
+
elsif scoped_order
|
59
|
+
options[:order] = scoped_order
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
add_limit_without_sqlserver_order_checking!(sql, options, scope)
|
64
|
+
end
|
65
|
+
|
48
66
|
def add_order_with_sqlserver_unique_checking!(sql, order, scope = :auto)
|
49
67
|
if connection.respond_to?(:sqlserver?)
|
50
68
|
order_sql = ''
|
@@ -159,6 +159,28 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
|
|
159
159
|
end
|
160
160
|
|
161
161
|
end
|
162
|
+
|
163
|
+
context "for add_limit! within a scoped method call" do
|
164
|
+
setup do
|
165
|
+
@connection.stubs(:select_value).with(regexp_matches(/TotalRows/)).returns '100000000'
|
166
|
+
end
|
167
|
+
|
168
|
+
should 'not add any ordering if the scope doesn\'t have an order' do
|
169
|
+
assert_equal 'SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM [developers]) AS tmp1) AS tmp2', add_limit!('SELECT * FROM [developers]', {:offset => 30, :limit => 10}, {})
|
170
|
+
end
|
171
|
+
|
172
|
+
should 'still add the default ordering if the scope doesn\'t have an order but the raw order option is there' do
|
173
|
+
assert_equal 'SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM [developers]) AS tmp1 ORDER BY [name] DESC) AS tmp2 ORDER BY [name]', add_limit!('SELECT * FROM [developers]', {:offset => 30, :limit => 10, :order => 'name'}, {})
|
174
|
+
end
|
175
|
+
|
176
|
+
should 'add scoped order options to the offset and limit sql' do
|
177
|
+
assert_equal 'SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM [developers]) AS tmp1 ORDER BY [id] DESC) AS tmp2 ORDER BY [id]', add_limit!('SELECT * FROM [developers]', {:offset => 30, :limit => 10}, {:order => 'id'})
|
178
|
+
end
|
179
|
+
|
180
|
+
should 'combine scoped order with raw order options in the offset and limit sql' do
|
181
|
+
assert_equal 'SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM [developers]) AS tmp1 ORDER BY [name] DESC, [id] DESC) AS tmp2 ORDER BY [name], [id]', add_limit!('SELECT * FROM [developers]', {:offset => 30, :limit => 10, :order => 'name'}, {:order => 'id'})
|
182
|
+
end
|
183
|
+
end
|
162
184
|
|
163
185
|
context 'dealing with various orders SQL snippets' do
|
164
186
|
|
@@ -350,6 +372,11 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
|
|
350
372
|
assert_equal '[foo].[bar]', @connection.quote_column_name('foo.bar')
|
351
373
|
end
|
352
374
|
|
375
|
+
should 'not quote already quoted column names with brackets' do
|
376
|
+
assert_equal '[foo]', @connection.quote_column_name('[foo]')
|
377
|
+
assert_equal '[foo].[bar]', @connection.quote_column_name('[foo].[bar]')
|
378
|
+
end
|
379
|
+
|
353
380
|
should 'quote table names like columns' do
|
354
381
|
assert_equal '[foo].[bar]', @connection.quote_column_name('foo.bar')
|
355
382
|
assert_equal '[foo].[bar].[baz]', @connection.quote_column_name('foo.bar.baz')
|
@@ -659,6 +686,11 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
|
|
659
686
|
sql
|
660
687
|
end
|
661
688
|
|
689
|
+
def add_limit!(sql, options, scope = :auto)
|
690
|
+
ActiveRecord::Base.send :add_limit!, sql, options, scope
|
691
|
+
sql
|
692
|
+
end
|
693
|
+
|
662
694
|
def order_to_min_set(order)
|
663
695
|
@connection.send :order_to_min_set, order
|
664
696
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-sqlserver-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins, Murray Steele, Shawn Balestracci, Joe Rafaniello, Tom Ward
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-18 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -85,8 +85,6 @@ files:
|
|
85
85
|
- test/schema/sqlserver_specific_schema.rb
|
86
86
|
has_rdoc: true
|
87
87
|
homepage: http://github.com/rails-sqlserver
|
88
|
-
licenses: []
|
89
|
-
|
90
88
|
post_install_message:
|
91
89
|
rdoc_options:
|
92
90
|
- --line-numbers
|
@@ -112,9 +110,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
110
|
requirements: []
|
113
111
|
|
114
112
|
rubyforge_project: arsqlserver
|
115
|
-
rubygems_version: 1.3.
|
113
|
+
rubygems_version: 1.3.1
|
116
114
|
signing_key:
|
117
|
-
specification_version:
|
115
|
+
specification_version: 2
|
118
116
|
summary: SQL Server 2000, 2005 and 2008 Adapter For Rails.
|
119
117
|
test_files: []
|
120
118
|
|