Class: ActiveRecord::ConnectionAdapters::TableDefinition

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

Instance Method Summary collapse

Constructor Details

#initialize(base, name = nil, temporary = nil, options = nil, as = nil) ⇒ TableDefinition

Returns a new instance of TableDefinition.



720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 720

def initialize(base, name=nil, temporary=nil, options=nil, as=nil)
  if(self.respond_to?(:indexes))
    @ar3 = false
  else
    @ar3 = true
  end
  @columns = []
  @columns_hash = {}
  @indexes = {}
  @base = base
  @temporary = temporary
  @options = options
  @name = name
  @as = as
end

Instance Method Details

#bigint(*args) ⇒ Object



780
781
782
783
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 780

def bigint(*args)
  ibm_parse_column_attributes_args('bigint',*args)
  return self
end

#char(*args) ⇒ Object Also known as: character

Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type char [character]



786
787
788
789
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 786

def char(*args)
  ibm_parse_column_attributes_args('char',*args)
  return self
end

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

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



794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 794

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

  # 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] if @base.native_database_types[type.to_sym].has_key? :limit
  end

  unless @columns.nil? or @columns.include? column
    @columns << column 
  end

  @columns_hash[name] = column

  return self
end

#decfloat(*args) ⇒ Object

Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type decfloat



765
766
767
768
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 765

def decfloat(*args)
  ibm_parse_column_attributes_args('decfloat',*args)
  return self
end

#double(*args) ⇒ Object

Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type double



759
760
761
762
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 759

def double(*args)
  ibm_parse_column_attributes_args('double',*args)
  return self
end

#graphic(*args) ⇒ Object



770
771
772
773
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 770

def graphic(*args)
  ibm_parse_column_attributes_args('graphic',*args)
  return self
end

#nativeObject



736
737
738
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 736

def native
  @base.native_database_types
end

#vargraphic(*args) ⇒ Object



775
776
777
778
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 775

def vargraphic(*args)
  ibm_parse_column_attributes_args('vargraphic',*args)
  return self
end

#xml(*args) ⇒ Object

Method to support the new syntax of rails 2.0 migrations for columns of type xml



753
754
755
756
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 753

def xml(*args )
  ibm_parse_column_attributes_args('xml', *args)
  return self
end