LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/preproc - whenever_do_continue.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 24 24 100.0 %
Date: 2019-09-19 02:07:14 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdlib.h>
       2             : 
       3             : exec sql include ../regression;
       4             : 
       5             : exec sql whenever sqlerror stop;
       6             : 
       7           4 : int main(void)
       8             : {
       9             :     exec sql begin declare section;
      10             :     struct
      11             :     {
      12             :         char ename[12];
      13             :         float sal;
      14             :         float comm;
      15             :     } emp;
      16             :     int loopcount;
      17             :     char msg[128];
      18             :     exec sql end declare section;
      19             : 
      20           4 :     ECPGdebug(1, stderr);
      21             : 
      22           4 :     strcpy(msg, "connect");
      23           4 :     exec sql connect to REGRESSDB1;
      24           4 : 
      25           4 :     strcpy(msg, "create");
      26           4 :     exec sql  create table emp(ename varchar,sal double precision, comm double precision);
      27           4 : 
      28           4 :     strcpy(msg, "insert");
      29           4 :     exec sql insert into emp values ('Ram',111100,21);
      30           4 :     exec sql insert into emp values ('aryan',11110,null);
      31           4 :     exec sql insert into emp values ('josh',10000,10);
      32           4 :     exec sql insert into emp values ('tom',20000,null);
      33           4 : 
      34             :     exec sql declare c cursor for select ename, sal, comm from emp order by ename collate "C" asc;
      35             : 
      36           4 :     exec sql open c;
      37           4 : 
      38             :     /* The 'BREAK' condition to exit the loop. */
      39             :     exec sql whenever not found do break;
      40             : 
      41             :     /* The DO CONTINUE makes the loop start at the next iteration when an error occurs.*/
      42             :     exec sql whenever sqlerror do continue;
      43             : 
      44          20 :     for (loopcount = 0; loopcount < 100; loopcount++)
      45             :     {
      46          20 :         exec sql fetch c into :emp;
      47          20 :         /* The employees with non-NULL commissions will be displayed. */
      48           8 :         printf("%s %7.2f %9.2f\n", emp.ename, emp.sal, emp.comm);
      49             :     }
      50             : 
      51             :     /*
      52             :      * This 'CONTINUE' shuts off the 'DO CONTINUE' and allow the program to
      53             :      * proceed if any further errors do occur.
      54             :      */
      55             :     exec sql whenever sqlerror continue;
      56             : 
      57           4 :     exec sql close c;
      58             : 
      59           4 :     strcpy(msg, "drop");
      60           4 :     exec sql drop table emp;
      61             : 
      62           4 :     exit(0);
      63             : }

Generated by: LCOV version 1.13