Header And Logo

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

Data Structures | Functions | Variables

dict_int.c File Reference

#include "postgres.h"
#include "commands/defrem.h"
#include "tsearch/ts_public.h"
Include dependency graph for dict_int.c:

Go to the source code of this file.

Data Structures

struct  DictInt

Functions

 PG_FUNCTION_INFO_V1 (dintdict_init)
Datum dintdict_init (PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1 (dintdict_lexize)
Datum dintdict_lexize (PG_FUNCTION_ARGS)

Variables

 PG_MODULE_MAGIC

Function Documentation

Datum dintdict_init ( PG_FUNCTION_ARGS   ) 

Definition at line 35 of file dict_int.c.

References defGetBoolean(), defGetString(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, lfirst, DictInt::maxlen, palloc0(), PG_GETARG_POINTER, PG_RETURN_POINTER, pg_strcasecmp(), and DictInt::rejectlong.

{
    List       *dictoptions = (List *) PG_GETARG_POINTER(0);
    DictInt    *d;
    ListCell   *l;

    d = (DictInt *) palloc0(sizeof(DictInt));
    d->maxlen = 6;
    d->rejectlong = false;

    foreach(l, dictoptions)
    {
        DefElem    *defel = (DefElem *) lfirst(l);

        if (pg_strcasecmp(defel->defname, "MAXLEN") == 0)
        {
            d->maxlen = atoi(defGetString(defel));
        }
        else if (pg_strcasecmp(defel->defname, "REJECTLONG") == 0)
        {
            d->rejectlong = defGetBoolean(defel);
        }
        else
        {
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                     errmsg("unrecognized intdict parameter: \"%s\"",
                            defel->defname)));
        }
    }

    PG_RETURN_POINTER(d);
}

Datum dintdict_lexize ( PG_FUNCTION_ARGS   ) 

Definition at line 70 of file dict_int.c.

References TSLexeme::lexeme, DictInt::maxlen, palloc0(), pfree(), PG_GETARG_INT32, PG_GETARG_POINTER, PG_RETURN_POINTER, pnstrdup(), and DictInt::rejectlong.

{
    DictInt    *d = (DictInt *) PG_GETARG_POINTER(0);
    char       *in = (char *) PG_GETARG_POINTER(1);
    char       *txt = pnstrdup(in, PG_GETARG_INT32(2));
    TSLexeme   *res = palloc0(sizeof(TSLexeme) * 2);

    res[1].lexeme = NULL;
    if (PG_GETARG_INT32(2) > d->maxlen)
    {
        if (d->rejectlong)
        {
            /* reject by returning void array */
            pfree(txt);
            res[0].lexeme = NULL;
        }
        else
        {
            /* trim integer */
            txt[d->maxlen] = '\0';
            res[0].lexeme = txt;
        }
    }
    else
    {
        res[0].lexeme = txt;
    }

    PG_RETURN_POINTER(res);
}

PG_FUNCTION_INFO_V1 ( dintdict_lexize   ) 
PG_FUNCTION_INFO_V1 ( dintdict_init   ) 

Variable Documentation

Definition at line 18 of file dict_int.c.