pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #10014: Does not work PQfn in libpq with array
2+ messages / 2 participants
[nested] [flat]

* BUG #10014: Does not work PQfn in libpq with array
@ 2014-04-14 08:42  aleksey.vitaliev@transas.com
  0 siblings, 1 reply; 2+ messages in thread

From: aleksey.vitaliev@transas.com @ 2014-04-14 08:42 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      10014
Logged by:          Vitalyev Aleksey
Email address:      aleksey.vitaliev@transas.com
PostgreSQL version: 9.2.4
Operating system:   Windows 7
Description:        

I have a store procedure __a(INT[] args). I try execute this procedure with
libpq and call PQfn function. How should I transmit array of int from c++
code?
I get only this message "number of array dimensions (16777216) exceeds the
maximum allowed (6)"

This is my code:
      int result_buf = 0;
      int result_len = 0;
      int result_is_int = 0;

      PQArgBlock args[1];
      int iFrom[] = {1,2};
      args[0].len = sizeof(iFrom) * 2;
      args[0].isint = 0;
      args[0].u.ptr = reinterpret_cast<int*> ( iFrom );

      PGresult* res = PQfn( m_conn, 1447769, &result_buf, &result_len,
result_is_int, args, 1 );
      if ( PQresultStatus(res) != PGRES_COMMAND_OK )
      {
         ::OutputDebugStringA( m_stringUtil.FormatEx("ExecFunc
failed!\n%s\n", PQresultErrorMessage(res))  );

         ReleaseResult( res );
         return false;
      }
      ReleaseResult( res );
      return true;


This is store procedure:
CREATE OR REPLACE FUNCTION ___a(oldUniqId INT[]) RETURNS BOOLEAN AS
$$
BEGIN
  RETURN TRUE;
  
END
$$ LANGUAGE plpgsql VOLATILE STRICT;  
ALTER FUNCTION ___a(INT[])
  OWNER TO postgres;


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #10014: Does not work PQfn in libpq with array
@ 2014-04-14 19:35  Heikki Linnakangas <hlinnakangas@vmware.com>
  parent: aleksey.vitaliev@transas.com
  0 siblings, 0 replies; 2+ messages in thread

From: Heikki Linnakangas @ 2014-04-14 19:35 UTC (permalink / raw)
  To: aleksey.vitaliev@transas.com; pgsql-bugs

On 04/14/2014 11:42 AM, aleksey.vitaliev@transas.com wrote:
> The following bug has been logged on the website:
>
> Bug reference:      10014
> Logged by:          Vitalyev Aleksey
> Email address:      aleksey.vitaliev@transas.com
> PostgreSQL version: 9.2.4
> Operating system:   Windows 7
> Description:
>
> I have a store procedure __a(INT[] args). I try execute this procedure with
> libpq and call PQfn function. How should I transmit array of int from c++
> code?

You probably shouldn't be using the PQfn function. Per the manual:

> Tip: This interface is somewhat obsolete, as one can achieve similar
> performance and greater functionality by setting up a prepared
> statement to define the function call. Then, executing the statement
> with binary transmission of parameters and results substitutes for a
> fast-path function call.

Constructing the binary format for arrays is quite complicated. You can 
look at the array_send/array_recv functions in the PostgreSQL source 
tree to see what's involved. There's also a library called libpqtypes 
out there that can do it for you. But it's a lot simpler to just use the 
text format.

Yet another approach is to pass the elements to the server separately, 
and construct the array in the server. Something like "SELECT 
myprocedure(ARRAY[?, ?, ?])".

- Heikki


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2014-04-14 19:35 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-04-14 08:42 BUG #10014: Does not work PQfn in libpq with array aleksey.vitaliev@transas.com
2014-04-14 19:35 ` Heikki Linnakangas <hlinnakangas@vmware.com>

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