Skip to content

Commit

Permalink
Handles null comment cases
Browse files Browse the repository at this point in the history
  • Loading branch information
gurkanindibay committed Dec 17, 2023
1 parent 4735aa6 commit c76c15b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/backend/distributed/deparser/deparse_database_stmts.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,9 @@ DeparseDatabaseCommentStmt(Node *node)

char *databaseName = strVal(stmt->object);

char *comment = stmt->comment!=NULL?quote_literal_cstr(stmt->comment):"NULL";

appendStringInfo(&str, "COMMENT ON DATABASE %s IS %s;",
databaseName,
quote_literal_cstr(stmt->comment));
appendStringInfo(&str, "COMMENT ON DATABASE %s IS %s;",databaseName,comment);

return str.data;
}
6 changes: 2 additions & 4 deletions src/backend/distributed/deparser/deparse_role_stmts.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,9 @@ DeparseRoleCommentStmt(Node *node)
initStringInfo(&str);

char *roleName = strVal(stmt->object);
char *comment = stmt->comment!=NULL?quote_literal_cstr(stmt->comment):"NULL";


appendStringInfo(&str, "COMMENT ON ROLE %s IS %s;",
roleName,
quote_literal_cstr(stmt->comment));
appendStringInfo(&str, "COMMENT ON ROLE %s IS %s;",roleName,comment);

return str.data;
}
32 changes: 24 additions & 8 deletions src/test/regress/expected/comment_on_database.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ create database test1;
comment on DATABASE test1 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';
SELECT ds.description AS database_comment
FROM pg_database d
LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid
WHERE d.datname = 'test1';
$$
);
result
Expand All @@ -21,17 +21,33 @@ WHERE d.datname = 'test1';
comment on DATABASE test1 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';
SELECT ds.description AS database_comment
FROM pg_database d
LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid
WHERE d.datname = 'test1';
$$
);
result
---------------------------------------------------------------------
comment-needs\!escape
comment-needs\!escape
comment-needs\!escape
(3 rows)

comment on DATABASE test1 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';
$$
);
result
---------------------------------------------------------------------



(3 rows)

drop DATABASE test1;
Expand Down
16 changes: 16 additions & 0 deletions src/test/regress/expected/comment_on_role.out
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ SELECT result FROM run_command_on_all_nodes(
comment-needs\!escape
comment-needs\!escape
comment-needs\!escape
(3 rows)

comment on role role1 is NULL;
SELECT result FROM run_command_on_all_nodes(
$$
SELECT ds.description AS role_comment
FROM pg_roles r
LEFT JOIN pg_shdescription ds ON r.oid = ds.objoid
WHERE r.rolname = 'role1';
$$
);
result
---------------------------------------------------------------------



(3 rows)

drop role role1;
Expand Down
11 changes: 11 additions & 0 deletions src/test/regress/sql/comment_on_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ SELECT result FROM run_command_on_all_nodes(
$$
);

comment on DATABASE test1 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';
$$
);

drop DATABASE test1;
reset citus.enable_create_database_propagation;
reset citus.grep_remote_commands;
Expand Down
11 changes: 11 additions & 0 deletions src/test/regress/sql/comment_on_role.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ SELECT result FROM run_command_on_all_nodes(
$$
);

comment on role role1 is NULL;

SELECT result FROM run_command_on_all_nodes(
$$
SELECT ds.description AS role_comment
FROM pg_roles r
LEFT JOIN pg_shdescription ds ON r.oid = ds.objoid
WHERE r.rolname = 'role1';
$$
);

drop role role1;
reset citus.grep_remote_commands;
reset citus.log_remote_commands;

0 comments on commit c76c15b

Please sign in to comment.