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

Function json_array_add

storage/connect/jsonudf.cpp:2264–2336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2262} // end of json_array_add_init
2263
2264char *json_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
2265 unsigned long *res_length, uchar *is_null, uchar *error)
2266{
2267 char *str = NULL;
2268 PGLOBAL g = (PGLOBAL)initid->ptr;
2269
2270 if (g->Xchk) {
2271 // This constant function was recalled
2272 str = (char*)g->Xchk;
2273 goto fin;
2274 } // endif Xchk
2275
2276 if (!CheckMemory(g, initid, args, 2, false, false, true)) {
2277 int *x;
2278 uint n = 2;
2279 PJSON jsp, top;
2280 PJVAL jvp;
2281 PJAR arp;
2282
2283 jvp = MakeTypedValue(g, args, 0, TYPE_JSON, &top);
2284 jsp = jvp->GetJson();
2285 x = GetIntArgPtr(g, args, n);
2286
2287 if (CheckPath(g, args, jsp, jvp, 2))
2288 PUSH_WARNING(g->Message);
2289 else if (jvp) {
2290 PGLOBAL gb = GetMemPtr(g, args, 0);
2291
2292 if (jvp->GetValType() != TYPE_JAR) {
2293 if ((arp = (PJAR)JsonNew(gb, TYPE_JAR))) {
2294 arp->AddArrayValue(gb, JvalNew(gb, TYPE_JVAL, jvp));
2295 jvp->SetValue(arp);
2296
2297 if (!top)
2298 top = arp;
2299
2300 } // endif arp
2301
2302 } else
2303 arp = jvp->GetArray();
2304
2305 if (arp) {
2306 arp->AddArrayValue(gb, MakeValue(gb, args, 1), x);
2307 arp->InitArray(gb);
2308 str = MakeResult(g, args, top, n);
2309 } else
2310 PUSH_WARNING(gb->Message);
2311
2312 } else {
2313 PUSH_WARNING("Target is not an array");
2314 // if (g->Mrr) *error = 1; (only if no path)
2315 } // endif jvp
2316
2317 } // endif CheckMemory
2318
2319 // In case of error or file, return unchanged argument
2320 if (!str)
2321 str = MakePSZ(g, args, 0);

Callers

nothing calls this directly

Calls 15

CheckMemoryFunction · 0.85
MakeTypedValueFunction · 0.85
CheckPathFunction · 0.85
GetMemPtrFunction · 0.85
JsonNewFunction · 0.85
JvalNewFunction · 0.85
MakeValueFunction · 0.85
MakeResultFunction · 0.85
MakePSZFunction · 0.85
GetValTypeMethod · 0.80
InitArrayMethod · 0.80
GetIntArgPtrFunction · 0.70

Tested by

no test coverage detected