本文整理汇总了C++中TupleDescGetAttInMetadata函数的典型用法代码示例。如果您正苦于以下问题:C++ TupleDescGetAttInMetadata函数的具体用法?C++ TupleDescGetAttInMetadata怎么用?C++ TupleDescGetAttInMetadata使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TupleDescGetAttInMetadata函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tt_setup_firstcall
static void
tt_setup_firstcall(FuncCallContext *funcctx, Oid prsid)
{
TupleDesc tupdesc;
MemoryContext oldcontext;
TSTokenTypeStorage *st;
TSParserCacheEntry *prs = lookup_ts_parser_cache(prsid);
if (!OidIsValid(prs->lextypeOid))
elog(ERROR, "method lextype isn't defined for text search parser %u",
prsid);
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
st = (TSTokenTypeStorage *) palloc(sizeof(TSTokenTypeStorage));
st->cur = 0;
/* lextype takes one dummy argument */
st->list = (LexDescr *) DatumGetPointer(OidFunctionCall1(prs->lextypeOid,
(Datum) 0));
funcctx->user_fctx = (void *) st;
tupdesc = CreateTemplateTupleDesc(3, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "tokid",
INT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "alias",
TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
TEXTOID, -1, 0);
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcontext);
}
示例2: dbms_alert_waitone
Datum
dbms_alert_waitone(PG_FUNCTION_ARGS)
{
text *name;
float8 timeout;
TupleDesc tupdesc;
AttInMetadata *attinmeta;
HeapTuple tuple;
Datum result;
int message_id;
char *str[2] = {NULL,"1"};
char *event_name;
int cycle = 0;
float8 endtime;
TupleDesc btupdesc;
if (PG_ARGISNULL(0))
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("event name is NULL"),
errdetail("Eventname may not be NULL.")));
if (PG_ARGISNULL(1))
timeout = TDAYS;
else
timeout = PG_GETARG_FLOAT8(1);
name = PG_GETARG_TEXT_P(0);
WATCH_PRE(timeout, endtime, cycle);
if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false))
{
if (NULL != find_event(name, false, &message_id))
{
str[0] = find_and_remove_message_item(message_id, sid,
false, false, false, NULL, &event_name);
if (event_name != NULL)
{
str[1] = "0";
pfree(event_name);
LWLockRelease(shmem_lock);
break;
}
}
LWLockRelease(shmem_lock);
}
WATCH_POST(timeout, endtime, cycle);
get_call_result_type(fcinfo, NULL, &tupdesc);
btupdesc = BlessTupleDesc(tupdesc);
attinmeta = TupleDescGetAttInMetadata(btupdesc);
tuple = BuildTupleFromCStrings(attinmeta, str);
result = HeapTupleGetDatum(tuple);
if (str[0])
pfree(str[0]);
return result;
}
示例3: plphp_htup_from_zval
/*
* plphp_htup_from_zval
* Build a HeapTuple from a zval (which must be an array) and a TupleDesc.
*
* The return HeapTuple is allocated in the current memory context and must
* be freed by the caller.
*
* If zval doesn't contain any of the element names from the TupleDesc,
* build a tuple from the first N elements. This allows us to accept
* arrays in form array(1,2,3) as the result of functions with OUT arguments.
* XXX -- possible optimization: keep the memory context created and only
* reset it between calls.
*/
HeapTuple
plphp_htup_from_zval(zval *val, TupleDesc tupdesc)
{
MemoryContext oldcxt;
MemoryContext tmpcxt;
HeapTuple ret;
AttInMetadata *attinmeta;
HashPosition pos;
zval **element;
char **values;
int i;
bool allempty = true;
tmpcxt = AllocSetContextCreate(TopTransactionContext,
"htup_from_zval cxt",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
oldcxt = MemoryContextSwitchTo(tmpcxt);
values = (char **) palloc(tupdesc->natts * sizeof(char *));
for (i = 0; i < tupdesc->natts; i++)
{
char *key = SPI_fname(tupdesc, i + 1);
zval *scalarval = plphp_array_get_elem(val, key);
values[i] = plphp_zval_get_cstring(scalarval, true, true);
/*
* Reset the flag is even one of the keys actually exists,
* even if it is NULL.
*/
if (scalarval != NULL)
allempty = false;
}
/* None of the names from the tuple exists,
* try to get 1st N array elements and assign them to the tuple
*/
if (allempty)
for (i = 0,
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(val), &pos);
(zend_hash_get_current_data_ex(Z_ARRVAL_P(val),
(void **) &element,
&pos) == SUCCESS) &&
(i < tupdesc->natts);
zend_hash_move_forward_ex(Z_ARRVAL_P(val), &pos), i++)
values[i] = plphp_zval_get_cstring(element[0], true, true);
attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcxt);
ret = BuildTupleFromCStrings(attinmeta, values);
MemoryContextDelete(tmpcxt);
return ret;
}
示例4: prs_setup_firstcall
static void
prs_setup_firstcall(FuncCallContext *funcctx, Oid prsid, text *txt)
{
TupleDesc tupdesc;
MemoryContext oldcontext;
PrsStorage *st;
TSParserCacheEntry *prs = lookup_ts_parser_cache(prsid);
char *lex = NULL;
int llen = 0,
type = 0;
void *prsdata;
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
st = (PrsStorage *) palloc(sizeof(PrsStorage));
st->cur = 0;
st->len = 16;
st->list = (LexemeEntry *) palloc(sizeof(LexemeEntry) * st->len);
prsdata = (void *) DatumGetPointer(FunctionCall2(&prs->prsstart,
PointerGetDatum(VARDATA(txt)),
Int32GetDatum(VARSIZE(txt) - VARHDRSZ)));
while ((type = DatumGetInt32(FunctionCall3(&prs->prstoken,
PointerGetDatum(prsdata),
PointerGetDatum(&lex),
PointerGetDatum(&llen)))) != 0)
{
if (st->cur >= st->len)
{
st->len = 2 * st->len;
st->list = (LexemeEntry *) repalloc(st->list, sizeof(LexemeEntry) * st->len);
}
st->list[st->cur].lexeme = palloc(llen + 1);
memcpy(st->list[st->cur].lexeme, lex, llen);
st->list[st->cur].lexeme[llen] = '\0';
st->list[st->cur].type = type;
st->cur++;
}
FunctionCall1(&prs->prsend, PointerGetDatum(prsdata));
st->len = st->cur;
st->cur = 0;
funcctx->user_fctx = (void *) st;
tupdesc = CreateTemplateTupleDesc(2, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "tokid",
INT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "token",
TEXTOID, -1, 0);
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcontext);
}
示例5: dbms_alert_waitany
Datum
dbms_alert_waitany(PG_FUNCTION_ARGS)
{
float8 timeout;
TupleDesc tupdesc;
AttInMetadata *attinmeta;
HeapTuple tuple;
Datum result;
char *str[3] = {NULL, NULL, "1"};
int cycle = 0;
float8 endtime;
TupleDesc btupdesc;
if (PG_ARGISNULL(0))
timeout = TDAYS;
else
timeout = PG_GETARG_FLOAT8(0);
WATCH_PRE(timeout, endtime, cycle);
if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false))
{
str[1] = find_and_remove_message_item(-1, sid,
true, false, false, NULL, &str[0]);
if (str[0])
{
str[2] = "0";
LWLockRelease(shmem_lock);
break;
}
LWLockRelease(shmem_lock);
}
WATCH_POST(timeout, endtime, cycle);
get_call_result_type(fcinfo, NULL, &tupdesc);
btupdesc = BlessTupleDesc(tupdesc);
attinmeta = TupleDescGetAttInMetadata(btupdesc);
tuple = BuildTupleFromCStrings(attinmeta, str);
result = HeapTupleGetDatum(tuple);
if (str[0])
pfree(str[0]);
if (str[1])
pfree(str[1]);
return result;
}
示例6: ts_setup_firstcall
static void
ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
TSVectorStat *stat)
{
TupleDesc tupdesc;
MemoryContext oldcontext;
StatEntry *node;
funcctx->user_fctx = (void *) stat;
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
stat->stack = palloc0(sizeof(StatEntry *) * (stat->maxdepth + 1));
stat->stackpos = 0;
node = stat->root;
/* find leftmost value */
if (node == NULL)
stat->stack[stat->stackpos] = NULL;
else
for (;;)
{
stat->stack[stat->stackpos] = node;
if (node->left)
{
stat->stackpos++;
node = node->left;
}
else
break;
}
Assert(stat->stackpos <= stat->maxdepth);
tupdesc = CreateTemplateTupleDesc(3, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word",
TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "ndoc",
INT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "nentry",
INT4OID, -1, 0);
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcontext);
}
示例7: testfunc5
Datum
testfunc5(PG_FUNCTION_ARGS)
{
int64 i = PG_GETARG_INT64(0);
FuncCallContext *funcctx;
MemoryContext oldcontext;
if (SRF_IS_FIRSTCALL())
{
TupleDesc tupd;
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
tupd = CreateTemplateTupleDesc(2, false);
TupleDescInitEntry(tupd, 1, "c1", INT8OID, -1, 0);
TupleDescInitEntry(tupd, 2, "c2", INT8OID, -1, 0);
funcctx->max_calls = 3;
funcctx->user_fctx = tupd;
MemoryContextSwitchTo(oldcontext);
}
funcctx = SRF_PERCALL_SETUP();
if (funcctx->call_cntr < funcctx->max_calls)
{
TupleDesc tupd;
HeapTupleData tupleData;
HeapTuple tuple = &tupleData;
char *values[2];
Datum result;
tupd = (TupleDesc)funcctx->user_fctx;
values[0] = palloc(32);
sprintf(values[0], INT64_FORMAT, i+1+funcctx->call_cntr);
values[1] = palloc(32);
sprintf(values[1], INT64_FORMAT, i+2+funcctx->call_cntr);
tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupd), values);
result = TupleGetDatum(TupleDescGetSlot(tuple), tuple);
SRF_RETURN_NEXT(funcctx, result);
}
else
{
SRF_RETURN_DONE(funcctx);
}
}
示例8: make_new_order_info
Datum make_new_order_info(PG_FUNCTION_ARGS)
{
/* result Datum */
Datum result;
char** cstr_values;
HeapTuple result_tuple;
/* tuple manipulating variables */
TupleDesc tupdesc;
TupleTableSlot *slot;
AttInMetadata *attinmeta;
/* loop variables. */
int i;
/* get tupdesc from the type name */
tupdesc = RelationNameGetTupleDesc("new_order_info");
/* allocate a slot for a tuple with this tupdesc */
slot = TupleDescGetSlot(tupdesc);
/*
* generate attribute metadata needed later to produce tuples
* from raw C strings
*/
attinmeta = TupleDescGetAttInMetadata(tupdesc);
cstr_values = (char **) palloc(3 * sizeof(char *));
for(i = 0; i < 3; i++) {
cstr_values[i] = (char*) palloc(16 * sizeof(char)); /* 16 bytes */
snprintf(cstr_values[i], 16, "%d", PG_GETARG_INT32(i));
}
/* build a tuple */
result_tuple = BuildTupleFromCStrings(attinmeta, cstr_values);
/* make the tuple into a datum */
result = TupleGetDatum(slot, result_tuple);
return result;
}
示例9: setup_firstcall
static void
setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx, Oid prsid)
{
TupleDesc tupdesc;
MemoryContext oldcontext;
TypeStorage *st;
WParserInfo *prs = findprs(prsid);
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
st = (TypeStorage *) palloc(sizeof(TypeStorage));
st->cur = 0;
st->list = (LexDescr *) DatumGetPointer(
OidFunctionCall1(prs->lextype, PointerGetDatum(prs->prs))
);
funcctx->user_fctx = (void *) st;
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
tupdesc = CreateTupleDescCopy(tupdesc);
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcontext);
}
示例10: testfunc3
Datum
testfunc3(PG_FUNCTION_ARGS)
{
TupleDesc tupd;
HeapTupleData tupleData;
HeapTuple tuple = &tupleData;
char *values[2];
Datum result;
int64 i = PG_GETARG_INT64(0);
tupd = CreateTemplateTupleDesc(2, false);
TupleDescInitEntry(tupd, 1, "c1", INT8OID, -1, 0);
TupleDescInitEntry(tupd, 2, "c2", INT8OID, -1, 0);
values[0] = palloc(32);
sprintf(values[0], INT64_FORMAT, i+1);
values[1] = palloc(32);
sprintf(values[1], INT64_FORMAT, i+2);
tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupd), values);
result = TupleGetDatum(TupleDescGetSlot(tuple), tuple);
PG_RETURN_DATUM(result);
}
示例11: build_pgstattuple_type
/*
* build_pgstattuple_type -- build a pgstattuple_type tuple
*/
static Datum
build_pgstattuple_type(pgstattuple_type *stat, FunctionCallInfo fcinfo)
{
#define NCOLUMNS 9
#define NCHARS 32
HeapTuple tuple;
char *values[NCOLUMNS];
char values_buf[NCOLUMNS][NCHARS];
int i;
double tuple_percent;
double dead_tuple_percent;
double free_percent; /* free/reusable space in % */
TupleDesc tupdesc;
AttInMetadata *attinmeta;
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
/*
* Generate attribute metadata needed later to produce tuples from raw C
* strings
*/
attinmeta = TupleDescGetAttInMetadata(tupdesc);
if (stat->table_len == 0)
{
tuple_percent = 0.0;
dead_tuple_percent = 0.0;
free_percent = 0.0;
}
else
{
tuple_percent = 100.0 * stat->tuple_len / stat->table_len;
dead_tuple_percent = 100.0 * stat->dead_tuple_len / stat->table_len;
free_percent = 100.0 * stat->free_space / stat->table_len;
}
/*
* Prepare a values array for constructing the tuple. This should be an
* array of C strings which will be processed later by the appropriate
* "in" functions.
*/
for (i = 0; i < NCOLUMNS; i++)
values[i] = values_buf[i];
i = 0;
snprintf(values[i++], NCHARS, INT64_FORMAT, stat->table_len);
snprintf(values[i++], NCHARS, INT64_FORMAT, stat->tuple_count);
snprintf(values[i++], NCHARS, INT64_FORMAT, stat->tuple_len);
snprintf(values[i++], NCHARS, "%.2f", tuple_percent);
snprintf(values[i++], NCHARS, INT64_FORMAT, stat->dead_tuple_count);
snprintf(values[i++], NCHARS, INT64_FORMAT, stat->dead_tuple_len);
snprintf(values[i++], NCHARS, "%.2f", dead_tuple_percent);
snprintf(values[i++], NCHARS, INT64_FORMAT, stat->free_space);
snprintf(values[i++], NCHARS, "%.2f", free_percent);
/* build a tuple */
tuple = BuildTupleFromCStrings(attinmeta, values);
/* make the tuple into a datum */
return HeapTupleGetDatum(tuple);
}
示例12: TradeStatusFrame1
//.........这里部分代码省略.........
strcat(values[i_status_name], SPI_getvalue(tuple, tupdesc, 3));
strcat(values[i_status_name], "\"");
strcat(values[i_type_name], "\"");
strcat(values[i_type_name], SPI_getvalue(tuple, tupdesc, 4));
strcat(values[i_type_name], "\"");
strcat(values[i_symbol], "\"");
strcat(values[i_symbol], SPI_getvalue(tuple, tupdesc, 5));
strcat(values[i_symbol], "\"");
strcat(values[i_trade_qty], SPI_getvalue(tuple, tupdesc, 6));
strcat(values[i_exec_name], "\"");
strcat(values[i_exec_name], SPI_getvalue(tuple, tupdesc, 7));
strcat(values[i_exec_name], "\"");
strcat(values[i_charge], SPI_getvalue(tuple, tupdesc, 8));
strcat(values[i_s_name], "\"");
strcat(values[i_s_name], SPI_getvalue(tuple, tupdesc, 9));
strcat(values[i_s_name], "\"");
strcat(values[i_ex_name], "\"");
strcat(values[i_ex_name], SPI_getvalue(tuple, tupdesc, 10));
strcat(values[i_ex_name], "\"");
}
strcat(values[i_trade_id], "}");
strcat(values[i_trade_dts], "}");
strcat(values[i_status_name], "}");
strcat(values[i_type_name], "}");
strcat(values[i_symbol], "}");
strcat(values[i_trade_qty], "}");
strcat(values[i_exec_name], "}");
strcat(values[i_charge], "}");
strcat(values[i_s_name], "}");
strcat(values[i_ex_name], "}");
#ifdef DEBUG
sprintf(sql, SQLTSF1_2, acct_id);
elog(NOTICE, "SQL\n%s", sql);
#endif /* DEBUG */
ret = SPI_execute_plan(TSF1_2, args, nulls, true, 0);
if (ret == SPI_OK_SELECT) {
tupdesc = SPI_tuptable->tupdesc;
tuptable = SPI_tuptable;
if (SPI_processed > 0) {
tuple = tuptable->vals[0];
values[i_cust_l_name] = SPI_getvalue(tuple, tupdesc, 1);
values[i_cust_f_name] = SPI_getvalue(tuple, tupdesc, 2);
values[i_broker_name] = SPI_getvalue(tuple, tupdesc, 3);
}
} else {
FAIL_FRAME_SET(&funcctx->max_calls, TSF1_statements[1].sql);
dump_tsf1_inputs(acct_id);
}
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) !=
TYPEFUNC_COMPOSITE) {
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function returning record called in context "
"that cannot accept type record")));
}
/*
* generate attribute metadata needed later to produce tuples from raw
* C strings
*/
attinmeta = TupleDescGetAttInMetadata(tupdesc);
funcctx->attinmeta = attinmeta;
MemoryContextSwitchTo(TSF1_savedcxt);
}
/* stuff done on every call of the function */
funcctx = SRF_PERCALL_SETUP();
call_cntr = funcctx->call_cntr;
max_calls = funcctx->max_calls;
attinmeta = funcctx->attinmeta;
if (call_cntr < max_calls) {
/* do when there is more left to send */
HeapTuple tuple;
Datum result;
#ifdef DEBUG
for (i = 0; i < 14; i++) {
elog(NOTICE, "TSF1 OUT: %d %s", i, values[i]);
}
#endif /* DEBUG */
/* Build a tuple. */
tuple = BuildTupleFromCStrings(attinmeta, values);
/* Make the tuple into a datum. */
result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
} else {
/* Do when there is no more left. */
SPI_finish();
if (TSF1_savedcxt) MemoryContextSwitchTo(TSF1_savedcxt);
SRF_RETURN_DONE(funcctx);
}
}
示例13: MarketFeedFrame1
//.........这里部分代码省略.........
if (ret != SPI_OK_INSERT) {
dump_mff1_inputs(price_quote_p, status_submitted_p,
symbol_p, trade_qty, type_limit_buy_p,
type_limit_sell_p, type_stop_loss_p);
FAIL_FRAME_SET(&funcctx->max_calls, MFF1_statements[4].sql);
}
++rows_sent;
#ifdef DEBUG
elog(NOTICE, "%d row(s) sent", rows_sent);
#endif /* DEBUG */
if (count > 0) {
strcat(values[i_symbol], ",");
strcat(values[i_trade_id], ",");
strcat(values[i_price_quote], ",");
strcat(values[i_trade_type], ",");
strcat(values[i_trade_qty], ",");
}
strcat(values[i_symbol], symbol);
strcat(values[i_trade_id], trade_id);
strcat(values[i_price_quote], req_price_quote);
strcat(values[i_trade_type], req_trade_type);
strcat(values[i_trade_qty], req_trade_qty);
++count;
}
/* FIXME: BEGIN/COMMIT statements not supported with SPI. */
/*
ret = SPI_exec("COMMIT;", 0);
if (ret == SPI_OK_SELECT) {
} else {
elog(NOTICE, "ERROR: COMMIT not ok = %d", ret);
}
*/
send_len += rows_sent;
p_s = att_addlength_pointer(p_s, typlen_s, p_s);
p_s = (char *) att_align_nominal(p_s, typalign_s);
}
strcat(values[i_symbol], "}");
strcat(values[i_trade_id], "}");
strcat(values[i_price_quote], "}");
strcat(values[i_trade_qty], "}");
strcat(values[i_trade_type], "}");
sprintf(values[i_num_updated], "%d", num_updated);
sprintf(values[i_send_len], "%d", send_len);
funcctx->max_calls = 1;
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) !=
TYPEFUNC_COMPOSITE) {
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function returning record called in context "
"that cannot accept type record")));
}
/*
* generate attribute metadata needed later to produce tuples from raw
* C strings
*/
attinmeta = TupleDescGetAttInMetadata(tupdesc);
funcctx->attinmeta = attinmeta;
MemoryContextSwitchTo(oldcontext);
}
/* stuff done on every call of the function */
funcctx = SRF_PERCALL_SETUP();
call_cntr = funcctx->call_cntr;
max_calls = funcctx->max_calls;
attinmeta = funcctx->attinmeta;
if (call_cntr < max_calls) {
/* do when there is more left to send */
HeapTuple tuple;
Datum result;
#ifdef DEBUG
for (i = 0; i < 7; i++) {
elog(NOTICE, "MFF1 OUT: %d %s", i, values[i]);
}
#endif /* DEBUG */
/* Build a tuple. */
tuple = BuildTupleFromCStrings(attinmeta, values);
/* Make the tuple into a datum. */
result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
} else {
/* Do when there is no more left. */
SPI_finish();
SRF_RETURN_DONE(funcctx);
}
}
示例14: pg_get_keywords
/* Function to return the list of grammar keywords */
Datum
pg_get_keywords(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
if (SRF_IS_FIRSTCALL())
{
MemoryContext oldcontext;
TupleDesc tupdesc;
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
tupdesc = CreateTemplateTupleDesc(3, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word",
TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "catcode",
CHAROID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "catdesc",
TEXTOID, -1, 0);
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcontext);
}
funcctx = SRF_PERCALL_SETUP();
if (funcctx->call_cntr < NumScanKeywords)
{
char *values[3];
HeapTuple tuple;
/* cast-away-const is ugly but alternatives aren't much better */
values[0] = (char *) ScanKeywords[funcctx->call_cntr].name;
switch (ScanKeywords[funcctx->call_cntr].category)
{
case UNRESERVED_KEYWORD:
values[1] = "U";
values[2] = _("unreserved");
break;
case COL_NAME_KEYWORD:
values[1] = "C";
values[2] = _("unreserved (cannot be function or type name)");
break;
case TYPE_FUNC_NAME_KEYWORD:
values[1] = "T";
values[2] = _("reserved (can be function or type name)");
break;
case RESERVED_KEYWORD:
values[1] = "R";
values[2] = _("reserved");
break;
default: /* shouldn't be possible */
values[1] = NULL;
values[2] = NULL;
break;
}
tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
}
SRF_RETURN_DONE(funcctx);
}
示例15: connection_limits
Datum
connection_limits(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
TupleDesc tupdesc;
AttInMetadata *attinmeta;
/* init on the first call */
if (SRF_IS_FIRSTCALL())
{
MemoryContext oldcontext;
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
reset_rules();
check_all_rules();
/* number of rules */
funcctx->max_calls = rules->n_rules;
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function returning record called in context "
"that cannot accept type record")));
/*
* generate attribute metadata needed later to produce tuples from raw
* C strings
*/
attinmeta = TupleDescGetAttInMetadata(tupdesc);
funcctx->attinmeta = attinmeta;
funcctx->tuple_desc = tupdesc;
/* switch back to the old context */
MemoryContextSwitchTo(oldcontext);
}
/* init the context */
funcctx = SRF_PERCALL_SETUP();
/* check if we have more data */
if (funcctx->max_calls > funcctx->call_cntr)
{
HeapTuple tuple;
Datum result;
Datum values[6];
bool nulls[6];
rule_t * rule = &(rules->rules[funcctx->call_cntr]);
memset(nulls, 0, sizeof(nulls));
/* rule line */
values[0] = UInt32GetDatum(rule->line);
/* database */
if (rule->fields & CHECK_DBNAME)
values[1] = CStringGetTextDatum(rule->database);
else
nulls[1] = TRUE;
/* username */
if (rule->fields & CHECK_USER)
values[2] = CStringGetTextDatum(rule->user);
else
nulls[2] = TRUE;
/* hostname or IP address */
if (rule->fields & CHECK_HOST)
values[3] = CStringGetTextDatum(rule->hostname);
else if (rule->fields & CHECK_IP)
{
char buffer[256];
memset(buffer, 0, 256);
format_address(buffer, 256, (struct sockaddr*)&rule->ip, (struct sockaddr*)&rule->mask);
values[3] = CStringGetTextDatum(buffer);
}
else
nulls[3] = TRUE;
/* count and limit */
values[4] = UInt32GetDatum(rule->count);
values[5] = UInt32GetDatum(rule->limit);
/* Build and return the tuple. */
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
/* make the tuple into a datum */
result = HeapTupleGetDatum(tuple);
/* Here we want to return another item: */
SRF_RETURN_NEXT(funcctx, result);
//.........这里部分代码省略.........