rails-sqlserver-2000-2005-adapter 2.2.16 → 2.2.17
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 +9 -1
- data/README.rdoc +4 -3
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +22 -1
- data/test/cases/column_test_sqlserver.rb +4 -4
- data/test/cases/schema_dumper_test_sqlserver.rb +11 -0
- data/test/cases/sqlserver_helper.rb +2 -0
- data/test/cases/unicode_test_sqlserver.rb +7 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
|
2
2
|
MASTER
|
3
3
|
|
4
|
-
|
4
|
+
|
5
|
+
* 2.2.17 * (May 14th, 2009)
|
6
|
+
|
7
|
+
* Add simplified type recognition for varchar(max) and nvarchar(max) under SQL Server 2005 to be a
|
8
|
+
:text type. This ensures schema dumper does the right thing. Fixes ticket #30. [Ken Collins]
|
9
|
+
|
10
|
+
* Tested ruby 1.9, ruby-odbc 0.9996, and DBI 0.4.1. Also added correct support for UTF-8 character
|
11
|
+
encoding going in and out of the DB. See before gist http://gist.github.com/111709 and after gist
|
12
|
+
http://gist.github.com/111719 [Ken Collins]
|
5
13
|
|
6
14
|
|
7
15
|
* 2.2.16 * (April 21st, 2009)
|
data/README.rdoc
CHANGED
@@ -6,6 +6,7 @@ The SQL Server adapter for rails is back for ActiveRecord 2.2 and up! We are cur
|
|
6
6
|
|
7
7
|
== What's New
|
8
8
|
|
9
|
+
* Fully tested under 1.9!!! Correctly encodes/decodes UTF-8 types in ruby 1.9 too.
|
9
10
|
* Now supports both rails 2.2 & 2.3!!!
|
10
11
|
* An ActiveRecord::Base.execute_procedure method that can be used by classes.
|
11
12
|
* Enabled support for DDL transactions.
|
@@ -119,11 +120,11 @@ It is our goal to match the adapter version with each version of rails. However
|
|
119
120
|
|
120
121
|
== Installation
|
121
122
|
|
122
|
-
First, you will need Ruby DBI and Ruby ODBC. 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.
|
123
|
+
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.
|
123
124
|
|
124
|
-
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.0. Because later versions of DBI will be changing many things, IT IS HIGHLY RECOMMENDED that you max your install to version 0.4.0 which the examples below show. For the time being we are not supporting DBI versions higher than 0.4.0. 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.
|
125
|
+
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.0 which the examples below show. For the time being we are not supporting DBI versions higher than 0.4.0. 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.
|
125
126
|
|
126
|
-
$ gem install dbi --version 0.4.
|
127
|
+
$ gem install dbi --version 0.4.1
|
127
128
|
$ gem install dbd-odbc --version 0.2.4
|
128
129
|
$ gem install rails-sqlserver-2000-2005-adapter -s http://gems.github.com
|
129
130
|
|
@@ -49,6 +49,10 @@ module ActiveRecord
|
|
49
49
|
|
50
50
|
class << self
|
51
51
|
|
52
|
+
def string_to_utf8_encoding(value)
|
53
|
+
value.force_encoding('UTF-8') rescue value
|
54
|
+
end
|
55
|
+
|
52
56
|
def string_to_binary(value)
|
53
57
|
"0x#{value.unpack("H*")[0]}"
|
54
58
|
end
|
@@ -59,6 +63,22 @@ module ActiveRecord
|
|
59
63
|
|
60
64
|
end
|
61
65
|
|
66
|
+
def type_cast(value)
|
67
|
+
if value && type == :string && is_utf8?
|
68
|
+
self.class.string_to_utf8_encoding(value)
|
69
|
+
else
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def type_cast_code(var_name)
|
75
|
+
if type == :string && is_utf8?
|
76
|
+
"#{self.class.name}.string_to_utf8_encoding(#{var_name})"
|
77
|
+
else
|
78
|
+
super
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
62
82
|
def is_identity?
|
63
83
|
@sqlserver_options[:is_identity]
|
64
84
|
end
|
@@ -106,6 +126,7 @@ module ActiveRecord
|
|
106
126
|
when /bit/i then :boolean
|
107
127
|
when /uniqueidentifier/i then :string
|
108
128
|
when /datetime/i then simplified_datetime
|
129
|
+
when /varchar\(max\)/ then :text
|
109
130
|
else super
|
110
131
|
end
|
111
132
|
end
|
@@ -158,7 +179,7 @@ module ActiveRecord
|
|
158
179
|
class SQLServerAdapter < AbstractAdapter
|
159
180
|
|
160
181
|
ADAPTER_NAME = 'SQLServer'.freeze
|
161
|
-
VERSION = '2.2.
|
182
|
+
VERSION = '2.2.17'.freeze
|
162
183
|
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
|
163
184
|
SUPPORTED_VERSIONS = [2000,2005].freeze
|
164
185
|
LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].freeze
|
@@ -67,8 +67,8 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
|
|
67
67
|
assert_equal :string, @char.type
|
68
68
|
assert_equal :string, @char10.type
|
69
69
|
if sqlserver_2005?
|
70
|
-
assert_equal :
|
71
|
-
assert_equal :
|
70
|
+
assert_equal :text, @varcharmax.type, @varcharmax.inspect
|
71
|
+
assert_equal :text, @varcharmax10.type, @varcharmax10.inspect
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -120,8 +120,8 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
|
|
120
120
|
assert_equal :string, @nchar10.type
|
121
121
|
assert_equal :string, @nvarchar100.type
|
122
122
|
if sqlserver_2005?
|
123
|
-
assert_equal :
|
124
|
-
assert_equal :
|
123
|
+
assert_equal :text, @nvarcharmax.type, @nvarcharmax.inspect
|
124
|
+
assert_equal :text, @nvarcharmax10.type, @nvarcharmax10.inspect
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -35,6 +35,17 @@ class SchemaDumperTestSqlserver < ActiveRecord::TestCase
|
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
+
context 'For strings' do
|
39
|
+
|
40
|
+
should 'have varchar(max) dumped as text' do
|
41
|
+
table_dump('sql_server_strings') do |output|
|
42
|
+
assert_match %r{t.text.*varchar_max}, output
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
38
49
|
|
39
50
|
|
40
51
|
private
|
@@ -98,6 +98,7 @@ module ActiveRecord
|
|
98
98
|
def sqlserver_2005? ; ActiveRecord::Base.connection.sqlserver_2005? ; end
|
99
99
|
def active_record_2_point_2? ; ActiveRecord::VERSION::MAJOR == 2 && ActiveRecord::VERSION::MINOR == 2 ; end
|
100
100
|
def active_record_2_point_3? ; ActiveRecord::VERSION::MAJOR == 2 && ActiveRecord::VERSION::MINOR == 3 ; end
|
101
|
+
def ruby_19? ; RUBY_VERSION >= '1.9' ; end
|
101
102
|
end
|
102
103
|
def assert_sql(*patterns_to_match)
|
103
104
|
$queries_executed = []
|
@@ -113,6 +114,7 @@ module ActiveRecord
|
|
113
114
|
def sqlserver_2005? ; self.class.sqlserver_2005? ; end
|
114
115
|
def active_record_2_point_2? ; self.class.active_record_2_point_2? ; end
|
115
116
|
def active_record_2_point_3? ; self.class.active_record_2_point_3? ; end
|
117
|
+
def ruby_19? ; self.class.ruby_19? ; end
|
116
118
|
end
|
117
119
|
end
|
118
120
|
|
@@ -29,13 +29,19 @@ class UnicodeTestSqlserver < ActiveRecord::TestCase
|
|
29
29
|
context 'Testing unicode data' do
|
30
30
|
|
31
31
|
setup do
|
32
|
-
@unicode_data = "
|
32
|
+
@unicode_data = "\344\270\200\344\272\21434\344\272\224\345\205\255"
|
33
|
+
@encoded_unicode_data = "\344\270\200\344\272\21434\344\272\224\345\205\255".force_encoding('UTF-8') if ruby_19?
|
33
34
|
end
|
34
35
|
|
35
36
|
should 'insert into nvarchar field' do
|
36
37
|
assert data = SqlServerUnicode.create!(:nvarchar => @unicode_data)
|
37
38
|
assert_equal @unicode_data, data.reload.nvarchar
|
38
39
|
end
|
40
|
+
|
41
|
+
should 're-encode data on DB reads' do
|
42
|
+
assert data = SqlServerUnicode.create!(:nvarchar => @unicode_data)
|
43
|
+
assert_equal @encoded_unicode_data, data.reload.nvarchar
|
44
|
+
end if ruby_19?
|
39
45
|
|
40
46
|
end
|
41
47
|
|
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.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
@@ -13,7 +13,7 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2009-
|
16
|
+
date: 2009-05-14 00:00:00 -07:00
|
17
17
|
default_executable:
|
18
18
|
dependencies: []
|
19
19
|
|