class Mkxms::Mssql::Index
Attributes
cells_per_object[RW]
columns[R]
fill_factor[RW]
flags[R]
included_columns[R]
name[RW]
relation[RW]
schema[RW]
spatial_index_geometry[RW]
storage[RW]
Public Class Methods
new(attrs)
click to toggle source
# File lib/mkxms/mssql/index_handler.rb, line 11 def initialize(attrs) @schema = attrs['schema'] @relation = attrs['relation'] @name = attrs['name'] @fill_factor = attrs['fill-factor'] @spatial_index_geometry = attrs['spatial-index-over'] @cells_per_object = attrs['cells-per-object'] @storage = attrs['stored-on'] @columns = [] @included_columns = [] @flags = [] @flags << :unique if attrs['unique'] @flags << :padded if attrs['padded'] @flags << :disabled if attrs['disabled'] @flags << :ignore_duplicates if attrs['ignore-duplicates'] @flags << :row_locks_prohibited if attrs['no-row-locks'] @flags << :page_locks_prohibited if attrs['no-page-locks'] end
Public Instance Methods
property_subject_identifiers()
click to toggle source
# File lib/mkxms/mssql/index_handler.rb, line 64 def property_subject_identifiers ['SCHEMA', @schema, 'TABLE', @relation, 'INDEX', @name].map {|n| Utils.unquoted_name(n)} end
qualified_relation()
click to toggle source
# File lib/mkxms/mssql/index_handler.rb, line 68 def qualified_relation [@schema, @relation].join '.' end
to_sql()
click to toggle source
# File lib/mkxms/mssql/index_handler.rb, line 36 def to_sql if @spatial_index_geometry else [].tap do |parts| parts << "CREATE #{'UNIQUE ' if unique?}INDEX #@name ON #{qualified_relation} (\n" + @columns.map(&:to_sql).join(', ') + "\n)" parts << "INCLUDE (\n" + @included_columns.map(&:name).join(', ') + "\n)" unless @included_columns.empty? # TODO: "WHERE" clause options = [] options << "PAD_INDEX = ON" if padded? options << "FILLFACTOR = #@fill_factor" if @fill_factor options << "IGNORE_DUP_KEY = ON" if ignore_duplicates? options << "ALLOW_ROW_LOCKS = OFF" if row_locks_prohibited? options << "ALLOW_PAGE_LOCKS = OFF" if page_locks_prohibited? parts << "WITH (#{options.join(', ')})" unless options.empty? parts << "ON #@storage" if @storage end.join(' ') + ';' + extended_properties_sql.joined_on_new_lines end end