LCOV - code coverage report
Current view: top level - monetdb5/modules/mal - json_util.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 31 6.5 %
Date: 2021-01-13 20:07:21 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /*
      10             :  * (c) Martin Kersten
      11             :  */
      12             : 
      13             : #include "monetdb_config.h"
      14             : #include "gdk.h"
      15             : #include "mal_exception.h"
      16             : 
      17             : typedef str json;
      18             : 
      19             : static str
      20           0 : JSONresultSet(json *res, bat *uuid, bat *rev, bat *js)
      21             : {
      22             :         BAT *bu, *br, *bj;
      23             :         char *result;
      24             :         size_t sz, len=0;
      25             : 
      26           0 :         if ((bu = BATdescriptor(*uuid)) == NULL)
      27           0 :                 throw(MAL, "json.resultset", INTERNAL_BAT_ACCESS);
      28           0 :         if ((br = BATdescriptor(*rev)) == NULL) {
      29           0 :                 BBPunfix(bu->batCacheid);
      30           0 :                 throw(MAL, "json.resultset", INTERNAL_BAT_ACCESS);
      31             :         }
      32           0 :         if ((bj = BATdescriptor(*js)) == NULL) {
      33           0 :                 BBPunfix(bu->batCacheid);
      34           0 :                 BBPunfix(br->batCacheid);
      35           0 :                 throw(MAL, "json.resultset", INTERNAL_BAT_ACCESS);
      36             :         }
      37           0 :         if ( !(BATcount(bu) == BATcount(br) && BATcount(br) == BATcount(bj)) ){
      38           0 :                 BBPunfix(bu->batCacheid);
      39           0 :                 BBPunfix(br->batCacheid);
      40           0 :                 BBPunfix(bj->batCacheid);
      41           0 :                 throw(MAL, "json.resultset", "Input not aligned");
      42             :         }
      43           0 :         sz= (22 + 12 + 20) * BATcount(bu);
      44           0 :         result = (char*) GDKmalloc(sz);
      45           0 :         if (result == NULL){
      46           0 :                 BBPunfix(bu->batCacheid);
      47           0 :                 BBPunfix(br->batCacheid);
      48           0 :                 BBPunfix(bj->batCacheid);
      49           0 :                 throw(MAL, "json.resultset", SQLSTATE(HY013) MAL_MALLOC_FAIL);
      50             :         }
      51           0 :         len += snprintf(result,sz,"[");
      52             :         /* here the dirty work follows */
      53             :         /* loop over the triple store */
      54           0 :         snprintf(result+len,sz-len,"]");
      55           0 :         BBPunfix(bu->batCacheid);
      56           0 :         BBPunfix(br->batCacheid);
      57           0 :         BBPunfix(bj->batCacheid);
      58           0 :         *res = result;
      59           0 :         return MAL_SUCCEED;
      60             : 
      61             : }
      62             : 
      63             : #include "mel.h"
      64             : mel_func json_util_init_funcs[] = {
      65             :  command("json", "resultSet", JSONresultSet, false, "Converts the json store into a single json string:", args(1,4, arg("",json),batarg("u",uuid),batarg("rev",lng),batarg("js",json))),
      66             :  { .imp=NULL }
      67             : };
      68             : #include "mal_import.h"
      69             : #ifdef _MSC_VER
      70             : #undef read
      71             : #pragma section(".CRT$XCU",read)
      72             : #endif
      73         255 : LIB_STARTUP_FUNC(init_json_util_mal)
      74         255 : { mal_module("json_util", NULL, json_util_init_funcs); }

Generated by: LCOV version 1.14