[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    Re: [GENERAL] Getting Text data as C string
From:       Denis Gasparin <denis () edistar ! com>
Date:       2007-03-12 13:56:16
Message-ID: 45F55C00.3040206 () edistar ! com
[Download RAW message or body]

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

[Attachment #3 (text/html)]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-15"
 http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Peter Eisentraut ha scritto:
<blockquote cite="mid200703121358.20418.peter_e@gmx.net" type="cite">
  <pre wrap="">Am Montag, 12. März 2007 12:47 schrieb Denis Gasparin:
  </pre>
  <blockquote type="cite">
    <pre wrap="">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:
    </pre>
  </blockquote>
  <pre wrap=""><!---->
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.

  </pre>
</blockquote>
I found these defines into the contrib section:<br>
<br>
#define GET_STR(textp) DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(textp)))<br>
#define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin,
CStringGetDatum(cstrp)))<br>
<br>
So i can safely use them to obtain a string pointer from a text pointer
and viceversa.<br>
<br>
I tried and all seemed to work ok.<br>
Thank you,<br>
Denis<br>
</body>
</html>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic