Module: JdbcSpec::Oracle::Column

Defined in:
lib/jdbc_adapter/jdbc_oracle.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.guess_date_or_time(value) ⇒ Object



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

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

.string_to_time(string, klass) ⇒ Object



69
70
71
72
# File 'lib/jdbc_adapter/jdbc_oracle.rb', line 69

def self.string_to_time(string, klass)
  time = klass.string_to_time(string)
  guess_date_or_time(time)
end

Instance Method Details

#primary=(val) ⇒ Object



45
46
47
48
49
50
# File 'lib/jdbc_adapter/jdbc_oracle.rb', line 45

def primary=(val)
  super
  if val && @sql_type =~ /^NUMBER$/i
    @type = :integer
  end
end

#type_cast(value) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/jdbc_adapter/jdbc_oracle.rb', line 52

def type_cast(value)
  return nil if value.nil?
  case type
  when :datetime then JdbcSpec::Oracle::Column.string_to_time(value, self.class)
  else
    super
  end
end

#type_cast_code(var_name) ⇒ Object



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

def type_cast_code(var_name)
  case type
  when :datetime  then "JdbcSpec::Oracle::Column.string_to_time(#{var_name}, self.class)"
  else
    super
  end
end