LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/compat_informix - sqlda.pgc (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 98.6 % 146 144
Test Date: 2026-07-25 22:15:46 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 57.7 % 71 41

             Branch data     Line data    Source code
       1                 :             : #include <stdlib.h>
       2                 :             : #include <string.h>
       3                 :             : #include <limits.h>
       4                 :             : 
       5                 :             : exec sql include ../regression;
       6                 :             : 
       7                 :             : exec sql include sqlda.h;
       8                 :             : exec sql include sqltypes.h;
       9                 :             : 
      10                 :             : exec sql whenever sqlerror stop;
      11                 :             : 
      12                 :             : /* These shouldn't be under DECLARE SECTION */
      13                 :             : sqlda_t *inp_sqlda, *outp_sqlda;
      14                 :             : 
      15                 :             : static void
      16                 :          16 : dump_sqlda(sqlda_t *sqlda)
      17                 :             : {
      18                 :             :     int i;
      19                 :             : 
      20         [ -  + ]:          16 :     if (sqlda == NULL)
      21                 :             :     {
      22                 :           0 :         printf("dump_sqlda called with NULL sqlda\n");
      23                 :           0 :         return;
      24                 :             :     }
      25                 :             : 
      26         [ +  + ]:          96 :     for (i = 0; i < sqlda->sqld; i++)
      27                 :             :     {
      28   [ +  -  +  + ]:          80 :         if (sqlda->sqlvar[i].sqlind && *(sqlda->sqlvar[i].sqlind) == -1)
      29                 :          16 :             printf("name sqlda descriptor: '%s' value NULL'\n", sqlda->sqlvar[i].sqlname);
      30                 :             :         else
      31   [ +  +  +  +  :          64 :         switch (sqlda->sqlvar[i].sqltype)
                      - ]
      32                 :             :         {
      33                 :          24 :         case SQLCHAR:
      34                 :          24 :             printf("name sqlda descriptor: '%s' value '%s'\n", sqlda->sqlvar[i].sqlname, sqlda->sqlvar[i].sqldata);
      35                 :          24 :             break;
      36                 :          16 :         case SQLINT:
      37                 :          16 :             printf("name sqlda descriptor: '%s' value %d\n", sqlda->sqlvar[i].sqlname, *(int *)sqlda->sqlvar[i].sqldata);
      38                 :          16 :             break;
      39                 :          12 :         case SQLFLOAT:
      40                 :          12 :             printf("name sqlda descriptor: '%s' value %f\n", sqlda->sqlvar[i].sqlname, *(double *)sqlda->sqlvar[i].sqldata);
      41                 :          12 :             break;
      42                 :          12 :         case SQLDECIMAL:
      43                 :             :             {
      44                 :             :                 char    val[64];
      45                 :          12 :                 dectoasc((dec_t *)sqlda->sqlvar[i].sqldata, val, 64, -1);
      46                 :          12 :                 printf("name sqlda descriptor: '%s' value DECIMAL '%s'\n", sqlda->sqlvar[i].sqlname, val);
      47                 :          12 :                 break;
      48                 :             :             }
      49                 :             :         }
      50                 :             :     }
      51                 :             : }
      52                 :             : 
      53                 :             : int
      54                 :           2 : main (void)
      55                 :             : {
      56                 :             : exec sql begin declare section;
      57                 :           2 :     char    *stmt1 = "SELECT * FROM t1";
      58                 :           2 :     char    *stmt2 = "SELECT * FROM t1 WHERE id = ?";
      59                 :             :     int rec;
      60                 :             :     int id;
      61                 :             : exec sql end declare section;
      62                 :             : 
      63                 :             :     char msg[128];
      64                 :             : 
      65                 :           2 :     ECPGdebug(1, stderr);
      66                 :             : 
      67                 :           2 :     strcpy(msg, "connect");
      68                 :           2 :     exec sql connect to REGRESSDB1 as regress1;
      69         [ -  + ]:           2 : 
      70                 :           2 :     strcpy(msg, "set");
      71                 :           2 :     exec sql set datestyle to iso;
      72         [ -  + ]:           2 : 
      73                 :           2 :     strcpy(msg, "create");
      74                 :           2 :     exec sql create table t1(
      75                 :             :         id integer,
      76                 :             :         t text,
      77                 :             :         d1 numeric,
      78                 :             :         d2 float8,
      79                 :             :         c char(10));
      80         [ -  + ]:           2 : 
      81                 :           2 :     strcpy(msg, "insert");
      82                 :           2 :     exec sql insert into t1 values
      83                 :             :         (1, 'a', 1.0, 1, 'a'),
      84                 :             :         (2, null, null, null, null),
      85                 :             :         (4, 'd', 4.0, 4, 'd');
      86         [ -  + ]:           2 : 
      87                 :           2 :     strcpy(msg, "commit");
      88                 :           2 :     exec sql commit;
      89         [ -  + ]:           2 : 
      90                 :             :     /* SQLDA test for getting all records from a table */
      91                 :             : 
      92                 :           2 :     outp_sqlda = NULL;
      93                 :             : 
      94                 :           2 :     strcpy(msg, "prepare");
      95                 :           2 :     exec sql prepare st_id1 from :stmt1;
      96         [ -  + ]:           2 : 
      97                 :           2 :     strcpy(msg, "declare");
      98                 :             :     exec sql declare mycur1 cursor for st_id1;
      99                 :             : 
     100                 :           2 :     strcpy(msg, "open");
     101                 :           2 :     exec sql open mycur1;
     102         [ -  + ]:           2 : 
     103                 :             :     exec sql whenever not found do break;
     104                 :             : 
     105                 :           2 :     rec = 0;
     106                 :             :     while (1)
     107                 :             :     {
     108                 :           8 :         strcpy(msg, "fetch");
     109                 :           8 :         exec sql fetch 1 from mycur1 into descriptor outp_sqlda;
     110   [ +  +  -  + ]:           8 : 
     111                 :           6 :         printf("FETCH RECORD %d\n", ++rec);
     112                 :           6 :         dump_sqlda(outp_sqlda);
     113                 :             :     }
     114                 :             : 
     115                 :             :     exec sql whenever not found continue;
     116                 :             : 
     117                 :           2 :     strcpy(msg, "close");
     118                 :           2 :     exec sql close mycur1;
     119         [ -  + ]:           2 : 
     120                 :           2 :     strcpy(msg, "deallocate");
     121                 :           2 :     exec sql deallocate prepare st_id1;
     122         [ -  + ]:           2 : 
     123                 :           2 :     free(outp_sqlda);
     124                 :             : 
     125                 :             :     /* SQLDA test for getting all records from a table
     126                 :             :        using the Informix-specific FETCH ... USING DESCRIPTOR
     127                 :             :      */
     128                 :             : 
     129                 :           2 :     outp_sqlda = NULL;
     130                 :             : 
     131                 :           2 :     strcpy(msg, "prepare");
     132                 :           2 :     exec sql prepare st_id2 from :stmt1;
     133         [ -  + ]:           2 : 
     134                 :           2 :     strcpy(msg, "declare");
     135                 :             :     exec sql declare mycur2 cursor for st_id2;
     136                 :             : 
     137                 :           2 :     strcpy(msg, "open");
     138                 :           2 :     exec sql open mycur2;
     139         [ -  + ]:           2 : 
     140                 :             :     exec sql whenever not found do break;
     141                 :             : 
     142                 :           2 :     rec = 0;
     143                 :             :     while (1)
     144                 :             :     {
     145                 :           8 :         strcpy(msg, "fetch");
     146                 :           8 :         exec sql fetch from mycur2 using descriptor outp_sqlda;
     147   [ +  +  -  + ]:           8 : 
     148                 :           6 :         printf("FETCH RECORD %d\n", ++rec);
     149                 :           6 :         dump_sqlda(outp_sqlda);
     150                 :             :     }
     151                 :             : 
     152                 :             :     exec sql whenever not found continue;
     153                 :             : 
     154                 :           2 :     strcpy(msg, "close");
     155                 :           2 :     exec sql close mycur2;
     156         [ -  + ]:           2 : 
     157                 :           2 :     strcpy(msg, "deallocate");
     158                 :           2 :     exec sql deallocate prepare st_id2;
     159         [ -  + ]:           2 : 
     160                 :           2 :     free(outp_sqlda);
     161                 :             : 
     162                 :             :     /* SQLDA test for getting one record using an input descriptor */
     163                 :             : 
     164                 :             :     /* Input sqlda has to be built manually */
     165                 :           2 :     inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
     166                 :           2 :     memset(inp_sqlda, 0, sizeof(sqlda_t));
     167                 :           2 :     inp_sqlda->sqld = 1;
     168                 :           2 :     inp_sqlda->sqlvar = malloc(sizeof(sqlvar_t));
     169                 :           2 :     memset(inp_sqlda->sqlvar, 0, sizeof(sqlvar_t));
     170                 :             : 
     171                 :           2 :     inp_sqlda->sqlvar[0].sqltype = SQLINT;
     172                 :           2 :     inp_sqlda->sqlvar[0].sqldata = (char *)&id;
     173                 :             : 
     174                 :           2 :     printf("EXECUTE RECORD 4\n");
     175                 :             : 
     176                 :           2 :     id = 4;
     177                 :             : 
     178                 :           2 :     outp_sqlda = NULL;
     179                 :             : 
     180                 :           2 :     strcpy(msg, "prepare");
     181                 :           2 :     exec sql prepare st_id3 FROM :stmt2;
     182         [ -  + ]:           2 : 
     183                 :           2 :     strcpy(msg, "execute");
     184                 :           2 :     exec sql execute st_id3 using descriptor inp_sqlda into descriptor outp_sqlda;
     185         [ -  + ]:           2 : 
     186                 :           2 :     dump_sqlda(outp_sqlda);
     187                 :             : 
     188                 :           2 :     strcpy(msg, "deallocate");
     189                 :           2 :     exec sql deallocate prepare st_id3;
     190         [ -  + ]:           2 : 
     191                 :           2 :     free(inp_sqlda->sqlvar);
     192                 :           2 :     free(inp_sqlda);
     193                 :           2 :     free(outp_sqlda);
     194                 :             : 
     195                 :             :     /* SQLDA test for getting one record using an input descriptor
     196                 :             :      * on a named connection
     197                 :             :      */
     198                 :             : 
     199                 :           2 :     exec sql connect to REGRESSDB1 as con2;
     200         [ -  + ]:           2 : 
     201                 :             :     /* Input sqlda has to be built manually */
     202                 :           2 :     inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
     203                 :           2 :     memset(inp_sqlda, 0, sizeof(sqlda_t));
     204                 :           2 :     inp_sqlda->sqld = 1;
     205                 :           2 :     inp_sqlda->sqlvar = malloc(sizeof(sqlvar_t));
     206                 :           2 :     memset(inp_sqlda->sqlvar, 0, sizeof(sqlvar_t));
     207                 :             : 
     208                 :           2 :     inp_sqlda->sqlvar[0].sqltype = SQLINT;
     209                 :           2 :     inp_sqlda->sqlvar[0].sqldata = (char *)&id;
     210                 :             : 
     211                 :           2 :     printf("EXECUTE RECORD 4\n");
     212                 :             : 
     213                 :           2 :     id = 4;
     214                 :             : 
     215                 :           2 :     outp_sqlda = NULL;
     216                 :             : 
     217                 :           2 :     strcpy(msg, "prepare");
     218                 :           2 :     exec sql at con2 prepare st_id4 FROM :stmt2;
     219         [ -  + ]:           2 : 
     220                 :           2 :     strcpy(msg, "execute");
     221                 :           2 :     exec sql at con2 execute st_id4 using descriptor inp_sqlda into descriptor outp_sqlda;
     222         [ -  + ]:           2 : 
     223                 :           2 :     dump_sqlda(outp_sqlda);
     224                 :             : 
     225                 :           2 :     strcpy(msg, "commit");
     226                 :           2 :     exec sql at con2 commit;
     227         [ -  + ]:           2 : 
     228                 :           2 :     strcpy(msg, "deallocate");
     229                 :           2 :     exec sql deallocate prepare st_id4;
     230         [ -  + ]:           2 : 
     231                 :           2 :     free(inp_sqlda->sqlvar);
     232                 :           2 :     free(inp_sqlda);
     233                 :           2 :     free(outp_sqlda);
     234                 :             : 
     235                 :           2 :     strcpy(msg, "disconnect");
     236                 :           2 :     exec sql disconnect con2;
     237         [ -  + ]:           2 : 
     238                 :             :     /* End test */
     239                 :             : 
     240                 :           2 :     strcpy(msg, "drop");
     241                 :           2 :     exec sql drop table t1;
     242         [ -  + ]:           2 : 
     243                 :           2 :     strcpy(msg, "commit");
     244                 :           2 :     exec sql commit;
     245         [ -  + ]:           2 : 
     246                 :           2 :     strcpy(msg, "disconnect");
     247                 :           2 :     exec sql disconnect;
     248         [ -  + ]:           2 : 
     249                 :           2 :     return 0;
     250                 :             : }
        

Generated by: LCOV version 2.0-1