本文整理汇总了C++中CStringGetDatum函数的典型用法代码示例。如果您正苦于以下问题:C++ CStringGetDatum函数的具体用法?C++ CStringGetDatum怎么用?C++ CStringGetDatum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CStringGetDatum函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeArrayTypeName
/*
* makeArrayTypeName
* - given a base type name, make an array type name for it
*
* the caller is responsible for pfreeing the result
*/
char *
makeArrayTypeName(const char *typeName, Oid typeNamespace)
{
char *arr = (char *) palloc(NAMEDATALEN);
int namelen = strlen(typeName);
Relation pg_type_desc;
int i;
/*
* The idea is to prepend underscores as needed until we make a name that
* doesn't collide with anything...
*/
pg_type_desc = heap_open(TypeRelationId, AccessShareLock);
for (i = 1; i < NAMEDATALEN - 1; i++)
{
arr[i - 1] = '_';
if (i + namelen < NAMEDATALEN)
strcpy(arr + i, typeName);
else
{
memcpy(arr + i, typeName, NAMEDATALEN - i);
truncate_identifier(arr, NAMEDATALEN, false);
}
if (!SearchSysCacheExists2(TYPENAMENSP,
CStringGetDatum(arr),
ObjectIdGetDatum(typeNamespace)))
break;
}
heap_close(pg_type_desc, AccessShareLock);
if (i >= NAMEDATALEN - 1)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("could not form array type name for type \"%s\"",
typeName)));
return arr;
}
示例2: GetRoleTupleByName
/*
* GetRoleTupleByOid -- as above, but search by role OID
*/
static HeapTuple
GetRoleTupleByName(const char * rolename)
{
HeapTuple tuple;
Relation relation;
SysScanDesc scan;
ScanKeyData key[1];
/*
* form a scan key
*/
ScanKeyInit(&key[0],
Anum_pg_authid_rolname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(rolename));
/*
* Open pg_authid and fetch a tuple. Force heap scan if we haven't yet
* built the critical shared relcache entries (i.e., we're starting up
* without a shared relcache cache file).
*/
relation = heap_open(AuthIdRelationId, AccessShareLock);
scan = systable_beginscan(relation, AuthIdRolnameIndexId,
criticalSharedRelcachesBuilt,
SNAPSHOT,
1, key);
tuple = systable_getnext(scan);
/* Must copy tuple before releasing buffer */
if (HeapTupleIsValid(tuple))
tuple = heap_copytuple(tuple);
/* all done */
systable_endscan(scan);
heap_close(relation, AccessShareLock);
return tuple;
}
示例3: enum_recv
/* Binary I/O support */
Datum
enum_recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
Oid enumtypoid = PG_GETARG_OID(1);
Oid enumoid;
HeapTuple tup;
char *name;
int nbytes;
name = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
/* must check length to prevent Assert failure within SearchSysCache */
if (strlen(name) >= NAMEDATALEN)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input value for enum %s: \"%s\"",
format_type_be(enumtypoid),
name)));
tup = SearchSysCache(ENUMTYPOIDNAME,
ObjectIdGetDatum(enumtypoid),
CStringGetDatum(name),
0, 0);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input value for enum %s: \"%s\"",
format_type_be(enumtypoid),
name)));
enumoid = HeapTupleGetOid(tup);
ReleaseSysCache(tup);
pfree(name);
PG_RETURN_OID(enumoid);
}
示例4: enum_in
Datum
enum_in(PG_FUNCTION_ARGS)
{
char *name = PG_GETARG_CSTRING(0);
Oid enumtypoid = PG_GETARG_OID(1);
Oid enumoid;
HeapTuple tup;
/* must check length to prevent Assert failure within SearchSysCache */
if (strlen(name) >= NAMEDATALEN)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input value for enum %s: \"%s\"",
format_type_be(enumtypoid),
name)));
tup = SearchSysCache2(ENUMTYPOIDNAME,
ObjectIdGetDatum(enumtypoid),
CStringGetDatum(name));
if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input value for enum %s: \"%s\"",
format_type_be(enumtypoid),
name)));
/* check it's safe to use in SQL */
check_safe_enum_use(tup);
/*
* This comes from pg_enum.oid and stores system oids in user tables. This
* oid must be preserved by binary upgrades.
*/
enumoid = HeapTupleGetOid(tup);
ReleaseSysCache(tup);
PG_RETURN_OID(enumoid);
}
示例5: current_schemas
Datum
current_schemas(PG_FUNCTION_ARGS)
{
List *search_path = fetch_search_path(PG_GETARG_BOOL(0));
ListCell *l;
Datum *names;
int i;
ArrayType *array;
names = (Datum *) palloc(list_length(search_path) * sizeof(Datum));
i = 0;
foreach(l, search_path)
{
char *nspname;
nspname = get_namespace_name(lfirst_oid(l));
if (nspname) /* watch out for deleted namespace */
{
names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname));
i++;
}
}
示例6: _String_coerceObject
Datum _String_coerceObject(Type self, jobject jstr)
{
char* tmp;
Datum ret;
if(jstr == 0)
return 0;
jstr = JNI_callObjectMethod(jstr, s_Object_toString);
if(JNI_exceptionCheck())
return 0;
tmp = String_createNTS(jstr);
JNI_deleteLocalRef(jstr);
ret = FunctionCall3(
&((String)self)->textInput,
CStringGetDatum(tmp),
ObjectIdGetDatum(((String)self) -> Type_extension.typeId /* elementType */ ),
Int32GetDatum(-1));
pfree(tmp);
return ret;
}
示例7: get_rewrite_oid_without_relid
/*
* Find rule oid, given only a rule name but no rel OID.
*
* If there's more than one, it's an error. If there aren't any, that's an
* error, too. In general, this should be avoided - it is provided to support
* syntax that is compatible with pre-7.3 versions of PG, where rule names
* were unique across the entire database.
*/
Oid
get_rewrite_oid_without_relid(const char *rulename, Oid *reloid)
{
Relation RewriteRelation;
HeapScanDesc scanDesc;
ScanKeyData scanKeyData;
HeapTuple htup;
Oid ruleoid;
/* Search pg_rewrite for such a rule */
ScanKeyInit(&scanKeyData,
Anum_pg_rewrite_rulename,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(rulename));
RewriteRelation = heap_open(RewriteRelationId, AccessShareLock);
scanDesc = heap_beginscan(RewriteRelation, SnapshotNow, 1, &scanKeyData);
htup = heap_getnext(scanDesc, ForwardScanDirection);
if (!HeapTupleIsValid(htup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" does not exist", rulename)));
ruleoid = HeapTupleGetOid(htup);
if (reloid != NULL)
*reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
if (HeapTupleIsValid(htup = heap_getnext(scanDesc, ForwardScanDirection)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("there are multiple rules named \"%s\"", rulename),
errhint("Specify a relation name as well as a rule name.")));
heap_endscan(scanDesc);
heap_close(RewriteRelation, AccessShareLock);
return ruleoid;
}
示例8: DropProceduralLanguage
/* ---------------------------------------------------------------------
* DROP PROCEDURAL LANGUAGE
* ---------------------------------------------------------------------
*/
void
DropProceduralLanguage(DropPLangStmt *stmt)
{
char *languageName;
HeapTuple langTup;
ObjectAddress object;
/*
* Check permission
*/
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to drop procedural language")));
/*
* Translate the language name, check that the language exists
*/
languageName = case_translate_language_name(stmt->plname);
langTup = SearchSysCache(LANGNAME,
CStringGetDatum(languageName),
0, 0, 0);
if (!HeapTupleIsValid(langTup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("language \"%s\" does not exist", languageName)));
object.classId = LanguageRelationId;
object.objectId = HeapTupleGetOid(langTup);
object.objectSubId = 0;
ReleaseSysCache(langTup);
/*
* Do the deletion
*/
performDeletion(&object, stmt->behavior);
}
示例9: GetResourceTypeByName
/* MPP-6923:
* GetResourceTypeByName: find the named resource in pg_resourcetype
*
* Input: name of resource
* Output: resourcetypid (int2), oid of entry
*
* updates output and returns true if named resource found
*
*/
static bool
GetResourceTypeByName(char *pNameIn, int *pTypeOut, Oid *pOidOut)
{
Relation pg_resourcetype;
ScanKeyData scankey;
SysScanDesc sscan;
HeapTuple tuple;
bool bStat = false;
/*
* SELECT * FROM pg_resourcetype WHERE resname = :1 FOR UPDATE
*
* XXX XXX: maybe should be share lock, ie remove FOR UPDATE ?
* XXX XXX: only one
*/
pg_resourcetype = heap_open(ResourceTypeRelationId, RowExclusiveLock);
ScanKeyInit(&scankey,
Anum_pg_resourcetype_resname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(pNameIn));
sscan = systable_beginscan(pg_resourcetype, ResourceTypeResnameIndexId, true,
SnapshotNow, 1, &scankey);
tuple = systable_getnext(sscan);
if (HeapTupleIsValid(tuple))
{
*pOidOut = HeapTupleGetOid(tuple);
*pTypeOut =
((Form_pg_resourcetype) GETSTRUCT(tuple))->restypid;
bStat = true;
}
systable_endscan(sscan);
heap_close(pg_resourcetype, RowExclusiveLock);
return (bStat);
} /* end GetResourceTypeByName */
示例10: dbms_assert_schema_name
Datum
dbms_assert_schema_name(PG_FUNCTION_ARGS)
{
Oid namespaceId;
AclResult aclresult;
text *sname;
char *nspname;
List *names;
if (PG_ARGISNULL(0))
INVALID_SCHEMA_NAME_EXCEPTION();
sname = PG_GETARG_TEXT_P(0);
if (EMPTY_STR(sname))
INVALID_SCHEMA_NAME_EXCEPTION();
nspname = text_to_cstring(sname);
#ifdef GP_VERSION_NUM
names = stringToQualifiedNameList(nspname, "dbms");
#else
names = stringToQualifiedNameList(nspname);
#endif
if (list_length(names) != 1)
INVALID_SCHEMA_NAME_EXCEPTION();
namespaceId = GetSysCacheOid(NAMESPACENAME,
CStringGetDatum(strVal(linitial(names))),
0, 0, 0);
if (!OidIsValid(namespaceId))
INVALID_SCHEMA_NAME_EXCEPTION();
aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
if (aclresult != ACLCHECK_OK)
INVALID_SCHEMA_NAME_EXCEPTION();
PG_RETURN_TEXT_P(sname);
}
示例11: LookupExtProtocolOid
/*
* Same as LookupExtProtocolFunction but returns the actual
* protocol Oid.
*/
Oid
LookupExtProtocolOid(const char *prot_name, bool missing_ok)
{
Oid protOid = InvalidOid;
Relation rel;
ScanKeyData skey;
SysScanDesc scan;
HeapTuple tup;
rel = heap_open(ExtprotocolRelationId, AccessShareLock);
/*
* Check the pg_extprotocol relation to be certain the protocol
* is there.
*/
ScanKeyInit(&skey,
Anum_pg_extprotocol_ptcname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(prot_name));
scan = systable_beginscan(rel, ExtprotocolPtcnameIndexId, true,
SnapshotNow, 1, &skey);
tup = systable_getnext(scan);
if (HeapTupleIsValid(tup))
protOid = HeapTupleGetOid(tup);
else if (!missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("protocol \"%s\" does not exist",
prot_name)));
systable_endscan(scan);
heap_close(rel, AccessShareLock);
return protOid;
}
示例12: getExtensionLoadPath
static void getExtensionLoadPath()
{
MemoryContext curr;
Datum dtm;
bool isnull;
StringInfoData buf;
/*
* Check whether sqlj.loadpath exists before querying it. I would more
* happily just PG_CATCH() the error and compare to ERRCODE_UNDEFINED_TABLE
* but what's required to make that work right is "not terribly well
* documented, but the exception-block handling in plpgsql provides a
* working model" and that code is a lot more fiddly than you would guess.
*/
if ( InvalidOid == get_relname_relid(LOADPATH_TBL_NAME,
GetSysCacheOid1(NAMESPACENAME, CStringGetDatum("sqlj"))) )
return;
SPI_connect();
curr = CurrentMemoryContext;
initStringInfo(&buf);
appendStringInfo(&buf, "SELECT path, exnihilo FROM sqlj.%s",
quote_identifier(LOADPATH_TBL_NAME));
if ( SPI_OK_SELECT == SPI_execute(buf.data, true, 1) && 1 == SPI_processed )
{
MemoryContextSwitchTo(TopMemoryContext);
pljavaLoadPath = (char const *)SPI_getvalue(
SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
MemoryContextSwitchTo(curr);
dtm = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 2,
&isnull);
if ( isnull )
elog(ERROR, "defect in CREATE EXTENSION script");
extensionExNihilo = DatumGetBool(dtm);
}
SPI_finish();
}
示例13: AlterLanguageOwner
/*
* Change language owner
*/
void
AlterLanguageOwner(const char *name, Oid newOwnerId)
{
HeapTuple tup;
Relation rel;
/* Translate name for consistency with CREATE */
name = case_translate_language_name(name);
rel = heap_open(LanguageRelationId, RowExclusiveLock);
tup = SearchSysCache1(LANGNAME, CStringGetDatum(name));
if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("language \"%s\" does not exist", name)));
AlterLanguageOwner_internal(tup, rel, newOwnerId);
ReleaseSysCache(tup);
heap_close(rel, RowExclusiveLock);
}
示例14: ssl_client_serial
Datum
ssl_client_serial(PG_FUNCTION_ARGS)
{
Datum result;
Port *port = MyProcPort;
X509 *peer = port->peer;
ASN1_INTEGER *serial = NULL;
BIGNUM *b;
char *decimal;
if (!peer)
PG_RETURN_NULL();
serial = X509_get_serialNumber(peer);
b = ASN1_INTEGER_to_BN(serial, NULL);
decimal = BN_bn2dec(b);
BN_free(b);
result = DirectFunctionCall3(numeric_in,
CStringGetDatum(decimal),
ObjectIdGetDatum(0),
Int32GetDatum(-1));
OPENSSL_free(decimal);
return result;
}
示例15: plperl_modify_tuple
static HeapTuple
plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
{
SV **svp;
HV *hvNew;
HeapTuple rtup;
SV *val;
char *key;
I32 klen;
int slotsused;
int *modattrs;
Datum *modvalues;
char *modnulls;
TupleDesc tupdesc;
tupdesc = tdata->tg_relation->rd_att;
svp = hv_fetch(hvTD, "new", 3, FALSE);
if (!svp)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("$_TD->{new} does not exist")));
if (!SvOK(*svp) || SvTYPE(*svp) != SVt_RV || SvTYPE(SvRV(*svp)) != SVt_PVHV)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("$_TD->{new} is not a hash reference")));
hvNew = (HV *) SvRV(*svp);
modattrs = palloc(tupdesc->natts * sizeof(int));
modvalues = palloc(tupdesc->natts * sizeof(Datum));
modnulls = palloc(tupdesc->natts * sizeof(char));
slotsused = 0;
hv_iterinit(hvNew);
while ((val = hv_iternextsv(hvNew, &key, &klen)))
{
int attn = SPI_fnumber(tupdesc, key);
if (attn <= 0 || tupdesc->attrs[attn - 1]->attisdropped)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("Perl hash contains nonexistent column \"%s\"",
key)));
if (SvOK(val) && SvTYPE(val) != SVt_NULL)
{
Oid typinput;
Oid typioparam;
FmgrInfo finfo;
/* XXX would be better to cache these lookups */
getTypeInputInfo(tupdesc->attrs[attn - 1]->atttypid,
&typinput, &typioparam);
fmgr_info(typinput, &finfo);
modvalues[slotsused] = FunctionCall3(&finfo,
CStringGetDatum(SvPV(val, PL_na)),
ObjectIdGetDatum(typioparam),
Int32GetDatum(tupdesc->attrs[attn - 1]->atttypmod));
modnulls[slotsused] = ' ';
}
else
{
modvalues[slotsused] = (Datum) 0;
modnulls[slotsused] = 'n';
}
modattrs[slotsused] = attn;
slotsused++;
}
hv_iterinit(hvNew);
rtup = SPI_modifytuple(tdata->tg_relation, otup, slotsused,
modattrs, modvalues, modnulls);
pfree(modattrs);
pfree(modvalues);
pfree(modnulls);
if (rtup == NULL)
elog(ERROR, "SPI_modifytuple failed: %s",
SPI_result_code_string(SPI_result));
return rtup;
}