rails-sqlserver-2000-2005-adapter 2.2.17 → 2.2.18

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 CHANGED
@@ -2,6 +2,13 @@
2
2
  MASTER
3
3
 
4
4
 
5
+ * 2.2.18 * (June 5th, 2009)
6
+
7
+ * Column reflection on table name rescues LoadError and a few others. Resolves tickets #25 & #33 [Ken Collins]
8
+
9
+ * Added 2008 support. Resolves ticket #32 [Ken Collins]
10
+
11
+
5
12
  * 2.2.17 * (May 14th, 2009)
6
13
 
7
14
  * Add simplified type recognition for varchar(max) and nvarchar(max) under SQL Server 2005 to be a
data/README.rdoc CHANGED
@@ -1,11 +1,12 @@
1
1
 
2
- == Rails SQL Server 2000 & 2005 Adapter
2
+ == Rails SQL Server 2000 & 2005 & 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
 
6
6
 
7
7
  == What's New
8
8
 
9
+ * Now supports SQL Server 2008 too!
9
10
  * Fully tested under 1.9!!! Correctly encodes/decodes UTF-8 types in ruby 1.9 too.
10
11
  * Now supports both rails 2.2 & 2.3!!!
11
12
  * An ActiveRecord::Base.execute_procedure method that can be used by classes.
@@ -20,6 +21,13 @@ The SQL Server adapter for rails is back for ActiveRecord 2.2 and up! We are cur
20
21
  * A block method to run queries within a specific isolation level.
21
22
  * Automatically reconnects to lost database connections.
22
23
 
24
+
25
+ ==== SQL Server 2008 Support
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 we 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 of their short comings in 2000/2005, the biggest being no limit/offset.
28
+
29
+
30
+
23
31
  ==== Date/Time Data Type Hinting
24
32
 
25
33
  Both SQL Server 2000 and 2005 do not have 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.
@@ -97,7 +97,11 @@ module ActiveRecord
97
97
  end
98
98
 
99
99
  def table_klass
100
- @table_klass ||= table_name.classify.constantize rescue nil
100
+ @table_klass ||= begin
101
+ table_name.classify.constantize
102
+ rescue StandardError, NameError, LoadError
103
+ nil
104
+ end
101
105
  (@table_klass && @table_klass < ActiveRecord::Base) ? @table_klass : nil
102
106
  end
103
107
 
@@ -179,9 +183,9 @@ module ActiveRecord
179
183
  class SQLServerAdapter < AbstractAdapter
180
184
 
181
185
  ADAPTER_NAME = 'SQLServer'.freeze
182
- VERSION = '2.2.17'.freeze
186
+ VERSION = '2.2.18'.freeze
183
187
  DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
184
- SUPPORTED_VERSIONS = [2000,2005].freeze
188
+ SUPPORTED_VERSIONS = [2000,2005,2008].freeze
185
189
  LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].freeze
186
190
 
187
191
  LOST_CONNECTION_EXCEPTIONS = [DBI::DatabaseError, DBI::InterfaceError]
@@ -250,6 +254,10 @@ module ActiveRecord
250
254
  database_year == 2005
251
255
  end
252
256
 
257
+ def sqlserver_2008?
258
+ database_year == 2008
259
+ end
260
+
253
261
  def version
254
262
  self.class::VERSION
255
263
  end
@@ -268,7 +276,7 @@ module ActiveRecord
268
276
 
269
277
  def native_text_database_type
270
278
  @@native_text_database_type ||
271
- if sqlserver_2005?
279
+ if sqlserver_2005? || sqlserver_2008?
272
280
  enable_default_unicode_types ? 'nvarchar(max)' : 'varchar(max)'
273
281
  else
274
282
  enable_default_unicode_types ? 'ntext' : 'text'
@@ -276,7 +284,7 @@ module ActiveRecord
276
284
  end
277
285
 
278
286
  def native_binary_database_type
279
- @@native_binary_database_type || (sqlserver_2005? ? 'varbinary(max)' : 'image')
287
+ @@native_binary_database_type || ((sqlserver_2005? || sqlserver_2008?) ? 'varbinary(max)' : 'image')
280
288
  end
281
289
 
282
290
  # QUOTING ==================================================#
@@ -59,6 +59,7 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
59
59
  @supported_version = ActiveRecord::ConnectionAdapters::SQLServerAdapter::SUPPORTED_VERSIONS
60
60
  @sqlserver_2000_string = "Microsoft SQL Server 2000 - 8.00.2039 (Intel X86)"
61
61
  @sqlserver_2005_string = "Microsoft SQL Server 2005 - 9.00.3215.00 (Intel X86)"
62
+ @sqlserver_2008_string = "Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)"
62
63
  end
63
64
 
64
65
  should 'return a string from #database_version that matches class regexp' do
@@ -80,6 +81,11 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
80
81
  assert @connection.sqlserver_2005?
81
82
  end
82
83
 
84
+ should 'return true to #sqlserver_2008?' do
85
+ @connection.stubs(:database_version).returns(@sqlserver_2008_string)
86
+ assert @connection.sqlserver_2008?
87
+ end
88
+
83
89
  end
84
90
 
85
91
  context 'for #unqualify_table_name and #unqualify_db_name' do
@@ -66,7 +66,7 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
66
66
  should 'have correct simplified types' do
67
67
  assert_equal :string, @char.type
68
68
  assert_equal :string, @char10.type
69
- if sqlserver_2005?
69
+ if sqlserver_2005? || sqlserver_2008?
70
70
  assert_equal :text, @varcharmax.type, @varcharmax.inspect
71
71
  assert_equal :text, @varcharmax10.type, @varcharmax10.inspect
72
72
  end
@@ -75,7 +75,7 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
75
75
  should 'have correct #sql_type per schema definition' do
76
76
  assert_equal 'char(1)', @char.sql_type, 'Specifing a char type with no limit is 1 by SQL Server standards.'
77
77
  assert_equal 'char(10)', @char10.sql_type, @char10.inspect
78
- if sqlserver_2005?
78
+ if sqlserver_2005? || sqlserver_2008?
79
79
  assert_equal 'varchar(max)', @varcharmax.sql_type, 'A -1 limit should be converted to max (max) type.'
80
80
  assert_equal 'varchar(max)', @varcharmax10.sql_type, 'A -1 limit should be converted to max (max) type.'
81
81
  end
@@ -84,7 +84,7 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
84
84
  should 'have correct #limit per schema definition' do
85
85
  assert_equal 1, @char.limit
86
86
  assert_equal 10, @char10.limit
87
- if sqlserver_2005?
87
+ if sqlserver_2005? || sqlserver_2008?
88
88
  assert_equal nil, @varcharmax.limit, 'Limits on max types are moot and we should let rails know that.'
89
89
  assert_equal nil, @varcharmax10.limit, 'Limits on max types are moot and we should let rails know that.'
90
90
  end
@@ -119,7 +119,7 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
119
119
  assert_equal :text, @ntext10.type
120
120
  assert_equal :string, @nchar10.type
121
121
  assert_equal :string, @nvarchar100.type
122
- if sqlserver_2005?
122
+ if sqlserver_2005? || sqlserver_2008?
123
123
  assert_equal :text, @nvarcharmax.type, @nvarcharmax.inspect
124
124
  assert_equal :text, @nvarcharmax10.type, @nvarcharmax10.inspect
125
125
  end
@@ -132,7 +132,7 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
132
132
  assert_equal 'ntext', @ntext10.sql_type, 'Even a next with a limit of 10 specified will mean nothing.'
133
133
  assert_equal 'nchar(10)', @nchar10.sql_type, 'An nchar with a limit of 10 needs to have it show up here.'
134
134
  assert_equal 'nvarchar(100)', @nvarchar100.sql_type, 'An nvarchar with a specified limit of 100 needs to show it.'
135
- if sqlserver_2005?
135
+ if sqlserver_2005? || sqlserver_2008?
136
136
  assert_equal 'nvarchar(max)', @nvarcharmax.sql_type, 'A -1 limit should be converted to max (max) type.'
137
137
  assert_equal 'nvarchar(max)', @nvarcharmax10.sql_type, 'A -1 limit should be converted to max (max) type.'
138
138
  end
@@ -144,7 +144,7 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
144
144
  assert_equal nil, @ntext.limit, 'An ntext column limit is moot, it is a fixed variable length'
145
145
  assert_equal 10, @nchar10.limit
146
146
  assert_equal 100, @nvarchar100.limit
147
- if sqlserver_2005?
147
+ if sqlserver_2005? || sqlserver_2008?
148
148
  assert_equal nil, @nvarcharmax.limit, 'Limits on max types are moot and we should let rails know that.'
149
149
  assert_equal nil, @nvarcharmax10.limit, 'Limits on max types are moot and we should let rails know that.'
150
150
  end
@@ -23,7 +23,7 @@ class ExecuteProcedureTestSqlserver < ActiveRecord::TestCase
23
23
  should 'quote bind vars correctly' do
24
24
  assert_sql(/EXEC sp_tables '%sql_server%', NULL, NULL, NULL, 1/) do
25
25
  @klass.execute_procedure :sp_tables, '%sql_server%', nil, nil, nil, true
26
- end if sqlserver_2005?
26
+ end if sqlserver_2005? || sqlserver_2008?
27
27
  assert_sql(/EXEC sp_tables '%sql_server%', NULL, NULL, NULL/) do
28
28
  @klass.execute_procedure :sp_tables, '%sql_server%', nil, nil, nil
29
29
  end if sqlserver_2000?
@@ -41,7 +41,7 @@ class SchemaDumperTestSqlserver < ActiveRecord::TestCase
41
41
  table_dump('sql_server_strings') do |output|
42
42
  assert_match %r{t.text.*varchar_max}, output
43
43
  end
44
- end
44
+ end if sqlserver_2005? || sqlserver_2008?
45
45
 
46
46
  end
47
47
 
@@ -96,6 +96,7 @@ module ActiveRecord
96
96
  class << self
97
97
  def sqlserver_2000? ; ActiveRecord::Base.connection.sqlserver_2000? ; end
98
98
  def sqlserver_2005? ; ActiveRecord::Base.connection.sqlserver_2005? ; end
99
+ def sqlserver_2008? ; ActiveRecord::Base.connection.sqlserver_2008? ; end
99
100
  def active_record_2_point_2? ; ActiveRecord::VERSION::MAJOR == 2 && ActiveRecord::VERSION::MINOR == 2 ; end
100
101
  def active_record_2_point_3? ; ActiveRecord::VERSION::MAJOR == 2 && ActiveRecord::VERSION::MINOR == 3 ; end
101
102
  def ruby_19? ; RUBY_VERSION >= '1.9' ; end
@@ -112,6 +113,7 @@ module ActiveRecord
112
113
  end
113
114
  def sqlserver_2000? ; self.class.sqlserver_2000? ; end
114
115
  def sqlserver_2005? ; self.class.sqlserver_2005? ; end
116
+ def sqlserver_2008? ; self.class.sqlserver_2008? ; end
115
117
  def active_record_2_point_2? ; self.class.active_record_2_point_2? ; end
116
118
  def active_record_2_point_3? ; self.class.active_record_2_point_3? ; end
117
119
  def ruby_19? ; self.class.ruby_19? ; end
@@ -14,7 +14,7 @@ class UnicodeTestSqlserver < ActiveRecord::TestCase
14
14
  test_string = 'Ken Collins'
15
15
  assert nvarcharmax_data = SqlServerUnicode.create!(:nvarchar_max => test_string)
16
16
  assert_equal test_string, SqlServerUnicode.find(nvarcharmax_data.id).nvarchar_max
17
- end if sqlserver_2005?
17
+ end if sqlserver_2005? || sqlserver_2008?
18
18
 
19
19
  should 'enforce default nchar_10 limit of 10' do
20
20
  assert_raise(ActiveRecord::StatementInvalid) { SqlServerUnicode.create!(:nchar => '01234567891') }
@@ -2,7 +2,6 @@ ActiveRecord::Schema.define do
2
2
 
3
3
  create_table :table_with_real_columns, :force => true do |t|
4
4
  t.column :real_number, :real
5
- # t.column :varchar_max, :varchar_max if ActiveRecord::Base.connection.sqlserver_2005?
6
5
  end
7
6
 
8
7
  create_table :defaults, :force => true do |t|
@@ -44,7 +43,7 @@ ActiveRecord::Schema.define do
44
43
  t.column :ntext_10, :ntext, :limit => 10
45
44
  t.column :nchar_10, :nchar, :limit => 10
46
45
  t.column :nvarchar_100, :nvarchar, :limit => 100
47
- if ActiveRecord::Base.connection.sqlserver_2005?
46
+ if ActiveRecord::Base.connection.sqlserver_2005? || ActiveRecord::Base.connection.sqlserver_2008?
48
47
  t.column :nvarchar_max, :nvarchar_max
49
48
  t.column :nvarchar_max_10, :nvarchar_max, :limit => 10
50
49
  end
@@ -53,7 +52,7 @@ ActiveRecord::Schema.define do
53
52
  create_table :sql_server_strings, :force => true do |t|
54
53
  t.column :char, :char
55
54
  t.column :char_10, :char, :limit => 10
56
- if ActiveRecord::Base.connection.sqlserver_2005?
55
+ if ActiveRecord::Base.connection.sqlserver_2005? || ActiveRecord::Base.connection.sqlserver_2008?
57
56
  t.column :varchar_max, :varchar_max
58
57
  t.column :varchar_max_10, :varchar_max, :limit => 10
59
58
  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.17
4
+ version: 2.2.18
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-05-14 00:00:00 -07:00
16
+ date: 2009-06-05 00:00:00 -07:00
17
17
  default_executable:
18
18
  dependencies: []
19
19
 
@@ -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 & 2005 Adapter For Rails.
70
+ summary: SQL Server 2000 & 2005 & 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