38#define VALID_LONG_MESSAGE_TYPE(id) \
39 ((id) == PqMsg_CopyData || \
40 (id) == PqMsg_DataRow || \
41 (id) == PqMsg_ErrorResponse || \
42 (id) == PqMsg_FunctionCallResponse || \
43 (id) == PqMsg_NoticeResponse || \
44 (id) == PqMsg_NotificationResponse || \
45 (id) == PqMsg_RowDescription)
112 if (avail < msgLength)
191 "message type 0x%02x arrived from server while idle",
544 goto advance_and_error;
553 goto advance_and_error;
565 goto advance_and_error;
571 result->
binary = (nfields > 0) ? 1 : 0;
574 for (
i = 0;
i < nfields;
i++)
593 goto advance_and_error;
600 columnid = (int) ((
int16) columnid);
601 typlen = (int) ((
int16) typlen);
609 goto advance_and_error;
692 const char *
errmsg = NULL;
698 goto advance_and_error;
703 goto not_enough_data;
712 goto advance_and_error;
717 for (
i = 0;
i < nparams;
i++)
722 goto not_enough_data;
792 goto advance_and_error;
795 if (tupnfields != nfields)
798 goto advance_and_error;
810 goto advance_and_error;
817 for (
i = 0;
i < nfields;
i++)
824 goto advance_and_error;
826 rowbuf[
i].
len = vlen;
842 goto advance_and_error;
901 bool have_position =
false;
957 have_position =
true;
1034 const char *querytext = NULL;
1095 querypos = atoi(
val);
1114 querypos = atoi(
val);
1128 if (querytext && querypos > 0)
1181 if (
val || valf || vall)
1203#define DISPLAY_SIZE 60
1204#define MIN_RIGHT_CUT 10
1227 wquery = strdup(query);
1248 slen = strlen(wquery) + 1;
1249 if (slen > SIZE_MAX /
sizeof(
int))
1255 qidx = (
int *)
malloc(slen *
sizeof(
int));
1261 scridx = (
int *)
malloc(slen *
sizeof(
int));
1287 for (cno = 0; wquery[qoffset] !=
'\0'; cno++)
1289 char ch = wquery[qoffset];
1291 qidx[cno] = qoffset;
1292 scridx[cno] = scroffset;
1300 wquery[qoffset] =
' ';
1306 else if (ch ==
'\r' || ch ==
'\n')
1312 wquery[qidx[cno - 1]] !=
'\r')
1349 qidx[iend] = qoffset;
1350 scridx[iend] = scroffset;
1391 wquery[qidx[iend]] =
'\0';
1420 scroffset += scridx[loc] - scridx[ibeg];
1421 for (
i = 0;
i < scroffset;
i++)
1457 libpq_append_conn_error(
conn,
"received invalid protocol negotiation message: server requested downgrade to a higher-numbered version");
1463 libpq_append_conn_error(
conn,
"received invalid protocol negotiation message: server requested downgrade to pre-3.0 protocol version");
1470 libpq_append_conn_error(
conn,
"received invalid protocol negotiation message: server requested downgrade to non-existent 3.1 protocol version");
1476 libpq_append_conn_error(
conn,
"received invalid protocol negotiation message: server reported negative number of unsupported parameters");
1486 if (their_version < conn->min_pversion)
1491 "min_protocol_version",
1505 for (
int i = 0;
i < num;
i++)
1589 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);
1594 if (cancel_key_len < 4)
1596 libpq_append_conn_error(
conn,
"received invalid BackendKeyData message: cancel key with length %d is too short (minimum 4 bytes)", cancel_key_len);
1601 if (cancel_key_len > 256)
1603 libpq_append_conn_error(
conn,
"received invalid BackendKeyData message: cancel key with length %d is too long (maximum 256 bytes)", cancel_key_len);
1672 nmlen = strlen(svname);
1684 strcpy(newNotify->
relname, svname);
1687 newNotify->
be_pid = be_pid;
1688 newNotify->
next = NULL;
1734 for (
i = 0;
i < nfields;
i++)
1768 switch (xact_status)
1818 if (avail < msgLength - 4)
1932 *buffer = (
char *)
malloc(msgLength + 1);
1933 if (*buffer == NULL)
1939 (*buffer)[msgLength] =
'\0';
1991 if (s[status - 1] ==
'\n')
1993 s[status - 1] =
'\0';
2158 int *result_buf,
int *actual_result_len,
2162 bool needInput =
false;
2184 for (
i = 0;
i < nargs; ++
i)
2252 if (avail < msgLength)
2283 if (*actual_result_len != -1)
2394 if (
len == 0 ||
len > INT_MAX)
2398 startpacket = (
char *)
malloc(*packetlen);
2421 size_t packet_len = 0;
2436#define ADD_STARTUP_OPTION(optname, optval) \
2439 strcpy(packet + packet_len, optname); \
2440 if (pg_add_size_overflow(packet_len, strlen(optname) + 1, &packet_len)) \
2443 strcpy(packet + packet_len, optval); \
2444 if (pg_add_size_overflow(packet_len, strlen(optval) + 1, &packet_len)) \
2470 if ((
val = getenv(next_eo->
envName)) != NULL)
2479 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)
Assert(PointerIsAligned(start, uint64))
static bool pg_add_size_overflow(size_t a, size_t b, size_t *result)
#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)