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

          Line data    Source code
       1             : #include <stdio.h>
       2             : #include <stdlib.h>
       3             : 
       4             : EXEC SQL include ../regression;
       5             : 
       6             : EXEC SQL BEGIN DECLARE SECTION;
       7             : struct TBempl
       8             : {
       9             :   long idnum;
      10             :   char name[21];
      11             :   short accs;
      12             :   char byte[20];
      13             : };
      14             : EXEC SQL END DECLARE SECTION;
      15             : 
      16             : EXEC SQL WHENEVER SQLERROR STOP;
      17             : 
      18             : int
      19           4 : main (void)
      20             : {
      21             :   EXEC SQL BEGIN DECLARE SECTION;
      22             :   struct TBempl empl;
      23           4 :   char *pointer = NULL;
      24           4 :   char *data = "\\001\\155\\000\\212";
      25             :   EXEC SQL END DECLARE SECTION;
      26             :   int i;
      27             : 
      28           4 :   ECPGdebug (1, stderr);
      29             : 
      30           4 :   empl.idnum = 1;
      31           4 :   EXEC SQL connect to REGRESSDB1;
      32           4 :   EXEC SQL set bytea_output = escape;
      33           4 :   EXEC SQL create table empl
      34             :     (idnum integer, name char (20), accs smallint, byte bytea);
      35           4 :   EXEC SQL insert into empl values (1, 'first user', 320, :data);
      36           4 :   EXEC SQL DECLARE C CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum;
      37           4 :   EXEC SQL OPEN C;
      38           4 :   EXEC SQL FETCH C INTO:empl.name,:empl.accs,:empl.byte;
      39           4 :   printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
      40             : 
      41           4 :   EXEC SQL CLOSE C;
      42           4 : 
      43           4 :   memset(empl.name, 0, 21L);
      44           4 :   EXEC SQL DECLARE B BINARY CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum;
      45           4 :   EXEC SQL OPEN B;
      46           4 :   EXEC SQL FETCH B INTO :empl.name,:empl.accs,:empl.byte;
      47           4 :   EXEC SQL CLOSE B;
      48           4 : 
      49             :   /* do not print a.accs because big/little endian will have different outputs here */
      50           4 :   printf ("name=%s, byte=", empl.name);
      51          20 :   for (i=0; i<4; i++)
      52          16 :     printf("(%o)", (unsigned char)empl.byte[i]);
      53           4 :   printf("\n");
      54             : 
      55           4 :   EXEC SQL DECLARE A BINARY CURSOR FOR select byte from empl where idnum =:empl.idnum;
      56           4 :   EXEC SQL OPEN A;
      57           4 :   EXEC SQL FETCH A INTO :pointer;
      58           4 :   EXEC SQL CLOSE A;
      59           4 : 
      60           4 :   if (pointer) {
      61           4 :     printf ("pointer=");
      62          20 :     for (i=0; i<4; i++)
      63          16 :         printf("(%o)", (unsigned char)pointer[i]);
      64           4 :     printf("\n");
      65           4 :     free(pointer);
      66             :   }
      67             : 
      68           4 :   EXEC SQL disconnect;
      69           4 :   exit (0);
      70             : }

Generated by: LCOV version 1.14