pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve <steeeeeveee@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Question about PQexecParams
Date: Sat, 11 Sep 2010 14:44:23 +0200
Message-ID: <20100911124423.75020@gmx.net> (raw)

Hello list,

I would like to call a function from my C application by using libpq and PQexecParams. My problem is that I don't know how to specify that I want to send an array to the function.

Assume the function is called lookup_data and takes the following parameters: lookup_data(integer,integer,bigint[])

I would like to specify the OID with my query. How would I do that? Assume I would like to query 3 values for bigint:

const char *paramValues[5];
Oid paramTypes[5];
int paramLengths[5];
int paramFormats[5];
    
int32_t ivalue1 = htonl(value1);
paramValues[0]  = (char *)&ivalue1;
paramTypes[0]   = INT4OID;
paramLengths[0] = sizeof(ivalue1);
paramFormats[0] = 1;

int32_t ivalue2 = htonl(value2);
paramValues[1]  = (char *)&ivalue2;
paramTypes[1]   = INT4OID;
paramLengths[1] = sizeof(ivalue2);
paramFormats[1] = 1;

etc...

How would I tell libpq that the next 3 values are an array of bigint?

I tried to use INT8OID and specify the query like below but that did not work:
SELECT * FROM lookup_data($1,$2,{$3,$4,$5})

Probably I have to set the query to be:
SELECT * FROM lookup_data($1,$2,{$3})

Or:
SELECT * FROM lookup_data($1,$2,$3)

But what would I set for paramTypes? How can I say that the values are an array of bigint? I assume that I can set paramValues to be an array and paramLengths to be sizeof one value multiplied by the amount of elements in the array.

I am somehow lost and don't know how to call the function and pass an array to libpq.

Can any one help me with this?


// Steve
-- 
GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99 Euro/mtl.!*
http://portal.gmx.net/de/go/dsl



view thread (7+ messages)  latest in thread

Message-ID: <20100911124423.75020@gmx.net>
Permalink:  ../20100911124423.75020@gmx.net/
Also on:    postgresql.org/message-id/20100911124423.75020@gmx.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: steeeeeveee@gmx.net
  Subject: Re: Question about PQexecParams
  In-Reply-To: <20100911124423.75020@gmx.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox