* Register the transient relations from 'tdata' using this SPI connection. * This should be called by PL implementations' trigger handlers after * connecting, in order to make transition tables visible to any queries run * in this connection. */
| 3625 | * in this connection. |
| 3626 | */ |
| 3627 | int |
| 3628 | SPI_register_trigger_data(TriggerData *tdata) |
| 3629 | { |
| 3630 | if (tdata == NULL) |
| 3631 | return SPI_ERROR_ARGUMENT; |
| 3632 | |
| 3633 | if (tdata->tg_newtable) |
| 3634 | { |
| 3635 | EphemeralNamedRelation enr = |
| 3636 | palloc(sizeof(EphemeralNamedRelationData)); |
| 3637 | int rc; |
| 3638 | |
| 3639 | enr->md.name = tdata->tg_trigger->tgnewtable; |
| 3640 | enr->md.reliddesc = tdata->tg_relation->rd_id; |
| 3641 | enr->md.tupdesc = NULL; |
| 3642 | enr->md.enrtype = ENR_NAMED_TUPLESTORE; |
| 3643 | enr->md.enrtuples = tuplestore_tuple_count(tdata->tg_newtable); |
| 3644 | enr->reldata = tdata->tg_newtable; |
| 3645 | rc = SPI_register_relation(enr); |
| 3646 | if (rc != SPI_OK_REL_REGISTER) |
| 3647 | return rc; |
| 3648 | } |
| 3649 | |
| 3650 | if (tdata->tg_oldtable) |
| 3651 | { |
| 3652 | EphemeralNamedRelation enr = |
| 3653 | palloc(sizeof(EphemeralNamedRelationData)); |
| 3654 | int rc; |
| 3655 | |
| 3656 | enr->md.name = tdata->tg_trigger->tgoldtable; |
| 3657 | enr->md.reliddesc = tdata->tg_relation->rd_id; |
| 3658 | enr->md.tupdesc = NULL; |
| 3659 | enr->md.enrtype = ENR_NAMED_TUPLESTORE; |
| 3660 | enr->md.enrtuples = tuplestore_tuple_count(tdata->tg_oldtable); |
| 3661 | enr->reldata = tdata->tg_oldtable; |
| 3662 | rc = SPI_register_relation(enr); |
| 3663 | if (rc != SPI_OK_REL_REGISTER) |
| 3664 | return rc; |
| 3665 | } |
| 3666 | |
| 3667 | return SPI_OK_TD_REGISTER; |
| 3668 | } |
no test coverage detected