Re: Creating server-side functions: one simple error - Mailing list pgsql-bugs

From elein (by way of elein
Subject Re: Creating server-side functions: one simple error
Date
Msg-id 200210112215.g9BMFYne132326@pimout3-ext.prodigy.net
Whole thread Raw
In response to Creating server-side functions: one simple error  (Ruslan A Dautkhanov <rusland@scn.ru>)
List pgsql-bugs
This will not work if there is no EOS on the data portion of the
string.  Text fields are not usually stored with the EOS on them,
are they?

elein
elein@norcov.com

On Wednesday 09 October 2002 21:14, Joe Conway wrote:
> Ruslan A Dautkhanov wrote:
> > Btw, how I can convert TEXT field to a CString one? I had tried to use
> >   char *cnum =3D PG_GETARG_CSTRING(0)  instead of
> >   text tnum =3D PG_GETARG_NAME(0),   but it's not worked properly. Is a=
ny
> > function to convert text object to a null-terminated string??? Thanks
> > again.
>
> I like to use the following macros:
>
> /* convert C string to text pointer */
> #define GET_TEXT(cstrp) \
>      DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp)))
> /* convert text pointer to C string */
> #define GET_STR(textp) \
>      DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp)))
>
> then you can do, e.g.
>    char   *cnum =3D GET_STR(PG_GETARG_TEXT_P(0));
>
> BTW, there are lots of good examples of C functions in contrib.
>
> HTH,
>
> Joe
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

pgsql-bugs by date:

Previous
From: Ruslan A Dautkhanov
Date:
Subject: Re: Creating server-side functions: one simple error
Next
From: Peter Eisentraut
Date:
Subject: Re: Creating server-side functions: one simple error