本文整理汇总了C++中SysCacheGetAttr函数的典型用法代码示例。如果您正苦于以下问题:C++ SysCacheGetAttr函数的具体用法?C++ SysCacheGetAttr怎么用?C++ SysCacheGetAttr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SysCacheGetAttr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: is_immutable_func
/*
* Check whether the function is IMMUTABLE.
*/
bool
is_immutable_func(Oid funcid)
{
HeapTuple tp;
bool isnull;
Datum datum;
tp = SearchSysCache(PROCOID, ObjectIdGetDatum(funcid), 0, 0, 0);
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for function %u", funcid);
#ifdef DEBUG_FDW
/* print function name and its immutability */
{
char *proname;
datum = SysCacheGetAttr(PROCOID, tp, Anum_pg_proc_proname, &isnull);
proname = pstrdup(DatumGetName(datum)->data);
elog(DEBUG1, "func %s(%u) is%s immutable", proname, funcid,
(DatumGetChar(datum) == PROVOLATILE_IMMUTABLE) ? "" : " not");
pfree(proname);
}
#endif
datum = SysCacheGetAttr(PROCOID, tp, Anum_pg_proc_provolatile, &isnull);
ReleaseSysCache(tp);
return (DatumGetChar(datum) == PROVOLATILE_IMMUTABLE);
}
示例2: GetForeignServer
/*
* GetForeignServer - look up the foreign server definition.
*/
ForeignServer *
GetForeignServer(Oid serverid)
{
Form_pg_foreign_server serverform;
ForeignServer *server;
HeapTuple tp;
Datum datum;
bool isnull;
tp = SearchSysCache(FOREIGNSERVEROID,
ObjectIdGetDatum(serverid),
0, 0, 0);
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for foreign server %u", serverid);
serverform = (Form_pg_foreign_server) GETSTRUCT(tp);
server = palloc(sizeof(ForeignServer));
server->serverid = serverid;
server->servername = pstrdup(NameStr(serverform->srvname));
server->owner = serverform->srvowner;
server->fdwid = serverform->srvfdw;
/* Extract server type */
datum = SysCacheGetAttr(FOREIGNSERVEROID,
tp,
Anum_pg_foreign_server_srvtype,
&isnull);
server->servertype = isnull ? NULL : pstrdup(TextDatumGetCString(datum));
/* Extract server version */
datum = SysCacheGetAttr(FOREIGNSERVEROID,
tp,
Anum_pg_foreign_server_srvversion,
&isnull);
server->serverversion = isnull ? NULL : pstrdup(TextDatumGetCString(datum));
/* Extract the srvoptions */
datum = SysCacheGetAttr(FOREIGNSERVEROID,
tp,
Anum_pg_foreign_server_srvoptions,
&isnull);
/* untransformRelOptions does exactly what we want - avoid duplication */
server->options = untransformRelOptions(datum);
ReleaseSysCache(tp);
return server;
}
示例3: GetSubscriptionRelState
/*
* Get state of subscription table.
*
* Returns SUBREL_STATE_UNKNOWN when not found and missing_ok is true.
*/
char
GetSubscriptionRelState(Oid subid, Oid relid, XLogRecPtr *sublsn,
bool missing_ok)
{
Relation rel;
HeapTuple tup;
char substate;
bool isnull;
Datum d;
rel = table_open(SubscriptionRelRelationId, AccessShareLock);
/* Try finding the mapping. */
tup = SearchSysCache2(SUBSCRIPTIONRELMAP,
ObjectIdGetDatum(relid),
ObjectIdGetDatum(subid));
if (!HeapTupleIsValid(tup))
{
if (missing_ok)
{
table_close(rel, AccessShareLock);
*sublsn = InvalidXLogRecPtr;
return SUBREL_STATE_UNKNOWN;
}
elog(ERROR, "subscription table %u in subscription %u does not exist",
relid, subid);
}
/* Get the state. */
d = SysCacheGetAttr(SUBSCRIPTIONRELMAP, tup,
Anum_pg_subscription_rel_srsubstate, &isnull);
Assert(!isnull);
substate = DatumGetChar(d);
d = SysCacheGetAttr(SUBSCRIPTIONRELMAP, tup,
Anum_pg_subscription_rel_srsublsn, &isnull);
if (isnull)
*sublsn = InvalidXLogRecPtr;
else
*sublsn = DatumGetLSN(d);
/* Cleanup */
ReleaseSysCache(tup);
table_close(rel, AccessShareLock);
return substate;
}
示例4: get_role_password
/*
* Fetch stored password for a user, for authentication.
*
* On error, returns NULL, and stores a palloc'd string describing the reason,
* for the postmaster log, in *logdetail. The error reason should *not* be
* sent to the client, to avoid giving away user information!
*/
char *
get_role_password(const char *role, char **logdetail)
{
TimestampTz vuntil = 0;
HeapTuple roleTup;
Datum datum;
bool isnull;
char *shadow_pass;
/* Get role info from pg_authid */
roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(role));
if (!HeapTupleIsValid(roleTup))
{
*logdetail = psprintf(_("Role \"%s\" does not exist."),
role);
return NULL; /* no such user */
}
datum = SysCacheGetAttr(AUTHNAME, roleTup,
Anum_pg_authid_rolpassword, &isnull);
if (isnull)
{
ReleaseSysCache(roleTup);
*logdetail = psprintf(_("User \"%s\" has no password assigned."),
role);
return NULL; /* user has no password */
}
shadow_pass = TextDatumGetCString(datum);
datum = SysCacheGetAttr(AUTHNAME, roleTup,
Anum_pg_authid_rolvaliduntil, &isnull);
if (!isnull)
vuntil = DatumGetTimestampTz(datum);
ReleaseSysCache(roleTup);
/*
* Password OK, but check to be sure we are not past rolvaliduntil
*/
if (!isnull && vuntil < GetCurrentTimestamp())
{
*logdetail = psprintf(_("User \"%s\" has an expired password."),
role);
return NULL;
}
return shadow_pass;
}
示例5: build_replindex_scan_key
/*
* Setup a ScanKey for a search in the relation 'rel' for a tuple 'key' that
* is setup to match 'rel' (*NOT* idxrel!).
*
* Returns whether any column contains NULLs.
*
* This is not generic routine, it expects the idxrel to be replication
* identity of a rel and meet all limitations associated with that.
*/
static bool
build_replindex_scan_key(ScanKey skey, Relation rel, Relation idxrel,
TupleTableSlot *searchslot)
{
int attoff;
bool isnull;
Datum indclassDatum;
oidvector *opclass;
int2vector *indkey = &idxrel->rd_index->indkey;
bool hasnulls = false;
Assert(RelationGetReplicaIndex(rel) == RelationGetRelid(idxrel));
indclassDatum = SysCacheGetAttr(INDEXRELID, idxrel->rd_indextuple,
Anum_pg_index_indclass, &isnull);
Assert(!isnull);
opclass = (oidvector *) DatumGetPointer(indclassDatum);
/* Build scankey for every attribute in the index. */
for (attoff = 0; attoff < IndexRelationGetNumberOfKeyAttributes(idxrel); attoff++)
{
Oid operator;
Oid opfamily;
RegProcedure regop;
int pkattno = attoff + 1;
int mainattno = indkey->values[attoff];
Oid optype = get_opclass_input_type(opclass->values[attoff]);
/*
* Load the operator info. We need this to get the equality operator
* function for the scan key.
*/
opfamily = get_opclass_family(opclass->values[attoff]);
operator = get_opfamily_member(opfamily, optype,
optype,
BTEqualStrategyNumber);
if (!OidIsValid(operator))
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
BTEqualStrategyNumber, optype, optype, opfamily);
regop = get_opcode(operator);
/* Initialize the scankey. */
ScanKeyInit(&skey[attoff],
pkattno,
BTEqualStrategyNumber,
regop,
searchslot->tts_values[mainattno - 1]);
/* Check for null value. */
if (searchslot->tts_isnull[mainattno - 1])
{
hasnulls = true;
skey[attoff].sk_flags |= SK_ISNULL;
}
}
return hasnulls;
}
示例6: plhaskell_call_handler
Datum
plhaskell_call_handler(PG_FUNCTION_ARGS)
{
Oid fn_oid = fcinfo->flinfo->fn_oid;
HeapTuple procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(fn_oid));
bool isnull;
Datum prosrcdatum = SysCacheGetAttr(PROCOID, procTup, Anum_pg_proc_prosrc, &isnull);
if (isnull)
elog(ERROR, "null prosrc");
Form_pg_proc procStruct = (Form_pg_proc) GETSTRUCT(procTup);
Oid *argTypes;
char **argNames;
char *argModes;
int argCount = get_func_arg_info(procTup, &argTypes, &argNames, &argModes);
Datum *datum = malloc(sizeof(Datum));
int r = plhaskell_test(
TextDatumGetCString(prosrcdatum),
procStruct->prorettype,
datum,
argTypes,
argCount,
fcinfo->arg,
sizeof(Datum)
);
if (r < 0)
elog(ERROR, (const char *) (*datum));
return *datum;
}
示例7: test_indoption
/*
* Common code for properties that are just bit tests of indoptions.
*
* tuple: the pg_index heaptuple
* attno: identify the index column to test the indoptions of.
* guard: if false, a boolean false result is forced (saves code in caller).
* iopt_mask: mask for interesting indoption bit.
* iopt_expect: value for a "true" result (should be 0 or iopt_mask).
*
* Returns false to indicate a NULL result (for "unknown/inapplicable"),
* otherwise sets *res to the boolean value to return.
*/
static bool
test_indoption(HeapTuple tuple, int attno, bool guard,
int16 iopt_mask, int16 iopt_expect,
bool *res)
{
Datum datum;
bool isnull;
int2vector *indoption;
int16 indoption_val;
if (!guard)
{
*res = false;
return true;
}
datum = SysCacheGetAttr(INDEXRELID, tuple,
Anum_pg_index_indoption, &isnull);
Assert(!isnull);
indoption = ((int2vector *) DatumGetPointer(datum));
indoption_val = indoption->values[attno - 1];
*res = (indoption_val & iopt_mask) == iopt_expect;
return true;
}
示例8: GetForeignDataWrapper
/*
* GetForeignDataWrapper - look up the foreign-data wrapper by OID.
*/
ForeignDataWrapper *
GetForeignDataWrapper(Oid fdwid)
{
Form_pg_foreign_data_wrapper fdwform;
ForeignDataWrapper *fdw;
Datum datum;
HeapTuple tp;
bool isnull;
tp = SearchSysCache1(FOREIGNDATAWRAPPEROID, ObjectIdGetDatum(fdwid));
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
fdwform = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp);
fdw = palloc(sizeof(ForeignDataWrapper));
fdw->fdwid = fdwid;
fdw->owner = fdwform->fdwowner;
fdw->fdwname = pstrdup(NameStr(fdwform->fdwname));
fdw->fdwvalidator = fdwform->fdwvalidator;
/* Extract the options */
datum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID,
tp,
Anum_pg_foreign_data_wrapper_fdwoptions,
&isnull);
fdw->options = untransformRelOptions(datum);
ReleaseSysCache(tp);
return fdw;
}
示例9: GetForeignTable
/*
* GetForeignTable - look up the foreign table definition by relation oid.
*/
ForeignTable *
GetForeignTable(Oid relid)
{
Form_pg_foreign_table tableform;
ForeignTable *ft;
HeapTuple tp;
Datum datum;
bool isnull;
tp = SearchSysCache1(FOREIGNTABLEREL, ObjectIdGetDatum(relid));
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for foreign table %u", relid);
tableform = (Form_pg_foreign_table) GETSTRUCT(tp);
ft = (ForeignTable *) palloc(sizeof(ForeignTable));
ft->relid = relid;
ft->serverid = tableform->ftserver;
/* Extract the ftoptions */
datum = SysCacheGetAttr(FOREIGNTABLEREL,
tp,
Anum_pg_foreign_table_ftoptions,
&isnull);
if (isnull)
ft->options = NIL;
else
ft->options = untransformRelOptions(datum);
ReleaseSysCache(tp);
return ft;
}
示例10: statext_dependencies_load
/*
* statext_dependencies_load
* Load the functional dependencies for the indicated pg_statistic_ext tuple
*/
MVDependencies *
statext_dependencies_load(Oid mvoid)
{
MVDependencies *result;
bool isnull;
Datum deps;
HeapTuple htup;
htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(mvoid));
if (!HeapTupleIsValid(htup))
elog(ERROR, "cache lookup failed for statistics object %u", mvoid);
deps = SysCacheGetAttr(STATEXTOID, htup,
Anum_pg_statistic_ext_stxdependencies, &isnull);
if (isnull)
elog(ERROR,
"requested statistic kind \"%c\" is not yet built for statistics object %u",
STATS_EXT_DEPENDENCIES, mvoid);
result = statext_dependencies_deserialize(DatumGetByteaPP(deps));
ReleaseSysCache(htup);
return result;
}
示例11: GetForeignColumnOptions
/*
* GetForeignColumnOptions - Get attfdwoptions of given relation/attnum
* as list of DefElem.
*/
List *
GetForeignColumnOptions(Oid relid, AttrNumber attnum)
{
List *options;
HeapTuple tp;
Datum datum;
bool isnull;
tp = SearchSysCache2(ATTNUM,
ObjectIdGetDatum(relid),
Int16GetDatum(attnum));
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
attnum, relid);
datum = SysCacheGetAttr(ATTNUM,
tp,
Anum_pg_attribute_attfdwoptions,
&isnull);
if (isnull)
options = NIL;
else
options = untransformRelOptions(datum);
ReleaseSysCache(tp);
return options;
}
示例12: statext_ndistinct_load
/*
* statext_ndistinct_load
* Load the ndistinct value for the indicated pg_statistic_ext tuple
*/
MVNDistinct *
statext_ndistinct_load(Oid mvoid)
{
MVNDistinct *result;
bool isnull;
Datum ndist;
HeapTuple htup;
htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(mvoid));
if (!HeapTupleIsValid(htup))
elog(ERROR, "cache lookup failed for statistics object %u", mvoid);
ndist = SysCacheGetAttr(STATEXTOID, htup,
Anum_pg_statistic_ext_stxndistinct, &isnull);
if (isnull)
elog(ERROR,
"requested statistic kind \"%c\" is not yet built for statistics object %u",
STATS_EXT_NDISTINCT, mvoid);
result = statext_ndistinct_deserialize(DatumGetByteaPP(ndist));
ReleaseSysCache(htup);
return result;
}
示例13: HeapTupleOfForeignConstraintIncludesColumn
/*
* HeapTupleOfForeignConstraintIncludesColumn fetches the columns from the foreign
* constraint and checks if the given column name matches one of them.
*/
static bool
HeapTupleOfForeignConstraintIncludesColumn(HeapTuple heapTuple, Oid relationId,
int pgConstraintKey, char *columnName)
{
Datum columnsDatum = 0;
Datum *columnArray = NULL;
int columnCount = 0;
int attrIdx = 0;
bool isNull = false;
columnsDatum = SysCacheGetAttr(CONSTROID, heapTuple, pgConstraintKey, &isNull);
deconstruct_array(DatumGetArrayTypeP(columnsDatum), INT2OID, 2, true,
's', &columnArray, NULL, &columnCount);
for (attrIdx = 0; attrIdx < columnCount; ++attrIdx)
{
AttrNumber attrNo = DatumGetInt16(columnArray[attrIdx]);
char *colName = get_relid_attribute_name(relationId, attrNo);
if (strncmp(colName, columnName, NAMEDATALEN) == 0)
{
return true;
}
}
return false;
}
示例14: caql_getattr_internal
Datum
caql_getattr_internal(cqContext *pCtx, HeapTuple tup,
AttrNumber attnum, bool *isnull)
{
if (pCtx->cq_usesyscache)
return SysCacheGetAttr(pCtx->cq_cacheId, tup, attnum, isnull);
else
return heap_getattr(tup, attnum, pCtx->cq_tupdesc, isnull);
}
示例15: minmax_get_strategy_procinfo
/*
* Cache and return the procedure for the given strategy.
*/
FmgrInfo *
minmax_get_strategy_procinfo(BrinDesc *bdesc, uint16 attno, Oid subtype,
uint16 strategynum)
{
MinmaxOpaque *opaque;
Assert(strategynum >= 1 &&
strategynum <= BTMaxStrategyNumber);
opaque = (MinmaxOpaque *) bdesc->bd_info[attno - 1]->oi_opaque;
/*
* We cache the procedures for the previous subtype in the opaque struct,
* to avoid repetitive syscache lookups. If the subtype changed,
* invalidate all the cached entries.
*/
if (opaque->cached_subtype != subtype)
{
uint16 i;
for (i = 1; i <= BTMaxStrategyNumber; i++)
opaque->strategy_procinfos[i - 1].fn_oid = InvalidOid;
opaque->cached_subtype = subtype;
}
if (opaque->strategy_procinfos[strategynum - 1].fn_oid == InvalidOid)
{
Form_pg_attribute attr;
HeapTuple tuple;
Oid opfamily,
oprid;
bool isNull;
opfamily = bdesc->bd_index->rd_opfamily[attno - 1];
attr = bdesc->bd_tupdesc->attrs[attno - 1];
tuple = SearchSysCache4(AMOPSTRATEGY, ObjectIdGetDatum(opfamily),
ObjectIdGetDatum(attr->atttypid),
ObjectIdGetDatum(subtype),
Int16GetDatum(strategynum));
if (!HeapTupleIsValid(tuple))
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
strategynum, attr->atttypid, subtype, opfamily);
oprid = DatumGetObjectId(SysCacheGetAttr(AMOPSTRATEGY, tuple,
Anum_pg_amop_amopopr, &isNull));
ReleaseSysCache(tuple);
Assert(!isNull && RegProcedureIsValid(oprid));
fmgr_info_cxt(get_opcode(oprid),
&opaque->strategy_procinfos[strategynum - 1],
bdesc->bd_context);
}
return &opaque->strategy_procinfos[strategynum - 1];
}