PRINT 'This file is not intended to be run end-to-end, but only selected parts.';
RETURN;

DROP TABLE [p2j_wrappers]
DROP TYPE [P2JLogical]
DROP ASSEMBLY [p2j_wrapper]
DROP ASSEMBLY p2jpl

CREATE ASSEMBLY p2jpl
FROM 'c:\Work\2ndSqlProject\P2JWrapper\bin\Debug\p2jpl.exe' 
WITH PERMISSION_SET = UNSAFE

CREATE ASSEMBLY p2j_wrapper
FROM 'c:\Work\2ndSqlProject\P2JWrapper\bin\Debug\P2JWrapper.dll' 
WITH PERMISSION_SET = SAFE

CREATE TYPE P2JLogical EXTERNAL NAME [p2j_wrapper].[P2JLogical]

CREATE TABLE [p2j_wrappers] (
	[id] [bigint] IDENTITY(21764, 17) NOT NULL,
	[p2j_logical] [P2JLogical] NULL,
	[sql_logical] [BIT] NULL
) ON [PRIMARY]


INSERT INTO [p2j_wrappers] VALUES ('true', 1)
INSERT INTO [p2j_wrappers] VALUES ('1', 1)
INSERT INTO [p2j_wrappers] VALUES (1, 1)
INSERT INTO [p2j_wrappers] VALUES ('false', 0)
INSERT INTO [p2j_wrappers] VALUES ('0', 0)
INSERT INTO [p2j_wrappers] VALUES (0, 0)
INSERT INTO [p2j_wrappers] VALUES (NULL, null)


SELECT * FROM [p2j_wrappers]

SELECT [p2j_logical].P2J_And('falsE'),
       [p2j_logical].P2J_And(' true') 
	FROM [p2j_wrappers]

SELECT [p2j_logical].value(), [p2j_logical].P2J_And('true').value() FROM [p2j_wrappers]

select cast([p2j_logical] as int) FROM [p2j_wrappers]
--ERR: Explicit conversion from data type ikvm-test.dbo.P2JLogical to int is not allowed.
