1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* dest.c
|
2002-02-27 20:36:13 +01:00
|
|
|
* support for communication destinations
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2002-06-20 22:29:54 +02:00
|
|
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2003-01-21 23:06:12 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.50 2003/01/21 22:06:12 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* INTERFACE ROUTINES
|
2002-02-27 20:36:13 +01:00
|
|
|
* BeginCommand - initialize the destination at start of command
|
1999-01-27 01:36:28 +01:00
|
|
|
* DestToFunction - identify per-tuple processing routines
|
2002-02-27 20:36:13 +01:00
|
|
|
* EndCommand - clean up the destination at end of command
|
1998-05-07 01:51:16 +02:00
|
|
|
* NullCommand - tell dest that an empty query string was recognized
|
|
|
|
* ReadyForQuery - tell dest that we are ready for a new query
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* These routines do the appropriate work before and after
|
|
|
|
* tuples are returned by a query to keep the backend and the
|
|
|
|
* "destination" portals synchronized.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-01-10 21:19:49 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "postgres.h"
|
|
|
|
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "access/printtup.h"
|
1998-01-26 02:42:53 +01:00
|
|
|
#include "libpq/libpq.h"
|
1999-04-25 05:19:27 +02:00
|
|
|
#include "libpq/pqformat.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* ----------------
|
1999-01-27 01:36:28 +01:00
|
|
|
* dummy DestReceiver functions
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-01-08 09:39:10 +01:00
|
|
|
static void
|
1999-05-26 00:43:53 +02:00
|
|
|
donothingReceive(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-01-27 01:36:28 +01:00
|
|
|
static void
|
2002-02-27 20:36:13 +01:00
|
|
|
donothingSetup(DestReceiver *self, int operation,
|
|
|
|
const char *portalName, TupleDesc typeinfo)
|
1999-01-27 01:36:28 +01:00
|
|
|
{
|
|
|
|
}
|
1997-08-29 11:06:27 +02:00
|
|
|
|
1999-01-27 01:36:28 +01:00
|
|
|
static void
|
1999-05-26 00:43:53 +02:00
|
|
|
donothingCleanup(DestReceiver *self)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-01-27 01:36:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* static DestReceiver structs for dest types needing no local state
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
static DestReceiver donothingDR = {
|
|
|
|
donothingReceive, donothingSetup, donothingCleanup
|
|
|
|
};
|
|
|
|
static DestReceiver debugtupDR = {
|
2002-02-27 20:36:13 +01:00
|
|
|
debugtup, debugSetup, donothingCleanup
|
1999-01-27 01:36:28 +01:00
|
|
|
};
|
|
|
|
static DestReceiver spi_printtupDR = {
|
2003-01-21 23:06:12 +01:00
|
|
|
spi_printtup, spi_dest_setup, donothingCleanup
|
1999-01-27 01:36:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* ----------------
|
2002-02-27 20:36:13 +01:00
|
|
|
* BeginCommand - initialize the destination at start of command
|
1999-01-27 01:36:28 +01:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
2002-02-27 20:36:13 +01:00
|
|
|
BeginCommand(const char *commandTag, CommandDest dest)
|
1999-01-27 01:36:28 +01:00
|
|
|
{
|
2002-02-27 20:36:13 +01:00
|
|
|
/* Nothing to do at present */
|
1999-01-27 01:36:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* DestToFunction - return appropriate receiver function set for dest
|
|
|
|
* ----------------
|
|
|
|
*/
|
1999-05-25 18:15:34 +02:00
|
|
|
DestReceiver *
|
1999-01-27 01:36:28 +01:00
|
|
|
DestToFunction(CommandDest dest)
|
|
|
|
{
|
|
|
|
switch (dest)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
case Remote:
|
2000-12-01 23:10:31 +01:00
|
|
|
return printtup_create_DR(false);
|
1999-01-27 01:36:28 +01:00
|
|
|
|
|
|
|
case RemoteInternal:
|
2000-12-01 23:10:31 +01:00
|
|
|
return printtup_create_DR(true);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case Debug:
|
1999-05-25 18:15:34 +02:00
|
|
|
return &debugtupDR;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case SPI:
|
1999-05-25 18:15:34 +02:00
|
|
|
return &spi_printtupDR;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case None:
|
1999-05-25 18:15:34 +02:00
|
|
|
return &donothingDR;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
2002-02-27 20:36:13 +01:00
|
|
|
/* should never get here */
|
1999-05-25 18:15:34 +02:00
|
|
|
return &donothingDR;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
2002-02-27 20:36:13 +01:00
|
|
|
* EndCommand - clean up the destination at end of command
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
2002-02-26 23:47:12 +01:00
|
|
|
EndCommand(const char *commandTag, CommandDest dest)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
switch (dest)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case Remote:
|
1999-01-27 01:36:28 +01:00
|
|
|
case RemoteInternal:
|
2002-02-26 23:47:12 +01:00
|
|
|
pq_puttextmessage('C', commandTag);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case None:
|
2002-02-26 23:47:12 +01:00
|
|
|
case Debug:
|
|
|
|
case SPI:
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are necessary to sync communications between fe/be processes doing
|
|
|
|
* COPY rel TO stdout
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
|
|
|
* or
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* COPY rel FROM stdin
|
|
|
|
*
|
1998-05-07 01:51:16 +02:00
|
|
|
* NOTE: the message code letters are changed at protocol version 2.0
|
|
|
|
* to eliminate possible confusion with data tuple messages.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
1996-11-10 04:06:38 +01:00
|
|
|
SendCopyBegin(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1998-05-07 01:51:16 +02:00
|
|
|
if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2)
|
1999-04-25 05:19:27 +02:00
|
|
|
pq_putbytes("H", 1); /* new way */
|
1998-05-07 01:51:16 +02:00
|
|
|
else
|
1999-04-25 05:19:27 +02:00
|
|
|
pq_putbytes("B", 1); /* old way */
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1996-11-10 04:06:38 +01:00
|
|
|
ReceiveCopyBegin(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1998-05-07 01:51:16 +02:00
|
|
|
if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2)
|
1999-04-25 05:19:27 +02:00
|
|
|
pq_putbytes("G", 1); /* new way */
|
1998-05-07 01:51:16 +02:00
|
|
|
else
|
1999-04-25 05:19:27 +02:00
|
|
|
pq_putbytes("D", 1); /* old way */
|
1998-05-07 01:51:16 +02:00
|
|
|
/* We *must* flush here to ensure FE knows it can send. */
|
1997-09-07 07:04:48 +02:00
|
|
|
pq_flush();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
1998-05-07 01:51:16 +02:00
|
|
|
* NullCommand - tell dest that an empty query string was recognized
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1998-05-07 01:51:16 +02:00
|
|
|
* In FE/BE protocol version 1.0, this hack is necessary to support
|
|
|
|
* libpq's crufty way of determining whether a multiple-command
|
|
|
|
* query string is done. In protocol 2.0 it's probably not really
|
|
|
|
* necessary to distinguish empty queries anymore, but we still do it
|
|
|
|
* for backwards compatibility with 1.0.
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
NullCommand(CommandDest dest)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
switch (dest)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
case RemoteInternal:
|
|
|
|
case Remote:
|
2001-03-22 07:16:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* tell the fe that we saw an empty query string
|
1999-01-27 01:36:28 +01:00
|
|
|
*/
|
2001-10-28 07:26:15 +01:00
|
|
|
pq_putbytes("I", 2); /* note we send I and \0 */
|
1998-05-07 01:51:16 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Debug:
|
|
|
|
case None:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* ReadyForQuery - tell dest that we are ready for a new query
|
|
|
|
*
|
|
|
|
* The ReadyForQuery message is sent in protocol versions 2.0 and up
|
|
|
|
* so that the FE can tell when we are done processing a query string.
|
|
|
|
*
|
|
|
|
* Note that by flushing the stdio buffer here, we can avoid doing it
|
|
|
|
* most other places and thus reduce the number of separate packets sent.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ReadyForQuery(CommandDest dest)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
switch (dest)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
case RemoteInternal:
|
|
|
|
case Remote:
|
1999-01-27 01:36:28 +01:00
|
|
|
if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2)
|
1999-04-25 05:19:27 +02:00
|
|
|
pq_putbytes("Z", 1);
|
1999-01-27 01:36:28 +01:00
|
|
|
/* Flush output at end of cycle in any case. */
|
|
|
|
pq_flush();
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Debug:
|
|
|
|
case None:
|
|
|
|
default:
|
|
|
|
break;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
}
|