---------- * exec_stmt_assert Assert statement * ---------- */
| 3883 | * ---------- |
| 3884 | */ |
| 3885 | static int |
| 3886 | exec_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 |
no test coverage detected