LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/preproc - cursor.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 188 188 100.0 %
Date: 2024-12-02 19:14:57 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14