SPI_execute_plan(): how to make a Datum to insert type inet ?

Started by Alex Vinogradovsabout 18 years ago3 messagesgeneral
Jump to latest
#1Alex Vinogradovs
AVinogradovs@Clearpathnet.com

Guys,

I've got SPI code that performs inserts into some tables. Code works
fine when destination columns are type text, but fails when there
is something different like inet or macaddr. For type inet, following
error message is produced : could not format inet value: Address family
not supported by protocol family, and for type macaddr the value
inserted is corrupted.
I am sure the problem is in how I make the Datum's for the invokation
of prepared plan, but I couldn't find a proper example anywhere. Here
is how I tried to implement it :

SPIPlanPtr plan = NULL;
Oid *types = palloc(sizeof(Oid));

types[0] = INETOID;

if((plan = SPI_prepare("insert into sometable valeues($1)", 1, types))
== NULL) {

// handle the error

}

Datum *params = palloc(sizeof(Datum));
char *nulls = palloc(1);

params[0] = DirectFunctionCall1(textin,
CStringGetDatum(pstrdup("192.168.1.1")));
nulls[0] = ' ';
if(SPI_execute_plan(plan, params, nulls, FALSE, 1) <= 0) {

// handle the error

}

Thanks!

Best regards
Alex Vinogradovs

#2Volkan YAZICI
yazicivo@ttmail.com
In reply to: Alex Vinogradovs (#1)
Re: SPI_execute_plan(): how to make a Datum to insert type inet ?

On Wed, 19 Mar 2008, Alex Vinogradovs <AVinogradovs@Clearpathnet.com> writes:

params[0] = DirectFunctionCall1(textin,
CStringGetDatum(pstrdup("192.168.1.1")));

Should't you be using inet_in instead of textin?

Regards.

#3Alex Vinogradovs
AVinogradovs@Clearpathnet.com
In reply to: Volkan YAZICI (#2)
Re: SPI_execute_plan(): how to make a Datum to insert type inet ?

That solved my problem. Thanks!

Show quoted text

On Wed, 2008-03-19 at 21:13 +0200, Volkan YAZICI wrote:

On Wed, 19 Mar 2008, Alex Vinogradovs <AVinogradovs@Clearpathnet.com> writes:

params[0] = DirectFunctionCall1(textin,
CStringGetDatum(pstrdup("192.168.1.1")));

Should't you be using inet_in instead of textin?

Regards.