1 /*-------------------------------------------------------------------------
4 * support for communication destinations
7 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.56 2003/05/06 00:20:33 tgl Exp $
13 *-------------------------------------------------------------------------
17 * BeginCommand - initialize the destination at start of command
18 * DestToFunction - identify per-tuple processing routines
19 * EndCommand - clean up the destination at end of command
20 * NullCommand - tell dest that an empty query string was recognized
21 * ReadyForQuery - tell dest that we are ready for a new query
24 * These routines do the appropriate work before and after
25 * tuples are returned by a query to keep the backend and the
26 * "destination" portals synchronized.
31 #include "access/printtup.h"
32 #include "access/xact.h"
33 #include "executor/tstoreReceiver.h"
34 #include "libpq/libpq.h"
35 #include "libpq/pqformat.h"
39 * dummy DestReceiver functions
43 donothingReceive(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
48 donothingSetup(DestReceiver *self, int operation,
49 const char *portalName, TupleDesc typeinfo, List *targetlist)
54 donothingCleanup(DestReceiver *self)
59 * static DestReceiver structs for dest types needing no local state
62 static DestReceiver donothingDR = {
63 donothingReceive, donothingSetup, donothingCleanup
66 static DestReceiver debugtupDR = {
67 debugtup, debugSetup, donothingCleanup
70 static DestReceiver spi_printtupDR = {
71 spi_printtup, spi_dest_setup, donothingCleanup
75 * BeginCommand - initialize the destination at start of command
79 BeginCommand(const char *commandTag, CommandDest dest)
81 /* Nothing to do at present */
85 * DestToFunction - return appropriate receiver function set for dest
89 DestToFunction(CommandDest dest)
94 return printtup_create_DR(false, true);
97 return printtup_create_DR(true, true);
100 /* like Remote, but suppress output of T message */
101 return printtup_create_DR(false, false);
103 case RemoteExecuteInternal:
104 return printtup_create_DR(true, false);
113 return &spi_printtupDR;
116 return tstoreReceiverCreateDR();
119 /* should never get here */
124 * EndCommand - clean up the destination at end of command
128 EndCommand(const char *commandTag, CommandDest dest)
135 case RemoteExecuteInternal:
136 pq_puttextmessage('C', commandTag);
148 * NullCommand - tell dest that an empty query string was recognized
150 * In FE/BE protocol version 1.0, this hack is necessary to support
151 * libpq's crufty way of determining whether a multiple-command
152 * query string is done. In protocol 2.0 it's probably not really
153 * necessary to distinguish empty queries anymore, but we still do it
154 * for backwards compatibility with 1.0. In protocol 3.0 it has some
155 * use again, since it ensures that there will be a recognizable end
156 * to the response to an Execute message.
160 NullCommand(CommandDest dest)
167 case RemoteExecuteInternal:
170 * tell the fe that we saw an empty query string. In protocols
171 * before 3.0 this has a useless empty-string message body.
173 if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3)
174 pq_putemptymessage('I');
176 pq_puttextmessage('I', "");
188 * ReadyForQuery - tell dest that we are ready for a new query
190 * The ReadyForQuery message is sent in protocol versions 2.0 and up
191 * so that the FE can tell when we are done processing a query string.
192 * In versions 3.0 and up, it also carries a transaction state indicator.
194 * Note that by flushing the stdio buffer here, we can avoid doing it
195 * most other places and thus reduce the number of separate packets sent.
199 ReadyForQuery(CommandDest dest)
206 case RemoteExecuteInternal:
207 if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3)
211 pq_beginmessage(&buf, 'Z');
212 pq_sendbyte(&buf, TransactionBlockStatusCode());
215 else if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2)
216 pq_putemptymessage('Z');
217 /* Flush output at end of cycle in any case. */