Fixes review comments

pull/7388/head
gurkanindibay 2023-12-25 19:40:57 +03:00
parent ce43bc7c29
commit 77bad0b90e
7 changed files with 34 additions and 46 deletions

View File

@ -712,20 +712,14 @@ List *
DatabaseCommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
{
CommentStmt *stmt = castNode(CommentStmt, node);
Relation relation;
Assert(stmt->objtype == OBJECT_DATABASE);
char *databaseName = strVal(stmt->object);
ObjectAddress objectAddress = get_object_address(stmt->objtype, stmt->object,
&relation, AccessExclusiveLock,
missing_ok);
Oid objid = get_database_oid(databaseName, missing_ok);
if (!OidIsValid(objid))
{
ereport(ERROR, (errmsg("database \"%s\" does not exist", databaseName)));
}
else
{
ObjectAddress *address = palloc0(sizeof(ObjectAddress));
ObjectAddressSet(*address, DatabaseRelationId, objid);
return list_make1(address);
}
ObjectAddress *objectAddressCopy = palloc0(sizeof(ObjectAddress));
*objectAddressCopy = objectAddress;
return list_make1(objectAddressCopy);
}

View File

@ -1423,20 +1423,14 @@ List *
RoleCommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
{
CommentStmt *stmt = castNode(CommentStmt, node);
Relation relation;
Assert(stmt->objtype == OBJECT_ROLE);
char *roleName = strVal(stmt->object);
ObjectAddress objectAddress = get_object_address(stmt->objtype, stmt->object,
&relation, AccessExclusiveLock,
missing_ok);
Oid objid = get_role_oid(roleName, missing_ok);
if (!OidIsValid(objid))
{
ereport(ERROR, (errmsg("role \"%s\" does not exist", roleName)));
}
else
{
ObjectAddress *address = palloc0(sizeof(ObjectAddress));
ObjectAddressSet(*address, AuthIdRelationId, objid);
return list_make1(address);
}
ObjectAddress *objectAddressCopy = palloc0(sizeof(ObjectAddress));
*objectAddressCopy = objectAddress;
return list_make1(objectAddressCopy);
}

View File

@ -321,7 +321,7 @@ DeparseDatabaseCommentStmt(Node *node)
StringInfoData str = { 0 };
initStringInfo(&str);
char *databaseName = strVal(stmt->object);
char const *databaseName = quote_identifier(strVal(stmt->object));
char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL";

View File

@ -542,7 +542,7 @@ DeparseRoleCommentStmt(Node *node)
StringInfoData str = { 0 };
initStringInfo(&str);
char *roleName = strVal(stmt->object);
char const *roleName = quote_identifier(strVal(stmt->object));
char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL";
appendStringInfo(&str, "COMMENT ON ROLE %s IS %s;", roleName, comment);

View File

@ -246,8 +246,8 @@ extern List * CreateDatabaseStmtObjectAddress(Node *node, bool missingOk,
bool isPostprocess);
extern void EnsureSupportedCreateDatabaseCommand(CreatedbStmt *stmt);
extern char * CreateDatabaseDDLCommand(Oid dbId);
extern List * DatabaseCommentObjectAddress(Node *node, bool missing_ok, bool
isPostprocess);
extern List * DatabaseCommentObjectAddress(Node *node, bool missing_ok,
bool isPostprocess);
/* domain.c - forward declarations */

View File

@ -1,14 +1,14 @@
set citus.log_remote_commands to on;
set citus.enable_create_database_propagation to on;
set citus.grep_remote_commands to 'COMMENT ON DATABASE';
create database test1;
comment on DATABASE test1 is 'test-comment';
create database "test1-\!escape";
comment on DATABASE "test1-\!escape" is 'test-comment';
SELECT result FROM run_command_on_all_nodes(
$$
SELECT ds.description AS database_comment
FROM pg_database d
LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid
WHERE d.datname = 'test1';
WHERE d.datname = 'test1-\!escape';
$$
);
result
@ -18,13 +18,13 @@ SELECT result FROM run_command_on_all_nodes(
test-comment
(3 rows)
comment on DATABASE test1 is 'comment-needs\!escape';
comment on DATABASE "test1-\!escape" is 'comment-needs\!escape';
SELECT result FROM run_command_on_all_nodes(
$$
SELECT ds.description AS database_comment
FROM pg_database d
LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid
WHERE d.datname = 'test1';
WHERE d.datname = 'test1-\!escape';
$$
);
result
@ -34,13 +34,13 @@ SELECT result FROM run_command_on_all_nodes(
comment-needs\!escape
(3 rows)
comment on DATABASE test1 is null;
comment on DATABASE "test1-\!escape" is null;
SELECT result FROM run_command_on_all_nodes(
$$
SELECT ds.description AS database_comment
FROM pg_database d
LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid
WHERE d.datname = 'test1';
WHERE d.datname = 'test1-\!escape';
$$
);
result
@ -50,7 +50,7 @@ SELECT result FROM run_command_on_all_nodes(
(3 rows)
drop DATABASE test1;
drop DATABASE "test1-\!escape";
reset citus.enable_create_database_propagation;
reset citus.grep_remote_commands;
reset citus.log_remote_commands;

View File

@ -3,42 +3,42 @@ set citus.log_remote_commands to on;
set citus.enable_create_database_propagation to on;
set citus.grep_remote_commands to 'COMMENT ON DATABASE';
create database test1;
create database "test1-\!escape";
comment on DATABASE test1 is 'test-comment';
comment on DATABASE "test1-\!escape" is 'test-comment';
SELECT result FROM run_command_on_all_nodes(
$$
SELECT ds.description AS database_comment
FROM pg_database d
LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid
WHERE d.datname = 'test1';
WHERE d.datname = 'test1-\!escape';
$$
);
comment on DATABASE test1 is 'comment-needs\!escape';
comment on DATABASE "test1-\!escape" is 'comment-needs\!escape';
SELECT result FROM run_command_on_all_nodes(
$$
SELECT ds.description AS database_comment
FROM pg_database d
LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid
WHERE d.datname = 'test1';
WHERE d.datname = 'test1-\!escape';
$$
);
comment on DATABASE test1 is null;
comment on DATABASE "test1-\!escape" is null;
SELECT result FROM run_command_on_all_nodes(
$$
SELECT ds.description AS database_comment
FROM pg_database d
LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid
WHERE d.datname = 'test1';
WHERE d.datname = 'test1-\!escape';
$$
);
drop DATABASE test1;
drop DATABASE "test1-\!escape";
reset citus.enable_create_database_propagation;
reset citus.grep_remote_commands;
reset citus.log_remote_commands;