Class: Mkxms::Mssql::Column

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

Constant Summary collapse

SQL_OBJECT_TYPE =
'COLUMN'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::FlagsQueries

flags_query

Methods included from ExtendedProperties

#extended_properties

Constructor Details

#initialize(name) ⇒ Column

Returns a new instance of Column.



53
54
55
56
57
# File 'lib/mkxms/mssql/table_handler.rb', line 53

def initialize(name)
  @name = name
  @flags = []
  @type_info = {}
end

Instance Attribute Details

#collationObject

Returns the value of attribute collation.



59
60
61
# File 'lib/mkxms/mssql/table_handler.rb', line 59

def collation
  @collation
end

#computed_expressionObject

Returns the value of attribute computed_expression.



59
60
61
# File 'lib/mkxms/mssql/table_handler.rb', line 59

def computed_expression
  @computed_expression
end

#flagsObject (readonly)

Returns the value of attribute flags.



60
61
62
# File 'lib/mkxms/mssql/table_handler.rb', line 60

def flags
  @flags
end

#nameObject

Returns the value of attribute name.



59
60
61
# File 'lib/mkxms/mssql/table_handler.rb', line 59

def name
  @name
end

#typeObject

Returns the value of attribute type.



59
60
61
# File 'lib/mkxms/mssql/table_handler.rb', line 59

def type
  @type
end

#type_infoObject (readonly)

Returns the value of attribute type_info.



60
61
62
# File 'lib/mkxms/mssql/table_handler.rb', line 60

def type_info
  @type_info
end

Instance Method Details

#each_type_part {|type| ... } ⇒ Object

Yields:



76
77
78
79
80
81
82
83
84
85
# File 'lib/mkxms/mssql/table_handler.rb', line 76

def each_type_part
  yield type
  yield("COLLATE " + collation) if collation
  yield(nullable? ? 'NULL' : 'NOT NULL')
  if identity?
    yield "IDENTITY"
    yield("NOT FOR REPLICATION") unless replicated?
  end
  yield("ROWGUID") if rowguid?
end

#to_sqlObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mkxms/mssql/table_handler.rb', line 64

def to_sql
  parts = [name]
  if computed_expression
    parts << "AS " + computed_expression
    parts << "PERSISTED" if persisted?
  else
    each_type_part {|part| parts << part}
  end
  
  return parts.join(' ')
end