Class: Mkxms::Mssql::Table
- Inherits:
-
Object
- Object
- Mkxms::Mssql::Table
- Defined in:
- lib/mkxms/mssql/table_handler.rb
Constant Summary collapse
- SQL_OBJECT_TYPE =
'TABLE'
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#heap_storage ⇒ Object
Returns the value of attribute heap_storage.
-
#lob_storage ⇒ Object
Returns the value of attribute lob_storage.
-
#name ⇒ Object
Returns the value of attribute name.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(schema, name) ⇒ Table
constructor
A new instance of Table.
- #to_sql ⇒ Object
Methods included from ExtendedProperties
Methods included from Property::Hosting
Methods included from Property::SchemaScoped
#property_subject_identifiers, #subitem_extended_properties_sql
Constructor Details
#initialize(schema, name) ⇒ Table
Returns a new instance of Table.
12 13 14 15 16 |
# File 'lib/mkxms/mssql/table_handler.rb', line 12 def initialize(schema, name) @schema = schema @name = name @columns = [] end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
19 20 21 |
# File 'lib/mkxms/mssql/table_handler.rb', line 19 def columns @columns end |
#heap_storage ⇒ Object
Returns the value of attribute heap_storage.
18 19 20 |
# File 'lib/mkxms/mssql/table_handler.rb', line 18 def heap_storage @heap_storage end |
#lob_storage ⇒ Object
Returns the value of attribute lob_storage.
18 19 20 |
# File 'lib/mkxms/mssql/table_handler.rb', line 18 def lob_storage @lob_storage end |
#name ⇒ Object
Returns the value of attribute name.
18 19 20 |
# File 'lib/mkxms/mssql/table_handler.rb', line 18 def name @name end |
#owner ⇒ Object
Returns the value of attribute owner.
18 19 20 |
# File 'lib/mkxms/mssql/table_handler.rb', line 18 def owner @owner end |
#schema ⇒ Object
Returns the value of attribute schema.
18 19 20 |
# File 'lib/mkxms/mssql/table_handler.rb', line 18 def schema @schema end |
Instance Method Details
#to_sql ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mkxms/mssql/table_handler.rb', line 21 def to_sql lines = ["CREATE TABLE #{schema}.#{name} ("] lines << columns.map{|c| " " + c.to_sql}.join(",\n") lines << ")" lines << "ON #{heap_storage}" if heap_storage lines << "TEXTIMAGE_ON #{lob_storage}" if lob_storage lines << ";" lines << "" if owner lines << ["ALTER AUTHORIZATION ON OBJECT::#{schema}.#{name} TO #{owner};"] lines << "" end lines.concat extended_properties_sql columns.each do |col| lines.concat subitem_extended_properties_sql(col) end return lines.join("\n") end |