LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/sql - sqljson.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 65 65 100.0 %
Date: 2024-02-28 06:10:54 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdio.h>
       2             : 
       3             : EXEC SQL INCLUDE sqlca;
       4             : exec sql include ../regression;
       5             : 
       6             : EXEC SQL WHENEVER SQLERROR sqlprint;
       7             : 
       8             : int
       9           4 : main ()
      10             : {
      11             : EXEC SQL BEGIN DECLARE SECTION;
      12             :   char json[1024];
      13             :   bool is_json[8];
      14             : EXEC SQL END DECLARE SECTION;
      15             : 
      16           4 :   ECPGdebug (1, stderr);
      17             : 
      18           4 :   EXEC SQL CONNECT TO REGRESSDB1;
      19           4 :   EXEC SQL SET AUTOCOMMIT = ON;
      20           4 : 
      21           4 :   EXEC SQL SELECT JSON_OBJECT(RETURNING text) INTO :json;
      22           4 :   printf("Found json=%s\n", json);
      23             : 
      24           4 :   EXEC SQL SELECT JSON_OBJECT(RETURNING text FORMAT JSON) INTO :json;
      25           4 :   printf("Found json=%s\n", json);
      26             : 
      27           4 :   EXEC SQL SELECT JSON_ARRAY(RETURNING jsonb) INTO :json;
      28           4 :   printf("Found json=%s\n", json);
      29             : 
      30           4 :   EXEC SQL SELECT JSON_ARRAY(RETURNING jsonb FORMAT JSON) INTO :json;
      31           4 :   printf("Found json=%s\n", json);
      32             : 
      33           4 :   EXEC SQL SELECT JSON_OBJECT(1: 1, '1': NULL WITH UNIQUE) INTO :json;
      34           4 :   // error
      35             : 
      36           4 :   EXEC SQL SELECT JSON_OBJECT(1: 1, '2': NULL, 1: '2' ABSENT ON NULL WITHOUT UNIQUE KEYS) INTO :json;
      37           4 :   printf("Found json=%s\n", json);
      38             : 
      39           4 :   EXEC SQL SELECT JSON_OBJECT(1: 1, '2': NULL ABSENT ON NULL WITHOUT UNIQUE RETURNING jsonb) INTO :json;
      40           4 :   printf("Found json=%s\n", json);
      41             : 
      42           4 :   EXEC SQL SELECT JSON(NULL) INTO :json;
      43           4 :   printf("Found json=%s\n", json);
      44             : 
      45           4 :   EXEC SQL SELECT JSON('{ "a" : 1 } ' FORMAT JSON) INTO :json;
      46           4 :   printf("Found json=%s\n", json);
      47             : 
      48           4 :   EXEC SQL SELECT JSON('{ "a" : 1 } ' FORMAT JSON ENCODING UTF8) INTO :json;
      49           4 :   // error
      50             : 
      51           4 :   EXEC SQL SELECT JSON('   1   '::jsonb) INTO :json;
      52           4 :   printf("Found json=%s\n", json);
      53             : 
      54           4 :   EXEC SQL SELECT JSON('   1   '::json WITH UNIQUE KEYS) INTO json;
      55           4 :   // error
      56             : 
      57           4 :   EXEC SQL SELECT JSON('{"a": 1, "a": 2}') INTO :json;
      58           4 :   printf("Found json=%s\n", json);
      59             : 
      60           4 :   EXEC SQL SELECT JSON('{"a": 1, "a": 2}' WITH UNIQUE KEYS) INTO :json;
      61           4 :   // error
      62             : 
      63           4 :   EXEC SQL SELECT JSON_SCALAR(NULL) INTO :json;
      64           4 :   printf("Found json=%s\n", json);
      65             : 
      66           4 :   EXEC SQL SELECT JSON_SCALAR(NULL::int) INTO :json;
      67           4 :   printf("Found json=%s\n", json);
      68             : 
      69           4 :   EXEC SQL SELECT JSON_SCALAR(123.45) INTO :json;
      70           4 :   printf("Found json=%s\n", json);
      71             : 
      72           4 :   EXEC SQL SELECT JSON_SCALAR(true) INTO :json;
      73           4 :   printf("Found json=%s\n", json);
      74             : 
      75           4 :   EXEC SQL SELECT JSON_SCALAR(' 123.45') INTO :json;
      76           4 :   printf("Found json=%s\n", json);
      77             : 
      78           4 :   EXEC SQL SELECT JSON_SCALAR('2020-06-07 01:02:03'::timestamp) INTO :json;
      79           4 :   printf("Found json=%s\n", json);
      80             : 
      81           4 :   EXEC SQL SELECT JSON_SCALAR('{}'::jsonb) INTO :json;
      82           4 :   printf("Found json=%s\n", json);
      83             : 
      84           4 :   EXEC SQL SELECT JSON_SERIALIZE(NULL) INTO :json;
      85           4 :   printf("Found json=%s\n", json);
      86             : 
      87           4 :   EXEC SQL SELECT JSON_SERIALIZE(JSON('{ "a" : 1 } ')) INTO :json;
      88           4 :   printf("Found json=%s\n", json);
      89             : 
      90           4 :   EXEC SQL SELECT JSON_SERIALIZE('{ "a" : 1 } ') INTO :json;
      91           4 :   printf("Found json=%s\n", json);
      92             : 
      93           4 :   EXEC SQL SELECT JSON_SERIALIZE('1' FORMAT JSON) INTO :json;
      94           4 :   printf("Found json=%s\n", json);
      95             : 
      96           4 :   EXEC SQL SELECT JSON_SERIALIZE('{ "a" : 1 } ' RETURNING varchar) INTO :json;
      97           4 :   printf("Found json=%s\n", json);
      98             : 
      99           4 :   EXEC SQL SELECT JSON_SERIALIZE('{ "a" : 1 } ' RETURNING jsonb);
     100           4 :   // error
     101             : 
     102           4 :   EXEC SQL WITH val (js) AS (VALUES ('{ "a": 1, "b": [{ "a": 1, "b": 0, "a": 2 }] }'))
     103             :       SELECT
     104             :       js IS JSON "IS JSON",
     105             :       js IS NOT JSON "IS NOT JSON",
     106             :       js IS JSON VALUE "IS VALUE",
     107             :       js IS JSON OBJECT "IS OBJECT",
     108             :       js IS JSON ARRAY "IS ARRAY",
     109             :       js IS JSON SCALAR "IS SCALAR",
     110             :       js IS JSON WITHOUT UNIQUE KEYS "WITHOUT UNIQUE",
     111             :       js IS JSON WITH UNIQUE KEYS "WITH UNIQUE"
     112             :           INTO :is_json[0], :is_json[1], :is_json[2], :is_json[3], :is_json[4],
     113             :           :is_json[5], :is_json[6], :is_json[7]
     114             :           FROM val;
     115          36 :       for (int i = 0; i < sizeof(is_json); i++)
     116          32 :           printf("Found is_json[%d]: %s\n", i, is_json[i] ? "true" : "false");
     117             : 
     118           4 :   EXEC SQL DISCONNECT;
     119           4 : 
     120           4 :   return 0;
     121             : }

Generated by: LCOV version 1.14