LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/preproc - pointer_to_struct.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 39 39 100.0 %
Date: 2024-11-21 08:14:44 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdio.h>
       2             : #include <stdlib.h>
       3             : 
       4             : exec sql include ../regression;
       5             : 
       6             : EXEC SQL WHENEVER sqlerror sqlprint;
       7             : EXEC SQL WHENEVER sqlwarning sqlprint;
       8             : EXEC SQL WHENEVER not found sqlprint;
       9             : 
      10             : EXEC SQL TYPE customer IS
      11             :     struct
      12             :     {
      13             :         varchar name[50];
      14             :         int     phone;
      15             :     };
      16             : 
      17             : EXEC SQL TYPE cust_ind IS
      18             :     struct ind
      19             :     {
      20             :         short   name_ind;
      21             :         short   phone_ind;
      22             :     };
      23             : 
      24           4 : int main()
      25             : {
      26             :     EXEC SQL begin declare section;
      27           4 :       customer  *custs1 = (customer *) malloc(sizeof(customer) * 10);
      28           4 :       cust_ind  *inds = (cust_ind *) malloc(sizeof(cust_ind) * 10);
      29             :       typedef struct
      30             :       {
      31             :         varchar name[50];
      32             :         int     phone;
      33             :       } customer2;
      34           4 :       customer2  *custs2 = (customer2 *) malloc(sizeof(customer2) * 10);
      35             : 
      36             :       struct customer3
      37             :       {
      38             :         char name[50];
      39             :         int     phone;
      40           4 :       } *custs3 = (struct customer3 *) malloc(sizeof(struct customer3) * 10);
      41             : 
      42             :       struct customer4
      43             :       {
      44             :         varchar name[50];
      45             :         int     phone;
      46           4 :       } *custs4 = (struct customer4 *) malloc(sizeof(struct customer4));
      47             : 
      48             :       int r;
      49             :       varchar onlyname[2][50];
      50             :     EXEC SQL end declare section;
      51             : 
      52           4 :     ECPGdebug(1, stderr);
      53             : 
      54           4 :     EXEC SQL connect to REGRESSDB1;
      55           4 : 
      56           4 :     EXEC SQL create table customers (c varchar(50), p int);
      57           4 :     EXEC SQL insert into customers values ('John Doe', '12345');
      58           4 :     EXEC SQL insert into customers values ('Jane Doe', '67890');
      59           4 : 
      60           4 :     EXEC SQL select * INTO :custs1:inds from customers limit 2;
      61           4 :     printf("custs1:\n");
      62          12 :     for (r = 0; r < 2; r++)
      63             :     {
      64           8 :         printf( "name  - %s\n", custs1[r].name.arr );
      65           8 :         printf( "phone - %d\n", custs1[r].phone );
      66             :     }
      67             : 
      68           4 :     EXEC SQL select * INTO :custs2:inds from customers limit 2;
      69           4 :     printf("\ncusts2:\n");
      70          12 :     for (r = 0; r < 2; r++)
      71             :     {
      72           8 :         printf( "name  - %s\n", custs2[r].name.arr );
      73           8 :         printf( "phone - %d\n", custs2[r].phone );
      74             :     }
      75             : 
      76           4 :     EXEC SQL select * INTO :custs3:inds from customers limit 2;
      77           4 :     printf("\ncusts3:\n");
      78          12 :     for (r = 0; r < 2; r++)
      79             :     {
      80           8 :         printf( "name  - %s\n", custs3[r].name );
      81           8 :         printf( "phone - %d\n", custs3[r].phone );
      82             :     }
      83             : 
      84           4 :     EXEC SQL select * INTO :custs4:inds from customers limit 1;
      85           4 :     printf("\ncusts4:\n");
      86           4 :     printf( "name  - %s\n", custs4->name.arr );
      87           4 :     printf( "phone - %d\n", custs4->phone );
      88             : 
      89           4 :     EXEC SQL select c INTO :onlyname from customers limit 2;
      90           4 :     printf("\nname:\n");
      91          12 :     for (r = 0; r < 2; r++)
      92             :     {
      93           8 :         printf( "name  - %s\n", onlyname[r].arr );
      94             :     }
      95             : 
      96           4 :     EXEC SQL disconnect all;
      97           4 : 
      98             :     /* All the memory will anyway be freed at the end */
      99           4 :     return 0;
     100             : }

Generated by: LCOV version 1.14