Re: Postgesql lib - Mailing list pgsql-novice

From Lukas
Subject Re: Postgesql lib
Date
Msg-id 15970.217.117.29.29.1231763895.squirrel@fmf.vgtu.lt
Whole thread Raw
In response to Re: Postgesql lib  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses IN vs =  ("Lukas" <lukas@fmf.vtu.lt>)
List pgsql-novice
Hello,

 Yes, you was right about VARDATA (working code below, maybe it will help
others), the problem was that I could not find documentation for VARDATA,
maybe you can point to it?

 Also, about the
ats = pclose (sendmail);
PG_RETURN_TEXT_P( ats );

Yes, ats is integer, so what is wrong here? actually it is working
normally, or I should know something more?


Code is here:

    text *To, *Subject, *Body;

    To = PG_GETARG_TEXT_P(0);

    char *cTo = (char *) calloc(VARSIZE(To) - VARHDRSZ, sizeof(char));
    strncpy(cTo, VARDATA(To), VARSIZE(To)-VARHDRSZ);

and latter:

    fprintf (sendmail, "To: %s\n", cTo);


--
Lukas
UAB nSoft
http://www.nsoft.lt
Lukas at nsoft.lt
+370 655 10 655




> "Lukas" <lukas@fmf.vtu.lt> writes:
>>  I am trying to write simple PG Lib on C (on Linux), it is working, bus
>> I
>> have some problem with data types, maybe someone can explain me a little
>> bit:
>
> You're assuming that VARDATA() produces a null-terminated string.
> It doesn't.  You either need to call textout to get a null-terminated
> string, or fix the fprintf calls to pay attention to the actual
> string length.
>
>>     ats = pclose (sendmail);
>>     PG_RETURN_TEXT_P( ats );
>
> ... and this part is even less likely to work.  pclose returns an
> integer.
>
>             regards, tom lane
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>
> --
> This message has been scanned for viruses and
> dangerous content by OpenProtect(http://www.openprotect.com), and is
> believed to be clean.
>
>



--
This message has been scanned for viruses and
dangerous content by OpenProtect(http://www.openprotect.com), and is
believed to be clean.


pgsql-novice by date:

Previous
From: Peter Jackson
Date:
Subject: Re: Foreign Keys
Next
From: "Wright, George"
Date:
Subject: debugging plpgsql functions