Commit 950bf6ab authored by Olivier Bertrand's avatar Olivier Bertrand

- Begin implementation of BSON

  modified:   storage/connect/bson.cpp
  modified:   storage/connect/bson.h
  modified:   storage/connect/bsonudf.cpp
  modified:   storage/connect/bsonudf.h
  modified:   storage/connect/jsonudf.cpp
parent b656d3d3
......@@ -653,7 +653,7 @@ PSZ BDOC::Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty) {
err = SerializeValue(MVP(bvp->To_Val));
break;
default:
strcpy(g->Message, "Invalid json tree");
err = SerializeValue(bvp);
} // endswitch Type
if (fs) {
......@@ -760,7 +760,7 @@ bool BDOC::SerializeObject(OFFSET obp) {
bool BDOC::SerializeValue(PBVAL jvp) {
char buf[64];
switch (jvp->Type) {
if (jvp) switch (jvp->Type) {
case TYPE_JAR:
return SerializeArray(jvp->To_Val, false);
case TYPE_JOB:
......@@ -788,8 +788,7 @@ bool BDOC::SerializeValue(PBVAL jvp) {
return jp->WriteStr("???"); // TODO
} // endswitch Type
strcpy(jp->g->Message, "Unrecognized value");
return true;
return jp->WriteStr("null");
} // end of SerializeValue
/* --------------------------- Class BJSON --------------------------- */
......@@ -860,7 +859,7 @@ int BJSON::GetObjectSize(PBPR bop, bool b)
/***********************************************************************/
PBPR BJSON::AddPair(PGLOBAL g, PBPR bop, PSZ key, OFFSET val)
{
PBPR brp, nrp = SubAllocPair(g, MOF(key), val);
PBPR brp, nrp = SubAllocPair(g, key, val);
if (bop) {
for (brp = bop; brp->Next; brp = MPP(brp->Next));
......@@ -995,10 +994,10 @@ PBPR BJSON::SetKeyValue(PGLOBAL g, PBPR bop, OFFSET bvp, PSZ key)
prp = brp;
if (!brp)
prp->Vlp = MOF(SubAllocPair(g, MOF(key), bvp));
prp->Vlp = MOF(SubAllocPair(g, key, bvp));
} else
bop = SubAllocPair(g, MOF(key), bvp);
bop = SubAllocPair(g, key, bvp);
// Return the first pair of this object
return bop;
......@@ -1094,7 +1093,7 @@ PBVAL BJSON::AddArrayValue(PGLOBAL g, PBVAL bap, PBVAL nvp, int* x)
nvp = SubAllocVal(g);
if (bap) {
int i = 0, n = *x;
int i = 0, n = (x) ? *x : INT_MAX32;
PBVAL bvp;
for (bvp = bap; bvp; bvp = MVP(bvp->Next), i++)
......@@ -1240,7 +1239,7 @@ PBVAL BJSON::SubAllocVal(PGLOBAL g)
bvp->To_Val = 0;
bvp->Nd = 0;
bvp->Type = TYPE_UNKNOWN;
bvp->Type = TYPE_NULL;
bvp->Next = 0;
return bvp;
} // end of SubAllocVal
......
......@@ -76,8 +76,14 @@ class BJSON : public BLOCK {
// SubAlloc functions
void* BsonSubAlloc(PGLOBAL g, size_t size);
PBPR SubAllocPair(PGLOBAL g, OFFSET key, OFFSET val = 0);
PBPR SubAllocPair(PGLOBAL g, PSZ key, OFFSET val = 0)
{return SubAllocPair(g, MOF(key), val);}
PBVAL SubAllocVal(PGLOBAL g);
PBVAL SubAllocVal(PGLOBAL g, OFFSET toval, int type = TYPE_UNKNOWN, short nd = 0);
PBVAL SubAllocVal(PGLOBAL g, OFFSET toval, int type = TYPE_NULL, short nd = 0);
PBVAL SubAllocVal(PGLOBAL g, PBVAL toval, int type = TYPE_NULL, short nd = 0)
{return SubAllocVal(g, MOF(toval), type, nd);}
PBVAL SubAllocVal(PGLOBAL g, PSZ str, int type = TYPE_STRG, short nd = 0)
{return SubAllocVal(g, MOF(str), type, nd);}
PBVAL SubAllocVal(PGLOBAL g, PVAL valp);
PBVAL DupVal(PGLOBAL g, PBVAL bvp);
......
This diff is collapsed.
......@@ -83,16 +83,28 @@ class BJNX : public BDOC {
}; // end of class BJNX
extern "C" {
DllExport my_bool json_test_bson_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* json_test_bson(UDF_EXEC_ARGS);
DllExport void json_test_bson_deinit(UDF_INIT*);
DllExport my_bool bson_test_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* bson_test(UDF_EXEC_ARGS);
DllExport void bson_test_deinit(UDF_INIT*);
DllExport my_bool jsonlocate_bson_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* jsonlocate_bson(UDF_EXEC_ARGS);
DllExport void jsonlocate_bson_deinit(UDF_INIT*);
DllExport my_bool bsonvalue_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* bsonvalue(UDF_EXEC_ARGS);
DllExport void bsonvalue_deinit(UDF_INIT*);
DllExport my_bool json_locate_all_bson_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* json_locate_all_bson(UDF_EXEC_ARGS);
DllExport void json_locate_all_bson_deinit(UDF_INIT*);
DllExport my_bool bson_make_array_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* bson_make_array(UDF_EXEC_ARGS);
DllExport void bson_make_array_deinit(UDF_INIT*);
DllExport my_bool bson_array_add_values_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* bson_array_add_values(UDF_EXEC_ARGS);
DllExport void bson_array_add_values_deinit(UDF_INIT*);
DllExport my_bool bsonlocate_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* bsonlocate(UDF_EXEC_ARGS);
DllExport void bsonlocate_deinit(UDF_INIT*);
DllExport my_bool bson_locate_all_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* bson_locate_all(UDF_EXEC_ARGS);
DllExport void bson_locate_all_deinit(UDF_INIT*);
} // extern "C"
......@@ -1950,6 +1950,8 @@ static PJVAL MakeTypedValue(PGLOBAL g, UDF_ARGS *args, uint i,
return jvp;
} // end of MakeTypedValue
/* ------------------------------ The JSON UDF's ------------------------------- */
/*********************************************************************************/
/* Make a Json value containing the parameter. */
/*********************************************************************************/
......
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