MCPcopy Create free account
hub / github.com/apache/cloudberry / exec_stmt_assert

Function exec_stmt_assert

src/pl/plpgsql/src/pl_exec.c:3885–3922  ·  view source on GitHub ↗

---------- * exec_stmt_assert Assert statement * ---------- */

Source from the content-addressed store, hash-verified

3883 * ----------
3884 */
3885static int
3886exec_stmt_assert(PLpgSQL_execstate *estate, PLpgSQL_stmt_assert *stmt)
3887{
3888 bool value;
3889 bool isnull;
3890
3891 /* do nothing when asserts are not enabled */
3892 if (!plpgsql_check_asserts)
3893 return PLPGSQL_RC_OK;
3894
3895 value = exec_eval_boolean(estate, stmt->cond, &isnull);
3896 exec_eval_cleanup(estate);
3897
3898 if (isnull || !value)
3899 {
3900 char *message = NULL;
3901
3902 if (stmt->message != NULL)
3903 {
3904 Datum val;
3905 Oid typeid;
3906 int32 typmod;
3907
3908 val = exec_eval_expr(estate, stmt->message,
3909 &isnull, &typeid, &typmod);
3910 if (!isnull)
3911 message = convert_value_to_string(estate, val, typeid);
3912 /* we mustn't do exec_eval_cleanup here */
3913 }
3914
3915 ereport(ERROR,
3916 (errcode(ERRCODE_ASSERT_FAILURE),
3917 message ? errmsg_internal("%s", message) :
3918 errmsg("assertion failed")));
3919 }
3920
3921 return PLPGSQL_RC_OK;
3922}
3923
3924/* ----------
3925 * Initialize a mostly empty execution state

Callers 1

exec_stmtsFunction · 0.85

Calls 7

exec_eval_booleanFunction · 0.85
exec_eval_cleanupFunction · 0.85
exec_eval_exprFunction · 0.85
convert_value_to_stringFunction · 0.85
errcodeFunction · 0.50
errmsg_internalFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected