Module: ArJdbc::DB2::Column
- Included in:
- ActiveRecord::ConnectionAdapters::DB2Adapter, ActiveRecord::ConnectionAdapters::DB2Column
- Defined in:
- lib/arjdbc/db2/column.rb
Overview
Defined Under Namespace
Modules: Cast
Class Method Summary collapse
-
.cast_to_date_or_time(value) ⇒ Object
deprecated
Deprecated.
use
self.class.string_to_time
-
.cast_to_time(value) ⇒ Object
deprecated
Deprecated.
use
self.class.string_to_time
orself.class.string_to_dummy_time
Instance Method Summary collapse
Class Method Details
.cast_to_date_or_time(value) ⇒ Object
Deprecated.
use self.class.string_to_time
19 20 21 22 23 24 25 26 27 |
# File 'lib/arjdbc/db2/column.rb', line 19 def self.cast_to_date_or_time(value) return value if value.is_a? Date return nil if value.blank? # https://github.com/jruby/activerecord-jdbc-adapter/commit/c225126e025df2e98ba3386c67e2a5bc5e5a73e6 return Time.now if value =~ /^CURRENT/ guess_date_or_time((value.is_a? Time) ? value : cast_to_time(value)) rescue value end |
.cast_to_time(value) ⇒ Object
Deprecated.
use self.class.string_to_time
or self.class.string_to_dummy_time
30 31 32 33 34 35 36 37 38 |
# File 'lib/arjdbc/db2/column.rb', line 30 def self.cast_to_time(value) return value if value.is_a? Time # AS400 returns a 2 digit year, LUW returns a 4 digit year time = DateTime.parse(value).to_time rescue nil return nil unless time time_array = [time.year, time.month, time.day, time.hour, time.min, time.sec] time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1; Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil end |
Instance Method Details
#type_cast(value) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/arjdbc/db2/column.rb', line 49 def type_cast(value) # AR5.2 return super unless respond_to?(:type) return nil if value.nil? || value == 'NULL' || value =~ /^\s*NULL\s*$/i case type when :string then value when :integer then value.respond_to?(:to_i) ? value.to_i : (value ? 1 : 0) when :primary_key then value.respond_to?(:to_i) ? value.to_i : (value ? 1 : 0) when :float then value.to_f when :date then self.class.string_to_date(value) when :datetime then self.class.string_to_time(value) when :timestamp then self.class.string_to_time(value) when :time then self.class.string_to_dummy_time(value) # TODO AS400 stores binary strings in EBCDIC (CCSID 65535), need to convert back to ASCII else super end end |
#type_cast_code(var_name) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/arjdbc/db2/column.rb', line 70 def type_cast_code(var_name) case type when :date then "#{self.class.name}.string_to_date(#{var_name})" when :datetime then "#{self.class.name}.string_to_time(#{var_name})" when :timestamp then "#{self.class.name}.string_to_time(#{var_name})" when :time then "#{self.class.name}.string_to_dummy_time(#{var_name})" else super end end |