more custom C function fun

Поиск
Список
Период
Сортировка
От Dan \"Heron\" Myers
Тема more custom C function fun
Дата
Msg-id 481FF00C.4060408@xnapid.com
обсуждение исходный текст
Ответы Re: more custom C function fun
Список pgsql-general
I have a custom C function that takes two text*s and returns a text*.

My problem is with this code:


PG_FUNCTION_INFO_V1(get_agent);

PGMODULEEXPORT Datum get_agent(PG_FUNCTION_ARGS)
{
    if(!PG_ARGISNULL(0))
    {
        text* calling_party = PG_GETARG_TEXT_P(0);

        char* thestr = VARDATA(calling_party);
        if(thestr[20] == ')')
        {
            PG_RETURN_TEXT_P(calling_party);
        }
    }
/* the other argument is ignored for now */
    PG_RETURN_NULL();
}

The problem is, the comparison in the inner if statement is always true.
  If I change to compare, say, thestr[0] == 'N', then it works as
expected (returning only those text*s whose first letter is N, returning
null for the rest).

However if I try to compare any character inside the text* with a
parenthesis (both '(' and ')'), then the equality is apparently always
true (the function never returns null, always returning calling_party),
whether or not there is any data in that column that contains a
parenthesis in that column.

Does anyone know of any oddities or whatnot I should be accounting for
when reading character data out of a text*?

- Dan

В списке pgsql-general по дате отправления:

Предыдущее
От: Martin Marques
Дата:
Сообщение: Re: checkpoint_segments warning?
Следующее
От: "Dan \"Heron\" Myers"
Дата:
Сообщение: Re: more custom C function fun