LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/preproc - array_of_struct.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 34 34 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 <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           4 : int main()
      24             : {
      25             :     EXEC SQL begin declare section;
      26             :       customer  custs1[10];
      27             :       cust_ind  inds[10];
      28             :       typedef struct
      29             :       {
      30             :         varchar name[50];
      31             :         int     phone;
      32             :       } customer2;
      33             :       customer2  custs2[10];
      34             :       struct customer3
      35             :       {
      36             :         varchar name[50];
      37             :         int     phone;
      38             :       } custs3[10];
      39             :       struct customer4
      40             :       {
      41             :         varchar name[50];
      42             :         int     phone;
      43             :       } custs4;
      44             :       int r;
      45             :       varchar onlyname[2][50];
      46             :     EXEC SQL end declare section;
      47             : 
      48           4 :     ECPGdebug(1, stderr);
      49             : 
      50           4 :     EXEC SQL connect to REGRESSDB1;
      51           4 : 
      52           4 :     EXEC SQL create table customers (c varchar(50), p int);
      53           4 :     EXEC SQL insert into customers values ('John Doe', '12345');
      54           4 :     EXEC SQL insert into customers values ('Jane Doe', '67890');
      55           4 : 
      56           4 :     EXEC SQL select * INTO :custs1:inds from customers limit 2;
      57           4 :     printf("custs1:\n");
      58          12 :     for (r = 0; r < 2; r++)
      59             :     {
      60           8 :         printf( "name  - %s\n", custs1[r].name.arr );
      61           8 :         printf( "phone - %d\n", custs1[r].phone );
      62             :     }
      63             : 
      64           4 :     EXEC SQL select * INTO :custs2:inds from customers limit 2;
      65           4 :     printf("\ncusts2:\n");
      66          12 :     for (r = 0; r < 2; r++)
      67             :     {
      68           8 :         printf( "name  - %s\n", custs2[r].name.arr );
      69           8 :         printf( "phone - %d\n", custs2[r].phone );
      70             :     }
      71             : 
      72           4 :     EXEC SQL select * INTO :custs3:inds from customers limit 2;
      73           4 :     printf("\ncusts3:\n");
      74          12 :     for (r = 0; r < 2; r++)
      75             :     {
      76           8 :         printf( "name  - %s\n", custs3[r].name.arr );
      77           8 :         printf( "phone - %d\n", custs3[r].phone );
      78             :     }
      79             : 
      80           4 :     EXEC SQL select * INTO :custs4:inds[0] from customers limit 1;
      81           4 :     printf("\ncusts4:\n");
      82           4 :     printf( "name  - %s\n", custs4.name.arr );
      83           4 :     printf( "phone - %d\n", custs4.phone );
      84             : 
      85           4 :     EXEC SQL select c INTO :onlyname from customers limit 2;
      86           4 :     printf("\nname:\n");
      87          12 :     for (r = 0; r < 2; r++)
      88             :     {
      89           8 :         printf( "name  - %s\n", onlyname[r].arr );
      90             :     }
      91             : 
      92           4 :     EXEC SQL disconnect all;
      93           4 : 
      94           4 :     return 0;
      95             : }

Generated by: LCOV version 1.13