activerecord-sqlserver-adapter 4.2.10 → 4.2.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3f5cb06eb492b1fce0526281946dea07336bec9
4
- data.tar.gz: 1b4d4a21a4a4ed6858572daac58016d8d5672d35
3
+ metadata.gz: 5645093f45bc28adecc3cc3a38fdb886f6683a9c
4
+ data.tar.gz: bddd84dff29484133c22f905f3c75439a68cbbe5
5
5
  SHA512:
6
- metadata.gz: ae62612e1fe093da674fa74d67ee2e85a516795871fb6fa5fc281fadd2c09a5a0378a7a202caf592d6ab4babaa08545e218fe18a46a9e195805e8cf69195746b
7
- data.tar.gz: 398a1381b3f0157bec451e29c45c57f4ade59291e10f3c17e95591bcf9471f743a2e96852c7509f946cd7237edf4b5ffcbfdd68b044165cf57d55f63daf602b9
6
+ metadata.gz: e2e9df466a158a7a1d35860e6c32c75b4e9f46774122b7cfcf8f43c1d9f770cb1a723cedf92f30ec9d06ec39501be10a018bbd0f6ffcff1257160127de7fa3f3
7
+ data.tar.gz: d24d8c79658031f51266734f5648af3cf5dc3e47911a245774f2a9dd32aecfbb25407703758ef707140507af7ab632dac93ccf193f9c30dd3c74543b5b6ef025
@@ -1,3 +1,18 @@
1
+ ## v4.2.11
2
+
3
+ #### Fixed
4
+
5
+ * Undefined method `database_prefix_remote_server?' Fixes #450. Thanks @jippeholwerda
6
+ * Document two methods for avoiding N'' quoting on char/varchar columns.
7
+ * First run failure of `change_column` while dropping constraint. Fixes #420. Thanks @GrumpyRainbow @rkr090
8
+ * Rounding errors w/datetime2(0) types having no fractional seconds. Fixes #465. Thanks @alawton
9
+
10
+ #### Changed
11
+
12
+ * Supporting escape hatch for N'' quoting. Remove `#is_utf8` string check in `#_quote` method.
13
+ This duplicated strings and forced encoding which was actually wasteful.
14
+
15
+
1
16
  ## v4.2.10
2
17
 
3
18
  #### Fixed
data/Gemfile CHANGED
@@ -49,9 +49,13 @@ group :odbc do
49
49
  end
50
50
 
51
51
  group :development do
52
- gem 'guard'
53
- gem 'guard-minitest'
54
52
  gem 'mocha'
55
53
  gem 'minitest', '< 5.3.4' # PENDING: [Rails5.x] Remove test order constraint.
56
54
  gem 'minitest-spec-rails'
55
+ gem 'pry'
56
+ end
57
+
58
+ group :guard do
59
+ gem 'guard'
60
+ gem 'guard-minitest'
57
61
  end
data/README.md CHANGED
@@ -197,5 +197,5 @@ Up-to-date list of contributors: http://github.com/rails-sqlserver/activerecord-
197
197
 
198
198
  ## License
199
199
 
200
- Copyright © 2008-2015. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
200
+ Copyright © 2008-2016. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
201
201
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.2.10
1
+ 4.2.11
@@ -11,7 +11,7 @@ install:
11
11
  - ps: Update-AppveyorBuild -Version "$(Get-Content $env:appveyor_build_folder\VERSION).$env:appveyor_build_number"
12
12
  - ruby --version
13
13
  - gem --version
14
- - bundle install --without odbc
14
+ - bundle install --without odbc guard
15
15
  build: off
16
16
  test_script:
17
17
  - powershell -File "%APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.ps1"
@@ -54,12 +54,10 @@ module ActiveRecord
54
54
  case value
55
55
  when Type::Binary::Data
56
56
  "0x#{value.hex}"
57
+ when ActiveRecord::Type::SQLServer::Char::Data
58
+ value.quoted
57
59
  when String, ActiveSupport::Multibyte::Chars
58
- if value.is_utf8?
59
- "#{QUOTED_STRING_PREFIX}#{super}"
60
- else
61
- super
62
- end
60
+ "#{QUOTED_STRING_PREFIX}#{super}"
63
61
  else
64
62
  super
65
63
  end
@@ -96,6 +96,7 @@ module ActiveRecord
96
96
  end
97
97
 
98
98
  def change_column_default(table_name, column_name, default)
99
+ schema_cache.clear_table_cache!(table_name)
99
100
  remove_default_constraint(table_name, column_name)
100
101
  column_object = schema_cache.columns(table_name).find { |c| c.name.to_s == column_name.to_s }
101
102
  do_execute "ALTER TABLE #{quote_table_name(table_name)} ADD CONSTRAINT #{default_constraint_name(table_name, column_name)} DEFAULT #{quote_default_value(default, column_object)} FOR #{quote_column_name(column_name)}"
@@ -8,6 +8,24 @@ module ActiveRecord
8
8
  :char
9
9
  end
10
10
 
11
+ def type_cast_for_database(value)
12
+ return if value.nil?
13
+ return value if value.is_a?(Data)
14
+ Data.new(super)
15
+ end
16
+
17
+ class Data
18
+
19
+ def initialize(value)
20
+ @value = value.to_s
21
+ end
22
+
23
+ def quoted
24
+ "'#{@value}'"
25
+ end
26
+
27
+ end
28
+
11
29
  end
12
30
  end
13
31
  end
@@ -9,9 +9,13 @@ module ActiveRecord
9
9
 
10
10
  def cast_fractional(value)
11
11
  return value if !value.respond_to?(fractional_property) || value.send(fractional_property).zero?
12
- seconds = value.send(fractional_property).to_f / fractional_operator.to_f
13
- seconds = ((seconds * (1 / fractional_precision)).round / (1 / fractional_precision)).round(fractional_scale)
14
- frac_seconds = (seconds * fractional_operator).to_i
12
+ frac_seconds = if fractional_scale == 0
13
+ 0
14
+ else
15
+ seconds = value.send(fractional_property).to_f / fractional_operator.to_f
16
+ seconds = ((seconds * (1 / fractional_precision)).round / (1 / fractional_precision)).round(fractional_scale)
17
+ (seconds * fractional_operator).to_i
18
+ end
15
19
  value.change fractional_property => frac_seconds
16
20
  end
17
21
 
@@ -74,7 +74,10 @@ module Arel
74
74
  end
75
75
 
76
76
  def visit_Arel_Table o, collector
77
- table_name = if o.engine.connection.database_prefix_remote_server?
77
+ # Apparently, o.engine.connection can actually be a different adapter
78
+ # than sqlserver. Can be removed if fixed in ActiveRecord. See:
79
+ # github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/450
80
+ table_name = if o.engine.connection.respond_to?(:sqlserver?) && o.engine.connection.database_prefix_remote_server?
78
81
  remote_server_table_name(o)
79
82
  else
80
83
  quote_table_name(o.name)
@@ -373,6 +373,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
373
373
  obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
374
374
  obj.save! ; obj.reload
375
375
  obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
376
+ col = column('datetime2_0')
377
+ col.cast_type.precision.must_equal 0
378
+ time = Time.utc 2016, 4, 19, 16, 45, 40, 771036
379
+ obj.datetime2_0 = time
380
+ obj.datetime2_0.must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
381
+ obj.save! ; obj.reload
382
+ obj.datetime2_0.must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
376
383
  end
377
384
 
378
385
  it 'datetimeoffset' do
@@ -107,6 +107,24 @@ class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
107
107
  assert_equal r, SSTestEdgeSchema.where('crazy]]quote' => 'crazyqoute').first
108
108
  end
109
109
 
110
+ it 'various methods to bypass national quoted columns for any column, but primarily useful for char/varchar' do
111
+ value = Class.new do
112
+ def quoted_id
113
+ "'T'"
114
+ end
115
+ end
116
+ # Using ActiveRecord's quoted_id feature for objects.
117
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: value.new).first }
118
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: value.new).first }
119
+ # Using our custom char type data.
120
+ data = ActiveRecord::Type::SQLServer::Char::Data
121
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: data.new('T')).first }
122
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: data.new('T')).first }
123
+ # Taking care of everything.
124
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: 'T').first }
125
+ assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: 'T').first }
126
+ end
127
+
110
128
  # With column names that have spaces
111
129
 
112
130
  it 'create record using a custom attribute reader and be able to load it back in' do
@@ -28,6 +28,7 @@ CREATE TABLE [sst_datatypes] (
28
28
  [datetime2_7] [datetime2](7) NULL DEFAULT '9999-12-31 23:59:59.9999999',
29
29
  [datetime2_3] [datetime2](3) NULL,
30
30
  [datetime2_1] [datetime2](1) NULL,
31
+ [datetime2_0] [datetime2](0) NULL,
31
32
  [datetimeoffset_7] [datetimeoffset](7) NULL DEFAULT '1984-01-24 04:20:00.1234567 -08:00',
32
33
  [datetimeoffset_3] [datetimeoffset](3) NULL,
33
34
  [datetimeoffset_1] [datetimeoffset](1) NULL,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-sqlserver-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.10
4
+ version: 4.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2016-03-20 00:00:00.000000000 Z
17
+ date: 2016-04-24 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord