Skip to content

Commit

Permalink
Merged if condition into one, defined TRIGGER_MAX_NEST_LEVEL
Browse files Browse the repository at this point in the history
Task: BABEL-2170

Signed-off-by: Deepakshi Mittal <[email protected]>
  • Loading branch information
deepakshi-mittal committed Jan 2, 2024
1 parent f105495 commit 9e30f51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 6 additions & 12 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,22 +745,16 @@ pltsql_bbfViewHasInsteadofTrigger(Relation view, CmdType event)
Oid current_tgoid = trigger->tgoid;
Oid prev_tgoid = InvalidOid;
prev_tgoid = lfirst_oid(list_tail(triggerInvocationSequence));
if (list_length(triggerInvocationSequence) > 32)
if (prev_tgoid == current_tgoid)
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)")));
}
else if (prev_tgoid == current_tgoid)
{
return false; /** A trigger called recursively by itself*/
return false; /** Loop trigger call by itself*/
}
else if (list_member_oid(triggerInvocationSequence, current_tgoid))
else if (list_length(triggerInvocationSequence) > TRIGGER_MAX_NEST_LEVEL || list_member_oid(triggerInvocationSequence, current_tgoid))
{
/** A trigger called recursively by another trigger */
/** Loop trigger call by another trigger */
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)")));
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("Maximum stored procedure, function, trigger, or view nesting level exceeded (limit %d)", TRIGGER_MAX_NEST_LEVEL)));
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions contrib/babelfishpg_tsql/src/pltsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
/* Max number of Args allowed for Prepared stmts. */
#define PREPARE_STMT_MAX_ARGS 2100

#define MAX_TRIGGER_NEST_LEVEL 32 /* Maximum allowed trigger nesting level*/

/*
* Compiler's namespace item types
*/
Expand Down

0 comments on commit 9e30f51

Please sign in to comment.