Help with SPI...

From: "Cristian Prieto" <cristian(at)clickdiario(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Help with SPI...
Date: 2005-08-30 19:28:11
Message-ID: 00bd01c5ad98$f6d5d410$6500a8c0@gt.ClickDiario.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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...

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-08-30 20:26:50 Re: 8.1 observation
Previous Message Tony Caduto 2005-08-30 19:01:34 8.1 observation