From 368e13cd095f084dfd5f6d30e8bcfe94b9d89fdd Mon Sep 17 00:00:00 2001 From: P Aswini Kumar Date: Fri, 13 Sep 2024 15:10:26 +0000 Subject: [PATCH] Refactor code Signed-off-by: P Aswini Kumar --- contrib/babelfishpg_tsql/src/pltsql.h | 1 - contrib/babelfishpg_tsql/src/pltsql_utils.c | 13 ------------- contrib/babelfishpg_tsql/src/rolecmds.c | 13 +++---------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/pltsql.h b/contrib/babelfishpg_tsql/src/pltsql.h index 93af2b89e5..5455a31e73 100644 --- a/contrib/babelfishpg_tsql/src/pltsql.h +++ b/contrib/babelfishpg_tsql/src/pltsql.h @@ -2104,7 +2104,6 @@ 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_RevokeRoleStmt(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_RenameStmt(Node *n, const char *old_name, const char *new_name); extern void update_ViewStmt(Node *n, const char *view_schema); diff --git a/contrib/babelfishpg_tsql/src/pltsql_utils.c b/contrib/babelfishpg_tsql/src/pltsql_utils.c index 7feeeee093..5c78f12ddc 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_utils.c +++ b/contrib/babelfishpg_tsql/src/pltsql_utils.c @@ -1079,19 +1079,6 @@ update_GrantRoleStmt(Node *n, List *privs, List *roles) stmt->grantee_roles = roles; } -void -update_RevokeRoleStmt(Node *n, List *privs, List *roles) -{ - GrantRoleStmt *stmt = (GrantRoleStmt *) n; - - if (!IsA(stmt, GrantRoleStmt)) - ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("query is not a RevokeRoleStmt"))); - - stmt->is_grant = false; - stmt->granted_roles = privs; - stmt->grantee_roles = roles; -} - void update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char *grantee, const char *priv) { diff --git a/contrib/babelfishpg_tsql/src/rolecmds.c b/contrib/babelfishpg_tsql/src/rolecmds.c index c5f1ed7a9e..334fa18213 100644 --- a/contrib/babelfishpg_tsql/src/rolecmds.c +++ b/contrib/babelfishpg_tsql/src/rolecmds.c @@ -627,14 +627,7 @@ grant_dbo_to_login(const char* login, const char* db_name, bool is_grant) tmp->location = -1; tmp->rolename = pstrdup(login); - if (is_grant) - { - update_GrantRoleStmt(stmt, dbo, list_make1(tmp)); - } - else - { - update_RevokeRoleStmt(stmt, dbo, list_make1(tmp)); - } + update_GrantRoleStmt(stmt, dbo, list_make1(tmp)); /* Run the built query */ /* need to make a wrapper PlannedStmt */ @@ -643,11 +636,11 @@ grant_dbo_to_login(const char* login, const char* db_name, bool is_grant) wrapper->canSetTag = false; wrapper->utilityStmt = stmt; wrapper->stmt_location = 0; - wrapper->stmt_len = 18; + wrapper->stmt_len = 23; /* do this step */ ProcessUtility(wrapper, - "(CREATE DATABASE )", + "(ALTER DATABASE OWNER )", false, PROCESS_UTILITY_SUBCOMMAND, NULL,