Home » Developer & Programmer » Precompilers, OCI & OCCI » Using Pointer to a structure for selecting multiple rows from a table (Oracle 10g)
Using Pointer to a structure for selecting multiple rows from a table [message #455312] Tue, 11 May 2010 02:20 Go to next message
kunalkumar2611
Messages: 4
Registered: April 2010
Junior Member
Hi All,

I am working on Pro*C and i have a requirement where i need to select all the rows from a table into a c - structure variable. Since i get to know the no of rows in the table which is getting selected only at run time, i need to create a pointer variable to the structure and i'll allocate the size to it based on the count of rows in the table using malloc or calloc.

I tried allocating memory using calloc and it does not show any error. But when i when the exec select statement run it shows an error.

Statements i have used:
struct common *comp;
struct common_ind *comp_i;

comp = (struct common*) calloc(rowcount, sizeof(struct common));
comp_i = (struct common_ind*) calloc(rowcount, sizeof(struct common_ind));

exec sql at db1 select * into :comp indicator :comp_i from tab1;

Error i get :

Stop Error: -2112
Stop Error: -1012
Stop Error: -1012


I am not able to understand this error.Any help on this will be appreciated. And if there is any other better way of doing the same also will be good help.

Thanks

[Updated on: Tue, 11 May 2010 02:21]

Report message to a moderator

Re: Using Pointer to a structure for selecting multiple rows from a table [message #456036 is a reply to message #455312] Fri, 14 May 2010 04:08 Go to previous messageGo to next message
culllcfc
Messages: 3
Registered: December 2008
Junior Member
With out giving this to much thought... What i would do in this senario would be to create a cursor and loop through each record adding them one at a time to a structure array.

I have never tried doing a select * into a sturcture in Pro*C so do not know if this is possible.

Hope this helps

Mark
Re: Using Pointer to a structure for selecting multiple rows from a table [message #456579 is a reply to message #456036] Tue, 18 May 2010 09:42 Go to previous message
mjm22
Messages: 54
Registered: January 2010
Location: Singapore
Member
I agree with Mark here. Declare a Cursor for your SQL and then do the select into your structure / indicator structure. Control it with a Batch Size (integer type) for improved performance... then you can insert the fetched rows into an array.
    for (;;)
    {
        EXEC SQL FOR :dbBatchSize
               FETCH curGetTheRows
                INTO :comp:comp_i;
 
        iZeroRowCheck = sqlca.sqlcode;
        iFetched = sqlca.sqlerrd[2];

        for (iLoop = 0; iLoop < (iFetched - iProcessed); iLoop++)
        {
            // if you  like you can populate an array in here with the fetched records
        }
        iProcessed = iFetched;

        if (iZeroRowCheck == 1403)
        {
            break;
        }
    }
Previous Topic: Profortran EXEC SQL coredump
Next Topic: NULL values in C Structures
Goto Forum:
  


Current Time: Sun Jun 20 14:18:19 CDT 2021