Placing array in temp table
Hi. I spent all of testerday making the code below that selects all the records from the cc_lkup table and places them in array of structs cc_lkup2[]. I have been asked to now place the contents of the array into a temp table called codes. Can someone please help me with a solution. I am really struggling with embeddd SQL and I am waiting for INGRES to call me back with training schedule. The jnl, log_it and err_supv are just functions we use for error handling. Thanks for any help.
-Carl
Code:
EXEC SQL DECLARE c1 CURSOR for
SELECT cc, cc_sn, cc_desc, cc_grp
FROM cc_lkup
WHERE cc_grp != ''
ORDER BY cc;
status = err_supv(apl_nm, prog_nm, jnl.blk, stmt_purpose, &retry_cnt,
&err_num, err_txt, &row_count, jnl.val1, jnl.val2, popup_flag);
jnl.blk = 1701;
sprintf(jnl.mesg,"Selecting all records in cc_lkup that contain a group");
sprintf(jnl.grp,"CJ");
sprintf(jnl.mod,"Project.sc");
sprintf(stmt_purpose,"Selecting all records that contain a group");
log_it(log_file, jnl);
if (status != IMCS_DB_SUCCESS)
exit(1);
EXEC SQL OPEN c1;
status = err_supv(apl_nm, prog_nm, jnl.blk, stmt_purpose, &retry_cnt,
&err_num, err_txt, &row_count, jnl.val1, jnl.val2, popup_flag);
jnl.blk = 1702;
sprintf(jnl.mesg,"Opening cursor name c1");
sprintf(jnl.grp,"CJ");
sprintf(jnl.mod,"Project.sc");
sprintf(stmt_purpose,"Opening cursor name c1");
log_it(log_file, jnl);
if (status != IMCS_DB_SUCCESS)
exit(1);
/* While loop to get all records from database table cc_lkup */
while (1)
{
EXEC SQL FETCH c1
INTO :cc_lkup2[y].cc, :cc_lkup2[y].cc_sn, :cc_lkup2[y].cc_desc, :cc_lkup2[y].cc_grp;
status = err_supv(apl_nm, prog_nm, jnl.blk, stmt_purpose, &retry_cnt,
&err_num, err_txt, &row_count, jnl.val1, jnl.val2, popup_flag);
if (row_count ==0 || status != IMCS_DB_SUCCESS)/*row_count value is 1 when array is filling with records and 0 when no records are left*/
break;
y++; /* increment array */
}
/*Write the details below to log when cursor is done finding records*/
/* or if none were found*/
if (row_count ==0)
{
jnl.blk = 1800;
sprintf(jnl.mesg,"Cursor is done placing records in my array");
sprintf(jnl.grp,"CJ");
sprintf(jnl.mod,"Project.sc");
sprintf(stmt_purpose,"Cursor is done placing records in my array");
log_it(log_file, jnl);
}
if (status != IMCS_DB_SUCCESS)
{
jnl.blk = 1805;
sprintf(jnl.mesg,"Cursor failed to place records into the array");
sprintf(jnl.grp,"CJ");
sprintf(jnl.mod,"Project.sc");
sprintf(stmt_purpose,"Cursor failed to place records into the array");
log_it(log_file, jnl);
}
/*Declared in main */
totalrecords = y;/*y holds the total number of records found*/
EXEC SQL CLOSE c1;