Re: URL Managment - C Function help

Поиск
Список
Период
Сортировка
От Samuel ROZE
Тема Re: URL Managment - C Function help
Дата
Msg-id 1256143691.2845.25.camel@samuel-laptop
обсуждение исходный текст
Ответ на Re: URL Managment - C Function help  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
I'm now using C strings. I don't need to use CStringGetTextDatum, but it
still don't works. There's the code:

---------------------------------------------------------------
PG_FUNCTION_INFO_V1(parse_url_record);
Datum parse_url_record (PG_FUNCTION_ARGS)
{// Vars about the params//text *str2 = PG_GETARG_TEXT_P(0);char str[] = "http://www.ovh.com/intenal.html";
// Some vars which will used to create the composite output typeTupleDesc    tupdesc;char        **values;HeapTuple
tuple;AttInMetadata*attinmeta;bool        nulls[2];url         *ret;
 
// Check NULLs valuesif(PG_ARGISNULL(0) || PG_ARGISNULL(1)) {    PG_RETURN_NULL();}
ret = parse_url_exec(str);
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
{    ereport(ERROR,            (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),             errmsg("function returning record
calledin context that
 
cannot accept type record")));}attinmeta = TupleDescGetAttInMetadata(tupdesc);
// ...values = (char **) palloc(2 * sizeof(char *));
// Add datas into the values Datumvalues[0] = (char *) ret->scheme;values[1] = (char *) ret->host;
// Convert values into a composite typememset(nulls, 0, sizeof(nulls));
// build tuple from datum arraytuple = BuildTupleFromCStrings(attinmeta, values);
// Return the composite typePG_RETURN_DATUM(HeapTupleGetDatum(tuple));
}
---------------------------------------------------------------

Thanks a lot !
Samuel ROZE.

Le mercredi 21 octobre 2009 à 11:42 -0400, Tom Lane a écrit :
> Samuel ROZE <samuel.roze@gmail.com> writes:
> > The problem is that they don't work fine... :/
> 
> I think the problem is that you are passing C strings to code that
> expects pointers to text datums --- which are not the same thing
> at all.  (text has a length word, not a null terminator byte.)
> It's pure accident that your first example works, and entirely
> unsurprising that the second one doesn't.  Some CStringGetTextDatum
> calls might help.
> 
>             regards, tom lane




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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Could regexp_matches be immutable?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Could regexp_matches be immutable?