Header And Logo

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

Data Structures | Functions

ltxtquery_op.c File Reference

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

Go to the source code of this file.

Data Structures

struct  CHKVAL

Functions

 PG_FUNCTION_INFO_V1 (ltxtq_exec)
 PG_FUNCTION_INFO_V1 (ltxtq_rexec)
bool ltree_execute (ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
static bool checkcondition_str (void *checkval, ITEM *val)
Datum ltxtq_exec (PG_FUNCTION_ARGS)
Datum ltxtq_rexec (PG_FUNCTION_ARGS)

Function Documentation

static bool checkcondition_str ( void *  checkval,
ITEM val 
) [static]

Definition at line 52 of file ltxtquery_op.c.

References compare_subnode(), ITEM::distance, ITEM::flag, ltree_level::len, ITEM::length, LEVEL_NEXT, LTREE_FIRST, ltree_strncasecmp(), LVAR_ANYEND, LVAR_SUBLEXEME, and ltree_level::name.

Referenced by ltxtq_exec().

{
    ltree_level *level = LTREE_FIRST(((CHKVAL *) checkval)->node);
    int         tlen = ((CHKVAL *) checkval)->node->numlevel;
    char       *op = ((CHKVAL *) checkval)->operand + val->distance;
    int         (*cmpptr) (const char *, const char *, size_t);

    cmpptr = (val->flag & LVAR_INCASE) ? ltree_strncasecmp : strncmp;
    while (tlen > 0)
    {
        if (val->flag & LVAR_SUBLEXEME)
        {
            if (compare_subnode(level, op, val->length, cmpptr, (val->flag & LVAR_ANYEND)))
                return true;
        }
        else if (
                 (
                  val->length == level->len ||
                  (level->len > val->length && (val->flag & LVAR_ANYEND))
                  ) &&
                 (*cmpptr) (op, level->name, val->length) == 0)
            return true;

        tlen--;
        level = LEVEL_NEXT(level);
    }

    return false;
}

bool ltree_execute ( ITEM curitem,
void *  checkval,
bool  calcnot,
bool(*)(void *checkval, ITEM *val chkcond 
)

Definition at line 19 of file ltxtquery_op.c.

References ITEM::left, ltree_execute(), ITEM::type, ITEM::val, and VAL.

Referenced by gist_qtxt(), ltree_execute(), and ltxtq_exec().

{
    if (curitem->type == VAL)
        return (*chkcond) (checkval, curitem);
    else if (curitem->val == (int32) '!')
    {
        return (calcnot) ?
            ((ltree_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
            : true;
    }
    else if (curitem->val == (int32) '&')
    {
        if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
            return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
        else
            return false;
    }
    else
    {                           /* |-operator */
        if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
            return true;
        else
            return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
    }
}

Datum ltxtq_exec ( PG_FUNCTION_ARGS   ) 
Datum ltxtq_rexec ( PG_FUNCTION_ARGS   ) 
PG_FUNCTION_INFO_V1 ( ltxtq_rexec   ) 
PG_FUNCTION_INFO_V1 ( ltxtq_exec   )