Module: ArJdbc::SybaseSQLAnywhere::Column

Defined in:
lib/arjdbc/sqlanywhere/adapter.rb

Instance Method Summary collapse

Instance Method Details

#default_value(value) ⇒ Object

Post process default value from JDBC into a Rails-friendly format (columns-internal)



17
18
19
20
21
22
# File 'lib/arjdbc/sqlanywhere/adapter.rb', line 17

def default_value(value)
  # jdbc returns column default strings with actual single quotes around the value.
  return $1 if value =~ /^'(.*)'$/

  value
end

#init_column(name, default, *args) ⇒ Object



12
13
14
# File 'lib/arjdbc/sqlanywhere/adapter.rb', line 12

def init_column(name, default, *args)
  @name = name.downcase
end

#simplified_type(field_type) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/arjdbc/sqlanywhere/adapter.rb', line 24

def simplified_type(field_type)
  case field_type
  when /int|bigint|smallint|tinyint/i                        then :integer
  when /numeric/i                                            then (@scale.nil? || @scale == 0) ? :integer : :decimal
  when /float|double|decimal|money|real|smallmoney/i         then :decimal
  when /datetime|smalldatetime/i                             then :datetime
  when /timestamp/i                                          then :timestamp
  when /time/i                                               then :time
  when /date/i                                               then :date
  when /text|ntext|xml/i                                     then :text
  when /binary|image|varbinary/i                             then :binary
  when /char|nchar|nvarchar|string|varchar/i                 then (@limit == 1073741823 ? (@limit = nil; :text) : :string)
  when /bit/i                                                then :boolean
  when /uniqueidentifier/i                                   then :string
  end
end

#type_cast(value) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/arjdbc/sqlanywhere/adapter.rb', line 41

def type_cast(value)
  return nil if value.nil? || value == "(null)" || value == "(NULL)"
  case type
  when :primary_key then value == true || value == false ? value == true ? 1 : 0 : value.to_i
  when :boolean   then value == true or (value =~ /^t(rue)?$/i) == 0 or value=="1"
  else
    super
  end
end