* ExecWithCheckOptions -- check that tuple satisfies any WITH CHECK OPTIONs * of the specified kind. * * Note that this needs to be called multiple times to ensure that all kinds of * WITH CHECK OPTIONs are handled (both those from views which have the WITH * CHECK OPTION set and from row-level security policies). See ExecInsert() * and ExecUpdate(). */
| 3214 | * and ExecUpdate(). |
| 3215 | */ |
| 3216 | void |
| 3217 | ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo, |
| 3218 | TupleTableSlot *slot, EState *estate) |
| 3219 | { |
| 3220 | Relation rel = resultRelInfo->ri_RelationDesc; |
| 3221 | TupleDesc tupdesc = RelationGetDescr(rel); |
| 3222 | ExprContext *econtext; |
| 3223 | ListCell *l1, |
| 3224 | *l2; |
| 3225 | |
| 3226 | /* |
| 3227 | * We will use the EState's per-tuple context for evaluating constraint |
| 3228 | * expressions (creating it if it's not already there). |
| 3229 | */ |
| 3230 | econtext = GetPerTupleExprContext(estate); |
| 3231 | |
| 3232 | /* Arrange for econtext's scan tuple to be the tuple under test */ |
| 3233 | econtext->ecxt_scantuple = slot; |
| 3234 | |
| 3235 | /* Check each of the constraints */ |
| 3236 | forboth(l1, resultRelInfo->ri_WithCheckOptions, |
| 3237 | l2, resultRelInfo->ri_WithCheckOptionExprs) |
| 3238 | { |
| 3239 | WithCheckOption *wco = (WithCheckOption *) lfirst(l1); |
| 3240 | ExprState *wcoExpr = (ExprState *) lfirst(l2); |
| 3241 | |
| 3242 | /* |
| 3243 | * Skip any WCOs which are not the kind we are looking for at this |
| 3244 | * time. |
| 3245 | */ |
| 3246 | if (wco->kind != kind) |
| 3247 | continue; |
| 3248 | |
| 3249 | /* |
| 3250 | * WITH CHECK OPTION checks are intended to ensure that the new tuple |
| 3251 | * is visible (in the case of a view) or that it passes the |
| 3252 | * 'with-check' policy (in the case of row security). If the qual |
| 3253 | * evaluates to NULL or FALSE, then the new tuple won't be included in |
| 3254 | * the view or doesn't pass the 'with-check' policy for the table. |
| 3255 | */ |
| 3256 | if (!ExecQual(wcoExpr, econtext)) |
| 3257 | { |
| 3258 | char *val_desc; |
| 3259 | Bitmapset *modifiedCols; |
| 3260 | |
| 3261 | switch (wco->kind) |
| 3262 | { |
| 3263 | /* |
| 3264 | * For WITH CHECK OPTIONs coming from views, we might be |
| 3265 | * able to provide the details on the row, depending on |
| 3266 | * the permissions on the relation (that is, if the user |
| 3267 | * could view it directly anyway). For RLS violations, we |
| 3268 | * don't include the data since we don't know if the user |
| 3269 | * should be able to view the tuple as that depends on the |
| 3270 | * USING policy. |
| 3271 | */ |
| 3272 | case WCO_VIEW_CHECK: |
| 3273 | /* See the comment in ExecConstraints(). */ |
no test coverage detected