* callback for individual changed tuples */
| 591 | * callback for individual changed tuples |
| 592 | */ |
| 593 | static void |
| 594 | pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, |
| 595 | Relation relation, ReorderBufferChange *change) |
| 596 | { |
| 597 | TestDecodingData *data; |
| 598 | TestDecodingTxnData *txndata; |
| 599 | Form_pg_class class_form; |
| 600 | TupleDesc tupdesc; |
| 601 | MemoryContext old; |
| 602 | |
| 603 | data = ctx->output_plugin_private; |
| 604 | txndata = txn->output_plugin_private; |
| 605 | |
| 606 | /* output BEGIN if we haven't yet */ |
| 607 | if (data->skip_empty_xacts && !txndata->xact_wrote_changes) |
| 608 | { |
| 609 | pg_output_begin(ctx, data, txn, false); |
| 610 | } |
| 611 | txndata->xact_wrote_changes = true; |
| 612 | |
| 613 | class_form = RelationGetForm(relation); |
| 614 | tupdesc = RelationGetDescr(relation); |
| 615 | |
| 616 | /* Avoid leaking memory by using and resetting our own context */ |
| 617 | old = MemoryContextSwitchTo(data->context); |
| 618 | |
| 619 | OutputPluginPrepareWrite(ctx, true); |
| 620 | |
| 621 | appendStringInfoString(ctx->out, "table "); |
| 622 | appendStringInfoString(ctx->out, |
| 623 | quote_qualified_identifier(get_namespace_name(get_rel_namespace(RelationGetRelid(relation))), |
| 624 | class_form->relrewrite ? |
| 625 | get_rel_name(class_form->relrewrite) : |
| 626 | NameStr(class_form->relname))); |
| 627 | appendStringInfoChar(ctx->out, ':'); |
| 628 | |
| 629 | switch (change->action) |
| 630 | { |
| 631 | case REORDER_BUFFER_CHANGE_INSERT: |
| 632 | appendStringInfoString(ctx->out, " INSERT:"); |
| 633 | if (change->data.tp.newtuple == NULL) |
| 634 | appendStringInfoString(ctx->out, " (no-tuple-data)"); |
| 635 | else |
| 636 | tuple_to_stringinfo(ctx->out, tupdesc, |
| 637 | &change->data.tp.newtuple->tuple, |
| 638 | false); |
| 639 | break; |
| 640 | case REORDER_BUFFER_CHANGE_UPDATE: |
| 641 | appendStringInfoString(ctx->out, " UPDATE:"); |
| 642 | if (change->data.tp.oldtuple != NULL) |
| 643 | { |
| 644 | appendStringInfoString(ctx->out, " old-key:"); |
| 645 | tuple_to_stringinfo(ctx->out, tupdesc, |
| 646 | &change->data.tp.oldtuple->tuple, |
| 647 | true); |
| 648 | appendStringInfoString(ctx->out, " new-tuple:"); |
| 649 | } |
| 650 |
nothing calls this directly
no test coverage detected