﻿
USE markus_SEC;   
GO    
exec sp_configure

exec sp_configure 'clr enabled',1
reconfigure with override


exec sp_configure 'show advanced options',1
reconfigure with override


exec sp_configure 'clr strict security',0;
reconfigure with override

ALTER DATABASE  markus_SEC
SET TRUSTWORTHY ON;
 


IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MarkupDataCompress]'))
	drop FUNCTION [dbo].[MarkupDataCompress]

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MarkupDataDeCompress]'))
	drop FUNCTION [dbo].[MarkupDataDecompress]

	
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MarkupDataText]'))
	drop FUNCTION [dbo].[MarkupDataText]

IF EXISTS (select * from sys.assemblies where name = 'MarkupDataParse')
	drop ASSEMBLY MarkupDataParse 
	
IF EXISTS (select * from sys.assemblies where name = 'System.Runtime.Serialization')
	drop ASSEMBLY [System.Runtime.Serialization] 

CREATE ASSEMBLY [System.Runtime.Serialization] 
	FROM 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.Serialization.dll' 
	WITH PERMISSION_SET = UNSAFE;

create ASSEMBLY MarkupDataParse 
FROM 'D:\Markus_V3\dbFunctions\MarkupDataParse.dll'
WITH PERMISSION_SET = UNSAFE;  

go

select * from sys.assemblies


/****** Object:  UserDefinedTableType [dbo].[VARCHAR_TABLE]    Script Date: 2023-05-30 오전 10:22:07 ******/
IF NOT EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'VARCHAR_TABLE' AND ss.name = N'dbo')
CREATE TYPE [dbo].[VARCHAR_TABLE] AS TABLE(
	[ITEM] [varchar](max) NULL
)
GO
/****** Object:  UserDefinedFunction [dbo].[MarkupDataCompress]    Script Date: 2023-05-30 오전 10:22:07 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MarkupDataCompress]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'CREATE FUNCTION [dbo].[MarkupDataCompress](@inputString [nvarchar](max))
RETURNS [nvarchar](max) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [MarkupDataParse].[MarkupDataParse.MarkupDataFunctions].[CompressString]' 
END
GO
/****** Object:  UserDefinedFunction [dbo].[MarkupDataDecompress]    Script Date: 2023-05-30 오전 10:22:07 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MarkupDataDecompress]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'CREATE FUNCTION [dbo].[MarkupDataDecompress](@inputString [nvarchar](max))
RETURNS [nvarchar](max) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [MarkupDataParse].[MarkupDataParse.MarkupDataFunctions].[DecompressString]' 
END
GO
/****** Object:  UserDefinedFunction [dbo].[MarkupDataText]    Script Date: 2023-05-30 오전 10:22:07 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MarkupDataText]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'CREATE FUNCTION [dbo].[MarkupDataText](@inputString [nvarchar](max))
RETURNS [nvarchar](max) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [MarkupDataParse].[MarkupDataParse.MarkupDataFunctions].[GetMarkupText]' 
END
GO
/****** Object:  Table [dbo].[ControlType]    Script Date: 2023-05-30 오전 10:22:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON