Martijn van Oosterhout wrote:
for (i=0; i<NVARS; i++)
{
sprintf(stmt,"SELECT %s FROM beamdata GROUP BY %s;",vars[i],vars[i]);
EXEC SQL PREPARE mystmt FROM :stmt;
EXEC SQL EXECUTE mystmt INTO wherever;
n_occ[i] = sqlca.sqlerrd[2];
}
Apologies. I already read this in the docs, but also forgot it again.
:-| There is a little more to the solution since I need another array to
save the retrieved data after each query. So in the hope to help others,
here's how I did it:
int *all_vars[NVARS];
int *tmp=NULL;
for (i=0; i<NVARS; i++)
{
sprintf(stmt,"SELECT %s FROM beamdata GROUP BY %s;",vars[i],vars[i]);
EXEC SQL PREPARE query FROM :stmt;
EXEC SQL EXECUTE query INTO :tmp;
n_occ[i] = sqlca.sqlerrd[2]; /* Number of rows processed in query */
if ((all_vars[i]=(int *)malloc(n_occ[i]*sizeof(int)))==NULL)
{
fprintf(stderr,"Memory allocation failure\n");
exit(-1);
}
memcpy(all_vars[i], tmp, n_occ[i]*sizeof(int));
EXEC SQL DEALLOCATE PREPARE query;
tmp=NULL;
}
(Remember to free allocated memory when done)
Thanks so much for the help!