24 #ifdef HAVE_NETINET_TCP_H 25 #include <netinet/tcp.h> 87 libpq_gettext(
"invalid setenv state %c, probably indicative of memory corruption\n"),
111 sprintf(setQuery,
"SET client_encoding = DEFAULT");
113 sprintf(setQuery,
"SET client_encoding = '%.60s'",
117 "Sending client_encoding with %s\n",
148 sprintf(setQuery,
"SET %s = DEFAULT",
151 sprintf(setQuery,
"SET %s = '%.60s'",
155 "Use environment variable %s to send %s\n",
237 if (!
PQsendQuery(conn,
"begin; select version(); end"))
274 if (val && strncmp(val,
"PostgreSQL ", 11) == 0)
285 ptr = strchr(val,
' ');
317 query =
"begin; select pg_catalog.pg_client_encoding(); end";
319 query =
"select pg_client_encoding()";
361 val = getenv(
"PGCLIENTENCODING");
385 "probably indicative of memory corruption\n"),
473 "message type 0x%02x arrived from server while idle",
523 "unexpected character %c following empty query response (\"I\" message)",
589 "server sent data (\"D\" message) without prior row description (\"T\" message)");
607 "server sent binary data (\"B\" message) without prior row description (\"T\" message)");
626 libpq_gettext(
"unexpected response from server; first received character was \"%c\"\n"),
663 goto advance_and_error;
680 goto advance_and_error;
686 for (i = 0; i < nfields; i++)
702 typlen = (int) ((
int16) typlen);
709 goto advance_and_error;
767 if (result && result != conn->
result)
792 char *bitmap = std_bitmap;
809 goto advance_and_error;
824 for (i = 0; i < nfields; i++)
831 if (nbytes >
sizeof(std_bitmap))
833 bitmap = (
char *)
malloc(nbytes);
837 goto advance_and_error;
846 bmap = bitmap[bitmap_index];
849 for (i = 0; i < nfields; i++)
863 rowbuf[
i].
len = vlen;
884 bmap = bitmap[bitmap_index];
892 if (bitmap != std_bitmap)
904 goto set_error_result;
942 if (bitmap != NULL && bitmap != std_bitmap)
977 if (
pqGets(&workBuf, conn))
1004 while (workBuf.
len > 0 && workBuf.
data[workBuf.
len - 1] ==
'\n')
1005 workBuf.
data[--workBuf.
len] =
'\0';
1006 splitp = strstr(workBuf.
data,
": ");
1012 startp = splitp + 3;
1017 startp = workBuf.
data;
1019 splitp = strchr(startp,
'\n');
1026 while (*splitp && isspace((
unsigned char) *splitp))
1088 if (strcmp(cmdTag,
"BEGIN") == 0)
1090 else if (strcmp(cmdTag,
"COMMIT") == 0)
1092 else if (strcmp(cmdTag,
"ROLLBACK") == 0)
1094 else if (strcmp(cmdTag,
"START TRANSACTION") == 0)
1102 else if (strcmp(cmdTag,
"*ABORT STATE*") == 0)
1138 newNotify->
be_pid = be_pid;
1139 newNotify->
next = NULL;
1191 if (msgLength == 3 &&
1202 *buffer = (
char *)
malloc(msgLength + 1);
1203 if (*buffer == NULL)
1210 (*buffer)[msgLength] =
'\0';
1222 if (
pqWait(
true,
false, conn) ||
1267 if (
pqWait(
true,
false, conn) ||
1315 if (bufsize - avail == 3 && buffer[-3] ==
'\\' && buffer[-2] ==
'.')
1318 return bufsize - avail;
1330 if (avail == 0 && bufsize > 3)
1406 "lost synchronization with server, resetting connection");
1429 int *result_buf,
int *actual_result_len,
1433 bool needInput =
false;
1449 for (i = 0; i < nargs; ++
i)
1451 if (
pqPutInt(args[i].len, 4, conn))
1475 if (
pqWait(
true,
false, conn) ||
1502 if (
pqGetInt(actual_result_len, 4, conn))
1609 return (
char *) startpacket;
int pqFlush(PGconn *conn)
int pqRowProcessor(PGconn *conn, const char **errmsgp)
static void checkXactStatus(PGconn *conn, const char *cmdTag)
int PQresetStart(PGconn *conn)
void pqParseInput2(PGconn *conn)
#define PG_DIAG_MESSAGE_PRIMARY
PGresult * pqFunctionCall2(PGconn *conn, Oid fnid, int *result_buf, int *actual_result_len, int result_is_int, const PQArgBlock *args, int nargs)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
static int getRowDescriptions(PGconn *conn)
#define PG_DIAG_MESSAGE_DETAIL
void pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
int pqGets(PQExpBuffer buf, PGconn *conn)
void termPQExpBuffer(PQExpBuffer str)
#define pqIsnonblocking(conn)
char * pqBuildStartupPacket2(PGconn *conn, int *packetlen, const PQEnvironmentOption *options)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
PQExpBufferData workBuffer
int pqPutMsgStart(char msg_type, bool force_len, PGconn *conn)
struct StartupPacket StartupPacket
#define MemSet(start, val, len)
int pqGetlineAsync2(PGconn *conn, char *buffer, int bufsize)
int pqGetInt(int *result, size_t bytes, PGconn *conn)
int pg_strcasecmp(const char *s1, const char *s2)
int pqGetnchar(char *s, size_t len, PGconn *conn)
int PQntuples(const PGresult *res)
PGresult * pqPrepareAsyncResult(PGconn *conn)
ExecStatusType PQresultStatus(const PGresult *res)
PostgresPollingStatusType pqSetenvPoll(PGconn *conn)
char * client_encoding_initial
int pqPutInt(int value, size_t bytes, PGconn *conn)
int PQsendQuery(PGconn *conn, const char *query)
PGAsyncStatusType asyncStatus
PGSetenvStatusType setenv_state
PGNoticeHooks noticeHooks
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
PGNoticeHooks noticeHooks
int pqReadData(PGconn *conn)
const PQEnvironmentOption * next_eo
int pqWait(int forRead, int forWrite, PGconn *conn)
PQnoticeReceiver noticeRec
static int getAnotherTuple(PGconn *conn, bool binary)
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
int pqPuts(const char *s, PGconn *conn)
int pqGetc(char *result, PGconn *conn)
void pqSaveMessageField(PGresult *res, char code, const char *value)
static int getNotify(PGconn *conn)
char database[SM_DATABASE]
PQExpBufferData errorMessage
void PQclear(PGresult *res)
size_t strlcpy(char *dst, const char *src, size_t siz)
#define PQExpBufferDataBroken(buf)
void * pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary)
int pqPutnchar(const char *s, size_t len, PGconn *conn)
int PQisBusy(PGconn *conn)
int pqGetline2(PGconn *conn, char *s, int maxlen)
char cmdStatus[CMDSTATUS_LEN]
int pqPutMsgEnd(PGconn *conn)
PostgresPollingStatusType
int errmsg(const char *fmt,...)
ProtocolVersion protoVersion
int pqSkipnchar(size_t len, PGconn *conn)
void pqClearAsyncResult(PGconn *conn)
void pqSaveErrorResult(PGconn *conn)
int pqGetCopyData2(PGconn *conn, char **buffer, int async)
static void static void status(const char *fmt,...) pg_attribute_printf(1
ExecStatusType resultStatus
PGresult * PQgetResult(PGconn *conn)
int pqEndcopy2(PGconn *conn)
void initPQExpBuffer(PQExpBuffer str)
void PQreset(PGconn *conn)
PGTransactionStatusType xactStatus
char * pqResultStrdup(PGresult *res, const char *str)
static int pqGetErrorNotice2(PGconn *conn, bool isError)