|
Home > Archive > PostgreSQL Discussion > August 2005 > Help with SPI...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Cristian Prieto 2005-08-30, 8:24 pm |
| 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_AR
GS)
{
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_ge
tbinval(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...
| |
| Michael Fuhr 2005-08-31, 3:24 am |
| On Tue, Aug 30, 2005 at 01:28:11PM -0600, Cristian Prieto wrote:
> 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.
You could use SPI_prepare() and SPI_execp() without having to
transform the bytea value into a string; see the SPI documentation
and look around for examples that use numbered parameters ($1, $2,
etc.).
--
Michael Fuhr
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?
http://archives.postgresql.org
|
|
|
|
|