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

Function jbin_array_add

storage/connect/jsonudf.cpp:4890–4957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4888} // end of jbin_array_add_init
4889
4890char *jbin_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
4891 unsigned long *res_length, uchar *is_null, uchar *error)
4892{
4893 int n = 2;
4894 PJSON top = NULL;
4895 PGLOBAL g = (PGLOBAL)initid->ptr;
4896 PBSON bsp = (PBSON)g->Xchk;
4897
4898 if (bsp && !bsp->Changed) {
4899 // This constant function was recalled
4900 *res_length = sizeof(BSON);
4901 return (char*)bsp;
4902 } // endif bsp
4903
4904 if (!CheckMemory(g, initid, args, 2, false, false, true)) {
4905 int *x = NULL;
4906 uint n = 2;
4907// PJSON jsp;
4908 PJVAL jvp;
4909 PJAR arp;
4910
4911 jvp = MakeTypedValue(g, args, 0, TYPE_JSON, &top);
4912 // jsp = jvp->GetJson();
4913 x = GetIntArgPtr(g, args, n);
4914
4915 if (CheckPath(g, args, top, jvp, n))
4916 PUSH_WARNING(g->Message);
4917 else if (jvp) {
4918 PGLOBAL gb = GetMemPtr(g, args, 0);
4919
4920 if (jvp->GetValType() != TYPE_JAR) {
4921 if ((arp = (PJAR)JsonNew(gb, TYPE_JAR))) {
4922 arp->AddArrayValue(gb, (PJVAL)JvalNew(gb, TYPE_JVAL, jvp));
4923 jvp->SetValue(arp);
4924
4925 if (!top)
4926 top = arp;
4927
4928 } // endif arp
4929
4930 } else
4931 arp = jvp->GetArray();
4932
4933 arp->AddArrayValue(gb, MakeValue(gb, args, 1), x);
4934 arp->InitArray(gb);
4935 } else {
4936 PUSH_WARNING("First argument target is not an array");
4937// if (g->Mrr) *error = 1; (only if no path)
4938 } // endif jvp
4939
4940 } // endif CheckMemory
4941
4942 // In case of error unchanged argument will be returned
4943 bsp = MakeBinResult(g, args, top, initid->max_length, n);
4944
4945 if (initid->const_item)
4946 // Keep result of constant function
4947 g->Xchk = bsp;

Callers

nothing calls this directly

Calls 14

CheckMemoryFunction · 0.85
MakeTypedValueFunction · 0.85
CheckPathFunction · 0.85
GetMemPtrFunction · 0.85
JsonNewFunction · 0.85
JvalNewFunction · 0.85
MakeValueFunction · 0.85
MakeBinResultFunction · 0.85
GetValTypeMethod · 0.80
InitArrayMethod · 0.80
GetIntArgPtrFunction · 0.70
AddArrayValueMethod · 0.45

Tested by

no test coverage detected