Class: ActiveRecord::ConnectionAdapters::FbColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/active_record/connection_adapters/fb_adapter.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, domain, type, sub_type, length, precision, scale, default_source, null_flag) ⇒ FbColumn

Returns a new instance of FbColumn.



31
32
33
34
35
36
37
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 31

def initialize(name, domain, type, sub_type, length, precision, scale, default_source, null_flag)
  @firebird_type = Fb::SqlType.from_code(type, sub_type || 0)
  super(name.downcase, nil, @firebird_type, !null_flag)
  @default = parse_default(default_source) if default_source
  @limit = (@firebird_type == 'BLOB') ? 10 * 1024 * 1024 : length
  @domain, @sub_type, @precision, @scale = domain, sub_type, precision, scale
end

Class Method Details

.value_to_boolean(value) ⇒ Object



64
65
66
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 64

def self.value_to_boolean(value)
  %W(#{FbAdapter.boolean_domain[:true]} true t 1).include? value.to_s.downcase
end

Instance Method Details

#defaultObject

Submits a CAST query to the database, casting the default value to the specified SQL type. This enables Firebird to provide an actual value when context variables are used as column defaults (such as CURRENT_TIMESTAMP).



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 52

def default
  if @default
    sql = "SELECT CAST(#{@default} AS #{column_def}) FROM RDB$DATABASE"
    connection = ActiveRecord::Base.connection
    if connection
      type_cast connection.select_one(sql)['cast']
    else
      raise ConnectionNotEstablished, "No Firebird connections established."
    end
  end
end

#typeObject



39
40
41
42
43
44
45
46
47
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 39

def type
  if @domain =~ /BOOLEAN/
    :boolean
  elsif @type == :binary and @sub_type == 1
    :text
  else
    @type
  end
end