| 3251 | } |
| 3252 | |
| 3253 | static void |
| 3254 | validateDomainConstraint(Oid domainoid, char *ccbin) |
| 3255 | { |
| 3256 | Expr *expr = (Expr *) stringToNode(ccbin); |
| 3257 | List *rels; |
| 3258 | ListCell *rt; |
| 3259 | EState *estate; |
| 3260 | ExprContext *econtext; |
| 3261 | ExprState *exprstate; |
| 3262 | |
| 3263 | /* Need an EState to run ExecEvalExpr */ |
| 3264 | estate = CreateExecutorState(); |
| 3265 | econtext = GetPerTupleExprContext(estate); |
| 3266 | |
| 3267 | /* build execution state for expr */ |
| 3268 | exprstate = ExecPrepareExpr(expr, estate); |
| 3269 | |
| 3270 | /* Fetch relation list with attributes based on this domain */ |
| 3271 | /* ShareLock is sufficient to prevent concurrent data changes */ |
| 3272 | |
| 3273 | rels = get_rels_with_domain(domainoid, ShareLock); |
| 3274 | |
| 3275 | foreach(rt, rels) |
| 3276 | { |
| 3277 | RelToCheck *rtc = (RelToCheck *) lfirst(rt); |
| 3278 | Relation testrel = rtc->rel; |
| 3279 | TupleDesc tupdesc = RelationGetDescr(testrel); |
| 3280 | TupleTableSlot *slot; |
| 3281 | TableScanDesc scan; |
| 3282 | Snapshot snapshot; |
| 3283 | |
| 3284 | /* Scan all tuples in this relation */ |
| 3285 | snapshot = RegisterSnapshot(GetLatestSnapshot()); |
| 3286 | scan = table_beginscan(testrel, snapshot, 0, NULL); |
| 3287 | slot = table_slot_create(testrel, NULL); |
| 3288 | while (table_scan_getnextslot(scan, ForwardScanDirection, slot)) |
| 3289 | { |
| 3290 | int i; |
| 3291 | |
| 3292 | /* Test attributes that are of the domain */ |
| 3293 | for (i = 0; i < rtc->natts; i++) |
| 3294 | { |
| 3295 | int attnum = rtc->atts[i]; |
| 3296 | Datum d; |
| 3297 | bool isNull; |
| 3298 | Datum conResult; |
| 3299 | Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1); |
| 3300 | |
| 3301 | d = slot_getattr(slot, attnum, &isNull); |
| 3302 | |
| 3303 | econtext->domainValue_datum = d; |
| 3304 | econtext->domainValue_isNull = isNull; |
| 3305 | |
| 3306 | conResult = ExecEvalExprSwitchContext(exprstate, |
| 3307 | econtext, |
| 3308 | &isNull); |
| 3309 | |
| 3310 | if (!isNull && !DatumGetBool(conResult)) |
no test coverage detected