本文整理汇总了C++中PG_RETURN_BYTEA_P函数的典型用法代码示例。如果您正苦于以下问题:C++ PG_RETURN_BYTEA_P函数的具体用法?C++ PG_RETURN_BYTEA_P怎么用?C++ PG_RETURN_BYTEA_P使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PG_RETURN_BYTEA_P函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pgbloomfun_add
Datum pgbloomfun_add(PG_FUNCTION_ARGS)
{
bytea *newbloomba, *bloomba = PG_GETARG_BYTEA_P(0);
text *key = PG_GETARG_TEXT_P(1);
pgbloom_t *pgbloom = get_pgbloom(bloomba);
bloom_t newbloom, *bloom = NULL;
size_t newbloom_size;
int space_left, i;
space_left = (pgbloom->last_capacity > pgbloom->last_entries) ||
(pgbloom->growth_factor == 0);
for (i=0; i<pgbloom->filters; i++)
{
bloom = next_bloom(bloomba, bloom);
if (bloom == NULL)
{
elog(ERROR, "pgbloomfun: missing filter in bloom object");
}
if (i == pgbloom->filters - 1 && space_left)
{
if (bloom_add(bloom, VARDATA(key), VARSIZE(key) - VARHDRSZ) == 0)
{
pgbloom->total_entries ++;
pgbloom->last_entries ++;
}
PG_RETURN_BYTEA_P(bloomba);
}
else if (bloom_check(bloom, VARDATA(key), VARSIZE(key) - VARHDRSZ))
{
PG_RETURN_BYTEA_P(bloomba); /* key already exists */
}
}
/* create a new filter */
pgbloom->filters += 1;
pgbloom->total_entries += 1;
pgbloom->last_entries = 1;
pgbloom->last_capacity *= pgbloom->growth_factor;
pgbloom->total_capacity += pgbloom->last_capacity;
/* calculate and allocate space */
bloom_init(&newbloom, pgbloom->last_capacity, pgbloom->error_rate);
newbloom_size = sizeof(newbloom) + newbloom.bits / 8;
newbloomba = palloc(VARSIZE(bloomba) + newbloom_size);
memcpy(newbloomba, bloomba, VARSIZE(bloomba));
SET_VARSIZE(newbloomba, VARSIZE(bloomba) + newbloom_size);
/* initialize the new bloom filter and add the new key to it */
bloom = (bloom_t *) (((unsigned char *) newbloomba) + VARSIZE(bloomba));
memset(bloom, 0, newbloom_size);
memcpy(bloom, &newbloom, sizeof(newbloom));
bloom_add(bloom, VARDATA(key), VARSIZE(key) - VARHDRSZ);
PG_RETURN_BYTEA_P(newbloomba);
}
示例2: gistoptions
Datum
gistoptions(PG_FUNCTION_ARGS)
{
Datum reloptions = PG_GETARG_DATUM(0);
bool validate = PG_GETARG_BOOL(1);
relopt_value *options;
GiSTOptions *rdopts;
int numoptions;
static const relopt_parse_elt tab[] = {
{"fillfactor", RELOPT_TYPE_INT, offsetof(GiSTOptions, fillfactor)},
{"buffering", RELOPT_TYPE_STRING, offsetof(GiSTOptions, bufferingModeOffset)}
};
options = parseRelOptions(reloptions, validate, RELOPT_KIND_GIST,
&numoptions);
/* if none set, we're done */
if (numoptions == 0)
PG_RETURN_NULL();
rdopts = allocateReloptStruct(sizeof(GiSTOptions), options, numoptions);
fillRelOptions((void *) rdopts, sizeof(GiSTOptions), options, numoptions,
validate, tab, lengthof(tab));
pfree(options);
PG_RETURN_BYTEA_P(rdopts);
}
示例3: ginoptions
Datum
ginoptions(PG_FUNCTION_ARGS)
{
Datum reloptions = PG_GETARG_DATUM(0);
bool validate = PG_GETARG_BOOL(1);
relopt_value *options;
GinOptions *rdopts;
int numoptions;
static const relopt_parse_elt tab[] = {
{"fastupdate", RELOPT_TYPE_BOOL, offsetof(GinOptions, useFastUpdate)}
};
options = parseRelOptions(reloptions, validate, RELOPT_KIND_GIN,
&numoptions);
/* if none set, we're done */
if (numoptions == 0)
PG_RETURN_NULL();
rdopts = allocateReloptStruct(sizeof(GinOptions), options, numoptions);
fillRelOptions((void *) rdopts, sizeof(GinOptions), options, numoptions,
validate, tab, lengthof(tab));
pfree(options);
PG_RETURN_BYTEA_P(rdopts);
}
示例4: sha_to_bytea_fn
Datum
sha_to_bytea_fn(PG_FUNCTION_ARGS)
{
Sha *value = PG_GETARG_SHA(0);
PG_RETURN_BYTEA_P(hexarr_to_bytea(value->bytes, SHA_LENGTH));
}
示例5: compactmolecule
Datum compactmolecule(PG_FUNCTION_ARGS){
Datum mol_datum = PG_GETARG_DATUM(0);
bool options_xyz = PG_GETARG_BOOL(1);
void* result = 0;
PG_BINGO_BEGIN
{
BingoPgCommon::BingoSessionHandler bingo_handler(fcinfo->flinfo->fn_oid);
bingo_handler.setFunctionName("compactmolecule");
BingoPgText mol_text(mol_datum);
int buf_size;
const char* mol_buf = mol_text.getText(buf_size);
int res_buf;
const char* bingo_result = mangoICM(mol_buf, buf_size, options_xyz, &res_buf);
if(bingo_result == 0) {
CORE_HANDLE_WARNING(0, 1, "bingo.compactmolecule", bingoGetError());
PG_RETURN_NULL();
}
BingoPgText result_data;
result_data.initFromBuffer(bingo_result, res_buf);
result = result_data.release();
}
PG_BINGO_END
if(result == 0)
PG_RETURN_NULL();
PG_RETURN_BYTEA_P(result);
}
示例6: geography_as_binary
Datum geography_as_binary(PG_FUNCTION_ARGS)
{
LWGEOM *lwgeom = NULL;
uint8_t *wkb = NULL;
bytea *wkb_result;
size_t wkb_size = 0;
GSERIALIZED *g = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
/* Get our lwgeom form */
lwgeom = lwgeom_from_gserialized(g);
if ( gserialized_ndims(g) > 2 )
{
/* Strip out the higher dimensions */
LWGEOM *tmp = lwgeom_force_2d(lwgeom);
lwgeom_free(lwgeom);
lwgeom = tmp;
}
/* Create WKB */
wkb = lwgeom_to_wkb(lwgeom, WKB_SFSQL, &wkb_size);
/* Copy to varlena pointer */
wkb_result = palloc(wkb_size + VARHDRSZ);
SET_VARSIZE(wkb_result, wkb_size + VARHDRSZ);
memcpy(VARDATA(wkb_result), wkb, wkb_size);
/* Clean up */
pfree(wkb);
lwgeom_free(lwgeom);
PG_RETURN_BYTEA_P(wkb_result);
}
示例7: 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;
const struct pg_encoding *enc;
datalen = VARSIZE(data) - VARHDRSZ;
namebuf = TextDatumGetCString(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");
SET_VARSIZE(result, VARHDRSZ + res);
PG_RETURN_BYTEA_P(result);
}
示例8: hstore_send
Datum
hstore_send(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 buf;
pq_begintypsend(&buf);
pq_sendint(&buf, count, 4);
for (i = 0; i < count; i++)
{
int32 keylen = HS_KEYLEN(entries, i);
pq_sendint(&buf, keylen, 4);
pq_sendtext(&buf, HS_KEY(entries, base, i), keylen);
if (HS_VALISNULL(entries, i))
{
pq_sendint(&buf, -1, 4);
}
else
{
int32 vallen = HS_VALLEN(entries, i);
pq_sendint(&buf, vallen, 4);
pq_sendtext(&buf, HS_VAL(entries, base, i), vallen);
}
}
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
示例9: ora_nlssort
Datum
ora_nlssort(PG_FUNCTION_ARGS)
{
text *locale;
text *result;
if (PG_ARGISNULL(0))
PG_RETURN_NULL();
if (PG_ARGISNULL(1))
{
if (def_locale != NULL)
locale = def_locale;
else
{
locale = palloc(VARHDRSZ);
SET_VARSIZE(locale, VARHDRSZ);
}
}
else
{
locale = PG_GETARG_TEXT_PP(1);
}
result = _nls_run_strxfrm(PG_GETARG_TEXT_PP(0), locale);
if (! result)
PG_RETURN_NULL();
PG_RETURN_BYTEA_P(result);
}
示例10: pg_digest
Datum
pg_digest(PG_FUNCTION_ARGS)
{
bytea *arg;
text *name;
unsigned len,
hlen;
PX_MD *md;
bytea *res;
name = PG_GETARG_TEXT_P(1);
/* will give error if fails */
md = find_provider(name, (PFN) px_find_digest, "Digest", 0);
hlen = px_md_result_size(md);
res = (text *) palloc(hlen + VARHDRSZ);
SET_VARSIZE(res, hlen + VARHDRSZ);
arg = PG_GETARG_BYTEA_P(0);
len = VARSIZE(arg) - VARHDRSZ;
px_md_update(md, (uint8 *) VARDATA(arg), len);
px_md_finish(md, (uint8 *) VARDATA(res));
px_md_free(md);
PG_FREE_IF_COPY(arg, 0);
PG_FREE_IF_COPY(name, 1);
PG_RETURN_BYTEA_P(res);
}
示例11: pgbloomfun_init
Datum pgbloomfun_init(PG_FUNCTION_ARGS)
{
int capacity = PG_GETARG_INT32(0);
int growth_factor = PG_GETARG_INT32(1);
double error_rate = PG_GETARG_FLOAT8(2);
pgbloom_t pgbloom;
size_t bloom_size;
bytea *res;
if (capacity <= 0)
elog(ERROR, "pgbloomfun: bloom filter capacity must be positive");
if (growth_factor < 0 || growth_factor > 1000)
elog(ERROR, "pgbloomfun: growth factor must be between 0 and 1000");
if (error_rate <= 0.0 || error_rate >= 1.0)
elog(ERROR, "pgbloomfun: error rate must be higher than 0.0 and lower than 1.0");
pgbloom.version = PGBLOOM_VERSION;
pgbloom.total_entries = pgbloom.last_entries = 0;
pgbloom.total_capacity = pgbloom.last_capacity = capacity;
pgbloom.growth_factor = growth_factor;
pgbloom.error_rate = error_rate;
pgbloom.filters = 1;
bloom_init(&pgbloom.bloom, capacity, error_rate);
bloom_size = sizeof(pgbloom) + pgbloom.bloom.bits / 8;
res = palloc(VARHDRSZ + bloom_size);
SET_VARSIZE(res, VARHDRSZ + bloom_size);
memset(VARDATA(res), 0, bloom_size);
memcpy(VARDATA(res), &pgbloom, sizeof(pgbloom));
PG_RETURN_BYTEA_P(res);
}
示例12: pg_read_binary_file
/*
* Read a section of a file, returning it as bytea
*/
Datum
pg_read_binary_file(PG_FUNCTION_ARGS)
{
text *filename_t = PG_GETARG_TEXT_PP(0);
int64 seek_offset = 0;
int64 bytes_to_read = -1;
bool missing_ok = false;
char *filename;
bytea *result;
/* handle optional arguments */
if (PG_NARGS() >= 3)
{
seek_offset = PG_GETARG_INT64(1);
bytes_to_read = PG_GETARG_INT64(2);
if (bytes_to_read < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("requested length cannot be negative")));
}
if (PG_NARGS() >= 4)
missing_ok = PG_GETARG_BOOL(3);
filename = convert_and_check_filename(filename_t);
result = read_binary_file(filename, seek_offset,
bytes_to_read, missing_ok);
if (result)
PG_RETURN_BYTEA_P(result);
else
PG_RETURN_NULL();
}
示例13: bloptions
Datum
bloptions(PG_FUNCTION_ARGS)
{
Datum reloptions = PG_GETARG_DATUM(0);
bool validate = PG_GETARG_BOOL(1);
relopt_value *options;
int numoptions;
BloomOptions *rdopts;
relopt_parse_elt tab[INDEX_MAX_KEYS+1];
int i;
char buf[16];
tab[0].optname = "length";
tab[0].opttype = RELOPT_TYPE_INT;
tab[0].offset = offsetof(BloomOptions, bloomLength);
for(i=0;i<INDEX_MAX_KEYS;i++)
{
snprintf(buf, sizeof(buf), "col%d", i+1);
tab[i+1].optname = pstrdup(buf);
tab[i+1].opttype = RELOPT_TYPE_INT;
tab[i+1].offset = offsetof(BloomOptions, bitSize[i]);
}
options = parseRelOptions(reloptions, validate, bloom_kind, &numoptions);
rdopts = allocateReloptStruct(sizeof(BloomOptions), options, numoptions);
fillRelOptions((void *) rdopts, sizeof(BloomOptions), options, numoptions,
validate, tab, INDEX_MAX_KEYS+1);
rdopts = makeDefaultBloomOptions(rdopts);
PG_RETURN_BYTEA_P(rdopts);
}
示例14: x509_get_serial_number
Datum x509_get_serial_number(PG_FUNCTION_ARGS) {
bytea *raw;
bytea *result;
BIGNUM *bn;
X509 *cert;
// check for null value.
raw = PG_GETARG_BYTEA_P(0);
if (raw == NULL || VARSIZE(raw) == VARHDRSZ) {
PG_RETURN_NULL();
}
cert = x509_from_bytea(raw);
if (cert == NULL) {
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED), errmsg(
"unable to decode X509 record")));
}
bn = ASN1_INTEGER_to_BN(X509_get_serialNumber(cert), NULL);
result = bn_to_bytea(bn);
BN_free(bn);
X509_free(cert);
PG_RETURN_BYTEA_P(result);
}
示例15: x509_in
Datum x509_in(PG_FUNCTION_ARGS) {
char *txt;
bytea *result;
X509 *x509;
// check for null input
txt = PG_GETARG_CSTRING(0);
if (txt == NULL || strlen(txt) == 0) {
PG_RETURN_NULL();
}
// write X509 cert into buffer
x509 = x509_from_string(txt);
if (x509 == NULL) {
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED), errmsg(
"unable to decode X509 record")));
PG_RETURN_NULL();
}
result = x509_to_bytea(x509);
X509_free(x509);
// return bytea
PG_RETURN_BYTEA_P(result);
}