LCOV - differential code coverage report
Current view: top level - src/interfaces/ecpg/test/sql - declare.pgc (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 100.0 % 108 108 108
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 5 5 5
Baseline: 16@8cea358b128 Branches: 54.2 % 96 52 44 52
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (240..) days: 100.0 % 108 108 108
Function coverage date bins:
(240..) days: 100.0 % 5 5 5
Branch coverage date bins:
(240..) days: 54.2 % 96 52 44 52

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : #include <locale.h>
                                  2                 :                : #include <string.h>
                                  3                 :                : #include <stdlib.h>
                                  4                 :                : 
                                  5                 :                : EXEC SQL WHENEVER SQLERROR SQLPRINT;
                                  6                 :                : 
                                  7                 :                : EXEC SQL INCLUDE sqlca;
                                  8                 :                : EXEC SQL INCLUDE ../regression;
                                  9                 :                : 
                                 10                 :                : #define ARRAY_SIZE 2
                                 11                 :                : 
                                 12                 :                : void execute_test(void);
                                 13                 :                : void commitTable(void);
                                 14                 :                : void reset(void);
                                 15                 :                : void printResult(char *tc_name, int loop);
                                 16                 :                : 
                                 17                 :                : EXEC SQL BEGIN DECLARE SECTION;
                                 18                 :                : int f1[ARRAY_SIZE];
                                 19                 :                : int f2[ARRAY_SIZE];
                                 20                 :                : char f3[ARRAY_SIZE][20];
                                 21                 :                : EXEC SQL END DECLARE SECTION;
                                 22                 :                : 
 1117 meskes@postgresql.or       23                 :CBC           1 : int main(void)
                                 24                 :                : {
                                 25                 :              1 :     setlocale(LC_ALL, "C");
                                 26                 :                : 
                                 27                 :              1 :     ECPGdebug(1, stderr);
                                 28                 :                : 
                                 29                 :              1 :     EXEC SQL CONNECT TO REGRESSDB1 AS con1;
                                 30         [ -  + ]:              1 :     EXEC SQL CONNECT TO REGRESSDB2 AS con2;
                                 31         [ -  + ]:              1 : 
                                 32                 :              1 :     EXEC SQL AT con1 CREATE TABLE source(f1 integer, f2 integer, f3 varchar(20));
                                 33         [ -  + ]:              1 :     EXEC SQL AT con2 CREATE TABLE source(f1 integer, f2 integer, f3 varchar(20));
                                 34         [ -  + ]:              1 : 
                                 35                 :              1 :     EXEC SQL AT con1 INSERT INTO source VALUES(1, 10, 'db on con1');
                                 36         [ -  + ]:              1 :     EXEC SQL AT con1 INSERT INTO source VALUES(2, 20, 'db on con1');
                                 37         [ -  + ]:              1 : 
                                 38                 :              1 :     EXEC SQL AT con2 INSERT INTO source VALUES(1, 10, 'db on con2');
                                 39         [ -  + ]:              1 :     EXEC SQL AT con2 INSERT INTO source VALUES(2, 20, 'db on con2');
                                 40         [ -  + ]:              1 : 
                                 41                 :              1 :     commitTable();
                                 42                 :                : 
                                 43                 :              1 :     execute_test();
                                 44                 :                : 
                                 45                 :              1 :     EXEC SQL AT con1 DROP TABLE IF EXISTS source;
                                 46         [ -  + ]:              1 :     EXEC SQL AT con2 DROP TABLE IF EXISTS source;
                                 47         [ -  + ]:              1 : 
                                 48                 :              1 :     commitTable();
                                 49                 :                : 
                                 50                 :              1 :     EXEC SQL DISCONNECT ALL;
                                 51         [ -  + ]:              1 : 
                                 52                 :              1 :     return 0;
                                 53                 :                : }
                                 54                 :                : 
                                 55                 :                : /*
                                 56                 :                :  * default connection: con2
                                 57                 :                :  * Non-default connection: con1
                                 58                 :                :  *
                                 59                 :                :  */
                                 60                 :              1 : void execute_test(void)
                                 61                 :                : {
                                 62                 :                :     EXEC SQL BEGIN DECLARE SECTION;
                                 63                 :                :     int i, count, length;
                                 64                 :              1 :     char *selectString = "SELECT f1,f2,f3 FROM source";
                                 65                 :                :     EXEC SQL END DECLARE SECTION;
                                 66                 :                : 
                                 67                 :                :     /*
                                 68                 :                :      * testcase1. using DECLARE STATEMENT without using AT clause,
                                 69                 :                :      * using PREPARE and CURSOR statement without using AT clause
                                 70                 :                :      */
                                 71                 :              1 :     reset();
                                 72                 :                : 
                                 73                 :                :     EXEC SQL DECLARE stmt_1 STATEMENT;
                                 74                 :              1 :     EXEC SQL PREPARE stmt_1 FROM :selectString;
                                 75         [ -  + ]:              1 :     EXEC SQL DECLARE cur_1 CURSOR FOR stmt_1;
                                 76                 :              1 :     EXEC SQL OPEN cur_1;
                                 77         [ -  + ]:              1 : 
                                 78                 :                :     EXEC SQL WHENEVER NOT FOUND DO BREAK;
                                 79                 :              1 :     i = 0;
                                 80                 :                :     while (1)
                                 81                 :                :     {
                                 82                 :              3 :         EXEC SQL FETCH cur_1 INTO :f1[i], :f2[i], :f3[i];
                                 83   [ +  +  -  + ]:              3 :         i++;
                                 84                 :                :     }
                                 85                 :              1 :     EXEC SQL CLOSE cur_1;
                                 86         [ -  + ]:              1 :     EXEC SQL DEALLOCATE PREPARE stmt_1;
                                 87         [ -  + ]:              4 :     EXEC SQL WHENEVER NOT FOUND CONTINUE;
                                 88                 :                : 
                                 89                 :              1 :     printResult("testcase1", 2);
                                 90                 :                : 
                                 91                 :                : 
                                 92                 :                :     /*
                                 93                 :                :      * testcase2. using DECLARE STATEMENT at con1,
                                 94                 :                :      * using PREPARE and CURSOR statement without using AT clause
                                 95                 :                :      */
                                 96                 :              1 :     reset();
                                 97                 :                : 
                                 98                 :                :     EXEC SQL AT con1 DECLARE stmt_2 STATEMENT;
                                 99                 :              1 :     EXEC SQL PREPARE stmt_2 FROM :selectString;
                                100         [ -  + ]:              1 :     EXEC SQL DECLARE cur_2 CURSOR FOR stmt_2;
                                101                 :              1 :     EXEC SQL OPEN cur_2;
                                102         [ -  + ]:              1 : 
                                103                 :                :     EXEC SQL WHENEVER NOT FOUND DO BREAK;
                                104                 :              1 :     i = 0;
                                105                 :                :     while (1)
                                106                 :                :     {
                                107                 :              3 :         EXEC SQL FETCH cur_2 INTO :f1[i], :f2[i], :f3[i];
                                108   [ +  +  -  + ]:              3 :         i++;
                                109                 :                :     }
                                110                 :              1 :     EXEC SQL CLOSE cur_2;
                                111         [ -  + ]:              1 :     EXEC SQL DEALLOCATE PREPARE stmt_2;
                                112         [ -  + ]:              4 :     EXEC SQL WHENEVER NOT FOUND CONTINUE;
                                113                 :                : 
                                114                 :              1 :     printResult("testcase2", 2);
                                115                 :                : 
                                116                 :                :     /*
                                117                 :                :      * testcase3. using DECLARE STATEMENT without using AT clause,
                                118                 :                :      * using PREPARE and EXECUTE statement without using AT clause
                                119                 :                :      */
                                120                 :              1 :     reset();
                                121                 :                : 
                                122                 :                :     EXEC SQL DECLARE stmt_3 STATEMENT;
  971                           123                 :              1 :     EXEC SQL PREPARE stmt_3 FROM :selectString;
                                124         [ -  + ]:              1 :     EXEC SQL EXECUTE stmt_3 INTO :f1, :f2, :f3;
 1117                           125         [ -  + ]:              1 : 
  971                           126                 :              1 :     EXEC SQL DEALLOCATE PREPARE stmt_3;
 1117                           127         [ -  + ]:              1 : 
                                128                 :              1 :     printResult("testcase3", 2);
                                129                 :                : 
                                130                 :                :     /*
                                131                 :                :      * testcase4. using DECLARE STATEMENT without using AT clause,
                                132                 :                :      * using PREPARE and CURSOR statement at con2
                                133                 :                :      */
                                134                 :              1 :     reset();
                                135                 :                : 
                                136                 :                :     EXEC SQL DECLARE stmt_4 STATEMENT;
                                137                 :              1 :     EXEC SQL AT con2 PREPARE stmt_4 FROM :selectString;
                                138         [ -  + ]:              1 :     EXEC SQL AT con2 DECLARE cur_4 CURSOR FOR stmt_4;
                                139                 :              1 :     EXEC SQL AT con2 OPEN cur_4;
                                140         [ -  + ]:              1 : 
                                141                 :                :     EXEC SQL WHENEVER NOT FOUND DO BREAK;
                                142                 :              1 :     i = 0;
                                143                 :                :     while (1)
                                144                 :                :     {
                                145                 :              3 :         EXEC SQL AT con2 FETCH cur_4 INTO :f1[i], :f2[i], :f3[i];
                                146   [ +  +  -  + ]:              3 :         i++;
                                147                 :                :     }
                                148                 :              1 :     EXEC SQL AT con2 CLOSE cur_4;
                                149         [ -  + ]:              1 :     EXEC SQL AT con2 DEALLOCATE PREPARE stmt_4;
                                150         [ -  + ]:              4 :     EXEC SQL WHENEVER NOT FOUND CONTINUE;
                                151                 :                : 
                                152                 :              1 :     printResult("testcase4", 2);
                                153                 :                : 
                                154                 :                :     /*
                                155                 :                :      * DESCRIBE statement is also supported.
                                156                 :                :      */
                                157                 :                :     EXEC SQL AT con1 DECLARE stmt_desc STATEMENT;
  975                           158                 :              1 :     EXEC SQL PREPARE stmt_desc FROM :selectString;
                                159         [ -  + ]:              1 :     EXEC SQL DECLARE cur_desc CURSOR FOR stmt_desc;
                                160                 :              1 :     EXEC SQL OPEN cur_desc;
                                161         [ -  + ]:              1 : 
                                162                 :                :     /* descriptor can be used for describe statement */
                                163                 :              1 :     EXEC SQL AT con1 ALLOCATE DESCRIPTOR desc_for_describe;
                                164         [ -  + ]:              1 :     EXEC SQL DESCRIBE stmt_desc INTO SQL DESCRIPTOR desc_for_describe;
                                165                 :                : 
                                166                 :              1 :     EXEC SQL AT con1 GET DESCRIPTOR desc_for_describe :count = COUNT;
                                167         [ -  + ]:              1 :     EXEC SQL AT con1 GET DESCRIPTOR desc_for_describe VALUE 3 :length = LENGTH;
                                168         [ -  + ]:              1 : 
                                169                 :              1 :     EXEC SQL AT con1 DEALLOCATE DESCRIPTOR desc_for_describe;
                                170         [ -  + ]:              1 : 
                                171                 :                :     /* for fetch statement */
                                172                 :              1 :     EXEC SQL AT con1 ALLOCATE DESCRIPTOR desc_for_fetch;
                                173         [ -  + ]:              1 :     EXEC SQL FETCH cur_desc INTO SQL DESCRIPTOR desc_for_fetch;
                                174         [ -  + ]:              1 : 
                                175                 :              1 :     EXEC SQL AT con1 GET DESCRIPTOR desc_for_fetch VALUE 3 :f3[0] = DATA;
                                176         [ -  + ]:              1 : 
                                177                 :              1 :     EXEC SQL AT con1 DEALLOCATE DESCRIPTOR desc_for_fetch;
                                178         [ -  + ]:              1 :     EXEC SQL CLOSE cur_desc;
                                179         [ -  + ]:              1 :     EXEC SQL DEALLOCATE stmt_desc;
                                180         [ -  + ]:              1 : 
                                181                 :              1 :     printf("****descriptor results****\n");
                                182                 :              1 :     printf("count: %d, length: %d, data: %s\n", count, length, f3[0]);
 1117                           183                 :              1 : }
                                184                 :                : 
                                185                 :              2 : void commitTable()
                                186                 :                : {
                                187                 :              2 :     EXEC SQL AT con1 COMMIT;
                                188         [ -  + ]:              2 :     EXEC SQL AT con2 COMMIT;
                                189         [ -  + ]:              2 : }
                                190                 :                : 
                                191                 :                : /*
                                192                 :                :  * reset all the output variables
                                193                 :                :  */
                                194                 :              4 : void reset()
                                195                 :                : {
                                196                 :              4 :     memset(f1, 0, sizeof(f1));
                                197                 :              4 :     memset(f2, 0, sizeof(f2));
                                198                 :              4 :     memset(f3, 0, sizeof(f3));
                                199                 :              4 : }
                                200                 :                : 
                                201                 :              4 : void printResult(char *tc_name, int loop)
                                202                 :                : {
                                203                 :                :     int i;
                                204                 :                : 
                                205         [ +  - ]:              4 :     if (tc_name)
                                206                 :              4 :         printf("****%s test results:****\n", tc_name);
                                207                 :                : 
                                208         [ +  + ]:             12 :     for (i = 0; i < loop; i++)
                                209                 :              8 :         printf("f1=%d, f2=%d, f3=%s\n", f1[i], f2[i], f3[i]);
                                210                 :                : 
                                211                 :              4 :     printf("\n");
                                212                 :              4 : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622