Class: Mkxms::Mssql::KeylikeConstraint
- Inherits:
-
Object
- Object
- Mkxms::Mssql::KeylikeConstraint
- Extended by:
- Utils::FlagsQueries
- Includes:
- ExtendedProperties, Property::Hosting
- Defined in:
- lib/mkxms/mssql/keylike_constraint_helper.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#fill_factor ⇒ Object
Returns the value of attribute fill_factor.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#name ⇒ Object
Returns the value of attribute name.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#stored_on ⇒ Object
Returns the value of attribute stored_on.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
-
#initialize(attrs) ⇒ KeylikeConstraint
constructor
A new instance of KeylikeConstraint.
- #property_subject_identifiers ⇒ Object
- #qualified_name ⇒ Object
- #qualified_table ⇒ Object
- #to_sql ⇒ Object
- #with_clause_sql ⇒ Object
Methods included from Utils::FlagsQueries
Methods included from ExtendedProperties
Methods included from Property::Hosting
Constructor Details
#initialize(attrs) ⇒ KeylikeConstraint
Returns a new instance of KeylikeConstraint.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
29 30 31 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 29 def columns @columns end |
#fill_factor ⇒ Object
Returns the value of attribute fill_factor.
28 29 30 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 28 def fill_factor @fill_factor end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
29 30 31 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 29 def flags @flags end |
#name ⇒ Object
Returns the value of attribute name.
28 29 30 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 28 def name @name end |
#schema ⇒ Object
Returns the value of attribute schema.
28 29 30 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 28 def schema @schema end |
#stored_on ⇒ Object
Returns the value of attribute stored_on.
28 29 30 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 28 def stored_on @stored_on end |
#table ⇒ Object
Returns the value of attribute table.
28 29 30 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 28 def table @table end |
Instance Method Details
#property_subject_identifiers ⇒ Object
63 64 65 |
# 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 ⇒ Object
59 60 61 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 59 def qualified_name "#@schema.#@name" if @name end |
#qualified_table ⇒ Object
55 56 57 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 55 def qualified_table "#@schema.#@table" end |
#to_sql ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# 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 ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mkxms/mssql/keylike_constraint_helper.rb', line 44 def with_clause_sql = [] << 'PAD_INDEX = ON' if padded? << "FILLFACTOR = #@fill_factor" if fill_factor << 'ALLOW_ROW_LOCKS = OFF' unless row_locks_ok? << 'ALLOW_PAGE_LOCKS = OFF' unless page_locks_ok? return '' if .empty? return " WITH (\n#{.join ", "}\n)" end |