Class: Mkxms::Mssql::Table

Inherits:
Object
  • Object
show all
Includes:
ExtendedProperties, Property::Hosting, Property::SchemaScoped
Defined in:
lib/mkxms/mssql/table_handler.rb

Constant Summary collapse

SQL_OBJECT_TYPE =
'TABLE'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExtendedProperties

#extended_properties

Methods included from Property::Hosting

#extended_properties_sql

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

#columnsObject (readonly)

Returns the value of attribute columns.



19
20
21
# File 'lib/mkxms/mssql/table_handler.rb', line 19

def columns
  @columns
end

#heap_storageObject

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_storageObject

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

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/mkxms/mssql/table_handler.rb', line 18

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



18
19
20
# File 'lib/mkxms/mssql/table_handler.rb', line 18

def owner
  @owner
end

#schemaObject

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_sqlObject



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