mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
Introduce macros for protocol characters.
This commit introduces descriptively-named macros for the identifiers used in wire protocol messages. These new macros are placed in a new header file so that they can be easily used by third-party code. Author: Dave Cramer Reviewed-by: Alvaro Herrera, Tatsuo Ishii, Peter Smith, Robert Haas, Tom Lane, Peter Eisentraut, Michael Paquier Discussion: https://postgr.es/m/CADK3HHKbBmK-PKf1bPNFoMC%2BoBt%2BpD9PH8h5nvmBQskEHm-Ehw%40mail.gmail.com
This commit is contained in:
@ -2281,7 +2281,7 @@ NotifyMyFrontEnd(const char *channel, const char *payload, int32 srcPid)
|
||||
{
|
||||
StringInfoData buf;
|
||||
|
||||
pq_beginmessage(&buf, 'A');
|
||||
pq_beginmessage(&buf, PqMsg_NotificationResponse);
|
||||
pq_sendint32(&buf, srcPid);
|
||||
pq_sendstring(&buf, channel);
|
||||
pq_sendstring(&buf, payload);
|
||||
|
@ -174,7 +174,7 @@ ReceiveCopyBegin(CopyFromState cstate)
|
||||
int16 format = (cstate->opts.binary ? 1 : 0);
|
||||
int i;
|
||||
|
||||
pq_beginmessage(&buf, 'G');
|
||||
pq_beginmessage(&buf, PqMsg_CopyInResponse);
|
||||
pq_sendbyte(&buf, format); /* overall format */
|
||||
pq_sendint16(&buf, natts);
|
||||
for (i = 0; i < natts; i++)
|
||||
@ -279,13 +279,13 @@ CopyGetData(CopyFromState cstate, void *databuf, int minread, int maxread)
|
||||
/* Validate message type and set packet size limit */
|
||||
switch (mtype)
|
||||
{
|
||||
case 'd': /* CopyData */
|
||||
case PqMsg_CopyData:
|
||||
maxmsglen = PQ_LARGE_MESSAGE_LIMIT;
|
||||
break;
|
||||
case 'c': /* CopyDone */
|
||||
case 'f': /* CopyFail */
|
||||
case 'H': /* Flush */
|
||||
case 'S': /* Sync */
|
||||
case PqMsg_CopyDone:
|
||||
case PqMsg_CopyFail:
|
||||
case PqMsg_Flush:
|
||||
case PqMsg_Sync:
|
||||
maxmsglen = PQ_SMALL_MESSAGE_LIMIT;
|
||||
break;
|
||||
default:
|
||||
@ -305,20 +305,20 @@ CopyGetData(CopyFromState cstate, void *databuf, int minread, int maxread)
|
||||
/* ... and process it */
|
||||
switch (mtype)
|
||||
{
|
||||
case 'd': /* CopyData */
|
||||
case PqMsg_CopyData:
|
||||
break;
|
||||
case 'c': /* CopyDone */
|
||||
case PqMsg_CopyDone:
|
||||
/* COPY IN correctly terminated by frontend */
|
||||
cstate->raw_reached_eof = true;
|
||||
return bytesread;
|
||||
case 'f': /* CopyFail */
|
||||
case PqMsg_CopyFail:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_QUERY_CANCELED),
|
||||
errmsg("COPY from stdin failed: %s",
|
||||
pq_getmsgstring(cstate->fe_msgbuf))));
|
||||
break;
|
||||
case 'H': /* Flush */
|
||||
case 'S': /* Sync */
|
||||
case PqMsg_Flush:
|
||||
case PqMsg_Sync:
|
||||
|
||||
/*
|
||||
* Ignore Flush/Sync for the convenience of client
|
||||
|
@ -144,7 +144,7 @@ SendCopyBegin(CopyToState cstate)
|
||||
int16 format = (cstate->opts.binary ? 1 : 0);
|
||||
int i;
|
||||
|
||||
pq_beginmessage(&buf, 'H');
|
||||
pq_beginmessage(&buf, PqMsg_CopyOutResponse);
|
||||
pq_sendbyte(&buf, format); /* overall format */
|
||||
pq_sendint16(&buf, natts);
|
||||
for (i = 0; i < natts; i++)
|
||||
@ -159,7 +159,7 @@ SendCopyEnd(CopyToState cstate)
|
||||
/* Shouldn't have any unsent data */
|
||||
Assert(cstate->fe_msgbuf->len == 0);
|
||||
/* Send Copy Done message */
|
||||
pq_putemptymessage('c');
|
||||
pq_putemptymessage(PqMsg_CopyDone);
|
||||
}
|
||||
|
||||
/*----------
|
||||
@ -247,7 +247,7 @@ CopySendEndOfRow(CopyToState cstate)
|
||||
CopySendChar(cstate, '\n');
|
||||
|
||||
/* Dump the accumulated row as one CopyData message */
|
||||
(void) pq_putmessage('d', fe_msgbuf->data, fe_msgbuf->len);
|
||||
(void) pq_putmessage(PqMsg_CopyData, fe_msgbuf->data, fe_msgbuf->len);
|
||||
break;
|
||||
case COPY_CALLBACK:
|
||||
cstate->data_dest_cb(fe_msgbuf->data, fe_msgbuf->len);
|
||||
|
Reference in New Issue
Block a user