diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2020-12-04 23:21:59 +0100 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2020-12-04 23:21:59 +0100 |
commit | c05b1288fd86c98d9b13724d6b115b35c77ca15a (patch) | |
tree | cfddcd8caf3498ffbc93da831c65b94f1bcfd95d | |
parent | 4b6d661c7f4bcf9f0f5a9f5d5f4a6743983fc9a5 (diff) | |
download | mariadb-git-c05b1288fd86c98d9b13724d6b115b35c77ca15a.tar.gz |
Remove a push warning causing failing assert. Modified storage/connect/filamap.cpp
-rw-r--r-- | storage/connect/bson.cpp | 386 | ||||
-rw-r--r-- | storage/connect/bson.h | 62 | ||||
-rw-r--r-- | storage/connect/bsonudf.cpp | 106 | ||||
-rw-r--r-- | storage/connect/bsonudf.h | 4 | ||||
-rw-r--r-- | storage/connect/filamap.cpp | 3 | ||||
-rw-r--r-- | storage/connect/global.h | 27 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/disabled.def | 1 | ||||
-rw-r--r-- | storage/connect/plugutil.cpp | 25 | ||||
-rw-r--r-- | storage/connect/tabbson.cpp | 346 | ||||
-rw-r--r-- | storage/connect/tabbson.h | 10 |
10 files changed, 400 insertions, 570 deletions
diff --git a/storage/connect/bson.cpp b/storage/connect/bson.cpp index e395bd8988d..b4ce7ec1505 100644 --- a/storage/connect/bson.cpp +++ b/storage/connect/bson.cpp @@ -21,6 +21,15 @@ #include "plgdbsem.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__) #define EL "\r\n" #else @@ -859,13 +868,14 @@ PBPR BJSON::SubAllocPair(OFFSET key, OFFSET val) /***********************************************************************/ /* 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; - 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 || (brp->Vlp && (MVP(brp->Vlp))->Type != TYPE_NULL)) + if (!b || (brp->Vlp && GetVal(brp)->Type != TYPE_NULL)) n++; return n; @@ -874,64 +884,60 @@ int BJSON::GetObjectSize(PBPR bop, bool b) /***********************************************************************/ /* 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) { - for (brp = bop; brp->Next; brp = MPP(brp->Next)); + if (bop->To_Val) { + for (brp = GetObject(bop); brp->Next; brp = GetNext(brp)); - brp->Next = MOF(nrp); + brp->Next = nrp; } else - bop = nrp; + bop->To_Val = nrp; - return bop; + bop->Nd++; } // end of AddPair /***********************************************************************/ /* 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)) - if (fvp) { - bvp = SubAllocVal(brp->Key, TYPE_STRG); - lvp->Next = MOF(bvp); - lvp = bvp; - } else - lvp = fvp = SubAllocVal(brp->Key, TYPE_STRG); + for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp)) + AddArrayValue(arp, MOF(SubAllocVal(brp->Key, TYPE_STRG))); - return fvp; + return arp; } // end of GetKeyList /***********************************************************************/ /* 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)) - if (fvp) { - bvp = DupVal(MVP(brp->Vlp)); - lvp->Next = MOF(bvp); - lvp = bvp; - } else - lvp = fvp = DupVal(MVP(brp->Vlp)); + for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp)) + AddArrayValue(arp, brp->Vlp); - return fvp; + return arp; } // end of GetObjectValList /***********************************************************************/ /* 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)) - if (!strcmp(MZP(brp->Key), key)) - return MVP(brp->Vlp); + CheckType(bop, TYPE_JOB); + + for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp)) + if (!strcmp(GetKey(brp), key)) + return GetVal(brp); return NULL; } // end of GetKeyValue; @@ -939,8 +945,11 @@ PBVAL BJSON::GetKeyValue(PBPR bop, PSZ key) /***********************************************************************/ /* Return the text corresponding to all keys (XML like). */ /***********************************************************************/ -PSZ BJSON::GetObjectText(PGLOBAL g, PBPR bop, PSTRG text) { - if (bop) { +PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text) +{ + CheckType(bop, TYPE_JOB); + + if (bop->To_Val) { bool b; if (!text) { @@ -977,8 +986,8 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBPR bop, PSTRG text) { } else #endif // 0 - for (PBPR brp = bop; brp; brp = MPP(brp->Next)) { - GetValueText(g, MVP(brp->Vlp), text); + for (PBPR brp = GetObject(bop); brp; brp = GetNext(brp)) { + GetValueText(g, GetVal(brp), text); if (brp->Next) 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. */ /***********************************************************************/ -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) { - for (brp = bop; brp; brp = MPP(brp->Next)) - if (!strcmp(MZP(brp->Key), key)) { + if (bop->To_Val) { + for (brp = GetObject(bop); brp; brp = GetNext(brp)) + if (!strcmp(GetKey(brp), key)) { brp->Vlp = bvp; - break; + return; } else prp = brp; if (!brp) - prp->Vlp = MOF(SubAllocPair(key, bvp)); + prp->Next = MOF(SubAllocPair(key, bvp)); } else - bop = SubAllocPair(key, bvp); + bop->To_Val = MOF(SubAllocPair(key, bvp)); - // Return the first pair of this object - return bop; + bop->Nd++; } // end of SetKeyValue /***********************************************************************/ /* Merge two objects. */ /***********************************************************************/ -PBPR BJSON::MergeObject(PBPR bop1, PBPR bop2) +PBVAL BJSON::MergeObject(PBVAL bop1, PBVAL bop2) { - if (bop1) - for (PBPR brp = bop2; brp; brp = MPP(brp->Next)) - SetKeyValue(bop1, brp->Vlp, MZP(brp->Key)); + CheckType(bop1, TYPE_JOB); + CheckType(bop2, TYPE_JOB); + + if (bop1->To_Val) + for (PBPR brp = GetObject(bop2); brp; brp = GetNext(brp)) + SetKeyValue(bop1, brp->Vlp, GetKey(brp)); - else - bop1 = bop2; + else { + bop1->To_Val = bop2->To_Val; + bop1->Nd = bop2->Nd; + } // endelse To_Val return bop1; } // end of MergeObject; @@ -1038,30 +1052,33 @@ PBPR BJSON::MergeObject(PBPR bop1, PBPR bop2) /***********************************************************************/ /* 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; - for (brp = bop; brp; brp = MPP(brp->Next)) + for (brp = GetObject(bop); brp; brp = GetNext(brp)) if (!strcmp(MZP(brp->Key), key)) { if (pbrp) { pbrp->Next = brp->Next; - return bop; } else - return MPP(brp->Next); + bop->To_Val = brp->Next; + bop->Nd--; + break; } else pbrp = brp; - return bop; } // end of DeleteKey /***********************************************************************/ /* 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) return false; @@ -1075,9 +1092,10 @@ bool BJSON::IsObjectNull(PBPR bop) /***********************************************************************/ int BJSON::GetArraySize(PBVAL bap, bool b) { + CheckType(bap, TYPE_JAR); 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 || bvp->Type != TYPE_NULL) n++; @@ -1090,13 +1108,12 @@ int BJSON::GetArraySize(PBVAL bap, bool b) /***********************************************************************/ PBVAL BJSON::GetArrayValue(PBVAL bap, int n) { + CheckType(bap, TYPE_JAR); 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) return bvp; - else - i++; return NULL; } // end of GetArrayValue @@ -1104,80 +1121,78 @@ PBVAL BJSON::GetArrayValue(PBVAL bap, int n) /***********************************************************************/ /* 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) - nvp = NewVal(); + nvp = MOF(NewVal()); - if (bap) { + if (bap->To_Val) { 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)) { - nvp->Next = bvp->Next; - bvp->Next = MOF(nvp); + MVP(nvp)->Next = bvp->Next; + bvp->Next = nvp; break; } // endif Next } else - bap = nvp; + bap->To_Val = nvp; - return bap; + bap->Nd++; } // end of AddArrayValue /***********************************************************************/ /* Merge two arrays. */ /***********************************************************************/ -PBVAL BJSON::MergeArray(PBVAL bap1, PBVAL bap2) +void BJSON::MergeArray(PBVAL bap1, PBVAL bap2) { - if (bap1) { - for (PBVAL bvp = bap2; bvp; bvp = MVP(bvp->Next)) - AddArrayValue(bap1, bvp); + CheckType(bap1, TYPE_JAR); + CheckType(bap2, TYPE_JAR); - return bap1; - } else - return bap2; + if (bap1->To_Val) { + for (PBVAL bvp = GetArray(bap2); bvp; bvp = GetNext(bvp)) + AddArrayValue(bap1, MOF(DupVal(bvp))); + + } else { + bap1->To_Val = bap2->To_Val; + bap1->Nd = bap2->Nd; + } // endif To_Val } // 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) { - for (int i = 0; bvp; i++, bvp = MVP(bvp->Next)) + if (bap->To_Val) { + for (int i = 0; bvp = GetArray(bap); i++, bvp = GetNext(bvp)) if (i == n) { - bvp->To_Val = nvp->To_Val; - bvp->Nd = nvp->Nd; - bvp->Type = nvp->Type; - return bap; + SetValueVal(bvp, nvp); + return; } else pvp = bvp; } // endif bap - if (!bvp) { - bvp = DupVal(nvp); - - if (pvp) - pvp->Next = MOF(bvp); - else - bap = bvp; - - } // endif bvp + if (!bvp) + AddArrayValue(bap, MOF(nvp)); - return bap; } // end of SetValue /***********************************************************************/ /* Return the text corresponding to all values. */ /***********************************************************************/ -PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text) { - if (bap) { +PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text) +{ + CheckType(bap, TYPE_JAR); + + if (bap->To_Val) { bool b; if (!text) { @@ -1192,7 +1207,7 @@ PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text) { b = false; } // endif text - for (PBVAL bvp = bap; bvp; bvp = MVP(bvp->Next)) { + for (PBVAL bvp = GetArray(bap); bvp; bvp = GetNext(bvp)) { GetValueText(g, bvp, text); if (bvp->Next) @@ -1200,14 +1215,14 @@ PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text) { else if (!b) text->Append(')'); - } // endfor jp + } // endfor bvp if (b) { text->Trim(); return text->GetStr(); } // endif b - } // endif First + } // endif To_Val return NULL; } // end of GetText; @@ -1215,22 +1230,23 @@ PSZ BJSON::GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text) { /***********************************************************************/ /* 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 (int i = 0; bvp; i++, bvp = MVP(bvp->Next)) + for (bvp = GetArray(bap); bvp; i++, bvp = GetNext(bvp)) if (i == n) { if (pvp) pvp->Next = bvp->Next; else - bap = bvp; + bap->To_Val = bvp->Next; + bap->Nd--; break; } // endif i - return bap; } // end of DeleteValue /***********************************************************************/ @@ -1238,7 +1254,9 @@ PBVAL BJSON::DeleteValue(PBVAL bap, int n) /***********************************************************************/ 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) return false; @@ -1288,9 +1306,10 @@ PBVAL BJSON::SubAllocStr(OFFSET toval, short nd) /***********************************************************************/ /* Allocate a BVALUE with a given string or numeric value. */ /***********************************************************************/ -PBVAL BJSON::SubAllocVal(PVAL valp) +PBVAL BJSON::NewVal(PVAL valp) { PBVAL vlp = NewVal(); + SetValue(vlp, valp); return vlp; } // end of SubAllocVal @@ -1306,90 +1325,6 @@ PBVAL BJSON::DupVal(PBVAL bvlp) { return bvp; } // 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. */ /***********************************************************************/ @@ -1397,9 +1332,9 @@ int BJSON::GetSize(PBVAL vlp, bool b) { switch (vlp->Type) { case TYPE_JAR: - return GetArraySize(MVP(vlp->To_Val)); + return GetArraySize(vlp); case TYPE_JOB: - return GetObjectSize(MPP(vlp->To_Val)); + return GetObjectSize(vlp); default: return 1; } // enswitch Type @@ -1407,28 +1342,6 @@ int BJSON::GetSize(PBVAL vlp, bool b) } // 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. */ /***********************************************************************/ PVAL BJSON::GetValue(PGLOBAL g, PBVAL vp) @@ -1604,11 +1517,12 @@ PSZ BJSON::GetString(PBVAL vp, char* buff) /***********************************************************************/ /* 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) - return GetObjectText(g, MPP(vlp->To_Val), text); + return GetObjectText(g, vlp, text); else if (vlp->Type == TYPE_JAR) - return GetArrayText(g, MVP(vlp->To_Val), text); + return GetArrayText(g, vlp, text); char buff[32]; 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; } // 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; } // end of SetValueObj; 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; } // end of SetValue; @@ -1640,14 +1558,17 @@ void BJSON::SetValueVal(PBVAL vlp, PBVAL vp) vlp->Type = vp->Type; } // 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()) { vlp->Type = TYPE_NULL; } else switch (valp->GetType()) { case TYPE_DATE: if (((DTVAL*)valp)->IsFormatted()) - vlp->To_Val = MOF(valp->GetCharValue()); + vlp->To_Val = MOF(PlugDup(G, valp->GetCharValue())); else { char buf[32]; @@ -1657,7 +1578,7 @@ void BJSON::SetValue(PBVAL vlp, PVAL valp) vlp->Type = TYPE_DTM; break; case TYPE_STRING: - vlp->To_Val = MOF(valp->GetCharValue()); + vlp->To_Val = MOF(PlugDup(G, valp->GetCharValue())); vlp->Type = TYPE_STRG; break; case TYPE_DOUBLE: @@ -1702,6 +1623,7 @@ void BJSON::SetValue(PBVAL vlp, PVAL valp) throw(777); } // endswitch Type + return vlp; } // end of SetValue /***********************************************************************/ @@ -1769,10 +1691,10 @@ bool BJSON::IsValueNull(PBVAL vlp) { b = true; break; case TYPE_JOB: - b = IsObjectNull(MPP(vlp->To_Val)); + b = IsObjectNull(vlp); break; case TYPE_JAR: - b = IsArrayNull(MVP(vlp->To_Val)); + b = IsArrayNull(vlp); break; default: b = false; diff --git a/storage/connect/bson.h b/storage/connect/bson.h index 077e71b1413..aceaed5eb7c 100644 --- a/storage/connect/bson.h +++ b/storage/connect/bson.h @@ -17,13 +17,6 @@ #endif #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 BOUT; @@ -71,6 +64,15 @@ public: // Constructor 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 SubSet(bool b = false); void MemSave(void) {G->Saved_Size = ((PPOOLHEADER)G->Sarea)->To_Free;} @@ -82,47 +84,49 @@ public: PBPR SubAllocPair(PSZ key, OFFSET val = 0) {return SubAllocPair(MOF(key), val);} PBVAL NewVal(int type = TYPE_NULL); + PBVAL NewVal(PVAL valp); PBVAL SubAllocVal(OFFSET 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);} PBVAL SubAllocStr(OFFSET str, short nd = 0); PBVAL SubAllocStr(PSZ str, short nd = 0) {return SubAllocStr(MOF(str), nd);} - PBVAL SubAllocVal(PVAL valp); PBVAL DupVal(PBVAL bvp); // Array functions + inline PBVAL GetArray(PBVAL vlp) {return MVP(vlp->To_Val);} int GetArraySize(PBVAL bap, bool b = false); PBVAL GetArrayValue(PBVAL bap, int i); PSZ GetArrayText(PGLOBAL g, PBVAL bap, PSTRG text); - PBVAL MergeArray(PBVAL bap1,PBVAL bap2); - PBVAL DeleteValue(PBVAL bap, int n); - PBVAL AddArrayValue(PBVAL bap, PBVAL nvp = NULL, int* x = NULL); - PBVAL SetArrayValue(PBVAL bap, PBVAL nvp, int n); + void MergeArray(PBVAL bap1,PBVAL bap2); + void DeleteValue(PBVAL bap, int n); + void AddArrayValue(PBVAL bap, OFFSET nvp = NULL, int* x = NULL); + 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); // Object functions - int GetObjectSize(PBPR bop, bool b = false); - PBPR GetNext(PBPR prp) {return MPP(prp->Next);} - PSZ GetObjectText(PGLOBAL g, PBPR bop, PSTRG text); - PBPR MergeObject(PBPR bop1, PBPR bop2); - PBPR AddPair(PBPR bop, PSZ key, OFFSET val = 0); + inline PBPR GetObject(PBVAL bop) {return MPP(bop->To_Val);} + inline PBPR GetNext(PBPR brp) { return MPP(brp->Next); } + int GetObjectSize(PBVAL bop, bool b = false); + PSZ GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text); + PBVAL MergeObject(PBVAL bop1, PBVAL bop2); + void AddPair(PBVAL bop, PSZ key, OFFSET val = 0); PSZ GetKey(PBPR prp) {return MZP(prp->Key);} PBVAL GetVal(PBPR prp) {return MVP(prp->Vlp);} - PBVAL GetKeyValue(PBPR bop, PSZ key); - PBVAL GetKeyList(PBPR bop); - PBVAL GetObjectValList(PBPR bop); - PBPR SetKeyValue(PBPR bop, OFFSET bvp, PSZ key); - inline PBPR SetKeyValue(PBPR bop, PBVAL vlp, PSZ key) - {return SetKeyValue(bop, MOF(vlp), key);} - PBPR DeleteKey(PBPR bop, PCSZ k); - bool IsObjectNull(PBPR bop); + PBVAL GetKeyValue(PBVAL bop, PSZ key); + PBVAL GetKeyList(PBVAL bop); + PBVAL GetObjectValList(PBVAL bop); + void SetKeyValue(PBVAL bop, OFFSET bvp, PSZ key); + inline void SetKeyValue(PBVAL bop, PBVAL vlp, PSZ key) + {SetKeyValue(bop, MOF(vlp), key);} + void DeleteKey(PBVAL bop, PCSZ k); + bool IsObjectNull(PBVAL bop); // Value functions int GetSize(PBVAL vlp, bool b = false); 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); } PSZ GetValueText(PGLOBAL g, PBVAL vlp, PSTRG text); inline PBVAL GetBson(PBVAL bvp) { return IsJson(bvp) ? MVP(bvp->To_Val) : bvp; } @@ -131,10 +135,10 @@ public: long long GetBigint(PBVAL vp); double GetDouble(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 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 SetInteger(PBVAL vlp, int n); void SetBigint(PBVAL vlp, longlong ll); diff --git a/storage/connect/bsonudf.cpp b/storage/connect/bsonudf.cpp index 36bec919ffd..356a5c5169f 100644 --- a/storage/connect/bsonudf.cpp +++ b/storage/connect/bsonudf.cpp @@ -348,7 +348,7 @@ PVAL BJNX::MakeJson(PGLOBAL g, PBVAL bvp) } // 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) { @@ -381,10 +381,10 @@ void BJNX::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp) break; case TYPE_JAR: - vp->SetValue_psz(GetArrayText(g, MVP(vlp->To_Val), NULL)); + vp->SetValue_psz(GetArrayText(g, vlp, NULL)); break; case TYPE_JOB: - vp->SetValue_psz(GetObjectText(g, MPP(vlp->To_Val), NULL)); + vp->SetValue_psz(GetObjectText(g, vlp, NULL)); break; case TYPE_NULL: vp->SetNull(true); @@ -437,8 +437,8 @@ PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b) for (; i < Nod && row; i++) { if (Nodes[i].Op == OP_NUM) { - Value->SetValue(row->Type == TYPE_JAR ? GetArraySize(MVP(row->To_Val)) : 1); - vlp = SubAllocVal(Value); + Value->SetValue(row->Type == TYPE_JAR ? GetArraySize(row) : 1); + vlp = NewVal(Value); return vlp; } else if (Nodes[i].Op == OP_XX) { Jb = b; @@ -460,11 +460,11 @@ PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b) } //endif Op } else - vlp = GetKeyValue(MPP(row->To_Val), Nodes[i].Key); + vlp = GetKeyValue(row, Nodes[i].Key); break; case TYPE_JAR: - bap = MVP(row->To_Val); + bap = row; if (!Nodes[i].Key) { 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) return (PBVAL)ExpandArray(g, bap, i); else - return SubAllocVal(CalculateArray(g, bap, i)); + return NewVal(CalculateArray(g, bap, i)); } else { // Unexpected array, unwrap it as [0] @@ -616,13 +616,13 @@ my_bool BJNX::CheckPath(PGLOBAL g) } else switch (row->Type) { case TYPE_JOB: if (Nodes[i].Key) - val = GetKeyValue(MPP(row->To_Val), Nodes[i].Key); + val = GetKeyValue(row, Nodes[i].Key); break; case TYPE_JAR: if (!Nodes[i].Key) 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; case TYPE_JVAL: @@ -660,10 +660,10 @@ PBVAL BJNX::GetRow(PGLOBAL g) // Expected Array was not there, wrap the value continue; - val = GetKeyValue(MPP(row->To_Val), Nodes[i].Key); + val = GetKeyValue(row, Nodes[i].Key); break; case TYPE_JAR: - arp = MVP(row->To_Val); + arp = row; if (!Nodes[i].Key) { if (Nodes[i].Op == OP_EQ) @@ -703,9 +703,9 @@ PBVAL BJNX::GetRow(PGLOBAL g) nwr = NewVal(); 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) { - AddArrayValue(MVP(row->To_Val), nwr); + AddArrayValue(row, MOF(nwr)); } else { strcpy(g->Message, "Wrong type when writing new row"); nwr = NULL; @@ -727,7 +727,7 @@ PBVAL BJNX::GetRow(PGLOBAL g) /***********************************************************************/ my_bool BJNX::WriteValue(PGLOBAL g, PBVAL jvalp) { - PBPR objp = NULL; + PBVAL objp = NULL; PBVAL arp = NULL; PBVAL jvp = NULL; PBVAL row = GetRow(g); @@ -736,8 +736,8 @@ my_bool BJNX::WriteValue(PGLOBAL g, PBVAL jvalp) return true; switch (row->Type) { - case TYPE_JOB: objp = MPP(row->To_Val); break; - case TYPE_JAR: arp = MVP(row->To_Val); break; + case TYPE_JOB: objp = row; break; + case TYPE_JAR: arp = row; break; case TYPE_JVAL: jvp = MVP(row->To_Val); break; default: 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) SetArrayValue(arp, jvalp, Nodes[Nod - 1].Rank); else - AddArrayValue(arp, jvalp); + AddArrayValue(arp, MOF(jvalp)); } // endif Key @@ -787,10 +787,10 @@ PSZ BJNX::Locate(PGLOBAL g, PBVAL jsp, PBVAL jvp, int k) switch (jsp->Type) { case TYPE_JAR: - err = LocateArray(g, MVP(jsp->To_Val)); + err = LocateArray(g, jsp); break; case TYPE_JOB: - err = LocateObject(g, MPP(jsp->To_Val)); + err = LocateObject(g, jsp); break; case TYPE_JVAL: err = LocateValue(g, MVP(jsp->To_Val)); @@ -810,9 +810,7 @@ PSZ BJNX::Locate(PGLOBAL g, PBVAL jsp, PBVAL jvp, int k) } // endif's } catch (int n) { - if (trace(1)) - htrc("Exception %d: %s\n", n, g->Message); - + xtrc(1, "Exception %d: %s\n", n, g->Message); PUSH_WARNING(g->Message); } catch (const char* msg) { strcpy(g->Message, msg); @@ -848,7 +846,7 @@ my_bool BJNX::LocateArray(PGLOBAL g, PBVAL jarp) /*********************************************************************************/ /* Locate in a JSON Object. */ /*********************************************************************************/ -my_bool BJNX::LocateObject(PGLOBAL g, PBPR jobp) +my_bool BJNX::LocateObject(PGLOBAL g, PBVAL jobp) { size_t m; @@ -857,7 +855,7 @@ my_bool BJNX::LocateObject(PGLOBAL g, PBPR jobp) 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; if (Jp->WriteStr(MZP(pair->Key))) @@ -879,9 +877,9 @@ my_bool BJNX::LocateValue(PGLOBAL g, PBVAL jvp) if (CompareTree(g, Bvalp, jvp)) Found = (--K == 0); else if (jvp->Type == TYPE_JAR) - return LocateArray(g, GetArray(jvp)); + return LocateArray(g, jvp); else if (jvp->Type == TYPE_JOB) - return LocateObject(g, GetObject(jvp)); + return LocateObject(g, jvp); return false; } // end of LocateValue @@ -914,10 +912,10 @@ PSZ BJNX::LocateAll(PGLOBAL g, PBVAL jsp, PBVAL bvp, int mx) switch (jsp->Type) { case TYPE_JAR: - err = LocateArrayAll(g, MVP(jsp->To_Val)); + err = LocateArrayAll(g, jsp); break; case TYPE_JOB: - err = LocateObjectAll(g, MPP(jsp->To_Val)); + err = LocateObjectAll(g, jsp); break; case TYPE_JVAL: err = LocateValueAll(g, MVP(jsp->To_Val)); @@ -957,7 +955,7 @@ my_bool BJNX::LocateArrayAll(PGLOBAL g, PBVAL jarp) if (I < Imax) { 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; if (LocateValueAll(g, GetArrayValue(jarp, i))) @@ -975,12 +973,12 @@ my_bool BJNX::LocateArrayAll(PGLOBAL g, PBVAL jarp) /*********************************************************************************/ /* Locate in a JSON Object. */ /*********************************************************************************/ -my_bool BJNX::LocateObjectAll(PGLOBAL g, PBPR jobp) +my_bool BJNX::LocateObjectAll(PGLOBAL g, PBVAL jobp) { if (I < Imax) { 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); if (LocateValueAll(g, MVP(pair->Vlp))) @@ -1002,9 +1000,9 @@ my_bool BJNX::LocateValueAll(PGLOBAL g, PBVAL jvp) if (CompareTree(g, Bvalp, jvp)) return AddPath(); else if (jvp->Type == TYPE_JAR) - return LocateArrayAll(g, GetArray(jvp)); + return LocateArrayAll(g, jvp); else if (jvp->Type == TYPE_JOB) - return LocateObjectAll(g, GetObject(jvp)); + return LocateObjectAll(g, jvp); return false; } // 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))); } 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 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) { 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) switch (v1->Type) { case TYPE_JAR: - if (v2->Type == TYPE_JAR) - b = CompareTree(g, MVP(v1->To_Val), MVP(v2->To_Val)); + case TYPE_JOB: + if (v2->Type == v1->Type) + b = CompareTree(g, v1, v2); break; case TYPE_STRG: @@ -1297,12 +1296,10 @@ char* bson_make_array(UDF_INIT* initid, UDF_ARGS* args, char* result, if (!g->Xchk) { if (!CheckMemory(g, initid, args, args->arg_count, false)) { 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++) - bvp = doc.AddArrayValue(bvp, MakeBinValue(g, args, i)); - - arp = doc.SubAllocVal(bvp, TYPE_JAR); + doc.AddArrayValue(arp, MakeBinValue(g, args, i)); if (!(str = doc.Serialize(g, arp, NULL, 0))) 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 (!CheckMemory(g, initid, args, args->arg_count, true)) { - uint n = 1; - bool b = false; + uint i = 0; BDOC doc(g); - PBVAL bvp = NULL, arp = MakeBinValue(g, args, 0); - - if (arp->Type == TYPE_JAR) { - bvp = doc.GetArray(arp); - b = !bvp; - } else - n = 0; + PBVAL arp, bvp = MakeBinValue(g, args, 0); - for (uint i = n; i < args->arg_count; i++) - bvp = doc.AddArrayValue(bvp, MakeBinValue(g, args, i)); + if (bvp->Type == TYPE_JAR) { + arp = bvp; + i = 1; + } else // First argument is not an array + arp = doc.NewVal(TYPE_JAR); - if (!n) - arp = doc.SubAllocVal(bvp, TYPE_JAR); - else if (b) - doc.SetValueArr(arp, bvp); + for (; i < args->arg_count; i++) + doc.AddArrayValue(arp, MakeBinValue(g, args, i)); -// str = MakeResult(g, args, top, args->arg_count); str = doc.Serialize(g, arp, NULL, 0); } // endif CheckMemory diff --git a/storage/connect/bsonudf.h b/storage/connect/bsonudf.h index b310aa1827b..b591b6b89f8 100644 --- a/storage/connect/bsonudf.h +++ b/storage/connect/bsonudf.h @@ -46,10 +46,10 @@ protected: PBVAL GetRow(PGLOBAL g); my_bool CompareValues(PGLOBAL g, PBVAL v1, PBVAL v2); 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 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 CompareTree(PGLOBAL g, PBVAL jp1, PBVAL jp2); my_bool AddPath(void); diff --git a/storage/connect/filamap.cpp b/storage/connect/filamap.cpp index 007968e0d44..18ba0b1018f 100644 --- a/storage/connect/filamap.cpp +++ b/storage/connect/filamap.cpp @@ -170,7 +170,8 @@ bool MAPFAM::OpenTableFile(PGLOBAL g) htrc("CreateFileMap: %s\n", g->Message); return (mode == MODE_READ && rc == ENOENT) - ? PushWarning(g, Tdbp) : true; + ? false : true; +// ? PushWarning(g, Tdbp) : true; --> assert fails into MariaDB } // endif hFile /*******************************************************************/ diff --git a/storage/connect/global.h b/storage/connect/global.h index f09d5250124..d4a46e1c862 100644 --- a/storage/connect/global.h +++ b/storage/connect/global.h @@ -220,34 +220,11 @@ DllExport char *PlugDup(PGLOBAL g, const char *str); DllExport void htrc(char const *fmt, ...); DllExport void xtrc(uint, char const* fmt, ...); DllExport uint GetTraceValue(void); +DllExport void* MakePtr(void* memp, size_t offset); +DllExport size_t MakeOff(void* memp, void* ptr); #if defined(__cplusplus) } // extern "C" #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 --------------------------*/ diff --git a/storage/connect/mysql-test/connect/disabled.def b/storage/connect/mysql-test/connect/disabled.def index 1de4deb0a60..e1f6219f89f 100644 --- a/storage/connect/mysql-test/connect/disabled.def +++ b/storage/connect/mysql-test/connect/disabled.def @@ -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_3 : Need MongoDB running and its Java Driver installed tbl_thread : Bug MDEV-9844,10179,14214 03/01/2018 OB Option THREAD removed +bson : Development #vcol : Different error code on different versions diff --git a/storage/connect/plugutil.cpp b/storage/connect/plugutil.cpp index 479310703eb..ac07f45ccf2 100644 --- a/storage/connect/plugutil.cpp +++ b/storage/connect/plugutil.cpp @@ -607,4 +607,27 @@ char *PlugDup(PGLOBAL g, const char *str) } // 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 -----------------------*/ diff --git a/storage/connect/tabbson.cpp b/storage/connect/tabbson.cpp index aa2f5957911..f3378d5f9bc 100644 --- a/storage/connect/tabbson.cpp +++ b/storage/connect/tabbson.cpp @@ -607,7 +607,7 @@ PBVAL BTUTIL::FindRow(PGLOBAL g) if (*objpath != '[' && !IsNum(objpath)) { // objpass is a key val = (jsp->Type == TYPE_JOB) ? - GetKeyValue(GetObject(jsp), objpath) : NULL; + GetKeyValue(jsp, objpath) : NULL; } else { if (*objpath == '[') { if (objpath[strlen(objpath) - 1] == ']') @@ -648,7 +648,7 @@ PBVAL BTUTIL::MakeTopTree(PGLOBAL g, PBVAL jsp) char* p; char* objpath = PlugDup(g, Tp->Objname); int i; - PBPR objp = NULL; + PBVAL objp = NULL; PBVAL arp = NULL; PBVAL val = NULL; @@ -799,7 +799,7 @@ PVAL BCUTIL::MakeBson(PGLOBAL g, PBVAL jsp) return Cp->Value; } // end of MakeJson - /***********************************************************************/ +/***********************************************************************/ /* GetColumnValue: */ /***********************************************************************/ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i) @@ -826,11 +826,11 @@ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i) bvp = row; } else - bvp = GetKeyValue(MPP(row->To_Val), nodes[i].Key); + bvp = GetKeyValue(row, nodes[i].Key); break; case TYPE_JAR: - arp = MVP(row->To_Val); + arp = row; if (!nodes[i].Key) { 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) return ExpandArray(g, arp, i); else - return CalculateArray(arp, i); + return CalculateArray(g, arp, i); } else { // Unexpected array, unwrap it as [0] @@ -887,8 +887,8 @@ PVAL BCUTIL::ExpandArray(PGLOBAL g, PBVAL arp, int n) throw 666; } // endif jvp - if (n < nod - 1 && GetBson(bvp)) { - SetValue(&bval, GetColumnValue(g, GetBson(bvp), n + 1)); + if (n < nod - 1 && IsJson(bvp)) { + SetValue(&bval, GetColumnValue(g, bvp, n + 1)); bvp = &bval; } // endif n @@ -906,75 +906,67 @@ PVAL BCUTIL::ExpandArray(PGLOBAL g, PBVAL arp, int n) return value; } // end of ExpandArray - /***********************************************************************/ - /* CalculateArray: */ - /***********************************************************************/ -PVAL BCUTIL::CalculateArray(PBVAL arp, int n) +/***********************************************************************/ +/* CalculateArray: */ +/***********************************************************************/ +PVAL BCUTIL::CalculateArray(PGLOBAL g, PBVAL arp, int n) { - throw("CalculateArray NIY"); -#if 0 - int i, ars, nv = 0, nextsame = Tjp->NextSame; + int i, ars, nv = 0, nextsame = Tp->NextSame; bool err; - OPVAL op = Nodes[n].Op; - PVAL val[2], vp = Nodes[n].Valp; - PJVAL jvrp, jvp; - JVALUE jval; + int nod = Cp->Nod; + JNODE *nodes = Cp->Nodes; + OPVAL op = nodes[n].Op; + PVAL val[2], vp = nodes[n].Valp, mulval = Cp->MulVal; + PBVAL jvrp, jvp; + BVAL jval; vp->Reset(); - ars = MY_MIN(Tjp->Limit, arp->size()); - - if (trace(1)) - htrc("CalculateArray: size=%d op=%d nextsame=%d\n", - ars, op, nextsame); + ars = MY_MIN(Tp->Limit, GetArraySize(arp)); + xtrc(1,"CalculateArray: size=%d op=%d nextsame=%d\n", ars, op, nextsame); 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)) - htrc("i=%d nv=%d\n", i, nv); - - if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) do { - if (jvrp->IsNull()) { - jvrp->Strp = PlugDup(g, GetJsonNull()); - jvrp->DataType = TYPE_STRG; + if (!IsValueNull(jvrp) || (op == OP_CNC && GetJsonNull())) do { + if (IsValueNull(jvrp)) { + SetString(jvrp, PlugDup(G, GetJsonNull())); jvp = jvrp; - } else if (n < Nod - 1 && jvrp->GetJson()) { - Tjp->NextSame = nextsame; - jval.SetValue(g, GetColumnValue(g, jvrp->GetJson(), n + 1)); + } else if (n < nod - 1 && IsJson(jvrp)) { + Tp->NextSame = nextsame; + SetValue(&jval, GetColumnValue(g, jvrp, n + 1)); jvp = &jval; } else jvp = jvrp; - if (trace(1)) - htrc("jvp=%s null=%d\n", - jvp->GetString(g), jvp->IsNull() ? 1 : 0); + xtrc(1, "jvp=%s null=%d\n", GetString(jvp), IsValueNull(jvp) ? 1 : 0); if (!nv++) { SetJsonValue(g, vp, jvp); continue; } else - SetJsonValue(g, MulVal, jvp); + SetJsonValue(g, mulval, jvp); - if (!MulVal->IsNull()) { + if (!mulval->IsNull()) { switch (op) { case OP_CNC: - if (Nodes[n].CncVal) { - val[0] = Nodes[n].CncVal; + if (nodes[n].CncVal) { + val[0] = nodes[n].CncVal; err = vp->Compute(g, val, 1, op); } // endif CncVal - val[0] = MulVal; + val[0] = mulval; err = vp->Compute(g, val, 1, op); break; - // case OP_NUM: + // case OP_NUM: case OP_SEP: - val[0] = Nodes[n].Valp; - val[1] = MulVal; + 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; + val[0] = nodes[n].Valp; + val[1] = mulval; err = vp->Compute(g, val, 2, op); } // endswitch Op @@ -991,24 +983,23 @@ PVAL BCUTIL::CalculateArray(PBVAL arp, int n) } // endif Null - } while (Tjp->NextSame > nextsame); + } while (Tp->NextSame > nextsame); } // endfor i if (op == OP_SEP) { // Calculate average - MulVal->SetValue(nv); + mulval->SetValue(nv); val[0] = vp; - val[1] = MulVal; + val[1] = mulval; if (vp->Compute(g, val, 2, OP_DIV)) vp->Reset(); } // endif Op - Tjp->NextSame = nextsame; + Tp->NextSame = nextsame; return vp; -#endif // 0 } // end of CalculateArray /***********************************************************************/ @@ -1031,7 +1022,7 @@ PBVAL BCUTIL::GetRow(PGLOBAL g) // Expected Array was not there, wrap the value continue; - val = GetKeyValue(MPP(row->To_Val), nodes[i].Key); + val = GetKeyValue(row, nodes[i].Key); break; case TYPE_JAR: arp = row; @@ -1058,7 +1049,7 @@ PBVAL BCUTIL::GetRow(PGLOBAL g) } // endswitch Type if (val) { - row = GetBson(val); + row = val; } else { // Construct missing objects for (i++; row && i < nod; i++) { @@ -1071,9 +1062,9 @@ PBVAL BCUTIL::GetRow(PGLOBAL g) nwr = NewVal(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) { - AddArrayValue(MVP(row->To_Val), nwr); + AddArrayValue(row, nwr); } else { strcpy(g->Message, "Wrong type when writing new row"); nwr = NULL; @@ -1157,7 +1148,8 @@ bool BSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) /***********************************************************************/ /* GetTable: makes a new Table Description Block. */ /***********************************************************************/ -PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) { +PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) +{ if (trace(1)) 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 if (Pretty <= 0 || (Pretty == 1 && (m == MODE_READ || m == MODE_UPDATE))) { - PGLOBAL G; USETEMP tmp = UseTemp(); bool map = Mapped && Pretty >= 0 && m != MODE_INSERT && !(tmp != TMP_NO && m == MODE_UPDATE) && @@ -1178,14 +1169,7 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) { if (Lrecl) { // Allocate the parse work memory - G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL)); - 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); + G = PlugInit(NULL, (size_t)Lrecl * 6); } else { strcpy(g->Message, "LRECL is not defined"); return NULL; @@ -1252,7 +1236,7 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) { txfp = new(g) DOSFAM(this); // Txfp must be set for TDBBSN - tdbp = new(g) TDBBSN(G, this, txfp); + tdbp = new(g) TDBBSN(g, this, txfp); } else { if (Zipped) { #if defined(ZIP_SUPPORT) @@ -1366,7 +1350,8 @@ PTDB TDBBSN::Clone(PTABS t) /***********************************************************************/ /* 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); 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.*/ /***********************************************************************/ -PCOL TDBBSN::InsertSpecialColumn(PCOL colp) { +PCOL TDBBSN::InsertSpecialColumn(PCOL colp) +{ if (!colp->IsSpecial()) return NULL; @@ -1390,7 +1376,8 @@ PCOL TDBBSN::InsertSpecialColumn(PCOL colp) { /***********************************************************************/ /* JSON Cardinality: returns table size in number of rows. */ /***********************************************************************/ -int TDBBSN::Cardinality(PGLOBAL g) { +int TDBBSN::Cardinality(PGLOBAL g) +{ if (!g) return 0; else if (Cardinal < 0) { @@ -1404,7 +1391,8 @@ int TDBBSN::Cardinality(PGLOBAL g) { /***********************************************************************/ /* JSON GetMaxSize: returns file size estimate in number of lines. */ /***********************************************************************/ -int TDBBSN::GetMaxSize(PGLOBAL g) { +int TDBBSN::GetMaxSize(PGLOBAL g) +{ if (MaxSize < 0) MaxSize = TDBDOS::GetMaxSize(g) * ((Xcol) ? Limit : 1); @@ -1414,7 +1402,8 @@ int TDBBSN::GetMaxSize(PGLOBAL g) { /***********************************************************************/ /* JSON EstimatedLength. Returns an estimated minimum line length. */ /***********************************************************************/ -int TDBBSN::EstimatedLength(void) { +int TDBBSN::EstimatedLength(void) +{ if (AvgLen <= 0) return (Lrecl ? Lrecl : 1024) / 8; // TODO: make it better else @@ -1425,7 +1414,8 @@ int TDBBSN::EstimatedLength(void) { /***********************************************************************/ /* OpenDB: Data Base open routine for JSN access method. */ /***********************************************************************/ -bool TDBBSN::OpenDB(PGLOBAL g) { +bool TDBBSN::OpenDB(PGLOBAL g) +{ if (Use == USE_OPEN) { /*******************************************************************/ /* Table already open replace it at its beginning. */ @@ -1437,13 +1427,11 @@ bool TDBBSN::OpenDB(PGLOBAL g) { /*******************************************************************/ /* First opening. */ /*******************************************************************/ -// Docp = new(g) BDOC(g->Sarea); - if (Mode == MODE_INSERT) switch (Jmode) { -// case MODE_OBJECT: Row = new(g) JOBJECT; break; -// case MODE_ARRAY: Row = new(g) JARRAY; break; -// case MODE_VALUE: Row = new(g) JVALUE; break; + case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break; + case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break; + case MODE_VALUE: Row = Bp->NewVal(TYPE_JVAL); break; default: sprintf(g->Message, "Invalid Jmode %d", Jmode); return true; @@ -1507,7 +1495,8 @@ bool TDBBSN::OpenDB(PGLOBAL g) { /* This is called from TDBDOS::OpenDB and must be executed before */ /* Kindex construction if the file is accessed using an index. */ /***********************************************************************/ -bool TDBBSN::SkipHeader(PGLOBAL g) { +bool TDBBSN::SkipHeader(PGLOBAL g) +{ int len = GetFileLength(g); bool rc = false; @@ -1531,7 +1520,8 @@ bool TDBBSN::SkipHeader(PGLOBAL g) { /***********************************************************************/ /* ReadDB: Data Base read routine for JSN access method. */ /***********************************************************************/ -int TDBBSN::ReadDB(PGLOBAL g) { +int TDBBSN::ReadDB(PGLOBAL g) +{ int rc; N++; @@ -1589,7 +1579,8 @@ int TDBBSN::ReadDB(PGLOBAL g) { /***********************************************************************/ /* PrepareWriting: Prepare the line for WriteDB. */ /***********************************************************************/ -bool TDBBSN::PrepareWriting(PGLOBAL g) { +bool TDBBSN::PrepareWriting(PGLOBAL g) +{ PSZ s; if (!(Top = Bp->MakeTopTree(g, Row))) @@ -1629,10 +1620,10 @@ int TDBBSN::WriteDB(PGLOBAL g) { void TDBBSN::CloseDB(PGLOBAL g) { TDBDOS::CloseDB(g); - ((PBDEF)To_Def)->G = PlugExit(((PBDEF)To_Def)->G); + Bp->G = PlugExit(Bp->G); } // end of CloseDB - /* ---------------------------- BSONCOL ------------------------------ */ +/* ---------------------------- BSONCOL ------------------------------ */ /***********************************************************************/ /* BSONCOL public constructor. */ @@ -1689,7 +1680,8 @@ bool BSONCOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check) /***********************************************************************/ /* 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) && (Tbp->Xval < 0 || Tbp->Xval == i)) || Xpd) { Xpd = true; // Expandable object @@ -1705,7 +1697,8 @@ bool BSONCOL::CheckExpand(PGLOBAL g, int i, PSZ nm, bool b) { /***********************************************************************/ /* 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; bool dg = true, b = false; 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 */ /* the node corresponding to that column. */ /***********************************************************************/ -bool BSONCOL::ParseJpath(PGLOBAL g) { +bool BSONCOL::ParseJpath(PGLOBAL g) +{ char* p, * p1 = NULL, * p2 = NULL, * pbuf = NULL; int i; bool a; @@ -1925,7 +1919,8 @@ fin: /***********************************************************************/ /* Get Jpath converted to Mongo path. */ /***********************************************************************/ -PSZ BSONCOL::GetJpath(PGLOBAL g, bool proj) { +PSZ BSONCOL::GetJpath(PGLOBAL g, bool proj) +{ if (Jpath) { char* p1, * p2, * mgopath; int i = 0; @@ -1990,35 +1985,10 @@ PSZ BSONCOL::GetJpath(PGLOBAL g, bool proj) { } // 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: */ /***********************************************************************/ -void BSONCOL::ReadColumn(PGLOBAL g) { +void BSONCOL::ReadColumn(PGLOBAL g) +{ if (!Tbp->SameRow || Xnod >= Tbp->SameRow) Value->SetValue_pval(Cp->GetColumnValue(g, Tbp->Row, 0)); @@ -2034,7 +2004,8 @@ void BSONCOL::ReadColumn(PGLOBAL g) { /***********************************************************************/ /* WriteColumn: */ /***********************************************************************/ -void BSONCOL::WriteColumn(PGLOBAL g) { +void BSONCOL::WriteColumn(PGLOBAL g) +{ if (Xpd && Tbp->Pretty < 2) { strcpy(g->Message, "Cannot write expanded column when Pretty is not 2"); throw 666; @@ -2052,75 +2023,48 @@ void BSONCOL::WriteColumn(PGLOBAL g) { if (Value->IsNull() && Tbp->Mode == MODE_INSERT) return; - throw "Write BSON NIY"; - -#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 + PBVAL jsp, row = Cp->GetRow(g); if (row) switch (Buf_Type) { 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_INT: case TYPE_TINY: case TYPE_SHORT: case TYPE_BIGINT: 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) - arp->SetArrayValue(G, new(G) JVALUE(G, Value), Nodes[Nod - 1].Rank); + Cp->SetArrayValue(row, jsp, Nodes[Nod - 1].Rank); else - arp->AddArrayValue(G, new(G) JVALUE(G, Value)); + Cp->AddArrayValue(row, jsp); - arp->InitArray(G); - } else if (objp) { + case TYPE_JOB: 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) - jvp->SetValue(g, Value); + break; + case TYPE_JVAL: + default: + Cp->SetValueVal(row, jsp); + } // endswitch Type break; default: // ?????????? sprintf(g->Message, "Invalid column type %d", Buf_Type); } // endswitch Type -#endif // 0 } // end of WriteColumn @@ -2169,7 +2113,7 @@ int TDBBSON::MakeNewDoc(PGLOBAL g) // Create a void table that will be populated Docp = Bp->NewVal(TYPE_JAR); - if (Bp->MakeTopTree(g, Docp)) + if (!(Top = Bp->MakeTopTree(g, Docp))) return RC_FX; Done = true; @@ -2187,7 +2131,7 @@ int TDBBSON::MakeDocument(PGLOBAL g) my_bool a; MODE mode = Mode; PBVAL jsp; - PBPR objp = NULL; + PBVAL objp = NULL; PBVAL arp = NULL; PBVAL val = NULL; @@ -2260,7 +2204,7 @@ int TDBBSON::MakeDocument(PGLOBAL g) } // endif Type key = p; - objp = Bp->GetObject(jsp); + objp = jsp; arp = NULL; val = Bp->GetKeyValue(objp, key); @@ -2285,7 +2229,7 @@ int TDBBSON::MakeDocument(PGLOBAL g) return RC_FX; } // endif Type - arp = Bp->GetArray(jsp); + arp = jsp; objp = NULL; i = atoi(p) - B; val = Bp->GetArrayValue(arp, i); @@ -2449,9 +2393,9 @@ bool TDBBSON::OpenDB(PGLOBAL g) if (Mode == MODE_INSERT) switch (Jmode) { - case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break; - case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break; - case MODE_VALUE: Row = Bp->NewVal(); break; + case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break; + case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break; + case MODE_VALUE: Row = Bp->NewVal(TYPE_JVAL); break; default: sprintf(g->Message, "Invalid Jmode %d", Jmode); return true; @@ -2479,7 +2423,7 @@ int TDBBSON::ReadDB(PGLOBAL) M++; rc = RC_OK; } else if (++Fpos < (signed)Bp->GetSize(Docp)) { - Row = Bp->GetArrayValue(Bp->GetBson(Docp), Fpos); + Row = Bp->GetArrayValue(Docp, Fpos); if (Row->Type == TYPE_JVAL) Row = Bp->GetBson(Row); @@ -2498,32 +2442,17 @@ int TDBBSON::ReadDB(PGLOBAL) /***********************************************************************/ int TDBBSON::WriteDB(PGLOBAL g) { - if (Jmode == MODE_OBJECT) { - PBVAL vp = Bp->DupVal(Row); - - if (Mode == MODE_INSERT) { - Bp->AddArrayValue(Docp, vp); - Row = Bp->NewVal(TYPE_JOB); - } else if (Bp->SetArrayValue(Docp, vp, Fpos)) - return RC_FX; + if (Mode == MODE_INSERT) { + Bp->AddArrayValue(Docp, Row); - } else if (Jmode == MODE_ARRAY) { - PBVAL vp = Bp->DupVal(Row); - - 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; + switch(Jmode) { + case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break; + case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break; + default: Row = Bp->NewVal(); break; + } // endswitch Jmode - } // endif Jmode + } else + Bp->SetArrayValue(Docp, Row, Fpos); Changed = true; return RC_OK; @@ -2534,26 +2463,15 @@ int TDBBSON::WriteDB(PGLOBAL g) /***********************************************************************/ int TDBBSON::DeleteDB(PGLOBAL g, int irc) { - strcpy(g->Message, "BSON Delete NIY"); - return RC_FX; -#if 0 - if (irc == RC_OK) { + if (irc == RC_OK) // Deleted current row - if (Doc->DeleteValue(Fpos)) { - sprintf(g->Message, "Value %d does not exist", Fpos + 1); - return RC_FX; - } // endif Delete - - Changed = true; - } else if (irc == RC_FX) + Bp->DeleteValue(Docp, Fpos); + else if (irc == RC_FX) // Delete all - for (int i = 0; i < Doc->size(); i++) { - Doc->DeleteValue(i); - Changed = true; - } // endfor i + Docp->To_Val = 0; + Changed = true; return RC_OK; -#endif // 0 } // end of DeleteDB /***********************************************************************/ diff --git a/storage/connect/tabbson.h b/storage/connect/tabbson.h index 127370ce342..677bcbfd6e9 100644 --- a/storage/connect/tabbson.h +++ b/storage/connect/tabbson.h @@ -134,7 +134,7 @@ public: PVAL MakeBson(PGLOBAL g, PBVAL jsp); PVAL GetColumnValue(PGLOBAL g, PBVAL row, int i); 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); protected: @@ -243,7 +243,7 @@ public: // Methods 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 void ReadColumn(PGLOBAL g); virtual void WriteColumn(PGLOBAL g); @@ -251,12 +251,6 @@ public: protected: bool CheckExpand(PGLOBAL g, int i, PSZ nm, bool b); 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 BSONCOL(void) {} |