Re: URL Managment - C Function help - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: URL Managment - C Function help
Date
Msg-id 4ADF2BD9.4040608@enterprisedb.com
Whole thread Raw
In response to URL Managment - C Function help  (Samuel ROZE <samuel.roze@gmail.com>)
Responses Re: URL Managment - C Function help
List pgsql-hackers
Samuel ROZE wrote:
> 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 type
>     TupleDesc    tupdesc;
>     Datum        values[2]; // 8 values
>     HeapTuple    tuple;
>     bool        nulls[2];
>     int            tuplen;
> 
>     // Check NULLs values
>     if(PG_ARGISNULL(0) || PG_ARGISNULL(1)) {
>         PG_RETURN_NULL();
>     }
> 
>     url *ret = parse_url_exec(str);
> 
>     // Add datas into the values Datum
>     values[0] = PointerGetDatum(ret->scheme);
>     values[1] = PointerGetDatum(ret->host);
> 
>     // Convert values into a composite type
>     /*tuplen = tupdesc->natts;
>     nulls = palloc(tuplen * sizeof(bool));*/
>     memset(nulls, 0, sizeof(nulls));
> 
>     // build tuple from datum array
>     tuple = heap_form_tuple(tupdesc, values, nulls);
>     // Free null values
>     /*pfree(nulls);*/
> 
>     // Return the composite type
>     PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
> }

You haven't initialized tupdesc.

BTW, there's a fine example in the manual:
http://www.postgresql.org/docs/8.4/interactive/xfunc-c.html#AEN44968

--  Heikki Linnakangas EnterpriseDB   http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: URL Managment - C Function help
Next
From: Dave Page
Date:
Subject: Re: Client application name