activerecord-jdbc-adapter 1.3.12 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e7fd59bd6f8be3d2d0da36e413324eea6539846
4
- data.tar.gz: ca2bb40471a4076ead3ee9476c5edbd53b63a06e
3
+ metadata.gz: 93ba4c816887c15797f7e73007e1a9c74bcc29f9
4
+ data.tar.gz: ac03282ee4b9e14b0f97fac01ce010cb0a91dcf3
5
5
  SHA512:
6
- metadata.gz: e14b3b99f73a202f4b494f79ee11af3440965a706c3d6e335292d184c3ea2bbf5166e0a2ba8f59a03ceffb8a40bc98eaa54f23448f40c18c7f1b0ae58e988e65
7
- data.tar.gz: 2833ecd5d304e9d99b80d8efd7e7e2be0061d3fef2db16eee749986602a8b361cbe293453c139426cf51034989c3e388b0c0fd564581178143d196cb25ee0aab
6
+ metadata.gz: 6ca18d9e975df305173bd10256e85eb4d213b0d11d518117d9c7b5ea50997c16c6bacf2155b162270ba01ab8a5d83b4adf92b12ea1a0e1def83f14dfafdbd3d3
7
+ data.tar.gz: d586f6ffc1fd69c843f5e7a6f2b0f2bb48f8b0329a090edbcb9c3101a28feac9548f3c6da95e001d92f3817bef71c33cd09f590fdfd1b0c42cfe73b354f64bdd
data/History.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.3.13 (11/21/14)
2
+
3
+ - handle ("hacked") date/time/timestamp conversion from the JDBC side on 4.2
4
+ - align SQLite's column class resolution with others in 1.3
5
+ - avoid the Column regressions in 1.3.12 caused by backporting too much (#603)
6
+
1
7
  ## 1.3.12 (11/18/14)
2
8
 
3
9
  - [sqlite] support for latest JDBC 3.8
@@ -20,9 +20,6 @@ module ArJdbc
20
20
  [ /as400/i, lambda { |config, column| column.extend(Column) } ]
21
21
  end
22
22
 
23
- # @private
24
- Column = DB2::Column
25
-
26
23
  # Boolean emulation can be disabled using :
27
24
  #
28
25
  # ArJdbc::AS400.emulate_booleans = false
@@ -873,27 +873,65 @@ module ActiveRecord
873
873
 
874
874
  # @note Used by Java API to convert dates from (custom) SELECTs (might get refactored).
875
875
  # @private
876
- def _string_to_date(value)
877
- jdbc_column_class.string_to_date(value)
878
- end
876
+ def _string_to_date(value); jdbc_column_class.string_to_date(value) end
879
877
 
880
878
  # @note Used by Java API to convert times from (custom) SELECTs (might get refactored).
881
879
  # @private
882
- def _string_to_time(value)
883
- jdbc_column_class.string_to_dummy_time(value)
884
- end
880
+ def _string_to_time(value); jdbc_column_class.string_to_dummy_time(value) end
885
881
 
886
882
  # @note Used by Java API to convert times from (custom) SELECTs (might get refactored).
887
883
  # @private
888
- def _string_to_timestamp(value)
889
- jdbc_column_class.string_to_time(value)
884
+ def _string_to_timestamp(value); jdbc_column_class.string_to_time(value) end
885
+
886
+ if ActiveRecord::VERSION::STRING > '4.2'
887
+
888
+ # @private
889
+ @@_date = nil
890
+
891
+ # @private
892
+ def _string_to_date(value)
893
+ if jdbc_column_class.respond_to?(:string_to_date)
894
+ jdbc_column_class.string_to_date(value)
895
+ else
896
+ (@@_date ||= ActiveRecord::Type::Date.new).send(:cast_value, value)
897
+ end
898
+ end
899
+
900
+ # @private
901
+ @@_time = nil
902
+
903
+ # @private
904
+ def _string_to_time(value)
905
+ if jdbc_column_class.respond_to?(:string_to_dummy_time)
906
+ jdbc_column_class.string_to_dummy_time(value)
907
+ else
908
+ (@@_time ||= ActiveRecord::Type::Time.new).send(:cast_value, value)
909
+ end
910
+ end
911
+
912
+ # @private
913
+ @@_date_time = nil
914
+
915
+ # @private
916
+ def _string_to_timestamp(value)
917
+ if jdbc_column_class.respond_to?(:string_to_time)
918
+ jdbc_column_class.string_to_time(value)
919
+ else
920
+ (@@_date_time ||= ActiveRecord::Type::DateTime.new).send(:cast_value, value)
921
+ end
922
+ end
923
+
890
924
  end
891
925
 
926
+
892
927
  if ActiveRecord::VERSION::MAJOR < 4 # emulating Rails 3.x compatibility
893
928
  JdbcConnection.raw_date_time = true if JdbcConnection.raw_date_time? == nil
894
929
  JdbcConnection.raw_boolean = true if JdbcConnection.raw_boolean? == nil
895
930
  end
896
931
 
897
932
  end
933
+ module Jdbc
934
+ autoload :TypeCast, 'arjdbc/jdbc/type_cast'
935
+ end
898
936
  end
899
937
  end
@@ -61,7 +61,7 @@ module ActiveRecord
61
61
 
62
62
  class << self
63
63
 
64
- if ActiveRecord::VERSION::MAJOR > 3
64
+ if ActiveRecord::VERSION::MAJOR > 3 && ActiveRecord::VERSION::STRING < '4.2'
65
65
 
66
66
  # @private provides compatibility between AR 3.x/4.0 API
67
67
  def string_to_date(value); value_to_date(value) end
@@ -0,0 +1,140 @@
1
+ module ActiveRecord::ConnectionAdapters
2
+ module Jdbc
3
+ # Type casting methods taken from AR 4.1's Column class.
4
+ # @private Simply to quickly "hack-in" 4.2 compatibility.
5
+ module TypeCast
6
+
7
+ TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set
8
+ FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set
9
+
10
+ #module Format
11
+ ISO_DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/
12
+ ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
13
+ #end
14
+
15
+ # Used to convert from BLOBs to Strings
16
+ def binary_to_string(value)
17
+ value
18
+ end
19
+
20
+ def value_to_date(value)
21
+ if value.is_a?(String)
22
+ return nil if value.empty?
23
+ fast_string_to_date(value) || fallback_string_to_date(value)
24
+ elsif value.respond_to?(:to_date)
25
+ value.to_date
26
+ else
27
+ value
28
+ end
29
+ end
30
+
31
+ def string_to_time(string)
32
+ return string unless string.is_a?(String)
33
+ return nil if string.empty?
34
+
35
+ fast_string_to_time(string) || fallback_string_to_time(string)
36
+ end
37
+
38
+ def string_to_dummy_time(string)
39
+ return string unless string.is_a?(String)
40
+ return nil if string.empty?
41
+
42
+ dummy_time_string = "2000-01-01 #{string}"
43
+
44
+ fast_string_to_time(dummy_time_string) || begin
45
+ time_hash = Date._parse(dummy_time_string)
46
+ return nil if time_hash[:hour].nil?
47
+ new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction))
48
+ end
49
+ end
50
+
51
+ # convert something to a boolean
52
+ def value_to_boolean(value)
53
+ if value.is_a?(String) && value.empty?
54
+ nil
55
+ else
56
+ TRUE_VALUES.include?(value)
57
+ end
58
+ end
59
+
60
+ # Used to convert values to integer.
61
+ # handle the case when an integer column is used to store boolean values
62
+ def value_to_integer(value)
63
+ case value
64
+ when TrueClass, FalseClass
65
+ value ? 1 : 0
66
+ else
67
+ value.to_i rescue nil
68
+ end
69
+ end
70
+
71
+ # convert something to a BigDecimal
72
+ def value_to_decimal(value)
73
+ # Using .class is faster than .is_a? and
74
+ # subclasses of BigDecimal will be handled
75
+ # in the else clause
76
+ if value.class == BigDecimal
77
+ value
78
+ elsif value.respond_to?(:to_d)
79
+ value.to_d
80
+ else
81
+ value.to_s.to_d
82
+ end
83
+ end
84
+
85
+ protected
86
+ # '0.123456' -> 123456
87
+ # '1.123456' -> 123456
88
+ def microseconds(time)
89
+ time[:sec_fraction] ? (time[:sec_fraction] * 1_000_000).to_i : 0
90
+ end
91
+
92
+ def new_date(year, mon, mday)
93
+ if year && year != 0
94
+ Date.new(year, mon, mday) rescue nil
95
+ end
96
+ end
97
+
98
+ def new_time(year, mon, mday, hour, min, sec, microsec, offset = nil)
99
+ # Treat 0000-00-00 00:00:00 as nil.
100
+ return nil if year.nil? || (year == 0 && mon == 0 && mday == 0)
101
+
102
+ if offset
103
+ time = Time.utc(year, mon, mday, hour, min, sec, microsec) rescue nil
104
+ return nil unless time
105
+
106
+ time -= offset
107
+ Base.default_timezone == :utc ? time : time.getlocal
108
+ else
109
+ Time.public_send(Base.default_timezone, year, mon, mday, hour, min, sec, microsec) rescue nil
110
+ end
111
+ end
112
+
113
+ def fast_string_to_date(string)
114
+ if string =~ ISO_DATE
115
+ new_date $1.to_i, $2.to_i, $3.to_i
116
+ end
117
+ end
118
+
119
+ # Doesn't handle time zones.
120
+ def fast_string_to_time(string)
121
+ if string =~ ISO_DATETIME
122
+ microsec = ($7.to_r * 1_000_000).to_i
123
+ new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec
124
+ end
125
+ end
126
+
127
+ def fallback_string_to_date(string)
128
+ new_date(*::Date._parse(string, false).values_at(:year, :mon, :mday))
129
+ end
130
+
131
+ def fallback_string_to_time(string)
132
+ time_hash = Date._parse(string)
133
+ time_hash[:sec_fraction] = microseconds(time_hash)
134
+
135
+ new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction, :offset))
136
+ end
137
+
138
+ end
139
+ end
140
+ end
@@ -61,7 +61,7 @@ module ArJdbc
61
61
  end
62
62
 
63
63
  # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
64
- def jdbc_column_class; Column end
64
+ def jdbc_column_class; ::ActiveRecord::ConnectionAdapters::MSSQLColumn end
65
65
 
66
66
  # @see ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport
67
67
  def self.arel_visitor_type(config)
@@ -738,9 +738,3 @@ module ActiveRecord::ConnectionAdapters
738
738
  end
739
739
 
740
740
  end
741
-
742
- module ArJdbc
743
- module MSSQL
744
- Column = ::ActiveRecord::ConnectionAdapters::MSSQLColumn
745
- end
746
- end
@@ -21,6 +21,10 @@ module ArJdbc
21
21
  ::ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
22
22
  end
23
23
 
24
+ def jdbc_column_class
25
+ ::ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
26
+ end
27
+
24
28
  # @private
25
29
  def init_connection(jdbc_connection)
26
30
  meta = jdbc_connection.meta_data
@@ -168,12 +172,12 @@ module ArJdbc
168
172
 
169
173
  # @private Only for Rails core compatibility.
170
174
  def new_column(field, default, type, null, collation, extra = "")
171
- Column.new(field, default, type, null, collation, strict_mode?, extra)
175
+ jdbc_column_class.new(field, default, type, null, collation, strict_mode?, extra)
172
176
  end unless AR42
173
177
 
174
178
  # @private Only for Rails core compatibility.
175
179
  def new_column(field, default, cast_type, sql_type = nil, null = true, collation = "", extra = "")
176
- Column.new(field, default, cast_type, sql_type, null, collation, strict_mode?, extra)
180
+ jdbc_column_class.new(field, default, cast_type, sql_type, null, collation, strict_mode?, extra)
177
181
  end if AR42
178
182
 
179
183
  # @private Only for Rails core compatibility.
@@ -378,9 +382,9 @@ module ArJdbc
378
382
  null = field['Null'] == "YES"
379
383
  if pass_cast_type
380
384
  cast_type = lookup_cast_type(sql_type)
381
- Column.new(field['Field'], field['Default'], cast_type, sql_type, null, field['Collation'], strict, field['Extra'])
385
+ jdbc_column_class.new(field['Field'], field['Default'], cast_type, sql_type, null, field['Collation'], strict, field['Extra'])
382
386
  else
383
- Column.new(field['Field'], field['Default'], sql_type, null, field['Collation'], strict, field['Extra'])
387
+ jdbc_column_class.new(field['Field'], field['Default'], sql_type, null, field['Collation'], strict, field['Extra'])
384
388
  end
385
389
  end
386
390
  columns
@@ -745,9 +749,3 @@ module ActiveRecord
745
749
 
746
750
  end
747
751
  end
748
-
749
- module ArJdbc
750
- module MySQL
751
- Column = ::ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
752
- end
753
- end
@@ -31,7 +31,7 @@ module ArJdbc
31
31
  end
32
32
 
33
33
  # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
34
- def jdbc_column_class; Column end
34
+ def jdbc_column_class; ::ActiveRecord::ConnectionAdapters::OracleColumn end
35
35
 
36
36
  # @private
37
37
  @@update_lob_values = true
@@ -683,9 +683,3 @@ module ActiveRecord::ConnectionAdapters
683
683
  end
684
684
 
685
685
  end
686
-
687
- module ArJdbc
688
- module Oracle
689
- Column = ::ActiveRecord::ConnectionAdapters::OracleColumn
690
- end
691
- end
@@ -21,6 +21,9 @@ module ArJdbc
21
21
  ::ActiveRecord::ConnectionAdapters::PostgreSQLJdbcConnection
22
22
  end
23
23
 
24
+ # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
25
+ def jdbc_column_class; ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn end
26
+
24
27
  # @private
25
28
  def init_connection(jdbc_connection)
26
29
  meta = jdbc_connection.meta_data
@@ -159,12 +162,12 @@ module ArJdbc
159
162
  when Array
160
163
  case column.sql_type
161
164
  when 'point'
162
- Column.point_to_string(value)
165
+ jdbc_column_class.point_to_string(value)
163
166
  when 'json'
164
- Column.json_to_string(value)
167
+ jdbc_column_class.json_to_string(value)
165
168
  else
166
169
  return super(value, column) unless column.array?
167
- Column.array_to_string(value, column, self)
170
+ jdbc_column_class.array_to_string(value, column, self)
168
171
  end
169
172
  when NilClass
170
173
  if column.array? && array_member
@@ -177,17 +180,17 @@ module ArJdbc
177
180
  when Hash
178
181
  case column.sql_type
179
182
  when 'hstore'
180
- Column.hstore_to_string(value)
183
+ jdbc_column_class.hstore_to_string(value)
181
184
  when 'json'
182
- Column.json_to_string(value)
185
+ jdbc_column_class.json_to_string(value)
183
186
  else super(value, column)
184
187
  end
185
188
  when IPAddr
186
189
  return super unless column.sql_type == 'inet' || column.sql_type == 'cidr'
187
- Column.cidr_to_string(value)
190
+ jdbc_column_class.cidr_to_string(value)
188
191
  when Range
189
192
  return super(value, column) unless /range$/ =~ column.sql_type
190
- Column.range_to_string(value)
193
+ jdbc_column_class.range_to_string(value)
191
194
  else
192
195
  super(value, column)
193
196
  end
@@ -826,30 +829,30 @@ module ArJdbc
826
829
  sql_type && sql_type[0, 3] == 'bit' ? quote_bit(value) : super
827
830
  when Array
828
831
  if AR4_COMPAT && column.array? # will be always falsy in AR < 4.0
829
- "'#{Column.array_to_string(value, column, self).gsub(/'/, "''")}'"
832
+ "'#{jdbc_column_class.array_to_string(value, column, self).gsub(/'/, "''")}'"
830
833
  elsif column.type == :json # only in AR-4.0
831
- super(Column.json_to_string(value), column)
834
+ super(jdbc_column_class.json_to_string(value), column)
832
835
  elsif column.type == :point # only in AR-4.0
833
- super(Column.point_to_string(value), column)
836
+ super(jdbc_column_class.point_to_string(value), column)
834
837
  else super
835
838
  end
836
839
  when Hash
837
840
  if column.type == :hstore # only in AR-4.0
838
- super(Column.hstore_to_string(value), column)
841
+ super(jdbc_column_class.hstore_to_string(value), column)
839
842
  elsif column.type == :json # only in AR-4.0
840
- super(Column.json_to_string(value), column)
843
+ super(jdbc_column_class.json_to_string(value), column)
841
844
  else super
842
845
  end
843
846
  when Range
844
847
  sql_type = column.respond_to?(:sql_type) && column.sql_type
845
848
  if sql_type && sql_type[-5, 5] == 'range' && AR4_COMPAT
846
- escaped = quote_string(Column.range_to_string(value))
849
+ escaped = quote_string(jdbc_column_class.range_to_string(value))
847
850
  "'#{escaped}'::#{sql_type}"
848
851
  else super
849
852
  end
850
853
  when IPAddr
851
854
  if column.type == :inet || column.type == :cidr # only in AR-4.0
852
- super(Column.cidr_to_string(value), column)
855
+ super(jdbc_column_class.cidr_to_string(value), column)
853
856
  else super
854
857
  end
855
858
  else
@@ -1079,6 +1082,7 @@ module ArJdbc
1079
1082
 
1080
1083
  # Returns the list of all column definitions for a table.
1081
1084
  def columns(table_name, name = nil)
1085
+ column = jdbc_column_class
1082
1086
  pass_cast_type = respond_to?(:lookup_cast_type)
1083
1087
  column_definitions(table_name).map do |row|
1084
1088
  # name, type, default, notnull, oid, fmod
@@ -1095,9 +1099,9 @@ module ArJdbc
1095
1099
  end
1096
1100
  if pass_cast_type
1097
1101
  cast_type = lookup_cast_type(type)
1098
- Column.new(name, default, cast_type, type, ! notnull, fmod, self)
1102
+ column.new(name, default, cast_type, type, ! notnull, fmod, self)
1099
1103
  else
1100
- Column.new(name, default, oid, type, ! notnull, fmod, self)
1104
+ column.new(name, default, oid, type, ! notnull, fmod, self)
1101
1105
  end
1102
1106
  end
1103
1107
  end
@@ -1483,11 +1487,6 @@ module ActiveRecord::ConnectionAdapters
1483
1487
  ::ArJdbc::PostgreSQL.jdbc_connection_class
1484
1488
  end
1485
1489
 
1486
- # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
1487
- def jdbc_column_class
1488
- ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn
1489
- end
1490
-
1491
1490
  if ::ActiveRecord::VERSION::MAJOR < 4 # Rails 3.x compatibility
1492
1491
  PostgreSQLJdbcConnection.raw_array_type = true if PostgreSQLJdbcConnection.raw_array_type? == nil
1493
1492
  PostgreSQLJdbcConnection.raw_hstore_type = true if PostgreSQLJdbcConnection.raw_hstore_type? == nil
@@ -1495,9 +1494,3 @@ module ActiveRecord::ConnectionAdapters
1495
1494
 
1496
1495
  end
1497
1496
  end
1498
-
1499
- module ArJdbc
1500
- module PostgreSQL
1501
- Column = ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn
1502
- end
1503
- end
@@ -28,6 +28,7 @@ module ArJdbc
28
28
  include ActiveRecord::ConnectionAdapters::PostgreSQL::ArrayParser
29
29
  end if AR4_COMPAT
30
30
 
31
+ include ActiveRecord::ConnectionAdapters::Jdbc::TypeCast if AR42_COMPAT
31
32
  include Cast
32
33
 
33
34
  end
@@ -12,6 +12,8 @@ module ArJdbc
12
12
  ::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
13
13
  end
14
14
 
15
+ def jdbc_column_class; ::ActiveRecord::ConnectionAdapters::SQLite3Column end
16
+
15
17
  # @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
16
18
  def self.column_selector
17
19
  [ /sqlite/i, lambda { |config, column| column.extend(Column) } ]
@@ -348,15 +350,15 @@ module ArJdbc
348
350
 
349
351
  # @override
350
352
  def columns(table_name, name = nil)
351
- klass = ::ActiveRecord::ConnectionAdapters::SQLite3Column
353
+ column = jdbc_column_class
352
354
  pass_cast_type = respond_to?(:lookup_cast_type)
353
355
  table_structure(table_name).map do |field|
354
356
  sql_type = field['type']
355
357
  if pass_cast_type
356
358
  cast_type = lookup_cast_type(sql_type)
357
- klass.new(field['name'], field['dflt_value'], cast_type, sql_type, field['notnull'] == 0)
359
+ column.new(field['name'], field['dflt_value'], cast_type, sql_type, field['notnull'] == 0)
358
360
  else
359
- klass.new(field['name'], field['dflt_value'], sql_type, field['notnull'] == 0)
361
+ column.new(field['name'], field['dflt_value'], sql_type, field['notnull'] == 0)
360
362
  end
361
363
  end
362
364
  end
@@ -592,10 +594,6 @@ module ActiveRecord::ConnectionAdapters
592
594
  ::ArJdbc::SQLite3.jdbc_connection_class
593
595
  end
594
596
 
595
- def jdbc_column_class
596
- ::ActiveRecord::ConnectionAdapters::SQLite3Column
597
- end
598
-
599
597
  # @private
600
598
  Version = ArJdbc::SQLite3::Version
601
599
 
@@ -1,5 +1,5 @@
1
1
  module ArJdbc
2
- VERSION = "1.3.12"
2
+ VERSION = "1.3.13"
3
3
  # @deprecated
4
4
  module Version
5
5
  # @private 1.2.x compatibility
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-jdbc-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.12
4
+ version: 1.3.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sieger, Ola Bini, Karol Bucek and JRuby contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -120,6 +120,7 @@ files:
120
120
  - lib/arjdbc/jdbc/railtie.rb
121
121
  - lib/arjdbc/jdbc/rake_tasks.rb
122
122
  - lib/arjdbc/jdbc/serialized_attributes_helper.rb
123
+ - lib/arjdbc/jdbc/type_cast.rb
123
124
  - lib/arjdbc/jdbc/type_converter.rb
124
125
  - lib/arjdbc/mimer.rb
125
126
  - lib/arjdbc/mimer/adapter.rb