What the PRO*C Pre-Compiler Does

Here's a sample set of PRO*C statements imbedded in the previous program. The statements expand into C code which can be compiled and executed. No magic here!

The PRO*C Code

/* Branch to the notfound label when the
 * 1403 ("No data found") condition occurs.
 */
        /* EXEC SQL WHENEVER NOT FOUND GOTO notfound; */ 

        /* EXEC SQL SELECT ename, sal, comm
            INTO :emprec INDICATOR :emprec_ind
            FROM EMP
            WHERE EMPNO = :emp_number; */ 

The resulting C Code

{
        sqlstm.stmt = "select ename ,sal ,comm into :s1:s2 ,:s3:s4 ,:s5:s6  \
 from EMP where EMPNO=:b2";
        sqlstm.iters = (unsigned int  )1;
        sqlstm.offset = (unsigned int  )28;
        sqlstm.selerr = (unsigned short)1;
        sqlstm.cud = sqlcud0;
        sqlstm.sqlest = (unsigned char  *)&sqlca;
        sqlstm.sqlety = (unsigned short)0;
        sqlstm.sqhstv[0] = (unsigned char  *)&emprec.emp_name;
        sqlstm.sqhstl[0] = (unsigned int  )22;
        sqlstm.sqindv[0] = (         short *)&emprec_ind.emp_name_ind;
        sqlstm.sqharm[0] = (unsigned int  )0;
        sqlstm.sqhstv[1] = (unsigned char  *)&emprec.salary;
        sqlstm.sqhstl[1] = (unsigned int  )4;
        sqlstm.sqindv[1] = (         short *)&emprec_ind.sal_ind;
        sqlstm.sqharm[1] = (unsigned int  )0;
        sqlstm.sqhstv[2] = (unsigned char  *)&emprec.commission;
        sqlstm.sqhstl[2] = (unsigned int  )4;
        sqlstm.sqindv[2] = (         short *)&emprec_ind.comm_ind;
        sqlstm.sqharm[2] = (unsigned int  )0;
        sqlstm.sqhstv[3] = (unsigned char  *)&emp_number;
        sqlstm.sqhstl[3] = (unsigned int  )4;
        sqlstm.sqindv[3] = (         short *)0;
        sqlstm.sqharm[3] = (unsigned int  )0;
        sqlstm.sqphsv = sqlstm.sqhstv;
        sqlstm.sqphsl = sqlstm.sqhstl;
        sqlstm.sqpind = sqlstm.sqindv;
        sqlstm.sqparm = sqlstm.sqharm;
        sqlstm.sqparc = sqlstm.sqharc;
        sqlcex(&sqlctx, &sqlstm, &sqlfpn);
        if (sqlca.sqlcode == 1403) goto notfound;
        if (sqlca.sqlcode < 0) sql_error("ORACLE error--\n");
}


Bob Dugan dugan@rpi.edu