Skip to content

Commit

Permalink
Support SSMS scripting for Users and fix crash in SSMS while clicking…
Browse files Browse the repository at this point in the history
… permissions (#1869) (#1972)

Added three new dummy views, sys.asymmetric_keys, sys.certificates and sys.database_permissions which are required by to script users, though empty views works fine here.Open a JIRA, BABEL-4440 for fully supporting it in future.

Task: BABEL-3921, BABEL-3593
Signed-off-by: Ashish Prasad <[email protected]>
  • Loading branch information
hash-16 authored Nov 2, 2023
1 parent 83bccd3 commit 17a7631
Show file tree
Hide file tree
Showing 26 changed files with 494 additions and 3 deletions.
63 changes: 63 additions & 0 deletions contrib/babelfishpg_tsql/sql/sys_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2917,6 +2917,53 @@ SELECT
WHERE FALSE;
GRANT SELECT ON sys.spatial_index_tessellations TO PUBLIC;

CREATE OR REPLACE VIEW sys.asymmetric_keys
AS
SELECT
CAST('' as sys.sysname) AS name
, CAST(0 as sys.int) AS principal_id
, CAST(0 as sys.int) AS asymmetric_key_id
, CAST('a' as sys.bpchar(2)) AS pvt_key_encryption_type
, CAST('' as sys.nvarchar(60)) AS pvt_key_encryption_type_desc
, CAST(null as sys.varbinary(32)) as thumbprint
, CAST('a' as sys.bpchar(2)) AS algorithm
, CAST('' as sys.nvarchar(60)) AS algorithm_desc
, CAST(0 as sys.int) AS key_length
, CAST(null as sys.varbinary(85)) as sid
, CAST('' as sys.nvarchar(128)) AS string_sid
, CAST(NULL as sys.varbinary(8000)) AS public_key
, CAST('' as sys.nvarchar(260)) AS attested_by
, CAST('' as sys.nvarchar(120)) AS provider_type
, CAST(NULL as sys.UNIQUEIDENTIFIER) as cryptographic_provider_guid
, CAST(NULL AS sys.sql_variant) AS cryptographic_provider_algid

WHERE FALSE;
GRANT SELECT ON sys.asymmetric_keys TO PUBLIC;

CREATE OR REPLACE VIEW sys.certificates
AS
SELECT
CAST('' as sys.sysname) AS name
, CAST(0 as sys.int) AS principal_id
, CAST(0 as sys.int) AS asymmetric_key_id
, CAST('a' as sys.bpchar(2)) AS pvt_key_encryption_type
, CAST('' as sys.nvarchar(60)) AS pvt_key_encryption_type_desc
, CAST(0 as sys.bit) AS is_active_for_begin_dialog
, CAST('' as sys.nvarchar(442)) AS issuer_name
, CAST('' as sys.nvarchar(64)) AS cert_serial_number
, CAST(null as sys.varbinary(85)) as sid
, CAST('' as sys.nvarchar(128)) AS string_sid
, CAST('' as sys.nvarchar(4000)) AS subject
, CAST('' as sys.datetime) AS expiry_date
, CAST('' as sys.datetime) AS start_date
, CAST(null as sys.varbinary(32)) as thumbprint
, CAST('' as sys.nvarchar(260)) as attested_by
, CAST('' as sys.datetime) AS pvt_key_last_backup_date
, CAST(0 AS sys.int) AS key_length

WHERE FALSE;
GRANT SELECT ON sys.certificates TO PUBLIC;

CREATE OR REPLACE VIEW sys.all_parameters
AS
SELECT
Expand Down Expand Up @@ -3093,3 +3140,19 @@ SELECT
CAST(0 as sys.BIT) AS is_ambiguous
WHERE FALSE;
GRANT SELECT ON sys.sql_expression_dependencies TO PUBLIC;

CREATE OR REPLACE VIEW sys.database_permissions
AS
SELECT
CAST(0 as sys.tinyint) AS class,
CAST('' as sys.NVARCHAR(60)) AS class_desc,
CAST(0 as sys.int) AS major_id,
CAST(0 as sys.int) AS minor_id,
CAST(0 as sys.int) AS grantee_principal_id,
CAST(0 as sys.int) AS grantor_principal_id,
CAST('a' as sys.BPCHAR(4)) AS type,
CAST('' as sys.NVARCHAR(128)) AS permission_name,
CAST('G' as sys.BPCHAR(1)) AS state,
CAST('' as sys.NVARCHAR(60)) AS state_desc
WHERE FALSE;
GRANT SELECT ON sys.database_permissions TO PUBLIC;
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,69 @@ BEGIN
END;
$$;

CREATE OR REPLACE VIEW sys.asymmetric_keys
AS
SELECT
CAST('' as sys.sysname) AS name
, CAST(0 as sys.int) AS principal_id
, CAST(0 as sys.int) AS asymmetric_key_id
, CAST('a' as sys.bpchar(2)) AS pvt_key_encryption_type
, CAST('' as sys.nvarchar(60)) AS pvt_key_encryption_type_desc
, CAST(null as sys.varbinary(32)) as thumbprint
, CAST('a' as sys.bpchar(2)) AS algorithm
, CAST('' as sys.nvarchar(60)) AS algorithm_desc
, CAST(0 as sys.int) AS key_length
, CAST(null as sys.varbinary(85)) as sid
, CAST('' as sys.nvarchar(128)) AS string_sid
, CAST(NULL as sys.varbinary(8000)) AS public_key
, CAST('' as sys.nvarchar(260)) AS attested_by
, CAST('' as sys.nvarchar(120)) AS provider_type
, CAST(NULL as sys.UNIQUEIDENTIFIER) as cryptographic_provider_guid
, CAST(NULL AS sys.sql_variant) AS cryptographic_provider_algid

WHERE FALSE;
GRANT SELECT ON sys.asymmetric_keys TO PUBLIC;

CREATE OR REPLACE VIEW sys.certificates
AS
SELECT
CAST('' as sys.sysname) AS name
, CAST(0 as sys.int) AS principal_id
, CAST(0 as sys.int) AS asymmetric_key_id
, CAST('a' as sys.bpchar(2)) AS pvt_key_encryption_type
, CAST('' as sys.nvarchar(60)) AS pvt_key_encryption_type_desc
, CAST(0 as sys.bit) AS is_active_for_begin_dialog
, CAST('' as sys.nvarchar(442)) AS issuer_name
, CAST('' as sys.nvarchar(64)) AS cert_serial_number
, CAST(null as sys.varbinary(85)) as sid
, CAST('' as sys.nvarchar(128)) AS string_sid
, CAST('' as sys.nvarchar(4000)) AS subject
, CAST('' as sys.datetime) AS expiry_date
, CAST('' as sys.datetime) AS start_date
, CAST(null as sys.varbinary(32)) as thumbprint
, CAST('' as sys.nvarchar(260)) as attested_by
, CAST('' as sys.datetime) AS pvt_key_last_backup_date
, CAST(0 AS sys.int) AS key_length

WHERE FALSE;
GRANT SELECT ON sys.certificates TO PUBLIC;

CREATE OR REPLACE VIEW sys.database_permissions
AS
SELECT
CAST(0 as sys.tinyint) AS class,
CAST('' as sys.NVARCHAR(60)) AS class_desc,
CAST(0 as sys.int) AS major_id,
CAST(0 as sys.int) AS minor_id,
CAST(0 as sys.int) AS grantee_principal_id,
CAST(0 as sys.int) AS grantor_principal_id,
CAST('a' as sys.bpchar(4)) AS type,
CAST('' as sys.NVARCHAR(128)) AS permission_name,
CAST('G' as sys.bpchar(1)) AS state,
CAST('' as sys.NVARCHAR(60)) AS state_desc
WHERE FALSE;
GRANT SELECT ON sys.database_permissions TO PUBLIC;

-- Drops the temporary procedure used by the upgrade script.
-- Please have this be one of the last statements executed in this upgrade script.
DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar);
Expand Down
11 changes: 11 additions & 0 deletions test/JDBC/expected/sys_asymmetric_keys-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
USE master
GO

DROP VIEW sys_asymmetric_keys_vu_prepare_view
GO

DROP PROC sys_asymmetric_keys_vu_prepare_proc
GO

DROP FUNCTION sys_asymmetric_keys_vu_prepare_func
GO
18 changes: 18 additions & 0 deletions test/JDBC/expected/sys_asymmetric_keys-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
USE master
GO

CREATE VIEW sys_asymmetric_keys_vu_prepare_view AS
SELECT * FROM sys.asymmetric_keys
GO

CREATE PROC sys_asymmetric_keys_vu_prepare_proc AS
SELECT * FROM sys.asymmetric_keys
GO

CREATE FUNCTION sys_asymmetric_keys_vu_prepare_func()
RETURNS INT
AS
BEGIN
RETURN (SELECT COUNT(*) FROM sys.asymmetric_keys WHERE key_length= 0)
END
GO
31 changes: 31 additions & 0 deletions test/JDBC/expected/sys_asymmetric_keys-vu-verify.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
USE master
GO

SELECT * FROM sys.asymmetric_keys
GO
~~START~~
varchar#!#int#!#int#!#char#!#nvarchar#!#varbinary#!#char#!#nvarchar#!#int#!#varbinary#!#nvarchar#!#varbinary#!#nvarchar#!#nvarchar#!#uniqueidentifier#!#sql_variant
~~END~~


SELECT * FROM sys_asymmetric_keys_vu_prepare_view
GO
~~START~~
varchar#!#int#!#int#!#char#!#nvarchar#!#varbinary#!#char#!#nvarchar#!#int#!#varbinary#!#nvarchar#!#varbinary#!#nvarchar#!#nvarchar#!#uniqueidentifier#!#sql_variant
~~END~~


EXEC sys_asymmetric_keys_vu_prepare_proc
GO
~~START~~
varchar#!#int#!#int#!#char#!#nvarchar#!#varbinary#!#char#!#nvarchar#!#int#!#varbinary#!#nvarchar#!#varbinary#!#nvarchar#!#nvarchar#!#uniqueidentifier#!#sql_variant
~~END~~


SELECT sys_asymmetric_keys_vu_prepare_func()
GO
~~START~~
int
0
~~END~~

11 changes: 11 additions & 0 deletions test/JDBC/expected/sys_certificates-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
USE master
GO

DROP VIEW sys_certificates_vu_prepare_view
GO

DROP PROC sys_certificates_vu_prepare_proc
GO

DROP FUNCTION sys_certificates_vu_prepare_func
GO
18 changes: 18 additions & 0 deletions test/JDBC/expected/sys_certificates-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
USE master
GO

CREATE VIEW sys_certificates_vu_prepare_view AS
SELECT * FROM sys.certificates
GO

CREATE PROC sys_certificates_vu_prepare_proc AS
SELECT * FROM sys.certificates
GO

CREATE FUNCTION sys_certificates_vu_prepare_func()
RETURNS INT
AS
BEGIN
RETURN (SELECT COUNT(*) FROM sys.certificates WHERE key_length = 0)
END
GO
31 changes: 31 additions & 0 deletions test/JDBC/expected/sys_certificates-vu-verify.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
USE master
GO

SELECT * FROM sys.certificates
GO
~~START~~
varchar#!#int#!#int#!#char#!#nvarchar#!#bit#!#nvarchar#!#nvarchar#!#varbinary#!#nvarchar#!#nvarchar#!#datetime#!#datetime#!#varbinary#!#nvarchar#!#datetime#!#int
~~END~~


SELECT * FROM sys_certificates_vu_prepare_view
GO
~~START~~
varchar#!#int#!#int#!#char#!#nvarchar#!#bit#!#nvarchar#!#nvarchar#!#varbinary#!#nvarchar#!#nvarchar#!#datetime#!#datetime#!#varbinary#!#nvarchar#!#datetime#!#int
~~END~~


EXEC sys_certificates_vu_prepare_proc
GO
~~START~~
varchar#!#int#!#int#!#char#!#nvarchar#!#bit#!#nvarchar#!#nvarchar#!#varbinary#!#nvarchar#!#nvarchar#!#datetime#!#datetime#!#varbinary#!#nvarchar#!#datetime#!#int
~~END~~


SELECT sys_certificates_vu_prepare_func()
GO
~~START~~
int
0
~~END~~

11 changes: 11 additions & 0 deletions test/JDBC/expected/sys_database_permissions-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
USE master
GO

DROP VIEW sys_database_permissions_vu_prepare_view
GO

DROP PROC sys_database_permissions_vu_prepare_proc
GO

DROP FUNCTION sys_database_permissions_vu_prepare_func
GO
18 changes: 18 additions & 0 deletions test/JDBC/expected/sys_database_permissions-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
USE master
GO

CREATE VIEW sys_database_permissions_vu_prepare_view AS
SELECT * FROM sys.database_permissions
GO

CREATE PROC sys_database_permissions_vu_prepare_proc AS
SELECT * FROM sys.database_permissions
GO

CREATE FUNCTION sys_database_permissions_vu_prepare_func()
RETURNS INT
AS
BEGIN
RETURN (SELECT COUNT(*) FROM sys.database_permissions WHERE state='A')
END
GO
31 changes: 31 additions & 0 deletions test/JDBC/expected/sys_database_permissions-vu-verify.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
USE master
GO

SELECT * FROM sys.database_permissions
GO
~~START~~
tinyint#!#nvarchar#!#int#!#int#!#int#!#int#!#char#!#nvarchar#!#char#!#nvarchar
~~END~~


SELECT * FROM sys_database_permissions_vu_prepare_view
GO
~~START~~
tinyint#!#nvarchar#!#int#!#int#!#int#!#int#!#char#!#nvarchar#!#char#!#nvarchar
~~END~~


EXEC sys_database_permissions_vu_prepare_proc
GO
~~START~~
tinyint#!#nvarchar#!#int#!#int#!#int#!#int#!#char#!#nvarchar#!#char#!#nvarchar
~~END~~


SELECT sys_database_permissions_vu_prepare_func()
GO
~~START~~
int
0
~~END~~

11 changes: 11 additions & 0 deletions test/JDBC/input/views/sys_asymmetric_keys-vu-cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
USE master
GO

DROP VIEW sys_asymmetric_keys_vu_prepare_view
GO

DROP PROC sys_asymmetric_keys_vu_prepare_proc
GO

DROP FUNCTION sys_asymmetric_keys_vu_prepare_func
GO
18 changes: 18 additions & 0 deletions test/JDBC/input/views/sys_asymmetric_keys-vu-prepare.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
USE master
GO

CREATE VIEW sys_asymmetric_keys_vu_prepare_view AS
SELECT * FROM sys.asymmetric_keys
GO

CREATE PROC sys_asymmetric_keys_vu_prepare_proc AS
SELECT * FROM sys.asymmetric_keys
GO

CREATE FUNCTION sys_asymmetric_keys_vu_prepare_func()
RETURNS INT
AS
BEGIN
RETURN (SELECT COUNT(*) FROM sys.asymmetric_keys WHERE key_length= 0)
END
GO
14 changes: 14 additions & 0 deletions test/JDBC/input/views/sys_asymmetric_keys-vu-verify.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
USE master
GO

SELECT * FROM sys.asymmetric_keys
GO

SELECT * FROM sys_asymmetric_keys_vu_prepare_view
GO

EXEC sys_asymmetric_keys_vu_prepare_proc
GO

SELECT sys_asymmetric_keys_vu_prepare_func()
GO
11 changes: 11 additions & 0 deletions test/JDBC/input/views/sys_certificates-vu-cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
USE master
GO

DROP VIEW sys_certificates_vu_prepare_view
GO

DROP PROC sys_certificates_vu_prepare_proc
GO

DROP FUNCTION sys_certificates_vu_prepare_func
GO
Loading

0 comments on commit 17a7631

Please sign in to comment.