From f590296c28ec54007692181e010d7064c1071ff2 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Tue, 18 Jul 2017 13:16:55 +0200 Subject: -- Finalize work on MongoDB access Implement discovery for the MongoDB Java Driver Create classes to minimize code and avoid dupicates Rearrange and rename implied files modified: storage/connect/CMakeLists.txt renamed: storage/connect/mongofam.cpp -> storage/connect/cmgfam.cpp renamed: storage/connect/mongofam.h -> storage/connect/cmgfam.h modified: storage/connect/cmgoconn.h modified: storage/connect/javaconn.h modified: storage/connect/jdbconn.cpp modified: storage/connect/jmgoconn.cpp modified: storage/connect/jmgoconn.h modified: storage/connect/mongo.cpp modified: storage/connect/mongo.h renamed: storage/connect/tabmgo.cpp -> storage/connect/tabcmg.cpp renamed: storage/connect/tabmgo.h -> storage/connect/tabcmg.h modified: storage/connect/tabjmg.cpp modified: storage/connect/tabjmg.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h -- Trace Sarea allocation and freeing modified: storage/connect/connect.cc modified: storage/connect/plugutil.cpp modified: storage/connect/user_connect.cc -- Null Json values where not mark as null in JSNX::SetJsonValue This was added in TYPE_NULL (declared as TYPE_VOID) modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/jsonudf.cpp -- Null JValues are ignored in JSNX::CalculateArray Also done in tabjson.cpp for JSONCOL::CalculateArray modified: storage/connect/json.h modified: storage/connect/jsonudf.cpp modified: storage/connect/tabjson.cpp -- Null JSON values now represented by connect_json_null session variable modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/jsonudf.cpp modified: storage/connect/tabjson.cpp -- JVALUE has size = 1 modified: storage/connect/json.h -- Fix by vuvova because Debian compilation failure. modified: storage/connect/value.cpp --- storage/connect/jsonudf.cpp | 270 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 241 insertions(+), 29 deletions(-) (limited to 'storage/connect/jsonudf.cpp') diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index 124e5bdc6ad..eb98510c702 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -1,5 +1,5 @@ /****************** jsonudf C++ Program Source Code File (.CPP) ******************/ -/* PROGRAM NAME: jsonudf Version 1.5 */ +/* PROGRAM NAME: jsonudf Version 1.6 */ /* (C) Copyright to the author Olivier BERTRAND 2015-2017 */ /* This program are the JSON User Defined Functions . */ /*********************************************************************************/ @@ -29,6 +29,7 @@ bool IsNum(PSZ s); char *NextChr(PSZ s, char sep); +char *GetJsonNull(void); uint GetJsonGrpSize(void); static int IsJson(UDF_ARGS *args, uint i); static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i); @@ -347,11 +348,13 @@ void JSNX::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n) SetJsonValue(g, vp, val->GetArray()->GetValue(0), n); break; case TYPE_JOB: - // if (!vp->IsTypeNum() || !Strict) { +// if (!vp->IsTypeNum() || !Strict) { vp->SetValue_psz(val->GetObject()->GetText(g, NULL)); break; - // } // endif Type +// } // endif Type + case TYPE_NULL: + vp->SetNull(true); default: vp->Reset(); } // endswitch Type @@ -488,15 +491,16 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) JVALUE jval; vp->Reset(); -//ars = MY_MIN(Tjp->Limit, arp->size()); ars = arp->size(); for (i = 0; i < ars; i++) { jvrp = arp->GetValue(i); -// do { - if (n < Nod - 1 && jvrp->GetJson()) { -// Tjp->NextSame = nextsame; + if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) { + if (jvrp->IsNull()) { + jvrp->Value = AllocateValue(g, GetJsonNull(), TYPE_STRING); + jvp = jvrp; + } else if (n < Nod - 1 && jvrp->GetJson()) { jval.SetValue(GetColumnValue(g, jvrp->GetJson(), n + 1)); jvp = &jval; } else @@ -510,25 +514,25 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) if (!MulVal->IsZero()) { switch (op) { - case OP_CNC: - if (Nodes[n].CncVal) { - val[0] = Nodes[n].CncVal; - err = vp->Compute(g, val, 1, op); - } // endif CncVal + case OP_CNC: + if (Nodes[n].CncVal) { + val[0] = Nodes[n].CncVal; + err = vp->Compute(g, val, 1, op); + } // endif CncVal - val[0] = MulVal; - err = vp->Compute(g, val, 1, op); - break; - // case OP_NUM: - case OP_SEP: - val[0] = Nodes[n].Valp; - val[1] = MulVal; - err = vp->Compute(g, val, 2, OP_ADD); - break; - default: - val[0] = Nodes[n].Valp; - val[1] = MulVal; - err = vp->Compute(g, val, 2, op); + val[0] = MulVal; + err = vp->Compute(g, val, 1, op); + break; +// case OP_NUM: + case OP_SEP: + val[0] = Nodes[n].Valp; + val[1] = MulVal; + err = vp->Compute(g, val, 2, OP_ADD); + break; + default: + val[0] = Nodes[n].Valp; + val[1] = MulVal; + err = vp->Compute(g, val, 2, op); } // endswitch Op if (err) @@ -536,7 +540,7 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) } // endif Zero -// } while (Tjp->NextSame > nextsame); + } // endif jvrp } // endfor i @@ -1100,6 +1104,7 @@ inline void JsonMemSave(PGLOBAL g) /*********************************************************************************/ inline void JsonFreeMem(PGLOBAL g) { + g->Activityp = NULL; PlugExit(g); } /* end of JsonFreeMem */ @@ -1111,7 +1116,7 @@ static my_bool JsonInit(UDF_INIT *initid, UDF_ARGS *args, unsigned long reslen, unsigned long memlen, unsigned long more = 0) { - PGLOBAL g = PlugInit(NULL, memlen + more); + PGLOBAL g = PlugInit(NULL, memlen + more + 500); // +500 to avoid CheckMem if (!g) { strcpy(message, "Allocation error"); @@ -1471,6 +1476,9 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n, ml += g->More; if (ml > g->Sarea_Size) { + if (trace) + htrc("Freeing Sarea size=%d\n", g->Sarea_Size); + free(g->Sarea); if (!(g->Sarea = PlugAllocMem(g, ml))) { @@ -1814,7 +1822,7 @@ char *json_make_array(UDF_INIT *initid, UDF_ARGS *args, char *result, return str; } // end of json_make_array -void json_array_deinit(UDF_INIT* initid) +void json_make_array_deinit(UDF_INIT* initid) { JsonFreeMem((PGLOBAL)initid->ptr); } // end of json_make_array_deinit @@ -2097,6 +2105,206 @@ void json_array_delete_deinit(UDF_INIT* initid) JsonFreeMem((PGLOBAL)initid->ptr); } // end of json_array_delete_deinit +/*********************************************************************************/ +/* Sum big integer values from a Json array. */ +/*********************************************************************************/ +my_bool jsonsum_int_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen, more; + + if (args->arg_count != 1) { + strcpy(message, "This function must have 1 argument"); + return true; + } else if (!IsJson(args, 0) && args->arg_type[0] != STRING_RESULT) { + strcpy(message, "First argument must be a json item"); + return true; + } else + CalcLen(args, false, reslen, memlen); + + // TODO: calculate this + more = (IsJson(args, 0) != 3) ? 1000 : 0; + + return JsonInit(initid, args, message, true, reslen, memlen, more); +} // end of jsonsum_int_init + +long long jsonsum_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) +{ + long long n = 0LL; + PGLOBAL g = (PGLOBAL)initid->ptr; + + if (g->N) { + if (!g->Activityp) { + *is_null = 1; + return 0LL; + } else + return *(long long*)g->Activityp; + + } else if (initid->const_item) + g->N = 1; + + if (!CheckMemory(g, initid, args, 1, false, false, true)) { + PJVAL jvp = MakeValue(g, args, 0); + + if (jvp && jvp->GetValType() == TYPE_JAR) { + PJAR arp = jvp->GetArray(); + + for (int i = 0; i < arp->size(); i++) + n += arp->GetValue(i)->GetBigint(); + + } else { + PUSH_WARNING("First argument target is not an array"); + } // endif jvp + + } else { + *error = 1; + n = -1LL; + } // end of CheckMemory + + if (g->N) { + // Keep result of constant function + long long *np = (long long*)PlugSubAlloc(g, NULL, sizeof(long long)); + *np = n; + g->Activityp = (PACTIVITY)np; + } // endif const_item + + return n; +} // end of jsonsum_int + +void jsonsum_int_deinit(UDF_INIT* initid) +{ + JsonFreeMem((PGLOBAL)initid->ptr); +} // end of jsonsum_int_deinit + +/*********************************************************************************/ +/* Sum big integer values from a Json array. */ +/*********************************************************************************/ +my_bool jsonsum_real_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen, more; + + if (args->arg_count != 1) { + strcpy(message, "This function must have 1 argument"); + return true; + } else if (!IsJson(args, 0) && args->arg_type[0] != STRING_RESULT) { + strcpy(message, "First argument must be a json item"); + return true; + } else + CalcLen(args, false, reslen, memlen); + + // TODO: calculate this + more = (IsJson(args, 0) != 3) ? 1000 : 0; + + return JsonInit(initid, args, message, true, reslen, memlen, more); +} // end of jsonsum_real_init + +double jsonsum_real(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) +{ + double n = 0.0; + PGLOBAL g = (PGLOBAL)initid->ptr; + + if (g->N) { + if (!g->Activityp) { + *is_null = 1; + return 0.0; + } else + return *(double*)g->Activityp; + + } else if (initid->const_item) + g->N = 1; + + if (!CheckMemory(g, initid, args, 1, false, false, true)) { + PJVAL jvp = MakeValue(g, args, 0); + + if (jvp && jvp->GetValType() == TYPE_JAR) { + PJAR arp = jvp->GetArray(); + + for (int i = 0; i < arp->size(); i++) + n += arp->GetValue(i)->GetFloat(); + + } else { + PUSH_WARNING("First argument target is not an array"); + } // endif jvp + + } else { + *error = 1; + n = -1.0; + } // end of CheckMemory + + if (g->N) { + // Keep result of constant function + double *np = (double*)PlugSubAlloc(g, NULL, sizeof(double)); + *np = n; + g->Activityp = (PACTIVITY)np; + } // endif const_item + + return n; +} // end of jsonsum_real + +void jsonsum_real_deinit(UDF_INIT* initid) +{ + JsonFreeMem((PGLOBAL)initid->ptr); +} // end of jsonsum_real_deinit + +/*********************************************************************************/ +/* Returns the average of big integer values from a Json array. */ +/*********************************************************************************/ +my_bool jsonavg_real_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + return jsonsum_real_init(initid, args, message); +} // end of jsonavg_real_init + +double jsonavg_real(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) +{ + double n = 0.0; + PGLOBAL g = (PGLOBAL)initid->ptr; + + if (g->N) { + if (!g->Activityp) { + *is_null = 1; + return 0.0; + } else + return *(double*)g->Activityp; + + } else if (initid->const_item) + g->N = 1; + + if (!CheckMemory(g, initid, args, 1, false, false, true)) { + PJVAL jvp = MakeValue(g, args, 0); + + if (jvp && jvp->GetValType() == TYPE_JAR) { + PJAR arp = jvp->GetArray(); + + if (arp->size()) { + for (int i = 0; i < arp->size(); i++) + n += arp->GetValue(i)->GetFloat(); + + n /= arp->size(); + } // endif size + + } else { + PUSH_WARNING("First argument target is not an array"); + } // endif jvp + + } else { + *error = 1; + n = -1.0; + } // end of CheckMemory + + if (g->N) { + // Keep result of constant function + double *np = (double*)PlugSubAlloc(g, NULL, sizeof(double)); + *np = n; + g->Activityp = (PACTIVITY)np; + } // endif const_item + + return n; +} // end of jsonavg_real + +void jsonavg_real_deinit(UDF_INIT* initid) +{ + JsonFreeMem((PGLOBAL)initid->ptr); +} // end of jsonavg_real_deinit + /*********************************************************************************/ /* Make a Json Object containing all the parameters. */ /*********************************************************************************/ @@ -2990,6 +3198,7 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, } catch (int n) { if (trace) htrc("Exception %d: %s\n", n, g->Message); + PUSH_WARNING(g->Message); str = NULL; } catch (const char *msg) { @@ -3039,7 +3248,7 @@ my_bool jsonget_int_init(UDF_INIT *initid, UDF_ARGS *args, char *message) } // end of jsonget_int_init long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args, - char *is_null, char *error) + char *is_null, char *error) { char *p, *path; long long n; @@ -3330,6 +3539,7 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, } catch (int n) { if (trace) htrc("Exception %d: %s\n", n, g->Message); + PUSH_WARNING(g->Message); *error = 1; path = NULL; @@ -3454,6 +3664,7 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, } catch (int n) { if (trace) htrc("Exception %d: %s\n", n, g->Message); + PUSH_WARNING(g->Message); *error = 1; path = NULL; @@ -3728,6 +3939,7 @@ char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, } catch (int n) { if (trace) htrc("Exception %d: %s\n", n, g->Message); + PUSH_WARNING(g->Message); str = NULL; } catch (const char *msg) { -- cgit v1.2.1 From e99af2a3fadc3a8d784e39ee724ffc66abb6f779 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Wed, 19 Jul 2017 23:30:40 +0200 Subject: -- Fix warnings from the new GCC 7 modified: storage/connect/ha_connect.cc -- Set NULL false in SetJsonValue modified: storage/connect/jsonudf.cpp modified: storage/connect/tabjson.cpp --- storage/connect/jsonudf.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'storage/connect/jsonudf.cpp') diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index eb98510c702..3f629ede4f7 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -328,6 +328,8 @@ PVAL JSNX::MakeJson(PGLOBAL g, PJSON jsp) void JSNX::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n) { if (val) { + vp->SetNull(false); + if (Jb) { vp->SetValue_psz(Serialize(g, val->GetJsp(), NULL, 0)); } else switch (val->GetValType()) { -- cgit v1.2.1 From 8476d3052ab903f0a33ff8fbae87f6892d88c59f Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Fri, 21 Jul 2017 15:24:13 +0200 Subject: -- Add mutex for user_connect handling modified: storage/connect/ha_connect.cc modified: storage/connect/user_connect.cc modified: storage/connect/plgdbutl.cpp modified: storage/connect/user_connect.cc -- Trace work storage allocation and freeing in DEVELOPMENT mode modified: storage/connect/ha_connect.cc modified: storage/connect/jsonudf.cpp modified: storage/connect/plugutil.cpp --- storage/connect/jsonudf.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'storage/connect/jsonudf.cpp') diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index 3f629ede4f7..566ad31510b 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -1478,8 +1478,10 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n, ml += g->More; if (ml > g->Sarea_Size) { +#if !defined(DEVELOPMENT) if (trace) - htrc("Freeing Sarea size=%d\n", g->Sarea_Size); +#endif + htrc("Freeing Sarea at %p size=%d\n", g->Sarea, g->Sarea_Size); free(g->Sarea); -- cgit v1.2.1 From 60c9485a8e5ebf410d9fa60caa7937f3fe3ca9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= Date: Tue, 1 Aug 2017 11:39:10 +0300 Subject: Merge connect/10.0 into 10.0 Squash all connect/10.0's commits into one and keep only changes from storage/connect directory. --- storage/connect/jsonudf.cpp | 61 ++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 28 deletions(-) (limited to 'storage/connect/jsonudf.cpp') diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index 4e00703d9ef..23c2b9785bc 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -1,5 +1,5 @@ /****************** jsonudf C++ Program Source Code File (.CPP) ******************/ -/* PROGRAM NAME: jsonudf Version 1.5 */ +/* PROGRAM NAME: jsonudf Version 1.6 */ /* (C) Copyright to the author Olivier BERTRAND 2015-2017 */ /* This program are the JSON User Defined Functions . */ /*********************************************************************************/ @@ -27,7 +27,8 @@ #endif #define M 7 -uint GetJsonGrpSize(void); +char *GetJsonNull(void); +uint GetJsonGrpSize(void); static int IsJson(UDF_ARGS *args, uint i); static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i); static char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, @@ -327,11 +328,13 @@ void JSNX::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n) SetJsonValue(g, vp, val->GetArray()->GetValue(0), n); break; case TYPE_JOB: - // if (!vp->IsTypeNum() || !Strict) { +// if (!vp->IsTypeNum() || !Strict) { vp->SetValue_psz(val->GetObject()->GetText(g, NULL)); break; - // } // endif Type +// } // endif Type + case TYPE_NULL: + vp->SetNull(true); default: vp->Reset(); } // endswitch Type @@ -459,7 +462,7 @@ PVAL JSNX::ExpandArray(PGLOBAL g, PJAR arp, int n) /*********************************************************************************/ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) { -//int i, ars, nv = 0, nextsame = Tjp->NextSame; + //int i, ars, nv = 0, nextsame = Tjp->NextSame; int i, ars, nv = 0, nextsame = 0; my_bool err; OPVAL op = Nodes[n].Op; @@ -468,15 +471,16 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) JVALUE jval; vp->Reset(); -//ars = MY_MIN(Tjp->Limit, arp->size()); ars = arp->size(); for (i = 0; i < ars; i++) { jvrp = arp->GetValue(i); -// do { - if (n < Nod - 1 && jvrp->GetJson()) { -// Tjp->NextSame = nextsame; + if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) { + if (jvrp->IsNull()) { + jvrp->Value = AllocateValue(g, GetJsonNull(), TYPE_STRING); + jvp = jvrp; + } else if (n < Nod - 1 && jvrp->GetJson()) { jval.SetValue(GetColumnValue(g, jvrp->GetJson(), n + 1)); jvp = &jval; } else @@ -490,25 +494,25 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) if (!MulVal->IsZero()) { switch (op) { - case OP_CNC: - if (Nodes[n].CncVal) { - val[0] = Nodes[n].CncVal; - err = vp->Compute(g, val, 1, op); - } // endif CncVal + case OP_CNC: + if (Nodes[n].CncVal) { + val[0] = Nodes[n].CncVal; + err = vp->Compute(g, val, 1, op); + } // endif CncVal - val[0] = MulVal; - err = vp->Compute(g, val, 1, op); - break; - // case OP_NUM: - case OP_SEP: - val[0] = Nodes[n].Valp; - val[1] = MulVal; - err = vp->Compute(g, val, 2, OP_ADD); - break; - default: - val[0] = Nodes[n].Valp; - val[1] = MulVal; - err = vp->Compute(g, val, 2, op); + val[0] = MulVal; + err = vp->Compute(g, val, 1, op); + break; + // case OP_NUM: + case OP_SEP: + val[0] = Nodes[n].Valp; + val[1] = MulVal; + err = vp->Compute(g, val, 2, OP_ADD); + break; + default: + val[0] = Nodes[n].Valp; + val[1] = MulVal; + err = vp->Compute(g, val, 2, op); } // endswitch Op if (err) @@ -516,7 +520,7 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) } // endif Zero -// } while (Tjp->NextSame > nextsame); + } // endif jvrp } // endfor i @@ -1081,6 +1085,7 @@ inline void JsonMemSave(PGLOBAL g) /*********************************************************************************/ inline void JsonFreeMem(PGLOBAL g) { + g->Activityp = NULL; PlugExit(g); } /* end of JsonFreeMem */ -- cgit v1.2.1 From cdf00b8d92f9f49b33c7cf3f4390cb3d810f9c33 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Mon, 7 Aug 2017 16:24:53 +0200 Subject: - Fix bug returning pointer to a stack string in JVALUE::GetString modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/jsonudf.cpp - Fix a compiler bug happening on some configuration and platforms in JSNX::CalculateArray modified: storage/connect/jsonudf.cpp - Set default Schema as current directory This fix several bugs like: Fail to make JSON catalog tables Fail to use zipped file made by a file LOAD modified: storage/connect/reldef.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h --- storage/connect/jsonudf.cpp | 66 ++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'storage/connect/jsonudf.cpp') diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index 566ad31510b..6acf18cd323 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -143,7 +143,7 @@ my_bool JSNX::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) jnp->Rank = B; jnp->Op = OP_LE; } else if (!Value->IsTypeNum()) { - jnp->CncVal = AllocateValue(g, (void*)", ", TYPE_STRING); + jnp->CncVal = AllocateValue(g, PlugDup(g, ", "), TYPE_STRING); jnp->Op = OP_CNC; } else jnp->Op = OP_ADD; @@ -181,6 +181,10 @@ my_bool JSNX::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) if (n > 2) { // Set concat intermediate string p[n - 1] = 0; + + if (trace) + htrc("Concat string=%s\n", p + 1); + jnp->CncVal = AllocateValue(g, p + 1, TYPE_STRING); } // endif n @@ -242,6 +246,9 @@ my_bool JSNX::ParseJpath(PGLOBAL g) // Jpath = Name; return true; + if (trace) + htrc("ParseJpath %s\n", SVP(Jpath)); + if (!(pbuf = PlgDBDup(g, Jpath))) return true; @@ -301,6 +308,12 @@ my_bool JSNX::ParseJpath(PGLOBAL g) Nod = i; MulVal = AllocateValue(g, Value); + + if (trace) + for (i = 0; i < Nod; i++) + htrc("Node(%d) Key=%s Op=%d Rank=%d\n", + i, SVP(Nodes[i].Key), Nodes[i].Op, Nodes[i].Rank); + Parsed = true; return false; } // end of ParseJpath @@ -485,7 +498,7 @@ PVAL JSNX::ExpandArray(PGLOBAL g, PJAR arp, int n) PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) { //int i, ars, nv = 0, nextsame = Tjp->NextSame; - int i, ars, nv = 0, nextsame = 0; + int i, nv = 0, nextsame = 0; my_bool err; OPVAL op = Nodes[n].Op; PVAL val[2], vp = Nodes[n].Valp; @@ -493,11 +506,20 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) JVALUE jval; vp->Reset(); - ars = arp->size(); +//ars = arp->size(); + + if (trace) + htrc("CalculateArray size=%d\n", arp->size()); +// htrc("CalculateArray size=%d\n", ars); - for (i = 0; i < ars; i++) { + for (i = 0; i < arp->size(); i++) { +//for (i = 0; i < ars; i++) { because compiler bug jvrp = arp->GetValue(i); + if (trace) + htrc("Value %s null=%d nv=%d\n", + jvrp->GetString(g), jvrp->IsNull() ? 1 : 0, nv); + if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) { if (jvrp->IsNull()) { jvrp->Value = AllocateValue(g, GetJsonNull(), TYPE_STRING); @@ -514,8 +536,8 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) } else SetJsonValue(g, MulVal, jvp, n); - if (!MulVal->IsZero()) { - switch (op) { + if (!MulVal->IsNull()) { + switch (op) { case OP_CNC: if (Nodes[n].CncVal) { val[0] = Nodes[n].CncVal; @@ -1876,7 +1898,7 @@ char *json_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result, PJAR arp; PJVAL jvp = MakeValue(g, args, 0, &top); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(top = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); return NULL; @@ -2666,7 +2688,7 @@ char *json_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result, PJSON jsp; PJVAL jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); return NULL; @@ -3050,7 +3072,7 @@ char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); return NULL; @@ -3165,7 +3187,7 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); goto err; @@ -3280,7 +3302,7 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); if (g->Mrr) *error = 1; @@ -3395,7 +3417,7 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); *is_null = 1; @@ -3511,7 +3533,7 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); goto err; @@ -3635,7 +3657,7 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); goto err; @@ -3807,7 +3829,7 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); goto err; @@ -3894,7 +3916,7 @@ char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { throw 2; } // endif jsp @@ -4230,14 +4252,14 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!strchr("[{ \t\r\n", *p)) { // Is this a file name? if (!(p = GetJsonFile(g, p))) { PUSH_WARNING(g->Message); goto fin; } else - fn = jvp->GetString(); + fn = jvp->GetString(g); } // endif p @@ -4380,7 +4402,7 @@ char *jbin_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result, PJVAL jvp = MakeValue(g, args, 0, &top); PGLOBAL gb = GetMemPtr(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(top = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); return NULL; @@ -4918,7 +4940,7 @@ char *jbin_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result, PJSON jsp; PJVAL jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); return NULL; @@ -4989,7 +5011,7 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); goto fin; @@ -5163,7 +5185,7 @@ char *bin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, } else jvp = MakeValue(g, args, 0); - if ((p = jvp->GetString())) { + if ((p = jvp->GetString(g))) { if (!(jsp = ParseJson(g, p, strlen(p)))) { PUSH_WARNING(g->Message); goto fin; -- cgit v1.2.1