class ActiveRecord::ConnectionAdapters::SQLite3Column

Public Class Methods

binary_to_string(value) click to toggle source
# File lib/arjdbc/sqlite3/adapter.rb, line 580
def self.binary_to_string(value)
  if value.respond_to?(:encoding) && value.encoding != Encoding::ASCII_8BIT
    value = value.force_encoding(Encoding::ASCII_8BIT)
  end
  value
end
new(name, *args) click to toggle source
# File lib/arjdbc/sqlite3/adapter.rb, line 568
def initialize(name, *args)
  if Hash === name
    super
  else
    super(nil, name, *args)
  end
end
string_to_binary(value) click to toggle source
# File lib/arjdbc/sqlite3/adapter.rb, line 576
def self.string_to_binary(value)
  value
end

Public Instance Methods

default_value(value) click to toggle source

@override {ActiveRecord::ConnectionAdapters::JdbcColumn#default_value}

# File lib/arjdbc/sqlite3/adapter.rb, line 597
def default_value(value)
  # JDBC returns column default strings with actual single quotes :
  return $1 if value =~ /^'(.*)'$/

  value
end
init_column(name, default, *args) click to toggle source

@override {ActiveRecord::ConnectionAdapters::JdbcColumn#init_column}

# File lib/arjdbc/sqlite3/adapter.rb, line 588
def init_column(name, default, *args)
  if default =~ /NULL/
    @default = nil
  else
    super
  end
end
type_cast(value) click to toggle source

@override {ActiveRecord::ConnectionAdapters::Column#type_cast}

Calls superclass method
# File lib/arjdbc/sqlite3/adapter.rb, line 605
def type_cast(value)
  return nil if value.nil?
  case type
    when :string then value
    when :primary_key
      value.respond_to?(:to_i) ? value.to_i : ( value ? 1 : 0 )
    when :float    then value.to_f
    when :decimal  then self.class.value_to_decimal(value)
    when :boolean  then self.class.value_to_boolean(value)
    else super
  end
end

Private Instance Methods

extract_limit(sql_type) click to toggle source

@override {ActiveRecord::ConnectionAdapters::Column#extract_limit}

Calls superclass method
# File lib/arjdbc/sqlite3/adapter.rb, line 639
def extract_limit(sql_type)
  return nil if sql_type =~ /^(real)\(\d+/i
  super
end
extract_precision(sql_type) click to toggle source
Calls superclass method
# File lib/arjdbc/sqlite3/adapter.rb, line 644
def extract_precision(sql_type)
  case sql_type
    when /^(real)\((\d+)(,\d+)?\)/i then $2.to_i
    else super
  end
end
extract_scale(sql_type) click to toggle source
Calls superclass method
# File lib/arjdbc/sqlite3/adapter.rb, line 651
def extract_scale(sql_type)
  case sql_type
    when /^(real)\((\d+)\)/i then 0
    when /^(real)\((\d+)(,(\d+))\)/i then $4.to_i
    else super
  end
end
simplified_type(field_type) click to toggle source

@override {ActiveRecord::ConnectionAdapters::Column#simplified_type}

Calls superclass method
# File lib/arjdbc/sqlite3/adapter.rb, line 621
def simplified_type(field_type)
  case field_type
    when /boolean/i       then :boolean
    when /text/i          then :text
    when /varchar/i       then :string
    when /int/i           then :integer
    when /float/i         then :float
    when /real|decimal/i  then
      extract_scale(field_type) == 0 ? :integer : :decimal
    when /datetime/i      then :datetime
    when /date/i          then :date
    when /time/i          then :time
    when /blob/i          then :binary
    else super
  end
end