Skip to content

Commit

Permalink
[CBRD-25737] When unloading serial and trigger as dba user, schema na…
Browse files Browse the repository at this point in the history
…me is missing
  • Loading branch information
airnet73 committed Dec 11, 2024
1 parent e560ed5 commit bc1dcb1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
16 changes: 9 additions & 7 deletions src/executables/unload_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,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 @@ -823,7 +826,12 @@ 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])));
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));
Expand All @@ -849,12 +857,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
69 changes: 35 additions & 34 deletions src/object/trigger_description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,16 @@
#define STRFREE_W(string) \
if (string != NULL) db_string_free((char *) (string))

static int is_required_trigger (TR_TRIGGER *trigger, DB_OBJLIST *classes);
static char *get_user_name (DB_OBJECT *user);

trigger_description::trigger_description ()
: name (0)
, event (0)
, class_name (0)
, attribute (0)
, full_event (0)
, status (0)
, priority (0)
, condition_time (0)
, condition (0)
, action_time (0)
, action (0)
, comment (0)
static int is_required_trigger (TR_TRIGGER * trigger, DB_OBJLIST * classes);
static char *get_user_name (DB_OBJECT * user);

trigger_description::trigger_description ():name (0), event (0), class_name (0), attribute (0), full_event (0), status (0), priority (0), condition_time (0),
condition (0), action_time (0), action (0), comment (0)
{
}

int trigger_description::init (const char *name)
int
trigger_description::init (const char *name)
{
struct db_object *trobj = tr_find_trigger (name);

Expand All @@ -70,7 +60,8 @@ int trigger_description::init (const char *name)
return init (trobj);
}

int trigger_description::init (struct db_object *trobj)
int
trigger_description::init (struct db_object *trobj)
{
assert (trobj != NULL);

Expand Down Expand Up @@ -186,7 +177,8 @@ trigger_description::~trigger_description ()
* name(in): trigger name
* file(in):
*/
void trigger_description::fprint (FILE *file)
void
trigger_description::fprint (FILE * file)
{
if (name != NULL)
{
Expand Down Expand Up @@ -235,7 +227,7 @@ void trigger_description::fprint (FILE *file)
* quoted_id_flag(in):
*/
int
tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *trigger_object)
tr_dump_trigger (extract_context & ctxt, print_output & output_ctx, DB_OBJECT * trigger_object)
{
int error = NO_ERROR;
TR_TRIGGER *trigger;
Expand All @@ -256,9 +248,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 +287,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 +342,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 All @@ -355,7 +358,7 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri
* classes(in):
*/
int
tr_dump_selective_triggers (extract_context &ctxt, print_output &output_ctx, DB_OBJLIST *classes)
tr_dump_selective_triggers (extract_context & ctxt, print_output & output_ctx, DB_OBJLIST * classes)
{
int error = NO_ERROR;
TR_TRIGGER *trigger;
Expand Down Expand Up @@ -423,8 +426,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 All @@ -447,7 +448,7 @@ tr_dump_selective_triggers (extract_context &ctxt, print_output &output_ctx, DB_
* classes(in):
*/
static int
is_required_trigger (TR_TRIGGER *trigger, DB_OBJLIST *classes)
is_required_trigger (TR_TRIGGER * trigger, DB_OBJLIST * classes)
{
DB_OBJLIST *cl;

Expand All @@ -469,7 +470,7 @@ is_required_trigger (TR_TRIGGER *trigger, DB_OBJLIST *classes)
* user(in): user object
*/
static char *
get_user_name (DB_OBJECT *user)
get_user_name (DB_OBJECT * user)
{
#define MAX_USER_NAME 32 /* actually its 8 */

Expand Down

0 comments on commit bc1dcb1

Please sign in to comment.