Skip to content

Commit

Permalink
Graph names with empty string '' are no more allowed. (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadshoaib authored and jrgemignani committed Feb 9, 2023
1 parent 005eb05 commit fd49347
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions regress/expected/catalog.out
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ SELECT count(*) FROM pg_namespace WHERE nspname = 'g';

-- invalid cases
SELECT create_graph(NULL);
ERROR: graph name must not be NULL
ERROR: graph name can not be NULL
SELECT drop_graph(NULL);
ERROR: graph name must not be NULL
ERROR: graph name can not be NULL
SELECT create_graph('');
ERROR: graph name can not be empty
--
-- alter_graph() RENAME function tests
--
Expand Down
2 changes: 1 addition & 1 deletion regress/sql/catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SELECT count(*) FROM pg_namespace WHERE nspname = 'g';
-- invalid cases
SELECT create_graph(NULL);
SELECT drop_graph(NULL);

SELECT create_graph('');
--
-- alter_graph() RENAME function tests
--
Expand Down
11 changes: 9 additions & 2 deletions src/backend/commands/graph_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,18 @@ Datum create_graph(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(0))
{
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("graph name must not be NULL")));
errmsg("graph name can not be NULL")));
}
graph_name = PG_GETARG_NAME(0);

graph_name_str = NameStr(*graph_name);

if (strlen(graph_name_str) == 0)
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("graph name can not be empty")));
}
if (graph_exists(graph_name_str))
{
ereport(ERROR,
Expand Down Expand Up @@ -157,7 +164,7 @@ Datum drop_graph(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(0))
{
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("graph name must not be NULL")));
errmsg("graph name can not be NULL")));
}
graph_name = PG_GETARG_NAME(0);
cascade = PG_GETARG_BOOL(1);
Expand Down

0 comments on commit fd49347

Please sign in to comment.