1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Remove a push warning causing failing assert. Modified storage/connect/filamap.cpp

This commit is contained in:
Olivier Bertrand
2020-12-04 23:21:59 +01:00
parent 4b6d661c7f
commit c05b1288fd
10 changed files with 400 additions and 570 deletions

View File

@@ -21,6 +21,15 @@
#include "plgdbsem.h" #include "plgdbsem.h"
#include "bson.h" #include "bson.h"
/***********************************************************************/
/* Check macro. */
/***********************************************************************/
#if defined(_DEBUG)
#define CheckType(X,Y) if (!X || X ->Type != Y) throw MSG(VALTYPE_NOMATCH);
#else
#define CheckType(V)
#endif
#if defined(__WIN__) #if defined(__WIN__)
#define EL "\r\n" #define EL "\r\n"
#else #else
@@ -859,13 +868,14 @@ PBPR BJSON::SubAllocPair(OFFSET key, OFFSET val)
/***********************************************************************/ /***********************************************************************/
/* Return the number of pairs in this object. */ /* Return the number of pairs in this object. */
/***********************************************************************/ /***********************************************************************/
int BJSON::GetObjectSize(PBPR bop, bool b) int BJSON::GetObjectSize(PBVAL bop, bool b)
{ {
CheckType(bop, TYPE_JOB);
int n = 0; int n = 0;
for (PBPR brp = bop; brp; brp = MPP(brp->Next)) for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp))
// If b return only non null pairs // If b return only non null pairs
if (!b || (brp->Vlp && (MVP(brp->Vlp))->Type != TYPE_NULL)) if (!b || (brp->Vlp && GetVal(brp)->Type != TYPE_NULL))
n++; n++;
return n; return n;
@@ -874,64 +884,60 @@ int BJSON::GetObjectSize(PBPR bop, bool b)
/***********************************************************************/ /***********************************************************************/
/* Add a new pair to an Object and return it. */ /* Add a new pair to an Object and return it. */
/***********************************************************************/ /***********************************************************************/
PBPR BJSON::AddPair(PBPR bop, PSZ key, OFFSET val) void BJSON::AddPair(PBVAL bop, PSZ key, OFFSET val)
{ {
PBPR brp, nrp = SubAllocPair(key, val); CheckType(bop, TYPE_JOB);
PBPR brp;
OFFSET nrp = MOF(SubAllocPair(key, val));
if (bop) { if (bop->To_Val) {
for (brp = bop; brp->Next; brp = MPP(brp->Next)); for (brp = GetObject(bop); brp->Next; brp = GetNext(brp));
brp->Next = MOF(nrp); brp->Next = nrp;
} else } else
bop = nrp; bop->To_Val = nrp;
return bop; bop->Nd++;
} // end of AddPair } // end of AddPair
/***********************************************************************/ /***********************************************************************/
/* Return all object keys as an array. */ /* Return all object keys as an array. */
/***********************************************************************/ /***********************************************************************/
PBVAL BJSON::GetKeyList(PBPR bop) PBVAL BJSON::GetKeyList(PBVAL bop)
{ {
PBVAL bvp, lvp, fvp = NULL; CheckType(bop, TYPE_JOB);
PBVAL arp = NewVal(TYPE_JAR);
for (PBPR brp = bop; brp; brp = MPP(brp->Next)) for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp))
if (fvp) { AddArrayValue(arp, MOF(SubAllocVal(brp->Key, TYPE_STRG)));
bvp = SubAllocVal(brp->Key, TYPE_STRG);
lvp->Next = MOF(bvp);
lvp = bvp;
} else
lvp = fvp = SubAllocVal(brp->Key, TYPE_STRG);
return fvp; return arp;
} // end of GetKeyList } // end of GetKeyList
/***********************************************************************/ /***********************************************************************/
/* Return all object values as an array. */ /* Return all object values as an array. */
/***********************************************************************/ /***********************************************************************/
PBVAL BJSON::GetObjectValList(PBPR bop) PBVAL BJSON::GetObjectValList(PBVAL bop)
{ {
PBVAL bvp, lvp, fvp = NULL; CheckType(bop, TYPE_JOB);
PBVAL arp = NewVal(TYPE_JAR);
for (PBPR brp = bop; brp; brp = MPP(brp->Next)) for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp))
if (fvp) { AddArrayValue(arp, brp->Vlp);
bvp = DupVal(MVP(brp->Vlp));
lvp->Next = MOF(bvp);
lvp = bvp;
} else
lvp = fvp = DupVal(MVP(brp->Vlp));
return fvp; return arp;
} // end of GetObjectValList } // end of GetObjectValList
/***********************************************************************/ /***********************************************************************/
/* Get the value corresponding to the given key. */ /* Get the value corresponding to the given key. */
/***********************************************************************/ /***********************************************************************/
PBVAL BJSON::GetKeyValue(PBPR bop, PSZ key) PBVAL BJSON::GetKeyValue(PBVAL bop, PSZ key)
{ {
for (PBPR brp = bop; brp; brp = MPP(brp->Next)) CheckType(bop, TYPE_JOB);
if (!strcmp(MZP(brp->Key), key))
return MVP(brp->Vlp); for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp))
if (!strcmp(GetKey(brp), key))
return GetVal(brp);
return NULL; return NULL;
} // end of GetKeyValue; } // end of GetKeyValue;
@@ -939,8 +945,11 @@ PBVAL BJSON::GetKeyValue(PBPR bop, PSZ key)
/***********************************************************************/ /***********************************************************************/
/* Return the text corresponding to all keys (XML like). */ /* Return the text corresponding to all keys (XML like). */
/***********************************************************************/ /***********************************************************************/
PSZ BJSON::GetObjectText(PGLOBAL g, PBPR bop, PSTRG text) { PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text)
if (bop) { {
CheckType(bop, TYPE_JOB);
if (bop->To_Val) {
bool b; bool b;
if (!text) { if (!text) {
@@ -977,8 +986,8 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBPR bop, PSTRG text) {
} else } else
#endif // 0 #endif // 0
for (PBPR brp = bop; brp; brp = MPP(brp->Next)) { for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp)) {
GetValueText(g, MVP(brp->Vlp), text); GetValueText(g, GetVal(brp), text);
if (brp->Next) if (brp->Next)
text->Append(' '); text->Append(' ');
@@ -998,39 +1007,44 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBPR bop, PSTRG text) {
/***********************************************************************/ /***********************************************************************/
/* Set or add a value corresponding to the given key. */ /* Set or add a value corresponding to the given key. */
/***********************************************************************/ /***********************************************************************/
PBPR BJSON::SetKeyValue(PBPR bop, OFFSET bvp, PSZ key) void BJSON::SetKeyValue(PBVAL bop, OFFSET bvp, PSZ key)
{ {
PBPR brp = bop, prp = NULL; CheckType(bop, TYPE_JOB);
PBPR brp, prp = NULL;
if (brp) { if (bop->To_Val) {
for (brp = bop; brp; brp = MPP(brp->Next)) for (brp = GetObject(bop); brp; brp = GetNext(brp))
if (!strcmp(MZP(brp->Key), key)) { if (!strcmp(GetKey(brp), key)) {
brp->Vlp = bvp; brp->Vlp = bvp;
break; return;
} else } else
prp = brp; prp = brp;
if (!brp) if (!brp)
prp->Vlp = MOF(SubAllocPair(key, bvp)); prp->Next = MOF(SubAllocPair(key, bvp));
} else } else
bop = SubAllocPair(key, bvp); bop->To_Val = MOF(SubAllocPair(key, bvp));
// Return the first pair of this object bop->Nd++;
return bop;
} // end of SetKeyValue } // end of SetKeyValue
/***********************************************************************/ /***********************************************************************/
/* Merge two objects. */ /* Merge two objects. */
/***********************************************************************/ /***********************************************************************/
PBPR BJSON::MergeObject(PBPR bop1, PBPR bop2) PBVAL BJSON::MergeObject(PBVAL bop1, PBVAL bop2)
{ {
if (bop1) CheckType(bop1, TYPE_JOB);
for (PBPR brp = bop2; brp; brp = MPP(brp->Next)) CheckType(bop2, TYPE_JOB);
SetKeyValue(bop1, brp->Vlp, MZP(brp->Key));
else if (bop1->To_Val)
bop1 = bop2; for (PBPR brp = GetObject(bop2); brp; brp = GetNext(brp))
SetKeyValue(bop1, brp->Vlp, GetKey(brp));
else {
bop1->To_Val = bop2->To_Val;
bop1->Nd = bop2->Nd;
} // endelse To_Val
return bop1; return bop1;
} // end of MergeObject; } // end of MergeObject;
@@ -1038,30 +1052,33 @@ PBPR BJSON::MergeObject(PBPR bop1, PBPR bop2)
/***********************************************************************/ /***********************************************************************/
/* Delete a value corresponding to the given key. */ /* Delete a value corresponding to the given key. */
/***********************************************************************/ /***********************************************************************/
PBPR BJSON::DeleteKey(PBPR bop, PCSZ key) void BJSON::DeleteKey(PBVAL bop, PCSZ key)
{ {
CheckType(bop, TYPE_JOB);
PBPR brp, pbrp = NULL; PBPR brp, pbrp = NULL;
for (brp = bop; brp; brp = MPP(brp->Next)) for (brp = GetObject(bop); brp; brp = GetNext(brp))
if (!strcmp(MZP(brp->Key), key)) { if (!strcmp(MZP(brp->Key), key)) {
if (pbrp) { if (pbrp) {
pbrp->Next = brp->Next; pbrp->Next = brp->Next;
return bop;
} else } else
return MPP(brp->Next); bop->To_Val = brp->Next;
bop->Nd--;
break;
} else } else
pbrp = brp; pbrp = brp;
return bop;
} // end of DeleteKey } // end of DeleteKey
/***********************************************************************/ /***********************************************************************/
/* True if void or if all members are nulls. */ /* True if void or if all members are nulls. */
/***********************************************************************/ /***********************************************************************/
bool BJSON::IsObjectNull(PBPR bop) bool BJSON::IsObjectNull(PBVAL bop)
{ {
for (PBPR brp = bop; brp; brp = MPP(brp->Next)) CheckType(bop, TYPE_JOB);
for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp))
if (brp->Vlp && (MVP(brp->Vlp))->Type != TYPE_NULL) if (brp->Vlp && (MVP(brp->Vlp))->Type != TYPE_NULL)
return false; return false;
@@ -1075,9 +1092,10 @@ bool BJSON::IsObjectNull(PBPR bop)
/***********************************************************************/ /***********************************************************************/
int BJSON::GetArraySize(PBVAL bap, bool b) int BJSON::GetArraySize(PBVAL bap, bool b)
{ {
CheckType(bap, TYPE_JAR);
int n = 0; int n = 0;
for (PBVAL bvp = bap; bvp; bvp = MVP(bvp->Next)) for (PBVAL bvp = GetArray(bap); bvp; bvp = GetNext(bvp))
// If b, return only non null values // If b, return only non null values
if (!b || bvp->Type != TYPE_NULL) if (!b || bvp->Type != TYPE_NULL)
n++; n++;
@@ -1090,13 +1108,12 @@ int BJSON::GetArraySize(PBVAL bap, bool b)
/***********************************************************************/ /***********************************************************************/
PBVAL BJSON::GetArrayValue(PBVAL bap, int n) PBVAL BJSON::GetArrayValue(PBVAL bap, int n)
{ {
CheckType(bap, TYPE_JAR);
int i = 0; int i = 0;
for (PBVAL bvp = bap; bvp; bvp = MVP(bvp->Next)) for (PBVAL bvp = GetArray(bap); bvp; bvp = GetNext(bvp), i++)
if (i == n) if (i == n)
return bvp; return bvp;
else
i++;
return NULL; return NULL;
} // end of GetArrayValue } // end of GetArrayValue
@@ -1104,80 +1121,78 @@ PBVAL BJSON::GetArrayValue(PBVAL bap, int n)
/***********************************************************************/ /***********************************************************************/
/* Add a Value to the Array Value list. */ /* Add a Value to the Array Value list. */
/***********************************************************************/ /***********************************************************************/
PBVAL BJSON::AddArrayValue(PBVAL bap, PBVAL nvp, int* x) void BJSON::AddArrayValue(PBVAL bap, OFFSET nvp, int* x)
{ {
CheckType(bap, TYPE_JAR);
if (!nvp) if (!nvp)
nvp = NewVal(); nvp = MOF(NewVal());
if (bap) { if (bap->To_Val) {
int i = 0, n = (x) ? *x : INT_MAX32; int i = 0, n = (x) ? *x : INT_MAX32;
PBVAL bvp;
for (bvp = bap; bvp; bvp = MVP(bvp->Next), i++) for (PBVAL bvp = GetArray(bap); bvp; bvp = GetNext(bvp), i++)
if (!bvp->Next || (x && i == n)) { if (!bvp->Next || (x && i == n)) {
nvp->Next = bvp->Next; MVP(nvp)->Next = bvp->Next;
bvp->Next = MOF(nvp); bvp->Next = nvp;
break; break;
} // endif Next } // endif Next
} else } else
bap = nvp; bap->To_Val = nvp;
return bap; bap->Nd++;
} // end of AddArrayValue } // end of AddArrayValue
/***********************************************************************/ /***********************************************************************/
/* Merge two arrays. */ /* Merge two arrays. */
/***********************************************************************/ /***********************************************************************/
PBVAL BJSON::MergeArray(PBVAL bap1, PBVAL bap2) void BJSON::MergeArray(PBVAL bap1, PBVAL bap2)
{ {
if (bap1) { CheckType(bap1, TYPE_JAR);
for (PBVAL bvp = bap2; bvp; bvp = MVP(bvp->Next)) CheckType(bap2, TYPE_JAR);
AddArrayValue(bap1, bvp);
return bap1; if (bap1->To_Val) {
} else for (PBVAL bvp = GetArray(bap2); bvp; bvp = GetNext(bvp))
return bap2; AddArrayValue(bap1, MOF(DupVal(bvp)));
} else {
bap1->To_Val = bap2->To_Val;
bap1->Nd = bap2->Nd;
} // endif To_Val
} // end of MergeArray } // end of MergeArray
/***********************************************************************/ /***********************************************************************/
/* Set the nth Value of the Array Value list or add it. */ /* Set the nth Value of the Array Value list or add it. */
/***********************************************************************/ /***********************************************************************/
PBVAL BJSON::SetArrayValue(PBVAL bap, PBVAL nvp, int n) void BJSON::SetArrayValue(PBVAL bap, PBVAL nvp, int n)
{ {
PBVAL bvp = bap, pvp = NULL; CheckType(bap, TYPE_JAR);
PBVAL bvp = NULL, pvp = NULL;
if (bvp) { if (bap->To_Val) {
for (int i = 0; bvp; i++, bvp = MVP(bvp->Next)) for (int i = 0; bvp = GetArray(bap); i++, bvp = GetNext(bvp))
if (i == n) { if (i == n) {
bvp->To_Val = nvp->To_Val; SetValueVal(bvp, nvp);
bvp->Nd = nvp->Nd; return;
bvp->Type = nvp->Type;
return bap;
} else } else
pvp = bvp; pvp = bvp;
} // endif bap } // endif bap
if (!bvp) { if (!bvp)
bvp = DupVal(nvp); AddArrayValue(bap, MOF(nvp));
if (pvp)
pvp->Next = MOF(bvp);
else
bap = bvp;
} // endif bvp
return bap;
} // end of SetValue } // end of SetValue
/***********************************************************************/ /***********************************************************************/
/* Return the text corresponding to all values. */ /* Return the text corresponding to all values. */
/***********************************************************************/ /***********************************************************************/
PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text) { PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text)
if (bap) { {
CheckType(bap, TYPE_JAR);
if (bap->To_Val) {
bool b; bool b;
if (!text) { if (!text) {
@@ -1192,7 +1207,7 @@ PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text) {
b = false; b = false;
} // endif text } // endif text
for (PBVAL bvp = bap; bvp; bvp = MVP(bvp->Next)) { for (PBVAL bvp = GetArray(bap); bvp; bvp = GetNext(bvp)) {
GetValueText(g, bvp, text); GetValueText(g, bvp, text);
if (bvp->Next) if (bvp->Next)
@@ -1200,14 +1215,14 @@ PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text) {
else if (!b) else if (!b)
text->Append(')'); text->Append(')');
} // endfor jp } // endfor bvp
if (b) { if (b) {
text->Trim(); text->Trim();
return text->GetStr(); return text->GetStr();
} // endif b } // endif b
} // endif First } // endif To_Val
return NULL; return NULL;
} // end of GetText; } // end of GetText;
@@ -1215,22 +1230,23 @@ PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text) {
/***********************************************************************/ /***********************************************************************/
/* Delete a Value from the Arrays Value list. */ /* Delete a Value from the Arrays Value list. */
/***********************************************************************/ /***********************************************************************/
PBVAL BJSON::DeleteValue(PBVAL bap, int n) void BJSON::DeleteValue(PBVAL bap, int n)
{ {
PBVAL bvp = bap, pvp = NULL; CheckType(bap, TYPE_JAR);
int i = 0;
PBVAL bvp, pvp = NULL;
if (bvp) for (bvp = GetArray(bap); bvp; i++, bvp = GetNext(bvp))
for (int i = 0; bvp; i++, bvp = MVP(bvp->Next))
if (i == n) { if (i == n) {
if (pvp) if (pvp)
pvp->Next = bvp->Next; pvp->Next = bvp->Next;
else else
bap = bvp; bap->To_Val = bvp->Next;
bap->Nd--;
break; break;
} // endif i } // endif i
return bap;
} // end of DeleteValue } // end of DeleteValue
/***********************************************************************/ /***********************************************************************/
@@ -1238,7 +1254,9 @@ PBVAL BJSON::DeleteValue(PBVAL bap, int n)
/***********************************************************************/ /***********************************************************************/
bool BJSON::IsArrayNull(PBVAL bap) bool BJSON::IsArrayNull(PBVAL bap)
{ {
for (PBVAL bvp = bap; bvp; bvp = MVP(bvp->Next)) CheckType(bap, TYPE_JAR);
for (PBVAL bvp = GetArray(bap); bvp; bvp = GetNext(bvp))
if (bvp->Type != TYPE_NULL) if (bvp->Type != TYPE_NULL)
return false; return false;
@@ -1288,9 +1306,10 @@ PBVAL BJSON::SubAllocStr(OFFSET toval, short nd)
/***********************************************************************/ /***********************************************************************/
/* Allocate a BVALUE with a given string or numeric value. */ /* Allocate a BVALUE with a given string or numeric value. */
/***********************************************************************/ /***********************************************************************/
PBVAL BJSON::SubAllocVal(PVAL valp) PBVAL BJSON::NewVal(PVAL valp)
{ {
PBVAL vlp = NewVal(); PBVAL vlp = NewVal();
SetValue(vlp, valp); SetValue(vlp, valp);
return vlp; return vlp;
} // end of SubAllocVal } // end of SubAllocVal
@@ -1306,90 +1325,6 @@ PBVAL BJSON::DupVal(PBVAL bvlp) {
return bvp; return bvp;
} // end of DupVal } // end of DupVal
#if 0
/***********************************************************************/
/* Constructor for a JVALUE. */
/***********************************************************************/
JVALUE::JVALUE(PJSON jsp) : JSON() {
if (jsp->GetType() == TYPE_JVAL) {
PJVAL jvp = (PJVAL)jsp;
// Val = ((PJVAL)jsp)->GetVal();
if (jvp->DataType == TYPE_JSON) {
Jsp = jvp->GetJsp();
DataType = TYPE_JSON;
Nd = 0;
} else {
LLn = jvp->LLn; // Must be LLn on 32 bit machines
Nd = jvp->Nd;
DataType = jvp->DataType;
} // endelse Jsp
} else {
Jsp = jsp;
// Val = NULL;
DataType = TYPE_JSON;
Nd = 0;
} // endif Type
Next = NULL;
Del = false;
Type = TYPE_JVAL;
} // end of JVALUE constructor
/***********************************************************************/
/* Constructor for a JVALUE with a given string or numeric value. */
/***********************************************************************/
JVALUE::JVALUE(PGLOBAL g, PVL vlp) : JSON() {
Jsp = NULL;
Val = vlp;
Next = NULL;
Del = false;
Type = TYPE_JVAL;
} // end of JVALUE constructor
#endif // 0
#if 0
/***********************************************************************/
/* Constructor for a given string. */
/***********************************************************************/
JVALUE::JVALUE(PGLOBAL g, PCSZ strp) : JSON() {
Jsp = NULL;
//Val = AllocVal(g, TYPE_STRG);
Strp = (char*)strp;
DataType = TYPE_STRG;
Nd = 0;
Next = NULL;
Del = false;
Type = TYPE_JVAL;
} // end of JVALUE constructor
/***********************************************************************/
/* Set or reset all Jvalue members. */
/***********************************************************************/
void JVALUE::Clear(void) {
Jsp = NULL;
Next = NULL;
Type = TYPE_JVAL;
Del = false;
Nd = 0;
DataType = TYPE_NULL;
} // end of Clear
/***********************************************************************/
/* Returns the type of the Value's value. */
/***********************************************************************/
JTYP JVALUE::GetValType(void) {
if (DataType == TYPE_JSON)
return Jsp->GetType();
//else if (Val)
// return Val->Type;
else
return DataType;
} // end of GetValType
#endif // 0
/***********************************************************************/ /***********************************************************************/
/* Return the size of value's value. */ /* Return the size of value's value. */
/***********************************************************************/ /***********************************************************************/
@@ -1397,37 +1332,15 @@ int BJSON::GetSize(PBVAL vlp, bool b)
{ {
switch (vlp->Type) { switch (vlp->Type) {
case TYPE_JAR: case TYPE_JAR:
return GetArraySize(MVP(vlp->To_Val)); return GetArraySize(vlp);
case TYPE_JOB: case TYPE_JOB:
return GetObjectSize(MPP(vlp->To_Val)); return GetObjectSize(vlp);
default: default:
return 1; return 1;
} // enswitch Type } // enswitch Type
} // end of GetSize } // end of GetSize
/***********************************************************************/
/* Return the Value's Object value. */
/***********************************************************************/
PBPR BJSON::GetObject(PBVAL vlp)
{
if (vlp->Type == TYPE_JOB)
return MPP(vlp->To_Val);
return NULL;
} // end of GetObject
/***********************************************************************/
/* Return the Value's Array value. */
/***********************************************************************/
PBVAL BJSON::GetArray(PBVAL vlp)
{
if (vlp->Type == TYPE_JAR)
return MVP(vlp->To_Val);
return NULL;
} // end of GetArray
/***********************************************************************/ /***********************************************************************/
/* Return the Value's as a Value struct. */ /* Return the Value's as a Value struct. */
/***********************************************************************/ /***********************************************************************/
@@ -1604,11 +1517,12 @@ PSZ BJSON::GetString(PBVAL vp, char* buff)
/***********************************************************************/ /***********************************************************************/
/* Return the Value's String value. */ /* Return the Value's String value. */
/***********************************************************************/ /***********************************************************************/
PSZ BJSON::GetValueText(PGLOBAL g, PBVAL vlp, PSTRG text) { PSZ BJSON::GetValueText(PGLOBAL g, PBVAL vlp, PSTRG text)
{
if (vlp->Type == TYPE_JOB) if (vlp->Type == TYPE_JOB)
return GetObjectText(g, MPP(vlp->To_Val), text); return GetObjectText(g, vlp, text);
else if (vlp->Type == TYPE_JAR) else if (vlp->Type == TYPE_JAR)
return GetArrayText(g, MVP(vlp->To_Val), text); return GetArrayText(g, vlp, text);
char buff[32]; char buff[32];
PSZ s = (vlp->Type == TYPE_NULL) ? NULL : GetString(vlp, buff); PSZ s = (vlp->Type == TYPE_NULL) ? NULL : GetString(vlp, buff);
@@ -1621,15 +1535,19 @@ PSZ BJSON::GetValueText(PGLOBAL g, PBVAL vlp, PSTRG text) {
return NULL; return NULL;
} // end of GetText } // end of GetText
void BJSON::SetValueObj(PBVAL vlp, PBPR bop) void BJSON::SetValueObj(PBVAL vlp, PBVAL bop)
{ {
vlp->To_Val = MOF(bop); CheckType(bop, TYPE_JOB);
vlp->To_Val = bop->To_Val;
vlp->Nd = bop->Nd;
vlp->Type = TYPE_JOB; vlp->Type = TYPE_JOB;
} // end of SetValueObj; } // end of SetValueObj;
void BJSON::SetValueArr(PBVAL vlp, PBVAL bap) void BJSON::SetValueArr(PBVAL vlp, PBVAL bap)
{ {
vlp->To_Val = MOF(bap); CheckType(bap, TYPE_JAR);
vlp->To_Val = bap->To_Val;
vlp->Nd = bap->Nd;
vlp->Type = TYPE_JAR; vlp->Type = TYPE_JAR;
} // end of SetValue; } // end of SetValue;
@@ -1640,14 +1558,17 @@ void BJSON::SetValueVal(PBVAL vlp, PBVAL vp)
vlp->Type = vp->Type; vlp->Type = vp->Type;
} // end of SetValue; } // end of SetValue;
void BJSON::SetValue(PBVAL vlp, PVAL valp) PBVAL BJSON::SetValue(PBVAL vlp, PVAL valp)
{ {
if (!vlp)
vlp = NewVal();
if (!valp || valp->IsNull()) { if (!valp || valp->IsNull()) {
vlp->Type = TYPE_NULL; vlp->Type = TYPE_NULL;
} else switch (valp->GetType()) { } else switch (valp->GetType()) {
case TYPE_DATE: case TYPE_DATE:
if (((DTVAL*)valp)->IsFormatted()) if (((DTVAL*)valp)->IsFormatted())
vlp->To_Val = MOF(valp->GetCharValue()); vlp->To_Val = MOF(PlugDup(G, valp->GetCharValue()));
else { else {
char buf[32]; char buf[32];
@@ -1657,7 +1578,7 @@ void BJSON::SetValue(PBVAL vlp, PVAL valp)
vlp->Type = TYPE_DTM; vlp->Type = TYPE_DTM;
break; break;
case TYPE_STRING: case TYPE_STRING:
vlp->To_Val = MOF(valp->GetCharValue()); vlp->To_Val = MOF(PlugDup(G, valp->GetCharValue()));
vlp->Type = TYPE_STRG; vlp->Type = TYPE_STRG;
break; break;
case TYPE_DOUBLE: case TYPE_DOUBLE:
@@ -1702,6 +1623,7 @@ void BJSON::SetValue(PBVAL vlp, PVAL valp)
throw(777); throw(777);
} // endswitch Type } // endswitch Type
return vlp;
} // end of SetValue } // end of SetValue
/***********************************************************************/ /***********************************************************************/
@@ -1769,10 +1691,10 @@ bool BJSON::IsValueNull(PBVAL vlp) {
b = true; b = true;
break; break;
case TYPE_JOB: case TYPE_JOB:
b = IsObjectNull(MPP(vlp->To_Val)); b = IsObjectNull(vlp);
break; break;
case TYPE_JAR: case TYPE_JAR:
b = IsArrayNull(MVP(vlp->To_Val)); b = IsArrayNull(vlp);
break; break;
default: default:
b = false; b = false;

View File

@@ -17,13 +17,6 @@
#endif #endif
#define ARGS MY_MIN(24,(int)len-i),s+MY_MAX(i-3,0) #define ARGS MY_MIN(24,(int)len-i),s+MY_MAX(i-3,0)
#define MOF(X) MakeOff(Base, X)
#define MP(X) MakePtr(Base, X)
#define MPP(X) (PBPR)MakePtr(Base, X)
#define MVP(X) (PBVAL)MakePtr(Base, X)
#define MZP(X) (PSZ)MakePtr(Base, X)
#define LLN(X) *(longlong*)MakePtr(Base, X)
#define DBL(X) *(double*)MakePtr(Base, X)
class BDOC; class BDOC;
class BOUT; class BOUT;
@@ -71,6 +64,15 @@ public:
// Constructor // Constructor
BJSON(PGLOBAL g, PBVAL vp = NULL) { G = g, Base = G->Sarea; Bvp = vp; } BJSON(PGLOBAL g, PBVAL vp = NULL) { G = g, Base = G->Sarea; Bvp = vp; }
// Utility functions
inline OFFSET MOF(void *p) {return MakeOff(Base, p);}
inline void *MP(OFFSET o) {return MakePtr(Base, o);}
inline PBPR MPP(OFFSET o) {return (PBPR)MakePtr(Base, o);}
inline PBVAL MVP(OFFSET o) {return (PBVAL)MakePtr(Base, o);}
inline PSZ MZP(OFFSET o) {return (PSZ)MakePtr(Base, o);}
inline longlong LLN(OFFSET o) {return *(longlong*)MakePtr(Base, o);}
inline double DBL(OFFSET o) {return *(double*)MakePtr(Base, o);}
void* GetBase(void) { return Base; } void* GetBase(void) { return Base; }
void SubSet(bool b = false); void SubSet(bool b = false);
void MemSave(void) {G->Saved_Size = ((PPOOLHEADER)G->Sarea)->To_Free;} void MemSave(void) {G->Saved_Size = ((PPOOLHEADER)G->Sarea)->To_Free;}
@@ -82,47 +84,49 @@ public:
PBPR SubAllocPair(PSZ key, OFFSET val = 0) PBPR SubAllocPair(PSZ key, OFFSET val = 0)
{return SubAllocPair(MOF(key), val);} {return SubAllocPair(MOF(key), val);}
PBVAL NewVal(int type = TYPE_NULL); PBVAL NewVal(int type = TYPE_NULL);
PBVAL NewVal(PVAL valp);
PBVAL SubAllocVal(OFFSET toval, int type = TYPE_NULL, short nd = 0); PBVAL SubAllocVal(OFFSET toval, int type = TYPE_NULL, short nd = 0);
PBVAL SubAllocVal(PBVAL toval, int type = TYPE_NULL, short nd = 0) PBVAL SubAllocVal(PBVAL toval, int type = TYPE_NULL, short nd = 0)
{return SubAllocVal(MOF(toval), type, nd);} {return SubAllocVal(MOF(toval), type, nd);}
PBVAL SubAllocStr(OFFSET str, short nd = 0); PBVAL SubAllocStr(OFFSET str, short nd = 0);
PBVAL SubAllocStr(PSZ str, short nd = 0) PBVAL SubAllocStr(PSZ str, short nd = 0)
{return SubAllocStr(MOF(str), nd);} {return SubAllocStr(MOF(str), nd);}
PBVAL SubAllocVal(PVAL valp);
PBVAL DupVal(PBVAL bvp); PBVAL DupVal(PBVAL bvp);
// Array functions // Array functions
inline PBVAL GetArray(PBVAL vlp) {return MVP(vlp->To_Val);}
int GetArraySize(PBVAL bap, bool b = false); int GetArraySize(PBVAL bap, bool b = false);
PBVAL GetArrayValue(PBVAL bap, int i); PBVAL GetArrayValue(PBVAL bap, int i);
PSZ GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text); PSZ GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text);
PBVAL MergeArray(PBVAL bap1,PBVAL bap2); void MergeArray(PBVAL bap1,PBVAL bap2);
PBVAL DeleteValue(PBVAL bap, int n); void DeleteValue(PBVAL bap, int n);
PBVAL AddArrayValue(PBVAL bap, PBVAL nvp = NULL, int* x = NULL); void AddArrayValue(PBVAL bap, OFFSET nvp = NULL, int* x = NULL);
PBVAL SetArrayValue(PBVAL bap, PBVAL nvp, int n); inline void AddArrayValue(PBVAL bap, PBVAL nvp = NULL, int* x = NULL)
{AddArrayValue(bap, MOF(nvp), x);}
void SetArrayValue(PBVAL bap, PBVAL nvp, int n);
bool IsArrayNull(PBVAL bap); bool IsArrayNull(PBVAL bap);
// Object functions // Object functions
int GetObjectSize(PBPR bop, bool b = false); inline PBPR GetObject(PBVAL bop) {return MPP(bop->To_Val);}
PBPR GetNext(PBPR prp) {return MPP(prp->Next);} inline PBPR GetNext(PBPR brp) { return MPP(brp->Next); }
PSZ GetObjectText(PGLOBAL g, PBPR bop, PSTRG text); int GetObjectSize(PBVAL bop, bool b = false);
PBPR MergeObject(PBPR bop1, PBPR bop2); PSZ GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text);
PBPR AddPair(PBPR bop, PSZ key, OFFSET val = 0); PBVAL MergeObject(PBVAL bop1, PBVAL bop2);
void AddPair(PBVAL bop, PSZ key, OFFSET val = 0);
PSZ GetKey(PBPR prp) {return MZP(prp->Key);} PSZ GetKey(PBPR prp) {return MZP(prp->Key);}
PBVAL GetVal(PBPR prp) {return MVP(prp->Vlp);} PBVAL GetVal(PBPR prp) {return MVP(prp->Vlp);}
PBVAL GetKeyValue(PBPR bop, PSZ key); PBVAL GetKeyValue(PBVAL bop, PSZ key);
PBVAL GetKeyList(PBPR bop); PBVAL GetKeyList(PBVAL bop);
PBVAL GetObjectValList(PBPR bop); PBVAL GetObjectValList(PBVAL bop);
PBPR SetKeyValue(PBPR bop, OFFSET bvp, PSZ key); void SetKeyValue(PBVAL bop, OFFSET bvp, PSZ key);
inline PBPR SetKeyValue(PBPR bop, PBVAL vlp, PSZ key) inline void SetKeyValue(PBVAL bop, PBVAL vlp, PSZ key)
{return SetKeyValue(bop, MOF(vlp), key);} {SetKeyValue(bop, MOF(vlp), key);}
PBPR DeleteKey(PBPR bop, PCSZ k); void DeleteKey(PBVAL bop, PCSZ k);
bool IsObjectNull(PBPR bop); bool IsObjectNull(PBVAL bop);
// Value functions // Value functions
int GetSize(PBVAL vlp, bool b = false); int GetSize(PBVAL vlp, bool b = false);
PBVAL GetNext(PBVAL vlp) {return MVP(vlp->Next);} PBVAL GetNext(PBVAL vlp) {return MVP(vlp->Next);}
PBPR GetObject(PBVAL vlp);
PBVAL GetArray(PBVAL vlp);
//PJSON GetJsp(void) { return (DataType == TYPE_JSON ? Jsp : NULL); } //PJSON GetJsp(void) { return (DataType == TYPE_JSON ? Jsp : NULL); }
PSZ GetValueText(PGLOBAL g, PBVAL vlp, PSTRG text); PSZ GetValueText(PGLOBAL g, PBVAL vlp, PSTRG text);
inline PBVAL GetBson(PBVAL bvp) { return IsJson(bvp) ? MVP(bvp->To_Val) : bvp; } inline PBVAL GetBson(PBVAL bvp) { return IsJson(bvp) ? MVP(bvp->To_Val) : bvp; }
@@ -131,10 +135,10 @@ public:
long long GetBigint(PBVAL vp); long long GetBigint(PBVAL vp);
double GetDouble(PBVAL vp); double GetDouble(PBVAL vp);
PVAL GetValue(PGLOBAL g, PBVAL vp); PVAL GetValue(PGLOBAL g, PBVAL vp);
void SetValueObj(PBVAL vlp, PBPR bop); void SetValueObj(PBVAL vlp, PBVAL bop);
void SetValueArr(PBVAL vlp, PBVAL bap); void SetValueArr(PBVAL vlp, PBVAL bap);
void SetValueVal(PBVAL vlp, PBVAL vp); void SetValueVal(PBVAL vlp, PBVAL vp);
void SetValue(PBVAL vlp, PVAL valp); PBVAL SetValue(PBVAL vlp, PVAL valp);
void SetString(PBVAL vlp, PSZ s, int ci = 0); void SetString(PBVAL vlp, PSZ s, int ci = 0);
void SetInteger(PBVAL vlp, int n); void SetInteger(PBVAL vlp, int n);
void SetBigint(PBVAL vlp, longlong ll); void SetBigint(PBVAL vlp, longlong ll);

View File

@@ -348,7 +348,7 @@ PVAL BJNX::MakeJson(PGLOBAL g, PBVAL bvp)
} // end of MakeJson } // end of MakeJson
/*********************************************************************************/ /*********************************************************************************/
/* SetValue: Set a value from a JVALUE contains. */ /* SetValue: Set a value from a BVALUE contains. */
/*********************************************************************************/ /*********************************************************************************/
void BJNX::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp) void BJNX::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp)
{ {
@@ -381,10 +381,10 @@ void BJNX::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp)
break; break;
case TYPE_JAR: case TYPE_JAR:
vp->SetValue_psz(GetArrayText(g, MVP(vlp->To_Val), NULL)); vp->SetValue_psz(GetArrayText(g, vlp, NULL));
break; break;
case TYPE_JOB: case TYPE_JOB:
vp->SetValue_psz(GetObjectText(g, MPP(vlp->To_Val), NULL)); vp->SetValue_psz(GetObjectText(g, vlp, NULL));
break; break;
case TYPE_NULL: case TYPE_NULL:
vp->SetNull(true); vp->SetNull(true);
@@ -437,8 +437,8 @@ PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b)
for (; i < Nod && row; i++) { for (; i < Nod && row; i++) {
if (Nodes[i].Op == OP_NUM) { if (Nodes[i].Op == OP_NUM) {
Value->SetValue(row->Type == TYPE_JAR ? GetArraySize(MVP(row->To_Val)) : 1); Value->SetValue(row->Type == TYPE_JAR ? GetArraySize(row) : 1);
vlp = SubAllocVal(Value); vlp = NewVal(Value);
return vlp; return vlp;
} else if (Nodes[i].Op == OP_XX) { } else if (Nodes[i].Op == OP_XX) {
Jb = b; Jb = b;
@@ -460,11 +460,11 @@ PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b)
} //endif Op } //endif Op
} else } else
vlp = GetKeyValue(MPP(row->To_Val), Nodes[i].Key); vlp = GetKeyValue(row, Nodes[i].Key);
break; break;
case TYPE_JAR: case TYPE_JAR:
bap = MVP(row->To_Val); bap = row;
if (!Nodes[i].Key) { if (!Nodes[i].Key) {
if (Nodes[i].Op == OP_EQ || Nodes[i].Op == OP_LE) if (Nodes[i].Op == OP_EQ || Nodes[i].Op == OP_LE)
@@ -472,7 +472,7 @@ PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b)
else if (Nodes[i].Op == OP_EXP) else if (Nodes[i].Op == OP_EXP)
return (PBVAL)ExpandArray(g, bap, i); return (PBVAL)ExpandArray(g, bap, i);
else else
return SubAllocVal(CalculateArray(g, bap, i)); return NewVal(CalculateArray(g, bap, i));
} else { } else {
// Unexpected array, unwrap it as [0] // Unexpected array, unwrap it as [0]
@@ -616,13 +616,13 @@ my_bool BJNX::CheckPath(PGLOBAL g)
} else switch (row->Type) { } else switch (row->Type) {
case TYPE_JOB: case TYPE_JOB:
if (Nodes[i].Key) if (Nodes[i].Key)
val = GetKeyValue(MPP(row->To_Val), Nodes[i].Key); val = GetKeyValue(row, Nodes[i].Key);
break; break;
case TYPE_JAR: case TYPE_JAR:
if (!Nodes[i].Key) if (!Nodes[i].Key)
if (Nodes[i].Op == OP_EQ || Nodes[i].Op == OP_LE) if (Nodes[i].Op == OP_EQ || Nodes[i].Op == OP_LE)
val = GetArrayValue(MVP(row->To_Val), Nodes[i].Rank); val = GetArrayValue(row, Nodes[i].Rank);
break; break;
case TYPE_JVAL: case TYPE_JVAL:
@@ -660,10 +660,10 @@ PBVAL BJNX::GetRow(PGLOBAL g)
// Expected Array was not there, wrap the value // Expected Array was not there, wrap the value
continue; continue;
val = GetKeyValue(MPP(row->To_Val), Nodes[i].Key); val = GetKeyValue(row, Nodes[i].Key);
break; break;
case TYPE_JAR: case TYPE_JAR:
arp = MVP(row->To_Val); arp = row;
if (!Nodes[i].Key) { if (!Nodes[i].Key) {
if (Nodes[i].Op == OP_EQ) if (Nodes[i].Op == OP_EQ)
@@ -703,9 +703,9 @@ PBVAL BJNX::GetRow(PGLOBAL g)
nwr = NewVal(); nwr = NewVal();
if (row->Type == TYPE_JOB) { if (row->Type == TYPE_JOB) {
SetKeyValue(MPP(row->To_Val), MOF(nwr), Nodes[i - 1].Key); SetKeyValue(row, MOF(nwr), Nodes[i - 1].Key);
} else if (row->Type == TYPE_JAR) { } else if (row->Type == TYPE_JAR) {
AddArrayValue(MVP(row->To_Val), nwr); AddArrayValue(row, MOF(nwr));
} else { } else {
strcpy(g->Message, "Wrong type when writing new row"); strcpy(g->Message, "Wrong type when writing new row");
nwr = NULL; nwr = NULL;
@@ -727,7 +727,7 @@ PBVAL BJNX::GetRow(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
my_bool BJNX::WriteValue(PGLOBAL g, PBVAL jvalp) my_bool BJNX::WriteValue(PGLOBAL g, PBVAL jvalp)
{ {
PBPR objp = NULL; PBVAL objp = NULL;
PBVAL arp = NULL; PBVAL arp = NULL;
PBVAL jvp = NULL; PBVAL jvp = NULL;
PBVAL row = GetRow(g); PBVAL row = GetRow(g);
@@ -736,8 +736,8 @@ my_bool BJNX::WriteValue(PGLOBAL g, PBVAL jvalp)
return true; return true;
switch (row->Type) { switch (row->Type) {
case TYPE_JOB: objp = MPP(row->To_Val); break; case TYPE_JOB: objp = row; break;
case TYPE_JAR: arp = MVP(row->To_Val); break; case TYPE_JAR: arp = row; break;
case TYPE_JVAL: jvp = MVP(row->To_Val); break; case TYPE_JVAL: jvp = MVP(row->To_Val); break;
default: default:
strcpy(g->Message, "Invalid target type"); strcpy(g->Message, "Invalid target type");
@@ -749,7 +749,7 @@ my_bool BJNX::WriteValue(PGLOBAL g, PBVAL jvalp)
if (Nodes[Nod - 1].Op == OP_EQ) if (Nodes[Nod - 1].Op == OP_EQ)
SetArrayValue(arp, jvalp, Nodes[Nod - 1].Rank); SetArrayValue(arp, jvalp, Nodes[Nod - 1].Rank);
else else
AddArrayValue(arp, jvalp); AddArrayValue(arp, MOF(jvalp));
} // endif Key } // endif Key
@@ -787,10 +787,10 @@ PSZ BJNX::Locate(PGLOBAL g, PBVAL jsp, PBVAL jvp, int k)
switch (jsp->Type) { switch (jsp->Type) {
case TYPE_JAR: case TYPE_JAR:
err = LocateArray(g, MVP(jsp->To_Val)); err = LocateArray(g, jsp);
break; break;
case TYPE_JOB: case TYPE_JOB:
err = LocateObject(g, MPP(jsp->To_Val)); err = LocateObject(g, jsp);
break; break;
case TYPE_JVAL: case TYPE_JVAL:
err = LocateValue(g, MVP(jsp->To_Val)); err = LocateValue(g, MVP(jsp->To_Val));
@@ -810,9 +810,7 @@ PSZ BJNX::Locate(PGLOBAL g, PBVAL jsp, PBVAL jvp, int k)
} // endif's } // endif's
} catch (int n) { } catch (int n) {
if (trace(1)) xtrc(1, "Exception %d: %s\n", n, g->Message);
htrc("Exception %d: %s\n", n, g->Message);
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
} catch (const char* msg) { } catch (const char* msg) {
strcpy(g->Message, msg); strcpy(g->Message, msg);
@@ -848,7 +846,7 @@ my_bool BJNX::LocateArray(PGLOBAL g, PBVAL jarp)
/*********************************************************************************/ /*********************************************************************************/
/* Locate in a JSON Object. */ /* Locate in a JSON Object. */
/*********************************************************************************/ /*********************************************************************************/
my_bool BJNX::LocateObject(PGLOBAL g, PBPR jobp) my_bool BJNX::LocateObject(PGLOBAL g, PBVAL jobp)
{ {
size_t m; size_t m;
@@ -857,7 +855,7 @@ my_bool BJNX::LocateObject(PGLOBAL g, PBPR jobp)
m = Jp->N; m = Jp->N;
for (PBPR pair = jobp; pair && !Found; pair = MPP(pair->Next)) { for (PBPR pair = GetObject(jobp); pair && !Found; pair = GetNext(pair)) {
Jp->N = m; Jp->N = m;
if (Jp->WriteStr(MZP(pair->Key))) if (Jp->WriteStr(MZP(pair->Key)))
@@ -879,9 +877,9 @@ my_bool BJNX::LocateValue(PGLOBAL g, PBVAL jvp)
if (CompareTree(g, Bvalp, jvp)) if (CompareTree(g, Bvalp, jvp))
Found = (--K == 0); Found = (--K == 0);
else if (jvp->Type == TYPE_JAR) else if (jvp->Type == TYPE_JAR)
return LocateArray(g, GetArray(jvp)); return LocateArray(g, jvp);
else if (jvp->Type == TYPE_JOB) else if (jvp->Type == TYPE_JOB)
return LocateObject(g, GetObject(jvp)); return LocateObject(g, jvp);
return false; return false;
} // end of LocateValue } // end of LocateValue
@@ -914,10 +912,10 @@ PSZ BJNX::LocateAll(PGLOBAL g, PBVAL jsp, PBVAL bvp, int mx)
switch (jsp->Type) { switch (jsp->Type) {
case TYPE_JAR: case TYPE_JAR:
err = LocateArrayAll(g, MVP(jsp->To_Val)); err = LocateArrayAll(g, jsp);
break; break;
case TYPE_JOB: case TYPE_JOB:
err = LocateObjectAll(g, MPP(jsp->To_Val)); err = LocateObjectAll(g, jsp);
break; break;
case TYPE_JVAL: case TYPE_JVAL:
err = LocateValueAll(g, MVP(jsp->To_Val)); err = LocateValueAll(g, MVP(jsp->To_Val));
@@ -957,7 +955,7 @@ my_bool BJNX::LocateArrayAll(PGLOBAL g, PBVAL jarp)
if (I < Imax) { if (I < Imax) {
Jpnp[++I].Type = TYPE_JAR; Jpnp[++I].Type = TYPE_JAR;
for (PBVAL vp = jarp; vp; vp = MVP(vp->Next)) { for (PBVAL vp = GetArray(jarp); vp; vp = GetNext(vp)) {
Jpnp[I].N = i; Jpnp[I].N = i;
if (LocateValueAll(g, GetArrayValue(jarp, i))) if (LocateValueAll(g, GetArrayValue(jarp, i)))
@@ -975,12 +973,12 @@ my_bool BJNX::LocateArrayAll(PGLOBAL g, PBVAL jarp)
/*********************************************************************************/ /*********************************************************************************/
/* Locate in a JSON Object. */ /* Locate in a JSON Object. */
/*********************************************************************************/ /*********************************************************************************/
my_bool BJNX::LocateObjectAll(PGLOBAL g, PBPR jobp) my_bool BJNX::LocateObjectAll(PGLOBAL g, PBVAL jobp)
{ {
if (I < Imax) { if (I < Imax) {
Jpnp[++I].Type = TYPE_JOB; Jpnp[++I].Type = TYPE_JOB;
for (PBPR pair = jobp; pair; pair = MPP(pair->Next)) { for (PBPR pair = GetObject(jobp); pair; pair = GetNext(pair)) {
Jpnp[I].Key = MZP(pair->Key); Jpnp[I].Key = MZP(pair->Key);
if (LocateValueAll(g, MVP(pair->Vlp))) if (LocateValueAll(g, MVP(pair->Vlp)))
@@ -1002,9 +1000,9 @@ my_bool BJNX::LocateValueAll(PGLOBAL g, PBVAL jvp)
if (CompareTree(g, Bvalp, jvp)) if (CompareTree(g, Bvalp, jvp))
return AddPath(); return AddPath();
else if (jvp->Type == TYPE_JAR) else if (jvp->Type == TYPE_JAR)
return LocateArrayAll(g, GetArray(jvp)); return LocateArrayAll(g, jvp);
else if (jvp->Type == TYPE_JOB) else if (jvp->Type == TYPE_JOB)
return LocateObjectAll(g, GetObject(jvp)); return LocateObjectAll(g, jvp);
return false; return false;
} // end of LocateValueAll } // end of LocateValueAll
@@ -1024,11 +1022,11 @@ my_bool BJNX::CompareTree(PGLOBAL g, PBVAL jp1, PBVAL jp2)
found = (CompareValues(g, GetArrayValue(jp1, i), GetArrayValue(jp2, i))); found = (CompareValues(g, GetArrayValue(jp1, i), GetArrayValue(jp2, i)));
} else if (jp1->Type == TYPE_JOB) { } else if (jp1->Type == TYPE_JOB) {
PBPR p1 = MPP(jp1->To_Val), p2 = MPP(jp2->To_Val); PBPR p1 = GetObject(jp1), p2 = GetObject(jp2);
// Keys can be differently ordered // Keys can be differently ordered
for (; found && p1 && p2; p1 = MPP(p1->Next)) for (; found && p1 && p2; p1 = MPP(p1->Next))
found = CompareValues(g, MVP(p1->Vlp), GetKeyValue(p2, MZP(p1->Key))); found = CompareValues(g, MVP(p1->Vlp), GetKeyValue(jp2, MZP(p1->Key)));
} else if (jp1->Type == TYPE_JVAL) { } else if (jp1->Type == TYPE_JVAL) {
found = CompareTree(g, MVP(jp1->To_Val), (MVP(jp2->To_Val))); found = CompareTree(g, MVP(jp1->To_Val), (MVP(jp2->To_Val)));
@@ -1048,8 +1046,9 @@ my_bool BJNX::CompareValues(PGLOBAL g, PBVAL v1, PBVAL v2)
if (v1 && v2) if (v1 && v2)
switch (v1->Type) { switch (v1->Type) {
case TYPE_JAR: case TYPE_JAR:
if (v2->Type == TYPE_JAR) case TYPE_JOB:
b = CompareTree(g, MVP(v1->To_Val), MVP(v2->To_Val)); if (v2->Type == v1->Type)
b = CompareTree(g, v1, v2);
break; break;
case TYPE_STRG: case TYPE_STRG:
@@ -1297,12 +1296,10 @@ char* bson_make_array(UDF_INIT* initid, UDF_ARGS* args, char* result,
if (!g->Xchk) { if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, false)) { if (!CheckMemory(g, initid, args, args->arg_count, false)) {
BDOC doc(g); BDOC doc(g);
PBVAL bvp = NULL, arp = NULL; PBVAL bvp = NULL, arp = doc.NewVal(TYPE_JAR);
for (uint i = 0; i < args->arg_count; i++) for (uint i = 0; i < args->arg_count; i++)
bvp = doc.AddArrayValue(bvp, MakeBinValue(g, args, i)); doc.AddArrayValue(arp, MakeBinValue(g, args, i));
arp = doc.SubAllocVal(bvp, TYPE_JAR);
if (!(str = doc.Serialize(g, arp, NULL, 0))) if (!(str = doc.Serialize(g, arp, NULL, 0)))
str = strcpy(result, g->Message); str = strcpy(result, g->Message);
@@ -1361,26 +1358,19 @@ char* bson_array_add_values(UDF_INIT* initid, UDF_ARGS* args, char* result,
if (!g->Xchk) { if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, true)) { if (!CheckMemory(g, initid, args, args->arg_count, true)) {
uint n = 1; uint i = 0;
bool b = false;
BDOC doc(g); BDOC doc(g);
PBVAL bvp = NULL, arp = MakeBinValue(g, args, 0); PBVAL arp, bvp = MakeBinValue(g, args, 0);
if (arp->Type == TYPE_JAR) { if (bvp->Type == TYPE_JAR) {
bvp = doc.GetArray(arp); arp = bvp;
b = !bvp; i = 1;
} else } else // First argument is not an array
n = 0; arp = doc.NewVal(TYPE_JAR);
for (uint i = n; i < args->arg_count; i++) for (; i < args->arg_count; i++)
bvp = doc.AddArrayValue(bvp, MakeBinValue(g, args, i)); doc.AddArrayValue(arp, MakeBinValue(g, args, i));
if (!n)
arp = doc.SubAllocVal(bvp, TYPE_JAR);
else if (b)
doc.SetValueArr(arp, bvp);
// str = MakeResult(g, args, top, args->arg_count);
str = doc.Serialize(g, arp, NULL, 0); str = doc.Serialize(g, arp, NULL, 0);
} // endif CheckMemory } // endif CheckMemory

View File

@@ -46,10 +46,10 @@ protected:
PBVAL GetRow(PGLOBAL g); PBVAL GetRow(PGLOBAL g);
my_bool CompareValues(PGLOBAL g, PBVAL v1, PBVAL v2); my_bool CompareValues(PGLOBAL g, PBVAL v1, PBVAL v2);
my_bool LocateArray(PGLOBAL g, PBVAL jarp); my_bool LocateArray(PGLOBAL g, PBVAL jarp);
my_bool LocateObject(PGLOBAL g, PBPR jobp); my_bool LocateObject(PGLOBAL g, PBVAL jobp);
my_bool LocateValue(PGLOBAL g, PBVAL jvp); my_bool LocateValue(PGLOBAL g, PBVAL jvp);
my_bool LocateArrayAll(PGLOBAL g, PBVAL jarp); my_bool LocateArrayAll(PGLOBAL g, PBVAL jarp);
my_bool LocateObjectAll(PGLOBAL g, PBPR jobp); my_bool LocateObjectAll(PGLOBAL g, PBVAL jobp);
my_bool LocateValueAll(PGLOBAL g, PBVAL jvp); my_bool LocateValueAll(PGLOBAL g, PBVAL jvp);
my_bool CompareTree(PGLOBAL g, PBVAL jp1, PBVAL jp2); my_bool CompareTree(PGLOBAL g, PBVAL jp1, PBVAL jp2);
my_bool AddPath(void); my_bool AddPath(void);

View File

@@ -170,7 +170,8 @@ bool MAPFAM::OpenTableFile(PGLOBAL g)
htrc("CreateFileMap: %s\n", g->Message); htrc("CreateFileMap: %s\n", g->Message);
return (mode == MODE_READ && rc == ENOENT) return (mode == MODE_READ && rc == ENOENT)
? PushWarning(g, Tdbp) : true; ? false : true;
// ? PushWarning(g, Tdbp) : true; --> assert fails into MariaDB
} // endif hFile } // endif hFile
/*******************************************************************/ /*******************************************************************/

View File

@@ -220,34 +220,11 @@ DllExport char *PlugDup(PGLOBAL g, const char *str);
DllExport void htrc(char const *fmt, ...); DllExport void htrc(char const *fmt, ...);
DllExport void xtrc(uint, char const* fmt, ...); DllExport void xtrc(uint, char const* fmt, ...);
DllExport uint GetTraceValue(void); DllExport uint GetTraceValue(void);
DllExport void* MakePtr(void* memp, size_t offset);
DllExport size_t MakeOff(void* memp, void* ptr);
#if defined(__cplusplus) #if defined(__cplusplus)
} // extern "C" } // extern "C"
#endif #endif
/***********************************************************************/
/* Inline routine definitions. */
/***********************************************************************/
/***********************************************************************/
/* This routine makes a pointer from an offset to a memory pointer. */
/***********************************************************************/
inline void* MakePtr(void* memp, size_t offset) {
// return ((offset == 0) ? NULL : &((char*)memp)[offset]);
return (!offset) ? NULL : (char *)memp + offset;
} /* end of MakePtr */
/***********************************************************************/
/* This routine makes an offset from a pointer new format. */
/***********************************************************************/
inline size_t MakeOff(void* memp, void* ptr) {
if (ptr) {
#if defined(_DEBUG)
assert(ptr > memp);
#endif // _DEBUG
return (size_t)((char*)ptr - (size_t)memp);
} else
return 0;
} /* end of MakeOff */
/*-------------------------- End of Global.H --------------------------*/ /*-------------------------- End of Global.H --------------------------*/

View File

@@ -20,4 +20,5 @@ mongo_c : Need MongoDB running and its C Driver installed
mongo_java_2 : Need MongoDB running and its Java Driver installed mongo_java_2 : Need MongoDB running and its Java Driver installed
mongo_java_3 : Need MongoDB running and its Java Driver installed mongo_java_3 : Need MongoDB running and its Java Driver installed
tbl_thread : Bug MDEV-9844,10179,14214 03/01/2018 OB Option THREAD removed tbl_thread : Bug MDEV-9844,10179,14214 03/01/2018 OB Option THREAD removed
bson : Development
#vcol : Different error code on different versions #vcol : Different error code on different versions

View File

@@ -607,4 +607,27 @@ char *PlugDup(PGLOBAL g, const char *str)
} // end of PlugDup } // end of PlugDup
/*--------------------- End of PLUGUTIL program -----------------------*/ /*************************************************************************/
/* This routine makes a pointer from an offset to a memory pointer. */
/*************************************************************************/
void* MakePtr(void* memp, size_t offset) {
// return ((offset == 0) ? NULL : &((char*)memp)[offset]);
return (!offset) ? NULL : (char *)memp + offset;
} /* end of MakePtr */
/*************************************************************************/
/* This routine makes an offset from a pointer new format. */
/*************************************************************************/
size_t MakeOff(void* memp, void* ptr) {
if (ptr) {
#if defined(_DEBUG) || defined(DEVELOPMENT)
if (ptr <= memp)
fprintf(stderr, "ptr %p <= memp %p", ptr, memp);
#endif // _DEBUG || DEVELOPMENT
return (size_t)((char*)ptr - (size_t)memp);
} else
return 0;
} /* end of MakeOff */
/*--------------------- End of PLUGUTIL program -----------------------*/

View File

@@ -607,7 +607,7 @@ PBVAL BTUTIL::FindRow(PGLOBAL g)
if (*objpath != '[' && !IsNum(objpath)) { // objpass is a key if (*objpath != '[' && !IsNum(objpath)) { // objpass is a key
val = (jsp->Type == TYPE_JOB) ? val = (jsp->Type == TYPE_JOB) ?
GetKeyValue(GetObject(jsp), objpath) : NULL; GetKeyValue(jsp, objpath) : NULL;
} else { } else {
if (*objpath == '[') { if (*objpath == '[') {
if (objpath[strlen(objpath) - 1] == ']') if (objpath[strlen(objpath) - 1] == ']')
@@ -648,7 +648,7 @@ PBVAL BTUTIL::MakeTopTree(PGLOBAL g, PBVAL jsp)
char* p; char* p;
char* objpath = PlugDup(g, Tp->Objname); char* objpath = PlugDup(g, Tp->Objname);
int i; int i;
PBPR objp = NULL; PBVAL objp = NULL;
PBVAL arp = NULL; PBVAL arp = NULL;
PBVAL val = NULL; PBVAL val = NULL;
@@ -799,7 +799,7 @@ PVAL BCUTIL::MakeBson(PGLOBAL g, PBVAL jsp)
return Cp->Value; return Cp->Value;
} // end of MakeJson } // end of MakeJson
/***********************************************************************/ /***********************************************************************/
/* GetColumnValue: */ /* GetColumnValue: */
/***********************************************************************/ /***********************************************************************/
PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i) PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i)
@@ -826,11 +826,11 @@ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i)
bvp = row; bvp = row;
} else } else
bvp = GetKeyValue(MPP(row->To_Val), nodes[i].Key); bvp = GetKeyValue(row, nodes[i].Key);
break; break;
case TYPE_JAR: case TYPE_JAR:
arp = MVP(row->To_Val); arp = row;
if (!nodes[i].Key) { if (!nodes[i].Key) {
if (nodes[i].Op == OP_EQ) if (nodes[i].Op == OP_EQ)
@@ -838,7 +838,7 @@ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i)
else if (nodes[i].Op == OP_EXP) else if (nodes[i].Op == OP_EXP)
return ExpandArray(g, arp, i); return ExpandArray(g, arp, i);
else else
return CalculateArray(arp, i); return CalculateArray(g, arp, i);
} else { } else {
// Unexpected array, unwrap it as [0] // Unexpected array, unwrap it as [0]
@@ -887,8 +887,8 @@ PVAL BCUTIL::ExpandArray(PGLOBAL g, PBVAL arp, int n)
throw 666; throw 666;
} // endif jvp } // endif jvp
if (n < nod - 1 && GetBson(bvp)) { if (n < nod - 1 && IsJson(bvp)) {
SetValue(&bval, GetColumnValue(g, GetBson(bvp), n + 1)); SetValue(&bval, GetColumnValue(g, bvp, n + 1));
bvp = &bval; bvp = &bval;
} // endif n } // endif n
@@ -906,75 +906,67 @@ PVAL BCUTIL::ExpandArray(PGLOBAL g, PBVAL arp, int n)
return value; return value;
} // end of ExpandArray } // end of ExpandArray
/***********************************************************************/ /***********************************************************************/
/* CalculateArray: */ /* CalculateArray: */
/***********************************************************************/ /***********************************************************************/
PVAL BCUTIL::CalculateArray(PBVAL arp, int n) PVAL BCUTIL::CalculateArray(PGLOBAL g, PBVAL arp, int n)
{ {
throw("CalculateArray NIY"); int i, ars, nv = 0, nextsame = Tp->NextSame;
#if 0
int i, ars, nv = 0, nextsame = Tjp->NextSame;
bool err; bool err;
OPVAL op = Nodes[n].Op; int nod = Cp->Nod;
PVAL val[2], vp = Nodes[n].Valp; JNODE *nodes = Cp->Nodes;
PJVAL jvrp, jvp; OPVAL op = nodes[n].Op;
JVALUE jval; PVAL val[2], vp = nodes[n].Valp, mulval = Cp->MulVal;
PBVAL jvrp, jvp;
BVAL jval;
vp->Reset(); vp->Reset();
ars = MY_MIN(Tjp->Limit, arp->size()); ars = MY_MIN(Tp->Limit, GetArraySize(arp));
xtrc(1,"CalculateArray: size=%d op=%d nextsame=%d\n", ars, op, nextsame);
if (trace(1))
htrc("CalculateArray: size=%d op=%d nextsame=%d\n",
ars, op, nextsame);
for (i = 0; i < ars; i++) { for (i = 0; i < ars; i++) {
jvrp = arp->GetArrayValue(i); jvrp = GetArrayValue(arp, i);
xtrc(1, "i=%d nv=%d\n", i, nv);
if (trace(1)) if (!IsValueNull(jvrp) || (op == OP_CNC && GetJsonNull())) do {
htrc("i=%d nv=%d\n", i, nv); if (IsValueNull(jvrp)) {
SetString(jvrp, PlugDup(G, GetJsonNull()));
if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) do {
if (jvrp->IsNull()) {
jvrp->Strp = PlugDup(g, GetJsonNull());
jvrp->DataType = TYPE_STRG;
jvp = jvrp; jvp = jvrp;
} else if (n < Nod - 1 && jvrp->GetJson()) { } else if (n < nod - 1 && IsJson(jvrp)) {
Tjp->NextSame = nextsame; Tp->NextSame = nextsame;
jval.SetValue(g, GetColumnValue(g, jvrp->GetJson(), n + 1)); SetValue(&jval, GetColumnValue(g, jvrp, n + 1));
jvp = &jval; jvp = &jval;
} else } else
jvp = jvrp; jvp = jvrp;
if (trace(1)) xtrc(1, "jvp=%s null=%d\n", GetString(jvp), IsValueNull(jvp) ? 1 : 0);
htrc("jvp=%s null=%d\n",
jvp->GetString(g), jvp->IsNull() ? 1 : 0);
if (!nv++) { if (!nv++) {
SetJsonValue(g, vp, jvp); SetJsonValue(g, vp, jvp);
continue; continue;
} else } else
SetJsonValue(g, MulVal, jvp); SetJsonValue(g, mulval, jvp);
if (!MulVal->IsNull()) { if (!mulval->IsNull()) {
switch (op) { switch (op) {
case OP_CNC: case OP_CNC:
if (Nodes[n].CncVal) { if (nodes[n].CncVal) {
val[0] = Nodes[n].CncVal; val[0] = nodes[n].CncVal;
err = vp->Compute(g, val, 1, op); err = vp->Compute(g, val, 1, op);
} // endif CncVal } // endif CncVal
val[0] = MulVal; val[0] = mulval;
err = vp->Compute(g, val, 1, op); err = vp->Compute(g, val, 1, op);
break; break;
// case OP_NUM: // case OP_NUM:
case OP_SEP: case OP_SEP:
val[0] = Nodes[n].Valp; val[0] = nodes[n].Valp;
val[1] = MulVal; val[1] = mulval;
err = vp->Compute(g, val, 2, OP_ADD); err = vp->Compute(g, val, 2, OP_ADD);
break; break;
default: default:
val[0] = Nodes[n].Valp; val[0] = nodes[n].Valp;
val[1] = MulVal; val[1] = mulval;
err = vp->Compute(g, val, 2, op); err = vp->Compute(g, val, 2, op);
} // endswitch Op } // endswitch Op
@@ -991,24 +983,23 @@ PVAL BCUTIL::CalculateArray(PBVAL arp, int n)
} // endif Null } // endif Null
} while (Tjp->NextSame > nextsame); } while (Tp->NextSame > nextsame);
} // endfor i } // endfor i
if (op == OP_SEP) { if (op == OP_SEP) {
// Calculate average // Calculate average
MulVal->SetValue(nv); mulval->SetValue(nv);
val[0] = vp; val[0] = vp;
val[1] = MulVal; val[1] = mulval;
if (vp->Compute(g, val, 2, OP_DIV)) if (vp->Compute(g, val, 2, OP_DIV))
vp->Reset(); vp->Reset();
} // endif Op } // endif Op
Tjp->NextSame = nextsame; Tp->NextSame = nextsame;
return vp; return vp;
#endif // 0
} // end of CalculateArray } // end of CalculateArray
/***********************************************************************/ /***********************************************************************/
@@ -1031,7 +1022,7 @@ PBVAL BCUTIL::GetRow(PGLOBAL g)
// Expected Array was not there, wrap the value // Expected Array was not there, wrap the value
continue; continue;
val = GetKeyValue(MPP(row->To_Val), nodes[i].Key); val = GetKeyValue(row, nodes[i].Key);
break; break;
case TYPE_JAR: case TYPE_JAR:
arp = row; arp = row;
@@ -1058,7 +1049,7 @@ PBVAL BCUTIL::GetRow(PGLOBAL g)
} // endswitch Type } // endswitch Type
if (val) { if (val) {
row = GetBson(val); row = val;
} else { } else {
// Construct missing objects // Construct missing objects
for (i++; row && i < nod; i++) { for (i++; row && i < nod; i++) {
@@ -1071,9 +1062,9 @@ PBVAL BCUTIL::GetRow(PGLOBAL g)
nwr = NewVal(TYPE_JOB); nwr = NewVal(TYPE_JOB);
if (row->Type == TYPE_JOB) { if (row->Type == TYPE_JOB) {
SetKeyValue(MPP(row->To_Val), MOF(nwr), nodes[i - 1].Key); SetKeyValue(row, MOF(nwr), nodes[i - 1].Key);
} else if (row->Type == TYPE_JAR) { } else if (row->Type == TYPE_JAR) {
AddArrayValue(MVP(row->To_Val), nwr); AddArrayValue(row, nwr);
} else { } else {
strcpy(g->Message, "Wrong type when writing new row"); strcpy(g->Message, "Wrong type when writing new row");
nwr = NULL; nwr = NULL;
@@ -1157,7 +1148,8 @@ bool BSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
/***********************************************************************/ /***********************************************************************/
/* GetTable: makes a new Table Description Block. */ /* GetTable: makes a new Table Description Block. */
/***********************************************************************/ /***********************************************************************/
PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) { PTDB BSONDEF::GetTable(PGLOBAL g, MODE m)
{
if (trace(1)) if (trace(1))
htrc("BSON GetTable Pretty=%d Uri=%s\n", Pretty, SVP(Uri)); htrc("BSON GetTable Pretty=%d Uri=%s\n", Pretty, SVP(Uri));
@@ -1169,7 +1161,6 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) {
// JSN not used for pretty=1 for insert or delete // JSN not used for pretty=1 for insert or delete
if (Pretty <= 0 || (Pretty == 1 && (m == MODE_READ || m == MODE_UPDATE))) { if (Pretty <= 0 || (Pretty == 1 && (m == MODE_READ || m == MODE_UPDATE))) {
PGLOBAL G;
USETEMP tmp = UseTemp(); USETEMP tmp = UseTemp();
bool map = Mapped && Pretty >= 0 && m != MODE_INSERT && bool map = Mapped && Pretty >= 0 && m != MODE_INSERT &&
!(tmp != TMP_NO && m == MODE_UPDATE) && !(tmp != TMP_NO && m == MODE_UPDATE) &&
@@ -1178,14 +1169,7 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) {
if (Lrecl) { if (Lrecl) {
// Allocate the parse work memory // Allocate the parse work memory
G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL)); G = PlugInit(NULL, (size_t)Lrecl * 6);
memset(G, 0, sizeof(GLOBAL));
G->Sarea_Size = (size_t)Lrecl * 6;
G->Sarea = PlugSubAlloc(g, NULL, G->Sarea_Size);
PlugSubSet(G->Sarea, G->Sarea_Size);
G->jump_level = 0;
// ((TDBBSN*)tdbp)->G = G;
// ((TDBBSN*)tdbp)->Docp = new(g) BDOC(G->Sarea);
} else { } else {
strcpy(g->Message, "LRECL is not defined"); strcpy(g->Message, "LRECL is not defined");
return NULL; return NULL;
@@ -1252,7 +1236,7 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) {
txfp = new(g) DOSFAM(this); txfp = new(g) DOSFAM(this);
// Txfp must be set for TDBBSN // Txfp must be set for TDBBSN
tdbp = new(g) TDBBSN(G, this, txfp); tdbp = new(g) TDBBSN(g, this, txfp);
} else { } else {
if (Zipped) { if (Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
@@ -1366,7 +1350,8 @@ PTDB TDBBSN::Clone(PTABS t)
/***********************************************************************/ /***********************************************************************/
/* Allocate JSN column description block. */ /* Allocate JSN column description block. */
/***********************************************************************/ /***********************************************************************/
PCOL TDBBSN::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) { PCOL TDBBSN::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
{
PBSCOL colp = new(g) BSONCOL(g, cdp, this, cprec, n); PBSCOL colp = new(g) BSONCOL(g, cdp, this, cprec, n);
return (colp->ParseJpath(g)) ? NULL : colp; return (colp->ParseJpath(g)) ? NULL : colp;
@@ -1375,7 +1360,8 @@ PCOL TDBBSN::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) {
/***********************************************************************/ /***********************************************************************/
/* InsertSpecialColumn: Put a special column ahead of the column list.*/ /* InsertSpecialColumn: Put a special column ahead of the column list.*/
/***********************************************************************/ /***********************************************************************/
PCOL TDBBSN::InsertSpecialColumn(PCOL colp) { PCOL TDBBSN::InsertSpecialColumn(PCOL colp)
{
if (!colp->IsSpecial()) if (!colp->IsSpecial())
return NULL; return NULL;
@@ -1390,7 +1376,8 @@ PCOL TDBBSN::InsertSpecialColumn(PCOL colp) {
/***********************************************************************/ /***********************************************************************/
/* JSON Cardinality: returns table size in number of rows. */ /* JSON Cardinality: returns table size in number of rows. */
/***********************************************************************/ /***********************************************************************/
int TDBBSN::Cardinality(PGLOBAL g) { int TDBBSN::Cardinality(PGLOBAL g)
{
if (!g) if (!g)
return 0; return 0;
else if (Cardinal < 0) { else if (Cardinal < 0) {
@@ -1404,7 +1391,8 @@ int TDBBSN::Cardinality(PGLOBAL g) {
/***********************************************************************/ /***********************************************************************/
/* JSON GetMaxSize: returns file size estimate in number of lines. */ /* JSON GetMaxSize: returns file size estimate in number of lines. */
/***********************************************************************/ /***********************************************************************/
int TDBBSN::GetMaxSize(PGLOBAL g) { int TDBBSN::GetMaxSize(PGLOBAL g)
{
if (MaxSize < 0) if (MaxSize < 0)
MaxSize = TDBDOS::GetMaxSize(g) * ((Xcol) ? Limit : 1); MaxSize = TDBDOS::GetMaxSize(g) * ((Xcol) ? Limit : 1);
@@ -1414,7 +1402,8 @@ int TDBBSN::GetMaxSize(PGLOBAL g) {
/***********************************************************************/ /***********************************************************************/
/* JSON EstimatedLength. Returns an estimated minimum line length. */ /* JSON EstimatedLength. Returns an estimated minimum line length. */
/***********************************************************************/ /***********************************************************************/
int TDBBSN::EstimatedLength(void) { int TDBBSN::EstimatedLength(void)
{
if (AvgLen <= 0) if (AvgLen <= 0)
return (Lrecl ? Lrecl : 1024) / 8; // TODO: make it better return (Lrecl ? Lrecl : 1024) / 8; // TODO: make it better
else else
@@ -1425,7 +1414,8 @@ int TDBBSN::EstimatedLength(void) {
/***********************************************************************/ /***********************************************************************/
/* OpenDB: Data Base open routine for JSN access method. */ /* OpenDB: Data Base open routine for JSN access method. */
/***********************************************************************/ /***********************************************************************/
bool TDBBSN::OpenDB(PGLOBAL g) { bool TDBBSN::OpenDB(PGLOBAL g)
{
if (Use == USE_OPEN) { if (Use == USE_OPEN) {
/*******************************************************************/ /*******************************************************************/
/* Table already open replace it at its beginning. */ /* Table already open replace it at its beginning. */
@@ -1437,13 +1427,11 @@ bool TDBBSN::OpenDB(PGLOBAL g) {
/*******************************************************************/ /*******************************************************************/
/* First opening. */ /* First opening. */
/*******************************************************************/ /*******************************************************************/
// Docp = new(g) BDOC(g->Sarea);
if (Mode == MODE_INSERT) if (Mode == MODE_INSERT)
switch (Jmode) { switch (Jmode) {
// case MODE_OBJECT: Row = new(g) JOBJECT; break; case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break;
// case MODE_ARRAY: Row = new(g) JARRAY; break; case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break;
// case MODE_VALUE: Row = new(g) JVALUE; break; case MODE_VALUE: Row = Bp->NewVal(TYPE_JVAL); break;
default: default:
sprintf(g->Message, "Invalid Jmode %d", Jmode); sprintf(g->Message, "Invalid Jmode %d", Jmode);
return true; return true;
@@ -1507,7 +1495,8 @@ bool TDBBSN::OpenDB(PGLOBAL g) {
/* This is called from TDBDOS::OpenDB and must be executed before */ /* This is called from TDBDOS::OpenDB and must be executed before */
/* Kindex construction if the file is accessed using an index. */ /* Kindex construction if the file is accessed using an index. */
/***********************************************************************/ /***********************************************************************/
bool TDBBSN::SkipHeader(PGLOBAL g) { bool TDBBSN::SkipHeader(PGLOBAL g)
{
int len = GetFileLength(g); int len = GetFileLength(g);
bool rc = false; bool rc = false;
@@ -1531,7 +1520,8 @@ bool TDBBSN::SkipHeader(PGLOBAL g) {
/***********************************************************************/ /***********************************************************************/
/* ReadDB: Data Base read routine for JSN access method. */ /* ReadDB: Data Base read routine for JSN access method. */
/***********************************************************************/ /***********************************************************************/
int TDBBSN::ReadDB(PGLOBAL g) { int TDBBSN::ReadDB(PGLOBAL g)
{
int rc; int rc;
N++; N++;
@@ -1589,7 +1579,8 @@ int TDBBSN::ReadDB(PGLOBAL g) {
/***********************************************************************/ /***********************************************************************/
/* PrepareWriting: Prepare the line for WriteDB. */ /* PrepareWriting: Prepare the line for WriteDB. */
/***********************************************************************/ /***********************************************************************/
bool TDBBSN::PrepareWriting(PGLOBAL g) { bool TDBBSN::PrepareWriting(PGLOBAL g)
{
PSZ s; PSZ s;
if (!(Top = Bp->MakeTopTree(g, Row))) if (!(Top = Bp->MakeTopTree(g, Row)))
@@ -1629,10 +1620,10 @@ int TDBBSN::WriteDB(PGLOBAL g) {
void TDBBSN::CloseDB(PGLOBAL g) void TDBBSN::CloseDB(PGLOBAL g)
{ {
TDBDOS::CloseDB(g); TDBDOS::CloseDB(g);
((PBDEF)To_Def)->G = PlugExit(((PBDEF)To_Def)->G); Bp->G = PlugExit(Bp->G);
} // end of CloseDB } // end of CloseDB
/* ---------------------------- BSONCOL ------------------------------ */ /* ---------------------------- BSONCOL ------------------------------ */
/***********************************************************************/ /***********************************************************************/
/* BSONCOL public constructor. */ /* BSONCOL public constructor. */
@@ -1689,7 +1680,8 @@ bool BSONCOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check)
/***********************************************************************/ /***********************************************************************/
/* Check whether this object is expanded. */ /* Check whether this object is expanded. */
/***********************************************************************/ /***********************************************************************/
bool BSONCOL::CheckExpand(PGLOBAL g, int i, PSZ nm, bool b) { bool BSONCOL::CheckExpand(PGLOBAL g, int i, PSZ nm, bool b)
{
if ((Tbp->Xcol && nm && !strcmp(nm, Tbp->Xcol) && if ((Tbp->Xcol && nm && !strcmp(nm, Tbp->Xcol) &&
(Tbp->Xval < 0 || Tbp->Xval == i)) || Xpd) { (Tbp->Xval < 0 || Tbp->Xval == i)) || Xpd) {
Xpd = true; // Expandable object Xpd = true; // Expandable object
@@ -1705,7 +1697,8 @@ bool BSONCOL::CheckExpand(PGLOBAL g, int i, PSZ nm, bool b) {
/***********************************************************************/ /***********************************************************************/
/* Analyse array processing options. */ /* Analyse array processing options. */
/***********************************************************************/ /***********************************************************************/
bool BSONCOL::SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm) { bool BSONCOL::SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm)
{
int n; int n;
bool dg = true, b = false; bool dg = true, b = false;
PJNODE jnp = &Nodes[i]; PJNODE jnp = &Nodes[i];
@@ -1838,7 +1831,8 @@ bool BSONCOL::SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm) {
/* when creating the table. It permits to indicate the position of */ /* when creating the table. It permits to indicate the position of */
/* the node corresponding to that column. */ /* the node corresponding to that column. */
/***********************************************************************/ /***********************************************************************/
bool BSONCOL::ParseJpath(PGLOBAL g) { bool BSONCOL::ParseJpath(PGLOBAL g)
{
char* p, * p1 = NULL, * p2 = NULL, * pbuf = NULL; char* p, * p1 = NULL, * p2 = NULL, * pbuf = NULL;
int i; int i;
bool a; bool a;
@@ -1925,7 +1919,8 @@ fin:
/***********************************************************************/ /***********************************************************************/
/* Get Jpath converted to Mongo path. */ /* Get Jpath converted to Mongo path. */
/***********************************************************************/ /***********************************************************************/
PSZ BSONCOL::GetJpath(PGLOBAL g, bool proj) { PSZ BSONCOL::GetJpath(PGLOBAL g, bool proj)
{
if (Jpath) { if (Jpath) {
char* p1, * p2, * mgopath; char* p1, * p2, * mgopath;
int i = 0; int i = 0;
@@ -1989,36 +1984,11 @@ PSZ BSONCOL::GetJpath(PGLOBAL g, bool proj) {
} // end of GetJpath } // end of GetJpath
/***********************************************************************/
/* MakeJson: Serialize the json item and set value to it. */
/***********************************************************************/
PVAL BSONCOL::MakeBson(PGLOBAL g, PBVAL jsp) {
if (Value->IsTypeNum()) {
strcpy(g->Message, "Cannot make Json for a numeric column");
Value->Reset();
#if 0
} else if (Value->GetType() == TYPE_BIN) {
if ((unsigned)Value->GetClen() >= sizeof(BSON)) {
ulong len = Tjp->Lrecl ? Tjp->Lrecl : 500;
PBSON bsp = JbinAlloc(g, NULL, len, jsp);
strcat(bsp->Msg, " column");
((BINVAL*)Value)->SetBinValue(bsp, sizeof(BSON));
} else {
strcpy(g->Message, "Column size too small");
Value->SetValue_char(NULL, 0);
} // endif Clen
#endif 0
} else
Value->SetValue_psz(Cp->SerialVal(g, jsp, 0));
return Value;
} // end of MakeJson
/***********************************************************************/ /***********************************************************************/
/* ReadColumn: */ /* ReadColumn: */
/***********************************************************************/ /***********************************************************************/
void BSONCOL::ReadColumn(PGLOBAL g) { void BSONCOL::ReadColumn(PGLOBAL g)
{
if (!Tbp->SameRow || Xnod >= Tbp->SameRow) if (!Tbp->SameRow || Xnod >= Tbp->SameRow)
Value->SetValue_pval(Cp->GetColumnValue(g, Tbp->Row, 0)); Value->SetValue_pval(Cp->GetColumnValue(g, Tbp->Row, 0));
@@ -2034,7 +2004,8 @@ void BSONCOL::ReadColumn(PGLOBAL g) {
/***********************************************************************/ /***********************************************************************/
/* WriteColumn: */ /* WriteColumn: */
/***********************************************************************/ /***********************************************************************/
void BSONCOL::WriteColumn(PGLOBAL g) { void BSONCOL::WriteColumn(PGLOBAL g)
{
if (Xpd && Tbp->Pretty < 2) { if (Xpd && Tbp->Pretty < 2) {
strcpy(g->Message, "Cannot write expanded column when Pretty is not 2"); strcpy(g->Message, "Cannot write expanded column when Pretty is not 2");
throw 666; throw 666;
@@ -2052,75 +2023,48 @@ void BSONCOL::WriteColumn(PGLOBAL g) {
if (Value->IsNull() && Tbp->Mode == MODE_INSERT) if (Value->IsNull() && Tbp->Mode == MODE_INSERT)
return; return;
throw "Write BSON NIY"; PBVAL jsp, row = Cp->GetRow(g);
#if 0
char* s;
PBPR objp = NULL;
PBVAL arp = NULL;
PBVAL jvp = NULL;
PBVAL jsp, row = Cp->GetRow();
switch (row->Type) {
case TYPE_JOB: objp = (PJOB)row; break;
case TYPE_JAR: arp = (PJAR)row; break;
case TYPE_JVAL: jvp = (PJVAL)row; break;
default: row = NULL; // ???????????????????????????
} // endswitch Type
if (row) switch (Buf_Type) { if (row) switch (Buf_Type) {
case TYPE_STRING: case TYPE_STRING:
if (Nodes[Nod - 1].Op == OP_XX) {
s = Value->GetCharValue();
if (!(jsp = ParseJson(G, s, strlen(s)))) {
strcpy(g->Message, s);
throw 666;
} // endif jsp
if (arp) {
if (Nod > 1 && Nodes[Nod - 2].Op == OP_EQ)
arp->SetArrayValue(G, new(G) JVALUE(jsp), Nodes[Nod - 2].Rank);
else
arp->AddArrayValue(G, new(G) JVALUE(jsp));
arp->InitArray(G);
} else if (objp) {
if (Nod > 1 && Nodes[Nod - 2].Key)
objp->SetKeyValue(G, new(G) JVALUE(jsp), Nodes[Nod - 2].Key);
} else if (jvp)
jvp->SetValue(jsp);
break;
} // endif Op
// fall through
case TYPE_DATE: case TYPE_DATE:
case TYPE_INT: case TYPE_INT:
case TYPE_TINY: case TYPE_TINY:
case TYPE_SHORT: case TYPE_SHORT:
case TYPE_BIGINT: case TYPE_BIGINT:
case TYPE_DOUBLE: case TYPE_DOUBLE:
if (arp) { if (Buf_Type == TYPE_STRING && Nodes[Nod - 1].Op == OP_XX) {
char *s = Value->GetCharValue();
if (!(jsp = Cp->ParseJson(g, s, strlen(s)))) {
strcpy(g->Message, s);
throw 666;
} // endif jsp
} else
jsp = Cp->NewVal(Value);
switch (row->Type) {
case TYPE_JAR:
if (Nodes[Nod - 1].Op == OP_EQ) if (Nodes[Nod - 1].Op == OP_EQ)
arp->SetArrayValue(G, new(G) JVALUE(G, Value), Nodes[Nod - 1].Rank); Cp->SetArrayValue(row, jsp, Nodes[Nod - 1].Rank);
else else
arp->AddArrayValue(G, new(G) JVALUE(G, Value)); Cp->AddArrayValue(row, jsp);
arp->InitArray(G); case TYPE_JOB:
} else if (objp) {
if (Nodes[Nod - 1].Key) if (Nodes[Nod - 1].Key)
objp->SetKeyValue(G, new(G) JVALUE(G, Value), Nodes[Nod - 1].Key); Cp->SetKeyValue(row, jsp, Nodes[Nod - 1].Key);
} else if (jvp) break;
jvp->SetValue(g, Value); case TYPE_JVAL:
default:
Cp->SetValueVal(row, jsp);
} // endswitch Type
break; break;
default: // ?????????? default: // ??????????
sprintf(g->Message, "Invalid column type %d", Buf_Type); sprintf(g->Message, "Invalid column type %d", Buf_Type);
} // endswitch Type } // endswitch Type
#endif // 0
} // end of WriteColumn } // end of WriteColumn
@@ -2169,7 +2113,7 @@ int TDBBSON::MakeNewDoc(PGLOBAL g)
// Create a void table that will be populated // Create a void table that will be populated
Docp = Bp->NewVal(TYPE_JAR); Docp = Bp->NewVal(TYPE_JAR);
if (Bp->MakeTopTree(g, Docp)) if (!(Top = Bp->MakeTopTree(g, Docp)))
return RC_FX; return RC_FX;
Done = true; Done = true;
@@ -2187,7 +2131,7 @@ int TDBBSON::MakeDocument(PGLOBAL g)
my_bool a; my_bool a;
MODE mode = Mode; MODE mode = Mode;
PBVAL jsp; PBVAL jsp;
PBPR objp = NULL; PBVAL objp = NULL;
PBVAL arp = NULL; PBVAL arp = NULL;
PBVAL val = NULL; PBVAL val = NULL;
@@ -2260,7 +2204,7 @@ int TDBBSON::MakeDocument(PGLOBAL g)
} // endif Type } // endif Type
key = p; key = p;
objp = Bp->GetObject(jsp); objp = jsp;
arp = NULL; arp = NULL;
val = Bp->GetKeyValue(objp, key); val = Bp->GetKeyValue(objp, key);
@@ -2285,7 +2229,7 @@ int TDBBSON::MakeDocument(PGLOBAL g)
return RC_FX; return RC_FX;
} // endif Type } // endif Type
arp = Bp->GetArray(jsp); arp = jsp;
objp = NULL; objp = NULL;
i = atoi(p) - B; i = atoi(p) - B;
val = Bp->GetArrayValue(arp, i); val = Bp->GetArrayValue(arp, i);
@@ -2449,9 +2393,9 @@ bool TDBBSON::OpenDB(PGLOBAL g)
if (Mode == MODE_INSERT) if (Mode == MODE_INSERT)
switch (Jmode) { switch (Jmode) {
case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break; case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break;
case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break; case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break;
case MODE_VALUE: Row = Bp->NewVal(); break; case MODE_VALUE: Row = Bp->NewVal(TYPE_JVAL); break;
default: default:
sprintf(g->Message, "Invalid Jmode %d", Jmode); sprintf(g->Message, "Invalid Jmode %d", Jmode);
return true; return true;
@@ -2479,7 +2423,7 @@ int TDBBSON::ReadDB(PGLOBAL)
M++; M++;
rc = RC_OK; rc = RC_OK;
} else if (++Fpos < (signed)Bp->GetSize(Docp)) { } else if (++Fpos < (signed)Bp->GetSize(Docp)) {
Row = Bp->GetArrayValue(Bp->GetBson(Docp), Fpos); Row = Bp->GetArrayValue(Docp, Fpos);
if (Row->Type == TYPE_JVAL) if (Row->Type == TYPE_JVAL)
Row = Bp->GetBson(Row); Row = Bp->GetBson(Row);
@@ -2498,32 +2442,17 @@ int TDBBSON::ReadDB(PGLOBAL)
/***********************************************************************/ /***********************************************************************/
int TDBBSON::WriteDB(PGLOBAL g) int TDBBSON::WriteDB(PGLOBAL g)
{ {
if (Jmode == MODE_OBJECT) { if (Mode == MODE_INSERT) {
PBVAL vp = Bp->DupVal(Row); Bp->AddArrayValue(Docp, Row);
if (Mode == MODE_INSERT) { switch(Jmode) {
Bp->AddArrayValue(Docp, vp); case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break;
Row = Bp->NewVal(TYPE_JOB); case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break;
} else if (Bp->SetArrayValue(Docp, vp, Fpos)) default: Row = Bp->NewVal(); break;
return RC_FX; } // endswitch Jmode
} else if (Jmode == MODE_ARRAY) { } else
PBVAL vp = Bp->DupVal(Row); Bp->SetArrayValue(Docp, Row, Fpos);
if (Mode == MODE_INSERT) {
Bp->AddArrayValue(Docp, vp);
Row = Bp->NewVal(TYPE_JAR);
} else if (Bp->SetArrayValue(Docp, vp, Fpos))
return RC_FX;
} else { // if (Jmode == MODE_VALUE)
if (Mode == MODE_INSERT) {
Bp->AddArrayValue(Docp, Row);
Row = Bp->NewVal();
} else if (Bp->SetArrayValue(Docp, Row, Fpos))
return RC_FX;
} // endif Jmode
Changed = true; Changed = true;
return RC_OK; return RC_OK;
@@ -2534,26 +2463,15 @@ int TDBBSON::WriteDB(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
int TDBBSON::DeleteDB(PGLOBAL g, int irc) int TDBBSON::DeleteDB(PGLOBAL g, int irc)
{ {
strcpy(g->Message, "BSON Delete NIY"); if (irc == RC_OK)
return RC_FX;
#if 0
if (irc == RC_OK) {
// Deleted current row // Deleted current row
if (Doc->DeleteValue(Fpos)) { Bp->DeleteValue(Docp, Fpos);
sprintf(g->Message, "Value %d does not exist", Fpos + 1); else if (irc == RC_FX)
return RC_FX;
} // endif Delete
Changed = true;
} else if (irc == RC_FX)
// Delete all // Delete all
for (int i = 0; i < Doc->size(); i++) { Docp->To_Val = 0;
Doc->DeleteValue(i);
Changed = true;
} // endfor i
Changed = true;
return RC_OK; return RC_OK;
#endif // 0
} // end of DeleteDB } // end of DeleteDB
/***********************************************************************/ /***********************************************************************/

View File

@@ -134,7 +134,7 @@ public:
PVAL MakeBson(PGLOBAL g, PBVAL jsp); PVAL MakeBson(PGLOBAL g, PBVAL jsp);
PVAL GetColumnValue(PGLOBAL g, PBVAL row, int i); PVAL GetColumnValue(PGLOBAL g, PBVAL row, int i);
PVAL ExpandArray(PGLOBAL g, PBVAL arp, int n); PVAL ExpandArray(PGLOBAL g, PBVAL arp, int n);
PVAL CalculateArray(PBVAL arp, int n); PVAL CalculateArray(PGLOBAL g, PBVAL arp, int n);
PBVAL GetRow(PGLOBAL g); PBVAL GetRow(PGLOBAL g);
protected: protected:
@@ -243,7 +243,7 @@ public:
// Methods // Methods
virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
bool ParseJpath(PGLOBAL g); bool ParseJpath(PGLOBAL g);
virtual PSZ GetJpath(PGLOBAL g, bool proj); virtual PSZ GetJpath(PGLOBAL g, bool proj);
virtual void ReadColumn(PGLOBAL g); virtual void ReadColumn(PGLOBAL g);
virtual void WriteColumn(PGLOBAL g); virtual void WriteColumn(PGLOBAL g);
@@ -251,12 +251,6 @@ public:
protected: protected:
bool CheckExpand(PGLOBAL g, int i, PSZ nm, bool b); bool CheckExpand(PGLOBAL g, int i, PSZ nm, bool b);
bool SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm); bool SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm);
//PVAL GetColumnValue(PGLOBAL g, PBVAL row, int i);
//PVAL ExpandArray(PGLOBAL g, PBVAL arp, int n);
//PVAL CalculateArray(PGLOBAL g, PBVAL arp, int n);
PVAL MakeBson(PGLOBAL g, PBVAL jsp);
//void SetJsonValue(PGLOBAL g, PVAL vp, PBVAL val);
//PBVAL GetRow(PGLOBAL g);
// Default constructor not to be used // Default constructor not to be used
BSONCOL(void) {} BSONCOL(void) {}