当前位置: 首页>>代码示例>>C++>>正文


C++ VARATT_SIZEP函数代码示例

本文整理汇总了C++中VARATT_SIZEP函数的典型用法代码示例。如果您正苦于以下问题:C++ VARATT_SIZEP函数的具体用法?C++ VARATT_SIZEP怎么用?C++ VARATT_SIZEP使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了VARATT_SIZEP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: heap_tuple_untoast_attr_slice

/* ----------
 * heap_tuple_untoast_attr_slice -
 *
 *		Public entry point to get back part of a toasted value
 *		from compression or external storage.
 * ----------
 */
varattrib *
heap_tuple_untoast_attr_slice(varattrib *attr, int32 sliceoffset, int32 slicelength)
{
    varattrib  *preslice;
    varattrib  *result;
    int32		attrsize;

    if (VARATT_IS_COMPRESSED(attr))
    {
        varattrib  *tmp;

        if (VARATT_IS_EXTERNAL(attr))
            tmp = toast_fetch_datum(attr);
        else
        {
            tmp = attr;			/* compressed in main tuple */
        }

        preslice = (varattrib *) palloc(attr->va_content.va_external.va_rawsize
                                        + VARHDRSZ);
        VARATT_SIZEP(preslice) = attr->va_content.va_external.va_rawsize + VARHDRSZ;
        pglz_decompress((PGLZ_Header *) tmp, VARATT_DATA(preslice));

        if (tmp != attr)
            pfree(tmp);
    }
    else
    {
        /* Plain value */
        if (VARATT_IS_EXTERNAL(attr))
        {
            /* fast path */
            return (toast_fetch_datum_slice(attr, sliceoffset, slicelength));
        }
        else
            preslice = attr;
    }

    /* slicing of datum for compressed cases and plain value */

    attrsize = VARSIZE(preslice) - VARHDRSZ;
    if (sliceoffset >= attrsize)
    {
        sliceoffset = 0;
        slicelength = 0;
    }

    if (((sliceoffset + slicelength) > attrsize) || slicelength < 0)
        slicelength = attrsize - sliceoffset;

    result = (varattrib *) palloc(slicelength + VARHDRSZ);
    VARATT_SIZEP(result) = slicelength + VARHDRSZ;

    memcpy(VARDATA(result), VARDATA(preslice) + sliceoffset, slicelength);

    if (preslice != attr)
        pfree(preslice);

    return result;
}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:67,代码来源:tuptoaster.c

示例2: heap_tuple_untoast_attr

/* ----------
 * heap_tuple_untoast_attr -
 *
 *	Public entry point to get back a toasted value from compression
 *	or external storage.
 * ----------
 */
varattrib *
heap_tuple_untoast_attr(varattrib *attr)
{
    varattrib  *result;

    if (VARATT_IS_EXTERNAL(attr))
    {
        if (VARATT_IS_COMPRESSED(attr))
        {
            /* ----------
             * This is an external stored compressed value
             * Fetch it from the toast heap and decompress.
             * ----------
             */
            varattrib  *tmp;

            tmp = toast_fetch_datum(attr);
            result = (varattrib *) palloc(attr->va_content.va_external.va_rawsize
                                          + VARHDRSZ);
            VARATT_SIZEP(result) = attr->va_content.va_external.va_rawsize
                + VARHDRSZ;
            pglz_decompress((PGLZ_Header *) tmp, VARATT_DATA(result));

            pfree(tmp);
        }
        else
        {
            /*
             * This is an external stored plain value
             */
            result = toast_fetch_datum(attr);
        }
    }
    else if (VARATT_IS_COMPRESSED(attr))
    {
        /*
         * This is a compressed value inside of the main tuple
         */
        result = (varattrib *) palloc(attr->va_content.va_compressed.va_rawsize
                                      + VARHDRSZ);
        VARATT_SIZEP(result) = attr->va_content.va_compressed.va_rawsize
            + VARHDRSZ;
        pglz_decompress((PGLZ_Header *) attr, VARATT_DATA(result));
    }
    else

        /*
         * This is a plain value inside of the main tuple - why am I
         * called?
         */
        return attr;

    return result;
}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:61,代码来源:tuptoaster.c

示例3: String_createText

text* String_createText(jstring javaString)
{
    text* result = 0;
    if(javaString != 0)
    {
        /* Would be nice if a direct conversion from UTF16 was provided.
         */
        char* utf8 = (char*)JNI_getStringUTFChars(javaString, 0);
        char* denc = (char*)pg_do_encoding_conversion(
            (unsigned char*)utf8, strlen(utf8), PG_UTF8, GetDatabaseEncoding());
        int dencLen = strlen(denc);
        int varSize = dencLen + VARHDRSZ;

        /* Allocate and initialize the text structure.
         */
        result = (text*)palloc(varSize);
#if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 3)
        VARATT_SIZEP(result) = varSize;	/* Total size of structure, not just data */
#else
        SET_VARSIZE(result, varSize);	/* Total size of structure, not just data */
#endif
        memcpy(VARDATA(result), denc, dencLen);

        /* pg_do_encoding_conversion will return the source argument
         * when no conversion is required. We don't want to accidentally
         * free that pointer.
         */
        if(denc != utf8)
            pfree(denc);
        JNI_releaseStringUTFChars(javaString, utf8);
    }
    return result;
}
开发者ID:DacKiller,项目名称:pljava,代码行数:33,代码来源:String.c

示例4: ASN1_STRING_to_text

/*
 * Converts OpenSSL ASN1_STRING structure into text
 *
 * Converts ASN1_STRING into text, converting all the characters into
 * current database encoding if possible.  Any invalid characters are
 * replaced by question marks.
 *
 * Parameter: str - OpenSSL ASN1_STRING structure.	Memory managment
 * of this structure is responsibility of caller.
 *
 * Returns Datum, which can be directly returned from a C language SQL
 * function.
 */
Datum
ASN1_STRING_to_text(ASN1_STRING *str)
{
    BIO		   *membuf = NULL;
    size_t		size,
                outlen;
    char	   *sp;
    char	   *dp;
    text	   *result;

    membuf = BIO_new(BIO_s_mem());
    (void) BIO_set_close(membuf, BIO_CLOSE);
    ASN1_STRING_print_ex(membuf, str,
                         ((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
                          | ASN1_STRFLGS_UTF8_CONVERT));

    outlen = 0;
    BIO_write(membuf, &outlen, 1);
    size = BIO_get_mem_data(membuf, &sp);
    dp = (char *) pg_do_encoding_conversion((unsigned char *) sp,
                                            size - 1,
                                            PG_UTF8,
                                            GetDatabaseEncoding());
    outlen = strlen(dp);
    result = palloc(VARHDRSZ + outlen);
    memcpy(VARDATA(result), dp, outlen);
    if (dp != sp)
        pfree(dp);

    BIO_free(membuf);
    VARATT_SIZEP(result) = outlen + VARHDRSZ;
    PG_RETURN_TEXT_P(result);
}
开发者ID:asurinsaka,项目名称:postgresql-8.2.19-lru,代码行数:46,代码来源:sslinfo.c

示例5: pg_stat_get_backend_activity

Datum
pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
{
    int32		beid = PG_GETARG_INT32(0);
    text	   *result;
    PgBackendStatus *beentry;
    int			len;
    const char *activity;

    if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
        activity = "<backend information not available>";
    else if (!superuser() && beentry->st_userid != GetUserId())
        activity = "<insufficient privilege>";
    else if (*(beentry->st_activity) == '\0')
        activity = "<command string not enabled>";
    else
        activity = beentry->st_activity;

    len = strlen(activity);
    result = palloc(VARHDRSZ + len);
    VARATT_SIZEP(result) = VARHDRSZ + len;
    memcpy(VARDATA(result), activity, len);

    PG_RETURN_TEXT_P(result);
}
开发者ID:rtzassociates,项目名称:postgresql-8.2.23,代码行数:25,代码来源:pgstatfuncs.c

示例6: pg_digest

Datum
pg_digest(PG_FUNCTION_ARGS)
{
    bytea	   *arg;
    text	   *name;
    unsigned	len,
                hlen;
    PX_MD	   *md;
    bytea	   *res;

    if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
        PG_RETURN_NULL();

    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);
    VARATT_SIZEP(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);
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:35,代码来源:pgcrypto.c

示例7: ltree2text

Datum
ltree2text(PG_FUNCTION_ARGS)
{
    ltree	   *in = PG_GETARG_LTREE(0);
    char	   *ptr;
    int			i;
    ltree_level *curlevel;
    text	   *out;

    out = (text *) palloc(in->len + VARHDRSZ);
    ptr = VARDATA(out);
    curlevel = LTREE_FIRST(in);
    for (i = 0; i < in->numlevel; i++)
    {
        if (i != 0)
        {
            *ptr = '.';
            ptr++;
        }
        memcpy(ptr, curlevel->name, curlevel->len);
        ptr += curlevel->len;
        curlevel = LEVEL_NEXT(curlevel);
    }

    VARATT_SIZEP(out) = VARHDRSZ + (ptr - VARDATA(out));
    PG_FREE_IF_COPY(in, 0);

    PG_RETURN_POINTER(out);
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:29,代码来源:ltree_op.c

示例8: pg_gen_salt_rounds

Datum
pg_gen_salt_rounds(PG_FUNCTION_ARGS)
{
    text	   *arg0;
    int			rounds;
    int			len;
    text	   *res;
    char		buf[PX_MAX_SALT_LEN + 1];

    if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
        PG_RETURN_NULL();

    arg0 = PG_GETARG_TEXT_P(0);
    rounds = PG_GETARG_INT32(1);

    len = VARSIZE(arg0) - VARHDRSZ;
    len = len > PX_MAX_SALT_LEN ? PX_MAX_SALT_LEN : len;
    memcpy(buf, VARDATA(arg0), len);
    buf[len] = 0;
    len = px_gen_salt(buf, buf, rounds);
    if (len < 0)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                 errmsg("gen_salt: %s", px_strerror(len))));

    res = (text *) palloc(len + VARHDRSZ);
    VARATT_SIZEP(res) = len + VARHDRSZ;
    memcpy(VARDATA(res), buf, len);

    PG_FREE_IF_COPY(arg0, 0);

    PG_RETURN_TEXT_P(res);
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:33,代码来源:pgcrypto.c

示例9: spheretrans_type

  Datum  spheretrans_type(PG_FUNCTION_ARGS)
  {
    SEuler     * se =  ( SEuler * )  PG_GETARG_POINTER ( 0 ) ;
    BpChar  *result =  ( BpChar * )  MALLOC ( 3 + VARHDRSZ );
    char     ret[4] ;
    int           i ;
    unsigned char t = 0;

    for ( i=0; i<3; i++ ){
      switch ( i ){
        case 0: t = se->phi_a  ; break;
        case 1: t = se->theta_a; break;
        case 2: t = se->psi_a  ; break;
      }
      switch ( t ){
        case EULER_AXIS_X : ret[i]='X'; break;
        case EULER_AXIS_Y : ret[i]='Y'; break;
        case EULER_AXIS_Z : ret[i]='Z'; break;
      }
    }
    ret[3] = '\0';
#if PG_VERSION_NUM < 80300
    VARATT_SIZEP(result) = 3 + VARHDRSZ;
#else
    SET_VARSIZE(result, 3 + VARHDRSZ);
#endif    
    memcpy((void*)VARDATA(result), (void*)&ret[0], 3 );

    PG_RETURN_BPCHAR_P(result);

  }
开发者ID:china-vo,项目名称:pgSphere,代码行数:31,代码来源:euler.c

示例10: 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);
}
开发者ID:berkeley-cs186,项目名称:course-fa07,代码行数:35,代码来源:encode.c

示例11: gin_extract_tsvector

Datum
gin_extract_tsvector(PG_FUNCTION_ARGS)
{
    tsvector   *vector = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
    uint32	   *nentries = (uint32 *) PG_GETARG_POINTER(1);
    Datum	   *entries = NULL;

    *nentries = 0;
    if (vector->size > 0)
    {
        int			i;
        WordEntry  *we = ARRPTR(vector);

        *nentries = (uint32) vector->size;
        entries = (Datum *) palloc(sizeof(Datum) * vector->size);

        for (i = 0; i < vector->size; i++)
        {
            text	   *txt = (text *) palloc(VARHDRSZ + we->len);

            VARATT_SIZEP(txt) = VARHDRSZ + we->len;
            memcpy(VARDATA(txt), STRPTR(vector) + we->pos, we->len);

            entries[i] = PointerGetDatum(txt);

            we++;
        }
    }

    PG_FREE_IF_COPY(vector, 0);
    PG_RETURN_POINTER(entries);
}
开发者ID:berkeley-cs186,项目名称:course-fa07,代码行数:32,代码来源:ginidx.c

示例12: dmetaphone_alt

Datum
dmetaphone_alt(PG_FUNCTION_ARGS)
{
    text	   *arg,
               *result;
    int			alen,
                rsize;
    char	   *aptr,
               *codes[2],
               *code,
               *rptr;

#ifdef DMETAPHONE_NOSTRICT
    if (PG_ARGISNULL(0))
        PG_RETURNNULL();
#endif
    arg = PG_GETARG_TEXT_P(0);
    alen = VARSIZE(arg) - VARHDRSZ;
    aptr = palloc(alen + 1);
    memcpy(aptr, VARDATA(arg), alen);
    aptr[alen] = 0;
    DoubleMetaphone(aptr, codes);
    code = codes[1];
    if (!code)
        code = "";
    rsize = VARHDRSZ + strlen(code);
    result = (text *) palloc(rsize);
    memset(result, 0, rsize);
    rptr = VARDATA(result);
    memcpy(rptr, code, strlen(code));
    VARATT_SIZEP(result) = rsize;
    PG_RETURN_TEXT_P(result);
}
开发者ID:berkeley-cs186,项目名称:course-fa07,代码行数:33,代码来源:dmetaphone.c

示例13: varchar_input

/*
 * varchar_input -- common guts of varcharin and varcharrecv
 *
 * s is the input text of length len (may not be null-terminated)
 * atttypmod is the typmod value to apply
 *
 * Note that atttypmod is measured in characters, which
 * is not necessarily the same as the number of bytes.
 *
 * If the input string is too long, raise an error, unless the extra
 * characters are spaces, in which case they're truncated.  (per SQL)
 */
static VarChar *
varchar_input(const char *s, size_t len, int32 atttypmod)
{
    VarChar    *result;
    size_t		maxlen;

    /* verify encoding */
    pg_verifymbstr(s, len, false);

    maxlen = atttypmod - VARHDRSZ;

    if (atttypmod >= (int32) VARHDRSZ && len > maxlen)
    {
        /* Verify that extra characters are spaces, and clip them off */
        size_t		mbmaxlen = pg_mbcharcliplen(s, len, maxlen);
        size_t		j;

        for (j = mbmaxlen; j < len; j++)
        {
            if (s[j] != ' ')
                ereport(ERROR,
                        (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
                      errmsg("value too long for type character varying(%d)",
                             (int) maxlen)));
        }

        len = mbmaxlen;
    }

    result = (VarChar *) palloc(len + VARHDRSZ);
    VARATT_SIZEP(result) = len + VARHDRSZ;
    memcpy(VARDATA(result), s, len);

    return result;
}
开发者ID:shubham2094,项目名称:postgresql_8.1,代码行数:47,代码来源:varchar.c

示例14: _byte_array_coerceObject

static Datum _byte_array_coerceObject(Type self, jobject byteArray)
{
    bytea* bytes = 0;
    if(byteArray == 0)
        return 0;

    if(JNI_isInstanceOf(byteArray, s_byteArray_class))
    {
        jsize  length    = JNI_getArrayLength((jarray)byteArray);
        int32  byteaSize = length + VARHDRSZ;

        bytes = (bytea*)palloc(byteaSize);
#if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 3)
        VARATT_SIZEP(bytes) = byteaSize;
#else
        SET_VARSIZE(bytes, byteaSize);
#endif
        JNI_getByteArrayRegion((jbyteArray)byteArray, 0, length, (jbyte*)VARDATA(bytes));
    }
    else if(JNI_isInstanceOf(byteArray, s_BlobValue_class))
    {
        jobject byteBuffer;
        int32 byteaSize;
        jlong length = JNI_callLongMethod(byteArray, s_BlobValue_length);

        byteaSize = (int32)(length + VARHDRSZ);
        bytes = (bytea*)palloc(byteaSize);
#if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 3)
        VARATT_SIZEP(bytes) = byteaSize;
#else
        SET_VARSIZE(bytes, byteaSize);
#endif

        byteBuffer = JNI_newDirectByteBuffer((void*)VARDATA(bytes), length);
        if(byteBuffer != 0)
            JNI_callVoidMethod(byteArray, s_BlobValue_getContents, byteBuffer);
        JNI_deleteLocalRef(byteBuffer);
    }
    else
    {
        Exception_throwIllegalArgument("Not coercable to bytea");
    }

    PG_RETURN_BYTEA_P(bytes);
}
开发者ID:ChiralBehaviors,项目名称:pljava,代码行数:45,代码来源:byte_array.c

示例15: pg_crypt

Datum
pg_crypt(PG_FUNCTION_ARGS)
{
    text	   *arg0;
    text	   *arg1;
    unsigned	len0,
                len1,
                clen;
    char	   *buf0,
               *buf1,
               *cres,
               *resbuf;
    text	   *res;

    if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
        PG_RETURN_NULL();

    arg0 = PG_GETARG_TEXT_P(0);
    arg1 = PG_GETARG_TEXT_P(1);
    len0 = VARSIZE(arg0) - VARHDRSZ;
    len1 = VARSIZE(arg1) - VARHDRSZ;

    buf0 = palloc(len0 + 1);
    buf1 = palloc(len1 + 1);

    memcpy(buf0, VARDATA(arg0), len0);
    memcpy(buf1, VARDATA(arg1), len1);

    buf0[len0] = '\0';
    buf1[len1] = '\0';

    resbuf = palloc(PX_MAX_CRYPT);

    memset(resbuf, 0, PX_MAX_CRYPT);

    cres = px_crypt(buf0, buf1, resbuf, PX_MAX_CRYPT);

    pfree(buf0);
    pfree(buf1);

    if (cres == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
                 errmsg("crypt(3) returned NULL")));

    clen = strlen(cres);

    res = (text *) palloc(clen + VARHDRSZ);
    VARATT_SIZEP(res) = clen + VARHDRSZ;
    memcpy(VARDATA(res), cres, clen);
    pfree(resbuf);

    PG_FREE_IF_COPY(arg0, 0);
    PG_FREE_IF_COPY(arg1, 1);

    PG_RETURN_TEXT_P(res);
}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:57,代码来源:pgcrypto.c


注:本文中的VARATT_SIZEP函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。