From 2a56960d7046dfe81f1d22d11a01ee53a4c04dd1 Mon Sep 17 00:00:00 2001 From: Rohit bhagat <65351720+rohit01010@users.noreply.github.com> Date: Tue, 21 Nov 2023 13:45:59 +0530 Subject: [PATCH 1/7] Added BABEL-4519 related fix in tsql upgrade script 2.8.0--3.0.0 (#2041) Fix added in PR-2019 should also present in babelfishpg_tsql--2.8.0--3.0.0.sql. This PR will update babelfishpg_tsql--2.8.0--3.0.0.sql to add fix mentioned in PR-2019. Updated expected_drop.out. Task: BABEL-4519 Signed-off-by: Rohit Bhagat --- .../babelfishpg_tsql--2.8.0--3.0.0.sql | 20 +++++++++++++++++++ .../expected_drop.out | 1 + 2 files changed, 21 insertions(+) diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.8.0--3.0.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.8.0--3.0.0.sql index 235479aa199..264feeda78f 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.8.0--3.0.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.8.0--3.0.0.sql @@ -6,6 +6,26 @@ SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false) -- please add your SQL here +CREATE OR REPLACE FUNCTION sys.babelfish_update_server_collation_name() RETURNS VOID +LANGUAGE C +AS 'babelfishpg_common', 'babelfish_update_server_collation_name'; + +SELECT sys.babelfish_update_server_collation_name(); + +DROP FUNCTION sys.babelfish_update_server_collation_name(); + +-- reset babelfishpg_tsql.restored_server_collation_name GUC +do +language plpgsql +$$ + declare + query text; + begin + query := pg_catalog.format('alter database %s reset babelfishpg_tsql.restored_server_collation_name', CURRENT_DATABASE()); + execute query; + end; +$$; + CREATE OR REPLACE FUNCTION sys.datepart_internal(IN datepart PG_CATALOG.TEXT, IN arg anyelement,IN df_tz INTEGER DEFAULT 0) RETURNS INTEGER AS $$ DECLARE result INTEGER; diff --git a/test/python/expected/sql_validation_framework/expected_drop.out b/test/python/expected/sql_validation_framework/expected_drop.out index 44393848c03..b6fdedd393e 100644 --- a/test/python/expected/sql_validation_framework/expected_drop.out +++ b/test/python/expected/sql_validation_framework/expected_drop.out @@ -15,6 +15,7 @@ Unexpected drop found for function sys.babelfish_update_server_collation_name in Unexpected drop found for function sys.babelfish_update_server_collation_name in file babelfishpg_tsql--2.5.0--3.0.0.sql Unexpected drop found for function sys.babelfish_update_server_collation_name in file babelfishpg_tsql--2.6.0--3.0.0.sql Unexpected drop found for function sys.babelfish_update_server_collation_name in file babelfishpg_tsql--2.7.0--3.0.0.sql +Unexpected drop found for function sys.babelfish_update_server_collation_name in file babelfishpg_tsql--2.8.0--3.0.0.sql Unexpected drop found for function sys.babelfishpg_common_get_babel_server_collation_oid in file babelfishpg_common--2.2.0--2.3.0.sql Unexpected drop found for function sys.babelfishpg_tsql_get_babel_server_collation_oid in file babelfishpg_tsql--2.2.0--2.3.0.sql Unexpected drop found for function sys.babelfishpg_tsql_get_babel_server_collation_oid in file babelfishpg_tsql--2.3.0--3.0.0.sql From dd23da9b3ada6d662a0246bcbb48e2b3dcaaae37 Mon Sep 17 00:00:00 2001 From: shalinilohia50 <46928246+shalinilohia50@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:45:03 +0530 Subject: [PATCH 2/7] Fix bugs for GRANT/REVOKE on SCHEMA (#2031) Bug fixes for GRANT/REVOKE .. ON SCHEMA 1. Server crash when using empty bracketed name. `schema::[]` 2. Server crash when using empty quoted identifier. `schema::""` 3. When granting permission to yourself, we need a different error message. 4. Error message in not-supported multi-keyword permission should (i) be in uppercase (ii) have a space between keywords 5. Not-supported object type in error message should be in uppercase 6. GRANT ON SCHEMA:: TO PUBLIC does not take effect 7. Specified collation for column names using NAME datatype Issues Resolved : BABEL-4344 Signed-off-by: Shalini Lohia --- contrib/babelfishpg_tsql/sql/ownership.sql | 10 +- .../babelfishpg_tsql--3.3.0--3.4.0.sql | 10 +- contrib/babelfishpg_tsql/src/catalog.c | 193 +++++++++----- contrib/babelfishpg_tsql/src/catalog.h | 2 + contrib/babelfishpg_tsql/src/pl_exec-2.c | 48 ++-- contrib/babelfishpg_tsql/src/pl_handler.c | 82 +++--- contrib/babelfishpg_tsql/src/pltsql_utils.c | 5 +- contrib/babelfishpg_tsql/src/tsqlIface.cpp | 20 ++ .../src/tsqlUnsupportedFeatureHandler.cpp | 8 +- test/JDBC/expected/BABEL-GRANT.out | 34 ++- test/JDBC/expected/GRANT_SCHEMA.out | 236 +++++++++++++++++- test/JDBC/input/BABEL-GRANT.sql | 18 +- test/JDBC/input/GRANT_SCHEMA.mix | 157 +++++++++++- .../expected_create.out | 1 - 14 files changed, 681 insertions(+), 143 deletions(-) diff --git a/contrib/babelfishpg_tsql/sql/ownership.sql b/contrib/babelfishpg_tsql/sql/ownership.sql index ee3a5446a43..a632a918157 100644 --- a/contrib/babelfishpg_tsql/sql/ownership.sql +++ b/contrib/babelfishpg_tsql/sql/ownership.sql @@ -17,11 +17,11 @@ GRANT SELECT on sys.babelfish_sysdatabases TO PUBLIC; -- BABELFISH_SCHEMA_PERMISSIONS CREATE TABLE sys.babelfish_schema_permissions ( dbid smallint NOT NULL, - schema_name NAME NOT NULL, - object_name NAME NOT NULL, - permission NAME NOT NULL, - grantee NAME NOT NULL, - object_type NAME, + schema_name NAME NOT NULL COLLATE sys.database_default, + object_name NAME NOT NULL COLLATE sys.database_default, + permission NAME NOT NULL COLLATE sys.database_default, + grantee NAME NOT NULL COLLATE sys.database_default, + object_type NAME COLLATE sys.database_default, PRIMARY KEY(dbid, schema_name, object_name, permission, grantee) ); diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql index fe141534577..88085d95304 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql @@ -892,11 +892,11 @@ LANGUAGE plpgsql STABLE; -- BABELFISH_SCHEMA_PERMISSIONS CREATE TABLE IF NOT EXISTS sys.babelfish_schema_permissions ( dbid smallint NOT NULL, - schema_name NAME NOT NULL, - object_name NAME NOT NULL, - permission NAME NOT NULL, - grantee NAME NOT NULL, - object_type NAME, + schema_name NAME NOT NULL COLLATE sys.database_default, + object_name NAME NOT NULL COLLATE sys.database_default, + permission NAME NOT NULL COLLATE sys.database_default, + grantee NAME NOT NULL COLLATE sys.database_default, + object_type NAME COLLATE sys.database_default, PRIMARY KEY(dbid, schema_name, object_name, permission, grantee) ); diff --git a/contrib/babelfishpg_tsql/src/catalog.c b/contrib/babelfishpg_tsql/src/catalog.c index 8f1f9bdc2a2..2d832e6a6e6 100644 --- a/contrib/babelfishpg_tsql/src/catalog.c +++ b/contrib/babelfishpg_tsql/src/catalog.c @@ -2843,6 +2843,10 @@ add_entry_to_bbf_schema(const char *schema_name, bool new_record_nulls_bbf_schema[BBF_SCHEMA_PERMS_NUM_OF_COLS]; int16 dbid = get_cur_db_id(); + /* Immediately return, if grantee is NULL or PUBLIC. */ + if ((grantee == NULL) || (strcmp(grantee, "public") == 0)) + return; + /* Fetch the relation */ bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), RowExclusiveLock); @@ -2885,45 +2889,65 @@ check_bbf_schema_for_entry(const char *schema_name, { Relation bbf_schema_rel; HeapTuple tuple_bbf_schema; - ScanKeyData key[5]; - TableScanDesc scan; + ScanKeyData scanKey[5]; + SysScanDesc scan; bool catalog_entry_exists = false; int16 dbid = get_cur_db_id(); + /* Immediately return false, if grantee is NULL or PUBLIC. */ + if ((grantee == NULL) || (strcmp(grantee, "public") == 0)) + return false; + bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), AccessShareLock); - ScanKeyInit(&key[0], + ScanKeyInit(&scanKey[0], Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyInit(&key[1], + ScanKeyEntryInitialize(&scanKey[1], 0, Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyInit(&key[2], + ScanKeyEntryInitialize(&scanKey[2], 0, Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(object_name)); - ScanKeyInit(&key[3], + ScanKeyEntryInitialize(&scanKey[3], 0, Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(permission)); - ScanKeyInit(&key[4], + ScanKeyEntryInitialize(&scanKey[4], 0, Anum_bbf_schema_perms_grantee, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(grantee)); + scan = systable_beginscan(bbf_schema_rel, + get_bbf_schema_perms_idx_oid(), + true, NULL, 5, scanKey); - scan = table_beginscan_catalog(bbf_schema_rel, 5, key); - - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); + tuple_bbf_schema = systable_getnext(scan); if (HeapTupleIsValid(tuple_bbf_schema)) catalog_entry_exists = true; - table_endscan(scan); + systable_endscan(scan); table_close(bbf_schema_rel, AccessShareLock); return catalog_entry_exists; } +/* + * Checks if a particular schema has any SCHEMA level permission granted to any user. + */ bool check_bbf_schema_for_schema(const char *schema_name, const char *object_name, @@ -2932,7 +2956,7 @@ check_bbf_schema_for_schema(const char *schema_name, Relation bbf_schema_rel; HeapTuple tuple_bbf_schema; ScanKeyData key[4]; - TableScanDesc scan; + SysScanDesc scan; bool catalog_entry_exists = false; int16 dbid = get_cur_db_id(); @@ -2942,26 +2966,37 @@ check_bbf_schema_for_schema(const char *schema_name, Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyInit(&key[1], + ScanKeyEntryInitialize(&key[1], 0, Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyInit(&key[2], + ScanKeyEntryInitialize(&key[2], 0, Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(object_name)); - ScanKeyInit(&key[3], + ScanKeyEntryInitialize(&key[3], 0, Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(permission)); - scan = table_beginscan_catalog(bbf_schema_rel, 4, key); + scan = systable_beginscan(bbf_schema_rel, + get_bbf_schema_perms_idx_oid(), + true, NULL, 4, key); - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); + tuple_bbf_schema = systable_getnext(scan); if (HeapTupleIsValid(tuple_bbf_schema)) catalog_entry_exists = true; - table_endscan(scan); + systable_endscan(scan); table_close(bbf_schema_rel, AccessShareLock); return catalog_entry_exists; } @@ -2974,44 +3009,59 @@ del_from_bbf_schema(const char *schema_name, { Relation bbf_schema_rel; HeapTuple tuple_bbf_schema; - ScanKeyData key[5]; - TableScanDesc scan; + ScanKeyData scanKey[5]; + SysScanDesc scan; int16 dbid = get_cur_db_id(); + /* Immediately return, if grantee is NULL or PUBLIC. */ + if ((grantee == NULL) || (strcmp(grantee, "public") == 0)) + return; + bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), RowExclusiveLock); - ScanKeyInit(&key[0], + ScanKeyInit(&scanKey[0], Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyInit(&key[1], + ScanKeyEntryInitialize(&scanKey[1], 0, Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyInit(&key[2], + ScanKeyEntryInitialize(&scanKey[2], 0, Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(object_name)); - ScanKeyInit(&key[3], + ScanKeyEntryInitialize(&scanKey[3], 0, Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(permission)); - ScanKeyInit(&key[4], + ScanKeyEntryInitialize(&scanKey[4], 0, Anum_bbf_schema_perms_grantee, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(grantee)); + scan = systable_beginscan(bbf_schema_rel, + get_bbf_schema_perms_idx_oid(), + true, NULL, 5, scanKey); - scan = table_beginscan_catalog(bbf_schema_rel, 5, key); - - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); + tuple_bbf_schema = systable_getnext(scan); if (HeapTupleIsValid(tuple_bbf_schema)) CatalogTupleDelete(bbf_schema_rel, &tuple_bbf_schema->t_self); - table_endscan(scan); + systable_endscan(scan); table_close(bbf_schema_rel, RowExclusiveLock); - - CommandCounterIncrement(); } void @@ -3035,9 +3085,12 @@ clean_up_bbf_schema(const char *schema_name, Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyInit(&scanKey[1], + ScanKeyEntryInitialize(&scanKey[1], 0, Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(schema_name)); scan = systable_beginscan(bbf_schema_rel, get_bbf_schema_perms_idx_oid(), @@ -3050,13 +3103,19 @@ clean_up_bbf_schema(const char *schema_name, Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyInit(&scanKey[1], + ScanKeyEntryInitialize(&scanKey[1], 0, Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyInit(&scanKey[2], + ScanKeyEntryInitialize(&scanKey[2], 0, Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(object_name)); scan = systable_beginscan(bbf_schema_rel, get_bbf_schema_perms_idx_oid(), @@ -3074,12 +3133,18 @@ clean_up_bbf_schema(const char *schema_name, table_close(bbf_schema_rel, RowExclusiveLock); } +/* + * For all objects belonging to a schema which has OBJECT level permission, + * It grants the permission explicitly when REVOKE has been executed on that + * specific schema. + */ + void grant_perms_to_objects_in_schema(const char *schema_name, const char *permission, const char *grantee) { - TableScanDesc scan; + SysScanDesc scan; Relation bbf_schema_rel; HeapTuple tuple_bbf_schema; const char *object_name; @@ -3095,21 +3160,31 @@ grant_perms_to_objects_in_schema(const char *schema_name, Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyInit(&scanKey[1], + ScanKeyEntryInitialize(&scanKey[1], 0, Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyInit(&scanKey[2], + ScanKeyEntryInitialize(&scanKey[2], 0, Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(permission)); - ScanKeyInit(&scanKey[3], + ScanKeyEntryInitialize(&scanKey[3], 0, Anum_bbf_schema_perms_grantee, - BTEqualStrategyNumber, F_NAMEEQ, + BTEqualStrategyNumber, + InvalidOid, + tsql_get_server_collation_oid_internal(false), + F_NAMEEQ, CStringGetDatum(grantee)); - scan = table_beginscan_catalog(bbf_schema_rel, 4, scanKey); - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); + scan = systable_beginscan(bbf_schema_rel, get_bbf_schema_perms_idx_oid(), + true, NULL, 4, scanKey); + tuple_bbf_schema = systable_getnext(scan); while (HeapTupleIsValid(tuple_bbf_schema)) { @@ -3162,9 +3237,9 @@ grant_perms_to_objects_in_schema(const char *schema_name, /* make sure later steps can see the object created here */ CommandCounterIncrement(); } - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); + tuple_bbf_schema = systable_getnext(scan); } - table_endscan(scan); + systable_endscan(scan); table_close(bbf_schema_rel, AccessShareLock); } diff --git a/contrib/babelfishpg_tsql/src/catalog.h b/contrib/babelfishpg_tsql/src/catalog.h index 7b8ad195c27..c3a7de00859 100644 --- a/contrib/babelfishpg_tsql/src/catalog.h +++ b/contrib/babelfishpg_tsql/src/catalog.h @@ -299,6 +299,8 @@ typedef FormData_bbf_function_ext *Form_bbf_function_ext; #define Anum_bbf_schema_perms_grantee 5 #define Anum_bbf_schema_perms_object_type 6 +#define PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA "ALL" + extern Oid bbf_schema_perms_oid; extern Oid bbf_schema_perms_idx_oid; diff --git a/contrib/babelfishpg_tsql/src/pl_exec-2.c b/contrib/babelfishpg_tsql/src/pl_exec-2.c index 4e948a0be0f..3e98b678e85 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec-2.c +++ b/contrib/babelfishpg_tsql/src/pl_exec-2.c @@ -3683,32 +3683,36 @@ exec_stmt_grantschema(PLtsql_execstate *estate, PLtsql_stmt_grantschema *stmt) char *dbname = get_cur_db_name(); char *login = GetUserNameFromId(GetSessionUserId(), false); bool login_is_db_owner; - Oid datdba; char *rolname; char *schema_name; ListCell *lc; ListCell *lc1; Oid schemaOid; + char *user = GetUserNameFromId(GetUserId(), false); /* * If the login is not the db owner or the login is not the member of * sysadmin or login is not the schema owner, then it doesn't have the permission to GRANT/REVOKE. */ login_is_db_owner = 0 == strncmp(login, get_owner_of_db(dbname), NAMEDATALEN); - datdba = get_role_oid("sysadmin", false); schema_name = get_physical_schema_name(dbname, stmt->schema_name); - schemaOid = LookupExplicitNamespace(schema_name, true); + + if(schema_name) + { + schemaOid = LookupExplicitNamespace(schema_name, true); + } + else + { + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_SCHEMA), + errmsg("An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as \"\" or [] are not allowed. Change the alias to a valid name."))); + } if (!OidIsValid(schemaOid)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_SCHEMA), errmsg("schema \"%s\" does not exist", schema_name))); - - if (!is_member_of_role(GetSessionUserId(), datdba) && !login_is_db_owner && !pg_namespace_ownercheck(schemaOid, GetUserId())) - ereport(ERROR, - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("Cannot find the schema \"%s\", because it does not exist or you do not have permission.", stmt->schema_name))); foreach(lc1, stmt->privileges) { @@ -3718,20 +3722,27 @@ exec_stmt_grantschema(PLtsql_execstate *estate, PLtsql_stmt_grantschema *stmt) char *grantee_name = (char *) lfirst(lc); Oid role_oid; bool grantee_is_db_owner; - rolname = get_physical_user_name(dbname, grantee_name); + if (strcmp(grantee_name, "public") != 0) + rolname = get_physical_user_name(dbname, grantee_name); + else + rolname = pstrdup("public"); role_oid = get_role_oid(rolname, true); grantee_is_db_owner = 0 == strncmp(grantee_name, get_owner_of_db(dbname), NAMEDATALEN); - - if (role_oid == InvalidOid) + if (strcmp(grantee_name, "public") != 0 && role_oid == InvalidOid) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("Cannot find the principal '%s', because it does not exist or you do not have permission.", grantee_name))); - if (pg_namespace_ownercheck(schemaOid, role_oid) || is_member_of_role(role_oid, datdba) || grantee_is_db_owner) + if ((strcmp(rolname, user) == 0) || pg_namespace_ownercheck(schemaOid, role_oid) || is_member_of_role(role_oid, get_sysadmin_oid()) || grantee_is_db_owner) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself."))); + if (!is_member_of_role(GetSessionUserId(), get_sysadmin_oid()) && !login_is_db_owner && !pg_namespace_ownercheck(schemaOid, GetUserId())) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + errmsg("Cannot find the schema \"%s\", because it does not exist or you do not have permission.", stmt->schema_name))); + parsetree_list = gen_grantschema_subcmds(schema_name, rolname, stmt->is_grant, stmt->with_grant_option, priv_name); /* Run all subcommands */ foreach(parsetree_item, parsetree_list) @@ -3761,17 +3772,22 @@ exec_stmt_grantschema(PLtsql_execstate *estate, PLtsql_stmt_grantschema *stmt) CommandCounterIncrement(); } /* Add entry for each grant statement. */ - if (stmt->is_grant && !check_bbf_schema_for_entry(stmt->schema_name, "ALL", priv_name, rolname)) - add_entry_to_bbf_schema(stmt->schema_name, "ALL", priv_name, rolname, NULL); + if (stmt->is_grant && !check_bbf_schema_for_entry(stmt->schema_name, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, priv_name, rolname)) + add_entry_to_bbf_schema(stmt->schema_name, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, priv_name, rolname, NULL); /* Remove entry for each revoke statement. */ - if (!stmt->is_grant && check_bbf_schema_for_entry(stmt->schema_name, "ALL", priv_name, rolname)) + if (!stmt->is_grant && check_bbf_schema_for_entry(stmt->schema_name, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, priv_name, rolname)) { /* If any object in the schema has the OBJECT level permission. Then, internally grant that permission back. */ grant_perms_to_objects_in_schema(stmt->schema_name, priv_name, rolname); - del_from_bbf_schema(stmt->schema_name, "ALL", priv_name, rolname); + del_from_bbf_schema(stmt->schema_name, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, priv_name, rolname); } + pfree(rolname); } } + pfree(user); + pfree(schema_name); + pfree(dbname); + pfree(login); return PLTSQL_RC_OK; } diff --git a/contrib/babelfishpg_tsql/src/pl_handler.c b/contrib/babelfishpg_tsql/src/pl_handler.c index 10297b0c90e..ab83ccdf4af 100644 --- a/contrib/babelfishpg_tsql/src/pl_handler.c +++ b/contrib/babelfishpg_tsql/src/pl_handler.c @@ -3641,7 +3641,10 @@ bbf_ProcessUtility(PlannedStmt *pstmt, char *permissions[] = {"select", "insert", "update", "references", "delete"}; for(i = 0; i < 5; i++) { - if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, obj, permissions[i], rol_spec->rolename)) + /* + * If object permission doesn't exist already, add an entry to the catalog. + */ + if (!check_bbf_schema_for_entry(logical_schema, obj, permissions[i], rol_spec->rolename)) add_entry_to_bbf_schema(logical_schema, obj, permissions[i], rol_spec->rolename, obj_type); } } @@ -3657,10 +3660,15 @@ bbf_ProcessUtility(PlannedStmt *pstmt, char *permissions[] = {"select", "insert", "update", "references", "delete"}; for(i = 0; i < 5; i++) { - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logical_schema, "ALL", permissions[i], rol_spec->rolename) && !has_schema_perms) + /* + * 1. If only schema permission exists, don't revoke any permission. + * 2. If only object permission exists, delete entry from the catalog and revoke permission. + * 3. If both schema and object permission exist, don't revoke any permission but delete object + * entry from the catalog. + */ + if (check_bbf_schema_for_entry(logical_schema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, permissions[i], rol_spec->rolename) && !has_schema_perms) has_schema_perms = true; - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logical_schema, obj, permissions[i], rol_spec->rolename)) - del_from_bbf_schema(logical_schema, obj, permissions[i], rol_spec->rolename); + del_from_bbf_schema(logical_schema, obj, permissions[i], rol_spec->rolename); } if (has_schema_perms) return; @@ -3687,7 +3695,12 @@ bbf_ProcessUtility(PlannedStmt *pstmt, foreach(lc, grant->grantees) { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - if ((ap->cols == NULL) && (rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, obj, ap->priv_name, rol_spec->rolename)) + /* + * Don't add an entry, if the permission is granted on column list. + */ + if (ap->cols != NULL) + break; + if (!check_bbf_schema_for_entry(logical_schema, obj, ap->priv_name, rol_spec->rolename)) add_entry_to_bbf_schema(logical_schema, obj, ap->priv_name, rol_spec->rolename, obj_type); } } @@ -3700,7 +3713,7 @@ bbf_ProcessUtility(PlannedStmt *pstmt, * 1. If GRANT on schema does not exist, execute REVOKE statement and remove the catalog entry if exists. * 2. If GRANT on schema exist, only remove the entry from the catalog if exists. */ - if ((logical_schema != NULL) && (rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, "ALL", ap->priv_name, rol_spec->rolename)) + if ((logical_schema != NULL) && !check_bbf_schema_for_entry(logical_schema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, ap->priv_name, rol_spec->rolename)) { if (prev_ProcessUtility) prev_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, @@ -3709,8 +3722,12 @@ bbf_ProcessUtility(PlannedStmt *pstmt, standard_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, queryEnv, dest, qc); } - if ((ap->cols == NULL) && (rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logical_schema, obj, ap->priv_name, rol_spec->rolename)) - del_from_bbf_schema(logical_schema, obj, ap->priv_name, rol_spec->rolename); + /* + * Don't remove an entry, if the permission is revoked on column list. + */ + if (ap->cols != NULL) + break; + del_from_bbf_schema(logical_schema, obj, ap->priv_name, rol_spec->rolename); } } } @@ -3743,28 +3760,28 @@ bbf_ProcessUtility(PlannedStmt *pstmt, logicalschema = get_logical_schema_name(schemaname, true); funcname = strVal(func); } - /* - * Case: When ALL PRIVILEGES is revoked internally during create function. - * Check if schema entry exists in the catalog, do not revoke any permission if exists. - */ - if (pstmt->stmt_len == 0 && list_length(grant->privileges) == 0) - { - if(check_bbf_schema_for_schema(logicalschema, "ALL", "execute")) - return; - break; - } + /* If ALL PRIVILEGES is granted/revoked. */ if (list_length(grant->privileges) == 0) { + /* + * Case: When ALL PRIVILEGES is revoked internally during create function. + * Check if schema entry exists in the catalog, do not revoke any permission if exists. + */ + if (pstmt->stmt_len == 0) + { + if(check_bbf_schema_for_schema(logicalschema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, "execute")) + return; + } + if (grant->is_grant) { foreach(lc, grant->grantees) { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logicalschema, funcname, "execute", rol_spec->rolename)) + if (!check_bbf_schema_for_entry(logicalschema, funcname, "execute", rol_spec->rolename)) add_entry_to_bbf_schema(logicalschema, funcname, "execute", rol_spec->rolename, obj_type); } - break; } else { @@ -3772,15 +3789,14 @@ bbf_ProcessUtility(PlannedStmt *pstmt, { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); bool has_schema_perms = false; - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logicalschema, "ALL", "execute", rol_spec->rolename) && !has_schema_perms) + if (check_bbf_schema_for_entry(logicalschema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, "execute", rol_spec->rolename) && !has_schema_perms) has_schema_perms = true; - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logicalschema, funcname, "execute", rol_spec->rolename)) - del_from_bbf_schema(logicalschema, funcname, "execute", rol_spec->rolename); + del_from_bbf_schema(logicalschema, funcname, "execute", rol_spec->rolename); if (has_schema_perms) return; } - break; } + break; } foreach(lc1, grant->privileges) { @@ -3798,9 +3814,11 @@ bbf_ProcessUtility(PlannedStmt *pstmt, foreach(lc, grant->grantees) { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - /* Don't store a row in catalog, if permission is granted for column */ - if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logicalschema, funcname, ap->priv_name, rol_spec->rolename)) + /* Add an entry to the catalog, if an entry doesn't exist already. */ + if (!check_bbf_schema_for_entry(logicalschema, funcname, ap->priv_name, rol_spec->rolename)) + { add_entry_to_bbf_schema(logicalschema, funcname, ap->priv_name, rol_spec->rolename, obj_type); + } } } else @@ -3809,10 +3827,10 @@ bbf_ProcessUtility(PlannedStmt *pstmt, { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); /* - * 1. If GRANT on schema does not exist, execute REVOKE statement and remove the catalog entry if exists. - * 2. If GRANT on schema exist, only remove the entry from the catalog if exists. - */ - if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logicalschema, "ALL", ap->priv_name, rol_spec->rolename)) + * 1. If GRANT on schema does not exist, execute REVOKE statement and remove the catalog entry if exists. + * 2. If GRANT on schema exist, only remove the entry from the catalog if exists. + */ + if (!check_bbf_schema_for_entry(logicalschema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, ap->priv_name, rol_spec->rolename)) { /* Execute REVOKE statement. */ if (prev_ProcessUtility) @@ -3822,8 +3840,8 @@ bbf_ProcessUtility(PlannedStmt *pstmt, standard_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, queryEnv, dest, qc); } - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logicalschema, funcname, ap->priv_name, rol_spec->rolename)) - del_from_bbf_schema(logicalschema, funcname, ap->priv_name, rol_spec->rolename); + /* Remove an entry from the catalog, if it exists. */ + del_from_bbf_schema(logicalschema, funcname, ap->priv_name, rol_spec->rolename); } } } diff --git a/contrib/babelfishpg_tsql/src/pltsql_utils.c b/contrib/babelfishpg_tsql/src/pltsql_utils.c index df3c57df719..d635d81ab7a 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_utils.c +++ b/contrib/babelfishpg_tsql/src/pltsql_utils.c @@ -1036,7 +1036,10 @@ update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char if (grantee && stmt->grantees) { RoleSpec *tmp = (RoleSpec *) llast(stmt->grantees); - + if (strcmp(grantee, "public") == 0) + { + tmp->roletype = ROLESPEC_PUBLIC; + } tmp->rolename = pstrdup(grantee); } diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index 695b28dc468..be3ceece6cb 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -5527,6 +5527,11 @@ makeGrantdbStatement(TSqlParser::Security_statementContext *ctx) char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); grantee_list = lappend(grantee_list, grantee_name); } + if (prin->PUBLIC()) + { + char *grantee_name = pstrdup("public"); + grantee_list = lappend(grantee_list, grantee_name); + } } result->grantees = grantee_list; return (PLtsql_stmt *) result; @@ -5555,6 +5560,11 @@ makeGrantdbStatement(TSqlParser::Security_statementContext *ctx) char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); grantee_list = lappend(grantee_list, grantee_name); } + if (prin->PUBLIC()) + { + char *grantee_name = pstrdup("public"); + grantee_list = lappend(grantee_list, grantee_name); + } } result->grantees = grantee_list; return (PLtsql_stmt *) result; @@ -5585,6 +5595,11 @@ makeGrantdbStatement(TSqlParser::Security_statementContext *ctx) char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); grantee_list = lappend(grantee_list, grantee_name); } + if (prin->PUBLIC()) + { + char *grantee_name = pstrdup("public"); + grantee_list = lappend(grantee_list, grantee_name); + } } List *privilege_list = NIL; for (auto perm: ctx->grant_statement()->permissions()->permission()) @@ -5637,6 +5652,11 @@ makeGrantdbStatement(TSqlParser::Security_statementContext *ctx) char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); grantee_list = lappend(grantee_list, grantee_name); } + if (prin->PUBLIC()) + { + char *grantee_name = pstrdup("public"); + grantee_list = lappend(grantee_list, grantee_name); + } } List *privilege_list = NIL; for (auto perm: ctx->revoke_statement()->permissions()->permission()) diff --git a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp index 29cdc5ac320..64a4d12f89e 100644 --- a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp @@ -1704,7 +1704,8 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedGrantStmt(TSqlParser::Gran continue; else { - unsupported_feature = "GRANT PERMISSION " + perm->getText(); + unsupported_feature = "GRANT PERMISSION " + ::getFullText(single_perm); + std::transform(unsupported_feature.begin(), unsupported_feature.end(), unsupported_feature.begin(), ::toupper); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(perm)); } } @@ -1719,6 +1720,7 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedGrantStmt(TSqlParser::Gran if (obj_type && !(obj_type->OBJECT() || obj_type->SCHEMA())) { unsupported_feature = "GRANT ON " + obj_type->getText(); + std::transform(unsupported_feature.begin(), unsupported_feature.end(), unsupported_feature.begin(), ::toupper); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(obj_type)); } } @@ -1798,7 +1800,8 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedRevokeStmt(TSqlParser::Rev continue; else { - unsupported_feature = "REVOKE PERMISSION " + perm->getText(); + unsupported_feature = "REVOKE PERMISSION " + ::getFullText(single_perm); + std::transform(unsupported_feature.begin(), unsupported_feature.end(), unsupported_feature.begin(), ::toupper); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(perm)); } } @@ -1813,6 +1816,7 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedRevokeStmt(TSqlParser::Rev if (obj_type && !(obj_type->OBJECT() || obj_type->SCHEMA())) { unsupported_feature = "REVOKE ON " + obj_type->getText(); + std::transform(unsupported_feature.begin(), unsupported_feature.end(), unsupported_feature.begin(), ::toupper); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(obj_type)); } } diff --git a/test/JDBC/expected/BABEL-GRANT.out b/test/JDBC/expected/BABEL-GRANT.out index d3f48b241fe..2a59cf3dead 100644 --- a/test/JDBC/expected/BABEL-GRANT.out +++ b/test/JDBC/expected/BABEL-GRANT.out @@ -174,7 +174,7 @@ GO REVOKE SELECT ON SCHEMA::scm FROM guest; GO -GRANT SHOWPLAN ON OBJECT::t1 TO guest; -- unsupported permission +GRANT showplan ON OBJECT::t1 TO guest; -- unsupported permission GO ~~ERROR (Code: 33557097)~~ @@ -188,20 +188,48 @@ GO ~~ERROR (Message: 'REVOKE PERMISSION SHOWPLAN' is not currently supported in Babelfish)~~ -GRANT ALL ON SCHEMA::scm TO guest; -- unsupported class +GRANT ALL ON SCHEMA::scm TO guest; GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The all permission has been deprecated and is not available for this class of entity.)~~ -REVOKE ALL ON SCHEMA::scm TO guest; -- unsupported class +REVOKE ALL ON SCHEMA::scm TO guest; GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The all permission has been deprecated and is not available for this class of entity.)~~ +GRANT create table ON OBJECT::t1 TO guest; -- unsupported permission +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: 'GRANT PERMISSION CREATE TABLE' is not currently supported in Babelfish)~~ + + +REVOKE create table ON OBJECT::t2 FROM alogin; -- unsupported permission +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: 'REVOKE PERMISSION CREATE TABLE' is not currently supported in Babelfish)~~ + + +GRANT SELECT ON table::t1 TO guest; -- unsupported object +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: 'GRANT ON TABLE' is not currently supported in Babelfish)~~ + + +REVOKE SELECT ON table::t1 FROM guest; -- unsupported object +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: 'REVOKE ON TABLE' is not currently supported in Babelfish)~~ + + GRANT ALL ON OBJECT::t1 TO guest WITH GRANT OPTION AS superuser; GO ~~ERROR (Code: 33557097)~~ diff --git a/test/JDBC/expected/GRANT_SCHEMA.out b/test/JDBC/expected/GRANT_SCHEMA.out index 1891d685978..935acbe2f53 100644 --- a/test/JDBC/expected/GRANT_SCHEMA.out +++ b/test/JDBC/expected/GRANT_SCHEMA.out @@ -12,9 +12,18 @@ go create user babel_4344_u1 for login babel_4344_l1; go +create login αιώνια with password = '12345678' +go + +create user αιώνια for login αιώνια; +go + create schema babel_4344_s1; go +create schema αγάπη; +go + create schema babel_4344_s2 authorization babel_4344_u1; go @@ -27,6 +36,9 @@ go create table babel_4344_s2.babel_4344_t1(a int); go +create table αγάπη.abc(a int); +go + create table babel_4344_t3(a int, b int); go @@ -45,12 +57,69 @@ go create proc babel_4344_s1.babel_4344_p1 as select 2; go +create proc babel_4344_s1.babel_4344_p3 as select 3; +go + CREATE FUNCTION babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.tables) END go CREATE FUNCTION babel_4344_s1.babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END go +grant SELECT on schema::babel_4344_S1 to public, αιώνια; +go + +grant select on schema::αγάπη to αιώνια; +go + +-- tsql user=αιώνια password=12345678 +use babel_4344_d1; +go + +select * from αγάπη.abc; +go +~~START~~ +int +~~END~~ + + +select * from babel_4344_S1.babel_4344_t1; +go +~~START~~ +int +~~END~~ + + +use master; +go + +-- tsql user=babel_4344_l1 password=12345678 +use babel_4344_d1; +go + +-- User has select privileges, tables and views be accessible +select * from babel_4344_s1.babel_4344_t1 +go +~~START~~ +int +~~END~~ + +select * from babel_4344_s1.babel_4344_v1; +go +~~START~~ +int +2 +~~END~~ + +use master; +go + +-- tsql +use babel_4344_d1; +go +revoke select on schema::babel_4344_s1 from public, αιώνια; +go + -- tsql user=babel_4344_l1 password=12345678 use babel_4344_d1; go @@ -117,9 +186,9 @@ go -- GRANT OBJECT privilege use babel_4344_d1; go -grant select on babel_4344_t1 to babel_4344_u1; +grant SELECT on babel_4344_t1 to BABEL_4344_U1; go -grant select on babel_4344_s1.babel_4344_t1 to babel_4344_u1; +grant SELECT on babel_4344_s1.babel_4344_t1 to babel_4344_u1; go grant all on babel_4344_s1.babel_4344_t1 to babel_4344_u1; go @@ -135,7 +204,14 @@ grant execute on babel_4344_p1 to babel_4344_u1; go grant execute on babel_4344_s1.babel_4344_p1 to babel_4344_u1; go -grant execute on babel_4344_f1 to babel_4344_u1; +-- inside a transaction, permission will not be granted since it is rolled back +begin transaction; +exec sp_executesql N'grant execute on babel_4344_s1.babel_4344_p3 to babel_4344_u1;'; +rollback transaction; +go + +-- Mixed case +grant Execute on Babel_4344_F1 to babel_4344_u1; go grant execute on babel_4344_s1.babel_4344_f1 to babel_4344_u1; go @@ -152,8 +228,36 @@ go ~~ERROR (Message: Cannot find the principal 'jdbc_user', because it does not exist or you do not have permission.)~~ -grant select on schema::babel_4344_s2 to guest; -- should pass +grant SELECT on schema::babel_4344_s2 to guest; -- should pass +go +grant select on schema::"" to guest; -- should fail go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.)~~ + +grant select on schema::non_existing_schema to guest; -- should fail +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: schema "non_existing_schema" does not exist)~~ + +-- grant statement via a procedure +create procedure grant_perm_proc as begin exec('grant select on schema::[] to guest') end; +go +exec grant_perm_proc; -- should fail +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.)~~ + +-- non-existing role +grant SELECT on schema::dbo to guest, babel_4344_u3; -- should fail +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Cannot find the principal 'babel_4344_u3', because it does not exist or you do not have permission.)~~ + -- tsql user=babel_4344_l1 password=12345678 -- User has OBJECT privileges, should be accessible. @@ -215,6 +319,12 @@ int 2 ~~END~~ +exec babel_4344_s1.babel_4344_p3; -- should fail, grant statement was rolled back +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: permission denied for procedure babel_4344_p3)~~ + select * from babel_4344_f1(); go ~~START~~ @@ -242,7 +352,7 @@ grant select on schema::babel_4344_s1 to babel_4344_u1; -- should fail go ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Cannot find the schema "babel_4344_s1", because it does not exist or you do not have permission.)~~ +~~ERROR (Message: Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself.)~~ use master; go @@ -256,6 +366,19 @@ go use master; go +-- psql +-- GRANT statement add an entry to the catalog +select schema_name, object_name, permission, grantee from sys.babelfish_schema_permissions +where schema_name = 'babel_4344_s1' collate "C" and object_name = 'ALL' collate "C" order by permission; +go +~~START~~ +name#!#name#!#name#!#name +babel_4344_s1#!#ALL#!#execute#!#babel_4344_d1_babel_4344_u1 +babel_4344_s1#!#ALL#!#insert#!#babel_4344_d1_babel_4344_u1 +babel_4344_s1#!#ALL#!#select#!#babel_4344_d1_babel_4344_u1 +~~END~~ + + -- tsql user=babel_4344_l1 password=12345678 -- User has OBJECT and SCHEMA privileges, should be accessible. use babel_4344_d1; @@ -295,7 +418,7 @@ select * from babel_4344_s1.babel_4344_f1(); go ~~START~~ int -10 +11 ~~END~~ use master; @@ -339,14 +462,14 @@ int 2 ~~END~~ -exec babel_4344_s1.babel_4344_p1; -- TODO: should be accessible +exec babel_4344_s1.babel_4344_p1; go ~~START~~ int 2 ~~END~~ -select * from babel_4344_s1.babel_4344_f1(); -- TODO: should be accessible +select * from babel_4344_s1.babel_4344_f1(); go ~~START~~ int @@ -412,7 +535,7 @@ select * from babel_4344_s1.babel_4344_f2(); go ~~START~~ int -14 +15 ~~END~~ use master; @@ -477,7 +600,7 @@ select * from babel_4344_s1.babel_4344_f1(); go ~~START~~ int -14 +15 ~~END~~ select * from babel_4344_s2.babel_4344_t1; @@ -498,6 +621,15 @@ go use master; go +-- psql +-- REVOKE on schema removes the entry from the catalog +select * from sys.babelfish_schema_permissions where schema_name = 'babel_4344_s1' collate sys.database_default; +go +~~START~~ +int2#!#name#!#name#!#name#!#name#!#name +~~END~~ + + -- tsql user=babel_4344_l1 password=12345678 -- User has no privileges, shouldn't be accessible. use babel_4344_d1; @@ -541,6 +673,54 @@ go use master; go +-- psql +-- grant object permission +grant select on babel_4344_s1.babel_4344_t1 to babel_4344_d1_babel_4344_u1; +go + +-- tsql +-- grant schema permission +use babel_4344_d1; +go +grant select on schema::babel_4344_s1 to babel_4344_u1; +go +use master +go + +-- tsql user=babel_4344_l1 password=12345678 +use babel_4344_d1; +go +select * from babel_4344_s1.babel_4344_t1; -- accessible +go +~~START~~ +int +2 +3 +3 +4 +5 +~~END~~ + +use master +go + +-- psql +-- revoke schema permission +revoke select on all tables in schema babel_4344_s1 from babel_4344_d1_babel_4344_u1; +go + +-- tsql user=babel_4344_l1 password=12345678 +use babel_4344_d1; +go +select * from babel_4344_s1.babel_4344_t1; -- not accessible +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: permission denied for table babel_4344_t1)~~ + +use master +go + -- tsql -- Drop objects use babel_4344_d1; @@ -579,6 +759,9 @@ go drop proc babel_4344_s1.babel_4344_p2; go +drop proc babel_4344_s1.babel_4344_p3; +go + drop function babel_4344_f1; go @@ -597,9 +780,18 @@ go drop schema babel_4344_s2; go +drop table αγάπη.abc; +go + +drop schema αγάπη; +go + drop user babel_4344_u1; go +drop user αιώνια; +go + use master; go @@ -629,3 +821,27 @@ void -- tsql drop login babel_4344_l1; go + +-- psql +-- Need to terminate active session before cleaning up the login +SELECT pg_terminate_backend(pid) FROM pg_stat_get_activity(NULL) +WHERE sys.suser_name(usesysid) = 'αιώνια' AND backend_type = 'client backend' AND usesysid IS NOT NULL; +go +~~START~~ +bool +t +~~END~~ + + +-- Wait to sync with another session +SELECT pg_sleep(1); +go +~~START~~ +void + +~~END~~ + + +-- tsql +drop login αιώνια; +go diff --git a/test/JDBC/input/BABEL-GRANT.sql b/test/JDBC/input/BABEL-GRANT.sql index 3e0155ea283..8388f782ffd 100644 --- a/test/JDBC/input/BABEL-GRANT.sql +++ b/test/JDBC/input/BABEL-GRANT.sql @@ -164,16 +164,28 @@ GO REVOKE SELECT ON SCHEMA::scm FROM guest; GO -GRANT SHOWPLAN ON OBJECT::t1 TO guest; -- unsupported permission +GRANT showplan ON OBJECT::t1 TO guest; -- unsupported permission GO REVOKE SHOWPLAN ON OBJECT::t2 TO alogin; -- unsupported permission GO -GRANT ALL ON SCHEMA::scm TO guest; -- unsupported class +GRANT ALL ON SCHEMA::scm TO guest; GO -REVOKE ALL ON SCHEMA::scm TO guest; -- unsupported class +REVOKE ALL ON SCHEMA::scm TO guest; +GO + +GRANT create table ON OBJECT::t1 TO guest; -- unsupported permission +GO + +REVOKE create table ON OBJECT::t2 FROM alogin; -- unsupported permission +GO + +GRANT SELECT ON table::t1 TO guest; -- unsupported object +GO + +REVOKE SELECT ON table::t1 FROM guest; -- unsupported object GO GRANT ALL ON OBJECT::t1 TO guest WITH GRANT OPTION AS superuser; diff --git a/test/JDBC/input/GRANT_SCHEMA.mix b/test/JDBC/input/GRANT_SCHEMA.mix index 1572bea803b..f4af9f7af76 100644 --- a/test/JDBC/input/GRANT_SCHEMA.mix +++ b/test/JDBC/input/GRANT_SCHEMA.mix @@ -12,9 +12,18 @@ go create user babel_4344_u1 for login babel_4344_l1; go +create login αιώνια with password = '12345678' +go + +create user αιώνια for login αιώνια; +go + create schema babel_4344_s1; go +create schema αγάπη; +go + create schema babel_4344_s2 authorization babel_4344_u1; go @@ -27,6 +36,9 @@ go create table babel_4344_s2.babel_4344_t1(a int); go +create table αγάπη.abc(a int); +go + create table babel_4344_t3(a int, b int); go @@ -45,12 +57,52 @@ go create proc babel_4344_s1.babel_4344_p1 as select 2; go +create proc babel_4344_s1.babel_4344_p3 as select 3; +go + CREATE FUNCTION babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.tables) END go CREATE FUNCTION babel_4344_s1.babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END go +grant SELECT on schema::babel_4344_S1 to public, αιώνια; +go + +grant select on schema::αγάπη to αιώνια; +go + +-- tsql user=αιώνια password=12345678 +use babel_4344_d1; +go + +select * from αγάπη.abc; +go + +select * from babel_4344_S1.babel_4344_t1; +go + +use master; +go + +-- tsql user=babel_4344_l1 password=12345678 +use babel_4344_d1; +go + +-- User has select privileges, tables and views be accessible +select * from babel_4344_s1.babel_4344_t1 +go +select * from babel_4344_s1.babel_4344_v1; +go +use master; +go + +-- tsql +use babel_4344_d1; +go +revoke select on schema::babel_4344_s1 from public, αιώνια; +go + -- tsql user=babel_4344_l1 password=12345678 use babel_4344_d1; go @@ -81,9 +133,9 @@ go -- GRANT OBJECT privilege use babel_4344_d1; go -grant select on babel_4344_t1 to babel_4344_u1; +grant SELECT on babel_4344_t1 to BABEL_4344_U1; go -grant select on babel_4344_s1.babel_4344_t1 to babel_4344_u1; +grant SELECT on babel_4344_s1.babel_4344_t1 to babel_4344_u1; go grant all on babel_4344_s1.babel_4344_t1 to babel_4344_u1; go @@ -99,7 +151,14 @@ grant execute on babel_4344_p1 to babel_4344_u1; go grant execute on babel_4344_s1.babel_4344_p1 to babel_4344_u1; go -grant execute on babel_4344_f1 to babel_4344_u1; +-- inside a transaction, permission will not be granted since it is rolled back +begin transaction; +exec sp_executesql N'grant execute on babel_4344_s1.babel_4344_p3 to babel_4344_u1;'; +rollback transaction; +go + +-- Mixed case +grant Execute on Babel_4344_F1 to babel_4344_u1; go grant execute on babel_4344_s1.babel_4344_f1 to babel_4344_u1; go @@ -108,7 +167,19 @@ grant select on schema::babel_4344_s2 to babel_4344_u1; -- should fail go grant select on schema::babel_4344_s2 to jdbc_user; -- should fail go -grant select on schema::babel_4344_s2 to guest; -- should pass +grant SELECT on schema::babel_4344_s2 to guest; -- should pass +go +grant select on schema::"" to guest; -- should fail +go +grant select on schema::non_existing_schema to guest; -- should fail +go +-- grant statement via a procedure +create procedure grant_perm_proc as begin exec('grant select on schema::[] to guest') end; +go +exec grant_perm_proc; -- should fail +go +-- non-existing role +grant SELECT on schema::dbo to guest, babel_4344_u3; -- should fail go -- tsql user=babel_4344_l1 password=12345678 @@ -133,6 +204,8 @@ exec babel_4344_p1; go exec babel_4344_s1.babel_4344_p1; go +exec babel_4344_s1.babel_4344_p3; -- should fail, grant statement was rolled back +go select * from babel_4344_f1(); go select * from babel_4344_s1.babel_4344_f1(); @@ -156,6 +229,12 @@ go use master; go +-- psql +-- GRANT statement add an entry to the catalog +select schema_name, object_name, permission, grantee from sys.babelfish_schema_permissions +where schema_name = 'babel_4344_s1' collate "C" and object_name = 'ALL' collate "C" order by permission; +go + -- tsql user=babel_4344_l1 password=12345678 -- User has OBJECT and SCHEMA privileges, should be accessible. use babel_4344_d1; @@ -196,9 +275,9 @@ select * from babel_4344_s1.babel_4344_t3 -- not accessible go select * from babel_4344_s1.babel_4344_v1; go -exec babel_4344_s1.babel_4344_p1; -- TODO: should be accessible +exec babel_4344_s1.babel_4344_p1; go -select * from babel_4344_s1.babel_4344_f1(); -- TODO: should be accessible +select * from babel_4344_s1.babel_4344_f1(); go select * from babel_4344_s2.babel_4344_t1; go @@ -287,6 +366,11 @@ go use master; go +-- psql +-- REVOKE on schema removes the entry from the catalog +select * from sys.babelfish_schema_permissions where schema_name = 'babel_4344_s1' collate sys.database_default; +go + -- tsql user=babel_4344_l1 password=12345678 -- User has no privileges, shouldn't be accessible. use babel_4344_d1; @@ -306,6 +390,41 @@ go use master; go +-- psql +-- grant object permission +grant select on babel_4344_s1.babel_4344_t1 to babel_4344_d1_babel_4344_u1; +go + +-- tsql +-- grant schema permission +use babel_4344_d1; +go +grant select on schema::babel_4344_s1 to babel_4344_u1; +go +use master +go + +-- tsql user=babel_4344_l1 password=12345678 +use babel_4344_d1; +go +select * from babel_4344_s1.babel_4344_t1; -- accessible +go +use master +go + +-- psql +-- revoke schema permission +revoke select on all tables in schema babel_4344_s1 from babel_4344_d1_babel_4344_u1; +go + +-- tsql user=babel_4344_l1 password=12345678 +use babel_4344_d1; +go +select * from babel_4344_s1.babel_4344_t1; -- not accessible +go +use master +go + -- tsql -- Drop objects use babel_4344_d1; @@ -344,6 +463,9 @@ go drop proc babel_4344_s1.babel_4344_p2; go +drop proc babel_4344_s1.babel_4344_p3; +go + drop function babel_4344_f1; go @@ -362,9 +484,18 @@ go drop schema babel_4344_s2; go +drop table αγάπη.abc; +go + +drop schema αγάπη; +go + drop user babel_4344_u1; go +drop user αιώνια; +go + use master; go @@ -384,3 +515,17 @@ go -- tsql drop login babel_4344_l1; go + +-- psql +-- Need to terminate active session before cleaning up the login +SELECT pg_terminate_backend(pid) FROM pg_stat_get_activity(NULL) +WHERE sys.suser_name(usesysid) = 'αιώνια' AND backend_type = 'client backend' AND usesysid IS NOT NULL; +go + +-- Wait to sync with another session +SELECT pg_sleep(1); +go + +-- tsql +drop login αιώνια; +go diff --git a/test/python/expected/sql_validation_framework/expected_create.out b/test/python/expected/sql_validation_framework/expected_create.out index 26777ae841c..6be51616c03 100644 --- a/test/python/expected/sql_validation_framework/expected_create.out +++ b/test/python/expected/sql_validation_framework/expected_create.out @@ -72,7 +72,6 @@ Could not find tests for procedure sys.printarg Could not find tests for procedure sys.sp_cursor_list Could not find tests for procedure sys.sp_describe_cursor Could not find tests for table sys.babelfish_helpcollation -Could not find tests for table sys.babelfish_schema_permissions Could not find tests for table sys.babelfish_syslanguages Could not find tests for table sys.service_settings Could not find tests for table sys.spt_datatype_info_table From 0a4cb02c7feb6b83d1b0449596d4cac9b5994627 Mon Sep 17 00:00:00 2001 From: Tanzeel Khan <140405735+tanscorpio7@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:46:02 +0530 Subject: [PATCH 3/7] update error message to include config option (#2043) Error message for repeatable read and serializable should have the config option value. Issues Resolved : BABEL-4145 Signed-off-by: Tanzeel Khan tzlkhan@amazon.com --- .../babelfishpg_tsql/src/backend_parser/gram-tsql-rule.y | 4 ++-- test/JDBC/expected/BABEL-3214.out | 4 ++-- test/JDBC/expected/BABEL_4145.out | 8 ++++---- test/JDBC/expected/TestIsolationLevels.out | 4 ++-- test/JDBC/expected/TestTransactionsSQLBatch.out | 4 ++-- test/python/expected/pymssql/TestTransactionsSQLBatch.out | 4 ++-- test/python/expected/pyodbc/TestTransactionsSQLBatch.out | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-rule.y b/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-rule.y index 98bc9d16d67..01c35364232 100644 --- a/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-rule.y +++ b/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-rule.y @@ -4416,7 +4416,7 @@ tsql_IsolationLevelStr: TSQLInstrumentation(INSTR_UNSUPPORTED_TSQL_ISOLATION_LEVEL_REPEATABLE_READ); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to get PG repeatable read isolation level."), + errmsg("Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to 'pg_isolation' to get PG repeatable read isolation level."), parser_errposition(@1))); } @@ -4438,7 +4438,7 @@ tsql_IsolationLevelStr: TSQLInstrumentation(INSTR_UNSUPPORTED_TSQL_ISOLATION_LEVEL_SERIALIZABLE); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ config option to get PG serializable isolation level."), + errmsg("Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_serializable’ config option to 'pg_isolation' to get PG serializable isolation level."), parser_errposition(@1))); } } diff --git a/test/JDBC/expected/BABEL-3214.out b/test/JDBC/expected/BABEL-3214.out index d770fdc5af5..c14fe5b0fac 100644 --- a/test/JDBC/expected/BABEL-3214.out +++ b/test/JDBC/expected/BABEL-3214.out @@ -44,7 +44,7 @@ SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to get PG repeatable read isolation level.)~~ +~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to 'pg_isolation' to get PG repeatable read isolation level.)~~ SELECT CAST(current_setting('transaction_isolation') AS VARCHAR); SELECT transaction_isolation_level from sys.dm_exec_sessions WHERE session_id = @@SPID; @@ -65,7 +65,7 @@ SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ config option to get PG serializable isolation level.)~~ +~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_serializable’ config option to 'pg_isolation' to get PG serializable isolation level.)~~ SELECT CAST(current_setting('transaction_isolation') AS VARCHAR); SELECT transaction_isolation_level from sys.dm_exec_sessions WHERE session_id = @@SPID; diff --git a/test/JDBC/expected/BABEL_4145.out b/test/JDBC/expected/BABEL_4145.out index e52cb738e67..7fadfedf469 100644 --- a/test/JDBC/expected/BABEL_4145.out +++ b/test/JDBC/expected/BABEL_4145.out @@ -115,7 +115,7 @@ SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to get PG repeatable read isolation level.)~~ +~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to 'pg_isolation' to get PG repeatable read isolation level.)~~ SELECT current_setting('transaction_isolation'); GO @@ -137,7 +137,7 @@ SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ config option to get PG serializable isolation level.)~~ +~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_serializable’ config option to 'pg_isolation' to get PG serializable isolation level.)~~ SELECT current_setting('transaction_isolation'); GO @@ -208,7 +208,7 @@ SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ config option to get PG serializable isolation level.)~~ +~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_serializable’ config option to 'pg_isolation' to get PG serializable isolation level.)~~ SELECT current_setting('transaction_isolation'); GO @@ -261,7 +261,7 @@ SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to get PG repeatable read isolation level.)~~ +~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to 'pg_isolation' to get PG repeatable read isolation level.)~~ SELECT current_setting('transaction_isolation'); GO diff --git a/test/JDBC/expected/TestIsolationLevels.out b/test/JDBC/expected/TestIsolationLevels.out index 83a45c49504..f8fcd463086 100644 --- a/test/JDBC/expected/TestIsolationLevels.out +++ b/test/JDBC/expected/TestIsolationLevels.out @@ -22,7 +22,7 @@ set transaction isolation level repeatable read; go ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to get PG repeatable read isolation level.)~~ +~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to 'pg_isolation' to get PG repeatable read isolation level.)~~ set transaction isolation level snapshot; @@ -32,7 +32,7 @@ set transaction isolation level serializable; go ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ config option to get PG serializable isolation level.)~~ +~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_serializable’ config option to 'pg_isolation' to get PG serializable isolation level.)~~ select set_config('default_transaction_isolation', 'read uncommitted', false); diff --git a/test/JDBC/expected/TestTransactionsSQLBatch.out b/test/JDBC/expected/TestTransactionsSQLBatch.out index 5db75c6d93b..e1a531820a5 100644 --- a/test/JDBC/expected/TestTransactionsSQLBatch.out +++ b/test/JDBC/expected/TestTransactionsSQLBatch.out @@ -108,7 +108,7 @@ int set transaction isolation level repeatable read; ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to get PG repeatable read isolation level.)~~ +~~ERROR (Message: Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to 'pg_isolation' to get PG repeatable read isolation level.)~~ #show transaction_isolation; #show default_transaction_isolation; @@ -374,7 +374,7 @@ int set transaction isolation level serializable; ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ config option to get PG serializable isolation level.)~~ +~~ERROR (Message: Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_serializable’ config option to 'pg_isolation' to get PG serializable isolation level.)~~ #show transaction_isolation; #show default_transaction_isolation; diff --git a/test/python/expected/pymssql/TestTransactionsSQLBatch.out b/test/python/expected/pymssql/TestTransactionsSQLBatch.out index 80824c2898b..e6aeddff3be 100644 --- a/test/python/expected/pymssql/TestTransactionsSQLBatch.out +++ b/test/python/expected/pymssql/TestTransactionsSQLBatch.out @@ -129,7 +129,7 @@ int set transaction isolation level repeatable read; ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: 'Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to get PG repeatable read isolation level.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n')~~ +~~ERROR (Message: 'Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to 'pg_isolation' to get PG repeatable read isolation level.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n')~~ #show transaction_isolation; #show default_transaction_isolation; @@ -430,7 +430,7 @@ int # begin transaction name -> save transaction name -> rollback tran name, Rollback whole transaction set transaction isolation level serializable; ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: 'Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ config option to get PG serializable isolation level.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n')~~ +~~ERROR (Message: 'Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_serializable’ config option to 'pg_isolation' to get PG serializable isolation level.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n')~~ #show transaction_isolation; #show default_transaction_isolation; diff --git a/test/python/expected/pyodbc/TestTransactionsSQLBatch.out b/test/python/expected/pyodbc/TestTransactionsSQLBatch.out index 81236fc80ca..f97475bc268 100644 --- a/test/python/expected/pyodbc/TestTransactionsSQLBatch.out +++ b/test/python/expected/pyodbc/TestTransactionsSQLBatch.out @@ -107,7 +107,7 @@ int set transaction isolation level repeatable read; ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: [42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to get PG repeatable read isolation level. (33557097) (SQLExecDirectW))~~ +~~ERROR (Message: [42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Isolation level ‘REPEATABLE READ’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_repeatable_read’ config option to 'pg_isolation' to get PG repeatable read isolation level. (33557097) (SQLExecDirectW))~~ #show transaction_isolation; #show default_transaction_isolation; @@ -372,7 +372,7 @@ int # begin transaction name -> save transaction name -> rollback tran name, Rollback whole transaction set transaction isolation level serializable; ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: [42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ config option to get PG serializable isolation level. (33557097) (SQLExecDirectW))~~ +~~ERROR (Message: [42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Isolation level ‘SERIALIZABLE’ is not currently supported in Babelfish. Set ‘babelfishpg_tsql.isolation_level_serializable’ config option to 'pg_isolation' to get PG serializable isolation level. (33557097) (SQLExecDirectW))~~ #show transaction_isolation; #show default_transaction_isolation; From a695d88e21a3b0418f2d49a1539a759e48be7d19 Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Tue, 21 Nov 2023 18:24:31 +0530 Subject: [PATCH 4/7] Resolve TDS protocol violation occurring due to parallel query enforced (#1937) This issue was mainly caused by incorrect inference of typmod information for numeric expression where its being set to default when Parallel worker is planned. Reason for the same is explained below: When parallel query is enforced, Postgres engine planes Gather node on the top of top plan. For example, consider following query - SELECT amount + 100 FROM overflow_test where id = 1 -- If parallel query is not enforced- Query Text: SELECT amount + 100 FROM overflow_test where id = 1 Index Scan using overflow_test_pkey on master_dbo.overflow_test (cost=0.15..8.17 rows=1 width=32) Output: ((amount)::numeric + '100'::numeric) Index Cond: (overflow_test.id = 1) -- If parallel query is enforced then Postgres will wrap the above plan under Gather node - Query Text: SELECT amount + 100 FROM overflow_test where id = 1 Gather (cost=0.15..8.17 rows=1 width=32) Output: (((amount)::numeric + '100'::numeric)) Workers Planned: 1 Single Copy: true -> Index Scan using overflow_test_pkey on master_dbo.overflow_test (cost=0.15..8.17 rows=1 width=32) Output: ((amount)::numeric + '100'::numeric) Index Cond: (overflow_test.id = 1) When Postgres does this, it also modifies targetlist of gather node to refer to the tuples returned by its lefttree subplan or outerplan (Indexscan in this case). Hence, targetlist of gather node will contain only one tle in above case which is Var with attno = OUTER_VAR (it indicates reference to its outer plan) and vartypmod being -1. Now, While sending metadata from TDS layer we use this typmod to deduce max_scale and precision for numeric. This would be set to default since vartypmod = -1 whereas actual data being computed may not fit in it hence it will run into an error while sending numeric response. Hence, hang or crash of end client software. This commit fixes this issue by taking special Var into account while We extract the information of outer plan from planned stmt and use the same to get the original/referenced tle from outer plan. This commit further improves the implementation of resolve_numeric_typmod_from_exp to handle reference to outer var correctly. It can now handle Append and MergeAppend node correctly which was required for following test case - -- setup create table t1 (a numeric(6,4), b numeric(6,3)); insert into t1 values (4, 16); insert into t1 values (10.1234, 10.123); insert into t1 values (1.2, 6); insert into t1 values (NULL, 101.123); -- test select a from t1 UNION All select b from t1; For this UNION ALL expression, typmod was always computed to be -1 which is not right and it should (7,4) ideally. This commit introduces helped function called resolve_numeric_typmod_from_append_or_mergeappend to compute typmod for expression correctly. Task: BABEL-4424, BABEL-4359 Signed-off-by: Dipesh Dhameliya --- .../src/backend/tds/tdsprinttup.c | 10 +- .../src/backend/tds/tdsresponse.c | 156 +++- .../babelfishpg_tds/src/backend/tds/tdsrpc.c | 13 +- .../src/include/tds_response.h | 6 +- contrib/babelfishpg_tsql/src/hooks.c | 22 +- test/JDBC/expected/BABEL-3943.out | 7 +- test/JDBC/expected/BABEL-4424.out | 883 ++++++++++++++++++ test/JDBC/expected/babel_613.out | 22 +- test/JDBC/input/BABEL-3943.mix | 5 - test/JDBC/input/BABEL-4424.sql | 400 ++++++++ test/JDBC/input/babel_613.sql | 8 +- test/JDBC/parallel_query_jdbc_schedule | 18 +- 12 files changed, 1475 insertions(+), 75 deletions(-) create mode 100644 test/JDBC/expected/BABEL-4424.out create mode 100644 test/JDBC/input/BABEL-4424.sql diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsprinttup.c b/contrib/babelfishpg_tds/src/backend/tds/tdsprinttup.c index 006f2bca156..bc1b9251cb2 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsprinttup.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsprinttup.c @@ -60,6 +60,13 @@ TdsPrinttupStartup(DestReceiver *self, int operation, TupleDesc typeinfo) { DR_printtup *myState = (DR_printtup *) self; Portal portal = myState->portal; + PlannedStmt *plannedStmt = PortalGetPrimaryStmt(portal); + List *targetList = NIL; + + if (portal->strategy != PORTAL_MULTI_QUERY) + { + targetList = FetchStatementTargetList((Node *) plannedStmt); + } /* * Create I/O buffer to be used for all messages. This cannot be inside @@ -78,7 +85,8 @@ TdsPrinttupStartup(DestReceiver *self, int operation, TupleDesc typeinfo) ALLOCSET_DEFAULT_SIZES); TdsSendRowDescription(typeinfo, - FetchPortalTargetList(portal), + plannedStmt, + targetList, portal->formats); return; } diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c index 6baaaeb264b..4cbe2c48efe 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c @@ -26,6 +26,7 @@ #include "miscadmin.h" #include "nodes/pathnodes.h" #include "parser/parse_coerce.h" +#include "parser/parsetree.h" #include "utils/fmgroids.h" #include "utils/lsyscache.h" #include "utils/syscache.h" @@ -128,6 +129,8 @@ static void FillTabNameWithoutNumParts(StringInfo buf, uint8 numParts, TdsRelati static void SetTdsEstateErrorData(void); static void ResetTdsEstateErrorData(void); static void SetAttributesForColmetada(TdsColumnMetaData *col); +static int32 resolve_numeric_typmod_from_exp(Plan *plan, Node *expr); +static int32 resolve_numeric_typmod_outer_var(Plan *plan, AttrNumber attno); static inline void SendPendingDone(bool more) @@ -401,9 +404,112 @@ PrintTupPrepareInfo(DR_printtup *myState, TupleDesc typeinfo, int numAttrs) } } +static int32 +resolve_numeric_typmod_from_append_or_mergeappend(Plan *plan, AttrNumber attno) +{ + ListCell *lc; + int32 max_precision = 0, + max_scale = 0, + precision = 0, + scale = 0, + integralDigitCount = 0, + typmod = -1, + result_typmod = -1; + List *planlist = NIL; + if (IsA(plan, Append)) + { + planlist = ((Append *) plan)->appendplans; + } + else if(IsA(plan, MergeAppend)) + { + planlist = ((MergeAppend *) plan)->mergeplans; + } + + Assert(planlist != NIL); + foreach(lc, planlist) + { + TargetEntry *tle; + Plan *outerplan = (Plan *) lfirst(lc); + + /* if outerplan is SubqueryScan then use actual subplan */ + if (IsA(outerplan, SubqueryScan)) + outerplan = ((SubqueryScan *)outerplan)->subplan; + + tle = get_tle_by_resno(outerplan->targetlist, attno); + if (IsA(tle->expr, Var)) + { + Var *var = (Var *)tle->expr; + if (var->varno == OUTER_VAR) + { + typmod = resolve_numeric_typmod_outer_var(outerplan, var->varattno); + } + else + { + typmod = resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr); + } + } + else + { + typmod = resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr); + } + if (typmod == -1) + continue; + scale = (typmod - VARHDRSZ) & 0xffff; + precision = ((typmod - VARHDRSZ) >> 16) & 0xffff; + integralDigitCount = Max(precision - scale, max_precision - max_scale); + max_scale = Max(max_scale, scale); + max_precision = integralDigitCount + max_scale; + /* + * If max_precision is more than TDS_MAX_NUM_PRECISION then adjust precision + * to TDS_MAX_NUM_PRECISION at the cost of scale. + */ + if (max_precision > TDS_MAX_NUM_PRECISION) + { + max_scale = Max(0, max_scale - (max_precision - TDS_MAX_NUM_PRECISION)); + max_precision = TDS_MAX_NUM_PRECISION; + } + result_typmod = ((max_precision << 16) | max_scale) + VARHDRSZ; + } + /* If max_precision is still default then use tds specific defaults */ + if (result_typmod == -1) + { + result_typmod = ((tds_default_numeric_precision << 16) | tds_default_numeric_scale) + VARHDRSZ; + } + return result_typmod; +} + +static int32 +resolve_numeric_typmod_outer_var(Plan *plan, AttrNumber attno) +{ + TargetEntry *tle; + Plan *outerplan = NULL; + + if (IsA(plan, Append) || IsA(plan, MergeAppend)) + return resolve_numeric_typmod_from_append_or_mergeappend(plan, attno); + else + outerplan = outerPlan(plan); + + /* if outerplan is SubqueryScan then use actual subplan */ + if (IsA(outerplan, SubqueryScan)) + outerplan = ((SubqueryScan *)outerplan)->subplan; + + /* outerplan must not be NULL */ + Assert(outerplan); + tle = get_tle_by_resno(outerplan->targetlist, attno); + if (IsA(tle->expr, Var)) + { + Var *var = (Var *)tle->expr; + if (var->varno == OUTER_VAR) + { + return resolve_numeric_typmod_outer_var(outerplan, var->varattno); + } + } + return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr); +} + /* look for a typmod to return from a numeric expression */ static int32 -resolve_numeric_typmod_from_exp(Node *expr) +resolve_numeric_typmod_from_exp(Plan *plan, Node *expr) { if (expr == NULL) return -1; @@ -434,6 +540,12 @@ resolve_numeric_typmod_from_exp(Node *expr) { Var *var = (Var *) expr; + /* If this var referes to tuple returned by its outer plan then find the original tle from it */ + if (var->varno == OUTER_VAR) + { + Assert(plan); + return (resolve_numeric_typmod_outer_var(plan, var->varattno)); + } return var->vartypmod; } case T_OpExpr: @@ -464,8 +576,8 @@ resolve_numeric_typmod_from_exp(Node *expr) { arg1 = linitial(op->args); arg2 = lsecond(op->args); - typmod1 = resolve_numeric_typmod_from_exp(arg1); - typmod2 = resolve_numeric_typmod_from_exp(arg2); + typmod1 = resolve_numeric_typmod_from_exp(plan, arg1); + typmod2 = resolve_numeric_typmod_from_exp(plan, arg2); scale1 = (typmod1 - VARHDRSZ) & 0xffff; precision1 = ((typmod1 - VARHDRSZ) >> 16) & 0xffff; scale2 = (typmod2 - VARHDRSZ) & 0xffff; @@ -474,7 +586,7 @@ resolve_numeric_typmod_from_exp(Node *expr) else if (list_length(op->args) == 1) { arg1 = linitial(op->args); - typmod1 = resolve_numeric_typmod_from_exp(arg1); + typmod1 = resolve_numeric_typmod_from_exp(plan, arg1); scale1 = (typmod1 - VARHDRSZ) & 0xffff; precision1 = ((typmod1 - VARHDRSZ) >> 16) & 0xffff; scale2 = 0; @@ -545,7 +657,7 @@ resolve_numeric_typmod_from_exp(Node *expr) scale = Min(precision, TDS_MAX_NUM_PRECISION) - integralDigitCount; /* - * precisionn adjustment to TDS_MAX_NUM_PRECISION + * precision adjustment to TDS_MAX_NUM_PRECISION */ if (precision > TDS_MAX_NUM_PRECISION) precision = TDS_MAX_NUM_PRECISION; @@ -653,7 +765,7 @@ resolve_numeric_typmod_from_exp(Node *expr) Assert(nullif->args != NIL); arg1 = linitial(nullif->args); - return resolve_numeric_typmod_from_exp(arg1); + return resolve_numeric_typmod_from_exp(plan, arg1); } case T_CoalesceExpr: { @@ -676,7 +788,7 @@ resolve_numeric_typmod_from_exp(Node *expr) foreach(lc, coale->args) { arg = lfirst(lc); - arg_typmod = resolve_numeric_typmod_from_exp(arg); + arg_typmod = resolve_numeric_typmod_from_exp(plan, arg); /* return -1 if we fail to resolve one of the arg's typmod */ if (arg_typmod == -1) return -1; @@ -717,7 +829,7 @@ resolve_numeric_typmod_from_exp(Node *expr) { casewhen = lfirst(lc); casewhen_result = (Node *) casewhen->result; - typmod = resolve_numeric_typmod_from_exp(casewhen_result); + typmod = resolve_numeric_typmod_from_exp(plan, casewhen_result); /* * return -1 if we fail to resolve one of the result's @@ -752,7 +864,7 @@ resolve_numeric_typmod_from_exp(Node *expr) Assert(aggref->args != NIL); te = (TargetEntry *) linitial(aggref->args); - typmod = resolve_numeric_typmod_from_exp((Node *) te->expr); + typmod = resolve_numeric_typmod_from_exp(plan, (Node *) te->expr); aggFuncName = get_func_name(aggref->aggfnoid); scale = (typmod - VARHDRSZ) & 0xffff; @@ -798,7 +910,7 @@ resolve_numeric_typmod_from_exp(Node *expr) { PlaceHolderVar *phv = (PlaceHolderVar *) expr; - return resolve_numeric_typmod_from_exp((Node *) phv->phexpr); + return resolve_numeric_typmod_from_exp(plan, (Node *) phv->phexpr); } case T_RelabelType: { @@ -807,7 +919,7 @@ resolve_numeric_typmod_from_exp(Node *expr) if (rlt->resulttypmod != -1) return rlt->resulttypmod; else - return resolve_numeric_typmod_from_exp((Node *) rlt->arg); + return resolve_numeric_typmod_from_exp(plan, (Node *) rlt->arg); } /* TODO handle more Expr types if needed */ default: @@ -1562,8 +1674,8 @@ TdsGetGenericTypmod(Node *expr) * for a relation. (used for keyset and dynamic cursors) */ void -PrepareRowDescription(TupleDesc typeinfo, List *targetlist, int16 *formats, - bool extendedInfo, bool fetchPkeys) +PrepareRowDescription(TupleDesc typeinfo, PlannedStmt *plannedstmt, List *targetlist, + int16 *formats, bool extendedInfo, bool fetchPkeys) { int natts = typeinfo->natts; int attno; @@ -1782,7 +1894,16 @@ PrepareRowDescription(TupleDesc typeinfo, List *targetlist, int16 *formats, * than -1. */ if (atttypmod == -1 && tle != NULL) - atttypmod = resolve_numeric_typmod_from_exp((Node *) tle->expr); + { + if (!plannedstmt || !plannedstmt->planTree) + { + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("Internal error detected while calculating the precision of numeric expression"), + errhint("plannedstmt is NULL while calculating the precision of numeric expression when it contains outer var"))); + } + atttypmod = resolve_numeric_typmod_from_exp(plannedstmt->planTree, (Node *) tle->expr); + } /* * Get the precision and scale out of the typmod value if @@ -2558,7 +2679,7 @@ TdsSendInfoOrError(int token, int number, int state, int class, } void -TdsSendRowDescription(TupleDesc typeinfo, +TdsSendRowDescription(TupleDesc typeinfo, PlannedStmt *plannedstmt, List *targetlist, int16 *formats) { TDSRequest request = TdsRequestCtrl->request; @@ -2567,7 +2688,7 @@ TdsSendRowDescription(TupleDesc typeinfo, Assert(typeinfo != NULL); /* Prepare the column metadata first */ - PrepareRowDescription(typeinfo, targetlist, formats, false, false); + PrepareRowDescription(typeinfo, plannedstmt, targetlist, formats, false, false); /* * If fNoMetadata flags is set in RPC header flag, the server doesn't need @@ -3293,7 +3414,8 @@ TDSStatementExceptionCallback(PLtsql_execstate *estate, PLtsql_stmt *stmt, bool void SendColumnMetadata(TupleDesc typeinfo, List *targetlist, int16 *formats) { - TdsSendRowDescription(typeinfo, targetlist, formats); + /* This will only be used for sp_preapre request hence do not need to pass plannedstmt */ + TdsSendRowDescription(typeinfo, NULL, targetlist, formats); TdsPrintTupShutdown(); } diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsrpc.c b/contrib/babelfishpg_tds/src/backend/tds/tdsrpc.c index d559825280e..363afd7fc8d 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsrpc.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsrpc.c @@ -2334,10 +2334,15 @@ static void SendCursorResponse(TDSRequestSP req) { int cmd_type = TDS_CMD_UNKNOWN; - Portal portal; - /* fetch the portal */ - portal = GetPortalFromCursorHandle(req->cursorHandle, false); + Portal portal = GetPortalFromCursorHandle(req->cursorHandle, false); + PlannedStmt *plannedStmt = PortalGetPrimaryStmt(portal); + List *targetList = NIL; + + if (portal->strategy != PORTAL_MULTI_QUERY) + { + targetList = FetchStatementTargetList((Node *) plannedStmt); + } /* * If we are in aborted transaction state, we can't run @@ -2366,7 +2371,7 @@ SendCursorResponse(TDSRequestSP req) * break the protocol. We also need to fetch the primary keys for dynamic * and keyset cursors (XXX: these cursors are not yet implemented). */ - PrepareRowDescription(portal->tupDesc, FetchPortalTargetList(portal), + PrepareRowDescription(portal->tupDesc, plannedStmt, targetList, portal->formats, true, (req->scrollopt & (SP_CURSOR_SCROLLOPT_DYNAMIC | SP_CURSOR_SCROLLOPT_KEYSET))); diff --git a/contrib/babelfishpg_tds/src/include/tds_response.h b/contrib/babelfishpg_tds/src/include/tds_response.h index 92504287dc2..698b52fa208 100644 --- a/contrib/babelfishpg_tds/src/include/tds_response.h +++ b/contrib/babelfishpg_tds/src/include/tds_response.h @@ -70,8 +70,8 @@ extern void TdsSendDone(int tag, int status, extern void SendColumnMetadataToken(int natts, bool sendRowStat); extern void SendTabNameToken(void); extern void SendColInfoToken(int natts, bool sendRowStat); -extern void PrepareRowDescription(TupleDesc typeinfo, List *targetlist, int16 *formats, - bool extendedInfo, bool fetchPkeys); +extern void PrepareRowDescription(TupleDesc typeinfo, PlannedStmt *plannedstmt, List *targetlist, + int16 *formats, bool extendedInfo, bool fetchPkeys); extern void SendReturnValueTokenInternal(ParameterToken token, uint8 status, FmgrInfo *finfo, Datum datum, bool isNull, bool forceCoercion); @@ -85,7 +85,7 @@ extern void TdsSendEnvChangeBinary(int envid, void *old, int old_nbytes); extern void TdsSendReturnStatus(int status); extern void TdsSendHandle(void); -extern void TdsSendRowDescription(TupleDesc typeinfo, +extern void TdsSendRowDescription(TupleDesc typeinfo, PlannedStmt *PlannedStmt, List *targetlist, int16 *formats); extern bool TdsPrintTup(TupleTableSlot *slot, DestReceiver *self); extern void TdsPrintTupShutdown(void); diff --git a/contrib/babelfishpg_tsql/src/hooks.c b/contrib/babelfishpg_tsql/src/hooks.c index b0f955b5d57..9047a6360ab 100644 --- a/contrib/babelfishpg_tsql/src/hooks.c +++ b/contrib/babelfishpg_tsql/src/hooks.c @@ -2917,8 +2917,13 @@ pltsql_detect_numeric_overflow(int weight, int dscale, int first_block, int nume if (sql_dialect != SQL_DIALECT_TSQL) return false; - total_digit_count = (dscale == 0) ? (weight * numeric_base) : - ((weight + 1) * numeric_base); + if (weight < 0) + { + /* weight < 0 means the integral part of the number is 0 */ + total_digit_count = dscale; + return (total_digit_count > TDS_NUMERIC_MAX_PRECISION); + } + total_digit_count = weight * numeric_base; /* * calculating exact #digits in the first partially filled numeric block, @@ -2931,7 +2936,7 @@ pltsql_detect_numeric_overflow(int weight, int dscale, int first_block, int nume /* * check if the first numeric block is partially filled If yes, add those - * digit count Else if fully filled, Ignore as those digits are already + * digit count Else if fully filled, Ignore as those digits might be already * added to total_digit_count */ if (partially_filled_numeric_block < pow(10, numeric_base - 1)) @@ -2941,18 +2946,13 @@ pltsql_detect_numeric_overflow(int weight, int dscale, int first_block, int nume int log_10 = (int) log10(partially_filled_numeric_block); // keep compiler happy total_digit_count += log_10 + 1; } - else - total_digit_count += 1; } /* - * calculating exact #digits in last block if decimal point exists If - * dscale is an exact multiple of numeric_base, last block is not - * partially filled, then, ignore as those digits are already added to - * total_digit_count Else, add the remainder digits + * Add dscale or display scale, the nominal precision expressed as number + * of digits after the decimal point. */ - if (dscale > 0) - total_digit_count += (dscale % numeric_base); + total_digit_count += dscale; return (total_digit_count > TDS_NUMERIC_MAX_PRECISION); } diff --git a/test/JDBC/expected/BABEL-3943.out b/test/JDBC/expected/BABEL-3943.out index 7210ff54445..d4e5339c23c 100644 --- a/test/JDBC/expected/BABEL-3943.out +++ b/test/JDBC/expected/BABEL-3943.out @@ -16,7 +16,6 @@ GO -- tsql --- TODO: Fix BABEL-4359 SELECT avg([owner_amounts].[tax]) FROM [owner_amounts] WHERE moment_id = 862 and ISNULL([owner_amounts].[active], 0) = 1 AND [owner_amounts].[tax] is not null GO ~~START~~ @@ -25,7 +24,6 @@ numeric ~~END~~ --- TODO: Fix BABEL-4359 SELECT avg([owner_amounts].[tax]) FROM [owner_amounts] WHERE moment_id = 862 and cast([owner_amounts].[active] as smallint) = 1 AND [owner_amounts].[tax] is not null GO ~~START~~ @@ -34,7 +32,6 @@ numeric ~~END~~ --- TODO: Fix BABEL-4359 SELECT TOP 1 [owner_amounts].[tax] FROM [owner_amounts] WHERE moment_id = 862 and cast([owner_amounts].[active] as smallint) = 1 GO ~~START~~ @@ -43,16 +40,14 @@ numeric ~~END~~ --- TODO: Fix BABEL-4359 SELECT avg([owner_amounts].[tax]) FROM [owner_amounts] WHERE moment_id = 862 and cast([owner_amounts].[active] as int) = 1 AND [owner_amounts].[tax] is not null GO ~~START~~ numeric -0E-8 +0.000000 ~~END~~ --- TODO: Fix BABEL-4359 SELECT TOP 1 [owner_amounts].[tax] FROM [owner_amounts] WHERE moment_id = 862 and cast([owner_amounts].[active] as int) = 1 GO ~~START~~ diff --git a/test/JDBC/expected/BABEL-4424.out b/test/JDBC/expected/BABEL-4424.out new file mode 100644 index 00000000000..5659724c1a5 --- /dev/null +++ b/test/JDBC/expected/BABEL-4424.out @@ -0,0 +1,883 @@ +create table babel_4359_t1 (a numeric(6,4), b numeric(6,3), c numeric); +go + +insert into babel_4359_t1 values (4, 16, 1111); +insert into babel_4359_t1 values (10.1234, 10.123, 222222); +insert into babel_4359_t1 values (1.2, 6, 33333333333333333); +insert into babel_4359_t1 values (NULL, 101.123, 444444444444444444); +insert into babel_4359_t1 values (10.123, NULL, 444444444444444444.44); +insert into babel_4359_t1 values (10.12, 10.1234, NULL); +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +select * from + ( + select a as col from babel_4359_t1 Union All + select b as col from babel_4359_t1 + ) dummy +order by col +go +~~START~~ +numeric + + +1.2000 +4.0000 +6.0000 +10.1200 +10.1230 +10.1230 +10.1230 +10.1234 +16.0000 +101.1230 +~~END~~ + + +select * from + ( + select a as col from babel_4359_t1 union all + select b as col from babel_4359_t1 union all + select c as col from babel_4359_t1 + ) dummy +order by col +go +~~START~~ +numeric + + + +1.2000 +4.0000 +6.0000 +10.1200 +10.1230 +10.1230 +10.1230 +10.1234 +16.0000 +101.1230 +1111.0000 +222222.0000 +33333333333333333.0000 +444444444444444444.0000 +444444444444444444.0000 +~~END~~ + + + +select * from + ( + select avg(a) as col from babel_4359_t1 union all + select avg(b) as col from babel_4359_t1 + ) dummy +order by col +select * from + ( + select a + b as col from babel_4359_t1 Union All + select b + c as col from babel_4359_t1 + ) dummy +order by col +go +~~START~~ +numeric +7.113280 +28.673800 +~~END~~ + +~~START~~ +numeric + + + + +7.2000 +20.0000 +20.2430 +20.2464 +1127.0000 +222232.1230 +33333333333333339.0000 +444444444444444545.1230 +~~END~~ + + +select * from + ( + (select a as col from babel_4359_t1 order by a) union all + (select b as col from babel_4359_t1 order by a) union all + (select c as col from babel_4359_t1 order by a) + ) dummy +order by col +go +~~START~~ +numeric + + + +1.2000 +4.0000 +6.0000 +10.1200 +10.1230 +10.1230 +10.1230 +10.1234 +16.0000 +101.1230 +1111.0000 +222222.0000 +33333333333333333.0000 +444444444444444444.0000 +444444444444444444.0000 +~~END~~ + + + +select * from + ( + (select min(a) as col from babel_4359_t1 ) union all + (select min(b) as col from babel_4359_t1 ) union all + (select min(c) as col from babel_4359_t1 ) + ) dummy +order by col +select min(col) from + ( + (select min(a) as col from babel_4359_t1 ) union all + (select min(b) as col from babel_4359_t1 ) union all + (select min(c) as col from babel_4359_t1 ) + ) dummy +go +~~START~~ +numeric +1.2000 +6.0000 +1111.0000 +~~END~~ + +~~START~~ +numeric +1.2000 +~~END~~ + + +select * from + ( + select max(a + b) as col from babel_4359_t1 Union All + select min(b + c) as col from babel_4359_t1 + ) dummy +order by col +go +~~START~~ +numeric +20.2464 +1127.0000 +~~END~~ + + +create table events (event_id numeric(6,3) primary key); +create table other_events (event_id numeric(6,5) primary key); +create table other_events_2 (event_id numeric); +go + +insert into events values (100.123), (10.12); +insert into other_events values (1.123456); +insert into other_events_2 values (111111111111111111), (NULL); +go +~~ROW COUNT: 2~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 2~~ + + +-- merge append node +select event_id + from ((select event_id from events order by event_id) + union all + (select event_id from other_events order by event_id) + union all + (select event_id from other_events_2 order by event_id)) ss +order by event_id; +go +~~START~~ +numeric + +1.12346 +10.12000 +100.12300 +111111111111111111.00000 +~~END~~ + + +drop table babel_4359_t1 +go +drop table events; +go +drop table other_events; +go +drop table other_events_2; +go + +create table babel_4424_t1 (a numeric(38,0)); +go + +create table babel_4424_t2 (a numeric(6,4)); +go + +insert into babel_4424_t1 values (9999999999999999999999999999999999999); +insert into babel_4424_t2 values (99.9999); +insert into babel_4424_t1 values (1111111111111111111111111111111111111); +insert into babel_4424_t2 values (11.1111); +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +select * from + ( + select a col from babel_4424_t1 + union all + select a col from babel_4424_t2 + )dummy +order by col; +go +~~START~~ +numeric +11 +99 +1111111111111111111111111111111111111 +9999999999999999999999999999999999999 +~~END~~ + + +select * from + ( select a + a from babel_4424_t1 ) dummy +go +~~START~~ +numeric +19999999999999999999999999999999999998 +2222222222222222222222222222222222222 +~~END~~ + + +select * from + ( + select a col from babel_4424_t1 + union all + select a + a col from babel_4424_t1 + )dummy +order by col; +go +~~START~~ +numeric +1111111111111111111111111111111111111 +2222222222222222222222222222222222222 +9999999999999999999999999999999999999 +19999999999999999999999999999999999998 +~~END~~ + + +select * from + ( + select a + a col from babel_4424_t1 + union all + select a col from babel_4424_t2 + )dummy +order by col; +go +~~START~~ +numeric +11 +99 +2222222222222222222222222222222222222 +19999999999999999999999999999999999998 +~~END~~ + + +create table babel_4424_t3 (a numeric(37,1)); +GO + +create table babel_4424_t4 (a numeric(38,1)); +GO + +insert into babel_4424_t3 values (999999999999999999999999999999999999.9); +insert into babel_4424_t3 values (111111111111111111111111111111111111.1); +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +insert into babel_4424_t4 values (9999999999999999999999999999999999999.9); +insert into babel_4424_t4 values (1111111111111111111111111111111111111.1); +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +select * from (select a + a from babel_4424_t3) dummy; +go +~~START~~ +numeric +1999999999999999999999999999999999999.8 +222222222222222222222222222222222222.2 +~~END~~ + + +select * from + ( + select a col from babel_4424_t3 + union all + select a col from babel_4424_t2 + ) dummy +order by col; +GO +~~START~~ +numeric +11.11 +99.99 +111111111111111111111111111111111111.10 +999999999999999999999999999999999999.90 +~~END~~ + + +select * from + ( + select a col from babel_4424_t3 + union all + select a col from babel_4424_t4 + ) dummy +order by col; +GO +~~START~~ +numeric +111111111111111111111111111111111111.1 +999999999999999999999999999999999999.9 +1111111111111111111111111111111111111.1 +9999999999999999999999999999999999999.9 +~~END~~ + + +create table babel_4424_t5 (a numeric(38, 37)); +GO + +create table babel_4424_t6 (a numeric(10, 10)); +GO + +insert into babel_4424_t5 values (9.99999999999999999999999999999999999); +insert into babel_4424_t6 values (0.9999999999); +insert into babel_4424_t5 values (1.11111111111111111111111111111111111); +insert into babel_4424_t6 values (0.1111111111); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +select * from ( select a + a from babel_4424_t5) dummy; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +select * from ( select a + a from babel_4424_t6) dummy; +GO +~~START~~ +numeric +1.9999999998 +0.2222222222 +~~END~~ + + +select * from + ( + select a col from babel_4424_t5 + union all + select a col from babel_4424_t6 + ) dummy +order by col; +GO +~~START~~ +numeric +0.1111111111000000000000000000000000000 +0.9999999999000000000000000000000000000 +1.1111111111111111111111111111111111100 +9.9999999999999999999999999999999999900 +~~END~~ + + +DROP TABLE babel_4424_t1; +go +DROP TABLE babel_4424_t2; +go +DROP TABLE babel_4424_t3; +go +DROP TABLE babel_4424_t4; +go +DROP TABLE babel_4424_t5; +go +DROP TABLE babel_4424_t6; +go + +create table babel_4424_t1 (a numeric(38,0) primary key); +go + +create table babel_4424_t2(a numeric(6,3) primary key); +go + +insert into babel_4424_t1 values (99999999999999999999999999999999999999); +insert into babel_4424_t2 values (99.9999); +insert into babel_4424_t1 values (11111111111111111111111111111111111111); +insert into babel_4424_t2 values (11.1111); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- index scan + append +select * from + ( + select a col from babel_4424_t1 where a = 1 + union all + select a col from babel_4424_t2 where a = 1 + ) dummy +order by col; +go +~~START~~ +numeric +~~END~~ + + +DROP TABLE babel_4424_t1; +go +DROP TABLE babel_4424_t2; +go + + +create table babel_4424_t1 (n3_0 numeric(3,0), n3_1 numeric(3,1), n6_0 numeric(6,0), n10_0 numeric(10,0), n10_9 numeric(10, 9), + n15_0 numeric(15,0), n16_15 numeric(16,15), n20_2 numeric(20,2), n25_5 numeric(25,0), n30_10 numeric(30, 10), + n30_29 numeric(30,29), n38_37 numeric(38,37)); +insert into babel_4424_t1 (n3_0) values (999); +insert into babel_4424_t1 (n3_1) values (99.9); +insert into babel_4424_t1 (n6_0) values (999999); +insert into babel_4424_t1 (n10_0) values (9999999999); +insert into babel_4424_t1 (n10_9) values (9.999999999); +insert into babel_4424_t1 (n15_0) values (999999999999999); +insert into babel_4424_t1 (n16_15) values (9.999999999999999); +insert into babel_4424_t1 (n20_2) values (999999999999999999.99); +insert into babel_4424_t1 (n25_5) values (99999999999999999999.99999); +insert into babel_4424_t1 (n30_10) values (99999999999999999999.9999999999); +insert into babel_4424_t1 (n30_29) values (9.99999999999999999999999999999); +insert into babel_4424_t1 (n38_37) values (9.9999999999999999999999999999999999999); +insert into babel_4424_t1 (n3_0, n3_1, n6_0, n10_0, n10_9, n15_0, n16_15, n20_2, n25_5, n30_10, n30_29, n38_37) +values (999, 99.9, 999999, 9999999999, 9.999999999, 999999999999999, 9.999999999999999, 999999999999999999.99, +99999999999999999999.99999, 99999999999999999999.9999999999, 9.99999999999999999999999999999, 9.9999999999999999999999999999999999999); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +insert into babel_4424_t1 (n3_0) values (111); +insert into babel_4424_t1 (n3_1) values (11.1); +insert into babel_4424_t1 (n6_0) values (111111); +insert into babel_4424_t1 (n10_0) values (1111111111); +insert into babel_4424_t1 (n10_9) values (1.111111111); +insert into babel_4424_t1 (n15_0) values (111111111111111); +insert into babel_4424_t1 (n16_15) values (1.111111111111111); +insert into babel_4424_t1 (n20_2) values (111111111111111111.11); +insert into babel_4424_t1 (n25_5) values (11111111111111111111.11111); +insert into babel_4424_t1 (n30_10) values (11111111111111111111.1111111111); +insert into babel_4424_t1 (n30_29) values (1.11111111111111111111111111111); +insert into babel_4424_t1 (n38_37) values (1.1111111111111111111111111111111111111); +insert into babel_4424_t1 (n3_0, n3_1, n6_0, n10_0, n10_9, n15_0, n16_15, n20_2, n25_5, n30_10, n30_29, n38_37) +values (111, 11.1, 111111, 1111111111, 1.111111111, 111111111111111, 1.111111111111111, 111111111111111111.11, +11111111111111111111.11111, 11111111111111111111.1111111111, 1.11111111111111111111111111111, 1.1111111111111111111111111111111111111); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +select n38_37 + 100 from babel_4424_t1 where n38_37 is not null; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +select n38_37 + n38_37 from babel_4424_t1 where n38_37 is not null; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +select sum(n38_37) from babel_4424_t1 where n38_37 is not null; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +select avg(n38_37) from babel_4424_t1 where n38_37 is not null; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +select n30_29 * 100 from babel_4424_t1 where n30_29 is not null; +GO +~~START~~ +numeric +999.99999999999999999999999999900 +999.99999999999999999999999999900 +111.11111111111111111111111111100 +111.11111111111111111111111111100 +~~END~~ + + +select n30_29 + n30_29 from babel_4424_t1 where n30_29 is not null; +GO +~~START~~ +numeric +19.99999999999999999999999999998 +19.99999999999999999999999999998 +2.22222222222222222222222222222 +2.22222222222222222222222222222 +~~END~~ + + +select n30_29 + n38_37 from babel_4424_t1 where n30_29 is not null and n38_37 is not null; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +select n3_0 * n3_0 from babel_4424_t1 where n3_0 is not null; +GO +~~START~~ +numeric +998001 +998001 +12321 +12321 +~~END~~ + + +select n3_0 * n3_1 from babel_4424_t1 where n3_0 is not null and n3_1 is not null; +GO +~~START~~ +numeric +99800.1 +1232.1 +~~END~~ + + +select n3_0 + n6_0 from babel_4424_t1 where n3_0 is not null and n6_0 is not null; +GO +~~START~~ +numeric +1000998 +111222 +~~END~~ + + +select n6_0 + n10_9 from babel_4424_t1 where n6_0 is not null and n10_9 is not null; +GO +~~START~~ +numeric +1000008.999999999 +111112.111111111 +~~END~~ + + +select n15_0 * n15_0 from babel_4424_t1 where n15_0 is not null; +GO +~~START~~ +numeric +999999999999998000000000000001 +999999999999998000000000000001 +12345679012345654320987654321 +12345679012345654320987654321 +~~END~~ + + +select n15_0 + n38_37 from babel_4424_t1 where n15_0 is not null and n38_37 is not null; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +select n15_0 + n16_15 from babel_4424_t1 where n15_0 is not null and n16_15 is not null; +GO +~~START~~ +numeric +1000000000000008.999999999999999 +111111111111112.111111111111111 +~~END~~ + + +select avg(n16_15) from babel_4424_t1 where n16_15 is not null; +GO +~~START~~ +numeric +5.555555555555555 +~~END~~ + + +select n16_15 * n16_15 from babel_4424_t1 where n16_15 is not null; +GO +~~START~~ +numeric +99.999999999999980000000000000001 +99.999999999999980000000000000001 +1.234567901234567654320987654321 +1.234567901234567654320987654321 +~~END~~ + + +select n15_0 + n16_15 + n30_10 from babel_4424_t1 where n15_0 is not null and n16_15 is not null and n30_10 is not null; +GO +~~START~~ +numeric +100001000000000000008.999999999899999 +11111222222222222223.222222222211111 +~~END~~ + + +select n20_2 + n38_37 from babel_4424_t1 where n20_2 is not null and n38_37 is not null; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +select n25_5 + n30_10 from babel_4424_t1 where n25_5 is not null and n30_10 is not null; +GO +~~START~~ +numeric +199999999999999999999.9999999999 +22222222222222222222.1111111111 +~~END~~ + + +select n30_29 + n30_10 from babel_4424_t1 where n30_29 is not null and n30_10 is not null; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +select * from +( + select n3_0 col from babel_4424_t1 where n3_0 is not null + union all + select n3_1 col from babel_4424_t1 where n3_1 is not null + union all + select n6_0 col from babel_4424_t1 where n6_0 is not null + union all + select n10_0 col from babel_4424_t1 where n10_0 is not null + union all + select n10_9 col from babel_4424_t1 where n10_9 is not null + union all + select n15_0 col from babel_4424_t1 where n15_0 is not null + union all + select n16_15 col from babel_4424_t1 where n16_15 is not null + union all + select n20_2 col from babel_4424_t1 where n20_2 is not null + union all + select n25_5 col from babel_4424_t1 where n25_5 is not null + union all + select n30_10 col from babel_4424_t1 where n30_10 is not null + union all + select n30_29 col from babel_4424_t1 where n30_29 is not null + union all + select n38_37 col from babel_4424_t1 where n38_37 is not null +) dummy +order by col; +GO +~~START~~ +numeric +1.1111111110000 +1.1111111110000 +1.1111111111111 +1.1111111111111 +1.1111111111111 +1.1111111111111 +1.1111111111111 +1.1111111111111 +9.9999999990000 +9.9999999990000 +9.9999999999999 +9.9999999999999 +9.9999999999999 +9.9999999999999 +9.9999999999999 +9.9999999999999 +11.1000000000000 +11.1000000000000 +99.9000000000000 +99.9000000000000 +111.0000000000000 +111.0000000000000 +999.0000000000000 +999.0000000000000 +111111.0000000000000 +111111.0000000000000 +999999.0000000000000 +999999.0000000000000 +1111111111.0000000000000 +1111111111.0000000000000 +9999999999.0000000000000 +9999999999.0000000000000 +111111111111111.0000000000000 +111111111111111.0000000000000 +999999999999999.0000000000000 +999999999999999.0000000000000 +111111111111111111.1100000000000 +111111111111111111.1100000000000 +999999999999999999.9900000000000 +999999999999999999.9900000000000 +11111111111111111111.0000000000000 +11111111111111111111.0000000000000 +11111111111111111111.1111111111000 +11111111111111111111.1111111111000 +99999999999999999999.9999999999000 +99999999999999999999.9999999999000 +100000000000000000000.0000000000000 +100000000000000000000.0000000000000 +~~END~~ + + +DROP table babel_4424_t1; +GO + +create table babel_4424_t1 (a numeric(38,38)); +GO + +insert into babel_4424_t1 values (0.1111111111111111111111111111111111111111); +go +~~ROW COUNT: 1~~ + + +select a + a from babel_4424_t1; +GO +~~START~~ +numeric +0.22222222222222222222222222222222222222 +~~END~~ + + +truncate table babel_4424_t1; +GO + +insert into babel_4424_t1 values (0.99999999999999999999999999999999999999) +GO +~~ROW COUNT: 1~~ + + +select a + a from babel_4424_t1; +GO +~~START~~ +numeric +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Arithmetic overflow error for data type numeric.)~~ + + +DROP table babel_4424_t1; +GO diff --git a/test/JDBC/expected/babel_613.out b/test/JDBC/expected/babel_613.out index 76c4a668b86..888b9c17202 100644 --- a/test/JDBC/expected/babel_613.out +++ b/test/JDBC/expected/babel_613.out @@ -154,19 +154,23 @@ numeric -- test Union All -select a from t1 Union All -select b from t1; +select * from + ( + select a as col from t1 Union All + select b as col from t1 + ) dummy +order by col go ~~START~~ numeric -4.00000000 -10.12340000 -1.20000000 -16.00000000 -10.12300000 -6.00000000 -101.12300000 +1.2000 +4.0000 +6.0000 +10.1230 +10.1234 +16.0000 +101.1230 ~~END~~ diff --git a/test/JDBC/input/BABEL-3943.mix b/test/JDBC/input/BABEL-3943.mix index b7577ad318b..6c9796f8a69 100644 --- a/test/JDBC/input/BABEL-3943.mix +++ b/test/JDBC/input/BABEL-3943.mix @@ -14,23 +14,18 @@ select 0,1,862 from generate_series(1,200000); GO -- tsql --- TODO: Fix BABEL-4359 SELECT avg([owner_amounts].[tax]) FROM [owner_amounts] WHERE moment_id = 862 and ISNULL([owner_amounts].[active], 0) = 1 AND [owner_amounts].[tax] is not null GO --- TODO: Fix BABEL-4359 SELECT avg([owner_amounts].[tax]) FROM [owner_amounts] WHERE moment_id = 862 and cast([owner_amounts].[active] as smallint) = 1 AND [owner_amounts].[tax] is not null GO --- TODO: Fix BABEL-4359 SELECT TOP 1 [owner_amounts].[tax] FROM [owner_amounts] WHERE moment_id = 862 and cast([owner_amounts].[active] as smallint) = 1 GO --- TODO: Fix BABEL-4359 SELECT avg([owner_amounts].[tax]) FROM [owner_amounts] WHERE moment_id = 862 and cast([owner_amounts].[active] as int) = 1 AND [owner_amounts].[tax] is not null GO --- TODO: Fix BABEL-4359 SELECT TOP 1 [owner_amounts].[tax] FROM [owner_amounts] WHERE moment_id = 862 and cast([owner_amounts].[active] as int) = 1 GO diff --git a/test/JDBC/input/BABEL-4424.sql b/test/JDBC/input/BABEL-4424.sql new file mode 100644 index 00000000000..8c75c00c51b --- /dev/null +++ b/test/JDBC/input/BABEL-4424.sql @@ -0,0 +1,400 @@ +create table babel_4359_t1 (a numeric(6,4), b numeric(6,3), c numeric); +go + +insert into babel_4359_t1 values (4, 16, 1111); +insert into babel_4359_t1 values (10.1234, 10.123, 222222); +insert into babel_4359_t1 values (1.2, 6, 33333333333333333); +insert into babel_4359_t1 values (NULL, 101.123, 444444444444444444); +insert into babel_4359_t1 values (10.123, NULL, 444444444444444444.44); +insert into babel_4359_t1 values (10.12, 10.1234, NULL); +go + +select * from + ( + select a as col from babel_4359_t1 Union All + select b as col from babel_4359_t1 + ) dummy +order by col +go + +select * from + ( + select a as col from babel_4359_t1 union all + select b as col from babel_4359_t1 union all + select c as col from babel_4359_t1 + ) dummy +order by col +go + +select * from + ( + select avg(a) as col from babel_4359_t1 union all + select avg(b) as col from babel_4359_t1 + ) dummy +order by col + +select * from + ( + select a + b as col from babel_4359_t1 Union All + select b + c as col from babel_4359_t1 + ) dummy +order by col +go + +select * from + ( + (select a as col from babel_4359_t1 order by a) union all + (select b as col from babel_4359_t1 order by a) union all + (select c as col from babel_4359_t1 order by a) + ) dummy +order by col +go + +select * from + ( + (select min(a) as col from babel_4359_t1 ) union all + (select min(b) as col from babel_4359_t1 ) union all + (select min(c) as col from babel_4359_t1 ) + ) dummy +order by col + +select min(col) from + ( + (select min(a) as col from babel_4359_t1 ) union all + (select min(b) as col from babel_4359_t1 ) union all + (select min(c) as col from babel_4359_t1 ) + ) dummy +go + +select * from + ( + select max(a + b) as col from babel_4359_t1 Union All + select min(b + c) as col from babel_4359_t1 + ) dummy +order by col +go + +create table events (event_id numeric(6,3) primary key); +create table other_events (event_id numeric(6,5) primary key); +create table other_events_2 (event_id numeric); +go + +insert into events values (100.123), (10.12); +insert into other_events values (1.123456); +insert into other_events_2 values (111111111111111111), (NULL); +go + +-- merge append node +select event_id + from ((select event_id from events order by event_id) + union all + (select event_id from other_events order by event_id) + union all + (select event_id from other_events_2 order by event_id)) ss +order by event_id; +go + +drop table babel_4359_t1 +go +drop table events; +go +drop table other_events; +go +drop table other_events_2; +go + +create table babel_4424_t1 (a numeric(38,0)); +go + +create table babel_4424_t2 (a numeric(6,4)); +go + +insert into babel_4424_t1 values (9999999999999999999999999999999999999); +insert into babel_4424_t2 values (99.9999); +insert into babel_4424_t1 values (1111111111111111111111111111111111111); +insert into babel_4424_t2 values (11.1111); +go + +select * from + ( + select a col from babel_4424_t1 + union all + select a col from babel_4424_t2 + )dummy +order by col; +go + +select * from + ( select a + a from babel_4424_t1 ) dummy +go + +select * from + ( + select a col from babel_4424_t1 + union all + select a + a col from babel_4424_t1 + )dummy +order by col; +go + +select * from + ( + select a + a col from babel_4424_t1 + union all + select a col from babel_4424_t2 + )dummy +order by col; +go + +create table babel_4424_t3 (a numeric(37,1)); +GO + +create table babel_4424_t4 (a numeric(38,1)); +GO + +insert into babel_4424_t3 values (999999999999999999999999999999999999.9); +insert into babel_4424_t3 values (111111111111111111111111111111111111.1); +go + +insert into babel_4424_t4 values (9999999999999999999999999999999999999.9); +insert into babel_4424_t4 values (1111111111111111111111111111111111111.1); +go + +select * from (select a + a from babel_4424_t3) dummy; +go + +select * from + ( + select a col from babel_4424_t3 + union all + select a col from babel_4424_t2 + ) dummy +order by col; +GO + +select * from + ( + select a col from babel_4424_t3 + union all + select a col from babel_4424_t4 + ) dummy +order by col; +GO + +create table babel_4424_t5 (a numeric(38, 37)); +GO + +create table babel_4424_t6 (a numeric(10, 10)); +GO + +insert into babel_4424_t5 values (9.99999999999999999999999999999999999); +insert into babel_4424_t6 values (0.9999999999); +insert into babel_4424_t5 values (1.11111111111111111111111111111111111); +insert into babel_4424_t6 values (0.1111111111); +GO + +select * from ( select a + a from babel_4424_t5) dummy; +GO + +select * from ( select a + a from babel_4424_t6) dummy; +GO + +select * from + ( + select a col from babel_4424_t5 + union all + select a col from babel_4424_t6 + ) dummy +order by col; +GO + +DROP TABLE babel_4424_t1; +go +DROP TABLE babel_4424_t2; +go +DROP TABLE babel_4424_t3; +go +DROP TABLE babel_4424_t4; +go +DROP TABLE babel_4424_t5; +go +DROP TABLE babel_4424_t6; +go + +create table babel_4424_t1 (a numeric(38,0) primary key); +go + +create table babel_4424_t2(a numeric(6,3) primary key); +go + +insert into babel_4424_t1 values (99999999999999999999999999999999999999); +insert into babel_4424_t2 values (99.9999); +insert into babel_4424_t1 values (11111111111111111111111111111111111111); +insert into babel_4424_t2 values (11.1111); +GO + +-- index scan + append +select * from + ( + select a col from babel_4424_t1 where a = 1 + union all + select a col from babel_4424_t2 where a = 1 + ) dummy +order by col; +go + +DROP TABLE babel_4424_t1; +go +DROP TABLE babel_4424_t2; +go + +create table babel_4424_t1 (n3_0 numeric(3,0), n3_1 numeric(3,1), n6_0 numeric(6,0), n10_0 numeric(10,0), n10_9 numeric(10, 9), + n15_0 numeric(15,0), n16_15 numeric(16,15), n20_2 numeric(20,2), n25_5 numeric(25,0), n30_10 numeric(30, 10), + n30_29 numeric(30,29), n38_37 numeric(38,37)); + +insert into babel_4424_t1 (n3_0) values (999); +insert into babel_4424_t1 (n3_1) values (99.9); +insert into babel_4424_t1 (n6_0) values (999999); +insert into babel_4424_t1 (n10_0) values (9999999999); +insert into babel_4424_t1 (n10_9) values (9.999999999); +insert into babel_4424_t1 (n15_0) values (999999999999999); +insert into babel_4424_t1 (n16_15) values (9.999999999999999); +insert into babel_4424_t1 (n20_2) values (999999999999999999.99); +insert into babel_4424_t1 (n25_5) values (99999999999999999999.99999); +insert into babel_4424_t1 (n30_10) values (99999999999999999999.9999999999); +insert into babel_4424_t1 (n30_29) values (9.99999999999999999999999999999); +insert into babel_4424_t1 (n38_37) values (9.9999999999999999999999999999999999999); +insert into babel_4424_t1 (n3_0, n3_1, n6_0, n10_0, n10_9, n15_0, n16_15, n20_2, n25_5, n30_10, n30_29, n38_37) +values (999, 99.9, 999999, 9999999999, 9.999999999, 999999999999999, 9.999999999999999, 999999999999999999.99, +99999999999999999999.99999, 99999999999999999999.9999999999, 9.99999999999999999999999999999, 9.9999999999999999999999999999999999999); +GO + +insert into babel_4424_t1 (n3_0) values (111); +insert into babel_4424_t1 (n3_1) values (11.1); +insert into babel_4424_t1 (n6_0) values (111111); +insert into babel_4424_t1 (n10_0) values (1111111111); +insert into babel_4424_t1 (n10_9) values (1.111111111); +insert into babel_4424_t1 (n15_0) values (111111111111111); +insert into babel_4424_t1 (n16_15) values (1.111111111111111); +insert into babel_4424_t1 (n20_2) values (111111111111111111.11); +insert into babel_4424_t1 (n25_5) values (11111111111111111111.11111); +insert into babel_4424_t1 (n30_10) values (11111111111111111111.1111111111); +insert into babel_4424_t1 (n30_29) values (1.11111111111111111111111111111); +insert into babel_4424_t1 (n38_37) values (1.1111111111111111111111111111111111111); +insert into babel_4424_t1 (n3_0, n3_1, n6_0, n10_0, n10_9, n15_0, n16_15, n20_2, n25_5, n30_10, n30_29, n38_37) +values (111, 11.1, 111111, 1111111111, 1.111111111, 111111111111111, 1.111111111111111, 111111111111111111.11, +11111111111111111111.11111, 11111111111111111111.1111111111, 1.11111111111111111111111111111, 1.1111111111111111111111111111111111111); +GO + +select n38_37 + 100 from babel_4424_t1 where n38_37 is not null; +GO + +select n38_37 + n38_37 from babel_4424_t1 where n38_37 is not null; +GO + +select sum(n38_37) from babel_4424_t1 where n38_37 is not null; +GO + +select avg(n38_37) from babel_4424_t1 where n38_37 is not null; +GO + +select n30_29 * 100 from babel_4424_t1 where n30_29 is not null; +GO + +select n30_29 + n30_29 from babel_4424_t1 where n30_29 is not null; +GO + +select n30_29 + n38_37 from babel_4424_t1 where n30_29 is not null and n38_37 is not null; +GO + +select n3_0 * n3_0 from babel_4424_t1 where n3_0 is not null; +GO + +select n3_0 * n3_1 from babel_4424_t1 where n3_0 is not null and n3_1 is not null; +GO + +select n3_0 + n6_0 from babel_4424_t1 where n3_0 is not null and n6_0 is not null; +GO + +select n6_0 + n10_9 from babel_4424_t1 where n6_0 is not null and n10_9 is not null; +GO + +select n15_0 * n15_0 from babel_4424_t1 where n15_0 is not null; +GO + +select n15_0 + n38_37 from babel_4424_t1 where n15_0 is not null and n38_37 is not null; +GO + +select n15_0 + n16_15 from babel_4424_t1 where n15_0 is not null and n16_15 is not null; +GO + +select avg(n16_15) from babel_4424_t1 where n16_15 is not null; +GO + +select n16_15 * n16_15 from babel_4424_t1 where n16_15 is not null; +GO + +select n15_0 + n16_15 + n30_10 from babel_4424_t1 where n15_0 is not null and n16_15 is not null and n30_10 is not null; +GO + +select n20_2 + n38_37 from babel_4424_t1 where n20_2 is not null and n38_37 is not null; +GO + +select n25_5 + n30_10 from babel_4424_t1 where n25_5 is not null and n30_10 is not null; +GO + +select n30_29 + n30_10 from babel_4424_t1 where n30_29 is not null and n30_10 is not null; +GO + +select * from +( + select n3_0 col from babel_4424_t1 where n3_0 is not null + union all + select n3_1 col from babel_4424_t1 where n3_1 is not null + union all + select n6_0 col from babel_4424_t1 where n6_0 is not null + union all + select n10_0 col from babel_4424_t1 where n10_0 is not null + union all + select n10_9 col from babel_4424_t1 where n10_9 is not null + union all + select n15_0 col from babel_4424_t1 where n15_0 is not null + union all + select n16_15 col from babel_4424_t1 where n16_15 is not null + union all + select n20_2 col from babel_4424_t1 where n20_2 is not null + union all + select n25_5 col from babel_4424_t1 where n25_5 is not null + union all + select n30_10 col from babel_4424_t1 where n30_10 is not null + union all + select n30_29 col from babel_4424_t1 where n30_29 is not null + union all + select n38_37 col from babel_4424_t1 where n38_37 is not null +) dummy +order by col; +GO + +DROP table babel_4424_t1; +GO + +create table babel_4424_t1 (a numeric(38,38)); +GO + +insert into babel_4424_t1 values (0.1111111111111111111111111111111111111111); +go + +select a + a from babel_4424_t1; +GO + +truncate table babel_4424_t1; +GO + +insert into babel_4424_t1 values (0.99999999999999999999999999999999999999) +GO + +select a + a from babel_4424_t1; +GO + +DROP table babel_4424_t1; +GO \ No newline at end of file diff --git a/test/JDBC/input/babel_613.sql b/test/JDBC/input/babel_613.sql index 4c09aa5e779..fd66c3d4d65 100644 --- a/test/JDBC/input/babel_613.sql +++ b/test/JDBC/input/babel_613.sql @@ -60,8 +60,12 @@ select coalesce(a, b) from t1; go -- test Union All -select a from t1 Union All -select b from t1; +select * from + ( + select a as col from t1 Union All + select b as col from t1 + ) dummy +order by col go -- test overflow from multiplication of columns diff --git a/test/JDBC/parallel_query_jdbc_schedule b/test/JDBC/parallel_query_jdbc_schedule index 2150b6bac9f..61b0f29ff26 100644 --- a/test/JDBC/parallel_query_jdbc_schedule +++ b/test/JDBC/parallel_query_jdbc_schedule @@ -14,18 +14,7 @@ ignore#!#Test-sp_droprolemember-vu-prepare ignore#!#Test-sp_droprolemember-vu-verify ignore#!#Test-sp_droprolemember-vu-cleanup -# Group 2: Incorrect precision BABEL-4396 -ignore#!#BABEL-3943 -ignore#!#BABEL-785 -ignore#!#TestDecimal-vu-verify -ignore#!#TestNumeric-vu-verify -ignore#!#babel_613 -ignore#!#babel_datatype -ignore#!#babel_isnull -ignore#!#BABEL-3006 -ignore#!#BABEL-3147-vu-verify - -# Group 3: Need ORDER BY +# Group 2: Need ORDER BY ignore#!#BABEL-2514 ignore#!#BABEL-2998 ignore#!#BABEL-328-vu-verify @@ -274,11 +263,6 @@ ignore#!#Test-sp_addrolemember-dep-vu-verify ignore#!#Test-sp_droprolemember-dep-vu-verify ignore#!#babel_table_type -# BABEL-4424 -ignore#!#TestDecimal -ignore#!#TestNumeric -ignore#!#numericOverflow - # Taking too much time to complete. (TIME-OUT FAILURES) ignore#!#BABEL-SP_TABLE_PRIVILIGES-vu-verify ignore#!#BABEL-SP_COLUMNS_MANAGED-dep-vu-verify From 8bb0d137bf58ed5964724901deecac2705a25b36 Mon Sep 17 00:00:00 2001 From: Zhibai Song Date: Tue, 21 Nov 2023 14:47:14 -0800 Subject: [PATCH 5/7] Fix the remaining issues about default keyword in proc/func call (#2039) 1. The error message should be the same as sql server 2. Function call with not exist default param, then should use NULL value 3. Support call by name default as well Task: BABEL-335 Signed-off-by: Zhibai Song --- contrib/babelfishpg_tds/error_mapping.txt | 1 + contrib/babelfishpg_tsql/src/hooks.c | 122 ++++++++++++++---- .../expected/TestErrorHelperFunctions.out | 1 + ...tErrorHelperFunctionsUpgrade-vu-verify.out | 4 +- .../expected/default_params-vu-cleanup.out | 6 + .../expected/default_params-vu-prepare.out | 6 + .../expected/default_params-vu-verify.out | 66 ++++++++++ test/JDBC/input/default_params-vu-cleanup.sql | 6 + test/JDBC/input/default_params-vu-prepare.sql | 6 + test/JDBC/input/default_params-vu-verify.sql | 28 ++++ 10 files changed, 223 insertions(+), 23 deletions(-) diff --git a/contrib/babelfishpg_tds/error_mapping.txt b/contrib/babelfishpg_tds/error_mapping.txt index 6f6f6ee4ca6..cf9453b0440 100644 --- a/contrib/babelfishpg_tds/error_mapping.txt +++ b/contrib/babelfishpg_tds/error_mapping.txt @@ -81,6 +81,7 @@ XX000 ERRCODE_INTERNAL_ERROR "CREATE FUNCTION failed because a column name is no 42883 ERRCODE_UNDEFINED_FUNCTION "could not identify an equality operator for type %s" SQL_ERROR_306 16 42883 ERRCODE_UNDEFINED_FUNCTION "could not identify an ordering operator for type %s" SQL_ERROR_306 16 42883 ERRCODE_UNDEFINED_FUNCTION "%s %s expects parameter \"%s\", which was not supplied." SQL_ERROR_201 16 +42883 ERRCODE_UNDEFINED_FUNCTION "Procedure or function \'%s\' expects parameter \'%s\', which was not supplied." SQL_ERROR_201 16 42883 ERRCODE_UNDEFINED_FUNCTION "%s %s has no parameters and arguments were supplied." SQL_ERROR_8146 16 42883 ERRCODE_UNDEFINED_FUNCTION "%s %s has too many arguments specified." SQL_ERROR_8144 16 42883 ERRCODE_UNDEFINED_FUNCTION "\"%s\" is not an parameter for %s %s." SQL_ERROR_8145 16 diff --git a/contrib/babelfishpg_tsql/src/hooks.c b/contrib/babelfishpg_tsql/src/hooks.c index 9047a6360ab..0a186dac9ea 100644 --- a/contrib/babelfishpg_tsql/src/hooks.c +++ b/contrib/babelfishpg_tsql/src/hooks.c @@ -94,6 +94,7 @@ static bool match_pltsql_func_call(HeapTuple proctup, int nargs, List *argnames, static ObjectAddress get_trigger_object_address(List *object, Relation *relp, bool missing_ok, bool object_from_input); Oid get_tsql_trigger_oid(List *object, const char *tsql_trigger_name, bool object_from_input); static Node *transform_like_in_add_constraint(Node *node); +static char** fetch_func_input_arg_names(HeapTuple func_tuple); /***************************************** * Analyzer Hooks @@ -3566,13 +3567,15 @@ PlTsqlMatchNamedCall(HeapTuple proctup, int nargs, List *argnames, static int getDefaultPosition(const List *default_positions, const ListCell *def_idx, int argPosition) { - int currPosition = intVal((Node *) lfirst(def_idx)); + int currPosition; + if (default_positions == NIL || def_idx == NULL) + return -1; + currPosition = intVal((Node *) lfirst(def_idx)); while (currPosition != argPosition) { def_idx = lnext(default_positions, def_idx); if (def_idx == NULL) { - elog(ERROR, "not enough default arguments"); return -1; } currPosition = intVal((Node *) lfirst(def_idx)); @@ -3580,11 +3583,41 @@ static int getDefaultPosition(const List *default_positions, const ListCell *def return list_cell_number(default_positions, def_idx); } +/** + * @brief fetch the func input arg names + * + * @param func_tuple or proc_tuple + * @return char** list of input arg names + */ +static char** fetch_func_input_arg_names(HeapTuple func_tuple) +{ + Datum proargnames; + Datum proargmodes; + char** arg_names; + bool isnull; + + proargnames = SysCacheGetAttr(PROCNAMEARGSNSP, func_tuple, + Anum_pg_proc_proargnames, + &isnull); + + proargmodes = SysCacheGetAttr(PROCNAMEARGSNSP, func_tuple, + Anum_pg_proc_proargmodes, + &isnull); + + if (isnull) + proargmodes = PointerGetDatum(NULL); /* just to be sure */ + + get_func_input_arg_names(proargnames, + proargmodes, + &arg_names); + return arg_names; +} + /** * @brief farg position default should get the corresponding default position value * * @param func_tuple - * @param defaults + * @param defaults can be NIL * @param fargs * @return List* */ @@ -3593,19 +3626,24 @@ replace_pltsql_function_defaults(HeapTuple func_tuple, List *defaults, List *far { HeapTuple bbffunctuple; + Form_pg_proc proc_form; if (sql_dialect != SQL_DIALECT_TSQL) return fargs; bbffunctuple = get_bbf_function_tuple_from_proctuple(func_tuple); + proc_form = (Form_pg_proc) GETSTRUCT(func_tuple); - if (HeapTupleIsValid(bbffunctuple)){ + if (HeapTupleIsValid(bbffunctuple)) + { Datum arg_default_positions; bool isnull; char *str; List *default_positions = NIL, *ret = NIL; ListCell *def_idx; ListCell *lc; + char **arg_names; + int position,i,j; /* Fetch default positions */ @@ -3614,46 +3652,86 @@ replace_pltsql_function_defaults(HeapTuple func_tuple, List *defaults, List *far Anum_bbf_function_ext_default_positions, &isnull); - if (isnull) - elog(ERROR, "not enough default arguments"); - - str =TextDatumGetCString(arg_default_positions); - default_positions = castNode(List, stringToNode(str)); - pfree(str); + if (!isnull) + { + str =TextDatumGetCString(arg_default_positions); + default_positions = castNode(List, stringToNode(str)); + pfree(str); - def_idx = list_head(default_positions); + def_idx = list_head(default_positions); + } + else + { + default_positions = NIL; + def_idx = NULL; + } i = 0; foreach(lc, fargs) { + bool has_default = false; if (nodeTag((Node*)lfirst(lc)) == T_RelabelType && nodeTag(((RelabelType*)lfirst(lc))->arg) == T_SetToDefault) { position = getDefaultPosition(default_positions, def_idx, i); - ret = lappend(ret, list_nth(defaults, position)); + if (position >= 0) + { + ret = lappend(ret, list_nth(defaults, position)); + has_default = true; + } + else if (proc_form->prokind == PROKIND_FUNCTION) + { + ret = lappend(ret, makeNullConst(proc_form->proargtypes.values[i], -1, InvalidOid)); + has_default = true; + } } - else if (nodeTag((Node*)lfirst(lc)) == T_FuncExpr) - { - if(((FuncExpr*)lfirst(lc))->funcformat == COERCE_IMPLICIT_CAST && + else if (nodeTag((Node*)lfirst(lc)) == T_FuncExpr && + ((FuncExpr*)lfirst(lc))->funcformat == COERCE_IMPLICIT_CAST && nodeTag(linitial(((FuncExpr*)lfirst(lc))->args)) == T_SetToDefault) - { + { // We'll keep the implicit cast function when it needs implicit cast - FuncExpr *funcExpr = (FuncExpr*)lfirst(lc); - List *newArgs = NIL; - position = getDefaultPosition(default_positions, def_idx, i); + FuncExpr *funcExpr = (FuncExpr*)lfirst(lc); + List *newArgs = NIL; + position = getDefaultPosition(default_positions, def_idx, i); + if (position >= 0) + { newArgs = lappend(newArgs, list_nth(defaults, position)); for (j = 1; j < list_length(funcExpr->args); ++j) newArgs = lappend(newArgs, list_nth(funcExpr->args, j)); funcExpr->args = newArgs; ret = lappend(ret, funcExpr); + has_default = true; + } + else if (proc_form->prokind == PROKIND_FUNCTION) + { + newArgs = lappend(newArgs, makeNullConst(proc_form->proargtypes.values[i], -1, InvalidOid)); + for (j = 1; j < list_length(funcExpr->args); ++j) + newArgs = lappend(newArgs, list_nth(funcExpr->args, j)); + funcExpr->args = newArgs; + ret = lappend(ret, funcExpr); + has_default = true; } } - else ret = lappend(ret, lfirst(lc)); + else + { + ret = lappend(ret, lfirst(lc)); + has_default = true; + } + if (!has_default) + { + arg_names = fetch_func_input_arg_names(func_tuple); + + if (proc_form->prokind == PROKIND_PROCEDURE) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_FUNCTION), + errmsg("Procedure or function \'%s\' expects parameter \'%s\', which was not supplied.", + NameStr(proc_form->proname), arg_names[i]))); + } ++i; } - return ret; - ReleaseSysCache(bbffunctuple); + + return ret; } else { diff --git a/test/JDBC/expected/TestErrorHelperFunctions.out b/test/JDBC/expected/TestErrorHelperFunctions.out index 049b0a2c380..012d319cf94 100644 --- a/test/JDBC/expected/TestErrorHelperFunctions.out +++ b/test/JDBC/expected/TestErrorHelperFunctions.out @@ -104,6 +104,7 @@ XX000#!#CREATE FUNCTION failed because a column name is not specified for column 42883#!#could not identify an equality operator for type %s#!##!#306 42883#!#could not identify an ordering operator for type %s#!##!#306 42883#!#%s %s expects parameter "%s", which was not supplied.#!##!#201 +42883#!#Procedure or function '%s' expects parameter '%s', which was not supplied.#!##!#201 42883#!#%s %s has no parameters and arguments were supplied.#!##!#8146 42883#!#%s %s has too many arguments specified.#!##!#8144 42883#!#"%s" is not an parameter for %s %s.#!##!#8145 diff --git a/test/JDBC/expected/TestErrorHelperFunctionsUpgrade-vu-verify.out b/test/JDBC/expected/TestErrorHelperFunctionsUpgrade-vu-verify.out index b33c88085d7..902d262c0ef 100644 --- a/test/JDBC/expected/TestErrorHelperFunctionsUpgrade-vu-verify.out +++ b/test/JDBC/expected/TestErrorHelperFunctionsUpgrade-vu-verify.out @@ -211,6 +211,7 @@ int 306 306 201 +201 8146 8144 8145 @@ -381,6 +382,7 @@ int 306 306 201 +201 8146 8144 8145 @@ -490,6 +492,6 @@ EXEC TestErrorHelperFunctionsUpgrade_VU_PREPARE_PROC GO ~~START~~ int -163 +164 ~~END~~ diff --git a/test/JDBC/expected/default_params-vu-cleanup.out b/test/JDBC/expected/default_params-vu-cleanup.out index fe3bae09741..b87d15db291 100644 --- a/test/JDBC/expected/default_params-vu-cleanup.out +++ b/test/JDBC/expected/default_params-vu-cleanup.out @@ -7,6 +7,9 @@ GO drop function default_params_func3; GO +drop function default_params_func4; +GO + drop procedure default_params_proc1; GO @@ -18,3 +21,6 @@ GO drop procedure default_params_proc4 GO + +drop function default_params_func5; +GO diff --git a/test/JDBC/expected/default_params-vu-prepare.out b/test/JDBC/expected/default_params-vu-prepare.out index 10c39f6ebbe..671870a5e72 100644 --- a/test/JDBC/expected/default_params-vu-prepare.out +++ b/test/JDBC/expected/default_params-vu-prepare.out @@ -7,6 +7,12 @@ GO create function default_params_func3 (@p1 varchar(20) = 'abc') returns varchar as begin return @p1 end; GO +create function default_params_func4 (@p1 int) returns int as begin return @p1 end; +GO + +create function default_params_func5 (@p1 varchar(20)) returns varchar as begin return @p1 end; +GO + create proc default_params_proc1 @p1 int=1, @p2 int=2, @p3 int=3 as select @p1, @p2, @p3 GO diff --git a/test/JDBC/expected/default_params-vu-verify.out b/test/JDBC/expected/default_params-vu-verify.out index 1f7a3cbc967..176a4cbe2f2 100644 --- a/test/JDBC/expected/default_params-vu-verify.out +++ b/test/JDBC/expected/default_params-vu-verify.out @@ -78,6 +78,23 @@ d ~~END~~ +-- it'll use default +select default_params_func4(default); +GO +~~START~~ +int + +~~END~~ + + +select default_params_func5(default); +GO +~~START~~ +varchar + +~~END~~ + + exec default_params_proc1 111, default, 333 GO ~~START~~ @@ -102,6 +119,30 @@ int#!#int#!#int ~~END~~ +exec default_params_proc1 @p1=default, @p2=default,@p3=300 +GO +~~START~~ +int#!#int#!#int +1#!#2#!#300 +~~END~~ + + +exec default_params_proc1 @p1=300, @p2=default,@p3=default +GO +~~START~~ +int#!#int#!#int +300#!#2#!#3 +~~END~~ + + +exec default_params_proc1 @p1=default, @p2=300,@p3=default +GO +~~START~~ +int#!#int#!#int +1#!#300#!#3 +~~END~~ + + exec default_params_proc2 default, 2 GO ~~START~~ @@ -134,6 +175,23 @@ d#!#3 ~~END~~ +-- verify the error message +exec default_params_proc3 default, default +GO +~~ERROR (Code: 201)~~ + +~~ERROR (Message: Procedure or function 'default_params_proc3' expects parameter '@p2', which was not supplied.)~~ + + +-- verify the error message +exec default_params_proc3 'ddd', default +GO +~~ERROR (Code: 201)~~ + +~~ERROR (Message: Procedure or function 'default_params_proc3' expects parameter '@p2', which was not supplied.)~~ + + +-- verify the type cast exec default_params_proc4 1,2,default GO ~~START~~ @@ -141,3 +199,11 @@ int#!#int#!#varchar 1#!#2#!#dbb ~~END~~ + +exec default_params_proc4 1,2, @p3=default +GO +~~START~~ +int#!#int#!#varchar +1#!#2#!#dbb +~~END~~ + diff --git a/test/JDBC/input/default_params-vu-cleanup.sql b/test/JDBC/input/default_params-vu-cleanup.sql index 3fbaa126fa7..bb29b05cc95 100644 --- a/test/JDBC/input/default_params-vu-cleanup.sql +++ b/test/JDBC/input/default_params-vu-cleanup.sql @@ -7,6 +7,9 @@ GO drop function default_params_func3; GO +drop function default_params_func4; +GO + drop procedure default_params_proc1; GO @@ -17,4 +20,7 @@ drop procedure default_params_proc3 GO drop procedure default_params_proc4 +GO + +drop function default_params_func5; GO \ No newline at end of file diff --git a/test/JDBC/input/default_params-vu-prepare.sql b/test/JDBC/input/default_params-vu-prepare.sql index 10c39f6ebbe..671870a5e72 100644 --- a/test/JDBC/input/default_params-vu-prepare.sql +++ b/test/JDBC/input/default_params-vu-prepare.sql @@ -7,6 +7,12 @@ GO create function default_params_func3 (@p1 varchar(20) = 'abc') returns varchar as begin return @p1 end; GO +create function default_params_func4 (@p1 int) returns int as begin return @p1 end; +GO + +create function default_params_func5 (@p1 varchar(20)) returns varchar as begin return @p1 end; +GO + create proc default_params_proc1 @p1 int=1, @p2 int=2, @p3 int=3 as select @p1, @p2, @p3 GO diff --git a/test/JDBC/input/default_params-vu-verify.sql b/test/JDBC/input/default_params-vu-verify.sql index dafc991c2fb..8772222e800 100644 --- a/test/JDBC/input/default_params-vu-verify.sql +++ b/test/JDBC/input/default_params-vu-verify.sql @@ -28,6 +28,13 @@ GO select default_params_func3('dddd'); GO +-- it'll use default +select default_params_func4(default); +GO + +select default_params_func5(default); +GO + exec default_params_proc1 111, default, 333 GO @@ -37,6 +44,15 @@ GO exec default_params_proc1 default GO +exec default_params_proc1 @p1=default, @p2=default,@p3=300 +GO + +exec default_params_proc1 @p1=300, @p2=default,@p3=default +GO + +exec default_params_proc1 @p1=default, @p2=300,@p3=default +GO + exec default_params_proc2 default, 2 GO @@ -49,5 +65,17 @@ GO exec default_params_proc3 'dddd', 3 GO +-- verify the error message +exec default_params_proc3 default, default +GO + +-- verify the error message +exec default_params_proc3 'ddd', default +GO + +-- verify the type cast exec default_params_proc4 1,2,default GO + +exec default_params_proc4 1,2, @p3=default +GO From 0cabf83ce4029286d9d4161f08b525a839e3e515 Mon Sep 17 00:00:00 2001 From: shalinilohia50 <46928246+shalinilohia50@users.noreply.github.com> Date: Wed, 22 Nov 2023 10:27:15 +0530 Subject: [PATCH 6/7] Revert "Fix bugs for GRANT/REVOKE on SCHEMA (#2031)" (#2051) This reverts commit dd23da9b3ada6d662a0246bcbb48e2b3dcaaae37. Co-authored-by: Shalini Lohia --- contrib/babelfishpg_tsql/sql/ownership.sql | 10 +- .../babelfishpg_tsql--3.3.0--3.4.0.sql | 10 +- contrib/babelfishpg_tsql/src/catalog.c | 193 +++++--------- contrib/babelfishpg_tsql/src/catalog.h | 2 - contrib/babelfishpg_tsql/src/pl_exec-2.c | 48 ++-- contrib/babelfishpg_tsql/src/pl_handler.c | 82 +++--- contrib/babelfishpg_tsql/src/pltsql_utils.c | 5 +- contrib/babelfishpg_tsql/src/tsqlIface.cpp | 20 -- .../src/tsqlUnsupportedFeatureHandler.cpp | 8 +- test/JDBC/expected/BABEL-GRANT.out | 34 +-- test/JDBC/expected/GRANT_SCHEMA.out | 236 +----------------- test/JDBC/input/BABEL-GRANT.sql | 18 +- test/JDBC/input/GRANT_SCHEMA.mix | 157 +----------- .../expected_create.out | 1 + 14 files changed, 143 insertions(+), 681 deletions(-) diff --git a/contrib/babelfishpg_tsql/sql/ownership.sql b/contrib/babelfishpg_tsql/sql/ownership.sql index a632a918157..ee3a5446a43 100644 --- a/contrib/babelfishpg_tsql/sql/ownership.sql +++ b/contrib/babelfishpg_tsql/sql/ownership.sql @@ -17,11 +17,11 @@ GRANT SELECT on sys.babelfish_sysdatabases TO PUBLIC; -- BABELFISH_SCHEMA_PERMISSIONS CREATE TABLE sys.babelfish_schema_permissions ( dbid smallint NOT NULL, - schema_name NAME NOT NULL COLLATE sys.database_default, - object_name NAME NOT NULL COLLATE sys.database_default, - permission NAME NOT NULL COLLATE sys.database_default, - grantee NAME NOT NULL COLLATE sys.database_default, - object_type NAME COLLATE sys.database_default, + schema_name NAME NOT NULL, + object_name NAME NOT NULL, + permission NAME NOT NULL, + grantee NAME NOT NULL, + object_type NAME, PRIMARY KEY(dbid, schema_name, object_name, permission, grantee) ); diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql index 88085d95304..fe141534577 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql @@ -892,11 +892,11 @@ LANGUAGE plpgsql STABLE; -- BABELFISH_SCHEMA_PERMISSIONS CREATE TABLE IF NOT EXISTS sys.babelfish_schema_permissions ( dbid smallint NOT NULL, - schema_name NAME NOT NULL COLLATE sys.database_default, - object_name NAME NOT NULL COLLATE sys.database_default, - permission NAME NOT NULL COLLATE sys.database_default, - grantee NAME NOT NULL COLLATE sys.database_default, - object_type NAME COLLATE sys.database_default, + schema_name NAME NOT NULL, + object_name NAME NOT NULL, + permission NAME NOT NULL, + grantee NAME NOT NULL, + object_type NAME, PRIMARY KEY(dbid, schema_name, object_name, permission, grantee) ); diff --git a/contrib/babelfishpg_tsql/src/catalog.c b/contrib/babelfishpg_tsql/src/catalog.c index 2d832e6a6e6..8f1f9bdc2a2 100644 --- a/contrib/babelfishpg_tsql/src/catalog.c +++ b/contrib/babelfishpg_tsql/src/catalog.c @@ -2843,10 +2843,6 @@ add_entry_to_bbf_schema(const char *schema_name, bool new_record_nulls_bbf_schema[BBF_SCHEMA_PERMS_NUM_OF_COLS]; int16 dbid = get_cur_db_id(); - /* Immediately return, if grantee is NULL or PUBLIC. */ - if ((grantee == NULL) || (strcmp(grantee, "public") == 0)) - return; - /* Fetch the relation */ bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), RowExclusiveLock); @@ -2889,65 +2885,45 @@ check_bbf_schema_for_entry(const char *schema_name, { Relation bbf_schema_rel; HeapTuple tuple_bbf_schema; - ScanKeyData scanKey[5]; - SysScanDesc scan; + ScanKeyData key[5]; + TableScanDesc scan; bool catalog_entry_exists = false; int16 dbid = get_cur_db_id(); - /* Immediately return false, if grantee is NULL or PUBLIC. */ - if ((grantee == NULL) || (strcmp(grantee, "public") == 0)) - return false; - bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), AccessShareLock); - ScanKeyInit(&scanKey[0], + ScanKeyInit(&key[0], Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyEntryInitialize(&scanKey[1], 0, + ScanKeyInit(&key[1], Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyEntryInitialize(&scanKey[2], 0, + ScanKeyInit(&key[2], Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(object_name)); - ScanKeyEntryInitialize(&scanKey[3], 0, + ScanKeyInit(&key[3], Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(permission)); - ScanKeyEntryInitialize(&scanKey[4], 0, + ScanKeyInit(&key[4], Anum_bbf_schema_perms_grantee, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(grantee)); - scan = systable_beginscan(bbf_schema_rel, - get_bbf_schema_perms_idx_oid(), - true, NULL, 5, scanKey); - tuple_bbf_schema = systable_getnext(scan); + scan = table_beginscan_catalog(bbf_schema_rel, 5, key); + + tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); if (HeapTupleIsValid(tuple_bbf_schema)) catalog_entry_exists = true; - systable_endscan(scan); + table_endscan(scan); table_close(bbf_schema_rel, AccessShareLock); return catalog_entry_exists; } -/* - * Checks if a particular schema has any SCHEMA level permission granted to any user. - */ bool check_bbf_schema_for_schema(const char *schema_name, const char *object_name, @@ -2956,7 +2932,7 @@ check_bbf_schema_for_schema(const char *schema_name, Relation bbf_schema_rel; HeapTuple tuple_bbf_schema; ScanKeyData key[4]; - SysScanDesc scan; + TableScanDesc scan; bool catalog_entry_exists = false; int16 dbid = get_cur_db_id(); @@ -2966,37 +2942,26 @@ check_bbf_schema_for_schema(const char *schema_name, Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyEntryInitialize(&key[1], 0, + ScanKeyInit(&key[1], Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyEntryInitialize(&key[2], 0, + ScanKeyInit(&key[2], Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(object_name)); - ScanKeyEntryInitialize(&key[3], 0, + ScanKeyInit(&key[3], Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(permission)); - scan = systable_beginscan(bbf_schema_rel, - get_bbf_schema_perms_idx_oid(), - true, NULL, 4, key); + scan = table_beginscan_catalog(bbf_schema_rel, 4, key); - tuple_bbf_schema = systable_getnext(scan); + tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); if (HeapTupleIsValid(tuple_bbf_schema)) catalog_entry_exists = true; - systable_endscan(scan); + table_endscan(scan); table_close(bbf_schema_rel, AccessShareLock); return catalog_entry_exists; } @@ -3009,59 +2974,44 @@ del_from_bbf_schema(const char *schema_name, { Relation bbf_schema_rel; HeapTuple tuple_bbf_schema; - ScanKeyData scanKey[5]; - SysScanDesc scan; + ScanKeyData key[5]; + TableScanDesc scan; int16 dbid = get_cur_db_id(); - /* Immediately return, if grantee is NULL or PUBLIC. */ - if ((grantee == NULL) || (strcmp(grantee, "public") == 0)) - return; - bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), RowExclusiveLock); - ScanKeyInit(&scanKey[0], + ScanKeyInit(&key[0], Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyEntryInitialize(&scanKey[1], 0, + ScanKeyInit(&key[1], Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyEntryInitialize(&scanKey[2], 0, + ScanKeyInit(&key[2], Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(object_name)); - ScanKeyEntryInitialize(&scanKey[3], 0, + ScanKeyInit(&key[3], Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(permission)); - ScanKeyEntryInitialize(&scanKey[4], 0, + ScanKeyInit(&key[4], Anum_bbf_schema_perms_grantee, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(grantee)); - scan = systable_beginscan(bbf_schema_rel, - get_bbf_schema_perms_idx_oid(), - true, NULL, 5, scanKey); - tuple_bbf_schema = systable_getnext(scan); + scan = table_beginscan_catalog(bbf_schema_rel, 5, key); + + tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); if (HeapTupleIsValid(tuple_bbf_schema)) CatalogTupleDelete(bbf_schema_rel, &tuple_bbf_schema->t_self); - systable_endscan(scan); + table_endscan(scan); table_close(bbf_schema_rel, RowExclusiveLock); + + CommandCounterIncrement(); } void @@ -3085,12 +3035,9 @@ clean_up_bbf_schema(const char *schema_name, Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyEntryInitialize(&scanKey[1], 0, + ScanKeyInit(&scanKey[1], Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(schema_name)); scan = systable_beginscan(bbf_schema_rel, get_bbf_schema_perms_idx_oid(), @@ -3103,19 +3050,13 @@ clean_up_bbf_schema(const char *schema_name, Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyEntryInitialize(&scanKey[1], 0, + ScanKeyInit(&scanKey[1], Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyEntryInitialize(&scanKey[2], 0, + ScanKeyInit(&scanKey[2], Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(object_name)); scan = systable_beginscan(bbf_schema_rel, get_bbf_schema_perms_idx_oid(), @@ -3133,18 +3074,12 @@ clean_up_bbf_schema(const char *schema_name, table_close(bbf_schema_rel, RowExclusiveLock); } -/* - * For all objects belonging to a schema which has OBJECT level permission, - * It grants the permission explicitly when REVOKE has been executed on that - * specific schema. - */ - void grant_perms_to_objects_in_schema(const char *schema_name, const char *permission, const char *grantee) { - SysScanDesc scan; + TableScanDesc scan; Relation bbf_schema_rel; HeapTuple tuple_bbf_schema; const char *object_name; @@ -3160,31 +3095,21 @@ grant_perms_to_objects_in_schema(const char *schema_name, Anum_bbf_schema_perms_dbid, BTEqualStrategyNumber, F_INT2EQ, Int16GetDatum(dbid)); - ScanKeyEntryInitialize(&scanKey[1], 0, + ScanKeyInit(&scanKey[1], Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(schema_name)); - ScanKeyEntryInitialize(&scanKey[2], 0, + ScanKeyInit(&scanKey[2], Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(permission)); - ScanKeyEntryInitialize(&scanKey[3], 0, + ScanKeyInit(&scanKey[3], Anum_bbf_schema_perms_grantee, - BTEqualStrategyNumber, - InvalidOid, - tsql_get_server_collation_oid_internal(false), - F_NAMEEQ, + BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(grantee)); - scan = systable_beginscan(bbf_schema_rel, get_bbf_schema_perms_idx_oid(), - true, NULL, 4, scanKey); - tuple_bbf_schema = systable_getnext(scan); + scan = table_beginscan_catalog(bbf_schema_rel, 4, scanKey); + tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); while (HeapTupleIsValid(tuple_bbf_schema)) { @@ -3237,9 +3162,9 @@ grant_perms_to_objects_in_schema(const char *schema_name, /* make sure later steps can see the object created here */ CommandCounterIncrement(); } - tuple_bbf_schema = systable_getnext(scan); + tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); } - systable_endscan(scan); + table_endscan(scan); table_close(bbf_schema_rel, AccessShareLock); } diff --git a/contrib/babelfishpg_tsql/src/catalog.h b/contrib/babelfishpg_tsql/src/catalog.h index c3a7de00859..7b8ad195c27 100644 --- a/contrib/babelfishpg_tsql/src/catalog.h +++ b/contrib/babelfishpg_tsql/src/catalog.h @@ -299,8 +299,6 @@ typedef FormData_bbf_function_ext *Form_bbf_function_ext; #define Anum_bbf_schema_perms_grantee 5 #define Anum_bbf_schema_perms_object_type 6 -#define PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA "ALL" - extern Oid bbf_schema_perms_oid; extern Oid bbf_schema_perms_idx_oid; diff --git a/contrib/babelfishpg_tsql/src/pl_exec-2.c b/contrib/babelfishpg_tsql/src/pl_exec-2.c index 3e98b678e85..4e948a0be0f 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec-2.c +++ b/contrib/babelfishpg_tsql/src/pl_exec-2.c @@ -3683,36 +3683,32 @@ exec_stmt_grantschema(PLtsql_execstate *estate, PLtsql_stmt_grantschema *stmt) char *dbname = get_cur_db_name(); char *login = GetUserNameFromId(GetSessionUserId(), false); bool login_is_db_owner; + Oid datdba; char *rolname; char *schema_name; ListCell *lc; ListCell *lc1; Oid schemaOid; - char *user = GetUserNameFromId(GetUserId(), false); /* * If the login is not the db owner or the login is not the member of * sysadmin or login is not the schema owner, then it doesn't have the permission to GRANT/REVOKE. */ login_is_db_owner = 0 == strncmp(login, get_owner_of_db(dbname), NAMEDATALEN); + datdba = get_role_oid("sysadmin", false); schema_name = get_physical_schema_name(dbname, stmt->schema_name); - - if(schema_name) - { - schemaOid = LookupExplicitNamespace(schema_name, true); - } - else - { - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_SCHEMA), - errmsg("An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as \"\" or [] are not allowed. Change the alias to a valid name."))); - } + schemaOid = LookupExplicitNamespace(schema_name, true); if (!OidIsValid(schemaOid)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_SCHEMA), errmsg("schema \"%s\" does not exist", schema_name))); + + if (!is_member_of_role(GetSessionUserId(), datdba) && !login_is_db_owner && !pg_namespace_ownercheck(schemaOid, GetUserId())) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + errmsg("Cannot find the schema \"%s\", because it does not exist or you do not have permission.", stmt->schema_name))); foreach(lc1, stmt->privileges) { @@ -3722,27 +3718,20 @@ exec_stmt_grantschema(PLtsql_execstate *estate, PLtsql_stmt_grantschema *stmt) char *grantee_name = (char *) lfirst(lc); Oid role_oid; bool grantee_is_db_owner; - if (strcmp(grantee_name, "public") != 0) - rolname = get_physical_user_name(dbname, grantee_name); - else - rolname = pstrdup("public"); + rolname = get_physical_user_name(dbname, grantee_name); role_oid = get_role_oid(rolname, true); grantee_is_db_owner = 0 == strncmp(grantee_name, get_owner_of_db(dbname), NAMEDATALEN); - if (strcmp(grantee_name, "public") != 0 && role_oid == InvalidOid) + + if (role_oid == InvalidOid) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("Cannot find the principal '%s', because it does not exist or you do not have permission.", grantee_name))); - if ((strcmp(rolname, user) == 0) || pg_namespace_ownercheck(schemaOid, role_oid) || is_member_of_role(role_oid, get_sysadmin_oid()) || grantee_is_db_owner) + if (pg_namespace_ownercheck(schemaOid, role_oid) || is_member_of_role(role_oid, datdba) || grantee_is_db_owner) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself."))); - if (!is_member_of_role(GetSessionUserId(), get_sysadmin_oid()) && !login_is_db_owner && !pg_namespace_ownercheck(schemaOid, GetUserId())) - ereport(ERROR, - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("Cannot find the schema \"%s\", because it does not exist or you do not have permission.", stmt->schema_name))); - parsetree_list = gen_grantschema_subcmds(schema_name, rolname, stmt->is_grant, stmt->with_grant_option, priv_name); /* Run all subcommands */ foreach(parsetree_item, parsetree_list) @@ -3772,22 +3761,17 @@ exec_stmt_grantschema(PLtsql_execstate *estate, PLtsql_stmt_grantschema *stmt) CommandCounterIncrement(); } /* Add entry for each grant statement. */ - if (stmt->is_grant && !check_bbf_schema_for_entry(stmt->schema_name, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, priv_name, rolname)) - add_entry_to_bbf_schema(stmt->schema_name, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, priv_name, rolname, NULL); + if (stmt->is_grant && !check_bbf_schema_for_entry(stmt->schema_name, "ALL", priv_name, rolname)) + add_entry_to_bbf_schema(stmt->schema_name, "ALL", priv_name, rolname, NULL); /* Remove entry for each revoke statement. */ - if (!stmt->is_grant && check_bbf_schema_for_entry(stmt->schema_name, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, priv_name, rolname)) + if (!stmt->is_grant && check_bbf_schema_for_entry(stmt->schema_name, "ALL", priv_name, rolname)) { /* If any object in the schema has the OBJECT level permission. Then, internally grant that permission back. */ grant_perms_to_objects_in_schema(stmt->schema_name, priv_name, rolname); - del_from_bbf_schema(stmt->schema_name, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, priv_name, rolname); + del_from_bbf_schema(stmt->schema_name, "ALL", priv_name, rolname); } - pfree(rolname); } } - pfree(user); - pfree(schema_name); - pfree(dbname); - pfree(login); return PLTSQL_RC_OK; } diff --git a/contrib/babelfishpg_tsql/src/pl_handler.c b/contrib/babelfishpg_tsql/src/pl_handler.c index ab83ccdf4af..10297b0c90e 100644 --- a/contrib/babelfishpg_tsql/src/pl_handler.c +++ b/contrib/babelfishpg_tsql/src/pl_handler.c @@ -3641,10 +3641,7 @@ bbf_ProcessUtility(PlannedStmt *pstmt, char *permissions[] = {"select", "insert", "update", "references", "delete"}; for(i = 0; i < 5; i++) { - /* - * If object permission doesn't exist already, add an entry to the catalog. - */ - if (!check_bbf_schema_for_entry(logical_schema, obj, permissions[i], rol_spec->rolename)) + if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, obj, permissions[i], rol_spec->rolename)) add_entry_to_bbf_schema(logical_schema, obj, permissions[i], rol_spec->rolename, obj_type); } } @@ -3660,15 +3657,10 @@ bbf_ProcessUtility(PlannedStmt *pstmt, char *permissions[] = {"select", "insert", "update", "references", "delete"}; for(i = 0; i < 5; i++) { - /* - * 1. If only schema permission exists, don't revoke any permission. - * 2. If only object permission exists, delete entry from the catalog and revoke permission. - * 3. If both schema and object permission exist, don't revoke any permission but delete object - * entry from the catalog. - */ - if (check_bbf_schema_for_entry(logical_schema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, permissions[i], rol_spec->rolename) && !has_schema_perms) + if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logical_schema, "ALL", permissions[i], rol_spec->rolename) && !has_schema_perms) has_schema_perms = true; - del_from_bbf_schema(logical_schema, obj, permissions[i], rol_spec->rolename); + if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logical_schema, obj, permissions[i], rol_spec->rolename)) + del_from_bbf_schema(logical_schema, obj, permissions[i], rol_spec->rolename); } if (has_schema_perms) return; @@ -3695,12 +3687,7 @@ bbf_ProcessUtility(PlannedStmt *pstmt, foreach(lc, grant->grantees) { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - /* - * Don't add an entry, if the permission is granted on column list. - */ - if (ap->cols != NULL) - break; - if (!check_bbf_schema_for_entry(logical_schema, obj, ap->priv_name, rol_spec->rolename)) + if ((ap->cols == NULL) && (rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, obj, ap->priv_name, rol_spec->rolename)) add_entry_to_bbf_schema(logical_schema, obj, ap->priv_name, rol_spec->rolename, obj_type); } } @@ -3713,7 +3700,7 @@ bbf_ProcessUtility(PlannedStmt *pstmt, * 1. If GRANT on schema does not exist, execute REVOKE statement and remove the catalog entry if exists. * 2. If GRANT on schema exist, only remove the entry from the catalog if exists. */ - if ((logical_schema != NULL) && !check_bbf_schema_for_entry(logical_schema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, ap->priv_name, rol_spec->rolename)) + if ((logical_schema != NULL) && (rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, "ALL", ap->priv_name, rol_spec->rolename)) { if (prev_ProcessUtility) prev_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, @@ -3722,12 +3709,8 @@ bbf_ProcessUtility(PlannedStmt *pstmt, standard_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, queryEnv, dest, qc); } - /* - * Don't remove an entry, if the permission is revoked on column list. - */ - if (ap->cols != NULL) - break; - del_from_bbf_schema(logical_schema, obj, ap->priv_name, rol_spec->rolename); + if ((ap->cols == NULL) && (rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logical_schema, obj, ap->priv_name, rol_spec->rolename)) + del_from_bbf_schema(logical_schema, obj, ap->priv_name, rol_spec->rolename); } } } @@ -3760,28 +3743,28 @@ bbf_ProcessUtility(PlannedStmt *pstmt, logicalschema = get_logical_schema_name(schemaname, true); funcname = strVal(func); } - + /* + * Case: When ALL PRIVILEGES is revoked internally during create function. + * Check if schema entry exists in the catalog, do not revoke any permission if exists. + */ + if (pstmt->stmt_len == 0 && list_length(grant->privileges) == 0) + { + if(check_bbf_schema_for_schema(logicalschema, "ALL", "execute")) + return; + break; + } /* If ALL PRIVILEGES is granted/revoked. */ if (list_length(grant->privileges) == 0) { - /* - * Case: When ALL PRIVILEGES is revoked internally during create function. - * Check if schema entry exists in the catalog, do not revoke any permission if exists. - */ - if (pstmt->stmt_len == 0) - { - if(check_bbf_schema_for_schema(logicalschema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, "execute")) - return; - } - if (grant->is_grant) { foreach(lc, grant->grantees) { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - if (!check_bbf_schema_for_entry(logicalschema, funcname, "execute", rol_spec->rolename)) + if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logicalschema, funcname, "execute", rol_spec->rolename)) add_entry_to_bbf_schema(logicalschema, funcname, "execute", rol_spec->rolename, obj_type); } + break; } else { @@ -3789,14 +3772,15 @@ bbf_ProcessUtility(PlannedStmt *pstmt, { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); bool has_schema_perms = false; - if (check_bbf_schema_for_entry(logicalschema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, "execute", rol_spec->rolename) && !has_schema_perms) + if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logicalschema, "ALL", "execute", rol_spec->rolename) && !has_schema_perms) has_schema_perms = true; - del_from_bbf_schema(logicalschema, funcname, "execute", rol_spec->rolename); + if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logicalschema, funcname, "execute", rol_spec->rolename)) + del_from_bbf_schema(logicalschema, funcname, "execute", rol_spec->rolename); if (has_schema_perms) return; } + break; } - break; } foreach(lc1, grant->privileges) { @@ -3814,11 +3798,9 @@ bbf_ProcessUtility(PlannedStmt *pstmt, foreach(lc, grant->grantees) { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - /* Add an entry to the catalog, if an entry doesn't exist already. */ - if (!check_bbf_schema_for_entry(logicalschema, funcname, ap->priv_name, rol_spec->rolename)) - { + /* Don't store a row in catalog, if permission is granted for column */ + if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logicalschema, funcname, ap->priv_name, rol_spec->rolename)) add_entry_to_bbf_schema(logicalschema, funcname, ap->priv_name, rol_spec->rolename, obj_type); - } } } else @@ -3827,10 +3809,10 @@ bbf_ProcessUtility(PlannedStmt *pstmt, { RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); /* - * 1. If GRANT on schema does not exist, execute REVOKE statement and remove the catalog entry if exists. - * 2. If GRANT on schema exist, only remove the entry from the catalog if exists. - */ - if (!check_bbf_schema_for_entry(logicalschema, PERMISSIONS_FOR_ALL_OBJECTS_IN_SCHEMA, ap->priv_name, rol_spec->rolename)) + * 1. If GRANT on schema does not exist, execute REVOKE statement and remove the catalog entry if exists. + * 2. If GRANT on schema exist, only remove the entry from the catalog if exists. + */ + if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logicalschema, "ALL", ap->priv_name, rol_spec->rolename)) { /* Execute REVOKE statement. */ if (prev_ProcessUtility) @@ -3840,8 +3822,8 @@ bbf_ProcessUtility(PlannedStmt *pstmt, standard_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, queryEnv, dest, qc); } - /* Remove an entry from the catalog, if it exists. */ - del_from_bbf_schema(logicalschema, funcname, ap->priv_name, rol_spec->rolename); + if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logicalschema, funcname, ap->priv_name, rol_spec->rolename)) + del_from_bbf_schema(logicalschema, funcname, ap->priv_name, rol_spec->rolename); } } } diff --git a/contrib/babelfishpg_tsql/src/pltsql_utils.c b/contrib/babelfishpg_tsql/src/pltsql_utils.c index d635d81ab7a..df3c57df719 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_utils.c +++ b/contrib/babelfishpg_tsql/src/pltsql_utils.c @@ -1036,10 +1036,7 @@ update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char if (grantee && stmt->grantees) { RoleSpec *tmp = (RoleSpec *) llast(stmt->grantees); - if (strcmp(grantee, "public") == 0) - { - tmp->roletype = ROLESPEC_PUBLIC; - } + tmp->rolename = pstrdup(grantee); } diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index be3ceece6cb..695b28dc468 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -5527,11 +5527,6 @@ makeGrantdbStatement(TSqlParser::Security_statementContext *ctx) char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); grantee_list = lappend(grantee_list, grantee_name); } - if (prin->PUBLIC()) - { - char *grantee_name = pstrdup("public"); - grantee_list = lappend(grantee_list, grantee_name); - } } result->grantees = grantee_list; return (PLtsql_stmt *) result; @@ -5560,11 +5555,6 @@ makeGrantdbStatement(TSqlParser::Security_statementContext *ctx) char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); grantee_list = lappend(grantee_list, grantee_name); } - if (prin->PUBLIC()) - { - char *grantee_name = pstrdup("public"); - grantee_list = lappend(grantee_list, grantee_name); - } } result->grantees = grantee_list; return (PLtsql_stmt *) result; @@ -5595,11 +5585,6 @@ makeGrantdbStatement(TSqlParser::Security_statementContext *ctx) char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); grantee_list = lappend(grantee_list, grantee_name); } - if (prin->PUBLIC()) - { - char *grantee_name = pstrdup("public"); - grantee_list = lappend(grantee_list, grantee_name); - } } List *privilege_list = NIL; for (auto perm: ctx->grant_statement()->permissions()->permission()) @@ -5652,11 +5637,6 @@ makeGrantdbStatement(TSqlParser::Security_statementContext *ctx) char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); grantee_list = lappend(grantee_list, grantee_name); } - if (prin->PUBLIC()) - { - char *grantee_name = pstrdup("public"); - grantee_list = lappend(grantee_list, grantee_name); - } } List *privilege_list = NIL; for (auto perm: ctx->revoke_statement()->permissions()->permission()) diff --git a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp index 64a4d12f89e..29cdc5ac320 100644 --- a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp @@ -1704,8 +1704,7 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedGrantStmt(TSqlParser::Gran continue; else { - unsupported_feature = "GRANT PERMISSION " + ::getFullText(single_perm); - std::transform(unsupported_feature.begin(), unsupported_feature.end(), unsupported_feature.begin(), ::toupper); + unsupported_feature = "GRANT PERMISSION " + perm->getText(); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(perm)); } } @@ -1720,7 +1719,6 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedGrantStmt(TSqlParser::Gran if (obj_type && !(obj_type->OBJECT() || obj_type->SCHEMA())) { unsupported_feature = "GRANT ON " + obj_type->getText(); - std::transform(unsupported_feature.begin(), unsupported_feature.end(), unsupported_feature.begin(), ::toupper); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(obj_type)); } } @@ -1800,8 +1798,7 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedRevokeStmt(TSqlParser::Rev continue; else { - unsupported_feature = "REVOKE PERMISSION " + ::getFullText(single_perm); - std::transform(unsupported_feature.begin(), unsupported_feature.end(), unsupported_feature.begin(), ::toupper); + unsupported_feature = "REVOKE PERMISSION " + perm->getText(); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(perm)); } } @@ -1816,7 +1813,6 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedRevokeStmt(TSqlParser::Rev if (obj_type && !(obj_type->OBJECT() || obj_type->SCHEMA())) { unsupported_feature = "REVOKE ON " + obj_type->getText(); - std::transform(unsupported_feature.begin(), unsupported_feature.end(), unsupported_feature.begin(), ::toupper); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(obj_type)); } } diff --git a/test/JDBC/expected/BABEL-GRANT.out b/test/JDBC/expected/BABEL-GRANT.out index 2a59cf3dead..d3f48b241fe 100644 --- a/test/JDBC/expected/BABEL-GRANT.out +++ b/test/JDBC/expected/BABEL-GRANT.out @@ -174,7 +174,7 @@ GO REVOKE SELECT ON SCHEMA::scm FROM guest; GO -GRANT showplan ON OBJECT::t1 TO guest; -- unsupported permission +GRANT SHOWPLAN ON OBJECT::t1 TO guest; -- unsupported permission GO ~~ERROR (Code: 33557097)~~ @@ -188,48 +188,20 @@ GO ~~ERROR (Message: 'REVOKE PERMISSION SHOWPLAN' is not currently supported in Babelfish)~~ -GRANT ALL ON SCHEMA::scm TO guest; +GRANT ALL ON SCHEMA::scm TO guest; -- unsupported class GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The all permission has been deprecated and is not available for this class of entity.)~~ -REVOKE ALL ON SCHEMA::scm TO guest; +REVOKE ALL ON SCHEMA::scm TO guest; -- unsupported class GO ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The all permission has been deprecated and is not available for this class of entity.)~~ -GRANT create table ON OBJECT::t1 TO guest; -- unsupported permission -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: 'GRANT PERMISSION CREATE TABLE' is not currently supported in Babelfish)~~ - - -REVOKE create table ON OBJECT::t2 FROM alogin; -- unsupported permission -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: 'REVOKE PERMISSION CREATE TABLE' is not currently supported in Babelfish)~~ - - -GRANT SELECT ON table::t1 TO guest; -- unsupported object -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: 'GRANT ON TABLE' is not currently supported in Babelfish)~~ - - -REVOKE SELECT ON table::t1 FROM guest; -- unsupported object -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: 'REVOKE ON TABLE' is not currently supported in Babelfish)~~ - - GRANT ALL ON OBJECT::t1 TO guest WITH GRANT OPTION AS superuser; GO ~~ERROR (Code: 33557097)~~ diff --git a/test/JDBC/expected/GRANT_SCHEMA.out b/test/JDBC/expected/GRANT_SCHEMA.out index 935acbe2f53..1891d685978 100644 --- a/test/JDBC/expected/GRANT_SCHEMA.out +++ b/test/JDBC/expected/GRANT_SCHEMA.out @@ -12,18 +12,9 @@ go create user babel_4344_u1 for login babel_4344_l1; go -create login αιώνια with password = '12345678' -go - -create user αιώνια for login αιώνια; -go - create schema babel_4344_s1; go -create schema αγάπη; -go - create schema babel_4344_s2 authorization babel_4344_u1; go @@ -36,9 +27,6 @@ go create table babel_4344_s2.babel_4344_t1(a int); go -create table αγάπη.abc(a int); -go - create table babel_4344_t3(a int, b int); go @@ -57,69 +45,12 @@ go create proc babel_4344_s1.babel_4344_p1 as select 2; go -create proc babel_4344_s1.babel_4344_p3 as select 3; -go - CREATE FUNCTION babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.tables) END go CREATE FUNCTION babel_4344_s1.babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END go -grant SELECT on schema::babel_4344_S1 to public, αιώνια; -go - -grant select on schema::αγάπη to αιώνια; -go - --- tsql user=αιώνια password=12345678 -use babel_4344_d1; -go - -select * from αγάπη.abc; -go -~~START~~ -int -~~END~~ - - -select * from babel_4344_S1.babel_4344_t1; -go -~~START~~ -int -~~END~~ - - -use master; -go - --- tsql user=babel_4344_l1 password=12345678 -use babel_4344_d1; -go - --- User has select privileges, tables and views be accessible -select * from babel_4344_s1.babel_4344_t1 -go -~~START~~ -int -~~END~~ - -select * from babel_4344_s1.babel_4344_v1; -go -~~START~~ -int -2 -~~END~~ - -use master; -go - --- tsql -use babel_4344_d1; -go -revoke select on schema::babel_4344_s1 from public, αιώνια; -go - -- tsql user=babel_4344_l1 password=12345678 use babel_4344_d1; go @@ -186,9 +117,9 @@ go -- GRANT OBJECT privilege use babel_4344_d1; go -grant SELECT on babel_4344_t1 to BABEL_4344_U1; +grant select on babel_4344_t1 to babel_4344_u1; go -grant SELECT on babel_4344_s1.babel_4344_t1 to babel_4344_u1; +grant select on babel_4344_s1.babel_4344_t1 to babel_4344_u1; go grant all on babel_4344_s1.babel_4344_t1 to babel_4344_u1; go @@ -204,14 +135,7 @@ grant execute on babel_4344_p1 to babel_4344_u1; go grant execute on babel_4344_s1.babel_4344_p1 to babel_4344_u1; go --- inside a transaction, permission will not be granted since it is rolled back -begin transaction; -exec sp_executesql N'grant execute on babel_4344_s1.babel_4344_p3 to babel_4344_u1;'; -rollback transaction; -go - --- Mixed case -grant Execute on Babel_4344_F1 to babel_4344_u1; +grant execute on babel_4344_f1 to babel_4344_u1; go grant execute on babel_4344_s1.babel_4344_f1 to babel_4344_u1; go @@ -228,36 +152,8 @@ go ~~ERROR (Message: Cannot find the principal 'jdbc_user', because it does not exist or you do not have permission.)~~ -grant SELECT on schema::babel_4344_s2 to guest; -- should pass -go -grant select on schema::"" to guest; -- should fail -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.)~~ - -grant select on schema::non_existing_schema to guest; -- should fail -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: schema "non_existing_schema" does not exist)~~ - --- grant statement via a procedure -create procedure grant_perm_proc as begin exec('grant select on schema::[] to guest') end; -go -exec grant_perm_proc; -- should fail -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.)~~ - --- non-existing role -grant SELECT on schema::dbo to guest, babel_4344_u3; -- should fail +grant select on schema::babel_4344_s2 to guest; -- should pass go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: Cannot find the principal 'babel_4344_u3', because it does not exist or you do not have permission.)~~ - -- tsql user=babel_4344_l1 password=12345678 -- User has OBJECT privileges, should be accessible. @@ -319,12 +215,6 @@ int 2 ~~END~~ -exec babel_4344_s1.babel_4344_p3; -- should fail, grant statement was rolled back -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for procedure babel_4344_p3)~~ - select * from babel_4344_f1(); go ~~START~~ @@ -352,7 +242,7 @@ grant select on schema::babel_4344_s1 to babel_4344_u1; -- should fail go ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself.)~~ +~~ERROR (Message: Cannot find the schema "babel_4344_s1", because it does not exist or you do not have permission.)~~ use master; go @@ -366,19 +256,6 @@ go use master; go --- psql --- GRANT statement add an entry to the catalog -select schema_name, object_name, permission, grantee from sys.babelfish_schema_permissions -where schema_name = 'babel_4344_s1' collate "C" and object_name = 'ALL' collate "C" order by permission; -go -~~START~~ -name#!#name#!#name#!#name -babel_4344_s1#!#ALL#!#execute#!#babel_4344_d1_babel_4344_u1 -babel_4344_s1#!#ALL#!#insert#!#babel_4344_d1_babel_4344_u1 -babel_4344_s1#!#ALL#!#select#!#babel_4344_d1_babel_4344_u1 -~~END~~ - - -- tsql user=babel_4344_l1 password=12345678 -- User has OBJECT and SCHEMA privileges, should be accessible. use babel_4344_d1; @@ -418,7 +295,7 @@ select * from babel_4344_s1.babel_4344_f1(); go ~~START~~ int -11 +10 ~~END~~ use master; @@ -462,14 +339,14 @@ int 2 ~~END~~ -exec babel_4344_s1.babel_4344_p1; +exec babel_4344_s1.babel_4344_p1; -- TODO: should be accessible go ~~START~~ int 2 ~~END~~ -select * from babel_4344_s1.babel_4344_f1(); +select * from babel_4344_s1.babel_4344_f1(); -- TODO: should be accessible go ~~START~~ int @@ -535,7 +412,7 @@ select * from babel_4344_s1.babel_4344_f2(); go ~~START~~ int -15 +14 ~~END~~ use master; @@ -600,7 +477,7 @@ select * from babel_4344_s1.babel_4344_f1(); go ~~START~~ int -15 +14 ~~END~~ select * from babel_4344_s2.babel_4344_t1; @@ -621,15 +498,6 @@ go use master; go --- psql --- REVOKE on schema removes the entry from the catalog -select * from sys.babelfish_schema_permissions where schema_name = 'babel_4344_s1' collate sys.database_default; -go -~~START~~ -int2#!#name#!#name#!#name#!#name#!#name -~~END~~ - - -- tsql user=babel_4344_l1 password=12345678 -- User has no privileges, shouldn't be accessible. use babel_4344_d1; @@ -673,54 +541,6 @@ go use master; go --- psql --- grant object permission -grant select on babel_4344_s1.babel_4344_t1 to babel_4344_d1_babel_4344_u1; -go - --- tsql --- grant schema permission -use babel_4344_d1; -go -grant select on schema::babel_4344_s1 to babel_4344_u1; -go -use master -go - --- tsql user=babel_4344_l1 password=12345678 -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1; -- accessible -go -~~START~~ -int -2 -3 -3 -4 -5 -~~END~~ - -use master -go - --- psql --- revoke schema permission -revoke select on all tables in schema babel_4344_s1 from babel_4344_d1_babel_4344_u1; -go - --- tsql user=babel_4344_l1 password=12345678 -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1; -- not accessible -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t1)~~ - -use master -go - -- tsql -- Drop objects use babel_4344_d1; @@ -759,9 +579,6 @@ go drop proc babel_4344_s1.babel_4344_p2; go -drop proc babel_4344_s1.babel_4344_p3; -go - drop function babel_4344_f1; go @@ -780,18 +597,9 @@ go drop schema babel_4344_s2; go -drop table αγάπη.abc; -go - -drop schema αγάπη; -go - drop user babel_4344_u1; go -drop user αιώνια; -go - use master; go @@ -821,27 +629,3 @@ void -- tsql drop login babel_4344_l1; go - --- psql --- Need to terminate active session before cleaning up the login -SELECT pg_terminate_backend(pid) FROM pg_stat_get_activity(NULL) -WHERE sys.suser_name(usesysid) = 'αιώνια' AND backend_type = 'client backend' AND usesysid IS NOT NULL; -go -~~START~~ -bool -t -~~END~~ - - --- Wait to sync with another session -SELECT pg_sleep(1); -go -~~START~~ -void - -~~END~~ - - --- tsql -drop login αιώνια; -go diff --git a/test/JDBC/input/BABEL-GRANT.sql b/test/JDBC/input/BABEL-GRANT.sql index 8388f782ffd..3e0155ea283 100644 --- a/test/JDBC/input/BABEL-GRANT.sql +++ b/test/JDBC/input/BABEL-GRANT.sql @@ -164,28 +164,16 @@ GO REVOKE SELECT ON SCHEMA::scm FROM guest; GO -GRANT showplan ON OBJECT::t1 TO guest; -- unsupported permission +GRANT SHOWPLAN ON OBJECT::t1 TO guest; -- unsupported permission GO REVOKE SHOWPLAN ON OBJECT::t2 TO alogin; -- unsupported permission GO -GRANT ALL ON SCHEMA::scm TO guest; +GRANT ALL ON SCHEMA::scm TO guest; -- unsupported class GO -REVOKE ALL ON SCHEMA::scm TO guest; -GO - -GRANT create table ON OBJECT::t1 TO guest; -- unsupported permission -GO - -REVOKE create table ON OBJECT::t2 FROM alogin; -- unsupported permission -GO - -GRANT SELECT ON table::t1 TO guest; -- unsupported object -GO - -REVOKE SELECT ON table::t1 FROM guest; -- unsupported object +REVOKE ALL ON SCHEMA::scm TO guest; -- unsupported class GO GRANT ALL ON OBJECT::t1 TO guest WITH GRANT OPTION AS superuser; diff --git a/test/JDBC/input/GRANT_SCHEMA.mix b/test/JDBC/input/GRANT_SCHEMA.mix index f4af9f7af76..1572bea803b 100644 --- a/test/JDBC/input/GRANT_SCHEMA.mix +++ b/test/JDBC/input/GRANT_SCHEMA.mix @@ -12,18 +12,9 @@ go create user babel_4344_u1 for login babel_4344_l1; go -create login αιώνια with password = '12345678' -go - -create user αιώνια for login αιώνια; -go - create schema babel_4344_s1; go -create schema αγάπη; -go - create schema babel_4344_s2 authorization babel_4344_u1; go @@ -36,9 +27,6 @@ go create table babel_4344_s2.babel_4344_t1(a int); go -create table αγάπη.abc(a int); -go - create table babel_4344_t3(a int, b int); go @@ -57,52 +45,12 @@ go create proc babel_4344_s1.babel_4344_p1 as select 2; go -create proc babel_4344_s1.babel_4344_p3 as select 3; -go - CREATE FUNCTION babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.tables) END go CREATE FUNCTION babel_4344_s1.babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END go -grant SELECT on schema::babel_4344_S1 to public, αιώνια; -go - -grant select on schema::αγάπη to αιώνια; -go - --- tsql user=αιώνια password=12345678 -use babel_4344_d1; -go - -select * from αγάπη.abc; -go - -select * from babel_4344_S1.babel_4344_t1; -go - -use master; -go - --- tsql user=babel_4344_l1 password=12345678 -use babel_4344_d1; -go - --- User has select privileges, tables and views be accessible -select * from babel_4344_s1.babel_4344_t1 -go -select * from babel_4344_s1.babel_4344_v1; -go -use master; -go - --- tsql -use babel_4344_d1; -go -revoke select on schema::babel_4344_s1 from public, αιώνια; -go - -- tsql user=babel_4344_l1 password=12345678 use babel_4344_d1; go @@ -133,9 +81,9 @@ go -- GRANT OBJECT privilege use babel_4344_d1; go -grant SELECT on babel_4344_t1 to BABEL_4344_U1; +grant select on babel_4344_t1 to babel_4344_u1; go -grant SELECT on babel_4344_s1.babel_4344_t1 to babel_4344_u1; +grant select on babel_4344_s1.babel_4344_t1 to babel_4344_u1; go grant all on babel_4344_s1.babel_4344_t1 to babel_4344_u1; go @@ -151,14 +99,7 @@ grant execute on babel_4344_p1 to babel_4344_u1; go grant execute on babel_4344_s1.babel_4344_p1 to babel_4344_u1; go --- inside a transaction, permission will not be granted since it is rolled back -begin transaction; -exec sp_executesql N'grant execute on babel_4344_s1.babel_4344_p3 to babel_4344_u1;'; -rollback transaction; -go - --- Mixed case -grant Execute on Babel_4344_F1 to babel_4344_u1; +grant execute on babel_4344_f1 to babel_4344_u1; go grant execute on babel_4344_s1.babel_4344_f1 to babel_4344_u1; go @@ -167,19 +108,7 @@ grant select on schema::babel_4344_s2 to babel_4344_u1; -- should fail go grant select on schema::babel_4344_s2 to jdbc_user; -- should fail go -grant SELECT on schema::babel_4344_s2 to guest; -- should pass -go -grant select on schema::"" to guest; -- should fail -go -grant select on schema::non_existing_schema to guest; -- should fail -go --- grant statement via a procedure -create procedure grant_perm_proc as begin exec('grant select on schema::[] to guest') end; -go -exec grant_perm_proc; -- should fail -go --- non-existing role -grant SELECT on schema::dbo to guest, babel_4344_u3; -- should fail +grant select on schema::babel_4344_s2 to guest; -- should pass go -- tsql user=babel_4344_l1 password=12345678 @@ -204,8 +133,6 @@ exec babel_4344_p1; go exec babel_4344_s1.babel_4344_p1; go -exec babel_4344_s1.babel_4344_p3; -- should fail, grant statement was rolled back -go select * from babel_4344_f1(); go select * from babel_4344_s1.babel_4344_f1(); @@ -229,12 +156,6 @@ go use master; go --- psql --- GRANT statement add an entry to the catalog -select schema_name, object_name, permission, grantee from sys.babelfish_schema_permissions -where schema_name = 'babel_4344_s1' collate "C" and object_name = 'ALL' collate "C" order by permission; -go - -- tsql user=babel_4344_l1 password=12345678 -- User has OBJECT and SCHEMA privileges, should be accessible. use babel_4344_d1; @@ -275,9 +196,9 @@ select * from babel_4344_s1.babel_4344_t3 -- not accessible go select * from babel_4344_s1.babel_4344_v1; go -exec babel_4344_s1.babel_4344_p1; +exec babel_4344_s1.babel_4344_p1; -- TODO: should be accessible go -select * from babel_4344_s1.babel_4344_f1(); +select * from babel_4344_s1.babel_4344_f1(); -- TODO: should be accessible go select * from babel_4344_s2.babel_4344_t1; go @@ -366,11 +287,6 @@ go use master; go --- psql --- REVOKE on schema removes the entry from the catalog -select * from sys.babelfish_schema_permissions where schema_name = 'babel_4344_s1' collate sys.database_default; -go - -- tsql user=babel_4344_l1 password=12345678 -- User has no privileges, shouldn't be accessible. use babel_4344_d1; @@ -390,41 +306,6 @@ go use master; go --- psql --- grant object permission -grant select on babel_4344_s1.babel_4344_t1 to babel_4344_d1_babel_4344_u1; -go - --- tsql --- grant schema permission -use babel_4344_d1; -go -grant select on schema::babel_4344_s1 to babel_4344_u1; -go -use master -go - --- tsql user=babel_4344_l1 password=12345678 -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1; -- accessible -go -use master -go - --- psql --- revoke schema permission -revoke select on all tables in schema babel_4344_s1 from babel_4344_d1_babel_4344_u1; -go - --- tsql user=babel_4344_l1 password=12345678 -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1; -- not accessible -go -use master -go - -- tsql -- Drop objects use babel_4344_d1; @@ -463,9 +344,6 @@ go drop proc babel_4344_s1.babel_4344_p2; go -drop proc babel_4344_s1.babel_4344_p3; -go - drop function babel_4344_f1; go @@ -484,18 +362,9 @@ go drop schema babel_4344_s2; go -drop table αγάπη.abc; -go - -drop schema αγάπη; -go - drop user babel_4344_u1; go -drop user αιώνια; -go - use master; go @@ -515,17 +384,3 @@ go -- tsql drop login babel_4344_l1; go - --- psql --- Need to terminate active session before cleaning up the login -SELECT pg_terminate_backend(pid) FROM pg_stat_get_activity(NULL) -WHERE sys.suser_name(usesysid) = 'αιώνια' AND backend_type = 'client backend' AND usesysid IS NOT NULL; -go - --- Wait to sync with another session -SELECT pg_sleep(1); -go - --- tsql -drop login αιώνια; -go diff --git a/test/python/expected/sql_validation_framework/expected_create.out b/test/python/expected/sql_validation_framework/expected_create.out index 6be51616c03..26777ae841c 100644 --- a/test/python/expected/sql_validation_framework/expected_create.out +++ b/test/python/expected/sql_validation_framework/expected_create.out @@ -72,6 +72,7 @@ Could not find tests for procedure sys.printarg Could not find tests for procedure sys.sp_cursor_list Could not find tests for procedure sys.sp_describe_cursor Could not find tests for table sys.babelfish_helpcollation +Could not find tests for table sys.babelfish_schema_permissions Could not find tests for table sys.babelfish_syslanguages Could not find tests for table sys.service_settings Could not find tests for table sys.spt_datatype_info_table From 7fc889ce6f5da7ef2258e9a3e3fe7a3907467a42 Mon Sep 17 00:00:00 2001 From: shalinilohia50 <46928246+shalinilohia50@users.noreply.github.com> Date: Thu, 23 Nov 2023 00:47:08 +0530 Subject: [PATCH 7/7] Revert GRANT/REVOKE on SCHEMA (#2056) This commit reverts e302bcac970b10. Task: BABEL-4344 Authored-by: Shalini Lohia --- contrib/babelfishpg_tsql/sql/ownership.sql | 11 - .../babelfishpg_tsql--3.3.0--3.4.0.sql | 12 - contrib/babelfishpg_tsql/src/catalog.c | 369 ---------- contrib/babelfishpg_tsql/src/catalog.h | 65 -- contrib/babelfishpg_tsql/src/codegen.c | 1 - contrib/babelfishpg_tsql/src/dbcmds.c | 6 +- contrib/babelfishpg_tsql/src/iterative_exec.c | 9 - contrib/babelfishpg_tsql/src/pl_exec-2.c | 103 +-- contrib/babelfishpg_tsql/src/pl_funcs-2.c | 1 - contrib/babelfishpg_tsql/src/pl_handler.c | 283 +------- contrib/babelfishpg_tsql/src/pltsql.h | 19 +- contrib/babelfishpg_tsql/src/pltsql_utils.c | 100 +-- contrib/babelfishpg_tsql/src/stmt_walker.c | 2 - contrib/babelfishpg_tsql/src/stmt_walker.h | 2 - contrib/babelfishpg_tsql/src/tsqlIface.cpp | 148 ---- contrib/babelfishpg_tsql/src/tsqlNodes.h | 1 - .../src/tsqlUnsupportedFeatureHandler.cpp | 10 +- .../JDBC/expected/AUTO_ANALYZE-vu-prepare.out | 1 - test/JDBC/expected/BABEL-CROSS-DB.out | 6 - test/JDBC/expected/BABEL-GRANT.out | 26 +- test/JDBC/expected/BABEL-SESSION.out | 15 - ...BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.out | 47 +- .../JDBC/expected/GRANT_SCHEMA-vu-cleanup.out | 75 --- .../JDBC/expected/GRANT_SCHEMA-vu-prepare.out | 74 -- test/JDBC/expected/GRANT_SCHEMA-vu-verify.out | 291 -------- test/JDBC/expected/GRANT_SCHEMA.out | 631 ------------------ test/JDBC/input/BABEL-CROSS-DB.mix | 6 - test/JDBC/input/BABEL-GRANT.sql | 22 - test/JDBC/input/BABEL-SESSION.mix | 15 - ...BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.sql | 15 +- test/JDBC/input/GRANT_SCHEMA-vu-cleanup.mix | 66 -- test/JDBC/input/GRANT_SCHEMA-vu-prepare.mix | 74 -- test/JDBC/input/GRANT_SCHEMA-vu-verify.mix | 179 ----- test/JDBC/input/GRANT_SCHEMA.mix | 386 ----------- test/JDBC/jdbc_schedule | 3 - test/JDBC/upgrade/13_6/schedule | 1 - test/JDBC/upgrade/13_9/schedule | 1 - test/JDBC/upgrade/14_10/schedule | 1 - test/JDBC/upgrade/14_11/schedule | 1 - test/JDBC/upgrade/14_3/schedule | 1 - test/JDBC/upgrade/14_5/schedule | 1 - test/JDBC/upgrade/14_6/schedule | 1 - test/JDBC/upgrade/15_2/schedule | 1 - test/JDBC/upgrade/15_4/schedule | 2 +- .../expected_create.out | 2 - 45 files changed, 52 insertions(+), 3034 deletions(-) delete mode 100644 test/JDBC/expected/GRANT_SCHEMA-vu-cleanup.out delete mode 100644 test/JDBC/expected/GRANT_SCHEMA-vu-prepare.out delete mode 100644 test/JDBC/expected/GRANT_SCHEMA-vu-verify.out delete mode 100644 test/JDBC/expected/GRANT_SCHEMA.out delete mode 100644 test/JDBC/input/GRANT_SCHEMA-vu-cleanup.mix delete mode 100644 test/JDBC/input/GRANT_SCHEMA-vu-prepare.mix delete mode 100644 test/JDBC/input/GRANT_SCHEMA-vu-verify.mix delete mode 100644 test/JDBC/input/GRANT_SCHEMA.mix diff --git a/contrib/babelfishpg_tsql/sql/ownership.sql b/contrib/babelfishpg_tsql/sql/ownership.sql index ee3a5446a43..b4180aaebdb 100644 --- a/contrib/babelfishpg_tsql/sql/ownership.sql +++ b/contrib/babelfishpg_tsql/sql/ownership.sql @@ -14,17 +14,6 @@ CREATE TABLE sys.babelfish_sysdatabases ( GRANT SELECT on sys.babelfish_sysdatabases TO PUBLIC; --- BABELFISH_SCHEMA_PERMISSIONS -CREATE TABLE sys.babelfish_schema_permissions ( - dbid smallint NOT NULL, - schema_name NAME NOT NULL, - object_name NAME NOT NULL, - permission NAME NOT NULL, - grantee NAME NOT NULL, - object_type NAME, - PRIMARY KEY(dbid, schema_name, object_name, permission, grantee) -); - -- BABELFISH_FUNCTION_EXT CREATE TABLE sys.babelfish_function_ext ( nspname NAME NOT NULL, diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql index fe141534577..2a70b44c35d 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.3.0--3.4.0.sql @@ -782,7 +782,6 @@ $BODY$ LANGUAGE plpgsql IMMUTABLE; - CREATE OR REPLACE FUNCTION sys.DATETRUNC(IN datepart PG_CATALOG.TEXT, IN date ANYELEMENT) RETURNS ANYELEMENT AS $body$ DECLARE @@ -889,17 +888,6 @@ END; $body$ LANGUAGE plpgsql STABLE; --- BABELFISH_SCHEMA_PERMISSIONS -CREATE TABLE IF NOT EXISTS sys.babelfish_schema_permissions ( - dbid smallint NOT NULL, - schema_name NAME NOT NULL, - object_name NAME NOT NULL, - permission NAME NOT NULL, - grantee NAME NOT NULL, - object_type NAME, - PRIMARY KEY(dbid, schema_name, object_name, permission, grantee) -); - create or replace function sys.babelfish_timezone_mapping(IN tmz text) returns text AS 'babelfishpg_tsql', 'timezone_mapping' LANGUAGE C IMMUTABLE ; diff --git a/contrib/babelfishpg_tsql/src/catalog.c b/contrib/babelfishpg_tsql/src/catalog.c index 8f1f9bdc2a2..1032acfb905 100644 --- a/contrib/babelfishpg_tsql/src/catalog.c +++ b/contrib/babelfishpg_tsql/src/catalog.c @@ -83,12 +83,6 @@ Oid bbf_servers_def_idx_oid; Oid bbf_function_ext_oid; Oid bbf_function_ext_idx_oid; -/***************************************** - * SCHEMA - *****************************************/ -Oid bbf_schema_perms_oid; -Oid bbf_schema_perms_idx_oid; - /***************************************** * DOMAIN MAPPING *****************************************/ @@ -1441,29 +1435,6 @@ clean_up_bbf_function_ext(int16 dbid) table_close(bbf_function_ext_rel, RowExclusiveLock); } - -/***************************************** - * SCHEMA - *****************************************/ - -Oid -get_bbf_schema_perms_oid() -{ - if (!OidIsValid(bbf_schema_perms_oid)) - bbf_schema_perms_oid = get_relname_relid(BBF_SCHEMA_PERMS_TABLE_NAME, - get_namespace_oid("sys", false)); - return bbf_schema_perms_oid; -} - -Oid -get_bbf_schema_perms_idx_oid() -{ - if (!OidIsValid(bbf_schema_perms_idx_oid)) - bbf_schema_perms_idx_oid = get_relname_relid(BBF_SCHEMA_PERMS_IDX_NAME, - get_namespace_oid("sys", false)); - return bbf_schema_perms_idx_oid; -} - /***************************************** * DOMAIN MAPPING *****************************************/ @@ -2828,346 +2799,6 @@ rename_procfunc_update_bbf_catalog(RenameStmt *stmt) table_close(bbf_func_ext_rel, RowExclusiveLock); } -/* Add a catalog entry. */ -void -add_entry_to_bbf_schema(const char *schema_name, - const char *object_name, - const char *permission, - const char *grantee, - const char *object_type) -{ - Relation bbf_schema_rel; - TupleDesc bbf_schema_dsc; - HeapTuple tuple_bbf_schema; - Datum new_record_bbf_schema[BBF_SCHEMA_PERMS_NUM_OF_COLS]; - bool new_record_nulls_bbf_schema[BBF_SCHEMA_PERMS_NUM_OF_COLS]; - int16 dbid = get_cur_db_id(); - - /* Fetch the relation */ - bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), - RowExclusiveLock); - bbf_schema_dsc = RelationGetDescr(bbf_schema_rel); - - /* Build a tuple to insert */ - MemSet(new_record_bbf_schema, 0, sizeof(new_record_bbf_schema)); - MemSet(new_record_nulls_bbf_schema, false, sizeof(new_record_nulls_bbf_schema)); - - new_record_bbf_schema[BBF_SCHEMA_PERMS_DBID] = Int16GetDatum(dbid); - new_record_bbf_schema[BBF_SCHEMA_PERMS_SCHEMA_NAME] = CStringGetDatum(pstrdup(schema_name)); - new_record_bbf_schema[BBF_SCHEMA_PERMS_OBJECT_NAME] = CStringGetDatum(pstrdup(object_name)); - new_record_bbf_schema[BBF_SCHEMA_PERMS_PERMISSION] = CStringGetDatum(pstrdup(permission)); - new_record_bbf_schema[BBF_SCHEMA_PERMS_GRANTEE] = CStringGetDatum(pstrdup(grantee)); - if (object_type != NULL) - new_record_bbf_schema[BBF_SCHEMA_PERMS_OBJECT_TYPE] = CStringGetDatum(pstrdup(object_type)); - else - new_record_nulls_bbf_schema[BBF_SCHEMA_PERMS_OBJECT_TYPE] = true; - - tuple_bbf_schema = heap_form_tuple(bbf_schema_dsc, - new_record_bbf_schema, - new_record_nulls_bbf_schema); - - /* Insert new record in the bbf_authid_user_ext table */ - CatalogTupleInsert(bbf_schema_rel, tuple_bbf_schema); - - /* Close bbf_authid_user_ext, but keep lock till commit */ - table_close(bbf_schema_rel, RowExclusiveLock); - - /* Advance cmd counter to make the insert visible */ - CommandCounterIncrement(); -} - -/* Check if the catalog entry exists. */ -bool -check_bbf_schema_for_entry(const char *schema_name, - const char *object_name, - const char *permission, - const char *grantee) -{ - Relation bbf_schema_rel; - HeapTuple tuple_bbf_schema; - ScanKeyData key[5]; - TableScanDesc scan; - bool catalog_entry_exists = false; - int16 dbid = get_cur_db_id(); - - bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), - AccessShareLock); - ScanKeyInit(&key[0], - Anum_bbf_schema_perms_dbid, - BTEqualStrategyNumber, F_INT2EQ, - Int16GetDatum(dbid)); - ScanKeyInit(&key[1], - Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(schema_name)); - ScanKeyInit(&key[2], - Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(object_name)); - ScanKeyInit(&key[3], - Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(permission)); - ScanKeyInit(&key[4], - Anum_bbf_schema_perms_grantee, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(grantee)); - - scan = table_beginscan_catalog(bbf_schema_rel, 5, key); - - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); - if (HeapTupleIsValid(tuple_bbf_schema)) - catalog_entry_exists = true; - - table_endscan(scan); - table_close(bbf_schema_rel, AccessShareLock); - return catalog_entry_exists; -} - -bool -check_bbf_schema_for_schema(const char *schema_name, - const char *object_name, - const char *permission) -{ - Relation bbf_schema_rel; - HeapTuple tuple_bbf_schema; - ScanKeyData key[4]; - TableScanDesc scan; - bool catalog_entry_exists = false; - int16 dbid = get_cur_db_id(); - - bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), - AccessShareLock); - ScanKeyInit(&key[0], - Anum_bbf_schema_perms_dbid, - BTEqualStrategyNumber, F_INT2EQ, - Int16GetDatum(dbid)); - ScanKeyInit(&key[1], - Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(schema_name)); - ScanKeyInit(&key[2], - Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(object_name)); - ScanKeyInit(&key[3], - Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(permission)); - - scan = table_beginscan_catalog(bbf_schema_rel, 4, key); - - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); - if (HeapTupleIsValid(tuple_bbf_schema)) - catalog_entry_exists = true; - - table_endscan(scan); - table_close(bbf_schema_rel, AccessShareLock); - return catalog_entry_exists; -} - -void -del_from_bbf_schema(const char *schema_name, - const char *object_name, - const char *permission, - const char *grantee) -{ - Relation bbf_schema_rel; - HeapTuple tuple_bbf_schema; - ScanKeyData key[5]; - TableScanDesc scan; - int16 dbid = get_cur_db_id(); - - bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), - RowExclusiveLock); - ScanKeyInit(&key[0], - Anum_bbf_schema_perms_dbid, - BTEqualStrategyNumber, F_INT2EQ, - Int16GetDatum(dbid)); - ScanKeyInit(&key[1], - Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(schema_name)); - ScanKeyInit(&key[2], - Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(object_name)); - ScanKeyInit(&key[3], - Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(permission)); - ScanKeyInit(&key[4], - Anum_bbf_schema_perms_grantee, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(grantee)); - - scan = table_beginscan_catalog(bbf_schema_rel, 5, key); - - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); - - if (HeapTupleIsValid(tuple_bbf_schema)) - CatalogTupleDelete(bbf_schema_rel, &tuple_bbf_schema->t_self); - - table_endscan(scan); - table_close(bbf_schema_rel, RowExclusiveLock); - - CommandCounterIncrement(); -} - -void -clean_up_bbf_schema(const char *schema_name, - const char *object_name, - bool is_schema) -{ - SysScanDesc scan; - Relation bbf_schema_rel; - HeapTuple tuple_bbf_schema; - int16 dbid = get_cur_db_id(); - - /* Fetch the relation */ - bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), - RowExclusiveLock); - - if (is_schema) - { - ScanKeyData scanKey[2]; - ScanKeyInit(&scanKey[0], - Anum_bbf_schema_perms_dbid, - BTEqualStrategyNumber, F_INT2EQ, - Int16GetDatum(dbid)); - ScanKeyInit(&scanKey[1], - Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(schema_name)); - scan = systable_beginscan(bbf_schema_rel, - get_bbf_schema_perms_idx_oid(), - true, NULL, 2, scanKey); - } - else - { - ScanKeyData scanKey[3]; - ScanKeyInit(&scanKey[0], - Anum_bbf_schema_perms_dbid, - BTEqualStrategyNumber, F_INT2EQ, - Int16GetDatum(dbid)); - ScanKeyInit(&scanKey[1], - Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(schema_name)); - ScanKeyInit(&scanKey[2], - Anum_bbf_schema_perms_object_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(object_name)); - scan = systable_beginscan(bbf_schema_rel, - get_bbf_schema_perms_idx_oid(), - true, NULL, 3, scanKey); - } - - while ((tuple_bbf_schema = systable_getnext(scan)) != NULL) - { - if (HeapTupleIsValid(tuple_bbf_schema)) - CatalogTupleDelete(bbf_schema_rel, - &tuple_bbf_schema->t_self); - } - - systable_endscan(scan); - table_close(bbf_schema_rel, RowExclusiveLock); -} - -void -grant_perms_to_objects_in_schema(const char *schema_name, - const char *permission, - const char *grantee) -{ - TableScanDesc scan; - Relation bbf_schema_rel; - HeapTuple tuple_bbf_schema; - const char *object_name; - const char *object_type; - ScanKeyData scanKey[4]; - int16 dbid = get_cur_db_id(); - const char *db_name = get_cur_db_name(); - - /* Fetch the relation */ - bbf_schema_rel = table_open(get_bbf_schema_perms_oid(), - AccessShareLock); - ScanKeyInit(&scanKey[0], - Anum_bbf_schema_perms_dbid, - BTEqualStrategyNumber, F_INT2EQ, - Int16GetDatum(dbid)); - ScanKeyInit(&scanKey[1], - Anum_bbf_schema_perms_schema_name, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(schema_name)); - ScanKeyInit(&scanKey[2], - Anum_bbf_schema_perms_permission, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(permission)); - ScanKeyInit(&scanKey[3], - Anum_bbf_schema_perms_grantee, - BTEqualStrategyNumber, F_NAMEEQ, - CStringGetDatum(grantee)); - - scan = table_beginscan_catalog(bbf_schema_rel, 4, scanKey); - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); - - while (HeapTupleIsValid(tuple_bbf_schema)) - { - Form_bbf_schema_perms schemaform; - schemaform = (Form_bbf_schema_perms) GETSTRUCT(tuple_bbf_schema); - object_name = pstrdup(NameStr(schemaform->object_name)); - object_type = pstrdup(NameStr(schemaform->object_type)); - - /* For each object, grant the permission explicitly. */ - if (strcmp(object_name, "ALL") != 0) - { - StringInfoData query; - char *schema; - List *res; - Node *res_stmt; - PlannedStmt *wrapper; - - schema = get_physical_schema_name((char *)db_name, schema_name); - initStringInfo(&query); - if (strcmp(permission, "execute") != 0) - appendStringInfo(&query, "GRANT \"%s\" ON \"%s\".\"%s\" TO \"%s\"; ", permission, schema, object_name, grantee); - else - { - if (object_type != NULL && strcmp(object_type, "f") == 0) - appendStringInfo(&query, "GRANT \"%s\" ON FUNCTION \"%s\".\"%s\" TO \"%s\"; ", permission, schema, object_name, grantee); - else - appendStringInfo(&query, "GRANT \"%s\" ON PROCEDURE \"%s\".\"%s\" TO \"%s\"; ", permission, schema, object_name, grantee); - } - res = raw_parser(query.data, RAW_PARSE_DEFAULT); - res_stmt = ((RawStmt *) linitial(res))->stmt; - - /* need to make a wrapper PlannedStmt */ - wrapper = makeNode(PlannedStmt); - wrapper->commandType = CMD_UTILITY; - wrapper->canSetTag = false; - wrapper->utilityStmt = res_stmt; - wrapper->stmt_location = 0; - wrapper->stmt_len = 1; - - /* do this step */ - ProcessUtility(wrapper, - "(GRANT STATEMENT )", - false, - PROCESS_UTILITY_SUBCOMMAND, - NULL, - NULL, - None_Receiver, - NULL); - - /* make sure later steps can see the object created here */ - CommandCounterIncrement(); - } - tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection); - } - table_endscan(scan); - table_close(bbf_schema_rel, AccessShareLock); -} - PG_FUNCTION_INFO_V1(update_user_catalog_for_guest_schema); Datum update_user_catalog_for_guest_schema(PG_FUNCTION_ARGS) diff --git a/contrib/babelfishpg_tsql/src/catalog.h b/contrib/babelfishpg_tsql/src/catalog.h index 7b8ad195c27..558969b7583 100644 --- a/contrib/babelfishpg_tsql/src/catalog.h +++ b/contrib/babelfishpg_tsql/src/catalog.h @@ -280,71 +280,6 @@ typedef struct FormData_bbf_function_ext typedef FormData_bbf_function_ext *Form_bbf_function_ext; -/***************************************** - * SCHEMA_PERMISSIONS - *****************************************/ -#define BBF_SCHEMA_PERMS_TABLE_NAME "babelfish_schema_permissions" -#define BBF_SCHEMA_PERMS_IDX_NAME "babelfish_schema_permissions_pkey" -#define BBF_SCHEMA_PERMS_NUM_OF_COLS 6 -#define BBF_SCHEMA_PERMS_DBID 0 -#define BBF_SCHEMA_PERMS_SCHEMA_NAME 1 -#define BBF_SCHEMA_PERMS_OBJECT_NAME 2 -#define BBF_SCHEMA_PERMS_PERMISSION 3 -#define BBF_SCHEMA_PERMS_GRANTEE 4 -#define BBF_SCHEMA_PERMS_OBJECT_TYPE 5 -#define Anum_bbf_schema_perms_dbid 1 -#define Anum_bbf_schema_perms_schema_name 2 -#define Anum_bbf_schema_perms_object_name 3 -#define Anum_bbf_schema_perms_permission 4 -#define Anum_bbf_schema_perms_grantee 5 -#define Anum_bbf_schema_perms_object_type 6 - -extern Oid bbf_schema_perms_oid; -extern Oid bbf_schema_perms_idx_oid; - -extern Oid get_bbf_schema_perms_oid(void); -extern Oid get_bbf_schema_perms_idx_oid(void); - -typedef struct FormData_bbf_schema_perms -{ - int16 dbid; - NameData schema_name; - NameData object_name; - NameData permission; - NameData grantee; - NameData object_type; -} FormData_bbf_schema_perms; - -typedef FormData_bbf_schema_perms *Form_bbf_schema_perms; - -extern void add_entry_to_bbf_schema(const char *schema_name, - const char *object_name, - const char *permission, - const char *grantee, - const char *object_type); - -extern bool check_bbf_schema_for_entry(const char *schema_name, - const char *object_name, - const char *permission, - const char *grantee); - -extern void del_from_bbf_schema(const char *schema_name, - const char *object_name, - const char *permission, - const char *grantee); - -extern bool check_bbf_schema_for_schema(const char *schema_name, - const char *object_name, - const char *permission); - -extern void clean_up_bbf_schema(const char *schema_name, - const char *object_name, - bool is_schema); - -extern void grant_perms_to_objects_in_schema(const char *schema_name, - const char *permission, - const char *grantee); - /***************************************** * DOMAIN MAPPING *****************************************/ diff --git a/contrib/babelfishpg_tsql/src/codegen.c b/contrib/babelfishpg_tsql/src/codegen.c index c25fb924e2e..745152d1ddb 100644 --- a/contrib/babelfishpg_tsql/src/codegen.c +++ b/contrib/babelfishpg_tsql/src/codegen.c @@ -301,7 +301,6 @@ stmt_default_act(Walker_context *ctx, PLtsql_stmt *stmt) case PLTSQL_STMT_USEDB: case PLTSQL_STMT_GRANTDB: case PLTSQL_STMT_CHANGE_DBOWNER: - case PLTSQL_STMT_GRANTSCHEMA: case PLTSQL_STMT_FULLTEXTINDEX: case PLTSQL_STMT_INSERT_BULK: case PLTSQL_STMT_DBCC: diff --git a/contrib/babelfishpg_tsql/src/dbcmds.c b/contrib/babelfishpg_tsql/src/dbcmds.c index 3254ce6805a..837e1afab2f 100644 --- a/contrib/babelfishpg_tsql/src/dbcmds.c +++ b/contrib/babelfishpg_tsql/src/dbcmds.c @@ -154,7 +154,7 @@ gen_createdb_subcmds(const char *schema, const char *dbo, const char *db_owner, update_CreateRoleStmt(stmt, dbo, NULL, db_owner); stmt = parsetree_nth_stmt(res, i++); - update_GrantStmt(stmt, get_database_name(MyDatabaseId), NULL, dbo, NULL); + update_GrantStmt(stmt, get_database_name(MyDatabaseId), NULL, dbo); if (guest) { @@ -181,7 +181,7 @@ gen_createdb_subcmds(const char *schema, const char *dbo, const char *db_owner, stmt = parsetree_nth_stmt(res, i++); update_AlterTableStmt(stmt, schema, db_owner); - + if (guest) { stmt = parsetree_nth_stmt(res, i++); @@ -261,7 +261,7 @@ gen_dropdb_subcmds(const char *schema, update_DropOwnedStmt(stmt, list_make2(pstrdup(db_owner), pstrdup(dbo))); stmt = parsetree_nth_stmt(stmt_list, i++); - update_GrantStmt(stmt, get_database_name(MyDatabaseId), NULL, dbo, NULL); + update_GrantStmt(stmt, get_database_name(MyDatabaseId), NULL, dbo); stmt = parsetree_nth_stmt(stmt_list, i++); update_DropRoleStmt(stmt, db_owner); diff --git a/contrib/babelfishpg_tsql/src/iterative_exec.c b/contrib/babelfishpg_tsql/src/iterative_exec.c index c5af008265a..b992b8c7698 100644 --- a/contrib/babelfishpg_tsql/src/iterative_exec.c +++ b/contrib/babelfishpg_tsql/src/iterative_exec.c @@ -808,15 +808,6 @@ dispatch_stmt(PLtsql_execstate *estate, PLtsql_stmt *stmt) errmsg("Showing Estimated Execution Plan for ALTER AUTHORIZATION statement is not yet supported"))); } exec_stmt_change_dbowner(estate, (PLtsql_stmt_change_dbowner *) stmt); - break; - case PLTSQL_STMT_GRANTSCHEMA: - if (pltsql_explain_only) - { - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("Showing Estimated Execution Plan for GRANT DB statment is not yet supported"))); - } - exec_stmt_grantschema(estate, (PLtsql_stmt_grantschema *) stmt); break; case PLTSQL_STMT_FULLTEXTINDEX: if (pltsql_explain_only) diff --git a/contrib/babelfishpg_tsql/src/pl_exec-2.c b/contrib/babelfishpg_tsql/src/pl_exec-2.c index 4e948a0be0f..8cab47c3ec4 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec-2.c +++ b/contrib/babelfishpg_tsql/src/pl_exec-2.c @@ -53,7 +53,6 @@ static int exec_run_dml_with_output(PLtsql_execstate *estate, PLtsql_stmt_push_r static int exec_stmt_usedb(PLtsql_execstate *estate, PLtsql_stmt_usedb *stmt); static int exec_stmt_usedb_explain(PLtsql_execstate *estate, PLtsql_stmt_usedb *stmt, bool shouldRestoreDb); static int exec_stmt_grantdb(PLtsql_execstate *estate, PLtsql_stmt_grantdb *stmt); -static int exec_stmt_grantschema(PLtsql_execstate *estate, PLtsql_stmt_grantschema *stmt); static int exec_stmt_fulltextindex(PLtsql_execstate *estate, PLtsql_stmt_fulltextindex *stmt); static int exec_stmt_insert_execute_select(PLtsql_execstate *estate, PLtsql_expr *expr); static int exec_stmt_insert_bulk(PLtsql_execstate *estate, PLtsql_stmt_insert_bulk *expr); @@ -3675,106 +3674,6 @@ get_insert_bulk_kilobytes_per_batch() return insert_bulk_kilobytes_per_batch; } -static int -exec_stmt_grantschema(PLtsql_execstate *estate, PLtsql_stmt_grantschema *stmt) -{ - List *parsetree_list; - ListCell *parsetree_item; - char *dbname = get_cur_db_name(); - char *login = GetUserNameFromId(GetSessionUserId(), false); - bool login_is_db_owner; - Oid datdba; - char *rolname; - char *schema_name; - ListCell *lc; - ListCell *lc1; - Oid schemaOid; - - /* - * If the login is not the db owner or the login is not the member of - * sysadmin or login is not the schema owner, then it doesn't have the permission to GRANT/REVOKE. - */ - login_is_db_owner = 0 == strncmp(login, get_owner_of_db(dbname), NAMEDATALEN); - datdba = get_role_oid("sysadmin", false); - schema_name = get_physical_schema_name(dbname, stmt->schema_name); - schemaOid = LookupExplicitNamespace(schema_name, true); - - if (!OidIsValid(schemaOid)) - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_SCHEMA), - errmsg("schema \"%s\" does not exist", - schema_name))); - - if (!is_member_of_role(GetSessionUserId(), datdba) && !login_is_db_owner && !pg_namespace_ownercheck(schemaOid, GetUserId())) - ereport(ERROR, - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("Cannot find the schema \"%s\", because it does not exist or you do not have permission.", stmt->schema_name))); - - foreach(lc1, stmt->privileges) - { - char *priv_name = (char *) lfirst(lc1); - foreach(lc, stmt->grantees) - { - char *grantee_name = (char *) lfirst(lc); - Oid role_oid; - bool grantee_is_db_owner; - rolname = get_physical_user_name(dbname, grantee_name); - role_oid = get_role_oid(rolname, true); - grantee_is_db_owner = 0 == strncmp(grantee_name, get_owner_of_db(dbname), NAMEDATALEN); - - - if (role_oid == InvalidOid) - ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("Cannot find the principal '%s', because it does not exist or you do not have permission.", grantee_name))); - - if (pg_namespace_ownercheck(schemaOid, role_oid) || is_member_of_role(role_oid, datdba) || grantee_is_db_owner) - ereport(ERROR, - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself."))); - - parsetree_list = gen_grantschema_subcmds(schema_name, rolname, stmt->is_grant, stmt->with_grant_option, priv_name); - /* Run all subcommands */ - foreach(parsetree_item, parsetree_list) - { - Node *stmt = ((RawStmt *) lfirst(parsetree_item))->stmt; - PlannedStmt *wrapper; - - /* need to make a wrapper PlannedStmt */ - wrapper = makeNode(PlannedStmt); - wrapper->commandType = CMD_UTILITY; - wrapper->canSetTag = false; - wrapper->utilityStmt = stmt; - wrapper->stmt_location = 0; - wrapper->stmt_len = 0; - - /* do this step */ - ProcessUtility(wrapper, - "(GRANT SCHEMA )", - false, - PROCESS_UTILITY_SUBCOMMAND, - NULL, - NULL, - None_Receiver, - NULL); - - /* make sure later steps can see the object created here */ - CommandCounterIncrement(); - } - /* Add entry for each grant statement. */ - if (stmt->is_grant && !check_bbf_schema_for_entry(stmt->schema_name, "ALL", priv_name, rolname)) - add_entry_to_bbf_schema(stmt->schema_name, "ALL", priv_name, rolname, NULL); - /* Remove entry for each revoke statement. */ - if (!stmt->is_grant && check_bbf_schema_for_entry(stmt->schema_name, "ALL", priv_name, rolname)) - { - /* If any object in the schema has the OBJECT level permission. Then, internally grant that permission back. */ - grant_perms_to_objects_in_schema(stmt->schema_name, priv_name, rolname); - del_from_bbf_schema(stmt->schema_name, "ALL", priv_name, rolname); - } - } - } - return PLTSQL_RC_OK; -} - /* * ALTER AUTHORIZATION ON DATABASE::dbname TO loginname */ @@ -3936,4 +3835,4 @@ exec_stmt_fulltextindex(PLtsql_execstate *estate, PLtsql_stmt_fulltextindex *stm */ exec_utility_cmd_helper(query_str); return PLTSQL_RC_OK; -} \ No newline at end of file +} diff --git a/contrib/babelfishpg_tsql/src/pl_funcs-2.c b/contrib/babelfishpg_tsql/src/pl_funcs-2.c index 6ec9d93652a..80352240b6e 100644 --- a/contrib/babelfishpg_tsql/src/pl_funcs-2.c +++ b/contrib/babelfishpg_tsql/src/pl_funcs-2.c @@ -484,7 +484,6 @@ free_stmt2(PLtsql_stmt *stmt) case PLTSQL_STMT_INSERT_BULK: case PLTSQL_STMT_GRANTDB: case PLTSQL_STMT_CHANGE_DBOWNER: - case PLTSQL_STMT_GRANTSCHEMA: case PLTSQL_STMT_FULLTEXTINDEX: case PLTSQL_STMT_SET_EXPLAIN_MODE: { diff --git a/contrib/babelfishpg_tsql/src/pl_handler.c b/contrib/babelfishpg_tsql/src/pl_handler.c index 10297b0c90e..cd63122e8da 100644 --- a/contrib/babelfishpg_tsql/src/pl_handler.c +++ b/contrib/babelfishpg_tsql/src/pl_handler.c @@ -3235,7 +3235,6 @@ bbf_ProcessUtility(PlannedStmt *pstmt, List *res; GrantStmt *stmt; PlannedStmt *wrapper; - RoleSpec *rolspec = create_schema->authrole; if (strcmp(queryString, "(CREATE LOGICAL DATABASE )") == 0 && context == PROCESS_UTILITY_SUBCOMMAND) @@ -3284,45 +3283,7 @@ bbf_ProcessUtility(PlannedStmt *pstmt, NULL); CommandCounterIncrement(); - /* Grant all privileges to the user.*/ - if (rolspec && strcmp(queryString, "(CREATE LOGICAL DATABASE )") != 0) - { - char *permissions[] = {"select", "insert", "update", "references", "delete", "execute"}; - List *parsetree_list; - ListCell *parsetree_item; - int i; - for (i = 0; i < 6; i++) - { - parsetree_list = gen_grantschema_subcmds(create_schema->schemaname, rolspec->rolename, true, false, permissions[i]); - /* Run all subcommands */ - foreach(parsetree_item, parsetree_list) - { - Node *stmt = ((RawStmt *) lfirst(parsetree_item))->stmt; - PlannedStmt *wrapper; - - /* need to make a wrapper PlannedStmt */ - wrapper = makeNode(PlannedStmt); - wrapper->commandType = CMD_UTILITY; - wrapper->canSetTag = false; - wrapper->utilityStmt = stmt; - wrapper->stmt_location = 0; - wrapper->stmt_len = 0; - - /* do this step */ - ProcessUtility(wrapper, - "(GRANT SCHEMA )", - false, - PROCESS_UTILITY_SUBCOMMAND, - NULL, - NULL, - None_Receiver, - NULL); - - /* make sure later steps can see the object created here */ - CommandCounterIncrement(); - } - } - } + return; } else @@ -3336,6 +3297,7 @@ bbf_ProcessUtility(PlannedStmt *pstmt, { if (sql_dialect == SQL_DIALECT_TSQL) bbf_ExecDropStmt(drop_stmt); + break; } @@ -3347,11 +3309,10 @@ bbf_ProcessUtility(PlannedStmt *pstmt, * database command. */ const char *schemaname = strVal(lfirst(list_head(drop_stmt->objects))); - char *cur_db = get_cur_db_name(); - const char *logicalschema = get_logical_schema_name(schemaname, true); if (strcmp(queryString, "(DROP DATABASE )") != 0) { + char *cur_db = get_cur_db_name(); char *guest_schema_name = get_physical_schema_name(cur_db, "guest"); if (strcmp(schemaname, guest_schema_name) == 0) @@ -3364,8 +3325,6 @@ bbf_ProcessUtility(PlannedStmt *pstmt, bbf_ExecDropStmt(drop_stmt); del_ns_ext_info(schemaname, drop_stmt->missing_ok); - if (logicalschema != NULL) - clean_up_bbf_schema(logicalschema, NULL, true); if (prev_ProcessUtility) prev_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, @@ -3603,233 +3562,6 @@ bbf_ProcessUtility(PlannedStmt *pstmt, } break; } - case T_GrantStmt: - { - GrantStmt *grant = (GrantStmt *) parsetree; - char *dbname = get_cur_db_name(); - const char *current_user = GetUserNameFromId(GetUserId(), false); - /* Ignore when GRANT statement has no specific named object. */ - if (sql_dialect != SQL_DIALECT_TSQL || grant->targtype != ACL_TARGET_OBJECT) - break; - Assert(list_length(grant->objects) == 1); - if (grant->objtype == OBJECT_SCHEMA) - break; - else if (grant->objtype == OBJECT_TABLE) - { - /* Ignore CREATE database subcommands */ - if (strcmp("(CREATE LOGICAL DATABASE )", queryString) != 0) - { - RangeVar *rv = (RangeVar *) linitial(grant->objects); - const char *logical_schema = NULL; - char *obj = rv->relname; - ListCell *lc; - ListCell *lc1; - const char *obj_type = "r"; - if (rv->schemaname != NULL) - logical_schema = get_logical_schema_name(rv->schemaname, true); - else - logical_schema = get_authid_user_ext_schema_name(dbname, current_user); - /* If ALL PRIVILEGES is granted/revoked. */ - if (list_length(grant->privileges) == 0) - { - if (grant->is_grant) - { - foreach(lc, grant->grantees) - { - RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - int i = 0; - char *permissions[] = {"select", "insert", "update", "references", "delete"}; - for(i = 0; i < 5; i++) - { - if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, obj, permissions[i], rol_spec->rolename)) - add_entry_to_bbf_schema(logical_schema, obj, permissions[i], rol_spec->rolename, obj_type); - } - } - break; - } - else - { - foreach(lc, grant->grantees) - { - RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - int i = 0; - bool has_schema_perms = false; - char *permissions[] = {"select", "insert", "update", "references", "delete"}; - for(i = 0; i < 5; i++) - { - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logical_schema, "ALL", permissions[i], rol_spec->rolename) && !has_schema_perms) - has_schema_perms = true; - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logical_schema, obj, permissions[i], rol_spec->rolename)) - del_from_bbf_schema(logical_schema, obj, permissions[i], rol_spec->rolename); - } - if (has_schema_perms) - return; - } - break; - } - } - foreach(lc1, grant->privileges) - { - AccessPriv *ap = (AccessPriv *) lfirst(lc1); - if (grant->is_grant) - { - /* - * 1. Execute the GRANT statement. - * 2. Add its corresponding entry in the catalog, if doesn't exist already. - * 3. Don't add an entry, if the permission is granted on column list. - */ - if (prev_ProcessUtility) - prev_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, - queryEnv, dest, qc); - else - standard_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, - queryEnv, dest, qc); - foreach(lc, grant->grantees) - { - RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - if ((ap->cols == NULL) && (rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, obj, ap->priv_name, rol_spec->rolename)) - add_entry_to_bbf_schema(logical_schema, obj, ap->priv_name, rol_spec->rolename, obj_type); - } - } - else - { - foreach(lc, grant->grantees) - { - RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - /* - * 1. If GRANT on schema does not exist, execute REVOKE statement and remove the catalog entry if exists. - * 2. If GRANT on schema exist, only remove the entry from the catalog if exists. - */ - if ((logical_schema != NULL) && (rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, "ALL", ap->priv_name, rol_spec->rolename)) - { - if (prev_ProcessUtility) - prev_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, - queryEnv, dest, qc); - else - standard_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, - queryEnv, dest, qc); - } - if ((ap->cols == NULL) && (rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logical_schema, obj, ap->priv_name, rol_spec->rolename)) - del_from_bbf_schema(logical_schema, obj, ap->priv_name, rol_spec->rolename); - } - } - } - return; - } - } - else if ((grant->objtype == OBJECT_PROCEDURE) || (grant->objtype == OBJECT_FUNCTION)) - { - ObjectWithArgs *ob = (ObjectWithArgs *) linitial(grant->objects); - ListCell *lc; - ListCell *lc1; - const char *logicalschema = NULL; - char *funcname = NULL; - const char *obj_type = NULL; - if (grant->objtype == OBJECT_FUNCTION) - obj_type = "f"; - else - obj_type = "p"; - if (list_length(ob->objname) == 1) - { - Node *func = (Node *) linitial(ob->objname); - funcname = strVal(func); - logicalschema = get_authid_user_ext_schema_name(dbname, current_user); - } - else - { - Node *schema = (Node *) linitial(ob->objname); - char *schemaname = strVal(schema); - Node *func = (Node *) lsecond(ob->objname); - logicalschema = get_logical_schema_name(schemaname, true); - funcname = strVal(func); - } - /* - * Case: When ALL PRIVILEGES is revoked internally during create function. - * Check if schema entry exists in the catalog, do not revoke any permission if exists. - */ - if (pstmt->stmt_len == 0 && list_length(grant->privileges) == 0) - { - if(check_bbf_schema_for_schema(logicalschema, "ALL", "execute")) - return; - break; - } - /* If ALL PRIVILEGES is granted/revoked. */ - if (list_length(grant->privileges) == 0) - { - if (grant->is_grant) - { - foreach(lc, grant->grantees) - { - RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logicalschema, funcname, "execute", rol_spec->rolename)) - add_entry_to_bbf_schema(logicalschema, funcname, "execute", rol_spec->rolename, obj_type); - } - break; - } - else - { - foreach(lc, grant->grantees) - { - RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - bool has_schema_perms = false; - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logicalschema, "ALL", "execute", rol_spec->rolename) && !has_schema_perms) - has_schema_perms = true; - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logicalschema, funcname, "execute", rol_spec->rolename)) - del_from_bbf_schema(logicalschema, funcname, "execute", rol_spec->rolename); - if (has_schema_perms) - return; - } - break; - } - } - foreach(lc1, grant->privileges) - { - AccessPriv *ap = (AccessPriv *) lfirst(lc1); - if (grant->is_grant) - { - /* Execute the GRANT statement. */ - if (prev_ProcessUtility) - prev_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, - queryEnv, dest, qc); - else - standard_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, - queryEnv, dest, qc); - /* Add entry to the catalog if it doesn't exist already. */ - foreach(lc, grant->grantees) - { - RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - /* Don't store a row in catalog, if permission is granted for column */ - if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logicalschema, funcname, ap->priv_name, rol_spec->rolename)) - add_entry_to_bbf_schema(logicalschema, funcname, ap->priv_name, rol_spec->rolename, obj_type); - } - } - else - { - foreach(lc, grant->grantees) - { - RoleSpec *rol_spec = (RoleSpec *) lfirst(lc); - /* - * 1. If GRANT on schema does not exist, execute REVOKE statement and remove the catalog entry if exists. - * 2. If GRANT on schema exist, only remove the entry from the catalog if exists. - */ - if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logicalschema, "ALL", ap->priv_name, rol_spec->rolename)) - { - /* Execute REVOKE statement. */ - if (prev_ProcessUtility) - prev_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, - queryEnv, dest, qc); - else - standard_ProcessUtility(pstmt, queryString, readOnlyTree, context, params, - queryEnv, dest, qc); - } - if ((rol_spec->rolename != NULL) && check_bbf_schema_for_entry(logicalschema, funcname, ap->priv_name, rol_spec->rolename)) - del_from_bbf_schema(logicalschema, funcname, ap->priv_name, rol_spec->rolename); - } - } - } - return; - } - } default: break; } @@ -5919,7 +5651,6 @@ bbf_ExecDropStmt(DropStmt *stmt) Relation relation = NULL; Oid schema_oid; ListCell *cell; - const char *logicalschema = NULL; db_id = get_cur_db_id(); @@ -5960,8 +5691,6 @@ bbf_ExecDropStmt(DropStmt *stmt) schema_oid = get_object_namespace(&address); if (OidIsValid(schema_oid)) schema_name = get_namespace_name(schema_oid); - if (schema_name != NULL) - logicalschema = get_logical_schema_name(schema_name, true); if (schema_name && major_name) { @@ -5987,8 +5716,6 @@ bbf_ExecDropStmt(DropStmt *stmt) major_name, NULL); } } - if (logicalschema != NULL) - clean_up_bbf_schema(logicalschema, major_name, false); } } else if (stmt->removeType == OBJECT_PROCEDURE || @@ -6032,8 +5759,6 @@ bbf_ExecDropStmt(DropStmt *stmt) schema_oid = get_object_namespace(&address); if (OidIsValid(schema_oid)) schema_name = get_namespace_name(schema_oid); - if (schema_name != NULL) - logicalschema = get_logical_schema_name(schema_name, true); if (schema_name && major_name) { @@ -6047,8 +5772,6 @@ bbf_ExecDropStmt(DropStmt *stmt) delete_extended_property(db_id, type, schema_name, major_name, NULL); } - if (logicalschema != NULL) - clean_up_bbf_schema(logicalschema, major_name, false); } } } diff --git a/contrib/babelfishpg_tsql/src/pltsql.h b/contrib/babelfishpg_tsql/src/pltsql.h index ae94b0ddf16..782bdbc4ebd 100644 --- a/contrib/babelfishpg_tsql/src/pltsql.h +++ b/contrib/babelfishpg_tsql/src/pltsql.h @@ -194,7 +194,6 @@ typedef enum PLtsql_stmt_type PLTSQL_STMT_GRANTDB, PLTSQL_STMT_CHANGE_DBOWNER, PLTSQL_STMT_DBCC, - PLTSQL_STMT_GRANTSCHEMA, PLTSQL_STMT_FULLTEXTINDEX, } PLtsql_stmt_type; @@ -1052,20 +1051,6 @@ typedef struct PLtsql_stmt_change_dbowner char *new_owner_name; /* Login name for new owner */ } PLtsql_stmt_change_dbowner; -/* - * Grant on schema stmt - */ -typedef struct PLtsql_stmt_grantschema -{ - PLtsql_stmt_type cmd_type; - int lineno; - bool is_grant; - List *privileges; /* list of privileges */ - List *grantees; /* list of users */ - bool with_grant_option; - char *schema_name; /* schema name */ -} PLtsql_stmt_grantschema; - /* * Fulltext Index stmt */ @@ -2048,7 +2033,6 @@ extern void pltsql_scanner_finish(void); extern int pltsql_yyparse(void); /* functions in pltsql_utils.c */ -extern List *gen_grantschema_subcmds(const char *schema, const char *db_user, bool is_grant, bool with_grant_option, const char *privilege); extern char *gen_createfulltextindex_cmds(const char *table_name, const char *schema_name, const List *column_name, const char *index_name); extern char *gen_dropfulltextindex_cmds(const char *index_name, const char *schema_name); extern char *get_fulltext_index_name(Oid relid, const char *table_name); @@ -2093,8 +2077,7 @@ extern void update_DropOwnedStmt(Node *n, List *role_list); extern void update_DropRoleStmt(Node *n, const char *role); extern void update_DropStmt(Node *n, const char *object); extern void update_GrantRoleStmt(Node *n, List *privs, List *roles); -extern void update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char *grantee, const char *priv); -extern void update_AlterDefaultPrivilegesStmt(Node *n, const char *object, const char *grantee, const char *priv); +extern void update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char *grantee); extern void update_RenameStmt(Node *n, const char *old_name, const char *new_name); extern void update_ViewStmt(Node *n, const char *view_schema); extern void pltsql_check_or_set_default_typmod(TypeName *typeName, int32 *typmod, bool is_cast); diff --git a/contrib/babelfishpg_tsql/src/pltsql_utils.c b/contrib/babelfishpg_tsql/src/pltsql_utils.c index df3c57df719..ed8cce8deba 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_utils.c +++ b/contrib/babelfishpg_tsql/src/pltsql_utils.c @@ -1017,7 +1017,7 @@ update_GrantRoleStmt(Node *n, List *privs, List *roles) } void -update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char *grantee, const char *priv) +update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char *grantee) { GrantStmt *stmt = (GrantStmt *) n; @@ -1039,39 +1039,6 @@ update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char tmp->rolename = pstrdup(grantee); } - - if (priv && stmt->privileges) - { - AccessPriv *tmp = (AccessPriv *) llast(stmt->privileges); - - tmp->priv_name = pstrdup(priv); - } -} - -void -update_AlterDefaultPrivilegesStmt(Node *n, const char *object, const char *grantee, const char *priv) -{ - AlterDefaultPrivilegesStmt *stmt = (AlterDefaultPrivilegesStmt *) n; - - ListCell *lc; - - if (!IsA(stmt, AlterDefaultPrivilegesStmt)) - ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("query is not a AlterDefaultPrivilegesStmt"))); - - if (grantee && priv && stmt->action) - { - update_GrantStmt((Node *)(stmt->action), NULL, NULL, grantee, priv); - } - - foreach(lc, stmt->options) - { - if (object) - { - DefElem *tmp = (DefElem *) lfirst(lc); - tmp->defname = pstrdup("schemas"); - tmp->arg = (Node *)list_make1(makeString((char *)object)); - } - } } void @@ -1731,71 +1698,6 @@ Oid get_sysadmin_oid(void) return sysadmin_oid; } -List -*gen_grantschema_subcmds(const char *schema, const char *rolname, bool is_grant, bool with_grant_option, const char *privilege) -{ - StringInfoData query; - List *stmt_list; - Node *stmt; - int expected_stmts = 2; - int i = 0; - initStringInfo(&query); - if (is_grant) - { - if (strcmp(privilege, "execute") == 0) - { - if (with_grant_option) - { - appendStringInfo(&query, "GRANT dummy ON ALL FUNCTIONS IN SCHEMA dummy TO dummy WITH GRANT OPTION; "); - appendStringInfo(&query, "GRANT dummy ON ALL PROCEDURES IN SCHEMA dummy TO dummy WITH GRANT OPTION; "); - } - else - { - appendStringInfo(&query, "GRANT dummy ON ALL FUNCTIONS IN SCHEMA dummy TO dummy; "); - appendStringInfo(&query, "GRANT dummy ON ALL PROCEDURES IN SCHEMA dummy TO dummy; "); - } - } - else - { - if (with_grant_option) - appendStringInfo(&query, "GRANT dummy ON ALL TABLES IN SCHEMA dummy TO dummy WITH GRANT OPTION; "); - else - appendStringInfo(&query, "GRANT dummy ON ALL TABLES IN SCHEMA dummy TO dummy; "); - appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES IN SCHEMA dummy GRANT dummy ON TABLES TO dummy; "); - } - } - else - { - if (strcmp(privilege, "execute") == 0) - { - appendStringInfo(&query, "REVOKE dummy ON ALL FUNCTIONS IN SCHEMA dummy FROM dummy; "); - appendStringInfo(&query, "REVOKE dummy ON ALL PROCEDURES IN SCHEMA dummy FROM dummy; "); - } - else - { - appendStringInfo(&query, "REVOKE dummy ON ALL TABLES IN SCHEMA dummy FROM dummy; "); - appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES IN SCHEMA dummy REVOKE dummy ON TABLES FROM dummy; "); - } - } - stmt_list = raw_parser(query.data, RAW_PARSE_DEFAULT); - if (list_length(stmt_list) != expected_stmts) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("Expected %d statements, but got %d statements after parsing", - expected_stmts, list_length(stmt_list)))); - /* Replace dummy elements in parsetree with real values */ - stmt = parsetree_nth_stmt(stmt_list, i++); - update_GrantStmt(stmt, schema, NULL, rolname, privilege); - - stmt = parsetree_nth_stmt(stmt_list, i++); - if (strcmp(privilege, "execute") == 0) - update_GrantStmt(stmt, schema, NULL, rolname, privilege); - else - update_AlterDefaultPrivilegesStmt(stmt, schema, rolname, privilege); - - return stmt_list; -} - /* * Generates the schema name for fulltext index statements * depending on whether it's master schema or not diff --git a/contrib/babelfishpg_tsql/src/stmt_walker.c b/contrib/babelfishpg_tsql/src/stmt_walker.c index e41ec44e768..6d996059d87 100644 --- a/contrib/babelfishpg_tsql/src/stmt_walker.c +++ b/contrib/babelfishpg_tsql/src/stmt_walker.c @@ -108,7 +108,6 @@ stmt_walker(PLtsql_stmt *stmt, WalkerFunc walker, void *context) case PLTSQL_STMT_SET_EXPLAIN_MODE: case PLTSQL_STMT_GRANTDB: case PLTSQL_STMT_CHANGE_DBOWNER: - case PLTSQL_STMT_GRANTSCHEMA: case PLTSQL_STMT_FULLTEXTINDEX: case PLTSQL_STMT_DBCC: break; @@ -211,7 +210,6 @@ general_walker_func(PLtsql_stmt *stmt, void *context) DISPATCH(GRANTDB, grantdb) DISPATCH(CHANGE_DBOWNER, change_dbowner) DISPATCH(DBCC, dbcc) - DISPATCH(GRANTSCHEMA, grantschema) DISPATCH(FULLTEXTINDEX, fulltextindex) /* TSQL-only executable node */ diff --git a/contrib/babelfishpg_tsql/src/stmt_walker.h b/contrib/babelfishpg_tsql/src/stmt_walker.h index 96e58e89ebe..885f0058a56 100644 --- a/contrib/babelfishpg_tsql/src/stmt_walker.h +++ b/contrib/babelfishpg_tsql/src/stmt_walker.h @@ -89,7 +89,6 @@ typedef bool (*Stmt_set_explain_mode) ACTION_SIGNITURE(set_explain_mode); typedef bool (*Stmt_grantdb_act) ACTION_SIGNITURE(grantdb); typedef bool (*Stmt_change_dbowner_act) ACTION_SIGNITURE(change_dbowner); typedef bool (*Stmt_dbcc_act) ACTION_SIGNITURE(dbcc); -typedef bool (*Stmt_grantschema_act) ACTION_SIGNITURE(grantschema); typedef bool (*Stmt_fulltextindex_act) ACTION_SIGNITURE(fulltextindex); /* TSQL-only executable node */ @@ -143,7 +142,6 @@ typedef struct Walker_context Stmt_grantdb_act grantdb_act; Stmt_change_dbowner_act change_dbowner_act; Stmt_dbcc_act dbcc_act; - Stmt_grantschema_act grantschema_act; Stmt_fulltextindex_act fulltextindex_act; /* TSQL-only executable node */ diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index 695b28dc468..3c560021c6c 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -1910,52 +1910,6 @@ class tsqlBuilder : public tsqlCommonMutator } } } - else if (ctx->grant_statement() && ctx->grant_statement()->ON() && ctx->grant_statement()->permission_object() - && ctx->grant_statement()->permission_object()->object_type() && ctx->grant_statement()->permission_object()->object_type()->SCHEMA()) - { - if (ctx->grant_statement()->TO() && ctx->grant_statement()->principals() && ctx->grant_statement()->permissions()) - { - for (auto perm: ctx->grant_statement()->permissions()->permission()) - { - auto single_perm = perm->single_permission(); - if (single_perm->EXECUTE() - || single_perm->EXEC() - || single_perm->SELECT() - || single_perm->INSERT() - || single_perm->UPDATE() - || single_perm->DELETE() - || single_perm->REFERENCES()) - { - clear_rewritten_query_fragment(); - return; - } - } - } - } - - else if (ctx->revoke_statement() && ctx->revoke_statement()->ON() && ctx->revoke_statement()->permission_object() - && ctx->revoke_statement()->permission_object()->object_type() && ctx->revoke_statement()->permission_object()->object_type()->SCHEMA()) - { - if (ctx->revoke_statement()->FROM() && ctx->revoke_statement()->principals() && ctx->revoke_statement()->permissions()) - { - for (auto perm: ctx->revoke_statement()->permissions()->permission()) - { - auto single_perm = perm->single_permission(); - if (single_perm->EXECUTE() - || single_perm->EXEC() - || single_perm->SELECT() - || single_perm->INSERT() - || single_perm->UPDATE() - || single_perm->DELETE() - || single_perm->REFERENCES()) - { - clear_rewritten_query_fragment(); - return; - } - } - } - } - PLtsql_stmt_execsql *stmt = (PLtsql_stmt_execsql *) getPLtsql_fragment(ctx); Assert(stmt); @@ -5561,108 +5515,6 @@ makeGrantdbStatement(TSqlParser::Security_statementContext *ctx) } } } - if (ctx->grant_statement() && ctx->grant_statement()->ON() && ctx->grant_statement()->permission_object() - && ctx->grant_statement()->permission_object()->object_type() && ctx->grant_statement()->permission_object()->object_type()->SCHEMA()) - { - if (ctx->grant_statement()->TO() && ctx->grant_statement()->principals() && ctx->grant_statement()->permissions()) - { - PLtsql_stmt_grantschema *result = (PLtsql_stmt_grantschema *) palloc0(sizeof(PLtsql_stmt_grantschema)); - result->cmd_type = PLTSQL_STMT_GRANTSCHEMA; - result->lineno = getLineNo(ctx->grant_statement()); - result->is_grant = true; - std::string schema_name; - if (ctx->grant_statement()->permission_object()->full_object_name()->object_name) - { - schema_name = stripQuoteFromId(ctx->grant_statement()->permission_object()->full_object_name()->object_name); - result->schema_name = pstrdup(downcase_truncate_identifier(schema_name.c_str(), schema_name.length(), true)); - } - List *grantee_list = NIL; - for (auto prin : ctx->grant_statement()->principals()->principal_id()) - { - if (prin->id()) - { - std::string id_str = ::getFullText(prin->id()); - char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); - grantee_list = lappend(grantee_list, grantee_name); - } - } - List *privilege_list = NIL; - for (auto perm: ctx->grant_statement()->permissions()->permission()) - { - auto single_perm = perm->single_permission(); - if (single_perm->EXECUTE()) - privilege_list = lappend(privilege_list, (void *)"execute"); - if (single_perm->EXEC()) - privilege_list = lappend(privilege_list, (void *)"execute"); - if (single_perm->SELECT()) - privilege_list = lappend(privilege_list, (void *)"select"); - if (single_perm->INSERT()) - privilege_list = lappend(privilege_list, (void *)"insert"); - if (single_perm->UPDATE()) - privilege_list = lappend(privilege_list, (void *)"update"); - if (single_perm->DELETE()) - privilege_list = lappend(privilege_list, (void *)"delete"); - if (single_perm->REFERENCES()) - privilege_list = lappend(privilege_list, (void *)"references"); - } - result->privileges = privilege_list; - if (ctx->grant_statement()->WITH()) - result->with_grant_option = true; - result->grantees = grantee_list; - return (PLtsql_stmt *) result; - } - } - - if (ctx->revoke_statement() && ctx->revoke_statement()->ON() && ctx->revoke_statement()->permission_object() - && ctx->revoke_statement()->permission_object()->object_type() && ctx->revoke_statement()->permission_object()->object_type()->SCHEMA()) - { - if (ctx->revoke_statement()->FROM() && ctx->revoke_statement()->principals() && ctx->revoke_statement()->permissions()) - { - PLtsql_stmt_grantschema *result = (PLtsql_stmt_grantschema *) palloc0(sizeof(PLtsql_stmt_grantschema)); - result->cmd_type = PLTSQL_STMT_GRANTSCHEMA; - result->lineno = getLineNo(ctx->revoke_statement()); - result->is_grant = false; - std::string schema_name; - if (ctx->revoke_statement()->permission_object()->full_object_name()->object_name) - { - schema_name = stripQuoteFromId(ctx->revoke_statement()->permission_object()->full_object_name()->object_name); - result->schema_name = pstrdup(downcase_truncate_identifier(schema_name.c_str(), schema_name.length(), true)); - } - List *grantee_list = NIL; - for (auto prin : ctx->revoke_statement()->principals()->principal_id()) - { - if (prin->id()) - { - std::string id_str = ::getFullText(prin->id()); - char *grantee_name = pstrdup(downcase_truncate_identifier(id_str.c_str(), id_str.length(), true)); - grantee_list = lappend(grantee_list, grantee_name); - } - } - List *privilege_list = NIL; - for (auto perm: ctx->revoke_statement()->permissions()->permission()) - { - auto single_perm = perm->single_permission(); - if (single_perm->EXECUTE()) - privilege_list = lappend(privilege_list, (void *)"execute"); - if (single_perm->EXEC()) - privilege_list = lappend(privilege_list, (void *)"execute"); - if (single_perm->SELECT()) - privilege_list = lappend(privilege_list, (void *)"select"); - if (single_perm->INSERT()) - privilege_list = lappend(privilege_list, (void *)"insert"); - if (single_perm->UPDATE()) - privilege_list = lappend(privilege_list, (void *)"update"); - if (single_perm->DELETE()) - privilege_list = lappend(privilege_list, (void *)"delete"); - if (single_perm->REFERENCES()) - privilege_list = lappend(privilege_list, (void *)"references"); - } - result->privileges = privilege_list; - result->grantees = grantee_list; - return (PLtsql_stmt *) result; - } - } - PLtsql_stmt *result; result = makeExecSql(ctx); attachPLtsql_fragment(ctx, result); diff --git a/contrib/babelfishpg_tsql/src/tsqlNodes.h b/contrib/babelfishpg_tsql/src/tsqlNodes.h index 27c68694422..e41e61ca87e 100644 --- a/contrib/babelfishpg_tsql/src/tsqlNodes.h +++ b/contrib/babelfishpg_tsql/src/tsqlNodes.h @@ -51,7 +51,6 @@ typedef enum pltsql_stmt_type PLTSQL_STMT_GRANTDB, PLTSQL_STMT_CHANGE_DBOWNER, PLTSQL_STMT_DBCC, - PLTSQL_STMT_GRANTSCHEMA PLTSQL_STMT_FULLTEXTINDEX } PLtsql_stmt_type; diff --git a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp index 29cdc5ac320..ee3cf57a8b0 100644 --- a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp @@ -1707,6 +1707,7 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedGrantStmt(TSqlParser::Gran unsupported_feature = "GRANT PERMISSION " + perm->getText(); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(perm)); } + } } @@ -1714,9 +1715,7 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedGrantStmt(TSqlParser::Gran { auto perm_obj = grant->permission_object(); auto obj_type = perm_obj->object_type(); - if (grant->ALL() && obj_type && obj_type->SCHEMA()) - throw PGErrorWrapperException(ERROR, ERRCODE_FEATURE_NOT_SUPPORTED, "The all permission has been deprecated and is not available for this class of entity.", getLineAndPos(grant)); - if (obj_type && !(obj_type->OBJECT() || obj_type->SCHEMA())) + if (obj_type && !obj_type->OBJECT()) { unsupported_feature = "GRANT ON " + obj_type->getText(); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(obj_type)); @@ -1801,6 +1800,7 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedRevokeStmt(TSqlParser::Rev unsupported_feature = "REVOKE PERMISSION " + perm->getText(); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(perm)); } + } } @@ -1808,9 +1808,7 @@ void TsqlUnsupportedFeatureHandlerImpl::checkSupportedRevokeStmt(TSqlParser::Rev { auto perm_obj = revoke->permission_object(); auto obj_type = perm_obj->object_type(); - if (revoke->ALL() && obj_type && obj_type->SCHEMA()) - throw PGErrorWrapperException(ERROR, ERRCODE_FEATURE_NOT_SUPPORTED, "The all permission has been deprecated and is not available for this class of entity.", getLineAndPos(revoke)); - if (obj_type && !(obj_type->OBJECT() || obj_type->SCHEMA())) + if (obj_type && !obj_type->OBJECT()) { unsupported_feature = "REVOKE ON " + obj_type->getText(); handle(INSTR_UNSUPPORTED_TSQL_REVOKE_STMT, unsupported_feature.c_str(), getLineAndPos(obj_type)); diff --git a/test/JDBC/expected/AUTO_ANALYZE-vu-prepare.out b/test/JDBC/expected/AUTO_ANALYZE-vu-prepare.out index d569a9922d3..a5551563705 100644 --- a/test/JDBC/expected/AUTO_ANALYZE-vu-prepare.out +++ b/test/JDBC/expected/AUTO_ANALYZE-vu-prepare.out @@ -22,7 +22,6 @@ babelfish_extended_properties babelfish_function_ext babelfish_helpcollation babelfish_namespace_ext -babelfish_schema_permissions babelfish_server_options babelfish_sysdatabases babelfish_syslanguages diff --git a/test/JDBC/expected/BABEL-CROSS-DB.out b/test/JDBC/expected/BABEL-CROSS-DB.out index 2273c92e4f2..bf13b5f26f5 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB.out +++ b/test/JDBC/expected/BABEL-CROSS-DB.out @@ -522,12 +522,6 @@ DROP PROCEDURE p1 GO -- tsql -USE db1; -GO - -DROP TABLE db1_t1; -GO - USE master; GO diff --git a/test/JDBC/expected/BABEL-GRANT.out b/test/JDBC/expected/BABEL-GRANT.out index d3f48b241fe..7847a641567 100644 --- a/test/JDBC/expected/BABEL-GRANT.out +++ b/test/JDBC/expected/BABEL-GRANT.out @@ -20,10 +20,6 @@ GO --- --- Prepare Objects --- ----- SCHEMA -CREATE SCHEMA scm; -GO - ---- TABLE CREATE TABLE t1 ( a int, b int); GO @@ -61,18 +57,6 @@ GO --- --- Basic Grant / Revoke --- -GRANT SELECT ON SCHEMA::scm TO guest; -GO - -GRANT SELECT ON SCHEMA::scm TO PUBLIC; -GO - -REVOKE SELECT ON SCHEMA::scm FROM PUBLIC; -GO - -GRANT INSERT ON SCHEMA::scm TO guest; -GO - GRANT ALL ON OBJECT::t1 TO guest WITH GRANT OPTION; GO @@ -171,9 +155,6 @@ GO ~~ERROR (Message: 'REVOKE ALL on Database' is not currently supported in Babelfish)~~ -REVOKE SELECT ON SCHEMA::scm FROM guest; -GO - GRANT SHOWPLAN ON OBJECT::t1 TO guest; -- unsupported permission GO ~~ERROR (Code: 33557097)~~ @@ -192,14 +173,14 @@ GRANT ALL ON SCHEMA::scm TO guest; -- unsupported class GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: The all permission has been deprecated and is not available for this class of entity.)~~ +~~ERROR (Message: 'GRANT ON SCHEMA' is not currently supported in Babelfish)~~ REVOKE ALL ON SCHEMA::scm TO guest; -- unsupported class GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: The all permission has been deprecated and is not available for this class of entity.)~~ +~~ERROR (Message: 'REVOKE ON SCHEMA' is not currently supported in Babelfish)~~ GRANT ALL ON OBJECT::t1 TO guest WITH GRANT OPTION AS superuser; @@ -232,9 +213,6 @@ GO --- --- Clean Up --- -DROP SCHEMA scm; -GO - DROP VIEW IF EXISTS my_view; GO diff --git a/test/JDBC/expected/BABEL-SESSION.out b/test/JDBC/expected/BABEL-SESSION.out index 6e9888edd58..87d51024a55 100644 --- a/test/JDBC/expected/BABEL-SESSION.out +++ b/test/JDBC/expected/BABEL-SESSION.out @@ -153,21 +153,6 @@ USE master; GO -- tsql -USE db1; -GO - -DROP TABLE tb1; -GO - -DROP TABLE janedoe_schema.t1; -GO - -DROP SCHEMA janedoe_schema; -GO - -USE master; -go - DROP DATABASE db1; GO diff --git a/test/JDBC/expected/BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.out b/test/JDBC/expected/BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.out index 9b95434b992..d2a093dc2e8 100644 --- a/test/JDBC/expected/BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.out +++ b/test/JDBC/expected/BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.out @@ -1,44 +1,49 @@ -EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "sysdatabases"; + +SET NOCOUNT ON +DECLARE @sp_columns_managed_var table(a nvarchar(128), b nvarchar(128), c nvarchar(128), d nvarchar(128), e int, f nvarchar(4000), g nvarchar(3), h nvarchar(128), i int, j int, k int, l int, m int, n int, o nvarchar(128), p nvarchar(128), q nvarchar(128), r nvarchar(128), s int, t int, u int) +INSERT INTO @sp_columns_managed_var EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "sysdatabases" +SELECT * FROM @sp_columns_managed_var ORDER BY a, b, c, d, e +SET NOCOUNT OFF +SET NOCOUNT ON +DECLARE @sp_columns_managed_var1 table(a nvarchar(128), b nvarchar(128), c nvarchar(128), d nvarchar(128), e int, f nvarchar(4000), g nvarchar(3), h nvarchar(128), i int, j int, k int, l int, m int, n int, o nvarchar(128), p nvarchar(128), q nvarchar(128), r nvarchar(128), s int, t int, u int) +INSERT INTO @sp_columns_managed_var1 EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "SYSDATABASES" +SELECT * FROM @sp_columns_managed_var1 ORDER BY a, b, c, d, e +SET NOCOUNT OFF +EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "sysdatabases", "name"; GO ~~START~~ nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int#!#nvarchar#!#nvarchar#!#nvarchar#!#int#!#int#!#int#!#int#!#int#!#int#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int#!#int#!#int -master#!#dbo#!#sysdatabases#!#name#!#1#!##!#YES#!#text#!#2147483647#!#2147483647#!##!##!##!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#category#!#9#!##!#YES#!#int#!##!##!#10#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#cmptlevel#!#10#!##!#YES#!#tinyint#!##!##!#3#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#crdate#!#7#!##!#YES#!#datetime#!##!##!##!##!##!#3#!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#dbid#!#2#!##!#YES#!#smallint#!##!##!#5#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#sid#!#3#!##!#YES#!#varbinary#!#85#!#85#!##!##!##!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#filename#!#11#!##!#YES#!#nvarchar#!#260#!#520#!##!##!##!##!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#mode#!#4#!##!#YES#!#smallint#!##!##!#5#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#name#!#1#!##!#YES#!#text#!#2147483647#!#2147483647#!##!##!##!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#reserved#!#8#!##!#YES#!#datetime#!##!##!##!##!##!#3#!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#sid#!#3#!##!#YES#!#varbinary#!#85#!#85#!##!##!##!##!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#status#!#5#!##!#YES#!#int#!##!##!#10#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#status2#!#6#!##!#YES#!#int#!##!##!#10#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#crdate#!#7#!##!#YES#!#datetime#!##!##!##!##!##!#3#!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#reserved#!#8#!##!#YES#!#datetime#!##!##!##!##!##!#3#!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#category#!#9#!##!#YES#!#int#!##!##!#10#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#cmptlevel#!#10#!##!#YES#!#tinyint#!##!##!#3#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#filename#!#11#!##!#YES#!#nvarchar#!#260#!#520#!##!##!##!##!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#version#!#12#!##!#YES#!#smallint#!##!##!#5#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 ~~END~~ - -EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "SYSDATABASES"; -GO ~~START~~ nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int#!#nvarchar#!#nvarchar#!#nvarchar#!#int#!#int#!#int#!#int#!#int#!#int#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int#!#int#!#int -master#!#dbo#!#sysdatabases#!#name#!#1#!##!#YES#!#text#!#2147483647#!#2147483647#!##!##!##!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#category#!#9#!##!#YES#!#int#!##!##!#10#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#cmptlevel#!#10#!##!#YES#!#tinyint#!##!##!#3#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#crdate#!#7#!##!#YES#!#datetime#!##!##!##!##!##!#3#!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#dbid#!#2#!##!#YES#!#smallint#!##!##!#5#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#sid#!#3#!##!#YES#!#varbinary#!#85#!#85#!##!##!##!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#filename#!#11#!##!#YES#!#nvarchar#!#260#!#520#!##!##!##!##!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#mode#!#4#!##!#YES#!#smallint#!##!##!#5#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#name#!#1#!##!#YES#!#text#!#2147483647#!#2147483647#!##!##!##!##!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#reserved#!#8#!##!#YES#!#datetime#!##!##!##!##!##!#3#!##!##!##!##!#0#!#0#!#0 +master#!#dbo#!#sysdatabases#!#sid#!#3#!##!#YES#!#varbinary#!#85#!#85#!##!##!##!##!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#status#!#5#!##!#YES#!#int#!##!##!#10#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#status2#!#6#!##!#YES#!#int#!##!##!#10#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#crdate#!#7#!##!#YES#!#datetime#!##!##!##!##!##!#3#!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#reserved#!#8#!##!#YES#!#datetime#!##!##!##!##!##!#3#!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#category#!#9#!##!#YES#!#int#!##!##!#10#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#cmptlevel#!#10#!##!#YES#!#tinyint#!##!##!#3#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 -master#!#dbo#!#sysdatabases#!#filename#!#11#!##!#YES#!#nvarchar#!#260#!#520#!##!##!##!##!##!##!##!##!#0#!#0#!#0 master#!#dbo#!#sysdatabases#!#version#!#12#!##!#YES#!#smallint#!##!##!#5#!#10#!#0#!##!##!##!##!##!#0#!#0#!#0 ~~END~~ - -EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "sysdatabases", "name"; -GO ~~START~~ nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int#!#nvarchar#!#nvarchar#!#nvarchar#!#int#!#int#!#int#!#int#!#int#!#int#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int#!#int#!#int master#!#dbo#!#sysdatabases#!#name#!#1#!##!#YES#!#text#!#2147483647#!#2147483647#!##!##!##!##!##!##!##!##!#0#!#0#!#0 diff --git a/test/JDBC/expected/GRANT_SCHEMA-vu-cleanup.out b/test/JDBC/expected/GRANT_SCHEMA-vu-cleanup.out deleted file mode 100644 index af83d2ea36d..00000000000 --- a/test/JDBC/expected/GRANT_SCHEMA-vu-cleanup.out +++ /dev/null @@ -1,75 +0,0 @@ --- tsql --- Drop objects -use grant_schema_d1; -go - -drop table grant_schema_s1.grant_schema_t1; -go - -drop table grant_schema_s1.grant_schema_t2; -go - -drop table grant_schema_s1.grant_schema_t3; -go - -drop view grant_schema_s1.grant_schema_v1; -go - -drop view grant_schema_s1.grant_schema_v2; -go - -drop proc grant_schema_s1.grant_schema_p1; -go - -drop proc grant_schema_s1.grant_schema_p2; -go - -drop function grant_schema_s1.grant_schema_f1; -go - -drop function grant_schema_s1.grant_schema_f2; -go - -drop schema grant_schema_s1; -go - -drop table grant_schema_s2.grant_schema_t1; -go - -drop table grant_schema_s2.grant_schema_t2; -go - -drop schema grant_schema_s2; -go - -drop user grant_schema_u1; -go - -use master; -go - -drop database grant_schema_d1; -go - --- psql --- Need to terminate active session before cleaning up the login -SELECT pg_terminate_backend(pid) FROM pg_stat_get_activity(NULL) -WHERE sys.suser_name(usesysid) = 'grant_schema_l1' AND backend_type = 'client backend' AND usesysid IS NOT NULL; -go -~~START~~ -bool -~~END~~ - - --- Wait to sync with another session -SELECT pg_sleep(1); -go -~~START~~ -void - -~~END~~ - - --- tsql -drop login grant_schema_l1; -go diff --git a/test/JDBC/expected/GRANT_SCHEMA-vu-prepare.out b/test/JDBC/expected/GRANT_SCHEMA-vu-prepare.out deleted file mode 100644 index 069a323b573..00000000000 --- a/test/JDBC/expected/GRANT_SCHEMA-vu-prepare.out +++ /dev/null @@ -1,74 +0,0 @@ --- tsql --- create objects -create database grant_schema_d1; -go - -use grant_schema_d1; -go - -create login grant_schema_l1 with password = '12345678' -go - -create user grant_schema_u1 for login grant_schema_l1; -go - -create schema grant_schema_s1; -go - -create table grant_schema_s1.grant_schema_t1(a int); -go - -create table grant_schema_s1.grant_schema_t2(b int); -go - -create table grant_schema_s1.grant_schema_t3(c int); -go - -create view grant_schema_s1.grant_schema_v1 as select 2; -go - -create view grant_schema_s1.grant_schema_v2 as select 2; -go - -create proc grant_schema_s1.grant_schema_p1 as select 2; -go - -create proc grant_schema_s1.grant_schema_p2 as select 2; -go - -CREATE FUNCTION grant_schema_s1.grant_schema_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END -go - -CREATE FUNCTION grant_schema_s1.grant_schema_f2() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END -go - -create schema grant_schema_s2; -go - -create table grant_schema_s2.grant_schema_t1(a int); -go - -create table grant_schema_s2.grant_schema_t2(a int); -go - --- GRANT OBJECT privilege -grant select on grant_schema_s1.grant_schema_t1 to grant_schema_u1; -go -grant select on grant_schema_s1.grant_schema_t3 to grant_schema_u1; -go -grant select on grant_schema_s1.grant_schema_v1 to grant_schema_u1; -go -grant select on grant_schema_s1.grant_schema_v2 to grant_schema_u1; -go -grant execute on grant_schema_s1.grant_schema_p1 to grant_schema_u1; -go -grant execute on grant_schema_s1.grant_schema_p2 to grant_schema_u1; -go -grant execute on grant_schema_s1.grant_schema_f1 to grant_schema_u1; -go -grant execute on grant_schema_s1.grant_schema_f2 to grant_schema_u1; -go -grant select on grant_schema_s2.grant_schema_t1 to grant_schema_u1; -go -grant select on grant_schema_s2.grant_schema_t2 to grant_schema_u1; -go diff --git a/test/JDBC/expected/GRANT_SCHEMA-vu-verify.out b/test/JDBC/expected/GRANT_SCHEMA-vu-verify.out deleted file mode 100644 index 16a45233e29..00000000000 --- a/test/JDBC/expected/GRANT_SCHEMA-vu-verify.out +++ /dev/null @@ -1,291 +0,0 @@ --- tsql user=grant_schema_l1 password=12345678 --- User has OBJECT privileges, should be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t1; -go -~~START~~ -int -~~END~~ - - -select * from grant_schema_s1.grant_schema_t2; -- case 1: has no permission -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table grant_schema_t2)~~ - - -select * from grant_schema_s1.grant_schema_v1; -go -~~START~~ -int -2 -~~END~~ - - -exec grant_schema_s1.grant_schema_p1; -go -~~START~~ -int -2 -~~END~~ - - -select * from grant_schema_s1.grant_schema_f1(); -go -~~START~~ -int -10 -~~END~~ - - --- tsql --- REVOKE OBJECT privilege -use grant_schema_d1; -go -revoke select on grant_schema_s1.grant_schema_t1 from grant_schema_u1; -go -revoke select on grant_schema_s1.grant_schema_v1 from grant_schema_u1; -go -revoke execute on grant_schema_s1.grant_schema_p1 from grant_schema_u1; -go -revoke execute on grant_schema_s1.grant_schema_f1 from grant_schema_u1; -go - --- tsql user=grant_schema_l1 password=12345678 --- User has no privileges, should not be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table grant_schema_t1)~~ - - -select * from grant_schema_s1.grant_schema_v1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for view grant_schema_v1)~~ - - -exec grant_schema_s1.grant_schema_p1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for procedure grant_schema_p1)~~ - - -select * from grant_schema_s1.grant_schema_f1(); -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for function grant_schema_f1)~~ - - --- tsql --- GRANT SCHEMA privilege -use grant_schema_d1; -go -grant select, execute on schema::grant_schema_s1 to grant_schema_u1; -go -use master; -go - --- tsql user=grant_schema_l1 password=12345678 --- User has SCHEMA privileges, should be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t1; -go -~~START~~ -int -~~END~~ - - -select * from grant_schema_s1.grant_schema_t2; -go -~~START~~ -int -~~END~~ - - -select * from grant_schema_s1.grant_schema_v1; -go -~~START~~ -int -2 -~~END~~ - - -exec grant_schema_s1.grant_schema_p1; -go -~~START~~ -int -2 -~~END~~ - - -select * from grant_schema_s1.grant_schema_f1(); -go -~~START~~ -int -11 -~~END~~ - - --- User has OBJECT and SCHEMA privileges, should be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t3; -go -~~START~~ -int -~~END~~ - - -select * from grant_schema_s1.grant_schema_v2; -go -~~START~~ -int -2 -~~END~~ - - -exec grant_schema_s1.grant_schema_p2; -go -~~START~~ -int -2 -~~END~~ - - -select * from grant_schema_s1.grant_schema_f2(); -go -~~START~~ -int -11 -~~END~~ - - --- tsql --- Case 6: User has SCHEMA privilege, REVOKE OBJECT privilege -use grant_schema_d1; -go -revoke select on grant_schema_s1.grant_schema_t3 from grant_schema_u1; -go -revoke select on grant_schema_s1.grant_schema_v2 from grant_schema_u1; -go -revoke execute on grant_schema_s1.grant_schema_p2 from grant_schema_u1; -go -revoke execute on grant_schema_s1.grant_schema_f2 from grant_schema_u1; -go - --- tsql user=grant_schema_l1 password=12345678 --- User has SCHEMA privileges, should be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t3; -go -~~START~~ -int -~~END~~ - - -select * from grant_schema_s1.grant_schema_v2; -go -~~START~~ -int -2 -~~END~~ - - -exec grant_schema_s1.grant_schema_p2; -go -~~START~~ -int -2 -~~END~~ - - -select * from grant_schema_s1.grant_schema_f2(); -go -~~START~~ -int -11 -~~END~~ - - --- tsql --- User has OBJECT privilege, REVOKE OBJECT privilege --- case 7: User has no privileges, should not be accessible. -use grant_schema_d1; -go -revoke select on grant_schema_s2.grant_schema_t2 from grant_schema_u1; -go -use master; -go - --- tsql user=grant_schema_l1 password=12345678 -use grant_schema_d1; -go - -select * from grant_schema_s2.grant_schema_t2; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table grant_schema_t2)~~ - - --- tsql --- User has OBJECT privilege, REVOKE SCHEMA privilege --- case 8: User has OBJECT privileges, would not be accessible. -use grant_schema_d1; -go -revoke select on schema::grant_schema_s2 from grant_schema_u1; -go -use master; -go - --- tsql user=grant_schema_l1 password=12345678 -use grant_schema_d1; -go - -select * from grant_schema_s2.grant_schema_t1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table grant_schema_t1)~~ - - --- tsql --- User has OBJECT privilege, GRANT and REVOKE SCHEMA privilege --- case 5: User has OBJECT privileges, would not be accessible. -use grant_schema_d1; -go -grant select on schema::grant_schema_s2 to grant_schema_u1; -go - -revoke select on schema::grant_schema_s2 from grant_schema_u1; -go -use master; -go - --- tsql user=grant_schema_l1 password=12345678 -use grant_schema_d1; -go - -select * from grant_schema_s2.grant_schema_t1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table grant_schema_t1)~~ - - diff --git a/test/JDBC/expected/GRANT_SCHEMA.out b/test/JDBC/expected/GRANT_SCHEMA.out deleted file mode 100644 index 1891d685978..00000000000 --- a/test/JDBC/expected/GRANT_SCHEMA.out +++ /dev/null @@ -1,631 +0,0 @@ --- tsql --- create objects -create database babel_4344_d1; -go - -use babel_4344_d1; -go - -create login babel_4344_l1 with password = '12345678' -go - -create user babel_4344_u1 for login babel_4344_l1; -go - -create schema babel_4344_s1; -go - -create schema babel_4344_s2 authorization babel_4344_u1; -go - -create table babel_4344_t1(a int); -go - -create table babel_4344_s1.babel_4344_t1(a int); -go - -create table babel_4344_s2.babel_4344_t1(a int); -go - -create table babel_4344_t3(a int, b int); -go - -create table babel_4344_s1.babel_4344_t3(a int, b int); -go - -create view babel_4344_v1 as select 1; -go - -create view babel_4344_s1.babel_4344_v1 as select 2; -go - -create proc babel_4344_p1 as select 1; -go - -create proc babel_4344_s1.babel_4344_p1 as select 2; -go - -CREATE FUNCTION babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.tables) END -go - -CREATE FUNCTION babel_4344_s1.babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END -go - --- tsql user=babel_4344_l1 password=12345678 -use babel_4344_d1; -go - --- User doesn't have any privileges, objects should not be accessible -select * from babel_4344_t1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t1)~~ - -select * from babel_4344_s1.babel_4344_t1 -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t1)~~ - -insert into babel_4344_s1.babel_4344_t1 values(1); -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t1)~~ - -select * from babel_4344_v1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for view babel_4344_v1)~~ - -select * from babel_4344_s1.babel_4344_v1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for view babel_4344_v1)~~ - -exec babel_4344_p1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for procedure babel_4344_p1)~~ - -exec babel_4344_s1.babel_4344_p1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for procedure babel_4344_p1)~~ - -select * from babel_4344_f1(); -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for function babel_4344_f1)~~ - -select * from babel_4344_s1.babel_4344_f1(); -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for function babel_4344_f1)~~ - -use master; -go - --- tsql --- GRANT OBJECT privilege -use babel_4344_d1; -go -grant select on babel_4344_t1 to babel_4344_u1; -go -grant select on babel_4344_s1.babel_4344_t1 to babel_4344_u1; -go -grant all on babel_4344_s1.babel_4344_t1 to babel_4344_u1; -go -grant select on babel_4344_t3(a) to babel_4344_u1; -- column privilege -go -grant select on babel_4344_s1.babel_4344_t3(a) to babel_4344_u1; -- column privilege -go -grant select on babel_4344_v1 to babel_4344_u1; -go -grant select on babel_4344_s1.babel_4344_v1 to babel_4344_u1; -go -grant execute on babel_4344_p1 to babel_4344_u1; -go -grant execute on babel_4344_s1.babel_4344_p1 to babel_4344_u1; -go -grant execute on babel_4344_f1 to babel_4344_u1; -go -grant execute on babel_4344_s1.babel_4344_f1 to babel_4344_u1; -go --- Grant schema permission to its owner, should fail -grant select on schema::babel_4344_s2 to babel_4344_u1; -- should fail -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself.)~~ - -grant select on schema::babel_4344_s2 to jdbc_user; -- should fail -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: Cannot find the principal 'jdbc_user', because it does not exist or you do not have permission.)~~ - -grant select on schema::babel_4344_s2 to guest; -- should pass -go - --- tsql user=babel_4344_l1 password=12345678 --- User has OBJECT privileges, should be accessible. -use babel_4344_d1; -go -select * from babel_4344_t1; -go -~~START~~ -int -~~END~~ - -select * from babel_4344_s1.babel_4344_t1 -go -~~START~~ -int -~~END~~ - -insert into babel_4344_s1.babel_4344_t1 values(2); -go -~~ROW COUNT: 1~~ - -select * from babel_4344_t3; -- not accessible, only column privilege is granted -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t3)~~ - -select * from babel_4344_s1.babel_4344_t3 -- not accessible, only column privilege is granted -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t3)~~ - -select * from babel_4344_v1; -go -~~START~~ -int -1 -~~END~~ - -select * from babel_4344_s1.babel_4344_v1; -go -~~START~~ -int -2 -~~END~~ - -exec babel_4344_p1; -go -~~START~~ -int -1 -~~END~~ - -exec babel_4344_s1.babel_4344_p1; -go -~~START~~ -int -2 -~~END~~ - -select * from babel_4344_f1(); -go -~~START~~ -int -3 -~~END~~ - -select * from babel_4344_s1.babel_4344_f1(); -go -~~START~~ -int -9 -~~END~~ - --- Grant schema permission to its owner -grant select on schema::babel_4344_s2 to babel_4344_u1; -- should fail -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself.)~~ - -grant select on schema::babel_4344_s2 to guest; -- should pass -go -grant select on schema::babel_4344_s1 to babel_4344_u1; -- should fail -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: Cannot find the schema "babel_4344_s1", because it does not exist or you do not have permission.)~~ - -use master; -go - --- tsql --- GRANT SCHEMA privilege -use babel_4344_d1; -go -grant select, insert, execute on schema::babel_4344_s1 to babel_4344_u1; -go -use master; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has OBJECT and SCHEMA privileges, should be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1 -go -~~START~~ -int -2 -~~END~~ - -insert into babel_4344_s1.babel_4344_t1 values(3); -go -~~ROW COUNT: 1~~ - -select * from babel_4344_s1.babel_4344_t3 -go -~~START~~ -int#!#int -~~END~~ - -select * from babel_4344_s1.babel_4344_v1; -go -~~START~~ -int -2 -~~END~~ - -exec babel_4344_s1.babel_4344_p1; -go -~~START~~ -int -2 -~~END~~ - -select * from babel_4344_s1.babel_4344_f1(); -go -~~START~~ -int -10 -~~END~~ - -use master; -go - --- tsql --- REVOKE SCHEMA privilege -use babel_4344_d1; -go -revoke select, insert, execute on schema::babel_4344_s1 from babel_4344_u1; -go -use master; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has OBJECT privileges, should be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1 -go -~~START~~ -int -2 -3 -~~END~~ - -insert into babel_4344_s1.babel_4344_t1 values(3); -go -~~ROW COUNT: 1~~ - -select * from babel_4344_s1.babel_4344_t3 -- not accessible -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t3)~~ - -select * from babel_4344_s1.babel_4344_v1; -go -~~START~~ -int -2 -~~END~~ - -exec babel_4344_s1.babel_4344_p1; -- TODO: should be accessible -go -~~START~~ -int -2 -~~END~~ - -select * from babel_4344_s1.babel_4344_f1(); -- TODO: should be accessible -go -~~START~~ -int -9 -~~END~~ - -select * from babel_4344_s2.babel_4344_t1; -go -~~START~~ -int -~~END~~ - -use master; -go - --- tsql --- create new objects in same schema -use babel_4344_d1; -go --- Grant the permissions again -grant select, insert, execute on schema::babel_4344_s1 to babel_4344_u1; -go -create table babel_4344_s1.babel_4344_t2(a int); -go -create view babel_4344_s1.babel_4344_v2 as select 2; -go -create proc babel_4344_s1.babel_4344_p2 as select 2; -go -CREATE FUNCTION babel_4344_s1.babel_4344_f2() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END -go -use master; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has SCHEMA privileges,objects should be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t2 -go -~~START~~ -int -~~END~~ - -insert into babel_4344_s1.babel_4344_t1 values(4); -go -~~ROW COUNT: 1~~ - -select * from babel_4344_s1.babel_4344_v2; -go -~~START~~ -int -2 -~~END~~ - -exec babel_4344_s1.babel_4344_p2; -go -~~START~~ -int -2 -~~END~~ - -select * from babel_4344_s1.babel_4344_f2(); -go -~~START~~ -int -14 -~~END~~ - -use master; -go - --- tsql --- REVOKE OBJECT privileges -use babel_4344_d1; -go -REVOKE all on babel_4344_s1.babel_4344_t1 FROM babel_4344_u1; -go -REVOKE select on babel_4344_s1.babel_4344_t3(a) FROM babel_4344_u1; -go -REVOKE select on babel_4344_s1.babel_4344_v1 FROM babel_4344_u1; -go -REVOKE execute on babel_4344_s1.babel_4344_p1 FROM babel_4344_u1; -go -REVOKE execute on babel_4344_s1.babel_4344_f1 FROM babel_4344_u1; -go -REVOKE all on babel_4344_s1.babel_4344_f1 FROM babel_4344_u1; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has SCHEMA privileges, should be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1 -go -~~START~~ -int -2 -3 -3 -4 -~~END~~ - -insert into babel_4344_s1.babel_4344_t1 values(5); -go -~~ROW COUNT: 1~~ - -select * from babel_4344_s1.babel_4344_t3; -go -~~START~~ -int#!#int -~~END~~ - -select * from babel_4344_s1.babel_4344_v1; -go -~~START~~ -int -2 -~~END~~ - -exec babel_4344_s1.babel_4344_p1; -go -~~START~~ -int -2 -~~END~~ - -select * from babel_4344_s1.babel_4344_f1(); -go -~~START~~ -int -14 -~~END~~ - -select * from babel_4344_s2.babel_4344_t1; -go -~~START~~ -int -~~END~~ - -use master; -go - --- tsql --- REVOKE SCHEMA privileges -use babel_4344_d1; -go -revoke select, insert, execute on schema::babel_4344_s1 from babel_4344_u1; -go -use master; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has no privileges, shouldn't be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t1)~~ - -insert into babel_4344_s1.babel_4344_t1 values(5); -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t1)~~ - -select * from babel_4344_s1.babel_4344_t3; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for table babel_4344_t3)~~ - -select * from babel_4344_s1.babel_4344_v1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for view babel_4344_v1)~~ - -exec babel_4344_s1.babel_4344_p1; -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for procedure babel_4344_p1)~~ - -select * from babel_4344_s1.babel_4344_f1(); -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: permission denied for function babel_4344_f1)~~ - -use master; -go - --- tsql --- Drop objects -use babel_4344_d1; -go - -drop table babel_4344_t1; -go - -drop table babel_4344_s1.babel_4344_t1; -go - -drop table babel_4344_t3; -go - -drop table babel_4344_s1.babel_4344_t3; -go - -drop table babel_4344_s1.babel_4344_t2; -go - -drop view babel_4344_v1; -go - -drop view babel_4344_s1.babel_4344_v1; -go - -drop view babel_4344_s1.babel_4344_v2; -go - -drop proc babel_4344_p1; -go - -drop proc babel_4344_s1.babel_4344_p1; -go - -drop proc babel_4344_s1.babel_4344_p2; -go - -drop function babel_4344_f1; -go - -drop function babel_4344_s1.babel_4344_f1; -go - -drop function babel_4344_s1.babel_4344_f2; -go - -drop schema babel_4344_s1; -go - -drop table babel_4344_s2.babel_4344_t1; -go - -drop schema babel_4344_s2; -go - -drop user babel_4344_u1; -go - -use master; -go - -drop database babel_4344_d1; -go - --- psql --- Need to terminate active session before cleaning up the login -SELECT pg_terminate_backend(pid) FROM pg_stat_get_activity(NULL) -WHERE sys.suser_name(usesysid) = 'babel_4344_l1' AND backend_type = 'client backend' AND usesysid IS NOT NULL; -go -~~START~~ -bool -t -~~END~~ - - --- Wait to sync with another session -SELECT pg_sleep(1); -go -~~START~~ -void - -~~END~~ - - --- tsql -drop login babel_4344_l1; -go diff --git a/test/JDBC/input/BABEL-CROSS-DB.mix b/test/JDBC/input/BABEL-CROSS-DB.mix index 630af3bad34..594fcd1b0e8 100644 --- a/test/JDBC/input/BABEL-CROSS-DB.mix +++ b/test/JDBC/input/BABEL-CROSS-DB.mix @@ -338,12 +338,6 @@ DROP PROCEDURE p1 GO -- tsql -USE db1; -GO - -DROP TABLE db1_t1; -GO - USE master; GO diff --git a/test/JDBC/input/BABEL-GRANT.sql b/test/JDBC/input/BABEL-GRANT.sql index 3e0155ea283..c175c338575 100644 --- a/test/JDBC/input/BABEL-GRANT.sql +++ b/test/JDBC/input/BABEL-GRANT.sql @@ -20,10 +20,6 @@ GO --- Prepare Objects --- ----- SCHEMA -CREATE SCHEMA scm; -GO - ---- TABLE CREATE TABLE t1 ( a int, b int); GO @@ -59,18 +55,6 @@ GO --- Basic Grant / Revoke --- -GRANT SELECT ON SCHEMA::scm TO guest; -GO - -GRANT SELECT ON SCHEMA::scm TO PUBLIC; -GO - -REVOKE SELECT ON SCHEMA::scm FROM PUBLIC; -GO - -GRANT INSERT ON SCHEMA::scm TO guest; -GO - GRANT ALL ON OBJECT::t1 TO guest WITH GRANT OPTION; GO @@ -161,9 +145,6 @@ GO REVOKE ALL TO alogin; -- database permission GO -REVOKE SELECT ON SCHEMA::scm FROM guest; -GO - GRANT SHOWPLAN ON OBJECT::t1 TO guest; -- unsupported permission GO @@ -198,9 +179,6 @@ GO --- Clean Up --- -DROP SCHEMA scm; -GO - DROP VIEW IF EXISTS my_view; GO diff --git a/test/JDBC/input/BABEL-SESSION.mix b/test/JDBC/input/BABEL-SESSION.mix index d9f7be4a8ca..41c1c853985 100644 --- a/test/JDBC/input/BABEL-SESSION.mix +++ b/test/JDBC/input/BABEL-SESSION.mix @@ -99,21 +99,6 @@ USE master; GO -- tsql -USE db1; -GO - -DROP TABLE tb1; -GO - -DROP TABLE janedoe_schema.t1; -GO - -DROP SCHEMA janedoe_schema; -GO - -USE master; -go - DROP DATABASE db1; GO diff --git a/test/JDBC/input/BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.sql b/test/JDBC/input/BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.sql index d05a2ea6460..d5fc741aa28 100644 --- a/test/JDBC/input/BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.sql +++ b/test/JDBC/input/BABEL-SP_COLUMNS_MANAGED-dep-vu-verify.sql @@ -1,10 +1,15 @@ -- sla 20000 +SET NOCOUNT ON +DECLARE @sp_columns_managed_var table(a nvarchar(128), b nvarchar(128), c nvarchar(128), d nvarchar(128), e int, f nvarchar(4000), g nvarchar(3), h nvarchar(128), i int, j int, k int, l int, m int, n int, o nvarchar(128), p nvarchar(128), q nvarchar(128), r nvarchar(128), s int, t int, u int) +INSERT INTO @sp_columns_managed_var EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "sysdatabases" +SELECT * FROM @sp_columns_managed_var ORDER BY a, b, c, d, e +SET NOCOUNT OFF -EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "sysdatabases"; -GO - -EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "SYSDATABASES"; -GO +SET NOCOUNT ON +DECLARE @sp_columns_managed_var1 table(a nvarchar(128), b nvarchar(128), c nvarchar(128), d nvarchar(128), e int, f nvarchar(4000), g nvarchar(3), h nvarchar(128), i int, j int, k int, l int, m int, n int, o nvarchar(128), p nvarchar(128), q nvarchar(128), r nvarchar(128), s int, t int, u int) +INSERT INTO @sp_columns_managed_var1 EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "SYSDATABASES" +SELECT * FROM @sp_columns_managed_var1 ORDER BY a, b, c, d, e +SET NOCOUNT OFF EXEC babel_sp_columns_managed_dep_vu_prepare_p1 "master", "dbo", "sysdatabases", "name"; GO diff --git a/test/JDBC/input/GRANT_SCHEMA-vu-cleanup.mix b/test/JDBC/input/GRANT_SCHEMA-vu-cleanup.mix deleted file mode 100644 index 156b92c61e6..00000000000 --- a/test/JDBC/input/GRANT_SCHEMA-vu-cleanup.mix +++ /dev/null @@ -1,66 +0,0 @@ --- tsql --- Drop objects -use grant_schema_d1; -go - -drop table grant_schema_s1.grant_schema_t1; -go - -drop table grant_schema_s1.grant_schema_t2; -go - -drop table grant_schema_s1.grant_schema_t3; -go - -drop view grant_schema_s1.grant_schema_v1; -go - -drop view grant_schema_s1.grant_schema_v2; -go - -drop proc grant_schema_s1.grant_schema_p1; -go - -drop proc grant_schema_s1.grant_schema_p2; -go - -drop function grant_schema_s1.grant_schema_f1; -go - -drop function grant_schema_s1.grant_schema_f2; -go - -drop schema grant_schema_s1; -go - -drop table grant_schema_s2.grant_schema_t1; -go - -drop table grant_schema_s2.grant_schema_t2; -go - -drop schema grant_schema_s2; -go - -drop user grant_schema_u1; -go - -use master; -go - -drop database grant_schema_d1; -go - --- psql --- Need to terminate active session before cleaning up the login -SELECT pg_terminate_backend(pid) FROM pg_stat_get_activity(NULL) -WHERE sys.suser_name(usesysid) = 'grant_schema_l1' AND backend_type = 'client backend' AND usesysid IS NOT NULL; -go - --- Wait to sync with another session -SELECT pg_sleep(1); -go - --- tsql -drop login grant_schema_l1; -go \ No newline at end of file diff --git a/test/JDBC/input/GRANT_SCHEMA-vu-prepare.mix b/test/JDBC/input/GRANT_SCHEMA-vu-prepare.mix deleted file mode 100644 index 306cd64d582..00000000000 --- a/test/JDBC/input/GRANT_SCHEMA-vu-prepare.mix +++ /dev/null @@ -1,74 +0,0 @@ --- tsql --- create objects -create database grant_schema_d1; -go - -use grant_schema_d1; -go - -create login grant_schema_l1 with password = '12345678' -go - -create user grant_schema_u1 for login grant_schema_l1; -go - -create schema grant_schema_s1; -go - -create table grant_schema_s1.grant_schema_t1(a int); -go - -create table grant_schema_s1.grant_schema_t2(b int); -go - -create table grant_schema_s1.grant_schema_t3(c int); -go - -create view grant_schema_s1.grant_schema_v1 as select 2; -go - -create view grant_schema_s1.grant_schema_v2 as select 2; -go - -create proc grant_schema_s1.grant_schema_p1 as select 2; -go - -create proc grant_schema_s1.grant_schema_p2 as select 2; -go - -CREATE FUNCTION grant_schema_s1.grant_schema_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END -go - -CREATE FUNCTION grant_schema_s1.grant_schema_f2() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END -go - -create schema grant_schema_s2; -go - -create table grant_schema_s2.grant_schema_t1(a int); -go - -create table grant_schema_s2.grant_schema_t2(a int); -go - --- GRANT OBJECT privilege -grant select on grant_schema_s1.grant_schema_t1 to grant_schema_u1; -go -grant select on grant_schema_s1.grant_schema_t3 to grant_schema_u1; -go -grant select on grant_schema_s1.grant_schema_v1 to grant_schema_u1; -go -grant select on grant_schema_s1.grant_schema_v2 to grant_schema_u1; -go -grant execute on grant_schema_s1.grant_schema_p1 to grant_schema_u1; -go -grant execute on grant_schema_s1.grant_schema_p2 to grant_schema_u1; -go -grant execute on grant_schema_s1.grant_schema_f1 to grant_schema_u1; -go -grant execute on grant_schema_s1.grant_schema_f2 to grant_schema_u1; -go -grant select on grant_schema_s2.grant_schema_t1 to grant_schema_u1; -go -grant select on grant_schema_s2.grant_schema_t2 to grant_schema_u1; -go \ No newline at end of file diff --git a/test/JDBC/input/GRANT_SCHEMA-vu-verify.mix b/test/JDBC/input/GRANT_SCHEMA-vu-verify.mix deleted file mode 100644 index 09e9a233360..00000000000 --- a/test/JDBC/input/GRANT_SCHEMA-vu-verify.mix +++ /dev/null @@ -1,179 +0,0 @@ --- tsql user=grant_schema_l1 password=12345678 --- User has OBJECT privileges, should be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t1; -go - -select * from grant_schema_s1.grant_schema_t2; -- case 1: has no permission -go - -select * from grant_schema_s1.grant_schema_v1; -go - -exec grant_schema_s1.grant_schema_p1; -go - -select * from grant_schema_s1.grant_schema_f1(); -go - --- tsql --- REVOKE OBJECT privilege -use grant_schema_d1; -go -revoke select on grant_schema_s1.grant_schema_t1 from grant_schema_u1; -go -revoke select on grant_schema_s1.grant_schema_v1 from grant_schema_u1; -go -revoke execute on grant_schema_s1.grant_schema_p1 from grant_schema_u1; -go -revoke execute on grant_schema_s1.grant_schema_f1 from grant_schema_u1; -go - --- tsql user=grant_schema_l1 password=12345678 --- User has no privileges, should not be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t1; -go - -select * from grant_schema_s1.grant_schema_v1; -go - -exec grant_schema_s1.grant_schema_p1; -go - -select * from grant_schema_s1.grant_schema_f1(); -go - --- tsql --- GRANT SCHEMA privilege -use grant_schema_d1; -go -grant select, execute on schema::grant_schema_s1 to grant_schema_u1; -go -use master; -go - --- tsql user=grant_schema_l1 password=12345678 --- User has SCHEMA privileges, should be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t1; -go - -select * from grant_schema_s1.grant_schema_t2; -go - -select * from grant_schema_s1.grant_schema_v1; -go - -exec grant_schema_s1.grant_schema_p1; -go - -select * from grant_schema_s1.grant_schema_f1(); -go - --- User has OBJECT and SCHEMA privileges, should be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t3; -go - -select * from grant_schema_s1.grant_schema_v2; -go - -exec grant_schema_s1.grant_schema_p2; -go - -select * from grant_schema_s1.grant_schema_f2(); -go - --- tsql --- Case 6: User has SCHEMA privilege, REVOKE OBJECT privilege -use grant_schema_d1; -go -revoke select on grant_schema_s1.grant_schema_t3 from grant_schema_u1; -go -revoke select on grant_schema_s1.grant_schema_v2 from grant_schema_u1; -go -revoke execute on grant_schema_s1.grant_schema_p2 from grant_schema_u1; -go -revoke execute on grant_schema_s1.grant_schema_f2 from grant_schema_u1; -go - --- tsql user=grant_schema_l1 password=12345678 --- User has SCHEMA privileges, should be accessible. -use grant_schema_d1; -go - -select * from grant_schema_s1.grant_schema_t3; -go - -select * from grant_schema_s1.grant_schema_v2; -go - -exec grant_schema_s1.grant_schema_p2; -go - -select * from grant_schema_s1.grant_schema_f2(); -go - --- tsql --- User has OBJECT privilege, REVOKE OBJECT privilege --- case 7: User has no privileges, should not be accessible. -use grant_schema_d1; -go -revoke select on grant_schema_s2.grant_schema_t2 from grant_schema_u1; -go -use master; -go - --- tsql user=grant_schema_l1 password=12345678 -use grant_schema_d1; -go - -select * from grant_schema_s2.grant_schema_t2; -go - --- tsql --- User has OBJECT privilege, REVOKE SCHEMA privilege --- case 8: User has OBJECT privileges, would not be accessible. -use grant_schema_d1; -go -revoke select on schema::grant_schema_s2 from grant_schema_u1; -go -use master; -go - --- tsql user=grant_schema_l1 password=12345678 -use grant_schema_d1; -go - -select * from grant_schema_s2.grant_schema_t1; -go - --- tsql --- User has OBJECT privilege, GRANT and REVOKE SCHEMA privilege --- case 5: User has OBJECT privileges, would not be accessible. -use grant_schema_d1; -go -grant select on schema::grant_schema_s2 to grant_schema_u1; -go - -revoke select on schema::grant_schema_s2 from grant_schema_u1; -go -use master; -go - --- tsql user=grant_schema_l1 password=12345678 -use grant_schema_d1; -go - -select * from grant_schema_s2.grant_schema_t1; -go - diff --git a/test/JDBC/input/GRANT_SCHEMA.mix b/test/JDBC/input/GRANT_SCHEMA.mix deleted file mode 100644 index 1572bea803b..00000000000 --- a/test/JDBC/input/GRANT_SCHEMA.mix +++ /dev/null @@ -1,386 +0,0 @@ --- tsql --- create objects -create database babel_4344_d1; -go - -use babel_4344_d1; -go - -create login babel_4344_l1 with password = '12345678' -go - -create user babel_4344_u1 for login babel_4344_l1; -go - -create schema babel_4344_s1; -go - -create schema babel_4344_s2 authorization babel_4344_u1; -go - -create table babel_4344_t1(a int); -go - -create table babel_4344_s1.babel_4344_t1(a int); -go - -create table babel_4344_s2.babel_4344_t1(a int); -go - -create table babel_4344_t3(a int, b int); -go - -create table babel_4344_s1.babel_4344_t3(a int, b int); -go - -create view babel_4344_v1 as select 1; -go - -create view babel_4344_s1.babel_4344_v1 as select 2; -go - -create proc babel_4344_p1 as select 1; -go - -create proc babel_4344_s1.babel_4344_p1 as select 2; -go - -CREATE FUNCTION babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.tables) END -go - -CREATE FUNCTION babel_4344_s1.babel_4344_f1() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END -go - --- tsql user=babel_4344_l1 password=12345678 -use babel_4344_d1; -go - --- User doesn't have any privileges, objects should not be accessible -select * from babel_4344_t1; -go -select * from babel_4344_s1.babel_4344_t1 -go -insert into babel_4344_s1.babel_4344_t1 values(1); -go -select * from babel_4344_v1; -go -select * from babel_4344_s1.babel_4344_v1; -go -exec babel_4344_p1; -go -exec babel_4344_s1.babel_4344_p1; -go -select * from babel_4344_f1(); -go -select * from babel_4344_s1.babel_4344_f1(); -go -use master; -go - --- tsql --- GRANT OBJECT privilege -use babel_4344_d1; -go -grant select on babel_4344_t1 to babel_4344_u1; -go -grant select on babel_4344_s1.babel_4344_t1 to babel_4344_u1; -go -grant all on babel_4344_s1.babel_4344_t1 to babel_4344_u1; -go -grant select on babel_4344_t3(a) to babel_4344_u1; -- column privilege -go -grant select on babel_4344_s1.babel_4344_t3(a) to babel_4344_u1; -- column privilege -go -grant select on babel_4344_v1 to babel_4344_u1; -go -grant select on babel_4344_s1.babel_4344_v1 to babel_4344_u1; -go -grant execute on babel_4344_p1 to babel_4344_u1; -go -grant execute on babel_4344_s1.babel_4344_p1 to babel_4344_u1; -go -grant execute on babel_4344_f1 to babel_4344_u1; -go -grant execute on babel_4344_s1.babel_4344_f1 to babel_4344_u1; -go --- Grant schema permission to its owner, should fail -grant select on schema::babel_4344_s2 to babel_4344_u1; -- should fail -go -grant select on schema::babel_4344_s2 to jdbc_user; -- should fail -go -grant select on schema::babel_4344_s2 to guest; -- should pass -go - --- tsql user=babel_4344_l1 password=12345678 --- User has OBJECT privileges, should be accessible. -use babel_4344_d1; -go -select * from babel_4344_t1; -go -select * from babel_4344_s1.babel_4344_t1 -go -insert into babel_4344_s1.babel_4344_t1 values(2); -go -select * from babel_4344_t3; -- not accessible, only column privilege is granted -go -select * from babel_4344_s1.babel_4344_t3 -- not accessible, only column privilege is granted -go -select * from babel_4344_v1; -go -select * from babel_4344_s1.babel_4344_v1; -go -exec babel_4344_p1; -go -exec babel_4344_s1.babel_4344_p1; -go -select * from babel_4344_f1(); -go -select * from babel_4344_s1.babel_4344_f1(); -go --- Grant schema permission to its owner -grant select on schema::babel_4344_s2 to babel_4344_u1; -- should fail -go -grant select on schema::babel_4344_s2 to guest; -- should pass -go -grant select on schema::babel_4344_s1 to babel_4344_u1; -- should fail -go -use master; -go - --- tsql --- GRANT SCHEMA privilege -use babel_4344_d1; -go -grant select, insert, execute on schema::babel_4344_s1 to babel_4344_u1; -go -use master; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has OBJECT and SCHEMA privileges, should be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1 -go -insert into babel_4344_s1.babel_4344_t1 values(3); -go -select * from babel_4344_s1.babel_4344_t3 -go -select * from babel_4344_s1.babel_4344_v1; -go -exec babel_4344_s1.babel_4344_p1; -go -select * from babel_4344_s1.babel_4344_f1(); -go -use master; -go - --- tsql --- REVOKE SCHEMA privilege -use babel_4344_d1; -go -revoke select, insert, execute on schema::babel_4344_s1 from babel_4344_u1; -go -use master; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has OBJECT privileges, should be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1 -go -insert into babel_4344_s1.babel_4344_t1 values(3); -go -select * from babel_4344_s1.babel_4344_t3 -- not accessible -go -select * from babel_4344_s1.babel_4344_v1; -go -exec babel_4344_s1.babel_4344_p1; -- TODO: should be accessible -go -select * from babel_4344_s1.babel_4344_f1(); -- TODO: should be accessible -go -select * from babel_4344_s2.babel_4344_t1; -go -use master; -go - --- tsql --- create new objects in same schema -use babel_4344_d1; -go --- Grant the permissions again -grant select, insert, execute on schema::babel_4344_s1 to babel_4344_u1; -go -create table babel_4344_s1.babel_4344_t2(a int); -go -create view babel_4344_s1.babel_4344_v2 as select 2; -go -create proc babel_4344_s1.babel_4344_p2 as select 2; -go -CREATE FUNCTION babel_4344_s1.babel_4344_f2() RETURNS INT AS BEGIN RETURN (SELECT COUNT(*) FROM sys.objects) END -go -use master; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has SCHEMA privileges,objects should be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t2 -go -insert into babel_4344_s1.babel_4344_t1 values(4); -go -select * from babel_4344_s1.babel_4344_v2; -go -exec babel_4344_s1.babel_4344_p2; -go -select * from babel_4344_s1.babel_4344_f2(); -go -use master; -go - --- tsql --- REVOKE OBJECT privileges -use babel_4344_d1; -go -REVOKE all on babel_4344_s1.babel_4344_t1 FROM babel_4344_u1; -go -REVOKE select on babel_4344_s1.babel_4344_t3(a) FROM babel_4344_u1; -go -REVOKE select on babel_4344_s1.babel_4344_v1 FROM babel_4344_u1; -go -REVOKE execute on babel_4344_s1.babel_4344_p1 FROM babel_4344_u1; -go -REVOKE execute on babel_4344_s1.babel_4344_f1 FROM babel_4344_u1; -go -REVOKE all on babel_4344_s1.babel_4344_f1 FROM babel_4344_u1; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has SCHEMA privileges, should be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1 -go -insert into babel_4344_s1.babel_4344_t1 values(5); -go -select * from babel_4344_s1.babel_4344_t3; -go -select * from babel_4344_s1.babel_4344_v1; -go -exec babel_4344_s1.babel_4344_p1; -go -select * from babel_4344_s1.babel_4344_f1(); -go -select * from babel_4344_s2.babel_4344_t1; -go -use master; -go - --- tsql --- REVOKE SCHEMA privileges -use babel_4344_d1; -go -revoke select, insert, execute on schema::babel_4344_s1 from babel_4344_u1; -go -use master; -go - --- tsql user=babel_4344_l1 password=12345678 --- User has no privileges, shouldn't be accessible. -use babel_4344_d1; -go -select * from babel_4344_s1.babel_4344_t1; -go -insert into babel_4344_s1.babel_4344_t1 values(5); -go -select * from babel_4344_s1.babel_4344_t3; -go -select * from babel_4344_s1.babel_4344_v1; -go -exec babel_4344_s1.babel_4344_p1; -go -select * from babel_4344_s1.babel_4344_f1(); -go -use master; -go - --- tsql --- Drop objects -use babel_4344_d1; -go - -drop table babel_4344_t1; -go - -drop table babel_4344_s1.babel_4344_t1; -go - -drop table babel_4344_t3; -go - -drop table babel_4344_s1.babel_4344_t3; -go - -drop table babel_4344_s1.babel_4344_t2; -go - -drop view babel_4344_v1; -go - -drop view babel_4344_s1.babel_4344_v1; -go - -drop view babel_4344_s1.babel_4344_v2; -go - -drop proc babel_4344_p1; -go - -drop proc babel_4344_s1.babel_4344_p1; -go - -drop proc babel_4344_s1.babel_4344_p2; -go - -drop function babel_4344_f1; -go - -drop function babel_4344_s1.babel_4344_f1; -go - -drop function babel_4344_s1.babel_4344_f2; -go - -drop schema babel_4344_s1; -go - -drop table babel_4344_s2.babel_4344_t1; -go - -drop schema babel_4344_s2; -go - -drop user babel_4344_u1; -go - -use master; -go - -drop database babel_4344_d1; -go - --- psql --- Need to terminate active session before cleaning up the login -SELECT pg_terminate_backend(pid) FROM pg_stat_get_activity(NULL) -WHERE sys.suser_name(usesysid) = 'babel_4344_l1' AND backend_type = 'client backend' AND usesysid IS NOT NULL; -go - --- Wait to sync with another session -SELECT pg_sleep(1); -go - --- tsql -drop login babel_4344_l1; -go diff --git a/test/JDBC/jdbc_schedule b/test/JDBC/jdbc_schedule index ac6f8bf86b1..2e8fd2a2c74 100644 --- a/test/JDBC/jdbc_schedule +++ b/test/JDBC/jdbc_schedule @@ -33,9 +33,6 @@ ignore#!#BABEL-3117-vu-prepare ignore#!#BABEL-3117-vu-verify ignore#!#BABEL-3655-vu-prepare ignore#!#BABEL-3655-vu-verify -ignore#!#GRANT_SCHEMA-vu-prepare -ignore#!#GRANT_SCHEMA-vu-verify -ignore#!#GRANT_SCHEMA-vu-cleanup ignore#!#sys-types-before-dep-vu-prepare ignore#!#sys-types-before-dep-vu-verify ignore#!#sys-types-before-dep-vu-cleanup diff --git a/test/JDBC/upgrade/13_6/schedule b/test/JDBC/upgrade/13_6/schedule index 1bbbdb8426d..ba25064192f 100644 --- a/test/JDBC/upgrade/13_6/schedule +++ b/test/JDBC/upgrade/13_6/schedule @@ -324,7 +324,6 @@ triggers_with_transaction BABEL-4046 getdate BABEL-4410 -GRANT_SCHEMA AUTO_ANALYZE-before-15-5-or-14-10 TestDatatypeAggSort babel_index_nulls_order-before-15-5 diff --git a/test/JDBC/upgrade/13_9/schedule b/test/JDBC/upgrade/13_9/schedule index ef6a4961de7..a971b993b32 100644 --- a/test/JDBC/upgrade/13_9/schedule +++ b/test/JDBC/upgrade/13_9/schedule @@ -320,7 +320,6 @@ triggers_with_transaction BABEL-4046 getdate BABEL-4410 -GRANT_SCHEMA AUTO_ANALYZE-before-15-5-or-14-10 cast_eliminate TestDatatypeAggSort diff --git a/test/JDBC/upgrade/14_10/schedule b/test/JDBC/upgrade/14_10/schedule index 4dd95acdc39..0b1bb7ddbad 100644 --- a/test/JDBC/upgrade/14_10/schedule +++ b/test/JDBC/upgrade/14_10/schedule @@ -410,7 +410,6 @@ smalldatetimefromparts-dep BABEL_4330 BABEL-4231 BABEL-4384 -GRANT_SCHEMA default_params BABEL-3326 cast_eliminate diff --git a/test/JDBC/upgrade/14_11/schedule b/test/JDBC/upgrade/14_11/schedule index 4dd95acdc39..0b1bb7ddbad 100644 --- a/test/JDBC/upgrade/14_11/schedule +++ b/test/JDBC/upgrade/14_11/schedule @@ -410,7 +410,6 @@ smalldatetimefromparts-dep BABEL_4330 BABEL-4231 BABEL-4384 -GRANT_SCHEMA default_params BABEL-3326 cast_eliminate diff --git a/test/JDBC/upgrade/14_3/schedule b/test/JDBC/upgrade/14_3/schedule index 7d0863cec1a..ee1b3f8b184 100644 --- a/test/JDBC/upgrade/14_3/schedule +++ b/test/JDBC/upgrade/14_3/schedule @@ -338,7 +338,6 @@ BABEL-4046 BABEL_4330 BABEL-2619 BABEL-4410 -GRANT_SCHEMA AUTO_ANALYZE-before-15-5-or-14-10 cast_eliminate TestDatatypeAggSort diff --git a/test/JDBC/upgrade/14_5/schedule b/test/JDBC/upgrade/14_5/schedule index 7b2c45e1f35..9fe4585c965 100644 --- a/test/JDBC/upgrade/14_5/schedule +++ b/test/JDBC/upgrade/14_5/schedule @@ -353,7 +353,6 @@ getdate BABEL_4330 BABEL-2619 BABEL-4410 -GRANT_SCHEMA AUTO_ANALYZE-before-15-5-or-14-10 cast_eliminate TestDatatypeAggSort diff --git a/test/JDBC/upgrade/14_6/schedule b/test/JDBC/upgrade/14_6/schedule index 00ec3f4823c..7ad6936075a 100644 --- a/test/JDBC/upgrade/14_6/schedule +++ b/test/JDBC/upgrade/14_6/schedule @@ -388,7 +388,6 @@ getdate BABEL_4330 BABEL-2619 BABEL-4410 -GRANT_SCHEMA AUTO_ANALYZE-before-15-5-or-14-10 cast_eliminate TestDatatypeAggSort diff --git a/test/JDBC/upgrade/15_2/schedule b/test/JDBC/upgrade/15_2/schedule index 6fc69d77500..c18de8224db 100644 --- a/test/JDBC/upgrade/15_2/schedule +++ b/test/JDBC/upgrade/15_2/schedule @@ -416,7 +416,6 @@ BABEL-4046 getdate BABEL_4330 BABEL-4410 -GRANT_SCHEMA AUTO_ANALYZE-before-15-5-or-14-10 default_params cast_eliminate diff --git a/test/JDBC/upgrade/15_4/schedule b/test/JDBC/upgrade/15_4/schedule index bf4ba499230..61b24ca550b 100644 --- a/test/JDBC/upgrade/15_4/schedule +++ b/test/JDBC/upgrade/15_4/schedule @@ -450,10 +450,10 @@ BABEL-4175 sp_who BABEL_4330 BABEL-4410 -GRANT_SCHEMA AUTO_ANALYZE-before-15-5-or-14-10 default_params cast_eliminate TestDatatypeAggSort babel_index_nulls_order-before-15-5 BABEL-2999 + diff --git a/test/python/expected/sql_validation_framework/expected_create.out b/test/python/expected/sql_validation_framework/expected_create.out index 26777ae841c..6e84326140f 100644 --- a/test/python/expected/sql_validation_framework/expected_create.out +++ b/test/python/expected/sql_validation_framework/expected_create.out @@ -72,7 +72,6 @@ Could not find tests for procedure sys.printarg Could not find tests for procedure sys.sp_cursor_list Could not find tests for procedure sys.sp_describe_cursor Could not find tests for table sys.babelfish_helpcollation -Could not find tests for table sys.babelfish_schema_permissions Could not find tests for table sys.babelfish_syslanguages Could not find tests for table sys.service_settings Could not find tests for table sys.spt_datatype_info_table @@ -200,7 +199,6 @@ Could not find upgrade tests for procedure sys.sp_unprepare Could not find upgrade tests for procedure sys.sp_updatestats Could not find upgrade tests for table sys.babelfish_configurations Could not find upgrade tests for table sys.babelfish_helpcollation -Could not find upgrade tests for table sys.babelfish_schema_permissions Could not find upgrade tests for table sys.babelfish_syslanguages Could not find upgrade tests for table sys.service_settings Could not find upgrade tests for table sys.spt_datatype_info_table