1999-04-25 05:19:27 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pqformat.h
|
|
|
|
* Definitions for formatting and parsing frontend/backend messages
|
|
|
|
*
|
2017-01-03 19:48:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1999-04-25 05:19:27 +02:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/libpq/pqformat.h
|
1999-04-25 05:19:27 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PQFORMAT_H
|
|
|
|
#define PQFORMAT_H
|
|
|
|
|
|
|
|
#include "lib/stringinfo.h"
|
2017-10-12 01:01:52 +02:00
|
|
|
#include "mb/pg_wchar.h"
|
|
|
|
#include "port/pg_bswap.h"
|
1999-04-25 05:19:27 +02:00
|
|
|
|
2003-04-22 02:08:07 +02:00
|
|
|
extern void pq_beginmessage(StringInfo buf, char msgtype);
|
2017-10-12 01:01:52 +02:00
|
|
|
extern void pq_beginmessage_reuse(StringInfo buf, char msgtype);
|
|
|
|
extern void pq_endmessage(StringInfo buf);
|
|
|
|
extern void pq_endmessage_reuse(StringInfo buf);
|
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
extern void pq_sendbytes(StringInfo buf, const char *data, int datalen);
|
2003-05-08 20:16:37 +02:00
|
|
|
extern void pq_sendcountedtext(StringInfo buf, const char *str, int slen,
|
2003-08-04 02:43:34 +02:00
|
|
|
bool countincludesself);
|
2003-05-09 17:44:42 +02:00
|
|
|
extern void pq_sendtext(StringInfo buf, const char *str, int slen);
|
1999-05-25 18:15:34 +02:00
|
|
|
extern void pq_sendstring(StringInfo buf, const char *str);
|
2009-03-02 22:18:43 +01:00
|
|
|
extern void pq_send_ascii_string(StringInfo buf, const char *str);
|
2003-05-09 23:19:50 +02:00
|
|
|
extern void pq_sendfloat4(StringInfo buf, float4 f);
|
|
|
|
extern void pq_sendfloat8(StringInfo buf, float8 f);
|
2017-10-12 01:01:52 +02:00
|
|
|
|
|
|
|
extern void pq_sendfloat4(StringInfo buf, float4 f);
|
|
|
|
extern void pq_sendfloat8(StringInfo buf, float8 f);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a int8 to a StringInfo buffer, which already has enough space
|
|
|
|
* preallocated.
|
|
|
|
*
|
|
|
|
* The use of restrict allows the compiler to optimize the code based on the
|
|
|
|
* assumption that buf, buf->len, buf->data and *buf->data don't
|
|
|
|
* overlap. Without the annotation buf->len etc cannot be kept in a register
|
|
|
|
* over subsequent pq_writeint* calls.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
pq_writeint8(StringInfo restrict buf, int8 i)
|
|
|
|
{
|
|
|
|
int8 ni = i;
|
|
|
|
|
|
|
|
Assert(buf->len + sizeof(i) <= buf->maxlen);
|
|
|
|
memcpy((char *restrict) (buf->data + buf->len), &ni, sizeof(ni));
|
|
|
|
buf->len += sizeof(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a int16 to a StringInfo buffer, which already has enough space
|
|
|
|
* preallocated.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
pq_writeint16(StringInfo restrict buf, int16 i)
|
|
|
|
{
|
|
|
|
int16 ni = pg_hton16(i);
|
|
|
|
|
|
|
|
Assert(buf->len + sizeof(ni) <= buf->maxlen);
|
|
|
|
memcpy((char *restrict) (buf->data + buf->len), &ni, sizeof(i));
|
|
|
|
buf->len += sizeof(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a int32 to a StringInfo buffer, which already has enough space
|
|
|
|
* preallocated.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
pq_writeint32(StringInfo restrict buf, int32 i)
|
|
|
|
{
|
|
|
|
int32 ni = pg_hton32(i);
|
|
|
|
|
|
|
|
Assert(buf->len + sizeof(i) <= buf->maxlen);
|
|
|
|
memcpy((char *restrict) (buf->data + buf->len), &ni, sizeof(i));
|
|
|
|
buf->len += sizeof(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a int64 to a StringInfo buffer, which already has enough space
|
|
|
|
* preallocated.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
pq_writeint64(StringInfo restrict buf, int64 i)
|
|
|
|
{
|
|
|
|
int64 ni = pg_hton64(i);
|
|
|
|
|
|
|
|
Assert(buf->len + sizeof(i) <= buf->maxlen);
|
|
|
|
memcpy((char *restrict) (buf->data + buf->len), &ni, sizeof(i));
|
|
|
|
buf->len += sizeof(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a null-terminated text string (with conversion) to a buffer with
|
|
|
|
* preallocated space.
|
|
|
|
*
|
|
|
|
* NB: The pre-allocated space needs to be sufficient for the string after
|
|
|
|
* converting to client encoding.
|
|
|
|
*
|
|
|
|
* NB: passed text string must be null-terminated, and so is the data
|
|
|
|
* sent to the frontend.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
pq_writestring(StringInfo restrict buf, const char *restrict str)
|
|
|
|
{
|
|
|
|
int slen = strlen(str);
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = pg_server_to_client(str, slen);
|
|
|
|
if (p != str) /* actual conversion has been done? */
|
|
|
|
slen = strlen(p);
|
|
|
|
|
|
|
|
Assert(buf->len + slen + 1 <= buf->maxlen);
|
|
|
|
|
|
|
|
memcpy(((char *restrict) buf->data + buf->len), p, slen + 1);
|
|
|
|
buf->len += slen + 1;
|
|
|
|
|
|
|
|
if (p != str)
|
|
|
|
pfree(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append a binary int8 to a StringInfo buffer */
|
|
|
|
static inline void
|
|
|
|
pq_sendint8(StringInfo buf, int8 i)
|
|
|
|
{
|
|
|
|
enlargeStringInfo(buf, sizeof(i));
|
|
|
|
pq_writeint8(buf, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append a binary int16 to a StringInfo buffer */
|
|
|
|
static inline void
|
|
|
|
pq_sendint16(StringInfo buf, int16 i)
|
|
|
|
{
|
|
|
|
enlargeStringInfo(buf, sizeof(i));
|
|
|
|
pq_writeint16(buf, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append a binary int32 to a StringInfo buffer */
|
|
|
|
static inline void
|
|
|
|
pq_sendint32(StringInfo buf, int32 i)
|
|
|
|
{
|
|
|
|
enlargeStringInfo(buf, sizeof(i));
|
|
|
|
pq_writeint32(buf, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append a binary int64 to a StringInfo buffer */
|
|
|
|
static inline void
|
|
|
|
pq_sendint64(StringInfo buf, int64 i)
|
|
|
|
{
|
|
|
|
enlargeStringInfo(buf, sizeof(i));
|
|
|
|
pq_writeint64(buf, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append a binary byte to a StringInfo buffer */
|
|
|
|
static inline void
|
|
|
|
pq_sendbyte(StringInfo buf, int8 byt)
|
|
|
|
{
|
|
|
|
pq_sendint8(buf, byt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a binary integer to a StringInfo buffer
|
|
|
|
*
|
|
|
|
* This function is deprecated.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
pq_sendint(StringInfo buf, int i, int b)
|
|
|
|
{
|
|
|
|
switch (b)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
pq_sendint8(buf, (int8) i);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pq_sendint16(buf, (int16) i);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
pq_sendint32(buf, (int32) i);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
elog(ERROR, "unsupported integer size %d", b);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-25 05:19:27 +02:00
|
|
|
|
2003-05-09 17:44:42 +02:00
|
|
|
extern void pq_begintypsend(StringInfo buf);
|
|
|
|
extern bytea *pq_endtypsend(StringInfo buf);
|
|
|
|
|
2003-04-22 02:08:07 +02:00
|
|
|
extern void pq_puttextmessage(char msgtype, const char *str);
|
|
|
|
extern void pq_putemptymessage(char msgtype);
|
1999-04-25 23:50:58 +02:00
|
|
|
|
2003-04-19 02:02:30 +02:00
|
|
|
extern int pq_getmsgbyte(StringInfo msg);
|
|
|
|
extern unsigned int pq_getmsgint(StringInfo msg, int b);
|
2003-05-09 17:44:42 +02:00
|
|
|
extern int64 pq_getmsgint64(StringInfo msg);
|
2003-05-09 23:19:50 +02:00
|
|
|
extern float4 pq_getmsgfloat4(StringInfo msg);
|
|
|
|
extern float8 pq_getmsgfloat8(StringInfo msg);
|
2003-04-19 02:02:30 +02:00
|
|
|
extern const char *pq_getmsgbytes(StringInfo msg, int datalen);
|
|
|
|
extern void pq_copymsgbytes(StringInfo msg, char *buf, int datalen);
|
2003-05-09 17:44:42 +02:00
|
|
|
extern char *pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes);
|
2003-04-19 02:02:30 +02:00
|
|
|
extern const char *pq_getmsgstring(StringInfo msg);
|
Fix several mistakes around parallel workers and client_encoding.
Previously, workers sent data to the leader using the client encoding.
That mostly worked, but the leader the converted the data back to the
server encoding. Since not all encoding conversions are reversible,
that could provoke failures. Fix by using the database encoding for
all communication between worker and leader.
Also, while temporary changes to GUC settings, as from the SET clause
of a function, are in general OK for parallel query, changing
client_encoding this way inside of a parallel worker is not OK.
Previously, that would have confused the leader; with these changes,
it would not confuse the leader, but it wouldn't do anything either.
So refuse such changes in parallel workers.
Also, the previous code naively assumed that when it received a
NotifyResonse from the worker, it could pass that directly back to the
user. But now that worker-to-leader communication always uses the
database encoding, that's clearly no longer correct - though,
actually, the old way was always broken for V2 clients. So
disassemble and reconstitute the message instead.
Issues reported by Peter Eisentraut. Patch by me, reviewed by
Peter Eisentraut.
2016-07-01 00:35:32 +02:00
|
|
|
extern const char *pq_getmsgrawstring(StringInfo msg);
|
2003-04-19 02:02:30 +02:00
|
|
|
extern void pq_getmsgend(StringInfo msg);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
#endif /* PQFORMAT_H */
|