Class: IBRuby::InterBaseConstraint
- Inherits:
-
Object
- Object
- IBRuby::InterBaseConstraint
- Defined in:
- lib/ibmeta.rb
Constant Summary collapse
- PRIMARY_KEY =
:PRIMARY_KEY
- FOREIGN_KEY =
:FOREIGN_KEY
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#foreign_cols ⇒ Object
Returns the value of attribute foreign_cols.
-
#foreign_table_name ⇒ Object
Returns the value of attribute foreign_table_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#table ⇒ Object
Returns the value of attribute table.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, columns, foreign_cols = nil, foreign_table_name = nil, name = nil) ⇒ InterBaseConstraint
constructor
columns are strings only, not complete columns.
- #to_sql ⇒ Object
Constructor Details
#initialize(type, columns, foreign_cols = nil, foreign_table_name = nil, name = nil) ⇒ InterBaseConstraint
columns are strings only, not complete columns. if they are complete columns then we just get their name
106 107 108 109 110 111 112 113 114 |
# File 'lib/ibmeta.rb', line 106 def initialize(type, columns, foreign_cols=nil, foreign_table_name=nil, name=nil) @name = name @type = type @columns = columns @foreign_cols=foreign_cols @foreign_table_name=foreign_table_name #puts "constraint created #{to_sql}" end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
99 100 101 |
# File 'lib/ibmeta.rb', line 99 def columns @columns end |
#foreign_cols ⇒ Object
Returns the value of attribute foreign_cols.
99 100 101 |
# File 'lib/ibmeta.rb', line 99 def foreign_cols @foreign_cols end |
#foreign_table_name ⇒ Object
Returns the value of attribute foreign_table_name.
99 100 101 |
# File 'lib/ibmeta.rb', line 99 def foreign_table_name @foreign_table_name end |
#name ⇒ Object
Returns the value of attribute name.
99 100 101 |
# File 'lib/ibmeta.rb', line 99 def name @name end |
#table ⇒ Object
Returns the value of attribute table.
99 100 101 |
# File 'lib/ibmeta.rb', line 99 def table @table end |
#type ⇒ Object
Returns the value of attribute type.
99 100 101 |
# File 'lib/ibmeta.rb', line 99 def type @type end |
Instance Method Details
#to_sql ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ibmeta.rb', line 116 def to_sql tab_name = table.nil? ? "NULL" : table.name sql = "alter table #{tab_name} add " if @type == :PRIMARY_KEY sql << "primary key (" sql << cycle_cols sql << ")" elsif @type == :FOREIGN_KEY sql << "foreign key (" sql << cycle_cols sql << ") references #{foreign_table_name} (" sql << cycle_cols(foreign_cols) sql << ")" else raise NotImplementedError, "Other constraints #{@type.to_s} not implemented yet" end end |