Commit a3542482 authored by Olivier Bertrand's avatar Olivier Bertrand

- Continue BSON implementation + fix create modified ha_connect.cc

parent 2113cab7
This diff is collapsed.
......@@ -37,7 +37,8 @@ typedef struct _jvalue {
bool B; // A boolean value True or false (0)
};
short Nd; // Number of decimals
short Type; // The value type
char Type; // The value type
char Ktp; // The key type
OFFSET Next; // Offset to the next value in array
} BVAL, *PBVAL; // end of struct BVALUE
......@@ -46,13 +47,12 @@ typedef struct _jvalue {
/***********************************************************************/
typedef struct _jpair {
OFFSET Key; // Offset to this pair key name
OFFSET Vlp; // To the value of the pair
OFFSET Next; // Offset to the next pair in object
BVAL Vlp; // The value of the pair
} BPAIR, *PBPR; // end of struct BPAIR
char* NextChr(PSZ s, char sep);
char* GetJsonNull(void);
const char* GetFmt(int type, bool un);
const char* GetFmt(int type, bool un);
DllExport bool IsNum(PSZ s);
......@@ -81,9 +81,9 @@ class BJSON : public BLOCK {
// SubAlloc functions
void* BsonSubAlloc(size_t size);
PBPR SubAllocPair(OFFSET key, OFFSET val = 0);
OFFSET NewPair(PSZ key, OFFSET val = 0)
{return MOF(SubAllocPair(DupStr(key), val));}
PBPR NewPair(OFFSET key, int type = TYPE_NULL);
OFFSET NewPair(PSZ key, int type = TYPE_NULL)
{return MOF(NewPair(DupStr(key), type));}
PBVAL NewVal(int type = TYPE_NULL);
PBVAL NewVal(PVAL valp);
PBVAL SubAllocVal(OFFSET toval, int type = TYPE_NULL, short nd = 0);
......@@ -110,13 +110,15 @@ class BJSON : public BLOCK {
// Object functions
inline PBPR GetObject(PBVAL bop) {return MPP(bop->To_Val);}
inline PBPR GetNext(PBPR brp) { return MPP(brp->Next); }
inline PBPR GetNext(PBPR brp) { return MPP(brp->Vlp.Next); }
void SetPairValue(PBPR brp, PBVAL bvp);
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 AddPair(PBVAL bop, PSZ key, int type = TYPE_NULL);
PSZ GetKey(PBPR prp) {return prp ? MZP(prp->Key) : NULL;}
PBVAL GetTo_Val(PBPR prp) {return prp ? MVP(prp->Vlp.To_Val) : NULL;}
PBVAL GetVlp(PBPR prp) {return prp ? (PBVAL)&prp->Vlp : NULL;}
PBVAL GetKeyValue(PBVAL bop, PSZ key);
PBVAL GetKeyList(PBVAL bop);
PBVAL GetObjectValList(PBVAL bop);
......@@ -131,7 +133,7 @@ class BJSON : public BLOCK {
PBVAL GetNext(PBVAL vlp) {return MVP(vlp->Next);}
//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; }
PBVAL GetBson(PBVAL bvp);
PSZ GetString(PBVAL vp, char* buff = NULL);
int GetInteger(PBVAL vp);
long long GetBigint(PBVAL vp);
......@@ -178,7 +180,7 @@ class BDOC : public BJSON {
protected:
OFFSET ParseArray(int& i);
OFFSET ParseObject(int& i);
PBVAL ParseValue(int& i);
PBVAL ParseValue(int& i, PBVAL bvp);
OFFSET ParseString(int& i);
void ParseNumeric(int& i, PBVAL bvp);
OFFSET ParseAsArray(int& i);
......
......@@ -856,7 +856,7 @@ my_bool BJNX::LocateObject(PGLOBAL g, PBVAL jobp)
if (Jp->WriteStr(MZP(pair->Key)))
return true;
if (LocateValue(g, MVP(pair->Vlp)))
if (LocateValue(g, GetVlp(pair)))
return true;
} // endfor i
......@@ -976,7 +976,7 @@ my_bool BJNX::LocateObjectAll(PGLOBAL g, PBVAL jobp)
for (PBPR pair = GetObject(jobp); pair; pair = GetNext(pair)) {
Jpnp[I].Key = MZP(pair->Key);
if (LocateValueAll(g, MVP(pair->Vlp)))
if (LocateValueAll(g, GetVlp(pair)))
return true;
} // endfor i
......@@ -1020,8 +1020,8 @@ my_bool BJNX::CompareTree(PGLOBAL g, PBVAL jp1, PBVAL jp2)
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(jp2, MZP(p1->Key)));
for (; found && p1 && p2; p1 = GetNext(p1))
found = CompareValues(g, GetVlp(p1), GetKeyValue(jp2, GetKey(p1)));
} else if (jp1->Type == TYPE_JVAL) {
found = CompareTree(g, MVP(jp1->To_Val), (MVP(jp2->To_Val)));
......
......@@ -170,7 +170,7 @@
#define JSONMAX 10 // JSON Default max grp size
extern "C" {
char version[]= "Version 1.07.0002 December 19, 2020";
char version[]= "Version 1.07.0002 December 25, 2020";
#if defined(__WIN__)
char compver[]= "Version 1.07.0002 " __DATE__ " " __TIME__;
char slash= '\\';
......@@ -6440,9 +6440,9 @@ int ha_connect::create(const char *name, TABLE *table_arg,
// Check table type
if (type == TAB_UNDEF) {
options->type= (options->srcdef) ? "MYSQL" :
#if defined(BSON_SUPPORT)
#if defined(REST_SUPPORT)
(options->http) ? "JSON" :
#endif // BSON_SUPPORT
#endif // REST_SUPPORT
(options->tabname) ? "PROXY" : "DOS";
type= GetTypeID(options->type);
sprintf(g->Message, "No table_type. Will be set to %s", options->type);
......@@ -6460,7 +6460,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
inward= IsFileType(type) && !options->filename &&
(type != TAB_JSON || !cnc.length);
((type != TAB_JSON && type != TAB_BSON) || !cnc.length);
if (options->data_charset) {
const CHARSET_INFO *data_charset;
......
......@@ -342,7 +342,7 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
strncpy(colname, bp->GetKey(jpp), 64);
fmt[bf] = 0;
if (Find(g, bp->GetVal(jpp), colname, MY_MIN(lvl, 0)))
if (Find(g, bp->GetVlp(jpp), colname, MY_MIN(lvl, 0)))
goto err;
} // endfor jpp
......@@ -444,7 +444,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j)
strncat(strncat(colname, "_", n), k, n - 1);
} // endif Key
if (Find(g, bp->GetVal(jrp), k, j + 1))
if (Find(g, bp->GetVlp(jrp), k, j + 1))
return true;
*p = *pc = 0;
......@@ -691,7 +691,7 @@ PBVAL BTUTIL::MakeTopTree(PGLOBAL g, int type)
} // endif Val
Tp->Row = val;
Tp->Row->Type = type;
if (Tp->Row) Tp->Row->Type = type;
} else
top = Tp->Row = NewVal(type);
......@@ -1052,18 +1052,20 @@ PBVAL BCUTIL::GetRow(PGLOBAL g)
} else {
// Construct missing objects
for (i++; row && i < nod; i++) {
int type;
if (nodes[i].Op == OP_XX)
break;
else if (!nodes[i].Key)
// Construct intermediate array
nwr = NewVal(TYPE_JAR);
type = TYPE_JAR;
else
nwr = NewVal(TYPE_JOB);
type = TYPE_JOB;
if (row->Type == TYPE_JOB) {
SetKeyValue(row, MOF(nwr), nodes[i - 1].Key);
nwr = AddPair(row, nodes[i - 1].Key, type);
} else if (row->Type == TYPE_JAR) {
AddArrayValue(row, nwr);
AddArrayValue(row, (nwr = NewVal(type)));
} else {
strcpy(g->Message, "Wrong type when writing new row");
nwr = NULL;
......@@ -2258,19 +2260,16 @@ int TDBBSON::MakeDocument(PGLOBAL g)
Docp = jsp;
else {
// The table is void or is just one object or one value
Docp = Bp->NewVal(TYPE_JAR);
if (val)
Bp->AddArrayValue(Docp, val);
else if (jsp)
Bp->AddArrayValue(Docp, Bp->DupVal(jsp));
if (objp)
Bp->SetKeyValue(objp, Bp->DupVal(Docp), key);
else if (arp)
Bp->SetArrayValue(arp, Bp->DupVal(Docp), i);
else
Top = Docp;
if (objp) {
Docp = Bp->GetKeyValue(objp, key);
Docp->To_Val = Bp->MOF(Bp->DupVal(Docp));
Docp->Type = TYPE_JAR;
} else if (arp) {
Docp = Bp->NewVal(TYPE_JAR);
Bp->AddArrayValue(Docp, jsp);
Bp->SetArrayValue(arp, Docp, i);
} else
Top = Docp = Bp->NewVal(TYPE_JAR);
} // endif jsp
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment