LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/sql - bytea.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 56 56 100.0 %
Date: 2019-11-13 21:06:57 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdlib.h>
       2             : #include <string.h>
       3             : #include <stdio.h>
       4             : #include <time.h>
       5             : 
       6             : exec sql include ../regression;
       7             : exec sql whenever sqlerror sqlprint;
       8             : 
       9             : static void
      10          32 : dump_binary(char *buf, int len, int ind)
      11             : {
      12             :     int i;
      13             : 
      14          32 :     printf("len=%d, ind=%d, data=0x", len, ind);
      15       16260 :     for (i = 0; i < len; ++i)
      16       16228 :         printf("%02x", 0xff & buf[i]);
      17          32 :     printf("\n");
      18          32 : }
      19             : 
      20             : #define DATA_SIZE 0x200
      21             : #define LACK_SIZE 13
      22             : #
      23             : int
      24           4 : main(void)
      25             : {
      26             : exec sql begin declare section;
      27             :     bytea send_buf[2][DATA_SIZE];
      28             :     bytea recv_buf[2][DATA_SIZE];
      29             :     bytea recv_vlen_buf[][DATA_SIZE];
      30             :     bytea recv_short_buf[DATA_SIZE - LACK_SIZE];
      31             :     int ind[2];
      32             : exec sql end declare section;
      33             :     int i, j, c;
      34             : 
      35             : #define init() { \
      36             :     for (i = 0; i < 2; ++i) \
      37             :     { \
      38             :         memset(recv_buf[i].arr, 0x0, sizeof(recv_buf[i].arr)); \
      39             :         recv_buf[i].len = 0; \
      40             :         ind[i] = 0; \
      41             :     } \
      42             :     recv_vlen_buf = NULL, \
      43             :     memset(recv_short_buf.arr, 0x0, sizeof(recv_short_buf.arr)); \
      44             : } \
      45             : while (0)
      46             : 
      47           4 :     ECPGdebug(1, stderr);
      48             : 
      49          12 :     for (i = 0; i < 2; ++i)
      50             :     {
      51        4104 :         for (j = 0, c = 0xff; (c == -1 ? c = 0xff : 1), j < DATA_SIZE; ++j, --c)
      52        4096 :             send_buf[i].arr[j] = c;
      53             : 
      54           8 :         send_buf[i].len = DATA_SIZE;
      55             :     }
      56             : 
      57           4 :     exec sql connect to REGRESSDB1;
      58           4 : 
      59           4 :     exec sql create table if not exists test (data1 bytea, data2 bytea);
      60           4 : 
      61           4 :     exec sql prepare ins_stmt from "insert into test values(?,?)";
      62           4 :     exec sql prepare sel_stmt from "select data1,data2 from test";
      63           4 :     exec sql allocate descriptor idesc;
      64           4 :     exec sql allocate descriptor odesc;
      65           4 : 
      66             :     /* Test for static sql statement with normal host variable, indicator */
      67           4 :     init();
      68           4 :     exec sql truncate test;
      69           4 :     exec sql insert into test values(:send_buf[0], :send_buf[1]);
      70           4 :     exec sql select data1,data2 into :recv_buf[0]:ind[0], :recv_short_buf:ind[1] from test;
      71           4 :     dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
      72           4 :     dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
      73             : 
      74             :     /* Test for variable length array */
      75           4 :     init();
      76           4 :     exec sql truncate test;
      77           4 :     exec sql insert into test values(:send_buf[0], :send_buf[1]);
      78           4 :     exec sql insert into test values(:send_buf[0], :send_buf[1]);
      79           4 :     exec sql select data1 into :recv_vlen_buf from test;
      80           4 :     dump_binary(recv_vlen_buf[0].arr, recv_vlen_buf[0].len, 0);
      81           4 :     dump_binary(recv_vlen_buf[1].arr, recv_vlen_buf[1].len, 0);
      82           4 :     free(recv_vlen_buf);
      83             : 
      84             :     /* Test for dynamic sql statement with normal host variable, indicator */
      85           4 :     init();
      86           4 :     exec sql truncate test;
      87           4 :     exec sql execute ins_stmt using :send_buf[0], :send_buf[1];
      88           4 :     exec sql execute sel_stmt into  :recv_buf[0]:ind[0], :recv_short_buf:ind[1];
      89           4 :     dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
      90           4 :     dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
      91             : 
      92             :     /* Test for dynamic sql statement with sql descriptor */
      93           4 :     init();
      94           4 :     exec sql truncate test;
      95           4 :     exec sql set descriptor idesc value 1 data = :send_buf[0];
      96           4 :     exec sql set descriptor idesc value 2 data = :send_buf[1];
      97           4 :     exec sql execute ins_stmt using sql descriptor idesc;
      98           4 :     exec sql execute sel_stmt into  sql descriptor odesc;
      99           4 :     exec sql get descriptor odesc value 1 :recv_buf[0] = data, :ind[0] = indicator;
     100           4 :     exec sql get descriptor odesc value 2 :recv_short_buf = data, :ind[1] = indicator;
     101           4 :     dump_binary(recv_buf[0].arr, recv_buf[0].len, ind[0]);
     102           4 :     dump_binary(recv_short_buf.arr, recv_short_buf.len, ind[1]);
     103             : 
     104           4 :     exec sql drop table test;
     105           4 :     exec sql commit;
     106           4 :     exec sql disconnect;
     107           4 : 
     108           4 :     return 0;
     109             : }

Generated by: LCOV version 1.13