activerecord-sqlserver-adapter 2.3.12 → 2.3.13

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,4 +1,15 @@
1
1
 
2
+ * 2-3-stable *
3
+
4
+
5
+
6
+ * 2.3.13 *
7
+
8
+ * Fixed native database type memoization, now at connection instance level. Fix #execute_procedure for :dblib mode to return indifferent access rows too. Misc test case fixes for 2000 & 2005 need for using coerced Time vs Date type. Fix SQL Server 2000's lack of using TinyTds' native affected rows for UPDATE statements, revert to raw SQL.
9
+
10
+ * Make login timeout and query timeout backward database.yml friendly for :dblib mode.
11
+
12
+
2
13
  * 2.3.12 *
3
14
 
4
15
  * Add multiple results set support with #execute_procedure for :dblib mode. [Ken Collins]
data/Rakefile CHANGED
@@ -31,13 +31,6 @@ namespace :test do
31
31
  end
32
32
 
33
33
  end
34
-
35
- desc 'Test without unicode types enabled, uses ODBC mode.'
36
- task :non_unicode_types do
37
- ENV['ENABLE_DEFAULT_UNICODE_TYPES'] = 'false'
38
- test = Rake::Task['test:odbc']
39
- test.invoke
40
- end
41
34
 
42
35
  end
43
36
 
@@ -147,7 +147,7 @@ module ActiveRecord
147
147
  class SQLServerAdapter < AbstractAdapter
148
148
 
149
149
  ADAPTER_NAME = 'SQLServer'.freeze
150
- VERSION = '2.3.12'.freeze
150
+ VERSION = '2.3.13'.freeze
151
151
  DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+(\d{4})/
152
152
  SUPPORTED_VERSIONS = [2000,2005,2008].freeze
153
153
  LIMITABLE_TYPES = ['string','integer','float','char','nchar','varchar','nvarchar'].to_set.freeze
@@ -182,7 +182,6 @@ module ActiveRecord
182
182
  super(@connection, logger)
183
183
  @database_version = info_schema_query { select_value('SELECT @@version') }
184
184
  @database_year = DATABASE_VERSION_REGEXP.match(@database_version)[1].to_i rescue 0
185
- initialize_native_database_types
186
185
  initialize_sqlserver_caches
187
186
  use_database
188
187
  unless SUPPORTED_VERSIONS.include?(@database_year)
@@ -269,7 +268,6 @@ module ActiveRecord
269
268
  when String, ActiveSupport::Multibyte::Chars
270
269
  if column && column.type == :binary
271
270
  column.class.string_to_binary(value)
272
- # elsif column && column.type == :string
273
271
  elsif value.is_utf8? || (column && column.type == :string)
274
272
  "N'#{quote_string(value)}'"
275
273
  else
@@ -417,7 +415,7 @@ module ActiveRecord
417
415
  r = row.with_indifferent_access
418
416
  yield(r) if block_given?
419
417
  end
420
- result.each
418
+ result.each.map{ |row| row.is_a?(Hash) ? row.with_indifferent_access : row }
421
419
  when :odbc
422
420
  results = []
423
421
  raw_connection_run(sql) do |handle|
@@ -570,7 +568,7 @@ module ActiveRecord
570
568
  # SCHEMA STATEMENTS ========================================#
571
569
 
572
570
  def native_database_types
573
- ActiveRecord::ConnectionAdapters::SQLServerAdapter::NATIVE_DATABASE_TYPES
571
+ @native_database_types ||= initialize_native_database_types.freeze
574
572
  end
575
573
 
576
574
  def table_alias_length
@@ -814,6 +812,8 @@ module ActiveRecord
814
812
  @connection = case @connection_options[:mode]
815
813
  when :dblib
816
814
  appname = config[:appname] || Rails.application.class.name.split('::').first rescue nil
815
+ login_timeout = config[:login_timeout].present? ? config[:login_timeout].to_i : nil
816
+ timeout = config[:timeout].present? ? config[:timeout].to_i/1000 : nil
817
817
  encoding = config[:encoding].present? ? config[:encoding] : nil
818
818
  TinyTds::Client.new({
819
819
  :dataserver => config[:dataserver],
@@ -821,8 +821,8 @@ module ActiveRecord
821
821
  :password => config[:password],
822
822
  :database => config[:database],
823
823
  :appname => appname,
824
- :login_timeout => config[:dblib_login_timeout],
825
- :timeout => config[:dblib_timeout],
824
+ :login_timeout => login_timeout,
825
+ :timeout => timeout,
826
826
  :encoding => encoding
827
827
  }).tap do |client|
828
828
  client.execute("SET ANSI_DEFAULTS ON").do
@@ -961,7 +961,7 @@ module ActiveRecord
961
961
  @update_sql = true
962
962
  case @connection_options[:mode]
963
963
  when :dblib
964
- execute(sql, name)
964
+ sqlserver_2000? ? execute(sql, name) && select_value('SELECT @@ROWCOUNT AS AffectedRows') : execute(sql, name)
965
965
  else
966
966
  execute(sql, name)
967
967
  select_value('SELECT @@ROWCOUNT AS AffectedRows')
@@ -1266,8 +1266,7 @@ module ActiveRecord
1266
1266
  end
1267
1267
 
1268
1268
  def initialize_native_database_types
1269
- return if defined?(ActiveRecord::ConnectionAdapters::SQLServerAdapter::NATIVE_DATABASE_TYPES)
1270
- ActiveRecord::ConnectionAdapters::SQLServerAdapter.const_set(:NATIVE_DATABASE_TYPES,{
1269
+ {
1271
1270
  :primary_key => "int NOT NULL IDENTITY(1,1) PRIMARY KEY",
1272
1271
  :string => { :name => native_string_database_type, :limit => 255 },
1273
1272
  :text => { :name => native_text_database_type },
@@ -1288,7 +1287,7 @@ module ActiveRecord
1288
1287
  :nvarchar_max => { :name => "nvarchar(max)" },
1289
1288
  :ntext => { :name => "ntext" },
1290
1289
  :ss_timestamp => { :name => 'timestamp'}
1291
- })
1290
+ }
1292
1291
  end
1293
1292
 
1294
1293
  def column_definitions(table_name)
@@ -1,12 +1,16 @@
1
1
  require 'cases/sqlserver_helper'
2
2
  require 'models/developer'
3
+ require 'models/topic'
3
4
 
4
5
  class BasicsTestSqlserver < ActiveRecord::TestCase
5
6
  end
6
7
 
7
8
  class BasicsTest < ActiveRecord::TestCase
8
9
 
9
- COERCED_TESTS = [:test_read_attributes_before_type_cast_on_datetime]
10
+ COERCED_TESTS = [
11
+ :test_read_attributes_before_type_cast_on_datetime,
12
+ :test_preserving_date_objects,
13
+ :test_to_xml ]
10
14
 
11
15
  include SqlserverCoercedTest
12
16
 
@@ -19,5 +23,59 @@ class BasicsTest < ActiveRecord::TestCase
19
23
  end
20
24
  end
21
25
 
26
+ def test_coerced_test_preserving_date_objects
27
+ klass = sqlserver_2008? ? Date : (connection_mode_dblib? ? Time : Date)
28
+ assert_kind_of klass, Topic.find(1).last_read, "The last_read attribute should be of the #{klass.name} class"
29
+ end
30
+
31
+ def test_coerced_test_to_xml
32
+ xml = REXML::Document.new(topics(:first).to_xml(:indent => 0))
33
+ bonus_time_in_current_timezone = topics(:first).bonus_time.xmlschema
34
+ written_on_in_current_timezone = topics(:first).written_on.xmlschema
35
+
36
+ assert_equal "topic", xml.root.name
37
+ assert_equal "The First Topic" , xml.elements["//title"].text
38
+ assert_equal "David" , xml.elements["//author-name"].text
39
+
40
+ assert_equal "1", xml.elements["//id"].text
41
+ assert_equal "integer" , xml.elements["//id"].attributes['type']
42
+
43
+ assert_equal "1", xml.elements["//replies-count"].text
44
+ assert_equal "integer" , xml.elements["//replies-count"].attributes['type']
45
+
46
+ assert_equal written_on_in_current_timezone, xml.elements["//written-on"].text
47
+ assert_equal "datetime" , xml.elements["//written-on"].attributes['type']
48
+
49
+ assert_equal "--- Have a nice day\n" , xml.elements["//content"].text
50
+ assert_equal "yaml" , xml.elements["//content"].attributes['type']
51
+
52
+ assert_equal "david@loudthinking.com", xml.elements["//author-email-address"].text
53
+
54
+ assert_equal nil, xml.elements["//parent-id"].text
55
+ assert_equal "integer", xml.elements["//parent-id"].attributes['type']
56
+ assert_equal "true", xml.elements["//parent-id"].attributes['nil']
57
+
58
+ if sqlserver_2000? || sqlserver_2005?
59
+ last_read_in_current_timezone, last_read_type = if connection_mode_odbc?
60
+ ["2004-04-15", "date"]
61
+ elsif connection_mode_dblib?
62
+ ["2004-04-15 00:00:00", "date"]
63
+ else
64
+ [topics(:first).last_read.xmlschema, "datetime"]
65
+ end
66
+ assert_equal last_read_in_current_timezone, xml.elements["//last-read"].text
67
+ assert_equal last_read_type , xml.elements["//last-read"].attributes['type']
68
+ else
69
+ assert_equal "2004-04-15", xml.elements["//last-read"].text
70
+ assert_equal "date" , xml.elements["//last-read"].attributes['type']
71
+ end
72
+
73
+ assert_equal "false", xml.elements["//approved"].text
74
+ assert_equal "boolean" , xml.elements["//approved"].attributes['type']
75
+
76
+ assert_equal bonus_time_in_current_timezone, xml.elements["//bonus-time"].text
77
+ assert_equal "datetime" , xml.elements["//bonus-time"].attributes['type']
78
+ end
79
+
22
80
 
23
81
  end
@@ -237,7 +237,8 @@ class ColumnTestSqlserver < ActiveRecord::TestCase
237
237
 
238
238
  should 'have column and objects cast to date' do
239
239
  assert_equal :date, @date.type, "This column: \n#{@date.inspect}"
240
- assert_instance_of Date, @chronic_date.date
240
+ klass = sqlserver_2008? ? Date : (connection_mode_dblib? ? Time : Date)
241
+ assert_instance_of klass, @chronic_date.date
241
242
  end
242
243
 
243
244
  should 'have column objects cast to time' do
@@ -84,3 +84,25 @@ class MigrationTest < ActiveRecord::TestCase
84
84
 
85
85
  end
86
86
 
87
+
88
+ class ChangeTableMigrationsTest < ActiveRecord::TestCase
89
+
90
+ COERCED_TESTS = [:test_string_creates_string_column]
91
+
92
+ include SqlserverCoercedTest
93
+
94
+ def test_coerced_string_creates_string_column
95
+ with_change_table do |t|
96
+ @connection.expects(:add_column).with(:delete_me, :foo, coerced_string_column, {})
97
+ @connection.expects(:add_column).with(:delete_me, :bar, coerced_string_column, {})
98
+ t.string :foo, :bar
99
+ end
100
+ end
101
+
102
+ def coerced_string_column
103
+ "#{Person.connection.native_string_database_type}(255)"
104
+ end
105
+
106
+ end
107
+
108
+
@@ -1,4 +1,4 @@
1
- print "Using SQLServer via ODBC\n"
1
+ print "Using SQLServer via ODBC to #{ENV['ACTIVERECORD_UNITTEST_DSN'] || 'activerecord_unittest'}\n"
2
2
  require_dependency 'models/course'
3
3
  require 'logger'
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-sqlserver-adapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 3
9
- - 12
10
- version: 2.3.12
9
+ - 13
10
+ version: 2.3.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ken Collins
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-10-26 00:00:00 -04:00
22
+ date: 2010-10-31 00:00:00 -04:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency