开发者

ECPG invocation of stored procedure with an array argument

I have a ECPG client attempting to obtain data. It uses a a prepared statement with a subselect clause using a stored function "getsipid" that takes 4 arguments. I have had this开发者_如何学Python working with the 4th argument declared as a simple varchar. I have tried to declare the 4th argument as an array however, ecpg is only passing the first argument of the array in the 4th arg and not all of them.

What is the trick to passsing the entire arry of requsr(s). This array size would typically only contain upto 5 arguements. I realize I could just add more arguments to the function to overcome this issue. I was hoping the solution would be more elegant.

Thanks for your comments

Dave

EXEC SQL BEGIN DECLARE SECTION;
const char* cid = connid;
const char* tgrp;      // group key ( trk )
const char* cca;       // call control agent key ( trk )
const char* dhost;     // dest host key (trk)
const char* regusr[MAX_USRS];   // Registration user (lin)
EXEC SQL END DECLARE SECTION;

The pgc file prepares the above host variables and the there is an invocation to the effect.

EXEC SQL AT :cid PREPARE ps_portdataviasip FROM
       "SELECT * FROM port LEFT JOIN linesip USING (id)\
                           LEFT JOIN trunksip USING (id)\
                           LEFT JOIN customer USING (cid)\
                       WHERE port.id =  (SELECT getsipid(?, ?, ?, ?))\
                       ORDER BY registersip.expiration DESC"; 
EXEC SQL AT :cid DECLARE cur_portsip CURSOR FOR ps_portdataviasip;
EXEC SQL AT :cid OPEN cur_portsip USING :cca, :tgrp, :dhost, :regusr;
EXEC SQL AT :cid FETCH NEXT FROM cur_portsip INTO DESCRIPTOR sqlda;

The stored function is declared as

CREATE OR REPLACE FUNCTION getsipid(cca character varying, tgrp character varying, 
    dhost character varying, usr character varying[]) RETURNS INTEGER AS


The problem typically is that you need to process the array to be in the PostgreSQL string representation. Typically this means converting it to CSV and surrounding it with appropriate brackets. So you get something like '{"myuser2","myuser1","myuser321"}'

This is actually pretty typical in a lot of environments, not only ecpg.

A second approach might be to make the function variadic and just pass the args in that way. Then they will come in as an array and you get to use them as such, but you pass them as individual arguments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜