rails-sqlserver-2000-2005-adapter 2.2.18 → 2.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +7 -0
- data/README.rdoc +8 -7
- data/Rakefile +13 -47
- 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 +5 -5
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
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
== Rails SQL Server 2000
|
2
|
+
== Rails SQL Server 2000, 2005 and 2008 Adapter
|
3
3
|
|
4
4
|
The SQL Server adapter for rails is back for ActiveRecord 2.2 and up! We are currently passing all tests and hope to continue to do so moving forward.
|
5
5
|
|
@@ -24,13 +24,13 @@ The SQL Server adapter for rails is back for ActiveRecord 2.2 and up! We are cur
|
|
24
24
|
|
25
25
|
==== SQL Server 2008 Support
|
26
26
|
|
27
|
-
Because this adapter is primarily coded to SQL Server 2000/2005, it does not take advantage of many of the things in 2008 that would speed up the code. At some point in the future there
|
27
|
+
Because this adapter is primarily coded to SQL Server 2000/2005, it does not take advantage of many of the things in 2008 that would speed up the code. At some point in the future there will be a branch of this code that is specifically targeted for 2008. That adapter version will remove much of the dirty innards of this version that are meant to code around many previous SQL Server 2000/2005 short comings, the biggest being no limit/offset.
|
28
28
|
|
29
29
|
|
30
30
|
|
31
31
|
==== Date/Time Data Type Hinting
|
32
32
|
|
33
|
-
Both SQL Server 2000 and 2005 do not
|
33
|
+
Both SQL Server 2000 and 2005 do not include native data types for just 'date' or 'time', it only has 'datetime'. To pass the ActiveRecord tests we implemented two simple class methods that can teach your models to coerce column information to be cast correctly. Simply past a list of symbols to either the <tt>coerce_sqlserver_date</tt> or <tt>coerce_sqlserver_time</tt> methods that correspond to 'datetime' columns that need to be cast correctly.
|
34
34
|
|
35
35
|
class Topic < ActiveRecord::Base
|
36
36
|
coerce_sqlserver_date :last_read
|
@@ -130,17 +130,17 @@ It is our goal to match the adapter version with each version of rails. However
|
|
130
130
|
|
131
131
|
First, you will need Ruby DBI and Ruby ODBC. If you are using the adapter under 1.9, then you need at least ruby-odbc version 0.9996. To my knowledge the ADO DBD for DBI is no longer supported. The installation below is not a comprehensive walk thru on how to get all the required moving parts like FreeTDS installed and/or configured. It will also assume gem installations of both the dependent libraries and the adapter itself.
|
132
132
|
|
133
|
-
It should be noted that this version of the adapter was developed using both the ancient 0.0.23 version of DBI up to the current stable release of 0.4.1. Note that DBI 0.4.1 is the minimal for ruby 1.9 compatibility. Because later versions of DBI will be changing many things, IT IS HIGHLY RECOMMENDED that you max your install to version 0.4.
|
133
|
+
It should be noted that this version of the adapter was developed using both the ancient 0.0.23 version of DBI up to the current stable release of 0.4.1. Note that DBI 0.4.1 is the minimal for ruby 1.9 compatibility. Because later versions of DBI will be changing many things, IT IS HIGHLY RECOMMENDED that you max your install to version 0.4.1 which the examples below show. For the time being we are not supporting DBI versions higher than 0.4.1. The good news is that if you were using a very old DBI with ADO, technically this adapter will still work for you, but be warned your path is getting old and may not be supported for long.
|
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
|
-
config.gem 'dbi', :version => '0.4.
|
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
|
|
@@ -152,6 +152,7 @@ Here are some external links for libraries and/or tutorials on how to install an
|
|
152
152
|
|
153
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 in Lighthouse. 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
|
+
* Github: http://github.com/rails-sqlserver
|
155
156
|
* Lighthouse: http://rails-sqlserver.lighthouseapp.com/projects/20277-sql-server-05-adapter/tickets
|
156
157
|
* Google Group: http://groups.google.com/group/rails-sqlserver-adapter
|
157
158
|
* IRC Room: #rails-sqlserver on irc.freenode.net
|
data/Rakefile
CHANGED
@@ -1,52 +1,18 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/testtask'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
%x( osql -S localhost -U rails -d activerecord_unittest2 -Q "grant BACKUP DATABASE, BACKUP LOG, CREATE DEFAULT, CREATE FUNCTION, CREATE PROCEDURE, CREATE RULE, CREATE TABLE, CREATE VIEW to 'rails';" -P )
|
17
|
-
end
|
18
|
-
|
19
|
-
desc 'Drop the SQL Server test databases'
|
20
|
-
task :drop_databases do
|
21
|
-
%x( osql -S localhost -U rails -Q "drop database activerecord_unittest" -P )
|
22
|
-
%x( osql -S localhost -U rails -Q "drop database activerecord_unittest2" -P )
|
23
|
-
end
|
24
|
-
|
25
|
-
desc 'Recreate the SQL Server test databases'
|
26
|
-
task :recreate_databases => [:drop_databases, :create_databases]
|
27
|
-
|
28
|
-
|
29
|
-
for adapter in %w( sqlserver sqlserver_odbc )
|
30
|
-
|
31
|
-
Rake::TestTask.new("test_#{adapter}") { |t|
|
32
|
-
t.libs << "test"
|
33
|
-
t.libs << "test/connections/native_#{adapter}"
|
34
|
-
t.libs << "../../../rails/activerecord/test/"
|
35
|
-
t.test_files = (
|
36
|
-
Dir.glob("test/cases/**/*_test_sqlserver.rb").sort +
|
37
|
-
Dir.glob("../../../rails/activerecord/test/**/*_test.rb").sort )
|
38
|
-
t.verbose = true
|
39
|
-
}
|
40
|
-
|
41
|
-
namespace adapter do
|
42
|
-
task :test => "test_#{adapter}"
|
43
|
-
end
|
44
|
-
|
4
|
+
require 'echoe'
|
5
|
+
|
6
|
+
Echoe.new('activerecord-sqlserver-adapter','2.2.19') do |p|
|
7
|
+
p.summary = "SQL Server 2000, 2005 and 2008 Adapter For Rails."
|
8
|
+
p.description = "SQL Server 2000, 2005 and 2008 Adapter For Rails."
|
9
|
+
p.author = ["Ken Collins","Murray Steele","Shawn Balestracci","Joe Rafaniello","Tom Ward"]
|
10
|
+
p.email = "ken@metaskills.net"
|
11
|
+
p.url = "http://github.com/rails-sqlserver"
|
12
|
+
p.runtime_dependencies = ["dbi =0.4.1","dbd-odbc =0.2.4"]
|
13
|
+
p.include_gemspec = false
|
14
|
+
p.ignore_pattern = ["autotest/*","*.gemspec","lib/rails-sqlserver-2000-2005-adapter.rb"]
|
15
|
+
p.project = 'arsqlserver'
|
45
16
|
end
|
46
17
|
|
47
|
-
|
48
|
-
Rake::TestTask.new(:test_unicode_types) do |t|
|
49
|
-
ENV['ENABLE_DEFAULT_UNICODE_TYPES'] = 'true'
|
50
|
-
test = Rake::Task['test_sqlserver_odbc']
|
51
|
-
test.invoke
|
52
|
-
end
|
18
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load(ext) }
|
@@ -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: rails-sqlserver-2000-2005-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
|
@@ -13,11 +13,11 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2009-06-
|
16
|
+
date: 2009-06-18 00:00:00 -07:00
|
17
17
|
default_executable:
|
18
18
|
dependencies: []
|
19
19
|
|
20
|
-
description: SQL Server 2000
|
20
|
+
description: SQL Server 2000, 2005 and 2008 Adapter For Rails.
|
21
21
|
email: ken@metaskills.net
|
22
22
|
executables: []
|
23
23
|
|
@@ -40,7 +40,7 @@ files:
|
|
40
40
|
- lib/core_ext/active_record.rb
|
41
41
|
- lib/core_ext/dbi.rb
|
42
42
|
has_rdoc: true
|
43
|
-
homepage: http://github.com/rails-sqlserver
|
43
|
+
homepage: http://github.com/rails-sqlserver
|
44
44
|
post_install_message:
|
45
45
|
rdoc_options:
|
46
46
|
- --line-numbers
|
@@ -67,7 +67,7 @@ rubyforge_project:
|
|
67
67
|
rubygems_version: 1.2.0
|
68
68
|
signing_key:
|
69
69
|
specification_version: 2
|
70
|
-
summary: SQL Server 2000
|
70
|
+
summary: SQL Server 2000, 2005 and 2008 Adapter For Rails.
|
71
71
|
test_files:
|
72
72
|
- test/cases/aaaa_create_tables_test_sqlserver.rb
|
73
73
|
- test/cases/adapter_test_sqlserver.rb
|