| 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 - 2019 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 | #include "json_util.h" |
| 17 | |
| 18 | str |
| 19 | JSONresultSet(json *res, bat *uuid, bat *rev, bat *js) |
| 20 | { |
| 21 | BAT *bu, *br, *bj; |
| 22 | char *result; |
| 23 | size_t sz, len=0; |
| 24 | |
| 25 | if ((bu = BATdescriptor(*uuid)) == NULL) |
| 26 | throw(MAL, "json.resultset" , INTERNAL_BAT_ACCESS); |
| 27 | if ((br = BATdescriptor(*rev)) == NULL) { |
| 28 | BBPunfix(bu->batCacheid); |
| 29 | throw(MAL, "json.resultset" , INTERNAL_BAT_ACCESS); |
| 30 | } |
| 31 | if ((bj = BATdescriptor(*js)) == NULL) { |
| 32 | BBPunfix(bu->batCacheid); |
| 33 | BBPunfix(br->batCacheid); |
| 34 | throw(MAL, "json.resultset" , INTERNAL_BAT_ACCESS); |
| 35 | } |
| 36 | if ( !(BATcount(bu) == BATcount(br) && BATcount(br) == BATcount(bj)) ){ |
| 37 | BBPunfix(bu->batCacheid); |
| 38 | BBPunfix(br->batCacheid); |
| 39 | BBPunfix(bj->batCacheid); |
| 40 | throw(MAL, "json.resultset" , "Input not aligned" ); |
| 41 | } |
| 42 | sz= (22 + 12 + 20) * BATcount(bu); |
| 43 | result = (char*) GDKmalloc(sz); |
| 44 | if (result == NULL){ |
| 45 | BBPunfix(bu->batCacheid); |
| 46 | BBPunfix(br->batCacheid); |
| 47 | BBPunfix(bj->batCacheid); |
| 48 | throw(MAL, "json.resultset" , SQLSTATE(HY001) MAL_MALLOC_FAIL); |
| 49 | } |
| 50 | len += snprintf(result,sz,"[" ); |
| 51 | /* here the dirty work follows */ |
| 52 | /* loop over the triple store */ |
| 53 | snprintf(result+len,sz-len,"]" ); |
| 54 | BBPunfix(bu->batCacheid); |
| 55 | BBPunfix(br->batCacheid); |
| 56 | BBPunfix(bj->batCacheid); |
| 57 | *res = result; |
| 58 | return MAL_SUCCEED; |
| 59 | |
| 60 | } |
| 61 | |