37#define VALID_LONG_MESSAGE_TYPE(id) \
38 ((id) == PqMsg_CopyData || \
39 (id) == PqMsg_DataRow || \
40 (id) == PqMsg_ErrorResponse || \
41 (id) == PqMsg_FunctionCallResponse || \
42 (id) == PqMsg_NoticeResponse || \
43 (id) == PqMsg_NotificationResponse || \
44 (id) == PqMsg_RowDescription)
111 if (avail < msgLength)
190 "message type 0x%02x arrived from server while idle",
543 goto advance_and_error;
552 goto advance_and_error;
564 goto advance_and_error;
570 result->
binary = (nfields > 0) ? 1 : 0;
573 for (
i = 0;
i < nfields;
i++)
592 goto advance_and_error;
599 columnid = (int) ((
int16) columnid);
600 typlen = (int) ((
int16) typlen);
608 goto advance_and_error;
691 const char *
errmsg = NULL;
697 goto advance_and_error;
702 goto not_enough_data;
711 goto advance_and_error;
716 for (
i = 0;
i < nparams;
i++)
721 goto not_enough_data;
791 goto advance_and_error;
794 if (tupnfields != nfields)
797 goto advance_and_error;
809 goto advance_and_error;
816 for (
i = 0;
i < nfields;
i++)
823 goto advance_and_error;
825 rowbuf[
i].
len = vlen;
841 goto advance_and_error;
900 bool have_position =
false;
956 have_position =
true;
1033 const char *querytext = NULL;
1094 querypos = atoi(
val);
1113 querypos = atoi(
val);
1127 if (querytext && querypos > 0)
1180 if (
val || valf || vall)
1202#define DISPLAY_SIZE 60
1203#define MIN_RIGHT_CUT 10
1226 wquery = strdup(query);
1247 slen = strlen(wquery) + 1;
1248 if (slen > SIZE_MAX /
sizeof(
int))
1254 qidx = (
int *)
malloc(slen *
sizeof(
int));
1260 scridx = (
int *)
malloc(slen *
sizeof(
int));
1286 for (cno = 0; wquery[qoffset] !=
'\0'; cno++)
1288 char ch = wquery[qoffset];
1290 qidx[cno] = qoffset;
1291 scridx[cno] = scroffset;
1299 wquery[qoffset] =
' ';
1305 else if (ch ==
'\r' || ch ==
'\n')
1311 wquery[qidx[cno - 1]] !=
'\r')
1348 qidx[iend] = qoffset;
1349 scridx[iend] = scroffset;
1390 wquery[qidx[iend]] =
'\0';
1419 scroffset += scridx[loc] - scridx[ibeg];
1420 for (
i = 0;
i < scroffset;
i++)
1456 libpq_append_conn_error(
conn,
"received invalid protocol negotiation message: server requested downgrade to a higher-numbered version");
1462 libpq_append_conn_error(
conn,
"received invalid protocol negotiation message: server requested downgrade to pre-3.0 protocol version");
1469 libpq_append_conn_error(
conn,
"received invalid protocol negotiation message: server requested downgrade to non-existent 3.1 protocol version");
1475 libpq_append_conn_error(
conn,
"received invalid protocol negotiation message: server reported negative number of unsupported parameters");
1485 if (their_version < conn->min_pversion)
1490 "min_protocol_version",
1504 for (
int i = 0;
i < num;
i++)
1588 libpq_append_conn_error(
conn,
"received invalid BackendKeyData message: cancel key with length %d not allowed in protocol version 3.0 (must be 4 bytes)", cancel_key_len);
1593 if (cancel_key_len < 4)
1595 libpq_append_conn_error(
conn,
"received invalid BackendKeyData message: cancel key with length %d is too short (minimum 4 bytes)", cancel_key_len);
1600 if (cancel_key_len > 256)
1602 libpq_append_conn_error(
conn,
"received invalid BackendKeyData message: cancel key with length %d is too long (maximum 256 bytes)", cancel_key_len);
1671 nmlen = strlen(svname);
1683 strcpy(newNotify->
relname, svname);
1686 newNotify->
be_pid = be_pid;
1687 newNotify->
next = NULL;
1733 for (
i = 0;
i < nfields;
i++)
1767 switch (xact_status)
1817 if (avail < msgLength - 4)
1931 *buffer = (
char *)
malloc(msgLength + 1);
1932 if (*buffer == NULL)
1938 (*buffer)[msgLength] =
'\0';
1990 if (s[status - 1] ==
'\n')
1992 s[status - 1] =
'\0';
2157 int *result_buf,
int *actual_result_len,
2161 bool needInput =
false;
2183 for (
i = 0;
i < nargs; ++
i)
2251 if (avail < msgLength)
2282 if (*actual_result_len != -1)
2393 if (
len == 0 ||
len > INT_MAX)
2397 startpacket = (
char *)
malloc(*packetlen);
2420 if (result <
s1 || result <
s2)
2440 size_t packet_len = 0;
2455#define ADD_STARTUP_OPTION(optname, optval) \
2458 strcpy(packet + packet_len, optname); \
2459 if (add_size_overflow(packet_len, strlen(optname) + 1, &packet_len)) \
2462 strcpy(packet + packet_len, optval); \
2463 if (add_size_overflow(packet_len, strlen(optval) + 1, &packet_len)) \
2489 if ((
val = getenv(next_eo->
envName)) != NULL)
2498 packet[packet_len] =
'\0';
#define MemSet(start, val, len)
int errmsg(const char *fmt,...)
void pqDropConnection(PGconn *conn, bool flushInput)
void * pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary)
void pqSaveMessageField(PGresult *res, char code, const char *value)
PGresult * pqPrepareAsyncResult(PGconn *conn)
void pqCommandQueueAdvance(PGconn *conn, bool isReadyForQuery, bool gotSync)
void pqSetResultError(PGresult *res, PQExpBuffer errorMessage, int offset)
void pqSaveErrorResult(PGconn *conn)
int pqRowProcessor(PGconn *conn, const char **errmsgp)
int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize)
PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
void pqClearAsyncResult(PGconn *conn)
int PQisBusy(PGconn *conn)
int pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
char * pqResultStrdup(PGresult *res, const char *str)
int pqReadData(PGconn *conn)
int pqPutInt(int value, size_t bytes, PGconn *conn)
int pqFlush(PGconn *conn)
void pqParseDone(PGconn *conn, int newInStart)
int pqPutMsgStart(char msg_type, PGconn *conn)
int pqSkipnchar(size_t len, PGconn *conn)
int pqGetc(char *result, PGconn *conn)
int pqGetInt(int *result, size_t bytes, PGconn *conn)
int pqWait(int forRead, int forWrite, PGconn *conn)
int pqGets(PQExpBuffer buf, PGconn *conn)
int pqPutnchar(const void *s, size_t len, PGconn *conn)
int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)
int pqGetnchar(void *s, size_t len, PGconn *conn)
int PQmblenBounded(const char *s, int encoding)
int pqPutMsgEnd(PGconn *conn)
void pqBuildErrorMessage3(PQExpBuffer msg, const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)
void pqParseInput3(PGconn *conn)
char * pqBuildStartupPacket3(PGconn *conn, int *packetlen, const PQEnvironmentOption *options)
int pqEndcopy3(PGconn *conn)
static int getNotify(PGconn *conn)
static int getAnotherTuple(PGconn *conn, int msgLength)
static int getRowDescriptions(PGconn *conn, int msgLength)
static void reportErrorPosition(PQExpBuffer msg, const char *query, int loc, int encoding)
PGresult * pqFunctionCall3(PGconn *conn, Oid fnid, int *result_buf, int *actual_result_len, int result_is_int, const PQArgBlock *args, int nargs)
int pqGetlineAsync3(PGconn *conn, char *buffer, int bufsize)
int pqGetCopyData3(PGconn *conn, char **buffer, int async)
int pqGetNegotiateProtocolVersion3(PGconn *conn)
static int getParameterStatus(PGconn *conn)
static size_t build_startup_packet(const PGconn *conn, char *packet, const PQEnvironmentOption *options)
static void handleFatalError(PGconn *conn)
#define VALID_LONG_MESSAGE_TYPE(id)
static int getCopyStart(PGconn *conn, ExecStatusType copytype)
static void handleSyncLoss(PGconn *conn, char id, int msgLength)
static int getReadyForQuery(PGconn *conn)
#define ADD_STARTUP_OPTION(optname, optval)
static int getBackendKeyData(PGconn *conn, int msgLength)
static int getCopyDataMessage(PGconn *conn)
static int getParamDescriptions(PGconn *conn, int msgLength)
int pqGetline3(PGconn *conn, char *s, int maxlen)
int pqGetErrorNotice3(PGconn *conn, bool isError)
static bool add_size_overflow(size_t s1, size_t s2, size_t *dst)
Assert(PointerIsAligned(start, uint64))
#define PQresultErrorField
#define pqIsnonblocking(conn)
#define pgHavePendingResult(conn)
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
int pg_strcasecmp(const char *s1, const char *s2)
size_t strlcpy(char *dst, const char *src, size_t siz)
#define PG_DIAG_INTERNAL_QUERY
#define PG_DIAG_SCHEMA_NAME
#define PG_DIAG_CONSTRAINT_NAME
#define PG_DIAG_DATATYPE_NAME
#define PG_DIAG_SOURCE_LINE
#define PG_DIAG_STATEMENT_POSITION
#define PG_DIAG_SOURCE_FILE
#define PG_DIAG_MESSAGE_HINT
#define PG_DIAG_TABLE_NAME
#define PG_DIAG_MESSAGE_PRIMARY
#define PG_DIAG_COLUMN_NAME
#define PG_DIAG_MESSAGE_DETAIL
#define PG_DIAG_SOURCE_FUNCTION
#define PG_DIAG_INTERNAL_POSITION
#define PG_PROTOCOL_MAJOR(v)
#define PG_PROTOCOL(m, n)
#define PG_PROTOCOL_MINOR(v)
void initPQExpBuffer(PQExpBuffer str)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
#define PQExpBufferDataBroken(buf)
#define PqMsg_CloseComplete
#define PqMsg_NotificationResponse
#define PqMsg_BindComplete
#define PqMsg_ParameterDescription
#define PqMsg_FunctionCall
#define PqMsg_FunctionCallResponse
#define PqMsg_ReadyForQuery
#define PqMsg_CopyInResponse
#define PqMsg_EmptyQueryResponse
#define PqMsg_RowDescription
#define PqMsg_CopyBothResponse
#define PqMsg_ParameterStatus
#define PqMsg_BackendKeyData
#define PqMsg_CommandComplete
#define PqMsg_ErrorResponse
#define PqMsg_NoticeResponse
#define PqMsg_CopyOutResponse
#define PqMsg_ParseComplete
PQnoticeReceiver noticeRec
PGTransactionStatusType xactStatus
ProtocolVersion min_pversion
PQExpBufferData workBuffer
char * client_encoding_initial
PQExpBufferData errorMessage
PGAsyncStatusType asyncStatus
PGpipelineStatus pipelineStatus
PGNoticeHooks noticeHooks
PGcmdQueueEntry * cmd_queue_head
PGContextVisibility show_context
PGNoticeHooks noticeHooks
char cmdStatus[CMDSTATUS_LEN]
PGMessageField * errFields
PGresParamDesc * paramDescs
ExecStatusType resultStatus
int pg_encoding_dsplen(int encoding, const char *mbstr)
int pg_encoding_max_length(int encoding)