36 #define VALID_LONG_MESSAGE_TYPE(id) \
37 ((id) == PqMsg_CopyData || \
38 (id) == PqMsg_DataRow || \
39 (id) == PqMsg_ErrorResponse || \
40 (id) == PqMsg_FunctionCallResponse || \
41 (id) == PqMsg_NoticeResponse || \
42 (id) == PqMsg_NotificationResponse || \
43 (id) == PqMsg_RowDescription)
108 if (avail < msgLength)
187 "message type 0x%02x arrived from server while idle",
525 goto advance_and_error;
534 goto advance_and_error;
546 goto advance_and_error;
552 result->
binary = (nfields > 0) ? 1 : 0;
555 for (
i = 0;
i < nfields;
i++)
574 goto advance_and_error;
581 columnid = (int) ((
int16) columnid);
582 typlen = (int) ((
int16) typlen);
590 goto advance_and_error;
673 const char *
errmsg = NULL;
679 goto advance_and_error;
684 goto not_enough_data;
693 goto advance_and_error;
698 for (
i = 0;
i < nparams;
i++)
703 goto not_enough_data;
773 goto advance_and_error;
776 if (tupnfields != nfields)
779 goto advance_and_error;
791 goto advance_and_error;
798 for (
i = 0;
i < nfields;
i++)
805 goto advance_and_error;
807 rowbuf[
i].
len = vlen;
823 goto advance_and_error;
881 bool have_position =
false;
937 have_position =
true;
1014 const char *querytext = NULL;
1075 querypos = atoi(
val);
1094 querypos = atoi(
val);
1108 if (querytext && querypos > 0)
1161 if (
val || valf || vall)
1183 #define DISPLAY_SIZE 60
1184 #define MIN_RIGHT_CUT 10
1207 wquery = strdup(query);
1220 slen = strlen(wquery) + 1;
1222 qidx = (
int *)
malloc(slen *
sizeof(
int));
1228 scridx = (
int *)
malloc(slen *
sizeof(
int));
1254 for (cno = 0; wquery[qoffset] !=
'\0'; cno++)
1256 char ch = wquery[qoffset];
1258 qidx[cno] = qoffset;
1259 scridx[cno] = scroffset;
1267 wquery[qoffset] =
' ';
1273 else if (ch ==
'\r' || ch ==
'\n')
1279 wquery[qidx[cno - 1]] !=
'\r')
1316 qidx[iend] = qoffset;
1317 scridx[iend] = scroffset;
1358 wquery[qidx[iend]] =
'\0';
1387 scroffset += scridx[loc] - scridx[ibeg];
1388 for (
i = 0;
i < scroffset;
i++)
1417 their_version = tmp;
1423 for (
int i = 0;
i < num;
i++)
1435 if (their_version < conn->pversion)
1443 "protocol extensions not supported by server: %s", num),
1449 if (!(their_version < conn->pversion) && !(num > 0))
1521 nmlen = strlen(svname);
1527 strcpy(newNotify->
relname, svname);
1530 newNotify->
be_pid = be_pid;
1531 newNotify->
next = NULL;
1578 for (
i = 0;
i < nfields;
i++)
1612 switch (xact_status)
1662 if (avail < msgLength - 4)
1776 *buffer = (
char *)
malloc(msgLength + 1);
1777 if (*buffer == NULL)
1783 (*buffer)[msgLength] =
'\0';
1835 if (s[status - 1] ==
'\n')
1837 s[status - 1] =
'\0';
2002 int *result_buf,
int *actual_result_len,
2006 bool needInput =
false;
2028 for (
i = 0;
i < nargs; ++
i)
2096 if (avail < msgLength)
2127 if (*actual_result_len != -1)
2237 startpacket = (
char *)
malloc(*packetlen);
2272 #define ADD_STARTUP_OPTION(optname, optval) \
2275 strcpy(packet + packet_len, optname); \
2276 packet_len += strlen(optname) + 1; \
2278 strcpy(packet + packet_len, optval); \
2279 packet_len += strlen(optval) + 1; \
2304 if ((
val = getenv(next_eo->
envName)) != NULL)
2313 packet[packet_len] =
'\0';
#define Assert(condition)
#define MemSet(start, val, len)
static void PGresult * res
int errmsg(const char *fmt,...)
void pqDropConnection(PGconn *conn, bool flushInput)
void pqSaveMessageField(PGresult *res, char code, const char *value)
void pqCommandQueueAdvance(PGconn *conn, bool isReadyForQuery, bool gotSync)
void pqSetResultError(PGresult *res, PQExpBuffer errorMessage, int offset)
void pqSaveErrorResult(PGconn *conn)
char * pqResultStrdup(PGresult *res, const char *str)
int pqRowProcessor(PGconn *conn, const char **errmsgp)
int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize)
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
void pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
void pqClearAsyncResult(PGconn *conn)
int PQisBusy(PGconn *conn)
void * pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary)
char * PQresultErrorField(const PGresult *res, int fieldcode)
PGresult * PQgetResult(PGconn *conn)
PGresult * pqPrepareAsyncResult(PGconn *conn)
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 pqGetnchar(char *s, size_t len, PGconn *conn)
int pqWait(int forRead, int forWrite, PGconn *conn)
int pqGets(PQExpBuffer buf, PGconn *conn)
int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)
int pqPutnchar(const char *s, size_t len, PGconn *conn)
int PQmblenBounded(const char *s, int encoding)
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
int pqPutMsgEnd(PGconn *conn)
void pqBuildErrorMessage3(PQExpBuffer msg, const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)
void pqParseInput3(PGconn *conn)
static int build_startup_packet(const PGconn *conn, char *packet, const PQEnvironmentOption *options)
int pqEndcopy3(PGconn *conn)
static int getNotify(PGconn *conn)
PGresult * pqFunctionCall3(PGconn *conn, Oid fnid, int *result_buf, int *actual_result_len, int result_is_int, const PQArgBlock *args, int nargs)
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)
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)
#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 getCopyDataMessage(PGconn *conn)
static int getParamDescriptions(PGconn *conn, int msgLength)
int pqGetline3(PGconn *conn, char *s, int maxlen)
int pqGetErrorNotice3(PGconn *conn, bool isError)
char * pqBuildStartupPacket3(PGconn *conn, int *packetlen, const PQEnvironmentOption *options)
#define libpq_ngettext(s, p, n)
#define pqIsnonblocking(conn)
#define pgHavePendingResult(conn)
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_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_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
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)