Help with SPI... - Mailing list pgsql-general

From Cristian Prieto
Subject Help with SPI...
Date
Msg-id 00bd01c5ad98$f6d5d410$6500a8c0@gt.ClickDiario.local
Whole thread Raw
Responses Re: Help with SPI...  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general
Hi, I will try to explain the most possible my question:
 
I'm writing a Store Procedure as a C Language Function in the Database, I need to handle a bytea (binary objetc) and store it in a modified mode in the database, I've done it in the following way:
 
PG_FUNCTION_INFO_V1(myspi);
 
Datum
myspi(PG_FUNCTION_ARGS)
{
 int ret;
 bool isnull;
 bytea *val;
 
 ret = SPI_connect();
 
 ret = SPI_exec("SELECT val FROM binary_table", 1);
 if (ret == SPI_OK_SELECT && SPI_processed > 0) {
    TupleDesc tupdesc = SPI_tuptable->tupdesc;
    SPITupleTable *tuptable = SPI_tuptable;
 
    val = DatumGetByteP(SPI_getbinval(tuptable->vals[0], tupdesc, 1, &isnull));
 }
 
/* Here I use and modified the new version of the val value */
 
// I don't know what to do here to store the new value again :(
 
 SPI_finish();
 PG_RETURN_INT32(val);
}
 
Well, the new value is really the content of a memory segment, I know I could store it again using SPI and an UPDATE statement, but that means that I need to transform the val value into a string, and I don't know the length of the string with the scape characters added.
 
Any idea in how to handle this?
 
Thanks a lot...
 

pgsql-general by date:

Previous
From: Tony Caduto
Date:
Subject: 8.1 observation
Next
From: Tom Lane
Date:
Subject: Re: 8.1 observation