LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/preproc - cursor.pgc (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 188 188
Test Date: 2026-07-25 22:15:46 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 50.0 % 130 65

             Branch data     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                 :             : #define CURNAME "mycur"
      18                 :             : 
      19                 :             : int
      20                 :           2 : main (void)
      21                 :             : {
      22                 :             : exec sql begin declare section;
      23                 :           2 :     char    *stmt1 = "SELECT id, t FROM t1";
      24                 :           2 :     char    *curname1 = CURNAME;
      25                 :           2 :     char    *curname2 = CURNAME;
      26                 :           2 :     char    *curname3 = CURNAME;
      27                 :             :     varchar curname4[50];
      28                 :           2 :     char    *curname5 = CURNAME;
      29                 :             :     int count;
      30                 :             :     int id;
      31                 :             :     char    t[64];
      32                 :             : exec sql end declare section;
      33                 :             : 
      34                 :             :     char msg[128];
      35                 :             : 
      36                 :           2 :     ECPGdebug(1, stderr);
      37                 :             : 
      38                 :           2 :     strcpy(msg, "connect");
      39                 :           2 :     exec sql connect to REGRESSDB1 as test1;
      40         [ -  + ]:           2 :     exec sql connect to REGRESSDB2 as test2;
      41         [ -  + ]:           2 : 
      42                 :           2 :     strcpy(msg, "set");
      43                 :           2 :     exec sql at test1 set datestyle to iso;
      44         [ -  + ]:           2 : 
      45                 :           2 :     strcpy(msg, "create");
      46                 :           2 :     exec sql at test1 create table t1(id serial primary key, t text);
      47         [ -  + ]:           2 :     exec sql at test2 create table t1(id serial primary key, t text);
      48         [ -  + ]:           2 : 
      49                 :           2 :     strcpy(msg, "insert");
      50                 :           2 :     exec sql at test1 insert into t1(id, t) values (default, 'a');
      51         [ -  + ]:           2 :     exec sql at test1 insert into t1(id, t) values (default, 'b');
      52         [ -  + ]:           2 :     exec sql at test1 insert into t1(id, t) values (default, 'c');
      53         [ -  + ]:           2 :     exec sql at test1 insert into t1(id, t) values (default, 'd');
      54         [ -  + ]:           2 :     exec sql at test2 insert into t1(id, t) values (default, 'e');
      55         [ -  + ]:           2 : 
      56                 :           2 :     strcpy(msg, "commit");
      57                 :           2 :     exec sql at test1 commit;
      58         [ -  + ]:           2 :     exec sql at test2 commit;
      59         [ -  + ]:           2 : 
      60                 :             :     /* Dynamic cursorname test with INTO list in FETCH stmts */
      61                 :             : 
      62                 :           2 :     strcpy(msg, "declare");
      63                 :           2 :     exec sql at test1 declare :curname1 cursor for
      64                 :             :         select id, t from t1;
      65         [ -  + ]:           2 : 
      66                 :           2 :     strcpy(msg, "open");
      67                 :           2 :     exec sql at test1 open :curname1;
      68         [ -  + ]:           2 : 
      69                 :           2 :     strcpy(msg, "fetch from");
      70                 :           2 :     exec sql at test1 fetch forward from :curname1 into :id, :t;
      71         [ -  + ]:           2 :     printf("%d %s\n", id, t);
      72                 :             : 
      73                 :           2 :     strcpy(msg, "fetch");
      74                 :           2 :     exec sql at test1 fetch forward :curname1 into :id, :t;
      75         [ -  + ]:           2 :     printf("%d %s\n", id, t);
      76                 :             : 
      77                 :           2 :     strcpy(msg, "fetch 1 from");
      78                 :           2 :     exec sql at test1 fetch 1 from :curname1 into :id, :t;
      79         [ -  + ]:           2 :     printf("%d %s\n", id, t);
      80                 :             : 
      81                 :           2 :     strcpy(msg, "fetch :count from");
      82                 :           2 :     count = 1;
      83                 :           2 :     exec sql at test1 fetch :count from :curname1 into :id, :t;
      84         [ -  + ]:           2 :     printf("%d %s\n", id, t);
      85                 :             : 
      86                 :           2 :     strcpy(msg, "move in");
      87                 :           2 :     exec sql at test1 move absolute 0 in :curname1;
      88         [ -  + ]:           2 : 
      89                 :           2 :     strcpy(msg, "fetch 1");
      90                 :           2 :     exec sql at test1 fetch 1 :curname1 into :id, :t;
      91         [ -  + ]:           2 :     printf("%d %s\n", id, t);
      92                 :             : 
      93                 :           2 :     strcpy(msg, "fetch :count");
      94                 :           2 :     count = 1;
      95                 :           2 :     exec sql at test1 fetch :count :curname1 into :id, :t;
      96         [ -  + ]:           2 :     printf("%d %s\n", id, t);
      97                 :             : 
      98                 :           2 :     strcpy(msg, "close");
      99                 :           2 :     exec sql at test1 close :curname1;
     100         [ -  + ]:           2 : 
     101                 :             :     /* Dynamic cursorname test with INTO list in DECLARE stmt */
     102                 :             : 
     103                 :           2 :     strcpy(msg, "declare");
     104                 :           2 :     exec sql at test1 declare :curname2 cursor for
     105                 :           2 :         select id, t into :id, :t from t1;
     106         [ -  + ]:           2 : 
     107                 :           2 :     strcpy(msg, "open");
     108                 :           2 :     exec sql at test1 open :curname2;
     109         [ -  + ]:           2 : 
     110                 :           2 :     strcpy(msg, "fetch from");
     111                 :           2 :     exec sql at test1 fetch from :curname2;
     112         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     113                 :             : 
     114                 :           2 :     strcpy(msg, "fetch");
     115                 :           2 :     exec sql at test1 fetch :curname2;
     116         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     117                 :             : 
     118                 :           2 :     strcpy(msg, "fetch 1 from");
     119                 :           2 :     exec sql at test1 fetch 1 from :curname2;
     120         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     121                 :             : 
     122                 :           2 :     strcpy(msg, "fetch :count from");
     123                 :           2 :     count = 1;
     124                 :           2 :     exec sql at test1 fetch :count from :curname2;
     125         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     126                 :             : 
     127                 :           2 :     strcpy(msg, "move");
     128                 :           2 :     exec sql at test1 move absolute 0 :curname2;
     129         [ -  + ]:           2 : 
     130                 :           2 :     strcpy(msg, "fetch 1");
     131                 :           2 :     exec sql at test1 fetch 1 :curname2;
     132         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     133                 :             : 
     134                 :           2 :     strcpy(msg, "fetch :count");
     135                 :           2 :     count = 1;
     136                 :           2 :     exec sql at test1 fetch :count :curname2;
     137         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     138                 :             : 
     139                 :           2 :     strcpy(msg, "close");
     140                 :           2 :     exec sql at test1 close :curname2;
     141         [ -  + ]:           2 : 
     142                 :             :     /* Dynamic cursorname test with PREPARED stmt */
     143                 :             : 
     144                 :           2 :     strcpy(msg, "prepare");
     145                 :           2 :     exec sql at test1 prepare st_id1 from :stmt1;
     146         [ -  + ]:           2 :     exec sql at test2 prepare st_id1 from :stmt1;
     147         [ -  + ]:           2 : 
     148                 :           2 :     strcpy(msg, "declare");
     149                 :           2 :     exec sql at test1 declare :curname3 cursor for st_id1;
     150         [ -  + ]:           2 :     exec sql at test2 declare :curname5 cursor for st_id1;
     151         [ -  + ]:           2 : 
     152                 :           2 :     strcpy(msg, "open");
     153                 :           2 :     exec sql at test1 open :curname3;
     154         [ -  + ]:           2 :     exec sql at test2 open :curname5;
     155         [ -  + ]:           2 : 
     156                 :           2 :     strcpy(msg, "fetch");
     157                 :           2 :     exec sql at test2 fetch :curname5 into :id, :t;
     158         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     159                 :             : 
     160                 :           2 :     strcpy(msg, "fetch from");
     161                 :           2 :     exec sql at test1 fetch from :curname3 into :id, :t;
     162         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     163                 :             : 
     164                 :           2 :     strcpy(msg, "fetch 1 from");
     165                 :           2 :     exec sql at test1 fetch 1 from :curname3 into :id, :t;
     166         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     167                 :             : 
     168                 :           2 :     strcpy(msg, "fetch :count from");
     169                 :           2 :     count = 1;
     170                 :           2 :     exec sql at test1 fetch :count from :curname3 into :id, :t;
     171         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     172                 :             : 
     173                 :           2 :     strcpy(msg, "move");
     174                 :           2 :     exec sql at test1 move absolute 0 :curname3;
     175         [ -  + ]:           2 : 
     176                 :           2 :     strcpy(msg, "fetch 1");
     177                 :           2 :     exec sql at test1 fetch 1 :curname3 into :id, :t;
     178         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     179                 :             : 
     180                 :           2 :     strcpy(msg, "fetch :count");
     181                 :           2 :     count = 1;
     182                 :           2 :     exec sql at test1 fetch :count :curname3 into :id, :t;
     183         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     184                 :             : 
     185                 :           2 :     strcpy(msg, "close");
     186                 :           2 :     exec sql at test1 close :curname3;
     187         [ -  + ]:           2 :     exec sql at test2 close :curname5;
     188         [ -  + ]:           2 : 
     189                 :           2 :     strcpy(msg, "deallocate prepare");
     190                 :           2 :     exec sql at test1 deallocate prepare st_id1;
     191         [ -  + ]:           2 :     exec sql at test2 deallocate prepare st_id1;
     192         [ -  + ]:           2 : 
     193                 :             :     /* Dynamic cursorname test with PREPARED stmt,
     194                 :             :        cursor name in varchar */
     195                 :             : 
     196                 :           2 :     curname4.len = strlen(CURNAME);
     197                 :           2 :     strcpy(curname4.arr, CURNAME);
     198                 :             : 
     199                 :           2 :     strcpy(msg, "prepare");
     200                 :           2 :     exec sql at test1 prepare st_id2 from :stmt1;
     201         [ -  + ]:           2 : 
     202                 :           2 :     strcpy(msg, "declare");
     203                 :           2 :     exec sql at test1 declare :curname4 cursor for st_id2;
     204         [ -  + ]:           2 : 
     205                 :           2 :     strcpy(msg, "open");
     206                 :           2 :     exec sql at test1 open :curname4;
     207         [ -  + ]:           2 : 
     208                 :           2 :     strcpy(msg, "fetch from");
     209                 :           2 :     exec sql at test1 fetch from :curname4 into :id, :t;
     210         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     211                 :             : 
     212                 :           2 :     strcpy(msg, "fetch");
     213                 :           2 :     exec sql at test1 fetch :curname4 into :id, :t;
     214         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     215                 :             : 
     216                 :           2 :     strcpy(msg, "fetch 1 from");
     217                 :           2 :     exec sql at test1 fetch 1 from :curname4 into :id, :t;
     218         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     219                 :             : 
     220                 :           2 :     strcpy(msg, "fetch :count from");
     221                 :           2 :     count = 1;
     222                 :           2 :     exec sql at test1 fetch :count from :curname4 into :id, :t;
     223         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     224                 :             : 
     225                 :           2 :     strcpy(msg, "move");
     226                 :           2 :     exec sql at test1 move absolute 0 :curname4;
     227         [ -  + ]:           2 : 
     228                 :           2 :     strcpy(msg, "fetch 1");
     229                 :           2 :     exec sql at test1 fetch 1 :curname4 into :id, :t;
     230         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     231                 :             : 
     232                 :           2 :     strcpy(msg, "fetch :count");
     233                 :           2 :     count = 1;
     234                 :           2 :     exec sql at test1 fetch :count :curname4 into :id, :t;
     235         [ -  + ]:           2 :     printf("%d %s\n", id, t);
     236                 :             : 
     237                 :           2 :     strcpy(msg, "close");
     238                 :           2 :     exec sql at test1 close :curname4;
     239         [ -  + ]:           2 : 
     240                 :           2 :     strcpy(msg, "deallocate prepare");
     241                 :           2 :     exec sql at test1 deallocate prepare st_id2;
     242         [ -  + ]:           2 : 
     243                 :             :     /* End test */
     244                 :             : 
     245                 :           2 :     strcpy(msg, "drop");
     246                 :           2 :     exec sql at test1 drop table t1;
     247         [ -  + ]:           2 :     exec sql at test2 drop table t1;
     248         [ -  + ]:           2 : 
     249                 :           2 :     strcpy(msg, "commit");
     250                 :           2 :     exec sql at test1 commit;
     251         [ -  + ]:           2 : 
     252                 :           2 :     strcpy(msg, "disconnect");
     253                 :           2 :     exec sql disconnect all;
     254         [ -  + ]:           2 : 
     255                 :           2 :     return 0;
     256                 :             : }
        

Generated by: LCOV version 2.0-1