39 "PGRES_NONFATAL_ERROR",
43 "PGRES_PIPELINE_SYNC",
44 "PGRES_PIPELINE_ABORTED"
51 .errMsg =
"out of memory\n",
64 const char **errmsgp);
71 const Oid *paramTypes,
72 const char *
const *paramValues,
73 const int *paramLengths,
74 const int *paramFormats,
141 #define PGRESULT_DATA_BLOCKSIZE 2048
142 #define PGRESULT_ALIGN_BOUNDARY MAXIMUM_ALIGNOF
143 #define PGRESULT_BLOCK_OVERHEAD Max(sizeof(PGresult_data), PGRESULT_ALIGN_BOUNDARY)
144 #define PGRESULT_SEP_ALLOC_THRESHOLD (PGRESULT_DATA_BLOCKSIZE / 2)
260 if (numAttributes <= 0 || !attDescs)
348 for (tup = 0; tup < src->
ntups; tup++)
381 for (
i = 0;
i <
dest->nEvents;
i++)
391 dest->events[
i].passThrough))
392 dest->events[
i].resultInitialized =
true;
412 if (!events || count <= 0)
415 msize = count *
sizeof(
PGEvent);
420 for (
i = 0;
i < count;
i++)
424 newEvents[
i].
data = NULL;
427 if (!newEvents[
i].
name)
434 msize += strlen(events[
i].
name) + 1;
453 const char *
errmsg = NULL;
464 if (tup_num < 0 || tup_num >
res->
ntups)
467 "row number %d is out of range 0..%d",
497 attval = &
res->
tuples[tup_num][field_num];
949 msgBuf[
sizeof(msgBuf) - 1] =
'\0';
1019 *errmsgp =
libpq_gettext(
"PGresult cannot support more than INT_MAX tuples");
1028 #if INT_MAX >= (SIZE_MAX / 2)
1069 pfield->
code = code;
1089 prev = pstatus, pstatus = pstatus->
next)
1091 if (strcmp(pstatus->
name,
name) == 0)
1112 pstatus->
name = ptr;
1114 ptr += strlen(
name) + 1;
1115 pstatus->
value = ptr;
1128 if (strcmp(
name,
"client_encoding") == 0)
1136 else if (strcmp(
name,
"standard_conforming_strings") == 0)
1141 else if (strcmp(
name,
"server_version") == 0)
1149 cnt = sscanf(
value,
"%d.%d.%d", &vmaj, &vmin, &vrev);
1177 else if (strcmp(
name,
"default_transaction_read_only") == 0)
1182 else if (strcmp(
name,
"in_hot_standby") == 0)
1187 else if (strcmp(
name,
"scram_iterations") == 0)
1246 for (
i = 0;
i < nfields;
i++)
1248 int clen = columns[
i].
len;
1334 entry->
query = NULL;
1406 entry->
query = NULL;
1476 entry->
query = strdup(query);
1502 const char *command,
1504 const Oid *paramTypes,
1505 const char *
const *paramValues,
1506 const int *paramLengths,
1507 const int *paramFormats,
1546 const char *stmtName,
const char *query,
1547 int nParams,
const Oid *paramTypes)
1582 if (nParams > 0 && paramTypes)
1588 for (
i = 0;
i < nParams;
i++)
1615 entry->
query = strdup(query);
1643 const char *stmtName,
1645 const char *
const *paramValues,
1646 const int *paramLengths,
1647 const int *paramFormats,
1765 const char *command,
1766 const char *stmtName,
1768 const Oid *paramTypes,
1769 const char *
const *paramValues,
1770 const int *paramLengths,
1771 const int *paramFormats,
1794 if (nParams > 0 && paramTypes)
1798 for (
i = 0;
i < nParams;
i++)
1820 if (nParams > 0 && paramFormats)
1824 for (
i = 0;
i < nParams;
i++)
1840 for (
i = 0;
i < nParams;
i++)
1842 if (paramValues && paramValues[
i])
1846 if (paramFormats && paramFormats[
i] != 0)
1850 nbytes = paramLengths[
i];
1860 nbytes = strlen(paramValues[
i]);
1907 entry->
query = strdup(command);
2239 const char *command,
2241 const Oid *paramTypes,
2242 const char *
const *paramValues,
2243 const int *paramLengths,
2244 const int *paramFormats,
2250 nParams, paramTypes, paramValues, paramLengths,
2251 paramFormats, resultFormat))
2269 const char *stmtName,
const char *query,
2270 int nParams,
const Oid *paramTypes)
2286 const char *stmtName,
2288 const char *
const *paramValues,
2289 const int *paramLengths,
2290 const int *paramFormats,
2296 nParams, paramValues, paramLengths,
2297 paramFormats, resultFormat))
2392 lastResult = result;
2818 if (!buffer || length <= 0)
2977 result_buf, result_len,
3133 prevquery->
next = NULL;
3274 "internal error: cannot send pipeline while in COPY\n");
3290 entry->
query = NULL;
3303 if (immediate_flush)
3409 return strdup(
libpq_gettext(
"PGresult is not an error result\n"));
3422 return workBuf.
data;
3434 if (pfield->
code == fieldcode)
3477 "column number %d is out of range 0..%d",
3486 int tup_num,
int field_num)
3490 if (tup_num < 0 || tup_num >=
res->
ntups)
3493 "row number %d is out of range 0..%d",
3500 "column number %d is out of range 0..%d",
3515 "parameter number %d is out of range 0..%d",
3553 bool all_lower =
true;
3565 if (field_name == NULL ||
3566 field_name[0] ==
'\0' ||
3574 for (iptr = field_name; *iptr; iptr++)
3597 field_case = strdup(field_name);
3598 if (field_case == NULL)
3603 for (iptr = field_case; *iptr; iptr++)
3731 static char buf[24];
3739 if (
len >
sizeof(
buf) - 1)
3755 char *endptr = NULL;
3756 unsigned long result;
3766 if (!endptr || (*endptr !=
' ' && *endptr !=
'\0'))
3769 return (
Oid) result;
3794 while (*p && *p !=
' ')
3797 goto interpret_error;
3814 for (
c = p; *
c;
c++)
3816 if (!isdigit((
unsigned char) *
c))
3817 goto interpret_error;
3820 goto interpret_error;
3826 "could not interpret result from server: %s",
4032 char *to,
const char *from,
size_t length,
4036 const char *
source = from;
4066 for (
i = 0;
i <
len;
i++)
4088 for (;
i <
len;
i++)
4090 if (((
size_t) (target - to)) / 2 >= length)
4106 char *to,
const char *from,
size_t length,
4148 int num_backslashes = 0;
4151 char quote_char = as_ident ?
'"' :
'\'';
4161 for (s =
str; (s -
str) <
len && *s !=
'\0'; ++s)
4163 if (*s == quote_char)
4165 else if (*s ==
'\\')
4175 if ((s -
str) + charlen >
len || memchr(s, 0, charlen) != NULL)
4187 input_len = s -
str;
4188 result_size = input_len + num_quotes + 3;
4189 if (!as_ident && num_backslashes > 0)
4190 result_size += num_backslashes + 2;
4191 result = rp = (
char *)
malloc(result_size);
4205 if (!as_ident && num_backslashes > 0)
4225 if (num_quotes == 0 && (num_backslashes == 0 || as_ident))
4227 memcpy(rp,
str, input_len);
4232 for (s =
str; s -
str < input_len; ++s)
4234 if (*s == quote_char || (!as_ident && *s ==
'\\'))
4276 static const char hextbl[] =
"0123456789abcdef";
4279 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4280 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4281 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4282 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
4283 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4284 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4285 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4286 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4294 if (
c > 0 &&
c < 127)
4316 static unsigned char *
4318 const unsigned char *from,
size_t from_length,
4319 size_t *to_length,
bool std_strings,
bool use_hex)
4321 const unsigned char *vp;
4323 unsigned char *result;
4326 size_t bslash_len = (std_strings ? 1 : 2);
4335 len += bslash_len + 1 + 2 * from_length;
4340 for (
i = from_length;
i > 0;
i--, vp++)
4342 if (*vp < 0x20 || *vp > 0x7e)
4343 len += bslash_len + 3;
4344 else if (*vp ==
'\'')
4346 else if (*vp ==
'\\')
4347 len += bslash_len + bslash_len;
4354 rp = result = (
unsigned char *)
malloc(
len);
4371 for (
i = from_length;
i > 0;
i--, vp++)
4373 unsigned char c = *vp;
4377 *rp++ =
hextbl[(
c >> 4) & 0xF];
4385 *rp++ = (
c >> 6) +
'0';
4386 *rp++ = ((
c >> 3) & 07) +
'0';
4387 *rp++ = (
c & 07) +
'0';
4414 const unsigned char *from,
size_t from_length,
4437 #define ISFIRSTOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '3')
4438 #define ISOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '7')
4439 #define OCTVAL(CH) ((CH) - '0')
4458 unsigned char *buffer,
4463 if (strtext == NULL)
4466 strtextlen = strlen((
const char *) strtext);
4468 if (strtext[0] ==
'\\' && strtext[1] ==
'x')
4470 const unsigned char *s;
4473 buflen = (strtextlen - 2) / 2;
4475 buffer = (
unsigned char *)
malloc(buflen > 0 ? buflen : 1);
4491 if (!*s || v1 == (
char) -1)
4494 if (v2 != (
char) -1)
4495 *p++ = (v1 << 4) | v2;
4498 buflen = p - buffer;
4506 buffer = (
unsigned char *)
malloc(strtextlen + 1);
4510 for (
i =
j = 0;
i < strtextlen;)
4516 if (strtext[
i] ==
'\\')
4517 buffer[
j++] = strtext[
i++];
4527 byte = (
byte << 3) +
OCTVAL(strtext[
i++]);
4528 byte = (
byte << 3) +
OCTVAL(strtext[
i++]);
4543 buffer[
j++] = strtext[
i++];
4561 *retbuflen = buflen;
#define unconstify(underlying_type, expr)
#define IS_HIGHBIT_SET(ch)
#define SQL_STR_DOUBLE(ch, escape_backslash)
static void PGresult * res
int errmsg(const char *fmt,...)
static char * PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident)
static int PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
unsigned char * PQescapeBytea(const unsigned char *from, size_t from_length, size_t *to_length)
PGresult * PQfn(PGconn *conn, int fnid, int *result_buf, int *result_len, int result_is_int, const PQArgBlock *args, int nargs)
int PQsendQueryParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
int PQsendQueryContinue(PGconn *conn, const char *query)
int PQgetlength(const PGresult *res, int tup_num, int field_num)
int PQsetSingleRowMode(PGconn *conn)
static char get_hex(char c)
int PQbinaryTuples(const PGresult *res)
int PQflush(PGconn *conn)
void PQfreemem(void *ptr)
PGnotify * PQnotifies(PGconn *conn)
PGresult * PQprepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)
int PQgetline(PGconn *conn, char *buffer, int length)
unsigned char * PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
static size_t PQescapeStringInternal(PGconn *conn, char *to, const char *from, size_t length, int *error, int encoding, bool std_strings)
Oid PQftype(const PGresult *res, int field_num)
int PQexitPipelineMode(PGconn *conn)
int PQsendClosePortal(PGconn *conn, const char *portal)
int PQsetResultAttrs(PGresult *res, int numAttributes, PGresAttDesc *attDescs)
void pqSaveMessageField(PGresult *res, char code, const char *value)
char * PQescapeIdentifier(PGconn *conn, const char *str, size_t len)
static unsigned char * PQescapeByteaInternal(PGconn *conn, const unsigned char *from, size_t from_length, size_t *to_length, bool std_strings, bool use_hex)
static int check_tuple_field_number(const PGresult *res, int tup_num, int field_num)
static void pqSaveWriteError(PGconn *conn)
int PQenterPipelineMode(PGconn *conn)
void pqCommandQueueAdvance(PGconn *conn, bool isReadyForQuery, bool gotSync)
void pqSetResultError(PGresult *res, PQExpBuffer errorMessage, int offset)
size_t PQescapeStringConn(PGconn *conn, char *to, const char *from, size_t length, int *error)
void pqSaveErrorResult(PGconn *conn)
char *const pgresStatus[]
char * pqResultStrdup(PGresult *res, const char *str)
#define PGRESULT_DATA_BLOCKSIZE
PGresult * PQexecParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
static int pqPipelineSyncInternal(PGconn *conn, bool immediate_flush)
ExecStatusType PQresultStatus(const PGresult *res)
Oid PQparamtype(const PGresult *res, int param_num)
static int check_param_number(const PGresult *res, int param_num)
int pqRowProcessor(PGconn *conn, const char **errmsgp)
PGresult * PQdescribePrepared(PGconn *conn, const char *stmt)
int PQnparams(const PGresult *res)
void PQclear(PGresult *res)
int PQsendClosePrepared(PGconn *conn, const char *stmt)
char * PQcmdTuples(PGresult *res)
char * PQresultErrorMessage(const PGresult *res)
static PGresult * PQexecFinish(PGconn *conn)
int PQfformat(const PGresult *res, int field_num)
static void pqAppendCmdQueueEntry(PGconn *conn, PGcmdQueueEntry *entry)
static int PQsendQueryGuts(PGconn *conn, const char *command, const char *stmtName, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
PGresult * PQclosePortal(PGconn *conn, const char *portal)
int PQendcopy(PGconn *conn)
static int pqPipelineFlush(PGconn *conn)
int PQputCopyEnd(PGconn *conn, const char *errormsg)
static int PQsendTypedCommand(PGconn *conn, char command, char type, const char *target)
int PQsendPipelineSync(PGconn *conn)
int PQntuples(const PGresult *res)
int PQputnbytes(PGconn *conn, const char *buffer, int nbytes)
int PQputline(PGconn *conn, const char *string)
int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize)
static const PGresult OOM_result
#define PGRESULT_BLOCK_OVERHEAD
int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
PGresult * PQexecPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
static PGcmdQueueEntry * pqAllocCmdQueueEntry(PGconn *conn)
static PGresult * getCopyResult(PGconn *conn, ExecStatusType copytype)
static PGEvent * dupEvents(PGEvent *events, int count, size_t *memSize)
char * PQfname(const PGresult *res, int field_num)
static bool static_std_strings
char * PQescapeLiteral(PGconn *conn, const char *str, size_t len)
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
PGresult * PQdescribePortal(PGconn *conn, const char *portal)
int PQsendDescribePrepared(PGconn *conn, const char *stmt)
PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
PGresult * PQexec(PGconn *conn, const char *query)
unsigned char * PQescapeByteaConn(PGconn *conn, const unsigned char *from, size_t from_length, size_t *to_length)
static const char hextbl[]
static bool PQexecStart(PGconn *conn)
size_t PQescapeString(char *to, const char *from, size_t length)
int PQconsumeInput(PGconn *conn)
#define ISFIRSTOCTDIGIT(CH)
static void parseInput(PGconn *conn)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Oid PQftable(const PGresult *res, int field_num)
int PQfnumber(const PGresult *res, const char *field_name)
char * PQcmdStatus(PGresult *res)
void pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
int PQsetnonblocking(PGconn *conn, int arg)
int PQsendPrepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)
#define PGRESULT_SEP_ALLOC_THRESHOLD
int PQfmod(const PGresult *res, int field_num)
void pqClearAsyncResult(PGconn *conn)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
int PQftablecol(const PGresult *res, int field_num)
static int static_client_encoding
int PQsetvalue(PGresult *res, int tup_num, int field_num, char *value, int len)
int PQsendQuery(PGconn *conn, const char *query)
int PQpipelineSync(PGconn *conn)
char * PQresStatus(ExecStatusType status)
int PQsendDescribePortal(PGconn *conn, const char *portal)
PGresult * PQclosePrepared(PGconn *conn, const char *stmt)
size_t PQresultMemorySize(const PGresult *res)
int PQisBusy(PGconn *conn)
int PQsendQueryPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
static void pqPipelineProcessQueue(PGconn *conn)
int PQsendFlushRequest(PGconn *conn)
void * pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary)
char * PQoidStatus(const PGresult *res)
char * PQresultErrorField(const PGresult *res, int fieldcode)
int PQisnonblocking(const PGconn *conn)
PGresult * PQcopyResult(const PGresult *src, int flags)
void * PQresultAlloc(PGresult *res, size_t nBytes)
Oid PQoidValue(const PGresult *res)
static bool pqAddTuple(PGresult *res, PGresAttValue *tup, const char **errmsgp)
char * PQresultVerboseErrorMessage(const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)
#define PGRESULT_ALIGN_BOUNDARY
int PQnfields(const PGresult *res)
static int check_field_number(const PGresult *res, int field_num)
PGresult * PQgetResult(PGconn *conn)
PGresult * pqPrepareAsyncResult(PGconn *conn)
int PQfsize(const PGresult *res, int field_num)
static bool PQsendQueryStart(PGconn *conn, bool newQuery)
static const int8 hexlookup[128]
int PQgetCopyData(PGconn *conn, char **buffer, int async)
static void pqRecycleCmdQueueEntry(PGconn *conn, PGcmdQueueEntry *entry)
void PQfreeNotify(PGnotify *notify)
int pqPutc(char c, PGconn *conn)
int pqReadData(PGconn *conn)
int pqPutInt(int value, size_t bytes, PGconn *conn)
int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)
int pqFlush(PGconn *conn)
int pqPutMsgStart(char msg_type, PGconn *conn)
int pqWait(int forRead, int forWrite, PGconn *conn)
int pqPutnchar(const char *s, size_t len, PGconn *conn)
int pqPuts(const char *s, PGconn *conn)
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)
int pqEndcopy3(PGconn *conn)
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 pqGetline3(PGconn *conn, char *s, int maxlen)
if(TABLE==NULL||TABLE_index==NULL)
int PQfireResultCreateEvents(PGconn *conn, PGresult *res)
#define PG_COPYRES_TUPLES
struct pg_result PGresult
#define PG_COPYRES_EVENTS
#define PG_COPYRES_NOTICEHOOKS
#define PQ_QUERY_PARAM_MAX_LIMIT
struct pgParameterStatus pgParameterStatus
#define pqClearConnErrorState(conn)
union pgresult_data PGresult_data
#define pqIsnonblocking(conn)
#define OUTBUFFER_THRESHOLD
#define pgHavePendingResult(conn)
static void const char * fmt
Assert(fmt[strlen(fmt) - 1] !='\n')
static rewind_source * source
#define pg_char_to_encoding
unsigned char pg_tolower(unsigned char ch)
#define PG_DIAG_SEVERITY_NONLOCALIZED
#define PG_DIAG_MESSAGE_PRIMARY
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
#define PQExpBufferBroken(str)
#define PQExpBufferDataBroken(buf)
PQnoticeReceiver noticeRec
PQnoticeProcessor noticeProc
struct PGcmdQueueEntry * next
struct pgMessageField * next
char contents[FLEXIBLE_ARRAY_MEMBER]
struct pgParameterStatus * next
PGTernaryBool in_hot_standby
PGcmdQueueEntry * cmd_queue_recycle
PGcmdQueueEntry * cmd_queue_tail
PGTernaryBool default_transaction_read_only
pgParameterStatus * pstatus
PQExpBufferData errorMessage
PGAsyncStatusType asyncStatus
int scram_sha_256_iterations
PGpipelineStatus pipelineStatus
PGNoticeHooks noticeHooks
PGcmdQueueEntry * cmd_queue_head
PGNoticeHooks noticeHooks
char cmdStatus[CMDSTATUS_LEN]
PGMessageField * errFields
PGresParamDesc * paramDescs
ExecStatusType resultStatus
static StringInfoData tmpbuf
int pg_encoding_mblen(int encoding, const char *mbstr)