本文整理匯總了C++中DatumGetCString函數的典型用法代碼示例。如果您正苦於以下問題:C++ DatumGetCString函數的具體用法?C++ DatumGetCString怎麽用?C++ DatumGetCString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DatumGetCString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: pgpool_remote_start
Datum
pgpool_remote_start(PG_FUNCTION_ARGS)
{
int r;
char *remote_host = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(0))));
char *remote_data_directory = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(1))));
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser to use pgpool_remote_start function"))));
snprintf(recovery_script, sizeof(recovery_script),
"%s/%s %s %s", DataDir, REMOTE_START_FILE,
remote_host, remote_data_directory);
elog(DEBUG1, "recovery_script: %s", recovery_script);
r = system(recovery_script);
if (r != 0)
{
elog(ERROR, "pgpool_remote_start failed");
}
PG_RETURN_BOOL(true);
}
示例2: find_language_template
/*
* Look to see if we have template information for the given language name.
*/
static PLTemplate *
find_language_template(const char *languageName)
{
PLTemplate *result;
Relation rel;
SysScanDesc scan;
ScanKeyData key;
HeapTuple tup;
rel = heap_open(PLTemplateRelationId, AccessShareLock);
ScanKeyInit(&key,
Anum_pg_pltemplate_tmplname,
BTEqualStrategyNumber, F_NAMEEQ,
NameGetDatum(languageName));
scan = systable_beginscan(rel, PLTemplateNameIndexId, true,
SnapshotNow, 1, &key);
tup = systable_getnext(scan);
if (HeapTupleIsValid(tup))
{
Form_pg_pltemplate tmpl = (Form_pg_pltemplate) GETSTRUCT(tup);
Datum datum;
bool isnull;
result = (PLTemplate *) palloc0(sizeof(PLTemplate));
result->tmpltrusted = tmpl->tmpltrusted;
/* Remaining fields are variable-width so we need heap_getattr */
datum = heap_getattr(tup, Anum_pg_pltemplate_tmplhandler,
RelationGetDescr(rel), &isnull);
if (!isnull)
result->tmplhandler =
DatumGetCString(DirectFunctionCall1(textout, datum));
datum = heap_getattr(tup, Anum_pg_pltemplate_tmplvalidator,
RelationGetDescr(rel), &isnull);
if (!isnull)
result->tmplvalidator =
DatumGetCString(DirectFunctionCall1(textout, datum));
datum = heap_getattr(tup, Anum_pg_pltemplate_tmpllibrary,
RelationGetDescr(rel), &isnull);
if (!isnull)
result->tmpllibrary =
DatumGetCString(DirectFunctionCall1(textout, datum));
/* Ignore template if handler or library info is missing */
if (!result->tmplhandler || !result->tmpllibrary)
result = NULL;
}
else
result = NULL;
systable_endscan(scan);
heap_close(rel, AccessShareLock);
return result;
}
示例3: pr_set
/*
* DML Functions
*/
Datum
pr_set(PG_FUNCTION_ARGS) {
text * key_arg = PG_GETARG_TEXT_P(0);
text * value_arg = PG_GETARG_TEXT_P(1);
int expire = PG_GETARG_UINT32(2);
int ret;
char * key = NULL;
char * value = NULL;
if (!pgredis || !pgredis->redis_server) {
elog(ERROR, "Unable to set, redis instance missing");
PG_RETURN_FALSE;
}
key = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(key_arg)));
value = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(value_arg)));
if (!key || !value) {
elog(ERROR, "Key/value incomplete in pgredis set");
PG_RETURN_FALSE;
}
ret = credis_set(pgredis->redis_server, key, value);
if (ret == CREDIS_OK) {
ret = credis_expire(pgredis->redis_server, key, expire);
}
PG_RETURN_BOOL(ret == CREDIS_OK);
}
示例4: CheckInMemConstraintsPgType
/*
* CheckInMemConstraintsPgType
* Check uniqueness constraints for pg_type in-memory tuples upon insert
*/
static void
CheckInMemConstraintsPgType(InMemHeapRelation relation, HeapTuple newTuple)
{
Assert(NULL != newTuple);
Assert(NULL != relation);
Assert(NULL != relation->rel);
TupleDesc tupleDesc = relation->rel->rd_att;
Oid relnamespaceNew = DatumGetObjectId(tuple_getattr(newTuple, tupleDesc, Anum_pg_type_typnamespace));
char *typnameNew = DatumGetCString(tuple_getattr(newTuple, tupleDesc, Anum_pg_type_typname));
for (int i = 0; i < relation->tupsize; i++)
{
HeapTuple tuple = relation->tuples[i].tuple;
Assert(NULL != tuple);
insist_log(HeapTupleGetOid(tuple) != HeapTupleGetOid(newTuple),
"in-memory tuple with Oid = %d already exists in pg_type.", HeapTupleGetOid(tuple));
Oid relnamespace = DatumGetObjectId(tuple_getattr(tuple, tupleDesc, Anum_pg_type_typnamespace));
char *typname = DatumGetCString(tuple_getattr(tuple, tupleDesc, Anum_pg_type_typname));
size_t typnameLen = strlen(typname);
insist_log(relnamespace != relnamespaceNew ||
typnameLen != strlen(typnameNew) ||
0 != strncmp(typname, typnameNew, typnameLen),
"in-memory tuple with typname = %s and typnamespace = %d already exists in pg_type.", typname, relnamespace);
}
}
示例5: CheckInMemConstraintsPgNamespace
/*
* CheckInMemConstraintsPgNamespace
* Check uniqueness constraints for pg_namespace in-memory tuples upon insert
*/
static void
CheckInMemConstraintsPgNamespace(InMemHeapRelation relation, HeapTuple newTuple)
{
Assert(NULL != newTuple);
Assert(NULL != relation);
Assert(NULL != relation->rel);
TupleDesc tupleDesc = relation->rel->rd_att;
Oid nspdboidNew = DatumGetObjectId(tuple_getattr(newTuple, tupleDesc, Anum_pg_namespace_nspdboid));
char *nspnameNew = DatumGetCString(tuple_getattr(newTuple, tupleDesc, Anum_pg_namespace_nspname));
for (int i = 0; i < relation->tupsize; i++)
{
HeapTuple tuple = relation->tuples[i].tuple;
Assert(NULL != tuple);
insist_log(HeapTupleGetOid(tuple) != HeapTupleGetOid(newTuple),
"in-memory tuple with Oid = %d already exists in pg_namespace.", HeapTupleGetOid(tuple));
Oid nspdboid = DatumGetObjectId(tuple_getattr(tuple, tupleDesc, Anum_pg_namespace_nspdboid));
char *nspname = DatumGetCString(tuple_getattr(tuple, tupleDesc, Anum_pg_namespace_nspname));
size_t nspnameLen = strlen(nspname);
insist_log(nspdboid != nspdboidNew ||
nspnameLen != strlen(nspnameNew) ||
0 != strncmp(nspname, nspnameNew, nspnameLen),
"in-memory tuple with nspname = %s and nspdboid = %d already exists in pg_namespace.", nspname, nspdboid);
}
}
示例6: dump_bvf1_inputs
void dump_bvf1_inputs(ArrayType *broker_list_p, text *sector_name_p) {
int ndim, nitems;
int *dim;
int16 typlen;
bool typbyval;
char typalign;
int i;
char *broker_list;
ndim = ARR_NDIM(broker_list_p);
dim = ARR_DIMS(broker_list_p);
nitems = ArrayGetNItems(ndim, dim);
get_typlenbyvalalign(ARR_ELEMTYPE(broker_list_p), &typlen, &typbyval,
&typalign);
broker_list = ARR_DATA_PTR(broker_list_p);
elog(NOTICE, "BVF1: INPUTS START");
for (i = 0; i < nitems; i++) {
elog(NOTICE, "BVF1: broker_list[%d] %s", i,
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(broker_list))));
broker_list = att_addlength_pointer(broker_list, typlen,
broker_list);
broker_list = (char *) att_align_nominal(broker_list, typalign);
}
elog(NOTICE, "BVF1: sector_name %s",
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(sector_name_p))));
elog(NOTICE, "BVF1: INPUTS END");
}
示例7: tintervalout
/*
* tintervalout - converts an internal tinterval format to a string
*/
Datum
tintervalout(PG_FUNCTION_ARGS)
{
TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0);
char *i_str,
*p;
i_str = (char *) palloc(T_INTERVAL_LEN); /* ["..." "..."] */
strcpy(i_str, "[\"");
if (tinterval->status == T_INTERVAL_INVAL)
strcat(i_str, INVALID_INTERVAL_STR);
else
{
p = DatumGetCString(DirectFunctionCall1(abstimeout,
AbsoluteTimeGetDatum(tinterval->data[0])));
strcat(i_str, p);
pfree(p);
strcat(i_str, "\" \"");
p = DatumGetCString(DirectFunctionCall1(abstimeout,
AbsoluteTimeGetDatum(tinterval->data[1])));
strcat(i_str, p);
pfree(p);
}
strcat(i_str, "\"]");
PG_RETURN_CSTRING(i_str);
}
示例8: pgpool_recovery
Datum
pgpool_recovery(PG_FUNCTION_ARGS)
{
int r;
char *script = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(0))));
char *remote_host = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(1))));
char *remote_data_directory = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(2))));
if (!superuser())
#ifdef ERRCODE_INSUFFICIENT_PRIVILEGE
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser to use pgpool_recovery function"))));
#else
elog(ERROR, "must be superuser to use pgpool_recovery function");
#endif
if (PG_NARGS() >= 5) /* Pgpool-II 4.0 or later */
{
char *remote_port = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(3))));
int recovery_node = PG_GETARG_INT32(4);
snprintf(recovery_script, sizeof(recovery_script), "\"%s/%s\" \"%s\" \"%s\" \"%s\" \"%s\" %d",
DataDir, script, DataDir, remote_host,
remote_data_directory, remote_port, recovery_node);
}
else if (PG_NARGS() >= 4) /* Pgpool-II 3.4 - 3.7 */
{
char *remote_port = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(3))));
snprintf(recovery_script, sizeof(recovery_script), "\"%s/%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
DataDir, script, DataDir, remote_host,
remote_data_directory, remote_port);
}
else
{
snprintf(recovery_script, sizeof(recovery_script), "\"%s/%s\" \"%s\" \"%s\" \"%s\"",
DataDir, script, DataDir, remote_host,
remote_data_directory);
}
elog(DEBUG1, "recovery_script: %s", recovery_script);
r = system(recovery_script);
if (r != 0)
{
elog(ERROR, "pgpool_recovery failed");
}
PG_RETURN_BOOL(true);
}
示例9: pgpool_pgctl
Datum
pgpool_pgctl(PG_FUNCTION_ARGS)
{
int r;
char *action = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(0))));
char *stop_mode = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(1))));
char *pg_ctl;
char *data_directory;
if (!superuser())
#ifdef ERRCODE_INSUFFICIENT_PRIVILEGE
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser to use pgpool_pgctl function"))));
#else
elog(ERROR, "must be superuser to use pgpool_pgctl function");
#endif
#if defined(PG_VERSION_NUM) && (PG_VERSION_NUM >= 90600)
pg_ctl = GetConfigOptionByName("pgpool.pg_ctl", NULL, false);
data_directory = GetConfigOptionByName("data_directory", NULL, false);
#else
pg_ctl = GetConfigOptionByName("pgpool.pg_ctl", NULL);
data_directory = GetConfigOptionByName("data_directory", NULL);
#endif
if (strcmp(stop_mode, "") != 0)
{
snprintf(command_text, sizeof(command_text),
"%s %s -D %s -m %s 2>/dev/null 1>/dev/null < /dev/null &",
pg_ctl, action, data_directory, stop_mode);
}
else
{
snprintf(command_text, sizeof(command_text),
"%s %s -D %s 2>/dev/null 1>/dev/null < /dev/null &",
pg_ctl, action, data_directory);
}
elog(DEBUG1, "command_text: %s", command_text);
r = system(command_text);
if (strcmp(action, "reload") == 0 && r != 0)
{
elog(ERROR, "pgpool_pgctl failed");
}
PG_RETURN_BOOL(true);
}
示例10: PLyDecimal_FromNumeric
static PyObject *
PLyDecimal_FromNumeric(PLyDatumToOb *arg, Datum d)
{
static PyObject *decimal_constructor;
char *str;
PyObject *pyvalue;
/* Try to import cdecimal. If it doesn't exist, fall back to decimal. */
if (!decimal_constructor)
{
PyObject *decimal_module;
decimal_module = PyImport_ImportModule("cdecimal");
if (!decimal_module)
{
PyErr_Clear();
decimal_module = PyImport_ImportModule("decimal");
}
if (!decimal_module)
PLy_elog(ERROR, "could not import a module for Decimal constructor");
decimal_constructor = PyObject_GetAttrString(decimal_module, "Decimal");
if (!decimal_constructor)
PLy_elog(ERROR, "no Decimal attribute in module");
}
str = DatumGetCString(DirectFunctionCall1(numeric_out, d));
pyvalue = PyObject_CallFunction(decimal_constructor, "s", str);
if (!pyvalue)
PLy_elog(ERROR, "conversion from numeric to Decimal failed");
return pyvalue;
}
示例11: fetch_restriction
static
void fetch_restriction(
HeapTuple *tuple,
TupleDesc *tupdesc,
Column_info_t info[4],
Restrict_t *restriction) {
restriction->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
restriction->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[1]);
char *str = DatumGetCString(
SPI_getvalue(*tuple, *tupdesc, info[2].colNumber));
// TODO(someone) because its text, no guarantee the text read is correct
// move this code to c++ to tokenize the integers.
int i = 0;
for (i = 0; i < MAX_RULE_LENGTH; ++i) restriction->restricted_edges[i] = -1;
str[0] = ',';
if (str != NULL) {
char *token = NULL;
int i = 0;
token = (char *)strtok(str, " ,");
while (token != NULL && i < MAX_RULE_LENGTH) {
restriction->restricted_edges[i] = atoi(token);
i++;
token = (char *)strtok(NULL, " ,");
}
}
}
示例12: printTypmod
/*
* Add typmod decoration to the basic type name
*/
static char *
printTypmod(const char *typname, int32 typmod, Oid typmodout)
{
char *res;
/* Shouldn't be called if typmod is -1 */
Assert(typmod >= 0);
if (typmodout == InvalidOid)
{
/* Default behavior: just print the integer typmod with parens */
res = psnprintf(strlen(typname) + MAX_INT32_LEN + 3, "%s(%d)",
typname, (int) typmod);
}
else
{
/* Use the type-specific typmodout procedure */
char *tmstr;
tmstr = DatumGetCString(OidFunctionCall1(typmodout,
Int32GetDatum(typmod)));
res = psnprintf(strlen(typname) + strlen(tmstr) + 1, "%s%s",
typname, tmstr);
}
return res;
}
示例13: binary_decode
Datum
binary_decode(PG_FUNCTION_ARGS)
{
text *data = PG_GETARG_TEXT_P(0);
Datum name = PG_GETARG_DATUM(1);
bytea *result;
char *namebuf;
int datalen,
resultlen,
res;
struct pg_encoding *enc;
datalen = VARSIZE(data) - VARHDRSZ;
namebuf = DatumGetCString(DirectFunctionCall1(textout, name));
enc = pg_find_encoding(namebuf);
if (enc == NULL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized encoding: \"%s\"", namebuf)));
resultlen = enc->decode_len(VARDATA(data), datalen);
result = palloc(VARHDRSZ + resultlen);
res = enc->decode(VARDATA(data), datalen, VARDATA(result));
/* Make this FATAL 'cause we've trodden on memory ... */
if (res > resultlen)
elog(FATAL, "overflow - decode estimate too small");
VARATT_SIZEP(result) = VARHDRSZ + res;
PG_RETURN_BYTEA_P(result);
}
示例14: base36_cast_from_text
Datum
base36_cast_from_text(PG_FUNCTION_ARGS)
{
text *txt = PG_GETARG_TEXT_P(0);
char *str = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(txt)));
PG_RETURN_INT32(base36_from_str(str));
}
示例15: jsonb_put_escaped_value
static void
jsonb_put_escaped_value(StringInfo out, JsonbValue *scalarVal)
{
switch (scalarVal->type)
{
case jbvNull:
appendBinaryStringInfo(out, "null", 4);
break;
case jbvString:
escape_json(out, pnstrdup(scalarVal->val.string.val, scalarVal->val.string.len));
break;
case jbvNumeric:
appendStringInfoString(out,
DatumGetCString(DirectFunctionCall1(numeric_out,
PointerGetDatum(scalarVal->val.numeric))));
break;
case jbvBool:
if (scalarVal->val.boolean)
appendBinaryStringInfo(out, "true", 4);
else
appendBinaryStringInfo(out, "false", 5);
break;
default:
elog(ERROR, "unknown jsonb scalar type");
}
}