LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/compat_oracle - char_array.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 35 35 100.0 %
Date: 2019-08-24 16:07:17 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdio.h>
       2             : #include <stdlib.h>
       3             : #include <string.h>
       4             : 
       5             : EXEC SQL INCLUDE ../regression;
       6             : 
       7          12 : static void warn(void)
       8             : {
       9          12 :   fprintf(stderr, "Warning: At least one column was truncated\n");
      10          12 : }
      11             : 
      12             : /* Compatible handling of char array to retrieve varchar field to char array
      13             :    should be fixed-length, blank-padded, then null-terminated.
      14             :    Conforms to the ANSI Fixed Character type. */
      15             : 
      16           4 : int main() {
      17             : 
      18             :   EXEC SQL WHENEVER SQLWARNING do warn();
      19             :   EXEC SQL WHENEVER SQLERROR STOP;
      20             : 
      21           4 :   const char *ppppp = "XXXXX";
      22             :   int loopcount;
      23             :   EXEC SQL BEGIN DECLARE SECTION;
      24             :   char shortstr[5];
      25             :   char bigstr[11];
      26           4 :   short shstr_ind = 0;
      27           4 :   short bigstr_ind = 0;
      28             :   EXEC SQL END DECLARE SECTION;
      29             : 
      30           4 :   ECPGdebug(1, stderr);
      31           4 :   EXEC SQL CONNECT TO REGRESSDB1;
      32           4 : 
      33           4 :   EXEC SQL CREATE TABLE strdbase (strval varchar(10));
      34           4 :   EXEC SQL INSERT INTO strdbase values ('');
      35           4 :   EXEC SQL INSERT INTO strdbase values ('AB');
      36           4 :   EXEC SQL INSERT INTO strdbase values ('ABCD');
      37           4 :   EXEC SQL INSERT INTO strdbase values ('ABCDE');
      38           4 :   EXEC SQL INSERT INTO strdbase values ('ABCDEF');
      39           4 :   EXEC SQL INSERT INTO strdbase values ('ABCDEFGHIJ');
      40           4 : 
      41             :   EXEC SQL declare C cursor for select strval, strval from strdbase;
      42           4 :   EXEC SQL OPEN C;
      43           4 : 
      44             :   EXEC SQL WHENEVER NOT FOUND DO BREAK;
      45             : 
      46           4 :   printf("Full Str.  :  Short  Ind.\n");
      47          28 :   for (loopcount = 0; loopcount < 100; loopcount++) {
      48          28 :     strncpy(shortstr, ppppp, sizeof shortstr);
      49          28 :     memset(bigstr, 0, sizeof bigstr);
      50          28 :     EXEC SQL FETCH C into :bigstr :bigstr_ind, :shortstr :shstr_ind;
      51          28 :     printf("\"%s\": \"%s\"  %d\n", bigstr, shortstr, shstr_ind);
      52             :   }
      53             : 
      54           4 :   EXEC SQL CLOSE C;
      55           4 :   EXEC SQL DROP TABLE strdbase;
      56           4 : 
      57           4 :   printf("\nGOOD-BYE!!\n\n");
      58             : 
      59           4 :   EXEC SQL COMMIT WORK;
      60           4 : 
      61           4 :   EXEC SQL DISCONNECT ALL;
      62           4 : 
      63           4 :   return 0;
      64             : }

Generated by: LCOV version 1.13