From c1f3073333d01987ac9c3e5f6c197b9e2afc3ba9 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 30 Nov 2008 20:51:25 +0000 Subject: Clean up the API for DestReceiver objects by eliminating the assumption that a Portal is a useful and sufficient additional argument for CreateDestReceiver --- it just isn't, in most cases. Instead formalize the approach of passing any needed parameters to the receiver separately. One unexpected benefit of this change is that we can declare typedef Portal in a less surprising location. This patch is just code rearrangement and doesn't change any functionality. I'll tackle the HOLD-cursor-vs-toast problem in a follow-on patch. --- src/backend/access/common/printtup.c | 50 ++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'src/backend/access/common/printtup.c') diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index 346f6e1d8ab..3645fd0f2f2 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.102 2008/04/17 21:37:28 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.103 2008/11/30 20:51:24 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -67,31 +67,16 @@ typedef struct * ---------------- */ DestReceiver * -printtup_create_DR(CommandDest dest, Portal portal) +printtup_create_DR(CommandDest dest) { - DR_printtup *self = (DR_printtup *) palloc(sizeof(DR_printtup)); + DR_printtup *self = (DR_printtup *) palloc0(sizeof(DR_printtup)); - if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3) - self->pub.receiveSlot = printtup; - else - { - /* - * In protocol 2.0 the Bind message does not exist, so there is no way - * for the columns to have different print formats; it's sufficient to - * look at the first one. - */ - if (portal->formats && portal->formats[0] != 0) - self->pub.receiveSlot = printtup_internal_20; - else - self->pub.receiveSlot = printtup_20; - } + self->pub.receiveSlot = printtup; /* might get changed later */ self->pub.rStartup = printtup_startup; self->pub.rShutdown = printtup_shutdown; self->pub.rDestroy = printtup_destroy; self->pub.mydest = dest; - self->portal = portal; - /* * Send T message automatically if DestRemote, but not if * DestRemoteExecute @@ -105,6 +90,33 @@ printtup_create_DR(CommandDest dest, Portal portal) return (DestReceiver *) self; } +/* + * Set parameters for a DestRemote (or DestRemoteExecute) receiver + */ +void +SetRemoteDestReceiverParams(DestReceiver *self, Portal portal) +{ + DR_printtup *myState = (DR_printtup *) self; + + Assert(myState->pub.mydest == DestRemote || + myState->pub.mydest == DestRemoteExecute); + + myState->portal = portal; + + if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3) + { + /* + * In protocol 2.0 the Bind message does not exist, so there is no way + * for the columns to have different print formats; it's sufficient to + * look at the first one. + */ + if (portal->formats && portal->formats[0] != 0) + myState->pub.receiveSlot = printtup_internal_20; + else + myState->pub.receiveSlot = printtup_20; + } +} + static void printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo) { -- cgit v1.2.3