LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/preproc - variable.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 59 59 100.0 %
Date: 2024-12-12 16:15:21 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             :     static varchar vc1[50], vc2[50], vc3[255];
      34             :     static int i1, i2, i3;
      35             : exec sql end declare section;
      36             : 
      37           4 :     exec sql char *married = NULL;
      38             :     exec sql long ind_married;
      39             :     exec sql ind children;
      40             :     int loopcount;
      41             :     char msg[128];
      42             : 
      43           4 :         ECPGdebug(1, stderr);
      44             : 
      45           4 :     strcpy(msg, "connect");
      46           4 :     exec sql connect to REGRESSDB1;
      47           4 : 
      48           4 :     strcpy(msg, "set");
      49           4 :     exec sql set datestyle to iso;
      50           4 : 
      51           4 :     strcpy(msg, "create");
      52           4 :     exec sql create table family(name char(8), born integer, age smallint, married date, children integer);
      53           4 : 
      54           4 :     strcpy(msg, "insert");
      55           4 :     exec sql insert into family(name, married, children) values ('Mum', '19870714', 3);
      56           4 :     exec sql insert into family(name, born, married, children) values ('Dad', '19610721', '19870714', 3);
      57           4 :     exec sql insert into family(name, age) values ('Child 1', 16);
      58           4 :     exec sql insert into family(name, age) values ('Child 2', 14);
      59           4 :     exec sql insert into family(name, age) values ('Child 3', 9);
      60           4 : 
      61           4 :     strcpy(msg, "commit");
      62           4 :     exec sql commit;
      63           4 : 
      64           4 :     strcpy(msg, "open");
      65           4 :     exec sql open cur;
      66           4 : 
      67             :     exec sql whenever not found do break;
      68             : 
      69           4 :     p=&personal;
      70           4 :     i=&ind_personal;
      71           4 :     memset(i, 0, sizeof(ind_personal));
      72          24 :     for (loopcount = 0; loopcount < 100; loopcount++) {
      73          24 :         strcpy(msg, "fetch");
      74          24 :         exec sql fetch cur into :p:i, :married:ind_married, :children.integer:ind_children.smallint;
      75          24 :         printf("%8.8s", personal.name.arr);
      76          20 :         if (i->ind_birth.born >= 0)
      77           4 :             printf(", born %ld", personal.birth.born);
      78          20 :         if (i->ind_birth.age >= 0)
      79          12 :             printf(", age = %d", personal.birth.age);
      80          20 :         if (ind_married >= 0)
      81           8 :             printf(", married %s", married);
      82          20 :         if (ind_children.smallint >= 0)
      83           8 :             printf(", children = %d", children.integer);
      84          20 :         putchar('\n');
      85             : 
      86          20 :         free(married);
      87          20 :         married = NULL;
      88             :     }
      89             : 
      90           4 :     strcpy(msg, "close");
      91           4 :     exec sql close cur;
      92           4 : 
      93           4 :     strcpy(msg, "drop");
      94           4 :     exec sql drop table family;
      95           4 : 
      96           4 :     strcpy(msg, "commit");
      97           4 :     exec sql commit;
      98           4 : 
      99           4 :     strcpy(msg, "disconnect");
     100           4 :     exec sql disconnect;
     101           4 : 
     102             :     /* this just to silence unused-variable warnings: */
     103           4 :     vc1.len = vc2.len = vc3.len = 0;
     104           4 :     i1 = i2 = i3 = 0;
     105           4 :     printf("%d %d %d %d %d %d\n",
     106             :            vc1.len, vc2.len, vc3.len,
     107             :            i1, i2, i3);
     108             : 
     109           4 :     return 0;
     110             : }

Generated by: LCOV version 1.14