Class: Mkxms::Mssql::ClrAssembly
- Inherits:
-
Object
- Object
- Mkxms::Mssql::ClrAssembly
- Includes:
- ExtendedProperties
- Defined in:
- lib/mkxms/mssql/clr_assembly_handler.rb
Constant Summary collapse
- RaiserrorSource =
Utils::RaiserrorWriter.new("%s: Missing or misconfigured assembly %s")
Instance Attribute Summary collapse
-
#access ⇒ Object
Returns the value of attribute access.
-
#error_stmt ⇒ Object
readonly
Returns the value of attribute error_stmt.
-
#lib_name ⇒ Object
Returns the value of attribute lib_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#warning_stmt ⇒ Object
readonly
Returns the value of attribute warning_stmt.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, lib_name = "", access:, owner: nil) ⇒ ClrAssembly
constructor
A new instance of ClrAssembly.
- #to_sql ⇒ Object
Methods included from ExtendedProperties
Constructor Details
#initialize(name, lib_name = "", access:, owner: nil) ⇒ ClrAssembly
Returns a new instance of ClrAssembly.
11 12 13 14 15 16 17 18 |
# File 'lib/mkxms/mssql/clr_assembly_handler.rb', line 11 def initialize(name, lib_name = "", access:, owner: nil) @name = name @error_stmt = RaiserrorSource.next_statement("ERROR".sql_quoted, name.sql_quoted, severity: :error) @warning_stmt = RaiserrorSource.next_statement("WARNING".sql_quoted, name.sql_quoted, severity: :warning) @lib_name = lib_name @access = access @owner = owner end |
Instance Attribute Details
#access ⇒ Object
Returns the value of attribute access.
21 22 23 |
# File 'lib/mkxms/mssql/clr_assembly_handler.rb', line 21 def access @access end |
#error_stmt ⇒ Object (readonly)
Returns the value of attribute error_stmt.
20 21 22 |
# File 'lib/mkxms/mssql/clr_assembly_handler.rb', line 20 def error_stmt @error_stmt end |
#lib_name ⇒ Object
Returns the value of attribute lib_name.
21 22 23 |
# File 'lib/mkxms/mssql/clr_assembly_handler.rb', line 21 def lib_name @lib_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/mkxms/mssql/clr_assembly_handler.rb', line 20 def name @name end |
#owner ⇒ Object
Returns the value of attribute owner.
21 22 23 |
# File 'lib/mkxms/mssql/clr_assembly_handler.rb', line 21 def owner @owner end |
#warning_stmt ⇒ Object (readonly)
Returns the value of attribute warning_stmt.
20 21 22 |
# File 'lib/mkxms/mssql/clr_assembly_handler.rb', line 20 def warning_stmt @warning_stmt end |
Class Method Details
.setup_sql ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/mkxms/mssql/clr_assembly_handler.rb', line 23 def self.setup_sql [].tap do |s| s << "IF NOT EXISTS (SELECT * FROM sys.tables t WHERE t.object_id = OBJECT_ID(N'xmigra.ignored_clr_assemblies'))" s << " CREATE TABLE xmigra.ignored_clr_assemblies (name SYSNAME PRIMARY KEY);" s << "" # Give a newline at the end end.join("\n") end |
Instance Method Details
#to_sql ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mkxms/mssql/clr_assembly_handler.rb', line 32 def to_sql [].tap do |s| s << "IF NOT EXISTS (" s << " SELECT asm.name" s << " FROM sys.assemblies asm" s << " WHERE asm.is_visible = 1" s << " AND QUOTENAME(asm.name) = #{name.sql_quoted}" s << " UNION ALL" s << " SELECT asm.name" s << " FROM xmigra.ignored_clr_assemblies asm" s << " WHERE asm.name = #{name.sql_quoted}" s << ") #{error_stmt};" s << "IF NOT EXISTS (" s << " SELECT asm.name, QUOTENAME(owner.name) as owner, REPLACE(LOWER(asm.permission_set_desc), '_', '-') as permission_set, asm.clr_name as library" s << " FROM sys.assemblies asm" s << " JOIN sys.database_principals owner ON asm.principal_id = owner.principal_id" if owner s << " WHERE asm.is_visible = 1" s << " AND QUOTENAME(asm.name) = #{name.sql_quoted}" s << " -- #{warning_stmt.error_marker} Run the query up to this point for assembly configuration --" cols = [ ["owner", owner], ["permission_set", access], ["library", lib_name], ].map {|t, v| [t.ljust(v.length), v.ljust(t.length)]} s << (" -- " + cols.map {|e| e[0]}.join(' ') + ' --') s << (" -- Expected values: " + cols.map {|e| e[1]}.join(' ') + ' --') s << " AND QUOTENAME(owner.name) = #{owner.sql_quoted}" if owner s << " AND REPLACE(LOWER(asm.permission_set_desc), '_', '-') = #{access.sql_quoted}" s << " AND asm.clr_name = #{lib_name.sql_quoted}" s << " UNION ALL" s << " SELECT asm.name, NULL, NULL, NULL" s << " FROM xmigra.ignored_clr_assemblies asm" s << " WHERE asm.name = #{name.sql_quoted}" s << ") #{warning_stmt};" s << "" # Gives a newline at the end end.join("\n") end |