Skip to content

Commit

Permalink
Sixth. fixed an issue where the action query entered by the user was …
Browse files Browse the repository at this point in the history
…rewritten into an unexecutable rewrite query.
  • Loading branch information
jongmin-won committed Dec 20, 2024
1 parent 2d1f5b8 commit 1034d83
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/parser/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ change_trigger_action_query (PARSER_CONTEXT * parser, PT_NODE * statement, char
save_custom = parser->custom_print;

parser->flag.is_parsing_trigger = 1;
parser->custom_print |= PT_SUPPRESS_RESOLVED;

new_trigger_stmt_str = parser_print_tree_with_quotes (parser, statement);

Expand Down Expand Up @@ -1223,8 +1224,13 @@ 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))
{
Expand Down
33 changes: 21 additions & 12 deletions src/parser/parse_tree_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -11663,6 +11663,12 @@ pt_print_expr (PARSER_CONTEXT * parser, PT_NODE * p)
}
else
{
if (parser->flag.is_parsing_trigger == 1 && p->info.expr.flag != 0)
{
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 @@ -13020,7 +13026,8 @@ 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 || parser->flag.is_parsing_trigger == 1)
//if (parser->flag.is_parsing_static_sql == 1 || parser->flag.is_parsing_trigger == 1)
if (parser->flag.is_parsing_static_sql == 1)
{
parser->custom_print |= PT_SUPPRESS_RESOLVED;
parser->custom_print & ~PT_PRINT_ALIAS;
Expand All @@ -13029,6 +13036,11 @@ pt_print_insert (PARSER_CONTEXT * parser, PT_NODE * p)
r1 = pt_print_bytes (parser, p->info.insert.spec);
r2 = pt_print_bytes_l (parser, p->info.insert.attr_list);

if (parser->flag.is_parsing_trigger == 1)
{
r2 = NULL;
}

parser->custom_print = save_custom;

if (p->info.insert.is_subinsert == PT_IS_SUBINSERT)
Expand Down Expand Up @@ -13579,17 +13591,14 @@ pt_print_name (PARSER_CONTEXT * parser, PT_NODE * p)
//char *dot = NULL;

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

/*
if (parser->flag.is_parsing_trigger == 1 && p->info.name.resolved != NULL)
{
if (strcasecmp (p->info.name.resolved, "obj") == 0 || strcasecmp (p->info.name.resolved, "new") == 0
|| strcasecmp (p->info.name.resolved, "old") == 0)
{
parser->custom_print &= ~PT_SUPPRESS_RESOLVED;
}
}
*/
//if (parser->flag.is_parsing_trigger != 1 && (*parser->statements)->node_type != PT_SCOPE)
if (parser->flag.is_parsing_trigger == 1 && p->info.name.resolved != NULL)
{
//if (strcasecmp (p->info.name.resolved, "obj") == 0 || strcasecmp (p->info.name.resolved, "new") == 0 || strcasecmp (p->info.name.resolved, "old") == 0)
//{
parser->custom_print &= ~PT_SUPPRESS_RESOLVED;
//}
}

if (!(parser->custom_print & PT_SUPPRESS_META_ATTR_CLASS) && (p->info.name.meta_class == PT_META_CLASS))
{
Expand Down

0 comments on commit 1034d83

Please sign in to comment.