From: | "Jack Orenstein" <jack(dot)orenstein(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Problems converting between C string and Datum |
Date: | 2006-09-20 15:19:29 |
Message-ID: | 7ecd811f0609200819n1eba1dc1i87073c0ef1c1719e@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks for all your help with the memory management problems. Next
problem: I'm having problems converting from a char* to a Datum and back
again.
I have a char* which I need as a Datum, for use with a plan returned
from SPI_prepare, so I'm doing this:
char* string;
Datum d;
...
d = DirectFunctionCall1(textin, CStringGetDatum(string));
...
ereport(WARNING, (errmsg("string: %s",
DatumGetCString(DirectFunctionCall1(textout, d)))));
(The ereport is for debugging -- my code then proceeds to call
SPI_execute_plan.)
This crashes doing the ereport:
psql:test.sql:23: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
So my questions are:
1) Is this code the way to convert char* to Datum and back again?
DirectFunctionCall1(textin, CStringGetDatum(string))
...
DatumGetCString(DirectFunctionCall1(textout, d))
I've put this code together based on examples I've found on the web
and in the postgres source.
2) Is there some neater way to generate debug output than ereport(WARNING, ...)?
The output is quite verbose, e.g.
psql:test.sql:23: WARNING: MY DEBUG OUTPUT
CONTEXT: SQL statement "insert into log select insert_ifs( $1 ,
$2 , $3 , $4 , $5 , $6 , $7 )"
PL/pgSQL function "regress" line 5 at SQL statement
for each line of output.
Jack Orenstein
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2006-09-20 16:42:51 | 8.2: select from an INSERT returning? |
Previous Message | Tom Lane | 2006-09-20 15:12:19 | Re: pg_dump output containing CREATE TYPE does not restore with psql |