Class: ActiveRecord::ConnectionAdapters::FrontBaseColumn

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

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from Column

#default, #limit, #name, #null, #precision, #primary, #scale, #sql_type, #type

Instance Method Summary collapse

Methods inherited from Column

binary_to_string, #human_name, #klass, #number?, string_to_binary, string_to_date, string_to_dummy_time, string_to_time, #text?, value_to_boolean, value_to_decimal

Constructor Details

#initialize(base, name, type, typename, limit, precision, scale, default, nullable) ⇒ FrontBaseColumn

Returns a new instance of FrontBaseColumn.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/active_record/connection_adapters/frontbase_adapter.rb', line 152

def initialize(base, name, type, typename, limit, precision, scale, default, nullable)
  
  @base       = base
  @name       = name
  @type       = simplified_type(type,typename,limit)
  @limit      = limit
  @precision  = precision
  @scale      = scale
  @default    = default
  @null       = nullable == "YES"
  @text       = [:string, :text].include? @type
  @number     = [:float, :integer, :decimal].include? @type
  @fb_autogen = false

  if @default
    @default.gsub!(/^'(.*)'$/,'\1') if @text
    @fb_autogen =  @default.include?("SELECT UNIQUE FROM")
    case @type
    when :boolean 
      @default = @default == "TRUE"
    when :binary
      if @default != "X''"
        buffer = ""
        @default.scan(/../) { |h| buffer << h.hex.chr }
        @default = buffer
      else
        @default = ""
      end
    else
      @default = type_cast(@default)
    end
  end
end

Instance Attribute Details

#fb_autogenObject (readonly)

Returns the value of attribute fb_autogen.



150
151
152
# File 'lib/active_record/connection_adapters/frontbase_adapter.rb', line 150

def fb_autogen
  @fb_autogen
end

Instance Method Details

#type_cast(value) ⇒ Object

Casts value (which is a String) to an appropriate instance.



187
188
189
190
191
192
193
# File 'lib/active_record/connection_adapters/frontbase_adapter.rb', line 187

def type_cast(value)
  if type == :twelvebytekey
    ActiveRecord::ConnectionAdapters::TwelveByteKey.new(value)
  else
    super(value)
  end
end

#type_cast_code(var_name) ⇒ Object



195
196
197
198
199
200
201
# File 'lib/active_record/connection_adapters/frontbase_adapter.rb', line 195

def type_cast_code(var_name)
  if type == :twelvebytekey
    "ActiveRecord::ConnectionAdapters::TwelveByteKey.new(#{var_name})"
  else
    super(var_name)
  end
end