LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/preproc - array_of_struct.pgc (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 42 42
Test Date: 2026-07-14 21:15:44 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 56.5 % 62 35

             Branch data     Line data    Source code
       1                 :             : #include <stdio.h>
       2                 :             : 
       3                 :             : exec sql include ../regression;
       4                 :             : 
       5                 :             : EXEC SQL WHENEVER sqlerror sqlprint;
       6                 :             : EXEC SQL WHENEVER sqlwarning sqlprint;
       7                 :             : EXEC SQL WHENEVER not found sqlprint;
       8                 :             : 
       9                 :             : EXEC SQL TYPE customer IS
      10                 :             :     struct
      11                 :             :     {
      12                 :             :         varchar name[50];
      13                 :             :         int     phone;
      14                 :             :     };
      15                 :             : 
      16                 :             : EXEC SQL TYPE cust_ind IS
      17                 :             :     struct ind
      18                 :             :     {
      19                 :             :         short   name_ind;
      20                 :             :         short   phone_ind;
      21                 :             :     };
      22                 :             : 
      23                 :             : EXEC SQL TYPE company IS
      24                 :             :     struct
      25                 :             :     {
      26                 :             :         customer customers[10];
      27                 :             :     };
      28                 :             : 
      29                 :           2 : int main(void)
      30                 :             : {
      31                 :             :     EXEC SQL begin declare section;
      32                 :             :       customer  custs1[10];
      33                 :             :       cust_ind  inds[10];
      34                 :             :       typedef struct
      35                 :             :       {
      36                 :             :         varchar name[50];
      37                 :             :         int     phone;
      38                 :             :       } customer2;
      39                 :             :       customer2  custs2[10];
      40                 :             :       struct customer3
      41                 :             :       {
      42                 :             :         varchar name[50];
      43                 :             :         int     phone;
      44                 :             :       } custs3[10];
      45                 :             :       struct customer4
      46                 :             :       {
      47                 :             :         varchar name[50];
      48                 :             :         int     phone;
      49                 :             :       } custs4;
      50                 :             : 
      51                 :             :       company acme;
      52                 :             : 
      53                 :             :       int r;
      54                 :             :       varchar onlyname[2][50];
      55                 :             :     EXEC SQL end declare section;
      56                 :             : 
      57                 :           2 :     ECPGdebug(1, stderr);
      58                 :             : 
      59                 :           2 :     EXEC SQL connect to REGRESSDB1;
      60   [ -  +  -  + ]:           2 : 
      61                 :           2 :     EXEC SQL create table customers (c varchar(50), p int);
      62   [ -  +  -  + ]:           2 : 
      63                 :             :     /* First we'll insert some data using C variable references */
      64                 :           2 :     strcpy(custs1[0].name.arr, "John Doe");
      65                 :           2 :     custs1[0].name.len = strlen(custs1[0].name.arr);
      66                 :           2 :     custs1[0].phone = 12345;
      67                 :             : 
      68                 :           2 :     strcpy(acme.customers[1].name.arr, "Jane Doe");
      69                 :           2 :     acme.customers[1].name.len = strlen(acme.customers[1].name.arr);
      70                 :           2 :     acme.customers[1].phone = 67890;
      71                 :             : 
      72                 :           2 :     EXEC SQL insert into customers values (:custs1->name,
      73                 :             :                                            :custs1[0].phone);
      74   [ -  +  -  +  :           2 :     EXEC SQL insert into customers values (:acme.customers[1].name,
                   -  + ]
      75                 :             :                                            :acme.customers[1].phone);
      76   [ -  +  -  +  :           2 : 
                   -  + ]
      77                 :             :     /* Clear the array, to be sure reading back into it actually gets data */
      78                 :           2 :     memset(custs1, 0, sizeof(customer) * 10);
      79                 :             : 
      80                 :             :     /* Now read back the data */
      81                 :           2 :     EXEC SQL select * INTO :custs1:inds from customers limit 2;
      82   [ -  +  -  +  :           2 :     printf("custs1:\n");
                   -  + ]
      83         [ +  + ]:           6 :     for (r = 0; r < 2; r++)
      84                 :             :     {
      85                 :           4 :         printf( "name  - %s\n", custs1[r].name.arr );
      86                 :           4 :         printf( "phone - %d\n", custs1[r].phone );
      87                 :             :     }
      88                 :             : 
      89                 :           2 :     EXEC SQL select * INTO :custs2:inds from customers limit 2;
      90   [ -  +  -  +  :           2 :     printf("\ncusts2:\n");
                   -  + ]
      91         [ +  + ]:           6 :     for (r = 0; r < 2; r++)
      92                 :             :     {
      93                 :           4 :         printf( "name  - %s\n", custs2[r].name.arr );
      94                 :           4 :         printf( "phone - %d\n", custs2[r].phone );
      95                 :             :     }
      96                 :             : 
      97                 :           2 :     EXEC SQL select * INTO :custs3:inds from customers limit 2;
      98   [ -  +  -  +  :           2 :     printf("\ncusts3:\n");
                   -  + ]
      99         [ +  + ]:           6 :     for (r = 0; r < 2; r++)
     100                 :             :     {
     101                 :           4 :         printf( "name  - %s\n", custs3[r].name.arr );
     102                 :           4 :         printf( "phone - %d\n", custs3[r].phone );
     103                 :             :     }
     104                 :             : 
     105                 :           2 :     EXEC SQL select * INTO :custs4:inds[0] from customers limit 1;
     106   [ -  +  -  +  :           2 :     printf("\ncusts4:\n");
                   -  + ]
     107                 :           2 :     printf( "name  - %s\n", custs4.name.arr );
     108                 :           2 :     printf( "phone - %d\n", custs4.phone );
     109                 :             : 
     110                 :           2 :     EXEC SQL select c INTO :onlyname from customers limit 2;
     111   [ -  +  -  +  :           2 :     printf("\nname:\n");
                   -  + ]
     112         [ +  + ]:           6 :     for (r = 0; r < 2; r++)
     113                 :             :     {
     114                 :           4 :         printf( "name  - %s\n", onlyname[r].arr );
     115                 :             :     }
     116                 :             : 
     117                 :           2 :     EXEC SQL disconnect all;
     118   [ -  +  -  + ]:           2 : 
     119                 :           2 :     return 0;
     120                 :             : }
        

Generated by: LCOV version 2.0-1