Class: Mkxms::Mssql::CheckConstraint

Inherits:
Object
  • Object
show all
Includes:
ExtendedProperties, Property::Hosting
Defined in:
lib/mkxms/mssql/check_constraint_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExtendedProperties

#extended_properties

Methods included from Property::Hosting

#extended_properties_sql

Constructor Details

#initialize(schema, table, name, enabled: true, when_replicated: true) ⇒ CheckConstraint

Returns a new instance of CheckConstraint.



9
10
11
12
13
14
15
16
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 9

def initialize(schema, table, name, enabled: true, when_replicated: true)
  @schema = schema
  @table = table
  @name = name
  @enabled = enabled
  @when_replicated = when_replicated
  @expression = ''
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



18
19
20
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 18

def enabled
  @enabled
end

#expressionObject (readonly)

Returns the value of attribute expression.



19
20
21
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 19

def expression
  @expression
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 18

def name
  @name
end

#schemaObject

Returns the value of attribute schema.



18
19
20
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 18

def schema
  @schema
end

#tableObject

Returns the value of attribute table.



18
19
20
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 18

def table
  @table
end

#when_replicatedObject

Returns the value of attribute when_replicated.



18
19
20
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 18

def when_replicated
  @when_replicated
end

Instance Method Details

#property_subject_identifiersObject



37
38
39
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 37

def property_subject_identifiers
  ['SCHEMA', schema, 'TABLE', table, 'CONSTRAINT', name].map {|s| Utils::unquoted_name(s)}
end

#qualified_nameObject



33
34
35
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 33

def qualified_name
  "#@schema.#@name" if @name
end

#qualified_tableObject



29
30
31
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 29

def qualified_table
  "#@schema.#@table"
end

#to_sqlObject



21
22
23
24
25
26
27
# File 'lib/mkxms/mssql/check_constraint_handler.rb', line 21

def to_sql
  "ALTER TABLE #@schema.#@table ADD%s CHECK%s #@expression;%s" % [
    @name ? " CONSTRAINT #@name" : '',
    @when_replicated ? '' : ' NOT FOR REPLICATION',
    @enabled ? '' : "\nALTER TABLE #@schema.#@table NOCHECK CONSTRAINT #@name;"
  ] + (name ? extended_properties_sql.joined_on_new_lines : '')
end