Class: Mkxms::Mssql::TableType::Column

Inherits:
Object
  • Object
show all
Extended by:
Utils::InitializedAttributes
Includes:
ExtendedProperties
Defined in:
lib/mkxms/mssql/table_type_handler.rb

Constant Summary collapse

SQL_OBJECT_TYPE =
'COLUMN'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::InitializedAttributes

attr_init

Methods included from ExtendedProperties

#extended_properties

Constructor Details

#initialize(attrs) ⇒ Column

Returns a new instance of Column.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mkxms/mssql/table_type_handler.rb', line 14

def initialize(attrs)
  a = attrs
  @name = a['name']
  @type_schema = a['type-schema']
  @type_name = a['type']
  @capacity = a['capacity']
  @capacity = @capacity.to_i unless @capacity.nil? || @capacity == 'max'
  @precision = a['precision']
  @scale = a['scale']
  @collation = a['collation']
  @nullable = !!a['nullable']
  @ansi_padded = !a['not-ansi-padded']
  @full_xml_document = !!a['full-xml-document']
  @xml_schema_collection = a['xml_collection_id']
end

Instance Attribute Details

#capacityObject

Returns the value of attribute capacity.



30
31
32
# File 'lib/mkxms/mssql/table_type_handler.rb', line 30

def capacity
  @capacity
end

#collationObject

Returns the value of attribute collation.



30
31
32
# File 'lib/mkxms/mssql/table_type_handler.rb', line 30

def collation
  @collation
end

#computed_expressionObject

Returns the value of attribute computed_expression.



31
32
33
# File 'lib/mkxms/mssql/table_type_handler.rb', line 31

def computed_expression
  @computed_expression
end

#nameObject

Returns the value of attribute name.



30
31
32
# File 'lib/mkxms/mssql/table_type_handler.rb', line 30

def name
  @name
end

#precisionObject

Returns the value of attribute precision.



30
31
32
# File 'lib/mkxms/mssql/table_type_handler.rb', line 30

def precision
  @precision
end

#scaleObject

Returns the value of attribute scale.



30
31
32
# File 'lib/mkxms/mssql/table_type_handler.rb', line 30

def scale
  @scale
end

#type_nameObject

Returns the value of attribute type_name.



30
31
32
# File 'lib/mkxms/mssql/table_type_handler.rb', line 30

def type_name
  @type_name
end

#type_schemaObject

Returns the value of attribute type_schema.



30
31
32
# File 'lib/mkxms/mssql/table_type_handler.rb', line 30

def type_schema
  @type_schema
end

#xml_schema_collectionObject

Returns the value of attribute xml_schema_collection.



30
31
32
# File 'lib/mkxms/mssql/table_type_handler.rb', line 30

def xml_schema_collection
  @xml_schema_collection
end

Instance Method Details

#ansi_padded=(val) ⇒ Object



38
# File 'lib/mkxms/mssql/table_type_handler.rb', line 38

def ansi_padded=(val); @ansi_padded = !!val; end

#ansi_padded?Boolean

Returns:

  • (Boolean)


37
# File 'lib/mkxms/mssql/table_type_handler.rb', line 37

def ansi_padded?; @ansi_padded; end

#full_xml_document=(val) ⇒ Object



41
# File 'lib/mkxms/mssql/table_type_handler.rb', line 41

def full_xml_document=(val); @full_xml_document = !!val; end

#full_xml_document?Boolean

Returns:

  • (Boolean)


40
# File 'lib/mkxms/mssql/table_type_handler.rb', line 40

def full_xml_document?; @full_xml_document; end

#max_byte_consumptionObject



55
56
57
58
59
60
61
# File 'lib/mkxms/mssql/table_type_handler.rb', line 55

def max_byte_consumption
  if [nil, '[sys]'].include?(type_schema) && %w[[nchar] [nvarchar]].include?(type_name)
    2 * capacity
  else
    capacity
  end
end

#nullable=(val) ⇒ Object



35
# File 'lib/mkxms/mssql/table_type_handler.rb', line 35

def nullable=(val); @nullable = !!val; end

#nullable?Boolean

Returns:

  • (Boolean)


34
# File 'lib/mkxms/mssql/table_type_handler.rb', line 34

def nullable?; @nullable; end

#type_specObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mkxms/mssql/table_type_handler.rb', line 43

def type_spec
  [type_schema, type_name].compact.join('.').tap do |result|
    result << "(#{capacity})" if capacity
    result << " COLLATE #{collation}" if collation
    result << "(#{[precision, scale].compact.join(', ')})" if precision
    result << ' NOT NULL' unless nullable?
    check_constraints.each do |c|
      result << " #{c.to_sql}"
    end
  end
end