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 = BBPquickdesc(*uuid)) == NULL)
27 0 : throw(MAL, "json.resultset", INTERNAL_BAT_ACCESS);
28 0 : if ((br = BBPquickdesc(*rev)) == NULL)
29 0 : throw(MAL, "json.resultset", INTERNAL_BAT_ACCESS);
30 0 : if ((bj = BBPquickdesc(*js)) == NULL)
31 0 : throw(MAL, "json.resultset", INTERNAL_BAT_ACCESS);
32 0 : if ( !(BATcount(bu) == BATcount(br) && BATcount(br) == BATcount(bj)) )
33 0 : throw(MAL, "json.resultset", "Input not aligned");
34 0 : sz= (22 + 12 + 20) * BATcount(bu);
35 0 : result = (char*) GDKmalloc(sz);
36 0 : if (result == NULL)
37 0 : throw(MAL, "json.resultset", SQLSTATE(HY013) MAL_MALLOC_FAIL);
38 0 : len += snprintf(result,sz,"[");
39 : /* here the dirty work follows */
40 : /* loop over the triple store */
41 0 : snprintf(result+len,sz-len,"]");
42 0 : *res = result;
43 0 : return MAL_SUCCEED;
44 : }
45 :
46 : #include "mel.h"
47 : mel_func json_util_init_funcs[] = {
48 : 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))),
49 : { .imp=NULL }
50 : };
51 : #include "mal_import.h"
52 : #ifdef _MSC_VER
53 : #undef read
54 : #pragma section(".CRT$XCU",read)
55 : #endif
56 257 : LIB_STARTUP_FUNC(init_json_util_mal)
57 257 : { mal_module("json_util", NULL, json_util_init_funcs); }
|