Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25737] Backport from develop to 11.3 - When unloading serial and trigger as dba user, schema name is missing #5720

Open
wants to merge 2 commits into
base: release/11.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/executables/unload_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ export_serial (extract_context & ctxt, print_output & output_ctx)
size_t uppercase_user_size = 0;
size_t query_size = 0;
char *query = NULL;
char owner_name[DB_MAX_IDENTIFIER_LENGTH] = { '\0' };
char *serial_name = NULL;
char output_owner[DB_MAX_USER_LENGTH + 4] = { '\0' };

/*
* You must check SERIAL_VALUE_INDEX enum defined on the top of this file
Expand Down Expand Up @@ -820,23 +823,27 @@ export_serial (extract_context & ctxt, print_output & output_ctx)
}
}

output_ctx ("\ncreate serial %s%s%s\n", PRINT_IDENTIFIER (db_get_string (&values[SERIAL_NAME])));
output_ctx ("\t start with %s\n", numeric_db_value_print (&values[SERIAL_CURRENT_VAL], str_buf));
output_ctx ("\t increment by %s\n", numeric_db_value_print (&values[SERIAL_INCREMENT_VAL], str_buf));
output_ctx ("\t minvalue %s\n", numeric_db_value_print (&values[SERIAL_MIN_VAL], str_buf));
output_ctx ("\t maxvalue %s\n", numeric_db_value_print (&values[SERIAL_MAX_VAL], str_buf));
output_ctx ("\t %scycle\n", (db_get_int (&values[SERIAL_CYCLIC]) == 0 ? "no" : ""));
SPLIT_USER_SPECIFIED_NAME (db_get_string (&values[SERIAL_UNIQUE_NAME]), owner_name, serial_name);
PRINT_OWNER_NAME (owner_name, (ctxt.is_dba_user || ctxt.is_dba_group_member), output_owner,
sizeof (output_owner));

output_ctx ("\nCREATE SERIAL %s%s%s%s\n", output_owner, PRINT_IDENTIFIER (db_get_string (&values[SERIAL_NAME])));
output_ctx ("\t START WITH %s\n", numeric_db_value_print (&values[SERIAL_CURRENT_VAL], str_buf));
output_ctx ("\t INCREMENT BY %s\n", numeric_db_value_print (&values[SERIAL_INCREMENT_VAL], str_buf));
output_ctx ("\t MINVALUE %s\n", numeric_db_value_print (&values[SERIAL_MIN_VAL], str_buf));
output_ctx ("\t MAXVALUE %s\n", numeric_db_value_print (&values[SERIAL_MAX_VAL], str_buf));
output_ctx ("\t %sCYCLE\n", (db_get_int (&values[SERIAL_CYCLIC]) == 0 ? "no" : ""));
if (db_get_int (&values[SERIAL_CACHED_NUM]) <= 1)
{
output_ctx ("\t nocache\n");
output_ctx ("\t NOCACHE\n");
}
else
{
output_ctx ("\t cache %d\n", db_get_int (&values[SERIAL_CACHED_NUM]));
output_ctx ("\t CACHE %d\n", db_get_int (&values[SERIAL_CACHED_NUM]));
}
if (DB_IS_NULL (&values[SERIAL_COMMENT]) == false)
{
output_ctx ("\t comment ");
output_ctx ("\t COMMENT ");
desc_value_print (output_ctx, &values[SERIAL_COMMENT]);
}
output_ctx (";\n");
Expand All @@ -846,12 +853,6 @@ export_serial (extract_context & ctxt, print_output & output_ctx)
output_ctx ("SELECT %s%s%s.NEXT_VALUE;\n", PRINT_IDENTIFIER (db_get_string (&values[SERIAL_NAME])));
}

if (ctxt.is_dba_user || ctxt.is_dba_group_member)
{
output_ctx ("call [change_serial_owner] ('%s', '%s') on class [db_serial];\n",
db_get_string (&values[SERIAL_NAME]), db_get_string (&values[SERIAL_OWNER_NAME]));
}

db_value_clear (&diff_value);
db_value_clear (&answer_value);
for (i = 0; i < SERIAL_VALUE_INDEX_MAX; i++)
Expand Down
31 changes: 20 additions & 11 deletions src/object/trigger_description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,27 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri
}
else if (trigger->status != TR_STATUS_INVALID)
{
if (trigger->class_mop != NULL)
{
name = db_get_class_name (trigger->class_mop);
if (sm_qualifier_name (name, owner_name, DB_MAX_USER_LENGTH) == NULL)
{
ASSERT_ERROR_AND_SET (error);
return error;
}
class_name = sm_remove_qualifier_name (name);
}

/* automatically filter out invalid triggers */
output_ctx ("CREATE TRIGGER ");
output_ctx ("[%s]\n", sm_remove_qualifier_name (trigger->name));
if (ctxt.is_dba_user || ctxt.is_dba_group_member)
{
output_ctx ("[%s].[%s]\n", owner_name, sm_remove_qualifier_name (trigger->name));
}
else
{
output_ctx ("[%s]\n", sm_remove_qualifier_name (trigger->name));
}
output_ctx (" STATUS %s\n", tr_status_as_string (trigger->status));
output_ctx (" PRIORITY %f\n", trigger->priority);

Expand All @@ -277,13 +295,6 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri

if (trigger->class_mop != NULL)
{
name = db_get_class_name (trigger->class_mop);
if (sm_qualifier_name (name, owner_name, DB_MAX_USER_LENGTH) == NULL)
{
ASSERT_ERROR_AND_SET (error);
return error;
}
class_name = sm_remove_qualifier_name (name);
output_ctx (" ON ");
if (ctxt.is_dba_user || ctxt.is_dba_group_member)
{
Expand Down Expand Up @@ -339,7 +350,7 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri
help_print_describe_comment (output_ctx, trigger->comment);
}

output_ctx (";\n");
output_ctx (";\n\n");
}

AU_ENABLE (save);
Expand Down Expand Up @@ -423,8 +434,6 @@ tr_dump_selective_triggers (extract_context &ctxt, print_output &output_ctx, DB_
if (trigger->status != TR_STATUS_INVALID)
{
tr_dump_trigger (ctxt, output_ctx, trigger_object);
output_ctx ("call [change_trigger_owner]('%s'," " '%s') on class [db_root];\n\n",
sm_remove_qualifier_name (trigger->name), get_user_name (trigger->owner));
}
}
else if (is_system_class < 0)
Expand Down
Loading