---------- * exec_stmt_block Execute a block of statements * ---------- */
| 1622 | * ---------- |
| 1623 | */ |
| 1624 | static int |
| 1625 | exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block) |
| 1626 | { |
| 1627 | volatile int rc = -1; |
| 1628 | int i; |
| 1629 | |
| 1630 | /* |
| 1631 | * First initialize all variables declared in this block |
| 1632 | */ |
| 1633 | estate->err_text = gettext_noop("during statement block local variable initialization"); |
| 1634 | |
| 1635 | for (i = 0; i < block->n_initvars; i++) |
| 1636 | { |
| 1637 | int n = block->initvarnos[i]; |
| 1638 | PLpgSQL_datum *datum = estate->datums[n]; |
| 1639 | |
| 1640 | /* |
| 1641 | * The set of dtypes handled here must match plpgsql_add_initdatums(). |
| 1642 | * |
| 1643 | * Note that we currently don't support promise datums within blocks, |
| 1644 | * only at a function's outermost scope, so we needn't handle those |
| 1645 | * here. |
| 1646 | */ |
| 1647 | switch (datum->dtype) |
| 1648 | { |
| 1649 | case PLPGSQL_DTYPE_VAR: |
| 1650 | { |
| 1651 | PLpgSQL_var *var = (PLpgSQL_var *) datum; |
| 1652 | |
| 1653 | /* |
| 1654 | * Free any old value, in case re-entering block, and |
| 1655 | * initialize to NULL |
| 1656 | */ |
| 1657 | assign_simple_var(estate, var, (Datum) 0, true, false); |
| 1658 | |
| 1659 | if (var->default_val == NULL) |
| 1660 | { |
| 1661 | /* |
| 1662 | * If needed, give the datatype a chance to reject |
| 1663 | * NULLs, by assigning a NULL to the variable. We |
| 1664 | * claim the value is of type UNKNOWN, not the var's |
| 1665 | * datatype, else coercion will be skipped. |
| 1666 | */ |
| 1667 | if (var->datatype->typtype == TYPTYPE_DOMAIN) |
| 1668 | exec_assign_value(estate, |
| 1669 | (PLpgSQL_datum *) var, |
| 1670 | (Datum) 0, |
| 1671 | true, |
| 1672 | UNKNOWNOID, |
| 1673 | -1); |
| 1674 | |
| 1675 | /* parser should have rejected NOT NULL */ |
| 1676 | Assert(!var->notnull); |
| 1677 | } |
| 1678 | else |
| 1679 | { |
| 1680 | exec_assign_expr(estate, (PLpgSQL_datum *) var, |
| 1681 | var->default_val); |
no test coverage detected