Thread: USE OF CURSORS IN ECPG

USE OF CURSORS IN ECPG

From
"Maurizio"
Date:
Hi,
I'm just starded using ecpg and I have some problem with cursors.
 
I wrote this lines
 
exec sql begin declare section;
    char query[500];
    int CodImpianto;
    int Cod1;
    int Cod2;
    char Descr[100];
exec sql end declare section;
strcpy(query, "select ............");
 
exec sql connect db;
 
sub1()
{
    exec sql prepare stmtunimpianto from :query;
    exec sql declare CUR_UNIMPIANTO cursor for stmtunimpianto;
    .
    .
    .
 
    exec sql open CUR_UNIMPIANTO using :CodImpianto;
    exec sql fetch CUR_UNIMPIANTO into :CodImpianto, :Descr;
    .
    .
 
    exec sql close CUR_UNIMPIANTO;
    exec sql execute StmtUpdImpianti using :Cod1, :Descr, :Cod2;
    exec sql commit;
}
 
I call this routine a lot of time.
If I rem the commit all works fine but if I execute the commit the cursor was deleted and I receive some errors.
 
At open cursor : sqlca.sqlcode = -230 Invalid statement namei in line ......
at fetch           : NOTICE : PerformPortalFetch: portal "cur_unimpianto" not found
 
Please could anyone help me ?
 
thanks
 
regards
Maurizio Cauci
DREAMTECH di Cauci Maurizio
Via Ronchetti, 2 - 21013 Gallarate (VA)
www.dreamtech-it.com

Re: USE OF CURSORS IN ECPG

From
Michael Meskes
Date:
On Tue, Nov 07, 2000 at 05:52:00PM +0100, Maurizio wrote:
> I'm just starded using ecpg and I have some problem with cursors.
> ...
>     exec sql prepare stmtunimpianto from :query;
>     .
>     .
>     exec sql commit;
> ...
> If I rem the commit all works fine but if I execute the commit the cursor was deleted and I receive some errors.
> 
> At open cursor : sqlca.sqlcode = -230 Invalid statement namei in line ......
> at fetch           : NOTICE : PerformPortalFetch: portal "cur_unimpianto" not found

No surprise here as ending a transaction forces a deallocation of all
prepared statements. AFAIK that's what the standard says.

Michael

-- 
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!