Using Pointer to a structure for selecting multiple rows from a table [message #455312] |
Tue, 11 May 2010 02:20  |
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 #456579 is a reply to message #456036] |
Tue, 18 May 2010 09:42  |
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;
}
}
|
|
|