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

          Line data    Source code
       1             : #include <stdio.h>
       2             : #include <stdlib.h>
       3             : #include <string.h>
       4             : #include <limits.h>
       5             : 
       6             : exec sql include ../regression;
       7             : 
       8             : exec sql include pgtypes_numeric.h;
       9             : 
      10             : exec sql begin declare section;
      11             : exec sql include struct.h;
      12             : exec sql end declare section;
      13             : 
      14             : exec sql whenever sqlerror stop;
      15             : 
      16             : /* Functions for test 1 */
      17             : 
      18             : static void
      19           4 : get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
      20             : {
      21             :     exec sql begin declare section;
      22           4 :     MYTYPE      *myvar = malloc(sizeof(MYTYPE));
      23           4 :     MYNULLTYPE  *mynullvar = malloc(sizeof(MYNULLTYPE));
      24             :     exec sql end declare section;
      25             : 
      26             :     /* Test DECLARE ... SELECT ... INTO with pointers */
      27             : 
      28           4 :     exec sql declare mycur cursor for select * INTO :myvar :mynullvar from a1;
      29           4 : 
      30           4 :     if (sqlca.sqlcode != 0)
      31           0 :         exit(1);
      32             : 
      33           4 :     *myvar0 = myvar;
      34           4 :     *mynullvar0 = mynullvar;
      35           4 : }
      36             : 
      37             : static void
      38           4 : open_cur1(void)
      39             : {
      40           4 :     exec sql open mycur;
      41           8 : }
      42           4 : 
      43           4 : static void
      44           4 : get_record1(void)
      45           4 : {
      46          20 :     exec sql fetch mycur;
      47          36 : }
      48          20 : 
      49          20 : static void
      50          20 : close_cur1(void)
      51          16 : {
      52          20 :     exec sql close mycur;
      53          20 : }
      54          16 : 
      55          16 : int
      56          16 : main (void)
      57             : {
      58             :     MYTYPE      *myvar;
      59             :     MYNULLTYPE  *mynullvar;
      60             :     int loopcount;
      61             :     char msg[128];
      62             : 
      63           4 :     ECPGdebug(1, stderr);
      64             : 
      65           4 :     strcpy(msg, "connect");
      66           4 :     exec sql connect to REGRESSDB1;
      67           4 : 
      68           4 :     strcpy(msg, "set");
      69           4 :     exec sql set datestyle to iso;
      70           4 : 
      71           4 :     strcpy(msg, "create");
      72           4 :     exec sql create table a1(id serial primary key, t text, d1 numeric, d2 float8, c character(10));
      73           4 : 
      74           4 :     strcpy(msg, "insert");
      75           4 :     exec sql insert into a1(id, t, d1, d2, c) values (default, 'a', 1.0, 2, 'a');
      76           4 :     exec sql insert into a1(id, t, d1, d2, c) values (default, null, null, null, null);
      77           4 :     exec sql insert into a1(id, t, d1, d2, c) values (default, 'b', 2.0, 3, 'b');
      78           4 : 
      79           4 :     strcpy(msg, "commit");
      80           4 :     exec sql commit;
      81           4 : 
      82             :     /* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */
      83             : 
      84           4 :     get_var1(&myvar, &mynullvar);
      85           4 :     open_cur1();
      86             : 
      87          16 :     for (loopcount = 0; loopcount < 100; loopcount++)
      88             :     {
      89          16 :         memset(myvar, 0, sizeof(MYTYPE));
      90          16 :         get_record1();
      91          16 :         if (sqlca.sqlcode == ECPG_NOT_FOUND)
      92           4 :             break;
      93          60 :         printf("id=%d%s t='%s'%s d1=%f%s d2=%f%s c = '%s'%s\n",
      94          12 :             myvar->id, mynullvar->id ? " (NULL)" : "",
      95          12 :             myvar->t, mynullvar->t ? " (NULL)" : "",
      96          12 :             myvar->d1, mynullvar->d1 ? " (NULL)" : "",
      97          12 :             myvar->d2, mynullvar->d2 ? " (NULL)" : "",
      98          24 :             myvar->c, mynullvar->c ? " (NULL)" : "");
      99             :     }
     100             : 
     101           4 :     close_cur1();
     102             : 
     103           4 :     free(myvar);
     104           4 :     free(mynullvar);
     105             : 
     106           4 :     strcpy(msg, "drop");
     107           4 :     exec sql drop table a1;
     108           4 : 
     109           4 :     strcpy(msg, "commit");
     110           4 :     exec sql commit;
     111           4 : 
     112           4 :     strcpy(msg, "disconnect");
     113           4 :     exec sql disconnect;
     114           4 : 
     115           4 :     return 0;
     116             : }

Generated by: LCOV version 1.14