*/
if (list_length(fdw_private) > FdwScanPrivateRelations)
{
- StringInfo relations;
+ StringInfoData relations;
char *rawrelations;
char *ptr;
int minrti,
rtoffset = bms_next_member(plan->fs_base_relids, -1) - minrti;
/* Now we can translate the string */
- relations = makeStringInfo();
+ initStringInfo(&relations);
ptr = rawrelations;
while (*ptr)
{
char *namespace;
namespace = get_namespace_name_or_temp(get_rel_namespace(rte->relid));
- appendStringInfo(relations, "%s.%s",
+ appendStringInfo(&relations, "%s.%s",
quote_identifier(namespace),
quote_identifier(relname));
}
else
- appendStringInfoString(relations,
+ appendStringInfoString(&relations,
quote_identifier(relname));
refname = (char *) list_nth(es->rtable_names, rti - 1);
if (refname == NULL)
refname = rte->eref->aliasname;
if (strcmp(refname, relname) != 0)
- appendStringInfo(relations, " %s",
+ appendStringInfo(&relations, " %s",
quote_identifier(refname));
}
else
- appendStringInfoChar(relations, *ptr++);
+ appendStringInfoChar(&relations, *ptr++);
}
- ExplainPropertyText("Relations", relations->data, es);
+ ExplainPropertyText("Relations", relations.data, es);
}
/*
TupleDesc tupdesc;
char *channel;
char operation;
- StringInfo payload = makeStringInfo();
+ StringInfoData payload;
bool foundPK;
List *indexoidlist;
ListCell *indexoidscan;
+ initStringInfo(&payload);
/* make sure it's called as a trigger */
if (!CALLED_AS_TRIGGER(fcinfo))
ereport(ERROR,
foundPK = true;
- strcpy_quoted(payload, RelationGetRelationName(rel), '"');
- appendStringInfoCharMacro(payload, ',');
- appendStringInfoCharMacro(payload, operation);
+ strcpy_quoted(&payload, RelationGetRelationName(rel), '"');
+ appendStringInfoCharMacro(&payload, ',');
+ appendStringInfoCharMacro(&payload, operation);
for (i = 0; i < indnkeyatts; i++)
{
int colno = index->indkey.values[i];
Form_pg_attribute attr = TupleDescAttr(tupdesc, colno - 1);
- appendStringInfoCharMacro(payload, ',');
- strcpy_quoted(payload, NameStr(attr->attname), '"');
- appendStringInfoCharMacro(payload, '=');
- strcpy_quoted(payload, SPI_getvalue(trigtuple, tupdesc, colno), '\'');
+ appendStringInfoCharMacro(&payload, ',');
+ strcpy_quoted(&payload, NameStr(attr->attname), '"');
+ appendStringInfoCharMacro(&payload, '=');
+ strcpy_quoted(&payload, SPI_getvalue(trigtuple, tupdesc, colno), '\'');
}
- Async_Notify(channel, payload->data);
+ Async_Notify(channel, payload.data);
}
ReleaseSysCache(indexTuple);
break;
char startstrbuf[128];
char startxlogfile[MAXFNAMELEN]; /* backup start WAL file */
XLogSegNo startsegno;
- StringInfo result = makeStringInfo();
- char *data;
+ StringInfoData result;
Assert(state != NULL);
+ initStringInfo(&result);
+
/* Use the log timezone here, not the session timezone */
pg_strftime(startstrbuf, sizeof(startstrbuf), "%Y-%m-%d %H:%M:%S %Z",
pg_localtime(&state->starttime, log_timezone));
XLByteToSeg(state->startpoint, startsegno, wal_segment_size);
XLogFileName(startxlogfile, state->starttli, startsegno, wal_segment_size);
- appendStringInfo(result, "START WAL LOCATION: %X/%08X (file %s)\n",
+ appendStringInfo(&result, "START WAL LOCATION: %X/%08X (file %s)\n",
LSN_FORMAT_ARGS(state->startpoint), startxlogfile);
if (ishistoryfile)
XLByteToSeg(state->stoppoint, stopsegno, wal_segment_size);
XLogFileName(stopxlogfile, state->stoptli, stopsegno, wal_segment_size);
- appendStringInfo(result, "STOP WAL LOCATION: %X/%08X (file %s)\n",
+ appendStringInfo(&result, "STOP WAL LOCATION: %X/%08X (file %s)\n",
LSN_FORMAT_ARGS(state->stoppoint), stopxlogfile);
}
- appendStringInfo(result, "CHECKPOINT LOCATION: %X/%08X\n",
+ appendStringInfo(&result, "CHECKPOINT LOCATION: %X/%08X\n",
LSN_FORMAT_ARGS(state->checkpointloc));
- appendStringInfoString(result, "BACKUP METHOD: streamed\n");
- appendStringInfo(result, "BACKUP FROM: %s\n",
+ appendStringInfoString(&result, "BACKUP METHOD: streamed\n");
+ appendStringInfo(&result, "BACKUP FROM: %s\n",
state->started_in_recovery ? "standby" : "primary");
- appendStringInfo(result, "START TIME: %s\n", startstrbuf);
- appendStringInfo(result, "LABEL: %s\n", state->name);
- appendStringInfo(result, "START TIMELINE: %u\n", state->starttli);
+ appendStringInfo(&result, "START TIME: %s\n", startstrbuf);
+ appendStringInfo(&result, "LABEL: %s\n", state->name);
+ appendStringInfo(&result, "START TIMELINE: %u\n", state->starttli);
if (ishistoryfile)
{
pg_strftime(stopstrfbuf, sizeof(stopstrfbuf), "%Y-%m-%d %H:%M:%S %Z",
pg_localtime(&state->stoptime, log_timezone));
- appendStringInfo(result, "STOP TIME: %s\n", stopstrfbuf);
- appendStringInfo(result, "STOP TIMELINE: %u\n", state->stoptli);
+ appendStringInfo(&result, "STOP TIME: %s\n", stopstrfbuf);
+ appendStringInfo(&result, "STOP TIMELINE: %u\n", state->stoptli);
}
/* either both istartpoint and istarttli should be set, or neither */
Assert(XLogRecPtrIsInvalid(state->istartpoint) == (state->istarttli == 0));
if (!XLogRecPtrIsInvalid(state->istartpoint))
{
- appendStringInfo(result, "INCREMENTAL FROM LSN: %X/%08X\n",
+ appendStringInfo(&result, "INCREMENTAL FROM LSN: %X/%08X\n",
LSN_FORMAT_ARGS(state->istartpoint));
- appendStringInfo(result, "INCREMENTAL FROM TLI: %u\n",
+ appendStringInfo(&result, "INCREMENTAL FROM TLI: %u\n",
state->istarttli);
}
- data = result->data;
- pfree(result);
-
- return data;
+ return result.data;
}
TimeLineID endtli;
backup_manifest_info manifest;
BackupState *backup_state;
- StringInfo tablespace_map;
+ StringInfoData tablespace_map;
/* Initial backup state, insofar as we know it now. */
state.tablespaces = NIL;
/* Allocate backup related variables. */
backup_state = (BackupState *) palloc0(sizeof(BackupState));
- tablespace_map = makeStringInfo();
+ initStringInfo(&tablespace_map);
basebackup_progress_wait_checkpoint();
do_pg_backup_start(opt->label, opt->fastcheckpoint, &state.tablespaces,
- backup_state, tablespace_map);
+ backup_state, &tablespace_map);
state.startptr = backup_state->startpoint;
state.starttli = backup_state->starttli;
if (opt->sendtblspcmapfile)
{
sendFileWithContent(sink, TABLESPACE_MAP,
- tablespace_map->data, -1, &manifest);
+ tablespace_map.data, -1, &manifest);
sendtblspclinks = false;
}
endtli = backup_state->stoptli;
/* Deallocate backup-related variables. */
- destroyStringInfo(tablespace_map);
+ pfree(tablespace_map.data);
pfree(backup_state);
}
PG_END_ENSURE_ERROR_CLEANUP(do_pg_abort_backup, BoolGetDatum(false));
check_publications(WalReceiverConn *wrconn, List *publications)
{
WalRcvExecResult *res;
- StringInfo cmd;
+ StringInfoData cmd;
TupleTableSlot *slot;
List *publicationsCopy = NIL;
Oid tableRow[1] = {TEXTOID};
- cmd = makeStringInfo();
- appendStringInfoString(cmd, "SELECT t.pubname FROM\n"
+ initStringInfo(&cmd);
+ appendStringInfoString(&cmd, "SELECT t.pubname FROM\n"
" pg_catalog.pg_publication t WHERE\n"
" t.pubname IN (");
- GetPublicationsStr(publications, cmd, true);
- appendStringInfoChar(cmd, ')');
+ GetPublicationsStr(publications, &cmd, true);
+ appendStringInfoChar(&cmd, ')');
- res = walrcv_exec(wrconn, cmd->data, 1, tableRow);
- destroyStringInfo(cmd);
+ res = walrcv_exec(wrconn, cmd.data, 1, tableRow);
+ pfree(cmd.data);
if (res->status != WALRCV_OK_TUPLES)
ereport(ERROR,
if (list_length(publicationsCopy))
{
/* Prepare the list of non-existent publication(s) for error message. */
- StringInfo pubnames = makeStringInfo();
+ StringInfoData pubnames;
+
+ initStringInfo(&pubnames);
- GetPublicationsStr(publicationsCopy, pubnames, false);
+ GetPublicationsStr(publicationsCopy, &pubnames, false);
ereport(WARNING,
errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg_plural("publication %s does not exist on the publisher",
"publications %s do not exist on the publisher",
list_length(publicationsCopy),
- pubnames->data));
+ pubnames.data));
}
}
int server_version = walrcv_server_version(wrconn);
bool check_columnlist = (server_version >= 150000);
int column_count = check_columnlist ? 4 : 3;
- StringInfo pub_names = makeStringInfo();
+ StringInfoData pub_names;
initStringInfo(&cmd);
+ initStringInfo(&pub_names);
/* Build the pub_names comma-separated string. */
- GetPublicationsStr(publications, pub_names, true);
+ GetPublicationsStr(publications, &pub_names, true);
/* Get the list of relations from the publisher */
if (server_version >= 160000)
" FROM pg_publication\n"
" WHERE pubname IN ( %s )) AS gpt\n"
" ON gpt.relid = c.oid\n",
- pub_names->data);
+ pub_names.data);
/* From version 19, inclusion of sequences in the target is supported */
if (server_version >= 190000)
" SELECT DISTINCT s.schemaname, s.sequencename, " CppAsString2(RELKIND_SEQUENCE) "::\"char\" AS relkind, NULL::int2vector AS attrs\n"
" FROM pg_catalog.pg_publication_sequences s\n"
" WHERE s.pubname IN ( %s )",
- pub_names->data);
+ pub_names.data);
}
else
{
appendStringInfo(&cmd, "FROM pg_catalog.pg_publication_tables t\n"
" WHERE t.pubname IN ( %s )",
- pub_names->data);
+ pub_names.data);
}
- destroyStringInfo(pub_names);
+ pfree(pub_names.data);
res = walrcv_exec(wrconn, cmd.data, column_count, tableRow);
pfree(cmd.data);
array_to_json(PG_FUNCTION_ARGS)
{
Datum array = PG_GETARG_DATUM(0);
- StringInfo result;
+ StringInfoData result;
- result = makeStringInfo();
+ initStringInfo(&result);
- array_to_json_internal(array, result, false);
+ array_to_json_internal(array, &result, false);
- PG_RETURN_TEXT_P(cstring_to_text_with_len(result->data, result->len));
+ PG_RETURN_TEXT_P(cstring_to_text_with_len(result.data, result.len));
}
/*
{
Datum array = PG_GETARG_DATUM(0);
bool use_line_feeds = PG_GETARG_BOOL(1);
- StringInfo result;
+ StringInfoData result;
- result = makeStringInfo();
+ initStringInfo(&result);
- array_to_json_internal(array, result, use_line_feeds);
+ array_to_json_internal(array, &result, use_line_feeds);
- PG_RETURN_TEXT_P(cstring_to_text_with_len(result->data, result->len));
+ PG_RETURN_TEXT_P(cstring_to_text_with_len(result.data, result.len));
}
/*
row_to_json(PG_FUNCTION_ARGS)
{
Datum array = PG_GETARG_DATUM(0);
- StringInfo result;
+ StringInfoData result;
- result = makeStringInfo();
+ initStringInfo(&result);
- composite_to_json(array, result, false);
+ composite_to_json(array, &result, false);
- PG_RETURN_TEXT_P(cstring_to_text_with_len(result->data, result->len));
+ PG_RETURN_TEXT_P(cstring_to_text_with_len(result.data, result.len));
}
/*
{
Datum array = PG_GETARG_DATUM(0);
bool use_line_feeds = PG_GETARG_BOOL(1);
- StringInfo result;
+ StringInfoData result;
- result = makeStringInfo();
+ initStringInfo(&result);
- composite_to_json(array, result, use_line_feeds);
+ composite_to_json(array, &result, use_line_feeds);
- PG_RETURN_TEXT_P(cstring_to_text_with_len(result->data, result->len));
+ PG_RETURN_TEXT_P(cstring_to_text_with_len(result.data, result.len));
}
/*
Datum
datum_to_json(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
{
- StringInfo result = makeStringInfo();
+ StringInfoData result;
- datum_to_json_internal(val, false, result, tcategory, outfuncoid,
+ initStringInfo(&result);
+ datum_to_json_internal(val, false, &result, tcategory, outfuncoid,
false);
- return PointerGetDatum(cstring_to_text_with_len(result->data, result->len));
+ return PointerGetDatum(cstring_to_text_with_len(result.data, result.len));
}
/*
{
int i;
const char *sep = "";
- StringInfo result;
+ StringInfoData result;
- result = makeStringInfo();
+ initStringInfo(&result);
- appendStringInfoChar(result, '[');
+ appendStringInfoChar(&result, '[');
for (i = 0; i < nargs; i++)
{
if (absent_on_null && nulls[i])
continue;
- appendStringInfoString(result, sep);
+ appendStringInfoString(&result, sep);
sep = ", ";
- add_json(args[i], nulls[i], result, types[i], false);
+ add_json(args[i], nulls[i], &result, types[i], false);
}
- appendStringInfoChar(result, ']');
+ appendStringInfoChar(&result, ']');
- return PointerGetDatum(cstring_to_text_with_len(result->data, result->len));
+ return PointerGetDatum(cstring_to_text_with_len(result.data, result.len));
}
/*
{
Jsonb *jb = PG_GETARG_JSONB_P(0);
StringInfoData buf;
- StringInfo jtext = makeStringInfo();
+ StringInfoData jtext;
int version = 1;
- (void) JsonbToCString(jtext, &jb->root, VARSIZE(jb));
+ initStringInfo(&jtext);
+ (void) JsonbToCString(&jtext, &jb->root, VARSIZE(jb));
pq_begintypsend(&buf);
pq_sendint8(&buf, version);
- pq_sendtext(&buf, jtext->data, jtext->len);
- destroyStringInfo(jtext);
+ pq_sendtext(&buf, jtext.data, jtext.len);
+ pfree(jtext.data);
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
text *json = PG_GETARG_TEXT_PP(0);
bool strip_in_arrays = PG_NARGS() == 2 ? PG_GETARG_BOOL(1) : false;
StripnullState *state;
+ StringInfoData strbuf;
JsonLexContext lex;
JsonSemAction *sem;
state = palloc0(sizeof(StripnullState));
sem = palloc0(sizeof(JsonSemAction));
+ initStringInfo(&strbuf);
state->lex = makeJsonLexContext(&lex, json, true);
- state->strval = makeStringInfo();
+ state->strval = &strbuf;
state->skip_next_null = false;
state->strip_in_arrays = strip_in_arrays;
jsonb_pretty(PG_FUNCTION_ARGS)
{
Jsonb *jb = PG_GETARG_JSONB_P(0);
- StringInfo str = makeStringInfo();
+ StringInfoData str;
- JsonbToCStringIndent(str, &jb->root, VARSIZE(jb));
+ initStringInfo(&str);
+ JsonbToCStringIndent(&str, &jb->root, VARSIZE(jb));
- PG_RETURN_TEXT_P(cstring_to_text_with_len(str->data, str->len));
+ PG_RETURN_TEXT_P(cstring_to_text_with_len(str.data, str.len));
}
/*
* Iterate over a json, and apply a specified JsonTransformStringValuesAction
* to every string value or element. Any necessary context for a
* JsonTransformStringValuesAction can be passed in the action_state variable.
- * Function returns a StringInfo, which is a copy of an original json with
+ * Function returns a Text Datum, which is a copy of an original json with
* transformed values.
*/
text *
JsonLexContext lex;
JsonSemAction *sem = palloc0(sizeof(JsonSemAction));
TransformJsonStringValuesState *state = palloc0(sizeof(TransformJsonStringValuesState));
+ StringInfoData strbuf;
+
+ initStringInfo(&strbuf);
state->lex = makeJsonLexContext(&lex, json, true);
- state->strval = makeStringInfo();
+ state->strval = &strbuf;
state->action = transform_action;
state->action_state = action_state;
{
MultirangeType *multirange = PG_GETARG_MULTIRANGE_P(0);
Oid mltrngtypoid = MultirangeTypeGetOid(multirange);
- StringInfo buf = makeStringInfo();
+ StringInfoData buf;
RangeType **ranges;
int32 range_count;
MultirangeIOData *cache;
+ initStringInfo(&buf);
cache = get_multirange_io_data(fcinfo, mltrngtypoid, IOFunc_send);
/* construct output */
- pq_begintypsend(buf);
+ pq_begintypsend(&buf);
- pq_sendint32(buf, multirange->rangeCount);
+ pq_sendint32(&buf, multirange->rangeCount);
multirange_deserialize(cache->typcache->rngtype, multirange, &range_count, &ranges);
for (int i = 0; i < range_count; i++)
range = RangeTypePGetDatum(ranges[i]);
outputbytes = SendFunctionCall(&cache->typioproc, range);
- pq_sendint32(buf, VARSIZE(outputbytes) - VARHDRSZ);
- pq_sendbytes(buf, VARDATA(outputbytes), VARSIZE(outputbytes) - VARHDRSZ);
+ pq_sendint32(&buf, VARSIZE(outputbytes) - VARHDRSZ);
+ pq_sendbytes(&buf, VARDATA(outputbytes), VARSIZE(outputbytes) - VARHDRSZ);
}
- PG_RETURN_BYTEA_P(pq_endtypsend(buf));
+ PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
/*
range_send(PG_FUNCTION_ARGS)
{
RangeType *range = PG_GETARG_RANGE_P(0);
- StringInfo buf = makeStringInfo();
+ StringInfoData buf;
RangeIOData *cache;
char flags;
RangeBound lower;
check_stack_depth(); /* recurses when subtype is a range type */
+ initStringInfo(&buf);
+
cache = get_range_io_data(fcinfo, RangeTypeGetOid(range), IOFunc_send);
/* deserialize */
flags = range_get_flags(range);
/* construct output */
- pq_begintypsend(buf);
+ pq_begintypsend(&buf);
- pq_sendbyte(buf, flags);
+ pq_sendbyte(&buf, flags);
if (RANGE_HAS_LBOUND(flags))
{
uint32 bound_len = VARSIZE(bound) - VARHDRSZ;
char *bound_data = VARDATA(bound);
- pq_sendint32(buf, bound_len);
- pq_sendbytes(buf, bound_data, bound_len);
+ pq_sendint32(&buf, bound_len);
+ pq_sendbytes(&buf, bound_data, bound_len);
}
if (RANGE_HAS_UBOUND(flags))
uint32 bound_len = VARSIZE(bound) - VARHDRSZ;
char *bound_data = VARDATA(bound);
- pq_sendint32(buf, bound_len);
- pq_sendbytes(buf, bound_data, bound_len);
+ pq_sendint32(&buf, bound_len);
+ pq_sendbytes(&buf, bound_data, bound_len);
}
- PG_RETURN_BYTEA_P(pq_endtypsend(buf));
+ PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
/*
get_range_partbound_string(List *bound_datums)
{
deparse_context context;
- StringInfo buf = makeStringInfo();
+ StringInfoData buf;
ListCell *cell;
char *sep;
+ initStringInfo(&buf);
memset(&context, 0, sizeof(deparse_context));
- context.buf = buf;
+ context.buf = &buf;
- appendStringInfoChar(buf, '(');
+ appendStringInfoChar(&buf, '(');
sep = "";
foreach(cell, bound_datums)
{
PartitionRangeDatum *datum =
lfirst_node(PartitionRangeDatum, cell);
- appendStringInfoString(buf, sep);
+ appendStringInfoString(&buf, sep);
if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
- appendStringInfoString(buf, "MINVALUE");
+ appendStringInfoString(&buf, "MINVALUE");
else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
- appendStringInfoString(buf, "MAXVALUE");
+ appendStringInfoString(&buf, "MAXVALUE");
else
{
Const *val = castNode(Const, datum->value);
}
sep = ", ";
}
- appendStringInfoChar(buf, ')');
+ appendStringInfoChar(&buf, ')');
- return buf->data;
+ return buf.data;
}
node->type == XML_ELEMENT_NODE) ? node->name : NULL;
int domain = error->domain;
int level = error->level;
- StringInfo errorBuf;
+ StringInfoData errorBuf;
/*
* Defend against someone passing us a bogus context struct.
}
/* Prepare error message in errorBuf */
- errorBuf = makeStringInfo();
+ initStringInfo(&errorBuf);
if (error->line > 0)
- appendStringInfo(errorBuf, "line %d: ", error->line);
+ appendStringInfo(&errorBuf, "line %d: ", error->line);
if (name != NULL)
- appendStringInfo(errorBuf, "element %s: ", name);
+ appendStringInfo(&errorBuf, "element %s: ", name);
if (error->message != NULL)
- appendStringInfoString(errorBuf, error->message);
+ appendStringInfoString(&errorBuf, error->message);
else
- appendStringInfoString(errorBuf, "(no message provided)");
+ appendStringInfoString(&errorBuf, "(no message provided)");
/*
* Append context information to errorBuf.
xmlGenericErrorFunc errFuncSaved = xmlGenericError;
void *errCtxSaved = xmlGenericErrorContext;
- xmlSetGenericErrorFunc(errorBuf,
+ xmlSetGenericErrorFunc(&errorBuf,
(xmlGenericErrorFunc) appendStringInfo);
/* Add context information to errorBuf */
- appendStringInfoLineSeparator(errorBuf);
+ appendStringInfoLineSeparator(&errorBuf);
xmlParserPrintFileContext(input);
}
/* Get rid of any trailing newlines in errorBuf */
- chopStringInfoNewlines(errorBuf);
+ chopStringInfoNewlines(&errorBuf);
/*
* Legacy error handling mode. err_occurred is never set, we just add the
if (xmlerrcxt->strictness == PG_XML_STRICTNESS_LEGACY)
{
appendStringInfoLineSeparator(&xmlerrcxt->err_buf);
- appendBinaryStringInfo(&xmlerrcxt->err_buf, errorBuf->data,
- errorBuf->len);
+ appendBinaryStringInfo(&xmlerrcxt->err_buf, errorBuf.data,
+ errorBuf.len);
- destroyStringInfo(errorBuf);
+ pfree(errorBuf.data);
return;
}
if (level >= XML_ERR_ERROR)
{
appendStringInfoLineSeparator(&xmlerrcxt->err_buf);
- appendBinaryStringInfo(&xmlerrcxt->err_buf, errorBuf->data,
- errorBuf->len);
+ appendBinaryStringInfo(&xmlerrcxt->err_buf, errorBuf.data,
+ errorBuf.len);
xmlerrcxt->err_occurred = true;
}
else if (level >= XML_ERR_WARNING)
{
ereport(WARNING,
- (errmsg_internal("%s", errorBuf->data)));
+ (errmsg_internal("%s", errorBuf.data)));
}
else
{
ereport(NOTICE,
- (errmsg_internal("%s", errorBuf->data)));
+ (errmsg_internal("%s", errorBuf.data)));
}
- destroyStringInfo(errorBuf);
+ pfree(errorBuf.data);
}