Class: Mkxms::Mssql::ClrAggregate

Inherits:
Object
  • Object
show all
Extended by:
Utils::InitializedAttributes
Includes:
ExtendedProperties, Property::Hosting, Property::SchemaScoped, Utils::SchemaQualifiedName
Defined in:
lib/mkxms/mssql/clr_aggregate_handler.rb

Constant Summary collapse

SQL_OBJECT_TYPE =
'AGGREGATE'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::InitializedAttributes

attr_init

Methods included from Utils::SchemaQualifiedName

#qualified_name

Methods included from ExtendedProperties

#extended_properties

Methods included from Property::Hosting

#extended_properties_sql

Methods included from Property::SchemaScoped

#property_subject_identifiers, #subitem_extended_properties_sql

Constructor Details

#initialize(attrs) ⇒ ClrAggregate

Returns a new instance of ClrAggregate.



15
16
17
18
19
# File 'lib/mkxms/mssql/clr_aggregate_handler.rb', line 15

def initialize(attrs)
  @schema = attrs['schema']
  @name = attrs['name']
  @execute_as = attrs['execute-as']
end

Instance Attribute Details

#clr_implObject

Returns the value of attribute clr_impl.



21
22
23
# File 'lib/mkxms/mssql/clr_aggregate_handler.rb', line 21

def clr_impl
  @clr_impl
end

#execute_asObject

Returns the value of attribute execute_as.



21
22
23
# File 'lib/mkxms/mssql/clr_aggregate_handler.rb', line 21

def execute_as
  @execute_as
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/mkxms/mssql/clr_aggregate_handler.rb', line 21

def name
  @name
end

#returnsObject

Returns the value of attribute returns.



21
22
23
# File 'lib/mkxms/mssql/clr_aggregate_handler.rb', line 21

def returns
  @returns
end

#schemaObject

Returns the value of attribute schema.



21
22
23
# File 'lib/mkxms/mssql/clr_aggregate_handler.rb', line 21

def schema
  @schema
end

Instance Method Details

#param_properties_sqlObject



46
47
48
49
50
# File 'lib/mkxms/mssql/clr_aggregate_handler.rb', line 46

def param_properties_sql
  params.map do |param|
    subitem_extended_properties_sql(param)
  end
end

#procedure_def_sqlObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mkxms/mssql/clr_aggregate_handler.rb', line 28

def procedure_def_sql
  [[].tap do |lines|
    lines << "IF NOT EXISTS ("
    lines << "  SELECT * FROM xmigra.ignored_clr_assemblies asm"
    lines << "  WHERE asm.name = #{clr_impl.assembly.sql_quoted}"
    lines << ")"
    lines << "CREATE AGGREGATE [{filename}] ("
    lines << params.map do |param|
      "  #{param.name} #{param.type_spec}".tap do |param_spec|
        param_spec << " = #{param.default_value}" if param.default_value
      end
    end.join(",\n")
    lines << ")"
    lines << "RETURNS #{returns.type_spec}" if returns
    lines << "EXTERNAL NAME #{clr_impl.full_specifier};"
  end.join("\n")]
end

#to_sqlObject



24
25
26
# File 'lib/mkxms/mssql/clr_aggregate_handler.rb', line 24

def to_sql
  (procedure_def_sql + extended_properties_sql + param_properties_sql)
end