rails-sqlserver-2000-2005-adapter 2.2.8 → 2.2.9

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
@@ -4,6 +4,16 @@ MASTER
4
4
  *
5
5
 
6
6
 
7
+ * 2.2.9 * (January 22nd, 2009)
8
+
9
+ * Fixing a small bug in the deprecated DBI::Timestamp conversion so it correctly converts nanosecond whole
10
+ numbers to back to pre type cast SQL Server milliseconds, ultimately allow ruby's Time#usec which is
11
+ microseconds to be correct. [Ken Collins]
12
+
13
+ * Sometimes views are more than 4000 chars long and will return NULL for the VIEW_DEFINITION. If so, use
14
+ sp_helptext procedure as a backup method. [Ken Collins]
15
+
16
+
7
17
  * 2.2.8 (January 9th, 2009)
8
18
 
9
19
  * Update execute_procedure method a bit to remove excess code. [Ken Collins]
@@ -150,7 +150,7 @@ module ActiveRecord
150
150
  class SQLServerAdapter < AbstractAdapter
151
151
 
152
152
  ADAPTER_NAME = 'SQLServer'.freeze
153
- VERSION = '2.2.8'.freeze
153
+ VERSION = '2.2.9'.freeze
154
154
  DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
155
155
  SUPPORTED_VERSIONS = [2000,2005].freeze
156
156
  LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].freeze
@@ -482,8 +482,13 @@ module ActiveRecord
482
482
 
483
483
  def view_information(table_name)
484
484
  table_name = unqualify_table_name(table_name)
485
- @sqlserver_view_information_cache[table_name] ||=
486
- info_schema_query { select_one("SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = '#{table_name}'") }
485
+ @sqlserver_view_information_cache[table_name] ||= begin
486
+ view_info = info_schema_query { select_one("SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = '#{table_name}'") }
487
+ if view_info
488
+ view_info['VIEW_DEFINITION'] ||= info_schema_query { select_values("EXEC sp_helptext #{table_name}").join }
489
+ end
490
+ view_info
491
+ end
487
492
  end
488
493
 
489
494
  def view_table_name(table_name)
data/lib/core_ext/dbi.rb CHANGED
@@ -2,14 +2,12 @@
2
2
  module SQLServerDBI
3
3
 
4
4
  module Timestamp
5
- # Will further change DBI::Timestamp #to_s return value by limiting the usec of
6
- # the time to 3 digits and in some cases adding zeros if needed. For example:
7
- # "1985-04-15 00:00:00.0" # => "1985-04-15 00:00:00.000"
8
- # "2008-11-08 10:24:36.547000" # => "2008-11-08 10:24:36.547"
9
- # "2008-11-08 10:24:36.123" # => "2008-11-08 10:24:36.000"
5
+ # Deprecated DBI. See documentation for Type::SqlserverTimestamp which
6
+ # this method tries to mimic as ODBC is still going to convert SQL Server
7
+ # milliconds to whole number representation of nanoseconds.
10
8
  def to_sqlserver_string
11
- datetime, usec = to_s[0..22].split('.')
12
- "#{datetime}.#{sprintf("%03d",usec)}"
9
+ datetime, nanoseconds = to_s.split('.')
10
+ "#{datetime}.#{sprintf("%03d",nanoseconds.to_i/1000000)}"
13
11
  end
14
12
  end
15
13
 
@@ -24,7 +22,7 @@ module SQLServerDBI
24
22
  # and the conversion we expect to have in the DB before type casting.
25
23
  #
26
24
  # "1985-04-15 00:00:00 0" # => "1985-04-15 00:00:00.000"
27
- # "2008-11-08 10:24:36 300000000" # => "2008-11-08 10:24:36.003"
25
+ # "2008-11-08 10:24:36 30000000" # => "2008-11-08 10:24:36.003"
28
26
  # "2008-11-08 10:24:36 123000000" # => "2008-11-08 10:24:36.123"
29
27
  class SqlserverTimestamp
30
28
  def self.parse(obj)
@@ -250,13 +250,13 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
250
250
  should 'find 003 millisecond in the DB with before and after casting' do
251
251
  existing_003 = SqlServerChronic.find_by_datetime!(@db_datetime_003)
252
252
  assert_equal @db_datetime_003, existing_003.datetime_before_type_cast
253
- assert_equal 3000, existing_003.datetime.usec, 'A 003 millisecond in SQL Server is 3000 milliseconds'
253
+ assert_equal 3000, existing_003.datetime.usec, 'A 003 millisecond in SQL Server is 3000 microseconds'
254
254
  end
255
255
 
256
256
  should 'find 123 millisecond in the DB with before and after casting' do
257
257
  existing_123 = SqlServerChronic.find_by_datetime!(@db_datetime_123)
258
258
  assert_equal @db_datetime_123, existing_123.datetime_before_type_cast
259
- assert_equal 123000, existing_123.datetime.usec, 'A 123 millisecond in SQL Server is 123000 milliseconds'
259
+ assert_equal 123000, existing_123.datetime.usec, 'A 123 millisecond in SQL Server is 123000 microseconds'
260
260
  end
261
261
 
262
262
  end
@@ -536,6 +536,19 @@ class AdapterTestSqlserver < ActiveRecord::TestCase
536
536
 
537
537
  end
538
538
 
539
+ context 'that have more than 4000 chars for their defintion' do
540
+
541
+ should 'cope with null returned for the defintion' do
542
+ assert_nothing_raised() { StringDefaultsBigView.columns }
543
+ end
544
+
545
+ should 'using alternate view defintion still be able to find real default' do
546
+ assert_equal 'null', StringDefaultsBigView.new.pretend_null,
547
+ StringDefaultsBigView.columns_hash['pretend_null'].inspect
548
+ end
549
+
550
+ end
551
+
539
552
  end
540
553
 
541
554
 
@@ -11,6 +11,7 @@ class SpecificSchemaTestSqlserver < ActiveRecord::TestCase
11
11
  assert_equal '(null)', default.string_with_pretend_null_two
12
12
  assert_equal 'NULL', default.string_with_pretend_null_three
13
13
  assert_equal '(NULL)', default.string_with_pretend_null_four
14
+ assert_equal '(3)', default.string_with_pretend_paren_three
14
15
  end
15
16
 
16
17
  should 'default strings after save' do
@@ -21,6 +21,7 @@ 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
23
  class StringDefaultsView < ActiveRecord::Base ; self.table_name = 'string_defaults_view' ; end
24
+ class StringDefaultsBigView < ActiveRecord::Base ; self.table_name = 'string_defaults_big_view' ; end
24
25
  class SqlServerUnicode < ActiveRecord::Base ; end
25
26
  class SqlServerString < ActiveRecord::Base ; end
26
27
  class SqlServerChronic < ActiveRecord::Base
@@ -17,6 +17,7 @@ ActiveRecord::Schema.define do
17
17
  t.column :string_with_pretend_null_two, :string, :default => '(null)'
18
18
  t.column :string_with_pretend_null_three, :string, :default => 'NULL'
19
19
  t.column :string_with_pretend_null_four, :string, :default => '(NULL)'
20
+ t.column :string_with_pretend_paren_three, :string, :default => '(3)'
20
21
  end
21
22
 
22
23
  create_table :sql_server_chronics, :force => true do |t|
@@ -67,6 +68,7 @@ ActiveRecord::Schema.define do
67
68
  SELECT id, name, balance
68
69
  FROM customers
69
70
  CUSTOMERSVIEW
71
+
70
72
  execute "IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'string_defaults_view') DROP VIEW string_defaults_view"
71
73
  execute <<-STRINGDEFAULTSVIEW
72
74
  CREATE VIEW string_defaults_view AS
@@ -74,4 +76,12 @@ ActiveRecord::Schema.define do
74
76
  FROM string_defaults
75
77
  STRINGDEFAULTSVIEW
76
78
 
79
+ execute "IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'string_defaults_big_view') DROP VIEW string_defaults_big_view"
80
+ execute <<-STRINGDEFAULTSBIGVIEW
81
+ CREATE VIEW string_defaults_big_view AS
82
+ SELECT id, string_with_pretend_null_one as pretend_null
83
+ /*#{'x'*4000}}*/
84
+ FROM string_defaults
85
+ STRINGDEFAULTSBIGVIEW
86
+
77
87
  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.8
4
+ version: 2.2.9
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-01-09 00:00:00 -08:00
16
+ date: 2009-01-22 00:00:00 -08:00
17
17
  default_executable:
18
18
  dependencies: []
19
19