Thread: ECPG and CURSOR declaration

ECPG and CURSOR declaration

From
"Frost, Mr. Michael (contractor)"
Date:
Hi All.  The following code compiles and works fine on 7.3.  However,
with 7.4 it doesn't make it through the compiler.  With 7.4 it seems to
want the cursor declare to be in the same subroutine as the fetch.

========================================================================
===========
#include <stdio.h>

void driver ( ) { void prepareIt ( char * ); EXEC SQL BEGIN DECLARE SECTION;     char sElect_G[2048];     long
lSubCenter_L,lProductionCenter_L, lModel_L, lGrid_L;     char szModelName_L[64];     char szProductCenterName_L[64];
EXECSQL END DECLARE SECTION;
 
 sprintf ( sElect_G, "SELECT %s %s FROM MDGRIDModels, MDGRIDProdCenters
WHERE MDGRIDModels.centerID = MDGRIDProdCenters.centerID AND
MDGRIDModels.subcenterID = MDGRIDProdCenters.subcenterID",           "MDGRIDModels.centerID,
MDGRIDModels.subcenterID,",          "generatingProc, gridID, modelName, productionCenter");
 
 prepareIt ( sElect_G );
            EXEC SQL FETCH CUR4LL INTO :lProductionCenter_L,                             :lSubCenter_L,
           :lModel_L,                             :lGrid_L,                             :szModelName_L,
           :szProductCenterName_L;
 


}

void prepareIt ( char *myString ) { EXEC SQL BEGIN DECLARE SECTION;     char sElect_G[2048]; EXEC SQL END DECLARE
SECTION;

  EXEC SQL PREPARE sQLstatement FROM :sElect_G;  EXEC SQL DECLARE CUR4LL CURSOR FOR sQLstatement;  EXEC SQL OPEN
CUR4LL;

}
========================================================================
=========


Thanks,
Michael Frost


Re: ECPG and CURSOR declaration

From
Michael Fuhr
Date:
On Wed, Jan 12, 2005 at 08:04:24AM -0800, Frost, Mr. Michael (contractor) wrote:

> Hi All.  The following code compiles and works fine on 7.3.  However,
> with 7.4 it doesn't make it through the compiler.  With 7.4 it seems to
> want the cursor declare to be in the same subroutine as the fetch.

The exact error message might tell us more than "seems to want."
I wrote a test program similar to yours and got the following error
when I ran ecpg:

curstest.pgc:23: ERROR: trying to access an undeclared cursor testcurs

I moved the function that declares the cursor to earlier in the
file so it came before the function that used the cursor.  The
program then compiled and ran fine using 8.0.0rc5.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/