LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/sql - fetch.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 33 33 100.0 %
Date: 2024-12-03 08:15:25 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdio.h>
       2             : #include <stdlib.h>
       3             : #include <string.h>
       4             : 
       5             : EXEC SQL INCLUDE ../regression;
       6             : 
       7           4 : int main() {
       8             :   EXEC SQL BEGIN DECLARE SECTION;
       9             :     char str[25];
      10           4 :     int i, count=1, loopcount;
      11             :   EXEC SQL END DECLARE SECTION;
      12             : 
      13           4 :   ECPGdebug(1, stderr);
      14           4 :   EXEC SQL CONNECT TO REGRESSDB1;
      15             : 
      16             :   EXEC SQL WHENEVER SQLWARNING SQLPRINT;
      17             :   EXEC SQL WHENEVER SQLERROR STOP;
      18             : 
      19           4 :   EXEC SQL CREATE TABLE My_Table ( Item1 int, Item2 text );
      20           4 : 
      21           4 :   EXEC SQL INSERT INTO My_Table VALUES ( 1, 'text1');
      22           4 :   EXEC SQL INSERT INTO My_Table VALUES ( 2, 'text2');
      23           4 :   EXEC SQL INSERT INTO My_Table VALUES ( 3, 'text3');
      24           4 :   EXEC SQL INSERT INTO My_Table VALUES ( 4, 'text4');
      25           4 : 
      26             :   EXEC SQL DECLARE C CURSOR FOR SELECT * FROM My_Table;
      27             : 
      28           4 :   EXEC SQL OPEN C;
      29           4 : 
      30             :   EXEC SQL WHENEVER NOT FOUND DO BREAK;
      31          20 :   for (loopcount = 0; loopcount < 100; loopcount++) {
      32          20 :     EXEC SQL FETCH 1 IN C INTO :i, :str;
      33          20 :     printf("%d: %s\n", i, str);
      34             :   }
      35             : 
      36             :   EXEC SQL WHENEVER NOT FOUND CONTINUE;
      37           4 :   EXEC SQL MOVE BACKWARD 2 IN C;
      38           4 : 
      39           4 :   EXEC SQL FETCH :count IN C INTO :i, :str;
      40           4 :   printf("%d: %s\n", i, str);
      41             : 
      42           4 :   EXEC SQL CLOSE C;
      43           4 : 
      44             :   EXEC SQL DECLARE D CURSOR FOR SELECT * FROM My_Table WHERE Item1 = $1;
      45             : 
      46           4 :   EXEC SQL OPEN D using 1;
      47           4 : 
      48           4 :   EXEC SQL FETCH 1 IN D INTO :i, :str;
      49           4 :   printf("%d: %s\n", i, str);
      50             : 
      51           4 :   EXEC SQL CLOSE D;
      52           4 : 
      53           4 :   EXEC SQL DROP TABLE My_Table;
      54           4 : 
      55           4 :   EXEC SQL DISCONNECT ALL;
      56           4 : 
      57           4 :   return 0;
      58             : }

Generated by: LCOV version 1.14