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

Function json_get_item

storage/connect/jsonudf.cpp:3460–3518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3458} // end of json_get_item_init
3459
3460char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
3461 unsigned long *res_length, uchar *is_null, uchar *)
3462{
3463 char *path, *str = NULL;
3464 PJSON jsp;
3465 PJVAL jvp;
3466 PJSNX jsx;
3467 PGLOBAL g = (PGLOBAL)initid->ptr;
3468
3469 if (g->N) {
3470 str = (char*)g->Activityp;
3471 goto fin;
3472 } else if (initid->const_item)
3473 g->N = 1;
3474
3475 if (!g->Xchk) {
3476 if (CheckMemory(g, initid, args, 1, true, true)) {
3477 PUSH_WARNING("CheckMemory error");
3478 goto fin;
3479 } // endif CheckMemory
3480
3481 jvp = MakeTypedValue(g, args, 0, TYPE_JSON);
3482 jsp = jvp->GetJson();
3483
3484 if (g->Mrr) { // First argument is a constant
3485 g->Xchk = jsp;
3486 JsonMemSave(g);
3487 } // endif Mrr
3488
3489 } else
3490 jsp = (PJSON)g->Xchk;
3491
3492 path = MakePSZ(g, args, 1);
3493 jsx = JsnxNew(g, jsp, TYPE_STRING, initid->max_length);
3494
3495 if (!jsx || jsx->SetJpath(g, path, true)) {
3496 PUSH_WARNING(g->Message);
3497 *is_null = 1;
3498 return NULL;
3499 } // endif SetJpath
3500
3501 jsx->ReadValue(g);
3502
3503 if (!jsx->GetValue()->IsNull())
3504 str = jsx->GetValue()->GetCharValue();
3505
3506 if (initid->const_item)
3507 // Keep result of constant function
3508 g->Activityp = (PACTIVITY)str;
3509
3510 fin:
3511 if (!str) {
3512 *is_null = 1;
3513 *res_length = 0;
3514 } else
3515 *res_length = strlen(str);
3516
3517 return str;

Callers

nothing calls this directly

Calls 11

CheckMemoryFunction · 0.85
MakeTypedValueFunction · 0.85
MakePSZFunction · 0.85
JsnxNewFunction · 0.85
JsonMemSaveFunction · 0.70
GetJsonMethod · 0.45
SetJpathMethod · 0.45
ReadValueMethod · 0.45
IsNullMethod · 0.45
GetValueMethod · 0.45
GetCharValueMethod · 0.45

Tested by

no test coverage detected