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-25719] Fix an issue where [user_schema] was incorrectly stored or missing in the condition and action_definition columns of the db_trigger catalog during trigger creation or loaddb execution with legacy unload files #5729

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
09c9346
1. Fix the issue where [user_schema] is not added to the action and c…
Dec 19, 2024
4a81ce2
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Dec 20, 2024
55a8430
Remove [user_schema] from the condition column when the owner perform…
Dec 20, 2024
195ad20
Remove warning messages in the parse_tree_cl file.
Dec 20, 2024
5adef67
Fixed an issue where the action query entered by the user was rewritt…
Dec 20, 2024
fc4c1d8
Second. fixed an issue where the action query entered by the user was…
Dec 20, 2024
5c34b6a
Third. fixed an issue where the action query entered by the user was …
Dec 20, 2024
3cc99b9
Fourth. fixed an issue where the action query entered by the user was…
Dec 20, 2024
2d1f5b8
Fifth. fixed an issue where the action query entered by the user was …
Dec 20, 2024
1034d83
Sixth. fixed an issue where the action query entered by the user was …
Dec 20, 2024
897bb06
Seventh. fixed an issue where the action query entered by the user wa…
Dec 21, 2024
93e18aa
The unload utility part will be fixed in issue CBRD-25762.
Dec 21, 2024
c0a67ae
Fixed the memory-monitor-check failure issue. We suspected that a mem…
Dec 23, 2024
c747dfd
edited for readability.
Dec 23, 2024
1f14a07
remove the part that does free_and_init when new_trigger_stmt_str is …
Dec 23, 2024
39e71d3
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Dec 30, 2024
19e79ea
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Dec 30, 2024
3aad5e0
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Jan 2, 2025
3447fc0
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Jan 3, 2025
b24bf76
Reflects the code review content.
Jan 3, 2025
9629c73
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Jan 3, 2025
61101f5
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Jan 6, 2025
a7aaf67
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Jan 6, 2025
815ef05
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Jan 7, 2025
9664301
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Jan 9, 2025
75547f6
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Jan 9, 2025
1905b0d
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Jan 24, 2025
c8aec2f
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Feb 3, 2025
9f44c2b
Merge remote-tracking branch 'upstream/develop' into CBRD-25719
Feb 4, 2025
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
3 changes: 2 additions & 1 deletion src/object/trigger_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,8 @@ compile_trigger_activity (TR_TRIGGER * trigger, TR_ACTIVITY * activity, int with
class_mop = ((curname == NULL && tempname == NULL) ? NULL : trigger->class_mop);

activity->statement =
pt_compile_trigger_stmt ((PARSER_CONTEXT *) activity->parser, text, class_mop, curname, tempname);
pt_compile_trigger_stmt ((PARSER_CONTEXT *) activity->parser, text, class_mop, curname, tempname,
&activity->source, with_evaluate);
if (activity->statement == NULL || pt_has_error ((PARSER_CONTEXT *) activity->parser))
{
error = er_errid ();
Expand Down
75 changes: 71 additions & 4 deletions src/parser/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static PT_NODE *pt_find_lck_class_from_partition (PARSER_CONTEXT * parser, PT_NO
static int pt_in_lck_array (PT_CLASS_LOCKS * lcks, const char *str, LC_PREFETCH_FLAGS flags);

static void remove_appended_trigger_info (char *msg, int with_evaluate);
static char *change_trigger_action_query (PARSER_CONTEXT * parser, PT_NODE * statement, int with_evaluate);

static PT_NODE *pt_set_trigger_obj_pre (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
static PT_NODE *pt_set_trigger_obj_post (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk);
Expand Down Expand Up @@ -1043,6 +1044,55 @@ remove_appended_trigger_info (char *msg, int with_evaluate)
}
}

/*
* change_trigger_action_query () - remove appended trigger info
* parser(in):
* action_stmt(in):
* with_evaluate(in):
*/
static char *
change_trigger_action_query (PARSER_CONTEXT * parser, PT_NODE * statement, int with_evaluate)
ctshim marked this conversation as resolved.
Show resolved Hide resolved
{
int result_len = 0;
char *result = NULL;
char *new_trigger_stmt_str = NULL;
unsigned int save_custom;

assert (parser != NULL || statement != NULL);

save_custom = parser->custom_print;
parser->flag.is_parsing_trigger = 1;

result = parser_print_tree_with_quotes (parser, statement);

parser->flag.is_parsing_trigger = 0;
parser->custom_print = save_custom;

/* remove appended trigger evaluate info */
result = remove_appended_trigger_evaluate (result, with_evaluate);
if (result == NULL)
{
return NULL;
}

result_len = strlen (result) + 1;
if (result_len < 0)
{
return NULL;
}

new_trigger_stmt_str = (char *) malloc (result_len);
if (new_trigger_stmt_str == NULL)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, (size_t) result_len);
return NULL;
}

snprintf (new_trigger_stmt_str, result_len, "%s", result);

return new_trigger_stmt_str;
ctshim marked this conversation as resolved.
Show resolved Hide resolved
}

/*
* pt_compile_trigger_stmt () - Compiles the trigger_stmt so that it can be
* executed by pt_exec_trigger_stmt
Expand All @@ -1052,21 +1102,22 @@ remove_appended_trigger_info (char *msg, int with_evaluate)
* class_op(in): class name to resolve name1 and name2 to
* name1(in): name to resolve
* name2(in): name to resolve
* new_trigger_stmt(in):
* with_evaluate(in):
*
*/

PT_NODE *
pt_compile_trigger_stmt (PARSER_CONTEXT * parser, const char *trigger_stmt, DB_OBJECT * class_op, const char *name1,
const char *name2)
const char *name2, char **new_trigger_stmt, int with_evaluate)
{
char *stmt_str = NULL;
const char *class_name;
PT_NODE **statement_p, *statement;
int is_update_object;
PT_NODE *err_node;
int with_evaluate;

assert (parser != NULL);
assert (parser != NULL || !*new_trigger_stmt);

if (!trigger_stmt)
return NULL;
Expand Down Expand Up @@ -1160,13 +1211,17 @@ pt_compile_trigger_stmt (PARSER_CONTEXT * parser, const char *trigger_stmt, DB_O
upd->info.update.spec = entity;
}

/* prevents forced cast() within the code. (parser->flag.is_parsing_trigger == 1 && p->info.expr.flag != 0) */
parser->flag.is_parsing_trigger = 1;

statement = pt_compile (parser, statement);

parser->flag.is_parsing_trigger = 0;

/* Remove those info we append, which users can't understand them */
if (pt_has_error (parser))
{
err_node = pt_get_errors (parser);
with_evaluate = strstr (trigger_stmt, "EVALUATE ( ") != NULL ? true : false;
while (err_node)
{
remove_appended_trigger_info (err_node->info.error_msg.error_message, with_evaluate);
Expand All @@ -1177,6 +1232,18 @@ pt_compile_trigger_stmt (PARSER_CONTEXT * parser, const char *trigger_stmt, DB_O
/* We need to do view translation here on the expression to be executed. */
if (statement)
{
char *new_trigger_stmt_str = NULL;

new_trigger_stmt_str =
change_trigger_action_query (parser, statement->info.scope.stmt->info.trigger_action.expression, with_evaluate);
if (new_trigger_stmt_str == NULL)
{
assert (new_trigger_stmt_str != NULL);
return NULL;
}

*new_trigger_stmt = new_trigger_stmt_str;

statement->info.scope.stmt->info.trigger_action.expression =
mq_translate (parser, statement->info.scope.stmt->info.trigger_action.expression);
/*
Expand Down
1 change: 1 addition & 0 deletions src/parser/parse_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ parser_create_parser (void)
parser->flag.is_auto_commit = 0;
parser->flag.is_parsing_static_sql = 0;
parser->flag.is_parsing_unload_schema = 0;
parser->flag.is_parsing_trigger = 0;

parser->external_into_label = NULL;
parser->external_into_label_cnt = 0;
Expand Down
1 change: 1 addition & 0 deletions src/parser/parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4024,6 +4024,7 @@ struct parser_context
unsigned is_auto_commit:1; /* set to true, if auto commit. */
unsigned is_parsing_static_sql:1; /* For PL/CSQL's static SQL: parameterize PL/CSQL variable symbols (to host variable) */
unsigned is_parsing_unload_schema:1; /* Parsing in unload: used to parse the scode (original query) of PL/CSQL to remove the owner. */
unsigned is_parsing_trigger:1;
} flag;
};

Expand Down
10 changes: 7 additions & 3 deletions src/parser/parse_tree_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -11668,6 +11668,12 @@ pt_print_expr (PARSER_CONTEXT * parser, PT_NODE * p)
}
else
{
if (parser->flag.is_parsing_trigger && p->info.expr.flag)
{
q = pt_append_varchar (parser, q, r1);
break;
}

r2 = pt_print_bytes (parser, p->info.expr.cast_type);
q = pt_append_nulstring (parser, q, " cast(");
q = pt_append_varchar (parser, q, r1);
Expand Down Expand Up @@ -13042,7 +13048,7 @@ pt_print_insert (PARSER_CONTEXT * parser, PT_NODE * p)

// TODO: [PL/CSQL] need refactoring
unsigned int save_custom = parser->custom_print;
if (parser->flag.is_parsing_static_sql == 1)
if (parser->flag.is_parsing_static_sql || parser->flag.is_parsing_trigger)
{
parser->custom_print |= PT_SUPPRESS_RESOLVED;
parser->custom_print & ~PT_PRINT_ALIAS;
Expand Down Expand Up @@ -13598,8 +13604,6 @@ pt_print_name (PARSER_CONTEXT * parser, PT_NODE * p)
PARSER_VARCHAR *q = NULL, *r1;
unsigned int save_custom = parser->custom_print;

char *dot = NULL;

parser->custom_print = parser->custom_print | p->info.name.custom_print;

if (!(parser->custom_print & PT_SUPPRESS_META_ATTR_CLASS) && (p->info.name.meta_class == PT_META_CLASS))
Expand Down
3 changes: 2 additions & 1 deletion src/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ extern "C"
extern PT_NODE *pt_class_pre_fetch (PARSER_CONTEXT * parser, PT_NODE * statement);

extern PT_NODE *pt_compile_trigger_stmt (PARSER_CONTEXT * parser, const char *trigger_stmt, DB_OBJECT * class_op,
const char *name1, const char *name2);
const char *name1, const char *name2, char **new_trigger_stmt,
int with_evaluate);
extern int pt_exec_trigger_stmt (PARSER_CONTEXT * parser, PT_NODE * trigger_stmt, DB_OBJECT * object1,
DB_OBJECT * object2, DB_VALUE * result);

Expand Down
Loading