Class: ActiveRecord::ConnectionAdapters::ColumnMethods::TableDefinition

Inherits:
TableDefinition
  • Object
show all
Includes:
ActiveRecord::ConnectionAdapters::ColumnMethods
Defined in:
lib/active_record/connection_adapters/ibm_db_adapter.rb

Overview

class TableDefinition

Instance Method Summary collapse

Methods included from ActiveRecord::ConnectionAdapters::ColumnMethods

#primary_key

Constructor Details

#initialize(conn, name, temporary = false, options = nil, as = nil, comment: nil) ⇒ TableDefinition

def initialize(base, name=nil, temporary=nil, options=nil)

if(self.respond_to?(:indexes)) @ar3 = false else @ar3 = true end

@columns = [] @columns_hash = {} @indexes = {} @base = base @temporary = temporary @options = options @name = name @foreign_keys = {} end



584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 584

def initialize(conn, name, temporary = false, options = nil, as = nil, comment: nil)
			@connection = conn
			@columns_hash = {}
			@indexes = []
			@foreign_keys = []
			@primary_keys = nil
			@temporary = temporary
			@options = options
			@as = as
			@name = name
			@comment = comment
			##
			#@base = base
end

Instance Method Details

#bigint(*args) ⇒ Object



648
649
650
651
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 648

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]



654
655
656
657
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 654

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



662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 662

def column(name, type, options ={})
  # construct a column definition where @base is adaptor instance
			column = ColumnDefinition.new(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] 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



633
634
635
636
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 633

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



627
628
629
630
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 627

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

#graphic(*args) ⇒ Object



638
639
640
641
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 638

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

#nativeObject



604
605
606
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 604

def native
			@base.native_database_types
end

#primary_keys(name = nil) ⇒ Object

:nodoc:



599
600
601
602
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 599

def primary_keys(name = nil) # :nodoc:
			@primary_keys = PrimaryKeyDefinition.new(name) if name
			@primary_keys
end

#vargraphic(*args) ⇒ Object



643
644
645
646
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 643

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



621
622
623
624
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 621

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