Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Functions

oid.c File Reference

#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include "catalog/pg_type.h"
#include "libpq/pqformat.h"
#include "utils/array.h"
#include "utils/builtins.h"
Include dependency graph for oid.c:

Go to the source code of this file.

Defines

#define OidVectorSize(n)   (offsetof(oidvector, values) + (n) * sizeof(Oid))

Functions

static Oid oidin_subr (const char *s, char **endloc)
Datum oidin (PG_FUNCTION_ARGS)
Datum oidout (PG_FUNCTION_ARGS)
Datum oidrecv (PG_FUNCTION_ARGS)
Datum oidsend (PG_FUNCTION_ARGS)
oidvectorbuildoidvector (const Oid *oids, int n)
Datum oidvectorin (PG_FUNCTION_ARGS)
Datum oidvectorout (PG_FUNCTION_ARGS)
Datum oidvectorrecv (PG_FUNCTION_ARGS)
Datum oidvectorsend (PG_FUNCTION_ARGS)
Oid oidparse (Node *node)
Datum oideq (PG_FUNCTION_ARGS)
Datum oidne (PG_FUNCTION_ARGS)
Datum oidlt (PG_FUNCTION_ARGS)
Datum oidle (PG_FUNCTION_ARGS)
Datum oidge (PG_FUNCTION_ARGS)
Datum oidgt (PG_FUNCTION_ARGS)
Datum oidlarger (PG_FUNCTION_ARGS)
Datum oidsmaller (PG_FUNCTION_ARGS)
Datum oidvectoreq (PG_FUNCTION_ARGS)
Datum oidvectorne (PG_FUNCTION_ARGS)
Datum oidvectorlt (PG_FUNCTION_ARGS)
Datum oidvectorle (PG_FUNCTION_ARGS)
Datum oidvectorge (PG_FUNCTION_ARGS)
Datum oidvectorgt (PG_FUNCTION_ARGS)

Define Documentation

#define OidVectorSize (   n  )     (offsetof(oidvector, values) + (n) * sizeof(Oid))

Definition at line 26 of file oid.c.

Referenced by buildoidvector(), and oidvectorin().


Function Documentation

oidvector* buildoidvector ( const Oid oids,
int  n 
)

Definition at line 164 of file oid.c.

References oidvector::dataoffset, oidvector::dim1, oidvector::elemtype, oidvector::lbound1, oidvector::ndim, OidVectorSize, palloc0(), SET_VARSIZE, and oidvector::values.

Referenced by AggregateCreate(), CreateProceduralLanguage(), examine_parameter_list(), makeRangeConstructors(), and UpdateIndexRelation().

{
    oidvector  *result;

    result = (oidvector *) palloc0(OidVectorSize(n));

    if (n > 0 && oids)
        memcpy(result->values, oids, n * sizeof(Oid));

    /*
     * Attach standard array header.  For historical reasons, we set the index
     * lower bound to 0 not 1.
     */
    SET_VARSIZE(result, OidVectorSize(n));
    result->ndim = 1;
    result->dataoffset = 0;     /* never any nulls */
    result->elemtype = OIDOID;
    result->dim1 = n;
    result->lbound1 = 0;

    return result;
}

Datum oideq ( PG_FUNCTION_ARGS   ) 

Definition at line 337 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

{
    Oid         arg1 = PG_GETARG_OID(0);
    Oid         arg2 = PG_GETARG_OID(1);

    PG_RETURN_BOOL(arg1 == arg2);
}

Datum oidge ( PG_FUNCTION_ARGS   ) 

Definition at line 373 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

{
    Oid         arg1 = PG_GETARG_OID(0);
    Oid         arg2 = PG_GETARG_OID(1);

    PG_RETURN_BOOL(arg1 >= arg2);
}

Datum oidgt ( PG_FUNCTION_ARGS   ) 

Definition at line 382 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

{
    Oid         arg1 = PG_GETARG_OID(0);
    Oid         arg2 = PG_GETARG_OID(1);

    PG_RETURN_BOOL(arg1 > arg2);
}

Datum oidin ( PG_FUNCTION_ARGS   ) 
static Oid oidin_subr ( const char *  s,
char **  endloc 
) [static]

Definition at line 34 of file oid.c.

References ereport, errcode(), errmsg(), and ERROR.

Referenced by oidin(), oidparse(), and oidvectorin().

{
    unsigned long cvt;
    char       *endptr;
    Oid         result;

    if (*s == '\0')
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("invalid input syntax for type oid: \"%s\"",
                        s)));

    errno = 0;
    cvt = strtoul(s, &endptr, 10);

    /*
     * strtoul() normally only sets ERANGE.  On some systems it also may set
     * EINVAL, which simply means it couldn't parse the input string. This is
     * handled by the second "if" consistent across platforms.
     */
    if (errno && errno != ERANGE && errno != EINVAL)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("invalid input syntax for type oid: \"%s\"",
                        s)));

    if (endptr == s && *s != '\0')
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("invalid input syntax for type oid: \"%s\"",
                        s)));

    if (errno == ERANGE)
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("value \"%s\" is out of range for type oid", s)));

    if (endloc)
    {
        /* caller wants to deal with rest of string */
        *endloc = endptr;
    }
    else
    {
        /* allow only whitespace after number */
        while (*endptr && isspace((unsigned char) *endptr))
            endptr++;
        if (*endptr)
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for type oid: \"%s\"",
                            s)));
    }

    result = (Oid) cvt;

    /*
     * Cope with possibility that unsigned long is wider than Oid, in which
     * case strtoul will not raise an error for some values that are out of
     * the range of Oid.
     *
     * For backwards compatibility, we want to accept inputs that are given
     * with a minus sign, so allow the input value if it matches after either
     * signed or unsigned extension to long.
     *
     * To ensure consistent results on 32-bit and 64-bit platforms, make sure
     * the error message is the same as if strtoul() had returned ERANGE.
     */
#if OID_MAX != ULONG_MAX
    if (cvt != (unsigned long) result &&
        cvt != (unsigned long) ((int) result))
        ereport(ERROR,
                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                 errmsg("value \"%s\" is out of range for type oid", s)));
#endif

    return result;
}

Datum oidlarger ( PG_FUNCTION_ARGS   ) 

Definition at line 391 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_OID.

{
    Oid         arg1 = PG_GETARG_OID(0);
    Oid         arg2 = PG_GETARG_OID(1);

    PG_RETURN_OID((arg1 > arg2) ? arg1 : arg2);
}

Datum oidle ( PG_FUNCTION_ARGS   ) 

Definition at line 364 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

{
    Oid         arg1 = PG_GETARG_OID(0);
    Oid         arg2 = PG_GETARG_OID(1);

    PG_RETURN_BOOL(arg1 <= arg2);
}

Datum oidlt ( PG_FUNCTION_ARGS   ) 

Definition at line 355 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

{
    Oid         arg1 = PG_GETARG_OID(0);
    Oid         arg2 = PG_GETARG_OID(1);

    PG_RETURN_BOOL(arg1 < arg2);
}

Datum oidne ( PG_FUNCTION_ARGS   ) 

Definition at line 346 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

{
    Oid         arg1 = PG_GETARG_OID(0);
    Oid         arg2 = PG_GETARG_OID(1);

    PG_RETURN_BOOL(arg1 != arg2);
}

Datum oidout ( PG_FUNCTION_ARGS   ) 

Definition at line 124 of file oid.c.

References palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, and snprintf().

Referenced by CopyOneRowTo(), plperl_trigger_build_args(), pltcl_trigger_handler(), and PLy_trigger_build_args().

{
    Oid         o = PG_GETARG_OID(0);
    char       *result = (char *) palloc(12);

    snprintf(result, 12, "%u", o);
    PG_RETURN_CSTRING(result);
}

Oid oidparse ( Node node  ) 

Definition at line 311 of file oid.c.

References elog, ERROR, intVal, nodeTag, NULL, oidin_subr(), strVal, T_Float, and T_Integer.

Referenced by get_object_address(), and objectNamesToOids().

{
    switch (nodeTag(node))
    {
        case T_Integer:
            return intVal(node);
        case T_Float:

            /*
             * Values too large for int4 will be represented as Float
             * constants by the lexer.  Accept these if they are valid OID
             * strings.
             */
            return oidin_subr(strVal(node), NULL);
        default:
            elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
    }
    return InvalidOid;          /* keep compiler quiet */
}

Datum oidrecv ( PG_FUNCTION_ARGS   ) 
Datum oidsend ( PG_FUNCTION_ARGS   ) 
Datum oidsmaller ( PG_FUNCTION_ARGS   ) 

Definition at line 400 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_OID.

{
    Oid         arg1 = PG_GETARG_OID(0);
    Oid         arg2 = PG_GETARG_OID(1);

    PG_RETURN_OID((arg1 < arg2) ? arg1 : arg2);
}

Datum oidvectoreq ( PG_FUNCTION_ARGS   ) 

Definition at line 409 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

Datum oidvectorge ( PG_FUNCTION_ARGS   ) 

Definition at line 441 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

Datum oidvectorgt ( PG_FUNCTION_ARGS   ) 

Definition at line 449 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

Datum oidvectorin ( PG_FUNCTION_ARGS   ) 

Definition at line 191 of file oid.c.

References oidvector::dataoffset, oidvector::dim1, oidvector::elemtype, ereport, errcode(), errmsg(), ERROR, FUNC_MAX_ARGS, oidvector::lbound1, oidvector::ndim, oidin_subr(), OidVectorSize, palloc0(), PG_GETARG_CSTRING, PG_RETURN_POINTER, SET_VARSIZE, and oidvector::values.

{
    char       *oidString = PG_GETARG_CSTRING(0);
    oidvector  *result;
    int         n;

    result = (oidvector *) palloc0(OidVectorSize(FUNC_MAX_ARGS));

    for (n = 0; n < FUNC_MAX_ARGS; n++)
    {
        while (*oidString && isspace((unsigned char) *oidString))
            oidString++;
        if (*oidString == '\0')
            break;
        result->values[n] = oidin_subr(oidString, &oidString);
    }
    while (*oidString && isspace((unsigned char) *oidString))
        oidString++;
    if (*oidString)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                 errmsg("oidvector has too many elements")));

    SET_VARSIZE(result, OidVectorSize(n));
    result->ndim = 1;
    result->dataoffset = 0;     /* never any nulls */
    result->elemtype = OIDOID;
    result->dim1 = n;
    result->lbound1 = 0;

    PG_RETURN_POINTER(result);
}

Datum oidvectorle ( PG_FUNCTION_ARGS   ) 

Definition at line 433 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

Datum oidvectorlt ( PG_FUNCTION_ARGS   ) 

Definition at line 425 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

Datum oidvectorne ( PG_FUNCTION_ARGS   ) 

Definition at line 417 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

Datum oidvectorout ( PG_FUNCTION_ARGS   ) 

Definition at line 228 of file oid.c.

References oidvector::dim1, palloc(), PG_GETARG_POINTER, PG_RETURN_CSTRING, and oidvector::values.

{
    oidvector  *oidArray = (oidvector *) PG_GETARG_POINTER(0);
    int         num,
                nnums = oidArray->dim1;
    char       *rp;
    char       *result;

    /* assumes sign, 10 digits, ' ' */
    rp = result = (char *) palloc(nnums * 12 + 1);
    for (num = 0; num < nnums; num++)
    {
        if (num != 0)
            *rp++ = ' ';
        sprintf(rp, "%u", oidArray->values[num]);
        while (*++rp != '\0')
            ;
    }
    *rp = '\0';
    PG_RETURN_CSTRING(result);
}

Datum oidvectorrecv ( PG_FUNCTION_ARGS   ) 

Definition at line 254 of file oid.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, array_recv(), Assert, buf, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, FunctionCallInfoData::flinfo, FUNC_MAX_ARGS, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, FunctionCallInfoData::isnull, NULL, ObjectIdGetDatum, OIDOID, PG_GETARG_POINTER, PG_RETURN_POINTER, and PointerGetDatum.

{
    StringInfo  buf = (StringInfo) PG_GETARG_POINTER(0);
    FunctionCallInfoData locfcinfo;
    oidvector  *result;

    /*
     * Normally one would call array_recv() using DirectFunctionCall3, but
     * that does not work since array_recv wants to cache some data using
     * fcinfo->flinfo->fn_extra.  So we need to pass it our own flinfo
     * parameter.
     */
    InitFunctionCallInfoData(locfcinfo, fcinfo->flinfo, 3,
                             InvalidOid, NULL, NULL);

    locfcinfo.arg[0] = PointerGetDatum(buf);
    locfcinfo.arg[1] = ObjectIdGetDatum(OIDOID);
    locfcinfo.arg[2] = Int32GetDatum(-1);
    locfcinfo.argnull[0] = false;
    locfcinfo.argnull[1] = false;
    locfcinfo.argnull[2] = false;

    result = (oidvector *) DatumGetPointer(array_recv(&locfcinfo));

    Assert(!locfcinfo.isnull);

    /* sanity checks: oidvector must be 1-D, 0-based, no nulls */
    if (ARR_NDIM(result) != 1 ||
        ARR_HASNULL(result) ||
        ARR_ELEMTYPE(result) != OIDOID ||
        ARR_LBOUND(result)[0] != 0)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
                 errmsg("invalid oidvector data")));

    /* check length for consistency with oidvectorin() */
    if (ARR_DIMS(result)[0] > FUNC_MAX_ARGS)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                 errmsg("oidvector has too many elements")));

    PG_RETURN_POINTER(result);
}

Datum oidvectorsend ( PG_FUNCTION_ARGS   ) 

Definition at line 302 of file oid.c.

References array_send().

{
    return array_send(fcinfo);
}