MCPcopy Create free account
hub / github.com/MariaDB/server / json_file

Function json_file

storage/connect/jsonudf.cpp:4550–4620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4548} // end of json_file_init
4549
4550char *json_file(UDF_INIT *initid, UDF_ARGS *args, char *result,
4551 unsigned long *res_length, uchar *is_null, uchar *error)
4552{
4553 char *str, *fn;
4554 PGLOBAL g = (PGLOBAL)initid->ptr;
4555
4556 if (g->N) {
4557 str = (char*)g->Xchk;
4558 goto fin;
4559 } else if (initid->const_item)
4560 g->N = 1;
4561
4562 PlugSubSet(g->Sarea, g->Sarea_Size);
4563 fn = MakePSZ(g, args, 0);
4564
4565 if (args->arg_count > 1) {
4566 int pretty = 3, pty = 3;
4567 size_t len;
4568 PJSON jsp;
4569 PJVAL jvp = NULL;
4570
4571 for (unsigned int i = 1; i < args->arg_count; i++)
4572 if (args->arg_type[i] == INT_RESULT && *(longlong*)args->args[i] < 4) {
4573 pretty = (int) * (longlong*)args->args[i];
4574 break;
4575 } // endif type
4576
4577 /*******************************************************************************/
4578 /* Parse the json file and allocate its tree structure. */
4579 /*******************************************************************************/
4580 if (!(jsp = ParseJsonFile(g, fn, &pty, len))) {
4581 PUSH_WARNING(g->Message);
4582 str = NULL;
4583 goto fin;
4584 } // endif jsp
4585
4586 if (pty == 3)
4587 PUSH_WARNING("File pretty format cannot be determined");
4588 else if (pretty != 3 && pty != pretty)
4589 PUSH_WARNING("File pretty format doesn't match the specified pretty value");
4590 else if (pretty == 3)
4591 pretty = pty;
4592
4593 // Check whether a path was specified
4594 if (CheckPath(g, args, jsp, jvp, 1)) {
4595 PUSH_WARNING(g->Message);
4596 str = NULL;
4597 goto fin;
4598 } else if (jvp)
4599 jsp = jvp->GetJson();
4600
4601 if (!(str = Serialize(g, jsp, NULL, 0)))
4602 PUSH_WARNING(g->Message);
4603
4604 } else
4605 if (!(str = GetJsonFile(g, fn)))
4606 PUSH_WARNING(g->Message);
4607

Callers

nothing calls this directly

Calls 7

PlugSubSetFunction · 0.85
MakePSZFunction · 0.85
ParseJsonFileFunction · 0.85
CheckPathFunction · 0.85
SerializeFunction · 0.85
GetJsonFileFunction · 0.85
GetJsonMethod · 0.45

Tested by

no test coverage detected