Re: Initializing Datums for use with SPI_execute_plan

From: Andrew - Supernews <andrew+nonews(at)supernews(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Initializing Datums for use with SPI_execute_plan
Date: 2006-09-14 23:15:49
Message-ID: slrnegjol5.2ea3.andrew+nonews@atlantis.supernews.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2006-09-14, "Jack Orenstein" <jack(dot)orenstein(at)gmail(dot)com> wrote:
> I don't think I explained myself clearly. I have a C string (char*,
> terminating zero) and a byte array (char*, possibly containing zeros,
> and I know the length). I want to obtain Datums wrapping these values
> that will be used to bind varchar and bytea columns, and I'm trying to
> find out how to generate these Datums.

One way:

bytea *my_bytea = (bytea *) palloc(byte_array_len + VARHDRSZ);
memcpy(VARDATA(my_bytea), byte_array, byte_array_len);
VARATT_SIZEP(my_bytea) = byte_array_len + VARHDRSZ;

values[0] = DirectFunctionCall1(textin,CStringGetDatum(yourstring));
values[1] = PointerGetDatum(my_bytea);

SPI_execute_plan...

--
Andrew, Supernews
http://www.supernews.com - individual and corporate NNTP services

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Geoffrey 2006-09-15 00:30:12 Re: PostgreSQL slammed by PHP creator
Previous Message Simon_Kelly 2006-09-14 22:16:02 Re: [Off Topic] PostgreSQL slammed by PHP creator