LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/preproc - autoprep.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 43 43 100.0 %
Date: 2024-11-21 08:14:44 Functions: 2 2 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             : /* test automatic prepare for all statements */
       6             : EXEC SQL INCLUDE ../regression;
       7             : 
       8           8 : static void test(void) {
       9             :   EXEC SQL BEGIN DECLARE SECTION;
      10           8 :     int item[4], ind[4], i = 1;
      11             :     int item1, ind1;
      12           8 :     char sqlstr[64] = "SELECT item2 FROM T ORDER BY item2 NULLS LAST";
      13             :   EXEC SQL END DECLARE SECTION;
      14             : 
      15           8 :   ECPGdebug(1, stderr);
      16           8 :   EXEC SQL CONNECT TO REGRESSDB1;
      17             : 
      18             :   EXEC SQL WHENEVER SQLWARNING SQLPRINT;
      19             :   EXEC SQL WHENEVER SQLERROR SQLPRINT;
      20             : 
      21           8 :   EXEC SQL CREATE TABLE T ( Item1 int, Item2 int );
      22           8 : 
      23           8 :   EXEC SQL INSERT INTO T VALUES ( 1, null );
      24           8 :   EXEC SQL INSERT INTO T VALUES ( 1, :i );
      25           8 :   i++;
      26           8 :   EXEC SQL INSERT INTO T VALUES ( 1, :i );
      27           8 :   EXEC SQL PREPARE I AS INSERT INTO T VALUES ( 1, 2 );
      28           8 :   EXEC SQL EXECUTE I;
      29           8 : 
      30           8 :   EXEC SQL SELECT Item2 INTO :item:ind FROM T ORDER BY Item2 NULLS LAST;
      31           8 : 
      32          40 :   for (i=0; i<4; i++)
      33          32 :     printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]);
      34             : 
      35             :   EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T;
      36             : 
      37           8 :   EXEC SQL OPEN C;
      38           8 : 
      39           8 :   EXEC SQL FETCH 1 IN C INTO :i;
      40           8 :   printf("i = %d\n", i);
      41             : 
      42           8 :   EXEC SQL CLOSE C;
      43           8 : 
      44           8 :   EXEC SQL PREPARE stmt1 FROM :sqlstr;
      45           8 : 
      46             :   EXEC SQL DECLARE cur1 CURSOR FOR stmt1;
      47             : 
      48           8 :   EXEC SQL OPEN cur1;
      49           8 : 
      50             :   EXEC SQL WHENEVER NOT FOUND DO BREAK;
      51             : 
      52           8 :   i = 0;
      53          40 :   while (i < 100)
      54             :   {
      55          40 :     EXEC SQL FETCH cur1 INTO :item1:ind1;
      56          40 :     printf("item[%d] = %d\n", i, ind1 ? -1 : item1);
      57          32 :     i++;
      58             :   }
      59             : 
      60           8 :   EXEC SQL CLOSE cur1;
      61           8 : 
      62           8 :   EXEC SQL DROP TABLE T;
      63           8 : 
      64           8 :   EXEC SQL DISCONNECT ALL;
      65           8 : }
      66             : 
      67           4 : int main() {
      68           4 :   test();
      69           4 :   test();     /* retry */
      70             : 
      71           4 :   return 0;
      72             : }

Generated by: LCOV version 1.14