LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/compat_oracle - char_array.pgc (source / functions) Coverage Total Hit
Test: Code coverage Lines: 0.0 % 58 0
Test Date: 2026-01-26 10:56:24 Functions: 0.0 % 2 0
Legend: Lines:     hit not hit

            Line data    Source code
       1              : #include <stdio.h>
       2              : #include <stdlib.h>
       3              : #include <string.h>
       4              : 
       5              : #include <pgtypes_numeric.h>
       6              : 
       7              : EXEC SQL INCLUDE sqlda.h;
       8              : 
       9              : EXEC SQL INCLUDE ../regression;
      10              : 
      11            0 : static void warn(void)
      12              : {
      13            0 :   fprintf(stderr, "Warning: At least one column was truncated\n");
      14            0 : }
      15              : 
      16              : /* Compatible handling of char array to retrieve varchar field to char array
      17              :    should be fixed-length, blank-padded, then null-terminated.
      18              :    Conforms to the ANSI Fixed Character type. */
      19              : 
      20            0 : int main() {
      21              : 
      22              :   EXEC SQL WHENEVER SQLWARNING do warn();
      23              :   EXEC SQL WHENEVER SQLERROR STOP;
      24              : 
      25            0 :   const char *ppppp = "XXXXX";
      26            0 :   int loopcount;
      27            0 :   sqlda_t *sqlda = NULL;
      28              : 
      29              :   EXEC SQL BEGIN DECLARE SECTION;
      30            0 :   char shortstr[5];
      31            0 :   char bigstr[11];
      32            0 :   short shstr_ind = 0;
      33            0 :   short bigstr_ind = 0;
      34              :   EXEC SQL END DECLARE SECTION;
      35              : 
      36            0 :   ECPGdebug(1, stderr);
      37            0 :   EXEC SQL CONNECT TO REGRESSDB1;
      38            0 : 
      39            0 :   EXEC SQL CREATE TABLE strdbase (strval varchar(10));
      40            0 :   EXEC SQL INSERT INTO strdbase values ('');
      41            0 :   EXEC SQL INSERT INTO strdbase values ('AB');
      42            0 :   EXEC SQL INSERT INTO strdbase values ('ABCD');
      43            0 :   EXEC SQL INSERT INTO strdbase values ('ABCDE');
      44            0 :   EXEC SQL INSERT INTO strdbase values ('ABCDEF');
      45            0 :   EXEC SQL INSERT INTO strdbase values ('ABCDEFGHIJ');
      46            0 : 
      47              :   EXEC SQL declare C cursor for select strval, strval from strdbase;
      48            0 :   EXEC SQL OPEN C;
      49            0 : 
      50              :   EXEC SQL WHENEVER NOT FOUND DO BREAK;
      51              : 
      52            0 :   printf("Full Str.  :  Short  Ind.\n");
      53            0 :   for (loopcount = 0; loopcount < 100; loopcount++) {
      54            0 :     strncpy(shortstr, ppppp, sizeof shortstr);
      55            0 :     memset(bigstr, 0, sizeof bigstr);
      56            0 :     EXEC SQL FETCH C into :bigstr :bigstr_ind, :shortstr :shstr_ind;
      57            0 :     printf("\"%s\": \"%s\"  %d\n", bigstr, shortstr, shstr_ind);
      58            0 :   }
      59            0 : 
      60            0 :   EXEC SQL CLOSE C;
      61            0 :   EXEC SQL DROP TABLE strdbase;
      62            0 :   EXEC SQL COMMIT WORK;
      63            0 : 
      64              :   /* SQLDA handling */
      65              :   EXEC SQL WHENEVER SQLWARNING SQLPRINT;
      66              :   EXEC SQL WHENEVER NOT FOUND STOP;
      67            0 :   EXEC SQL PREPARE stmt1 FROM "SELECT 123::numeric(3,0), 't'::varchar(2)";
      68            0 :   EXEC SQL DECLARE cur1 CURSOR FOR stmt1;
      69            0 :   EXEC SQL OPEN cur1;
      70            0 :   EXEC SQL FETCH NEXT FROM cur1 INTO DESCRIPTOR sqlda;
      71            0 : 
      72            0 :   printf("\n-----------------\ntype    : data\n");
      73            0 :   for (int i = 0 ; i < sqlda->sqld ; i++)
      74              :   {
      75            0 :           sqlvar_t v = sqlda->sqlvar[i];
      76            0 :           char *sqldata = v.sqldata;
      77              : 
      78            0 :           if (v.sqltype == ECPGt_numeric)
      79            0 :                   sqldata =
      80            0 :                           PGTYPESnumeric_to_asc((numeric*) sqlda->sqlvar[i].sqldata, -1);
      81              : 
      82            0 :           printf("%-8s: \"%s\"\n", v.sqlname.data, sqldata);
      83            0 :   }
      84              : 
      85            0 :   EXEC SQL CLOSE cur1;
      86            0 :   EXEC SQL COMMIT WORK;
      87            0 : 
      88            0 :   printf("\nGOOD-BYE!!\n\n");
      89              : 
      90            0 :   EXEC SQL DISCONNECT ALL;
      91            0 : 
      92            0 :   return 0;
      93            0 : }
        

Generated by: LCOV version 2.3.2-1