Module: JdbcSpec::Derby::Column

Defined in:
lib/jdbc_adapter/jdbc_derby.rb

Instance Method Summary collapse

Instance Method Details

#cast_to_date_or_time(value) ⇒ Object



55
56
57
58
59
# File 'lib/jdbc_adapter/jdbc_derby.rb', line 55

def cast_to_date_or_time(value)
  return value if value.is_a? Date
  return nil if value.blank?
  guess_date_or_time (value.is_a? Time) ? value : cast_to_time(value)
end

#cast_to_time(value) ⇒ Object



61
62
63
64
65
66
# File 'lib/jdbc_adapter/jdbc_derby.rb', line 61

def cast_to_time(value)
  return value if value.is_a? Time
  time_array = ParseDate.parsedate value
  time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
  Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
end

#guess_date_or_time(value) ⇒ Object



68
69
70
71
# File 'lib/jdbc_adapter/jdbc_derby.rb', line 68

def guess_date_or_time(value)
  (value.hour == 0 and value.min == 0 and value.sec == 0) ?
  Date.new(value.year, value.month, value.day) : value
end

#simplified_type(field_type) ⇒ Object



73
74
75
76
77
# File 'lib/jdbc_adapter/jdbc_derby.rb', line 73

def simplified_type(field_type)
  return :boolean if field_type =~ /smallint/i 
  return :float if field_type =~ /real/i
  super
end

#value_to_binary(value) ⇒ Object



51
52
53
# File 'lib/jdbc_adapter/jdbc_derby.rb', line 51

def value_to_binary(value)
  value.scan(/[0-9A-Fa-f]{2}/).collect {|v| v.to_i(16)}.pack("C*")
end