本文整理汇总了C++中resetStringInfo函数的典型用法代码示例。如果您正苦于以下问题:C++ resetStringInfo函数的具体用法?C++ resetStringInfo怎么用?C++ resetStringInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resetStringInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pgut_errinit
static pgutErrorData *
pgut_errinit(int elevel)
{
int save_errno = errno;
pgutErrorData *edata = getErrorData();
edata->elevel = elevel;
edata->save_errno = save_errno;
edata->ecode = (elevel >= ERROR ? 1 : 0);
if (edata->msg.data)
resetStringInfo(&edata->msg);
else
initStringInfo(&edata->msg);
if (edata->detail.data)
resetStringInfo(&edata->detail);
else
initStringInfo(&edata->detail);
if (edata->hint.data)
resetStringInfo(&edata->hint);
else
initStringInfo(&edata->hint);
return edata;
}
示例2: add_projection_desc_httpheader
static void add_projection_desc_httpheader(CHURL_HEADERS headers, ProjectionInfo *projInfo, List *qualsAttributes) {
int i;
char long_number[sizeof(int32) * 8];
int *varNumbers = projInfo->pi_varNumbers;
StringInfoData formatter;
initStringInfo(&formatter);
/* Convert the number of projection columns to a string */
pg_ltoa(list_length(projInfo->pi_targetlist) + list_length(qualsAttributes), long_number);
churl_headers_append(headers, "X-GP-ATTRS-PROJ", long_number);
for(i = 0; i < list_length(projInfo->pi_targetlist); i++) {
int number = varNumbers[i] - 1;
pg_ltoa(number, long_number);
resetStringInfo(&formatter);
appendStringInfo(&formatter, "X-GP-ATTRS-PROJ-IDX");
churl_headers_append(headers, formatter.data,long_number);
}
ListCell *attribute = NULL;
foreach(attribute, qualsAttributes)
{
AttrNumber attrNumber = lfirst_int(attribute);
pg_ltoa(attrNumber, long_number);
resetStringInfo(&formatter);
appendStringInfo(&formatter, "X-GP-ATTRS-PROJ-IDX");
churl_headers_append(headers, formatter.data,long_number);
}
示例3: GetUniqueMatRelName
/*
* GetUniqueMatRelName
*
* Returns a unique name for the given CV's underlying materialization table
*/
char *
GetUniqueMatRelName(char *cvname, char* nspname)
{
char *relname = palloc0(NAMEDATALEN);
int i = 0;
StringInfoData suffix;
Oid nspoid;
if (nspname != NULL)
nspoid = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(nspname));
else
nspoid = InvalidOid;
initStringInfo(&suffix);
strcpy(relname, cvname);
while (true)
{
appendStringInfo(&suffix, "%s%d", CQ_TABLE_SUFFIX, i);
append_suffix(relname, suffix.data, NAMEDATALEN);
resetStringInfo(&suffix);
if (!OidIsValid(get_relname_relid(relname, nspoid)))
break;
}
return relname;
}
示例4: testStringInfo
static rc
testStringInfo(void)
{
StringInfo str = makeStringInfo();
appendStringInfoChar(str,'a');
ASSERT_EQUALS_STRING("a", str->data, "data is a");
appendStringInfoString(str, "hello");
ASSERT_EQUALS_STRING("ahello", str->data, "data is ahello");
ASSERT_EQUALS_INT(6, str->len, "length is 6");
for(int i = 0; i < 256; i++)
appendStringInfoChar(str, 'b');
ASSERT_EQUALS_INT(6 + 256, str->len, "length is 6 + 256");
for(int i = 255; i < 256 + 6; i++)
ASSERT_EQUALS_INT('b', str->data[i], "chars are all b");
resetStringInfo(str);
ASSERT_EQUALS_INT(0, str->len, "after reset length is 0");
appendStringInfo(str, "%s", "test");
ASSERT_EQUALS_STRING("test", str->data, "data is test");
return PASS;
}
示例5: getElementNodeStr
char *
getElementNodeStr(XMLCompNodeHdr element)
{
XMLScanData textScan;
XMLNodeHdr textNode;
StringInfoData si;
initScanForTextNodes(&textScan, element);
/*
* Set the size to something smaller than what 'initStringInfo()' does
*/
si.maxlen = 32;
si.data = (char *) palloc(si.maxlen);
resetStringInfo(&si);
while ((textNode = getNextXMLNode(&textScan, false)) != NULL)
{
char *cntPart = XNODE_CONTENT(textNode);
appendStringInfoString(&si, cntPart);
}
finalizeScanForTextNodes(&textScan);
return si.data;
}
示例6: pq_getstring
/* --------------------------------
* pq_getstring - get a null terminated string from connection
*
* The return value is placed in an expansible StringInfo, which has
* already been initialized by the caller.
*
* This is used only for dealing with old-protocol clients. The idea
* is to produce a StringInfo that looks the same as we would get from
* pq_getmessage() with a newer client; we will then process it with
* pq_getmsgstring. Therefore, no character set conversion is done here,
* even though this is presumably useful only for text.
*
* returns 0 if OK, EOF if trouble
* --------------------------------
*/
int
pq_getstring(StringInfo s)
{
int i;
resetStringInfo(s);
/* Read until we get the terminating '\0' */
for (;;)
{
while (PqRecvPointer >= PqRecvLength)
{
if (pq_recvbuf()) /* If nothing in buffer, then recv some */
return EOF; /* Failed to recv data */
}
for (i = PqRecvPointer; i < PqRecvLength; i++)
{
if (PqRecvBuffer[i] == '\0')
{
/* include the '\0' in the copy */
appendBinaryStringInfo(s, PqRecvBuffer + PqRecvPointer,
i - PqRecvPointer + 1);
PqRecvPointer = i + 1; /* advance past \0 */
return 0;
}
}
/* If we're here we haven't got the \0 in the buffer yet. */
appendBinaryStringInfo(s, PqRecvBuffer + PqRecvPointer,
PqRecvLength - PqRecvPointer);
PqRecvPointer = PqRecvLength;
}
}
示例7: CopyClear
/* Discard accumulated COPY line */
static void
CopyClear(void)
{
/* Make sure init is done */
CopyAppend(NULL);
resetStringInfo(©String);
}
示例8: initialize_worker_spi
/*
* Initialize workspace for a worker process: create the schema if it doesn't
* already exist.
*/
static void
initialize_worker_spi(worktable *table)
{
int ret;
int ntup;
bool isnull;
StringInfoData buf;
SetCurrentStatementStartTimestamp();
StartTransactionCommand();
SPI_connect();
PushActiveSnapshot(GetTransactionSnapshot());
pgstat_report_activity(STATE_RUNNING, "initializing spi_worker schema");
/* XXX could we use CREATE SCHEMA IF NOT EXISTS? */
initStringInfo(&buf);
appendStringInfo(&buf, "select count(*) from pg_namespace where nspname = '%s'",
table->schema);
ret = SPI_execute(buf.data, true, 0);
if (ret != SPI_OK_SELECT)
elog(FATAL, "SPI_execute failed: error code %d", ret);
if (SPI_processed != 1)
elog(FATAL, "not a singleton result");
ntup = DatumGetInt64(SPI_getbinval(SPI_tuptable->vals[0],
SPI_tuptable->tupdesc,
1, &isnull));
if (isnull)
elog(FATAL, "null result");
if (ntup == 0)
{
resetStringInfo(&buf);
appendStringInfo(&buf,
"CREATE SCHEMA \"%s\" "
"CREATE TABLE \"%s\" ("
" type text CHECK (type IN ('total', 'delta')), "
" value integer)"
"CREATE UNIQUE INDEX \"%s_unique_total\" ON \"%s\" (type) "
"WHERE type = 'total'",
table->schema, table->name, table->name, table->name);
/* set statement start time */
SetCurrentStatementStartTimestamp();
ret = SPI_execute(buf.data, false, 0);
if (ret != SPI_OK_UTILITY)
elog(FATAL, "failed to create my schema");
}
SPI_finish();
PopActiveSnapshot();
CommitTransactionCommand();
pgstat_report_activity(STATE_IDLE, NULL);
}
示例9: pg_split_opts
/*
* pg_split_opts -- split a string of options and append it to an argv array
*
* The caller is responsible for ensuring the argv array is large enough. The
* maximum possible number of arguments added by this routine is
* (strlen(optstr) + 1) / 2.
*
* Because some option values can contain spaces we allow escaping using
* backslashes, with \\ representing a literal backslash.
*/
void
pg_split_opts(char **argv, int *argcp, char *optstr)
{
StringInfoData s;
initStringInfo(&s);
while (*optstr)
{
bool last_was_escape = false;
resetStringInfo(&s);
/* skip over leading space */
while (isspace((unsigned char) *optstr))
optstr++;
if (*optstr == '\0')
break;
/*
* Parse a single option + value, stopping at the first space, unless
* it's escaped.
*/
while (*optstr)
{
if (isspace((unsigned char) *optstr) && !last_was_escape)
break;
if (!last_was_escape && *optstr == '\\')
last_was_escape = true;
else
{
last_was_escape = false;
appendStringInfoChar(&s, *optstr);
}
optstr++;
}
/* now store the option */
argv[(*argcp)++] = pstrdup(s.data);
}
resetStringInfo(&s);
}
示例10: initStringInfo
/*
* initStringInfo
*
* Initialize a StringInfoData struct (with previously undefined contents)
* to describe an empty string.
*/
void
initStringInfo(StringInfo str)
{
int size = 1024; /* initial default buffer size */
str->data = (char *) palloc(size);
str->maxlen = size;
resetStringInfo(str);
}
示例11: decoder_raw_insert
/*
* Decode an INSERT entry
*/
static void
decoder_raw_insert(StringInfo s,
Relation relation,
HeapTuple tuple)
{
TupleDesc tupdesc = RelationGetDescr(relation);
int natt;
bool first_column = true;
StringInfo values = makeStringInfo();
/* Initialize string info for values */
initStringInfo(values);
/* Query header */
appendStringInfo(s, "INSERT INTO ");
print_relname(s, relation);
appendStringInfo(s, " (");
/* Build column names and values */
for (natt = 0; natt < tupdesc->natts; natt++)
{
Form_pg_attribute attr;
Datum origval;
bool isnull;
attr = tupdesc->attrs[natt];
/* Skip dropped columns and system columns */
if (attr->attisdropped || attr->attnum < 0)
continue;
/* Skip comma for first colums */
if (!first_column)
{
appendStringInfoString(s, ", ");
appendStringInfoString(values, ", ");
}
else
first_column = false;
/* Print attribute name */
appendStringInfo(s, "%s", quote_identifier(NameStr(attr->attname)));
/* Get Datum from tuple */
origval = heap_getattr(tuple, natt + 1, tupdesc, &isnull);
/* Get output function */
print_value(values, origval, attr->atttypid, isnull);
}
/* Append values */
appendStringInfo(s, ") VALUES (%s);", values->data);
/* Clean up */
resetStringInfo(values);
}
示例12: hstore_to_json
Datum
hstore_to_json(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
HEntry *entries = ARRPTR(in);
StringInfoData tmp,
dst;
if (count == 0)
PG_RETURN_TEXT_P(cstring_to_text_with_len("{}",2));
initStringInfo(&tmp);
initStringInfo(&dst);
appendStringInfoChar(&dst, '{');
for (i = 0; i < count; i++)
{
resetStringInfo(&tmp);
appendBinaryStringInfo(&tmp, HS_KEY(entries, base, i), HS_KEYLEN(entries, i));
escape_json(&dst, tmp.data);
appendStringInfoString(&dst, ": ");
if (HS_VALISNULL(entries, i))
appendStringInfoString(&dst, "null");
else
{
resetStringInfo(&tmp);
appendBinaryStringInfo(&tmp, HS_VAL(entries, base, i), HS_VALLEN(entries, i));
escape_json(&dst, tmp.data);
}
if (i + 1 != count)
appendStringInfoString(&dst, ", ");
}
appendStringInfoChar(&dst, '}');
PG_RETURN_TEXT_P(cstring_to_text(dst.data));
}
示例13: set_next_db_target
/*
* This function will set a string in shared memory which is the name of the database to connect to
* the next time the background worker restarts. Because a bgworker can only connect to one database
* at a time, and some catalogs and stats are scoped to the current database, the bg worker
* periodically restarts to collect latest stats from another database.
*
*/
int set_next_db_target(void) {
int retval, processed;
StringInfoData buf;
SPITupleTable *coltuptable;
char* next_db_target;
SetCurrentStatementStartTimestamp();
StartTransactionCommand();
SPI_connect();
PushActiveSnapshot(GetTransactionSnapshot());
/* get sorted list of databases, find one after target_db*/
initStringInfo(&buf);
appendStringInfo(&buf,
"SELECT datname FROM pg_database WHERE datname NOT IN ('template0', 'template1') AND datallowconn IS TRUE AND datname > '%s' ORDER BY datname ASC LIMIT 1;", target_db
);
retval = SPI_execute(buf.data, false, 0);
if (retval != SPI_OK_SELECT) {
elog(FATAL, "Database information collection failed");
// FAIL RETURN 1
}
processed = SPI_processed;
if(processed == 0) {
//No matching records so pick first database.
resetStringInfo(&buf);
appendStringInfoString(&buf,
"SELECT datname FROM pg_database WHERE datname NOT IN ('template0', 'template1') AND datallowconn IS TRUE ORDER BY datname ASC LIMIT 1;"
);
retval = SPI_execute(buf.data, false, 0);
if (retval != SPI_OK_SELECT) {
elog(FATAL, "Database information collection failed");
// FAIL RETURN 1
}
}
coltuptable = SPI_tuptable;
next_db_target = SPI_getvalue(coltuptable->vals[0], coltuptable->tupdesc, 1);
// elog(LOG, "NEXTDB TARGET: %s", next_db_target); //print next target db
strcpy(pgsampler_state->next_db, next_db_target);
SPI_finish();
PopActiveSnapshot();
CommitTransactionCommand();
return 0;
}
示例14: pgsp_json_xmlize
char *
pgsp_json_xmlize(char *json)
{
pgspParserContext ctx;
JsonSemAction sem;
JsonLexContext lex;
int start_len;
char buf[32];
init_json_lex_context(&lex, json);
init_parser_context(&ctx, PGSP_JSON_XMLIZE, json, buf, sizeof(buf));
sem.semstate = (void*)&ctx;
sem.object_start = xml_objstart;
sem.object_end = xml_objend;
sem.array_start = NULL;
sem.array_end = xml_arrend;
sem.object_field_start = xml_ofstart;
sem.object_field_end = xml_ofend;
sem.array_element_start= xml_aestart;
sem.array_element_end = xml_aeend;
sem.scalar = xml_scalar;
appendStringInfo(ctx.dest,
"<explain xmlns=\"http://www.postgresql.org/2009/explain\">\n <Query>");
start_len = ctx.dest->len;
if (!run_pg_parse_json(&lex, &sem))
{
if (ctx.dest->len > start_len &&
ctx.dest->data[ctx.dest->len - 1] != '\n')
appendStringInfoChar(ctx.dest, '\n');
if (ctx.dest->len == start_len)
{
resetStringInfo(ctx.dest);
appendStringInfoString(ctx.dest, "<Input was not JSON>");
}
else
appendStringInfoString(ctx.dest, "<truncated>");
}
else
appendStringInfo(ctx.dest, "</Query>\n</explain>\n");
return ctx.dest->data;
}
示例15: worker_merge_files_into_table
/*
* worker_merge_files_into_table creates a task table within the job's schema,
* which should have already been created by the task tracker protocol, and
* copies files in its task directory into this table. If the schema doesn't
* exist, the function defaults to the 'public' schema. Note that, unlike
* partitioning functions, this function is not always idempotent. On success,
* the function creates the table and loads data, and subsequent calls to the
* function error out because the table already exist. On failure, the task
* table creation commands are rolled back, and the function can be called
* again.
*/
Datum
worker_merge_files_into_table(PG_FUNCTION_ARGS)
{
uint64 jobId = PG_GETARG_INT64(0);
uint32 taskId = PG_GETARG_UINT32(1);
ArrayType *columnNameObject = PG_GETARG_ARRAYTYPE_P(2);
ArrayType *columnTypeObject = PG_GETARG_ARRAYTYPE_P(3);
StringInfo jobSchemaName = JobSchemaName(jobId);
StringInfo taskTableName = TaskTableName(taskId);
StringInfo taskDirectoryName = TaskDirectoryName(jobId, taskId);
bool schemaExists = false;
List *columnNameList = NIL;
List *columnTypeList = NIL;
/* we should have the same number of column names and types */
int32 columnNameCount = ArrayObjectCount(columnNameObject);
int32 columnTypeCount = ArrayObjectCount(columnTypeObject);
if (columnNameCount != columnTypeCount)
{
ereport(ERROR, (errmsg("column name array size: %d and type array size: %d"
" do not match", columnNameCount, columnTypeCount)));
}
/*
* If the schema for the job isn't already created by the task tracker
* protocol, we fall to using the default 'public' schema.
*/
schemaExists = JobSchemaExists(jobSchemaName);
if (!schemaExists)
{
resetStringInfo(jobSchemaName);
appendStringInfoString(jobSchemaName, "public");
}
/* create the task table and copy files into the table */
columnNameList = ArrayObjectToCStringList(columnNameObject);
columnTypeList = ArrayObjectToCStringList(columnTypeObject);
CreateTaskTable(jobSchemaName, taskTableName, columnNameList, columnTypeList);
CopyTaskFilesFromDirectory(jobSchemaName, taskTableName, taskDirectoryName);
PG_RETURN_VOID();
}