rails-sqlserver-2000-2005-adapter 2.2.1 → 2.2.2

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
@@ -1,10 +1,17 @@
1
1
 
2
- *MASTER* ()
2
+ MASTER
3
3
 
4
4
  *
5
5
 
6
6
 
7
- *2.2.1* (November 25th, 2008)
7
+ 2.2.2 (December 2nd, 2008)
8
+
9
+ * Add support for view defaults by making column_definitions use real table name for schema info.
10
+
11
+ * Include version in connection method and inspection. [Ken Collins]
12
+
13
+
14
+ 2.2.1 (November 25th, 2008)
8
15
 
9
16
  * Add identity insert support for views. Cache #views so that identity #table_name_or_views_table_name
10
17
  will run quickly. [Ken Collins]
@@ -13,7 +20,7 @@
13
20
  #table_exists? will not fall back to checking views too. [Ken Collins]
14
21
 
15
22
 
16
- *2.2.0* (November 21st, 2008)
23
+ 2.2.0 (November 21st, 2008)
17
24
 
18
25
  * Release for rails 2.2.2. Many many changes. [Ken Collins], [Murray Steele], [Shawn Balestracci], [Joe Rafaniello]
19
26
 
data/README.rdoc CHANGED
@@ -13,6 +13,7 @@ The SQL Server adapter for rails is back for ActiveRecord 2.2 and up! We are cur
13
13
  * Pessimistic locking suppot. See the #add_lock! method for details.
14
14
  * Enabled #case_sensitive_equality_operator used by unique validations.
15
15
  * Unicode character support for nchar, nvarchar and ntext data types.
16
+ * Support for views as table names. Also support views during identity inserts.
16
17
 
17
18
  ==== Date/Time Data Type Hinting
18
19
 
@@ -98,7 +99,7 @@ Here are some external links for libraries and/or tutorials on how to install an
98
99
 
99
100
  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.
100
101
 
101
- * Lighthouse: http://rails-sqlserver.lighthouseapp.com/projects/20277-sql-server-05-adapter/overview
102
+ * Lighthouse: http://rails-sqlserver.lighthouseapp.com/projects/20277-sql-server-05-adapter/tickets
102
103
  * Google Group: http://groups.google.com/group/rails-sqlserver-adapter
103
104
  * IRC Room: #rails-sqlserver on irc.freenode.net
104
105
 
@@ -150,6 +150,7 @@ module ActiveRecord
150
150
  class SQLServerAdapter < AbstractAdapter
151
151
 
152
152
  ADAPTER_NAME = 'SQLServer'.freeze
153
+ VERSION = '2.2.2'.freeze
153
154
  DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
154
155
  SUPPORTED_VERSIONS = [2000,2005].freeze
155
156
  LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].freeze
@@ -203,8 +204,12 @@ module ActiveRecord
203
204
  database_year == 2005
204
205
  end
205
206
 
207
+ def version
208
+ self.class::VERSION
209
+ end
210
+
206
211
  def inspect
207
- "#<#{self.class} year: #{database_year}, connection_options: #{@connection_options.inspect}>"
212
+ "#<#{self.class} version: #{version}, year: #{database_year}, connection_options: #{@connection_options.inspect}>"
208
213
  end
209
214
 
210
215
  def native_text_database_type
@@ -751,7 +756,7 @@ module ActiveRecord
751
756
  # IDENTITY INSERTS =========================================#
752
757
 
753
758
  def with_identity_insert_enabled(table_name, &block)
754
- table_name = table_name_or_views_table_name(table_name)
759
+ table_name = quote_table_name(table_name_or_views_table_name(table_name))
755
760
  set_identity_insert(table_name, true)
756
761
  yield
757
762
  ensure
@@ -781,7 +786,7 @@ module ActiveRecord
781
786
 
782
787
  def table_name_or_views_table_name(table_name)
783
788
  unquoted_table_name = unqualify_table_name(table_name)
784
- views.include?(unquoted_table_name) ? view_table_name(unquoted_table_name) : table_name
789
+ views.include?(unquoted_table_name) ? view_table_name(unquoted_table_name) : unquoted_table_name
785
790
  end
786
791
 
787
792
  # HELPER METHODS ===========================================#
@@ -849,7 +854,8 @@ module ActiveRecord
849
854
 
850
855
  def column_definitions(table_name)
851
856
  db_name = unqualify_db_name(table_name)
852
- table_name = unqualify_table_name(table_name)
857
+ real_table_name = table_name_or_views_table_name(table_name)
858
+ passed_table_name = unqualify_table_name(table_name)
853
859
  sql = %{
854
860
  SELECT
855
861
  columns.TABLE_NAME as table_name,
@@ -874,12 +880,13 @@ module ActiveRecord
874
880
  ELSE 1
875
881
  END as is_identity
876
882
  FROM #{db_name}INFORMATION_SCHEMA.COLUMNS columns
877
- WHERE columns.TABLE_NAME = '#{table_name}'
883
+ WHERE columns.TABLE_NAME = '#{real_table_name}'
878
884
  ORDER BY columns.ordinal_position
879
885
  }.gsub(/[ \t\r\n]+/,' ')
880
886
  results = without_type_conversion { select(sql,nil,true) }
881
887
  results.collect do |ci|
882
888
  ci.symbolize_keys!
889
+ ci[:table_name] = passed_table_name
883
890
  ci[:type] = case ci[:type]
884
891
  when /^bit|image|text|ntext|datetime$/
885
892
  ci[:type]
@@ -27,6 +27,10 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
27
27
  assert_equal 'SQLServer', @connection.adapter_name
28
28
  end
29
29
 
30
+ should 'include version in inspect' do
31
+ assert_match(/version\: \d.\d.\d/,@connection.inspect)
32
+ end
33
+
30
34
  should 'support migrations' do
31
35
  assert @connection.supports_migrations?
32
36
  end
@@ -393,8 +397,19 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
393
397
  end
394
398
  end
395
399
 
400
+ should 'find identity column' do
401
+ assert CustomersView.columns_hash['id'].primary
402
+ assert CustomersView.columns_hash['id'].is_identity?
403
+ end
404
+
405
+ should 'pick up on default values from table' do
406
+ assert_equal 0, CustomersView.new.balance
407
+ assert_equal 'null', StringDefaultsView.new.string_with_pretend_null_one
408
+ end
409
+
396
410
  should 'yield all column objects having the correct table name' do
397
- assert CustomersView.columns.all?{ |c| c.table_name == 'customers_view' }
411
+ assert CustomersView.columns.all?{ |c| c.table_name == 'customers_view' },
412
+ CustomersView.columns.map(&:table_name).inspect
398
413
  end
399
414
 
400
415
  should 'respond true to table_exists?' do
@@ -20,6 +20,7 @@ class FkTestHasFk < ActiveRecord::Base ; end
20
20
  class FkTestHasPk < ActiveRecord::Base ; end
21
21
  class NumericData < ActiveRecord::Base ; self.table_name = 'numeric_data' ; end
22
22
  class CustomersView < ActiveRecord::Base ; self.table_name = 'customers_view' ; end
23
+ class StringDefaultsView < ActiveRecord::Base ; self.table_name = 'string_defaults_view' ; end
23
24
  class SqlServerUnicode < ActiveRecord::Base ; end
24
25
  class SqlServerString < ActiveRecord::Base ; end
25
26
  class SqlServerChronic < ActiveRecord::Base
@@ -67,6 +67,11 @@ ActiveRecord::Schema.define do
67
67
  SELECT id, name, balance
68
68
  FROM customers
69
69
  CUSTOMERSVIEW
70
-
70
+ execute "IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'string_defaults_view') DROP VIEW string_defaults_view"
71
+ execute <<-STRINGDEFAULTSVIEW
72
+ CREATE VIEW string_defaults_view AS
73
+ SELECT id, string_with_pretend_null_one
74
+ FROM string_defaults
75
+ STRINGDEFAULTSVIEW
71
76
 
72
77
  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.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins