#include <stdio.h>



EXEC SQL WHENEVER sqlerror sqlprint;
EXEC SQL WHENEVER sqlwarning sqlprint;
EXEC SQL WHENEVER not found sqlprint;



void main (){

	int i;
 EXEC SQL BEGIN DECLARE SECTION;
	
	struct employee {
   		int empno;
	   char ename[11];
	   char job[15];
	}; 

	int empno;
	char ename[11];
	char job[15];

	
	struct employee emp[14];
	struct employee *emp2 = emp;

 EXEC SQL END DECLARE SECTION;

	
	EXEC SQL CONNECT TO 'unix:postgresql://localhost/postgres' AS main USER ashutosh;

    EXEC SQL DECLARE cur1 CURSOR FOR  select empno, ename, job from emp;

    EXEC SQL OPEN cur1;

    /* Fetch multiple columns into one structure. */
    EXEC SQL FETCH 3 FROM cur1 INTO :emp2;

    for (i = 0; i < 3; i++)
    {
        /* Print members of the structure. */
        printf("empno=%d, ename=%s, job=%s\n", emp2[i].empno, emp2[i].ename, emp2[i].job);
    }

    EXEC SQL CLOSE cur1;

	EXEC SQL DISCONNECT;
}
