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

          Line data    Source code
       1             : #include <stdlib.h>
       2             : #include <string.h>
       3             : 
       4             : exec sql include ../regression;
       5             : 
       6             : exec sql whenever sqlerror stop;
       7             : 
       8             : exec sql type c is char reference;
       9             : typedef char* c;
      10             : 
      11             : exec sql type ind is union { int integer; short smallint; };
      12             : typedef union { int integer; short smallint; } ind;
      13             : 
      14             : #define BUFFERSIZ 8
      15             : exec sql type str is varchar[BUFFERSIZ];
      16             : 
      17             : exec sql declare cur cursor for
      18             :        select name, born, age, married, children from family;
      19             : 
      20             : int
      21           4 : main (void)
      22             : {
      23             :     exec sql struct birthinfo { long born; short age; };
      24             : exec sql begin declare section;
      25             :     struct personal_struct  {   str name;
      26             :                     struct birthinfo birth;
      27             :                 } personal, *p;
      28             :     struct personal_indicator { int ind_name;
      29             :                     struct birthinfo ind_birth;
      30             :                   } ind_personal, *i;
      31             :     ind ind_children;
      32             :     struct t1 { str name; }; struct t2 { str name; };
      33             : exec sql end declare section;
      34             : 
      35           4 :     exec sql char *married = NULL;
      36             :     exec sql long ind_married;
      37             :     exec sql ind children;
      38             :     int loopcount;
      39             :     char msg[128];
      40             : 
      41           4 :         ECPGdebug(1, stderr);
      42             : 
      43           4 :     strcpy(msg, "connect");
      44           4 :     exec sql connect to REGRESSDB1;
      45           4 : 
      46           4 :     strcpy(msg, "set");
      47           4 :     exec sql set datestyle to iso;
      48           4 : 
      49           4 :     strcpy(msg, "create");
      50           4 :     exec sql create table family(name char(8), born integer, age smallint, married date, children integer);
      51           4 : 
      52           4 :     strcpy(msg, "insert");
      53           4 :     exec sql insert into family(name, married, children) values ('Mum', '19870714', 3);
      54           4 :     exec sql insert into family(name, born, married, children) values ('Dad', '19610721', '19870714', 3);
      55           4 :     exec sql insert into family(name, age) values ('Child 1', 16);
      56           4 :     exec sql insert into family(name, age) values ('Child 2', 14);
      57           4 :     exec sql insert into family(name, age) values ('Child 3', 9);
      58           4 : 
      59           4 :     strcpy(msg, "commit");
      60           4 :     exec sql commit;
      61           4 : 
      62           4 :     strcpy(msg, "open");
      63           4 :     exec sql open cur;
      64           4 : 
      65             :     exec sql whenever not found do break;
      66             : 
      67           4 :     p=&personal;
      68           4 :     i=&ind_personal;
      69           4 :     memset(i, 0, sizeof(ind_personal));
      70          24 :     for (loopcount = 0; loopcount < 100; loopcount++) {
      71          24 :         strcpy(msg, "fetch");
      72          24 :         exec sql fetch cur into :p:i, :married:ind_married, :children.integer:ind_children.smallint;
      73          24 :         printf("%8.8s", personal.name.arr);
      74          20 :         if (i->ind_birth.born >= 0)
      75           4 :             printf(", born %ld", personal.birth.born);
      76          20 :         if (i->ind_birth.age >= 0)
      77          12 :             printf(", age = %d", personal.birth.age);
      78          20 :         if (ind_married >= 0)
      79           8 :             printf(", married %s", married);
      80          20 :         if (ind_children.smallint >= 0)
      81           8 :             printf(", children = %d", children.integer);
      82          20 :         putchar('\n');
      83             : 
      84          20 :         free(married);
      85          20 :         married = NULL;
      86             :     }
      87             : 
      88           4 :     strcpy(msg, "close");
      89           4 :     exec sql close cur;
      90           4 : 
      91           4 :     strcpy(msg, "drop");
      92           4 :     exec sql drop table family;
      93           4 : 
      94           4 :     strcpy(msg, "commit");
      95           4 :     exec sql commit;
      96           4 : 
      97           4 :     strcpy(msg, "disconnect");
      98           4 :     exec sql disconnect;
      99           4 : 
     100           4 :     return 0;
     101             : }

Generated by: LCOV version 1.13