class Mkxms::Mssql::Trigger
Attributes
clr_impl[RW]
disabled[RW]
execute_as[RW]
name[RW]
not_replicable[RW]
schema[RW]
table[RW]
timing[RW]
Public Class Methods
new(schema, name, timing, execute_as: nil, disabled: false, not_replicable: false)
click to toggle source
# File lib/mkxms/mssql/dml_trigger_handler.rb, line 15 def initialize(schema, name, timing, execute_as: nil, disabled: false, not_replicable: false) @schema = schema @name = name @timing = timing @execute_as = execute_as @disabled = disabled @not_replicable = not_replicable end
Public Instance Methods
clr_definition()
click to toggle source
# File lib/mkxms/mssql/dml_trigger_handler.rb, line 40 def clr_definition [].tap do |lines| lines << "CREATE TRIGGER #{schema}.#{name}" lines << "ON #{table.qualified_name}" case execute_as when 'OWNER' lines << "WITH EXECUTE AS OWNER" when String lines << "WITH EXECUTE AS #{execute_as.sql_quoted}" end lines << "#{timing} #{events.join(', ')}" lines << "NOT FOR REPLICATION" if not_replicable lines << "AS EXTERNAL NAME #{clr_impl.full_specifier};" end.join("\n") end
to_sql()
click to toggle source
# File lib/mkxms/mssql/dml_trigger_handler.rb, line 28 def to_sql def_sql = clr_impl ? clr_definition : definition [def_sql.expand_tabs.gsub(/ +\n/, "\n")].tap do |result| unless (ep_sql = extended_properties_sql).empty? result << ep_sql.joined_on_new_lines end if disabled result << "DISABLE TRIGGER #{qualified_name} ON #{table.qualified_name};" end end.join(ddl_block_separator) end