class Mkxms::Mssql::KeylikeConstraint

Attributes

columns[R]
fill_factor[RW]
flags[R]
name[RW]
schema[RW]
stored_on[RW]
table[RW]

Public Class Methods

new(attrs) click to toggle source
# File lib/mkxms/mssql/keylike_constraint_helper.rb, line 12
def initialize(attrs)
  @schema = attrs['schema']
  @table = attrs['table']
  @name = attrs['name']
  @stored_on = attrs['stored-on']
  @fill_factor = attrs['fill-factor']
  
  @flags = []
  @flags << :clustered if attrs['clustered']
  @flags << :paddedd if attrs['padded']
  @flags << :row_locks_ok unless attrs['no-row-locks']
  @flags << :page_locks_ok unless attrs['no-page-locks']
  
  @columns = []
end

Public Instance Methods

property_subject_identifiers() click to toggle source
# File lib/mkxms/mssql/keylike_constraint_helper.rb, line 63
def property_subject_identifiers
  @prop_subj_id ||= ['SCHEMA', schema, 'TABLE', table, 'CONSTRAINT', name].map {|s| Utils::unquoted_name(s)}
end
qualified_name() click to toggle source
# File lib/mkxms/mssql/keylike_constraint_helper.rb, line 59
def qualified_name
  "#@schema.#@name" if @name
end
qualified_table() click to toggle source
# File lib/mkxms/mssql/keylike_constraint_helper.rb, line 55
def qualified_table
  "#@schema.#@table"
end
to_sql() click to toggle source
# File lib/mkxms/mssql/keylike_constraint_helper.rb, line 32
def to_sql
  "ALTER TABLE #@schema.#@table ADD #{"CONSTRAINT #@name " if @name}" +
  "#{self.sql_constraint_type} #{'NON' unless clustered?}CLUSTERED (\n" +
  '    ' + columns.map {|c| c.to_sql}.join(", ") +
  "\n)" +
  with_clause_sql +
  # TODO: Handle partitioned constraints
  "#{" ON #@stored_on" if @stored_on}" +
  ";" +
  (name ? extended_properties_sql.joined_on_new_lines : '')
end
with_clause_sql() click to toggle source
# File lib/mkxms/mssql/keylike_constraint_helper.rb, line 44
def with_clause_sql
  options = []
  options << 'PAD_INDEX = ON' if padded?
  options << "FILLFACTOR = #@fill_factor" if fill_factor
  options << 'ALLOW_ROW_LOCKS = OFF' unless row_locks_ok?
  options << 'ALLOW_PAGE_LOCKS = OFF' unless page_locks_ok?
  
  return '' if options.empty?
  return " WITH (\n#{options.join ", "}\n)"
end