Re: Getting Text data as C string

From: Denis Gasparin <denis(at)edistar(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting Text data as C string
Date: 2007-03-12 13:56:16
Message-ID: 45F55C00.3040206@edistar.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter Eisentraut ha scritto:
> Am Montag, 12. März 2007 12:47 schrieb Denis Gasparin:
>
>> I wrote a simple c stored procedure that accepts only one text parameter
>> that i want to convert to a c string.
>> The problem is that i obtain the C string correctly but with spurious
>> characters at the end... I use these calls to obtain the c string:
>>
>
> The data in a text datum is not null terminated. You need to call the
> function textout() to convert. Grep the source code for examples of invoking
> it.
>
>
I found these defines into the contrib section:

#define GET_STR(textp) DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(textp)))
#define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin,
CStringGetDatum(cstrp)))

So i can safely use them to obtain a string pointer from a text pointer
and viceversa.

I tried and all seemed to work ok.
Thank you,
Denis

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Magnus Hagander 2007-03-12 13:56:17 Re: [GENERAL] PostgreSQL crashes on Windows 2003
Previous Message Joost Kraaijeveld 2007-03-12 13:46:22 Re: [GENERAL] PostgreSQL crashes on Windows 2003