Commit ca630041 authored by Olivier Bertrand's avatar Olivier Bertrand

- Fix bug causing bnx base wrong after CheckMemory

  Add negative array indexes starting from the last
  modified:   storage/connect/bson.cpp
  modified:   storage/connect/bsonudf.cpp
  modified:   storage/connect/json.cpp
parent 571294f9
...@@ -1138,6 +1138,9 @@ PBVAL BJSON::GetArrayValue(PBVAL bap, int n) ...@@ -1138,6 +1138,9 @@ PBVAL BJSON::GetArrayValue(PBVAL bap, int n)
CheckType(bap, TYPE_JAR); CheckType(bap, TYPE_JAR);
int i = 0; int i = 0;
if (n < 0)
n += GetArraySize(bap);
for (PBVAL bvp = GetArray(bap); bvp; bvp = GetNext(bvp), i++) for (PBVAL bvp = GetArray(bap); bvp; bvp = GetNext(bvp), i++)
if (i == n) if (i == n)
return bvp; return bvp;
......
...@@ -3707,6 +3707,7 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3707,6 +3707,7 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
PUSH_WARNING("CheckMemory error"); PUSH_WARNING("CheckMemory error");
goto fin; goto fin;
} else { } else {
bnx.Reset();
jvp = bnx.MakeValue(args, 0, true); jvp = bnx.MakeValue(args, 0, true);
if (g->Mrr) { // First argument is a constant if (g->Mrr) { // First argument is a constant
...@@ -4052,6 +4053,7 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args, ...@@ -4052,6 +4053,7 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
*is_null = 1; *is_null = 1;
return 0.0; return 0.0;
} else { } else {
bnx.Reset();
jvp = bnx.MakeValue(args, 0); jvp = bnx.MakeValue(args, 0);
if ((p = bnx.GetString(jvp))) { if ((p = bnx.GetString(jvp))) {
......
...@@ -58,11 +58,19 @@ char *GetJsonNull(void); ...@@ -58,11 +58,19 @@ char *GetJsonNull(void);
/***********************************************************************/ /***********************************************************************/
/* IsNum: check whether this string is all digits. */ /* IsNum: check whether this string is all digits. */
/***********************************************************************/ /***********************************************************************/
bool IsNum(PSZ s) { bool IsNum(PSZ s)
for (char* p = s; *p; p++) {
char* p = s;
if (*p == '-')
p++;
if (*p == ']')
return false;
else for (; *p; p++)
if (*p == ']') if (*p == ']')
break; break;
else if (!isdigit(*p) || *p == '-') else if (!isdigit(*p))
return false; return false;
return true; return true;
...@@ -1257,6 +1265,8 @@ PJVAL JARRAY::GetArrayValue(int i) ...@@ -1257,6 +1265,8 @@ PJVAL JARRAY::GetArrayValue(int i)
{ {
if (Mvals && i >= 0 && i < Size) if (Mvals && i >= 0 && i < Size)
return Mvals[i]; return Mvals[i];
else if (Mvals && i < 0 && i >= -Size)
return Mvals[Size + i];
else else
return NULL; return NULL;
} // end of GetValue } // end of GetValue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment