Header And Logo

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

Defines | Typedefs | Functions

_ltree_op.c File Reference

#include "postgres.h"
#include <ctype.h>
#include "ltree.h"
Include dependency graph for _ltree_op.c:

Go to the source code of this file.

Defines

#define NEXTVAL(x)   ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )

Typedefs

typedef Datum(* PGCALL2 )(PG_FUNCTION_ARGS)

Functions

 PG_FUNCTION_INFO_V1 (_ltree_isparent)
 PG_FUNCTION_INFO_V1 (_ltree_r_isparent)
 PG_FUNCTION_INFO_V1 (_ltree_risparent)
 PG_FUNCTION_INFO_V1 (_ltree_r_risparent)
 PG_FUNCTION_INFO_V1 (_ltq_regex)
 PG_FUNCTION_INFO_V1 (_ltq_rregex)
 PG_FUNCTION_INFO_V1 (_lt_q_regex)
 PG_FUNCTION_INFO_V1 (_lt_q_rregex)
 PG_FUNCTION_INFO_V1 (_ltxtq_exec)
 PG_FUNCTION_INFO_V1 (_ltxtq_rexec)
Datum _ltree_r_isparent (PG_FUNCTION_ARGS)
Datum _ltree_r_risparent (PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1 (_ltree_extract_isparent)
 PG_FUNCTION_INFO_V1 (_ltree_extract_risparent)
 PG_FUNCTION_INFO_V1 (_ltq_extract_regex)
 PG_FUNCTION_INFO_V1 (_ltxtq_extract_exec)
Datum _ltree_extract_isparent (PG_FUNCTION_ARGS)
Datum _ltree_extract_risparent (PG_FUNCTION_ARGS)
Datum _ltq_extract_regex (PG_FUNCTION_ARGS)
Datum _ltxtq_extract_exec (PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1 (_lca)
Datum _lca (PG_FUNCTION_ARGS)
static bool array_iterator (ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Datum _ltree_isparent (PG_FUNCTION_ARGS)
Datum _ltree_risparent (PG_FUNCTION_ARGS)
Datum _ltq_regex (PG_FUNCTION_ARGS)
Datum _ltq_rregex (PG_FUNCTION_ARGS)
Datum _lt_q_regex (PG_FUNCTION_ARGS)
Datum _lt_q_rregex (PG_FUNCTION_ARGS)
Datum _ltxtq_exec (PG_FUNCTION_ARGS)
Datum _ltxtq_rexec (PG_FUNCTION_ARGS)

Define Documentation

#define NEXTVAL (   x  )     ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )

Definition at line 42 of file _ltree_op.c.

Referenced by _lca(), _lt_q_regex(), and array_iterator().


Typedef Documentation

typedef Datum(* PGCALL2)(PG_FUNCTION_ARGS)

Definition at line 40 of file _ltree_op.c.


Function Documentation

Datum _lca ( PG_FUNCTION_ARGS   ) 

Definition at line 300 of file _ltree_op.c.

References ARR_DATA_PTR, ARR_DIMS, ARR_NDIM, array_contains_nulls(), ArrayGetNItems(), ereport, errcode(), errmsg(), ERROR, lca_inner(), NEXTVAL, palloc(), pfree(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_RETURN_NULL, and PG_RETURN_POINTER.

{
    ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
    int         num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la));
    ltree      *item = (ltree *) ARR_DATA_PTR(la);
    ltree     **a,
               *res;

    if (ARR_NDIM(la) > 1)
        ereport(ERROR,
                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                 errmsg("array must be one-dimensional")));
    if (array_contains_nulls(la))
        ereport(ERROR,
                (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                 errmsg("array must not contain nulls")));

    a = (ltree **) palloc(sizeof(ltree *) * num);
    while (num > 0)
    {
        num--;
        a[num] = item;
        item = NEXTVAL(item);
    }
    res = lca_inner(a, ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la)));
    pfree(a);

    PG_FREE_IF_COPY(la, 0);

    if (res)
        PG_RETURN_POINTER(res);
    else
        PG_RETURN_NULL();
}

Datum _lt_q_regex ( PG_FUNCTION_ARGS   ) 

Definition at line 142 of file _ltree_op.c.

References ARR_DATA_PTR, ARR_DIMS, ARR_NDIM, array_contains_nulls(), array_iterator(), ArrayGetNItems(), ereport, errcode(), errmsg(), ERROR, ltq_regex(), NEXTVAL, NULL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, and PG_RETURN_BOOL.

Referenced by _lt_q_rregex().

{
    ArrayType  *_tree = PG_GETARG_ARRAYTYPE_P(0);
    ArrayType  *_query = PG_GETARG_ARRAYTYPE_P(1);
    lquery     *query = (lquery *) ARR_DATA_PTR(_query);
    bool        res = false;
    int         num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));

    if (ARR_NDIM(_query) > 1)
        ereport(ERROR,
                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                 errmsg("array must be one-dimensional")));
    if (array_contains_nulls(_query))
        ereport(ERROR,
                (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                 errmsg("array must not contain nulls")));

    while (num > 0)
    {
        if (array_iterator(_tree, ltq_regex, (void *) query, NULL))
        {
            res = true;
            break;
        }
        num--;
        query = (lquery *) NEXTVAL(query);
    }

    PG_FREE_IF_COPY(_tree, 0);
    PG_FREE_IF_COPY(_query, 1);
    PG_RETURN_BOOL(res);
}

Datum _lt_q_rregex ( PG_FUNCTION_ARGS   ) 
Datum _ltq_extract_regex ( PG_FUNCTION_ARGS   ) 

Definition at line 254 of file _ltree_op.c.

References array_iterator(), ltq_regex(), palloc(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LQUERY, PG_RETURN_NULL, PG_RETURN_POINTER, and VARSIZE.

{
    ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
    lquery     *query = PG_GETARG_LQUERY(1);
    ltree      *found,
               *item;

    if (!array_iterator(la, ltq_regex, (void *) query, &found))
    {
        PG_FREE_IF_COPY(la, 0);
        PG_FREE_IF_COPY(query, 1);
        PG_RETURN_NULL();
    }

    item = (ltree *) palloc(VARSIZE(found));
    memcpy(item, found, VARSIZE(found));

    PG_FREE_IF_COPY(la, 0);
    PG_FREE_IF_COPY(query, 1);
    PG_RETURN_POINTER(item);
}

Datum _ltq_regex ( PG_FUNCTION_ARGS   ) 

Definition at line 121 of file _ltree_op.c.

References array_iterator(), ltq_regex(), NULL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LQUERY, and PG_RETURN_BOOL.

Referenced by _ltq_rregex().

{
    ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
    lquery     *query = PG_GETARG_LQUERY(1);
    bool        res = array_iterator(la, ltq_regex, (void *) query, NULL);

    PG_FREE_IF_COPY(la, 0);
    PG_FREE_IF_COPY(query, 1);
    PG_RETURN_BOOL(res);
}

Datum _ltq_rregex ( PG_FUNCTION_ARGS   ) 
Datum _ltree_extract_isparent ( PG_FUNCTION_ARGS   ) 

Definition at line 208 of file _ltree_op.c.

References array_iterator(), ltree_isparent(), palloc(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE, PG_RETURN_NULL, PG_RETURN_POINTER, and VARSIZE.

{
    ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
    ltree      *query = PG_GETARG_LTREE(1);
    ltree      *found,
               *item;

    if (!array_iterator(la, ltree_isparent, (void *) query, &found))
    {
        PG_FREE_IF_COPY(la, 0);
        PG_FREE_IF_COPY(query, 1);
        PG_RETURN_NULL();
    }

    item = (ltree *) palloc(VARSIZE(found));
    memcpy(item, found, VARSIZE(found));

    PG_FREE_IF_COPY(la, 0);
    PG_FREE_IF_COPY(query, 1);
    PG_RETURN_POINTER(item);
}

Datum _ltree_extract_risparent ( PG_FUNCTION_ARGS   ) 

Definition at line 231 of file _ltree_op.c.

References array_iterator(), ltree_risparent(), palloc(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE, PG_RETURN_NULL, PG_RETURN_POINTER, and VARSIZE.

{
    ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
    ltree      *query = PG_GETARG_LTREE(1);
    ltree      *found,
               *item;

    if (!array_iterator(la, ltree_risparent, (void *) query, &found))
    {
        PG_FREE_IF_COPY(la, 0);
        PG_FREE_IF_COPY(query, 1);
        PG_RETURN_NULL();
    }

    item = (ltree *) palloc(VARSIZE(found));
    memcpy(item, found, VARSIZE(found));

    PG_FREE_IF_COPY(la, 0);
    PG_FREE_IF_COPY(query, 1);
    PG_RETURN_POINTER(item);
}

Datum _ltree_isparent ( PG_FUNCTION_ARGS   ) 
Datum _ltree_r_isparent ( PG_FUNCTION_ARGS   ) 
Datum _ltree_r_risparent ( PG_FUNCTION_ARGS   ) 
Datum _ltree_risparent ( PG_FUNCTION_ARGS   ) 
Datum _ltxtq_exec ( PG_FUNCTION_ARGS   ) 
Datum _ltxtq_extract_exec ( PG_FUNCTION_ARGS   ) 

Definition at line 277 of file _ltree_op.c.

References array_iterator(), ltxtq_exec(), palloc(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTXTQUERY, PG_RETURN_NULL, PG_RETURN_POINTER, and VARSIZE.

{
    ArrayType  *la = PG_GETARG_ARRAYTYPE_P(0);
    ltxtquery  *query = PG_GETARG_LTXTQUERY(1);
    ltree      *found,
               *item;

    if (!array_iterator(la, ltxtq_exec, (void *) query, &found))
    {
        PG_FREE_IF_COPY(la, 0);
        PG_FREE_IF_COPY(query, 1);
        PG_RETURN_NULL();
    }

    item = (ltree *) palloc(VARSIZE(found));
    memcpy(item, found, VARSIZE(found));

    PG_FREE_IF_COPY(la, 0);
    PG_FREE_IF_COPY(query, 1);
    PG_RETURN_POINTER(item);
}

Datum _ltxtq_rexec ( PG_FUNCTION_ARGS   ) 
static bool array_iterator ( ArrayType la,
PGCALL2  callback,
void *  param,
ltree **  found 
) [static]

Definition at line 45 of file _ltree_op.c.

References ARR_DATA_PTR, ARR_DIMS, ARR_NDIM, array_contains_nulls(), ArrayGetNItems(), DatumGetBool, DirectFunctionCall2, ereport, errcode(), errmsg(), ERROR, NEXTVAL, and PointerGetDatum.

Referenced by _lt_q_regex(), _ltq_extract_regex(), _ltq_regex(), _ltree_extract_isparent(), _ltree_extract_risparent(), _ltree_isparent(), _ltree_risparent(), _ltxtq_exec(), and _ltxtq_extract_exec().

{
    int         num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la));
    ltree      *item = (ltree *) ARR_DATA_PTR(la);

    if (ARR_NDIM(la) > 1)
        ereport(ERROR,
                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                 errmsg("array must be one-dimensional")));
    if (array_contains_nulls(la))
        ereport(ERROR,
                (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                 errmsg("array must not contain nulls")));

    if (found)
        *found = NULL;
    while (num > 0)
    {
        if (DatumGetBool(DirectFunctionCall2(callback,
                             PointerGetDatum(item), PointerGetDatum(param))))
        {

            if (found)
                *found = item;
            return true;
        }
        num--;
        item = NEXTVAL(item);
    }

    return false;
}

PG_FUNCTION_INFO_V1 ( _ltxtq_extract_exec   ) 
PG_FUNCTION_INFO_V1 ( _ltq_extract_regex   ) 
PG_FUNCTION_INFO_V1 ( _lca   ) 
PG_FUNCTION_INFO_V1 ( _ltree_extract_risparent   ) 
PG_FUNCTION_INFO_V1 ( _ltq_rregex   ) 
PG_FUNCTION_INFO_V1 ( _lt_q_regex   ) 
PG_FUNCTION_INFO_V1 ( _ltree_r_isparent   ) 
PG_FUNCTION_INFO_V1 ( _ltree_extract_isparent   ) 
PG_FUNCTION_INFO_V1 ( _ltree_r_risparent   ) 
PG_FUNCTION_INFO_V1 ( _ltxtq_rexec   ) 
PG_FUNCTION_INFO_V1 ( _ltq_regex   ) 
PG_FUNCTION_INFO_V1 ( _ltree_isparent   ) 
PG_FUNCTION_INFO_V1 ( _ltree_risparent   ) 
PG_FUNCTION_INFO_V1 ( _ltxtq_exec   ) 
PG_FUNCTION_INFO_V1 ( _lt_q_rregex   )