Re: Creating server-side functions: one simple error

From: Joe Conway <mail(at)joeconway(dot)com>
To: Ruslan A Dautkhanov <rusland(at)scn(dot)ru>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Creating server-side functions: one simple error
Date: 2002-10-10 04:14:19
Message-ID: 3DA4FE9B.4080005@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Ruslan A Dautkhanov wrote:
> Btw, how I can convert TEXT field to a CString one? I had tried to use
> char *cnum = PG_GETARG_CSTRING(0) instead of
> text tnum = PG_GETARG_NAME(0), but it's not worked properly. Is any 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 = GET_STR(PG_GETARG_TEXT_P(0));

BTW, there are lots of good examples of C functions in contrib.

HTH,

Joe

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Ruslan A Dautkhanov 2002-10-10 09:42:31 Re: Creating server-side functions: one simple error
Previous Message Ruslan A Dautkhanov 2002-10-10 03:06:39 Re: Creating server-side functions: one simple error