Class: Mkxms::Mssql::TableHandler::ColumnHandler

Inherits:
Object
  • Object
show all
Includes:
PropertyHandler::ElementHandler
Defined in:
lib/mkxms/mssql/table_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PropertyHandler::ElementHandler

#handle_property_element

Constructor Details

#initialize(columns, node) ⇒ ColumnHandler

Returns a new instance of ColumnHandler.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/mkxms/mssql/table_handler.rb', line 92

def initialize(columns, node)
  a = node.attributes
  
  col_attrs = {}
  use_attr = proc {|k| col_attrs[k.gsub('-', '_').to_sym] = node.attributes[k]}
  col_type = %w[type-schema type].map {|k| use_attr[k]}.compact.join('.')
  
  if a.has_key?('capacity')
    col_type << "(%s)" % [use_attr['capacity']]
  end
  
  prec_scale = []
  if a.has_key?('precision') || a.has_key?('scale')
    prec_scale << use_attr['precision']
  end
  if a.has_key?('scale')
    prec_scale << use_attr['scale']
  end
  unless prec_scale.empty?
    col_type << "(%s)" % (prec_scale.join(', '))
  end
  
  if a.has_key?('xml_collection_id')
    col_type << "(%s %s)" % [
      xml_structure = (a['full-xml-document'] ? 'DOCUMENT' : 'CONTENT'),
      a['xml_collection_id']
    ]
    col_attrs[:xml_validation] = {xml_structure.downcase => a['xml_collection_id']}
  end
  
  raise UnsupportedFeatureError.new("Column #{name} declared 'not-ansi-padded'") if a['not-ansi-padded']
  
  @column = Column.new(a['name']).tap do |c|
    c.type = col_type
    c.collation = a['collation']
    c.flags << :nullable if a['nullable']
    c.flags << :replicated if a['replicated']
    c.flags << :filestream if a['filestream']
    c.type_info.update(col_attrs)
    store_properties_on c
    columns << c
  end
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



136
137
138
# File 'lib/mkxms/mssql/table_handler.rb', line 136

def column
  @column
end

Instance Method Details

#handle_computed_expression_element(parse) ⇒ Object



138
139
140
141
# File 'lib/mkxms/mssql/table_handler.rb', line 138

def handle_computed_expression_element(parse)
  column.flags << :persisted if parse.node.attributes['persisted']
  # Handle expression in #handle_text
end

#handle_text(text, parent_element) ⇒ Object



143
144
145
146
147
148
# File 'lib/mkxms/mssql/table_handler.rb', line 143

def handle_text(text, parent_element)
  case %i[namespace name].map {|m| parent_element.send(m)}
  when ['', 'computed-expression']
    (column.computed_expression ||= '') << text
  end
end