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.



76
77
78
79
80
81
82
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 76

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



114
115
116
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 114

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).



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 97

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

#typeObject



84
85
86
87
88
89
90
91
92
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 84

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