LCOV - differential code coverage report
Current view: top level - src/interfaces/ecpg/test/sql - sqlda.pgc (source / functions) Coverage Total Hit UIC GIC
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 96.1 % 152 146 6 146
Current Date: 2025-09-06 07:49:51 +0900 Functions: 100.0 % 2 2 2
Baseline: lcov-20250907-010129-baseline Branches: 57.5 % 73 42 31 42
Baseline Date: 2025-09-05 08:21:35 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 0.0 % 2 0 2
(360..) days: 97.3 % 150 146 4 146
Function coverage date bins:
(360..) days: 100.0 % 2 2 2
Branch coverage date bins:
(360..) days: 57.5 % 73 42 31 42

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

Generated by: LCOV version 2.4-beta