Class: ActiveRecord::ConnectionAdapters::TableDefinition

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

Overview

class IBM_DBColumn

Instance Method Summary collapse

Instance Method Details

#column(name, type, options = {}) ⇒ Object

Overrides the abstract adapter in order to handle the DEFAULT option for the native XML datat type



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 232

def column(name, type, options ={})
  # construct a column definition where @base is adaptor instance
  column = ColumnDefinition.new(@base, name, type)

  # DB2 does not accept DEFAULT NULL option for XML
  # for table create, but does accept nullable option
  unless type.to_s == 'xml'
    column.null    = options[:null]
    column.default = options[:default]
  else
    column.null    = options[:null]
    # Override column object's (instance of ColumnDefinition structure)
    # to_s which is expected to return the create_table SQL fragment
    # and bypass DEFAULT NULL option while still appending NOT NULL
    def column.to_s
      sql = "#{base.quote_column_name(name)} #{type}"
      unless self.null == nil
        sql << " NOT NULL" if (self.null == false)
      end
      return sql
    end
  end

  column.scale     = options[:scale]      if options[:scale]
  column.precision = options[:precision]  if options[:precision]
  # append column's limit option and yield native limits
  if options[:limit]
    column.limit   = options[:limit]
  elsif @base.native_database_types[type.to_sym]
    column.limit   = @base.native_database_types[type.to_sym][:limit]
  end

  unless @columns.include? column
    @columns << column 
  end
  return self
end