Commit 4eeadedc authored by Olivier Bertrand's avatar Olivier Bertrand

- Fix json_bjson (s was erase by Json_Subset)

  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/jsonudf.h

- Fix compile error (Force_Bson was not conditional by BSON_SUPPORT)
  modified:   storage/connect/ha_connect.cc

- Continue Bjson implementation
  modified:   storage/connect/block.h
  modified:   storage/connect/bson.cpp
  modified:   storage/connect/bson.h
  modified:   storage/connect/bsonudf.cpp
  modified:   storage/connect/bsonudf.h
  modified:   storage/connect/plugutil.cpp
  modified:   storage/connect/tabbson.cpp
  modified:   storage/connect/tabjson.cpp

- Typo
  deleted:    storage/connect/Header.h
parent 871532c3
This diff is collapsed.
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
/* global pointer of the Plug application, and an optional pointer to */ /* global pointer of the Plug application, and an optional pointer to */
/* the memory pool to use, defaulting to NULL meaning using the Plug */ /* the memory pool to use, defaulting to NULL meaning using the Plug */
/* standard default memory pool, example: */ /* standard default memory pool, example: */
/* tabp = new(g) XTAB("EMPLOYEE"); */ /* tabp = new(g) XTAB("EMPLOYEE"); */
/* allocates a XTAB class object in the standard Plug memory pool. */ /* allocates a XTAB class object in the standard Plug memory pool. */
/***********************************************************************/ /***********************************************************************/
#if !defined(BLOCK_DEFINED) #if !defined(BLOCK_DEFINED)
#define BLOCK_DEFINED #define BLOCK_DEFINED
......
/*************** json CPP Declares Source Code File (.H) ***************/ /*************** bson CPP Declares Source Code File (.H) ***************/
/* Name: json.cpp Version 1.5 */ /* Name: bson.cpp Version 1.0 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2020 */ /* (C) Copyright to the author Olivier BERTRAND 2020 */
/* */ /* */
/* This file contains the JSON classes functions. */ /* This file contains the BJSON classes functions. */
/***********************************************************************/ /***********************************************************************/
/***********************************************************************/ /***********************************************************************/
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
/* Include application header files: */ /* Include application header files: */
/* global.h is header containing all global declarations. */ /* global.h is header containing all global declarations. */
/* plgdbsem.h is header containing the DB application declarations. */ /* plgdbsem.h is header containing the DB application declarations. */
/* xjson.h is header containing the JSON classes declarations. */ /* bson.h is header containing the BSON classes declarations. */
/***********************************************************************/ /***********************************************************************/
#include "global.h" #include "global.h"
#include "plgdbsem.h" #include "plgdbsem.h"
...@@ -112,6 +112,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -112,6 +112,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
{ {
int i, pretty = (ptyp) ? *ptyp : 3; int i, pretty = (ptyp) ? *ptyp : 3;
bool b = false; bool b = false;
PBVAL bvp = NULL;
s = js; s = js;
len = lng; len = lng;
...@@ -128,26 +129,26 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -128,26 +129,26 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
pty[0] = false; pty[0] = false;
try { try {
Bvp = NewVal(); bvp = NewVal();
Bvp->Type = TYPE_UNKNOWN; bvp->Type = TYPE_UNKNOWN;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
switch (s[i]) { switch (s[i]) {
case '[': case '[':
if (Bvp->Type != TYPE_UNKNOWN) if (bvp->Type != TYPE_UNKNOWN)
Bvp->To_Val = ParseAsArray(i, pretty, ptyp); bvp->To_Val = ParseAsArray(i, pretty, ptyp);
else else
Bvp->To_Val = ParseArray(++i); bvp->To_Val = ParseArray(++i);
Bvp->Type = TYPE_JAR; bvp->Type = TYPE_JAR;
break; break;
case '{': case '{':
if (Bvp->Type != TYPE_UNKNOWN) { if (bvp->Type != TYPE_UNKNOWN) {
Bvp->To_Val = ParseAsArray(i, pretty, ptyp); bvp->To_Val = ParseAsArray(i, pretty, ptyp);
Bvp->Type = TYPE_JAR; bvp->Type = TYPE_JAR;
} else { } else {
Bvp->To_Val = ParseObject(++i); bvp->To_Val = ParseObject(++i);
Bvp->Type = TYPE_JOB; bvp->Type = TYPE_JOB;
} // endif Type } // endif Type
break; break;
...@@ -157,7 +158,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -157,7 +158,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
case '\r': case '\r':
break; break;
case ',': case ',':
if (Bvp->Type != TYPE_UNKNOWN && (pretty == 1 || pretty == 3)) { if (bvp->Type != TYPE_UNKNOWN && (pretty == 1 || pretty == 3)) {
if (comma) if (comma)
*comma = true; *comma = true;
...@@ -177,18 +178,18 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -177,18 +178,18 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
} // endif b } // endif b
default: default:
if (Bvp->Type != TYPE_UNKNOWN) { if (bvp->Type != TYPE_UNKNOWN) {
Bvp->To_Val = ParseAsArray(i, pretty, ptyp); bvp->To_Val = ParseAsArray(i, pretty, ptyp);
Bvp->Type = TYPE_JAR; bvp->Type = TYPE_JAR;
} else if ((Bvp->To_Val = MOF(ParseValue(i)))) } else if ((bvp->To_Val = MOF(ParseValue(i))))
Bvp->Type = TYPE_JVAL; bvp->Type = TYPE_JVAL;
else else
throw 4; throw 4;
break; break;
}; // endswitch s[i] }; // endswitch s[i]
if (Bvp->Type == TYPE_UNKNOWN) if (bvp->Type == TYPE_UNKNOWN)
sprintf(g->Message, "Invalid Json string '%.*s'", MY_MIN((int)len, 50), s); sprintf(g->Message, "Invalid Json string '%.*s'", MY_MIN((int)len, 50), s);
else if (ptyp && pretty == 3) { else if (ptyp && pretty == 3) {
*ptyp = 3; // Not recognized pretty *ptyp = 3; // Not recognized pretty
...@@ -205,13 +206,13 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -205,13 +206,13 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
if (trace(1)) if (trace(1))
htrc("Exception %d: %s\n", n, G->Message); htrc("Exception %d: %s\n", n, G->Message);
GetMsg(g); GetMsg(g);
Bvp = NULL; bvp = NULL;
} catch (const char* msg) { } catch (const char* msg) {
strcpy(g->Message, msg); strcpy(g->Message, msg);
Bvp = NULL; bvp = NULL;
} // end catch } // end catch
return Bvp; return bvp;
} // end of ParseJson } // end of ParseJson
/***********************************************************************/ /***********************************************************************/
...@@ -391,13 +392,11 @@ PBVAL BDOC::ParseValue(int& i) ...@@ -391,13 +392,11 @@ PBVAL BDOC::ParseValue(int& i)
bvp->Type = TYPE_JOB; bvp->Type = TYPE_JOB;
break; break;
case '"': case '"':
// jvp->Val = AllocVal(g, TYPE_STRG);
bvp->To_Val = ParseString(++i); bvp->To_Val = ParseString(++i);
bvp->Type = TYPE_STRG; bvp->Type = TYPE_STRG;
break; break;
case 't': case 't':
if (!strncmp(s + i, "true", 4)) { if (!strncmp(s + i, "true", 4)) {
// jvp->Val = AllocVal(g, TYPE_BOOL);
bvp->B = true; bvp->B = true;
bvp->Type = TYPE_BOOL; bvp->Type = TYPE_BOOL;
i += 3; i += 3;
...@@ -407,7 +406,6 @@ PBVAL BDOC::ParseValue(int& i) ...@@ -407,7 +406,6 @@ PBVAL BDOC::ParseValue(int& i)
break; break;
case 'f': case 'f':
if (!strncmp(s + i, "false", 5)) { if (!strncmp(s + i, "false", 5)) {
// jvp->Val = AllocVal(g, TYPE_BOOL);
bvp->B = false; bvp->B = false;
bvp->Type = TYPE_BOOL; bvp->Type = TYPE_BOOL;
i += 4; i += 4;
...@@ -872,7 +870,7 @@ void BJSON::SubSet(bool b) ...@@ -872,7 +870,7 @@ void BJSON::SubSet(bool b)
if (b) if (b)
G->Saved_Size = 0; G->Saved_Size = 0;
} /* end of JsonSubSet */ } // end of SubSet
/* ------------------------ Bobject functions ------------------------ */ /* ------------------------ Bobject functions ------------------------ */
......
#pragma once
/**************** bson H Declares Source Code File (.H) ****************/ /**************** bson H Declares Source Code File (.H) ****************/
/* Name: bson.h Version 1.0 */ /* Name: bson.h Version 1.0 */
/* */ /* */
...@@ -6,6 +5,7 @@ ...@@ -6,6 +5,7 @@
/* */ /* */
/* This file contains the BSON classe declares. */ /* This file contains the BSON classe declares. */
/***********************************************************************/ /***********************************************************************/
#pragma once
#include <mysql_com.h> #include <mysql_com.h>
#include "json.h" #include "json.h"
#include "xobject.h" #include "xobject.h"
...@@ -189,130 +189,3 @@ class BDOC : public BJSON { ...@@ -189,130 +189,3 @@ class BDOC : public BJSON {
// Default constructor not to be used // Default constructor not to be used
BDOC(void) {} BDOC(void) {}
}; // end of class BDOC }; // end of class BDOC
#if 0
/***********************************************************************/
/* Class JOBJECT: contains a list of value pairs. */
/***********************************************************************/
class JOBJECT : public JSON {
friend class JDOC;
friend class JSNX;
friend class SWAP;
public:
JOBJECT(void) : JSON() { Type = TYPE_JOB; First = Last = NULL; }
JOBJECT(int i) : JSON(i) {}
// Methods
virtual void Clear(void) { First = Last = NULL; }
virtual PJPR GetFirst(void) { return First; }
virtual int GetSize(PBPR prp, bool b);
virtual PJOB GetObject(void) { return this; }
virtual PSZ GetText(PGLOBAL g, PSTRG text);
virtual bool Merge(PGLOBAL g, PJSON jsp);
virtual bool IsNull(void);
// Specific
PJPR AddPair(PGLOBAL g, PCSZ key);
PJVAL GetKeyValue(const char* key);
PJAR GetKeyList(PGLOBAL g);
PJAR GetValList(PGLOBAL g);
void SetKeyValue(PGLOBAL g, PJVAL jvp, PCSZ key);
void DeleteKey(PCSZ k);
protected:
PJPR First;
PJPR Last;
}; // end of class JOBJECT
/***********************************************************************/
/* Class JARRAY. */
/***********************************************************************/
class JARRAY : public JSON {
friend class SWAP;
public:
JARRAY(void);
JARRAY(int i) : JSON(i) {}
// Methods
virtual void Clear(void) { First = Last = NULL; Size = 0; }
virtual int size(void) { return Size; }
virtual PJAR GetArray(void) { return this; }
virtual int GetSize(bool b);
virtual PJVAL GetArrayValue(int i);
virtual PSZ GetText(PGLOBAL g, PSTRG text);
virtual bool Merge(PGLOBAL g, PJSON jsp);
virtual bool DeleteValue(int n);
virtual bool IsNull(void);
// Specific
PJVAL AddArrayValue(PGLOBAL g, PJVAL jvp = NULL, int* x = NULL);
bool SetArrayValue(PGLOBAL g, PJVAL jvp, int i);
void InitArray(PGLOBAL g);
protected:
// Members
int Size; // The number of items in the array
int Alloc; // The Mvals allocated size
PJVAL First; // Used when constructing
PJVAL Last; // Last constructed value
PJVAL* Mvals; // Allocated when finished
}; // end of class JARRAY
/***********************************************************************/
/* Class JVALUE. */
/***********************************************************************/
class JVALUE : public JSON {
friend class JARRAY;
friend class JSNX;
friend class JSONDISC;
friend class JSONCOL;
friend class JSON;
friend class JDOC;
friend class SWAP;
public:
JVALUE(void) : JSON() { Type = TYPE_JVAL; Clear(); }
JVALUE(PJSON jsp);
JVALUE(PGLOBAL g, PVAL valp);
JVALUE(PGLOBAL g, PCSZ strp);
JVALUE(int i) : JSON(i) {}
// Methods
virtual void Clear(void);
//virtual JTYP GetType(void) {return TYPE_JVAL;}
virtual JTYP GetValType(void);
virtual PJOB GetObject(void);
virtual PJAR GetArray(void);
virtual PJSON GetJsp(void) { return (DataType == TYPE_JSON ? Jsp : NULL); }
virtual PSZ GetText(PGLOBAL g, PSTRG text);
virtual bool IsNull(void);
// Specific
inline PJSON GetJson(void) { return (DataType == TYPE_JSON ? Jsp : this); }
PSZ GetString(PGLOBAL g, char* buff = NULL);
int GetInteger(void);
long long GetBigint(void);
double GetFloat(void);
PVAL GetValue(PGLOBAL g);
void SetValue(PJSON jsp);
void SetValue(PGLOBAL g, PVAL valp);
void SetString(PGLOBAL g, PSZ s, int ci = 0);
void SetInteger(PGLOBAL g, int n);
void SetBigint(PGLOBAL g, longlong ll);
void SetFloat(PGLOBAL g, double f);
void SetBool(PGLOBAL g, bool b);
protected:
union {
PJSON Jsp; // To the json value
char* Strp; // Ptr to a string
int N; // An integer value
long long LLn; // A big integer value
double F; // A (double) float value
bool B; // True or false
};
PJVAL Next; // Next value in array
JTYP DataType; // The data value type
int Nd; // Decimal number
bool Del; // True when deleted
}; // end of class JVALUE
#endif // 0
...@@ -1706,3 +1706,127 @@ void bson_locate_all_deinit(UDF_INIT* initid) { ...@@ -1706,3 +1706,127 @@ void bson_locate_all_deinit(UDF_INIT* initid) {
JsonFreeMem((PGLOBAL)initid->ptr); JsonFreeMem((PGLOBAL)initid->ptr);
} // end of bson_locate_all_deinit } // end of bson_locate_all_deinit
/*********************************************************************************/
/* Convert a pretty=0 Json file to binary BJSON. */
/*********************************************************************************/
my_bool bfile_bjson_init(UDF_INIT* initid, UDF_ARGS* args, char* message) {
unsigned long reslen, memlen;
if (args->arg_count != 2 && args->arg_count != 3) {
strcpy(message, "This function must have 2 or 3 arguments");
return true;
} else if (args->arg_count == 3 && args->arg_type[2] != INT_RESULT) {
strcpy(message, "Third Argument must be an integer (LRECL)");
return true;
} else for (int i = 0; i < 2; i++)
if (args->arg_type[i] != STRING_RESULT) {
sprintf(message, "Arguments %d must be a string (file name)", i + 1);
return true;
} // endif args
CalcLen(args, false, reslen, memlen);
memlen = memlen * M;
memlen += (args->arg_count == 3) ? (ulong)*(longlong*)args->args[2] : 1024;
return JsonInit(initid, args, message, false, reslen, memlen);
} // end of bfile_bjson_init
char *bfile_bjson(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char*, char *error) {
char *buf, *str = NULL, fn[_MAX_PATH], ofn[_MAX_PATH];
bool loop;
ssize_t len, newloc;
size_t lrecl, binszp;
PBVAL jsp;
PBJNX bnxp;
PGLOBAL g = (PGLOBAL)initid->ptr;
BDOC doc(g);
strcpy(fn, MakePSZ(g, args, 0));
strcpy(ofn, MakePSZ(g, args, 1));
if (args->arg_count == 3)
lrecl = (size_t)*(longlong*)args->args[2];
else
lrecl = 1024;
if (!g->Xchk) {
int msgid = MSGID_OPEN_MODE_STRERROR;
FILE *fout;
FILE *fin;
if (!(fin = global_fopen(g, msgid, fn, "rt")))
str = strcpy(result, g->Message);
else if (!(fout = global_fopen(g, msgid, ofn, "wb")))
str = strcpy(result, g->Message);
else if ((buf = (char*)malloc(lrecl))) {
try {
do {
loop = false;
PlugSubSet(g->Sarea, g->Sarea_Size);
if (!fgets(buf, lrecl, fin)) {
if (!feof(fin)) {
sprintf(g->Message, "Error %d reading %zd bytes from %s",
errno, lrecl, fn);
str = strcpy(result, g->Message);
} else
str = strcpy(result, ofn);
} else if ((len = strlen(buf))) {
if ((jsp = doc.ParseJson(g, buf, len))) {
newloc = (size_t)PlugSubAlloc(g, NULL, 0);
binszp = newloc - (size_t)jsp;
if (fwrite(&binszp, sizeof(binszp), 1, fout) != 1) {
sprintf(g->Message, "Error %d writing %zd bytes to %s",
errno, sizeof(binszp), ofn);
str = strcpy(result, g->Message);
} else if (fwrite(jsp, binszp, 1, fout) != 1) {
sprintf(g->Message, "Error %d writing %zd bytes to %s",
errno, binszp, ofn);
str = strcpy(result, g->Message);
} else
loop = true;
} else {
str = strcpy(result, g->Message);
} // endif jsp
} else
loop = true;
} while (loop);
} catch (int) {
str = strcpy(result, g->Message);
} catch (const char* msg) {
str = strcpy(result, msg);
} // end catch
free(buf);
} else
str = strcpy(result, "Buffer malloc failed");
if (fin) fclose(fin);
if (fout) fclose(fout);
g->Xchk = str;
} else
str = (char*)g->Xchk;
if (!str) {
if (g->Message)
str = strcpy(result, g->Message);
else
str = strcpy(result, "Unexpected error");
} // endif str
*res_length = strlen(str);
return str;
} // end of bfile_bjson
void bfile_bjson_deinit(UDF_INIT* initid) {
JsonFreeMem((PGLOBAL)initid->ptr);
} // end of bfile_bjson_deinit
...@@ -106,5 +106,8 @@ extern "C" { ...@@ -106,5 +106,8 @@ extern "C" {
DllExport my_bool bson_locate_all_init(UDF_INIT*, UDF_ARGS*, char*); DllExport my_bool bson_locate_all_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* bson_locate_all(UDF_EXEC_ARGS); DllExport char* bson_locate_all(UDF_EXEC_ARGS);
DllExport void bson_locate_all_deinit(UDF_INIT*); DllExport void bson_locate_all_deinit(UDF_INIT*);
} // extern "C"
DllExport my_bool bfile_bjson_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* bfile_bjson(UDF_EXEC_ARGS);
DllExport void bfile_bjson_deinit(UDF_INIT*);
} // extern "C"
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
#define JSONMAX 10 // JSON Default max grp size #define JSONMAX 10 // JSON Default max grp size
extern "C" { extern "C" {
char version[]= "Version 1.07.0002 December 07, 2020"; char version[]= "Version 1.07.0002 December 12, 2020";
#if defined(__WIN__) #if defined(__WIN__)
char compver[]= "Version 1.07.0002 " __DATE__ " " __TIME__; char compver[]= "Version 1.07.0002 " __DATE__ " " __TIME__;
char slash= '\\'; char slash= '\\';
...@@ -516,7 +516,9 @@ char *GetJavaWrapper(void) ...@@ -516,7 +516,9 @@ char *GetJavaWrapper(void)
bool MongoEnabled(void) {return THDVAR(current_thd, enable_mongo);} bool MongoEnabled(void) {return THDVAR(current_thd, enable_mongo);}
#endif // JAVA_SUPPORT || CMGO_SUPPORT #endif // JAVA_SUPPORT || CMGO_SUPPORT
#if defined(BSON_SUPPORT)
bool Force_Bson(void) {return THDVAR(current_thd, force_bson);} bool Force_Bson(void) {return THDVAR(current_thd, force_bson);}
#endif // BSON_SUPPORT)
#if defined(XMSG) || defined(NEWMSG) #if defined(XMSG) || defined(NEWMSG)
extern "C" const char *msglang(void) extern "C" const char *msglang(void)
......
...@@ -1174,13 +1174,16 @@ static uint GetJsonGroupSize(void) ...@@ -1174,13 +1174,16 @@ static uint GetJsonGroupSize(void)
/*********************************************************************************/ /*********************************************************************************/
/* Program for SubSet re-initialization of the memory pool. */ /* Program for SubSet re-initialization of the memory pool. */
/*********************************************************************************/ /*********************************************************************************/
my_bool JsonSubSet(PGLOBAL g) my_bool JsonSubSet(PGLOBAL g, my_bool b)
{ {
PPOOLHEADER pph = (PPOOLHEADER)g->Sarea; PPOOLHEADER pph = (PPOOLHEADER)g->Sarea;
pph->To_Free = (g->Saved_Size) ? g->Saved_Size : sizeof(POOLHEADER); pph->To_Free = (g->Saved_Size) ? g->Saved_Size : sizeof(POOLHEADER);
pph->FreeBlk = g->Sarea_Size - pph->To_Free; pph->FreeBlk = g->Sarea_Size - pph->To_Free;
g->Saved_Size = 0;
if (b)
g->Saved_Size = 0;
return FALSE; return FALSE;
} /* end of JsonSubSet */ } /* end of JsonSubSet */
...@@ -1458,7 +1461,7 @@ int IsJson(UDF_ARGS *args, uint i, bool b) ...@@ -1458,7 +1461,7 @@ int IsJson(UDF_ARGS *args, uint i, bool b)
char *sap; char *sap;
PGLOBAL g = PlugInit(NULL, (size_t)args->lengths[i] * M + 1024); PGLOBAL g = PlugInit(NULL, (size_t)args->lengths[i] * M + 1024);
JsonSubSet(g); // JsonSubSet(g);
sap = MakePSZ(g, args, i); sap = MakePSZ(g, args, i);
if (ParseJson(g, sap, strlen(sap))) if (ParseJson(g, sap, strlen(sap)))
......
...@@ -53,13 +53,13 @@ typedef struct _jnode { ...@@ -53,13 +53,13 @@ typedef struct _jnode {
typedef class JSNX *PJSNX; typedef class JSNX *PJSNX;
/*********************************************************************************/ /*********************************************************************************/
/* The JSON tree node. Can be an Object or an Array. */ /* The JSON utility functions. */
/*********************************************************************************/ /*********************************************************************************/
bool IsNum(PSZ s); bool IsNum(PSZ s);
char *NextChr(PSZ s, char sep); char *NextChr(PSZ s, char sep);
char *GetJsonNull(void); char *GetJsonNull(void);
uint GetJsonGrpSize(void); uint GetJsonGrpSize(void);
my_bool JsonSubSet(PGLOBAL g); my_bool JsonSubSet(PGLOBAL g, my_bool b = false);
my_bool CalcLen(UDF_ARGS* args, my_bool obj, unsigned long& reslen, my_bool CalcLen(UDF_ARGS* args, my_bool obj, unsigned long& reslen,
unsigned long& memlen, my_bool mod = false); unsigned long& memlen, my_bool mod = false);
my_bool JsonInit(UDF_INIT* initid, UDF_ARGS* args, char* message, my_bool mbn, my_bool JsonInit(UDF_INIT* initid, UDF_ARGS* args, char* message, my_bool mbn,
......
...@@ -96,7 +96,7 @@ char *msglang(void); ...@@ -96,7 +96,7 @@ char *msglang(void);
typedef struct { typedef struct {
ushort Segsize; ushort Segsize;
ushort Size; ushort Size;
} AREASIZE; } AREASIZE;
ACTIVITY defActivity = { /* Describes activity and language */ ACTIVITY defActivity = { /* Describes activity and language */
NULL, /* Points to user work area(s) */ NULL, /* Points to user work area(s) */
...@@ -204,7 +204,7 @@ PGLOBAL PlugExit(PGLOBAL g) ...@@ -204,7 +204,7 @@ PGLOBAL PlugExit(PGLOBAL g)
/* Note: this routine is not really implemented for Unix. */ /* Note: this routine is not really implemented for Unix. */
/***********************************************************************/ /***********************************************************************/
LPSTR PlugRemoveType(LPSTR pBuff, LPCSTR FileName) LPSTR PlugRemoveType(LPSTR pBuff, LPCSTR FileName)
{ {
#if defined(__WIN__) #if defined(__WIN__)
char drive[_MAX_DRIVE]; char drive[_MAX_DRIVE];
#else #else
...@@ -228,8 +228,7 @@ LPSTR PlugRemoveType(LPSTR pBuff, LPCSTR FileName) ...@@ -228,8 +228,7 @@ LPSTR PlugRemoveType(LPSTR pBuff, LPCSTR FileName)
htrc("buff='%s'\n", pBuff); htrc("buff='%s'\n", pBuff);
return pBuff; return pBuff;
} // end of PlugRemoveType } // end of PlugRemoveType
BOOL PlugIsAbsolutePath(LPCSTR path) BOOL PlugIsAbsolutePath(LPCSTR path)
{ {
...@@ -246,7 +245,7 @@ BOOL PlugIsAbsolutePath(LPCSTR path) ...@@ -246,7 +245,7 @@ BOOL PlugIsAbsolutePath(LPCSTR path)
/* Note: this routine is not really implemented for Unix. */ /* Note: this routine is not really implemented for Unix. */
/***********************************************************************/ /***********************************************************************/
LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath) LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath)
{ {
char newname[_MAX_PATH]; char newname[_MAX_PATH];
char direc[_MAX_DIR], defdir[_MAX_DIR], tmpdir[_MAX_DIR]; char direc[_MAX_DIR], defdir[_MAX_DIR], tmpdir[_MAX_DIR];
char fname[_MAX_FNAME]; char fname[_MAX_FNAME];
...@@ -347,14 +346,14 @@ LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath) ...@@ -347,14 +346,14 @@ LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath)
} else } else
return FileName; // Error, return unchanged name return FileName; // Error, return unchanged name
} // end of PlugSetPath } // end of PlugSetPath
#if defined(XMSG) #if defined(XMSG)
/***********************************************************************/ /***********************************************************************/
/* PlugGetMessage: get a message from the message file. */ /* PlugGetMessage: get a message from the message file. */
/***********************************************************************/ /***********************************************************************/
char *PlugReadMessage(PGLOBAL g, int mid, char *m) char *PlugReadMessage(PGLOBAL g, int mid, char *m)
{ {
char msgfile[_MAX_PATH], msgid[32], buff[256]; char msgfile[_MAX_PATH], msgid[32], buff[256];
char *msg; char *msg;
FILE *mfile = NULL; FILE *mfile = NULL;
...@@ -405,14 +404,14 @@ char *PlugReadMessage(PGLOBAL g, int mid, char *m) ...@@ -405,14 +404,14 @@ char *PlugReadMessage(PGLOBAL g, int mid, char *m)
msg = stmsg; msg = stmsg;
return msg; return msg;
} // end of PlugReadMessage } // end of PlugReadMessage
#elif defined(NEWMSG) #elif defined(NEWMSG)
/***********************************************************************/ /***********************************************************************/
/* PlugGetMessage: get a message from the resource string table. */ /* PlugGetMessage: get a message from the resource string table. */
/***********************************************************************/ /***********************************************************************/
char *PlugGetMessage(PGLOBAL g, int mid) char *PlugGetMessage(PGLOBAL g, int mid)
{ {
char *msg; char *msg;
#if 0 // was !defined(UNIX) && !defined(UNIV_LINUX) #if 0 // was !defined(UNIX) && !defined(UNIV_LINUX)
...@@ -440,7 +439,7 @@ char *PlugGetMessage(PGLOBAL g, int mid) ...@@ -440,7 +439,7 @@ char *PlugGetMessage(PGLOBAL g, int mid)
msg = stmsg; msg = stmsg;
return msg; return msg;
} // end of PlugGetMessage } // end of PlugGetMessage
#endif // NEWMSG #endif // NEWMSG
#if defined(__WIN__) #if defined(__WIN__)
...@@ -448,13 +447,13 @@ char *PlugGetMessage(PGLOBAL g, int mid) ...@@ -448,13 +447,13 @@ char *PlugGetMessage(PGLOBAL g, int mid)
/* Return the line length of the console screen buffer. */ /* Return the line length of the console screen buffer. */
/***********************************************************************/ /***********************************************************************/
short GetLineLength(PGLOBAL g) short GetLineLength(PGLOBAL g)
{ {
CONSOLE_SCREEN_BUFFER_INFO coninfo; CONSOLE_SCREEN_BUFFER_INFO coninfo;
HANDLE hcons = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hcons = GetStdHandle(STD_OUTPUT_HANDLE);
BOOL b = GetConsoleScreenBufferInfo(hcons, &coninfo); BOOL b = GetConsoleScreenBufferInfo(hcons, &coninfo);
return (b) ? coninfo.dwSize.X : 0; return (b) ? coninfo.dwSize.X : 0;
} // end of GetLineLength } // end of GetLineLength
#endif // __WIN__ #endif // __WIN__
/***********************************************************************/ /***********************************************************************/
...@@ -527,13 +526,13 @@ void FreeSarea(PGLOBAL g) ...@@ -527,13 +526,13 @@ void FreeSarea(PGLOBAL g)
/* the address and size not larger than memory size. */ /* the address and size not larger than memory size. */
/***********************************************************************/ /***********************************************************************/
BOOL PlugSubSet(void *memp, size_t size) BOOL PlugSubSet(void *memp, size_t size)
{ {
PPOOLHEADER pph = (PPOOLHEADER)memp; PPOOLHEADER pph = (PPOOLHEADER)memp;
pph->To_Free = (size_t)sizeof(POOLHEADER); pph->To_Free = (size_t)sizeof(POOLHEADER);
pph->FreeBlk = size - pph->To_Free; pph->FreeBlk = size - pph->To_Free;
return FALSE; return FALSE;
} /* end of PlugSubSet */ } /* end of PlugSubSet */
/***********************************************************************/ /***********************************************************************/
/* Use it to export a function that do throwing. */ /* Use it to export a function that do throwing. */
...@@ -596,7 +595,7 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size) ...@@ -596,7 +595,7 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size)
/* Program for sub-allocating and copying a string in a storage area. */ /* Program for sub-allocating and copying a string in a storage area. */
/***********************************************************************/ /***********************************************************************/
char *PlugDup(PGLOBAL g, const char *str) char *PlugDup(PGLOBAL g, const char *str)
{ {
if (str) { if (str) {
char *sm = (char*)PlugSubAlloc(g, NULL, strlen(str) + 1); char *sm = (char*)PlugSubAlloc(g, NULL, strlen(str) + 1);
...@@ -605,12 +604,13 @@ char *PlugDup(PGLOBAL g, const char *str) ...@@ -605,12 +604,13 @@ char *PlugDup(PGLOBAL g, const char *str)
} else } else
return NULL; return NULL;
} // end of PlugDup } // end of PlugDup
/*************************************************************************/ /*************************************************************************/
/* This routine makes a pointer from an offset to a memory pointer. */ /* This routine makes a pointer from an offset to a memory pointer. */
/*************************************************************************/ /*************************************************************************/
void* MakePtr(void* memp, size_t offset) { void* MakePtr(void* memp, size_t offset)
{
// return ((offset == 0) ? NULL : &((char*)memp)[offset]); // return ((offset == 0) ? NULL : &((char*)memp)[offset]);
return (!offset) ? NULL : (char *)memp + offset; return (!offset) ? NULL : (char *)memp + offset;
} /* end of MakePtr */ } /* end of MakePtr */
...@@ -618,11 +618,14 @@ void* MakePtr(void* memp, size_t offset) { ...@@ -618,11 +618,14 @@ void* MakePtr(void* memp, size_t offset) {
/*************************************************************************/ /*************************************************************************/
/* This routine makes an offset from a pointer new format. */ /* This routine makes an offset from a pointer new format. */
/*************************************************************************/ /*************************************************************************/
size_t MakeOff(void* memp, void* ptr) { size_t MakeOff(void* memp, void* ptr)
{
if (ptr) { if (ptr) {
#if defined(_DEBUG) || defined(DEVELOPMENT) #if defined(_DEBUG) || defined(DEVELOPMENT)
if (ptr <= memp) if (ptr <= memp) {
fprintf(stderr, "ptr %p <= memp %p", ptr, memp); fprintf(stderr, "ptr %p <= memp %p", ptr, memp);
throw 999;
} // endif ptr
#endif // _DEBUG || DEVELOPMENT #endif // _DEBUG || DEVELOPMENT
return (size_t)((char*)ptr - (size_t)memp); return (size_t)((char*)ptr - (size_t)memp);
} else } else
......
...@@ -259,7 +259,7 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) ...@@ -259,7 +259,7 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
} // endif Lrecl } // endif Lrecl
// Allocate the parse work memory // Allocate the parse work memory
tdp->G = PlugInit(NULL, (size_t)tdp->Lrecl * (tdp->Pretty >= 0 ? 6 : 2)); tdp->G = PlugInit(NULL, (size_t)tdp->Lrecl * (tdp->Pretty >= 0 ? 4 : 2));
tdp->Ending = GetIntegerTableOption(g, topt, "Ending", CRLF); tdp->Ending = GetIntegerTableOption(g, topt, "Ending", CRLF);
if (tdp->Zipped) { if (tdp->Zipped) {
...@@ -1167,7 +1167,7 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -1167,7 +1167,7 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m)
if (Lrecl) { if (Lrecl) {
// Allocate the parse work memory // Allocate the parse work memory
G = PlugInit(NULL, (size_t)Lrecl * 6); G = PlugInit(NULL, (size_t)Lrecl * 4);
} else { } else {
strcpy(g->Message, "LRECL is not defined"); strcpy(g->Message, "LRECL is not defined");
return NULL; return NULL;
...@@ -1200,7 +1200,6 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -1200,7 +1200,6 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m)
} // endif Driver } // endif Driver
} else if (Zipped) { } else if (Zipped) {
// if (Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) { if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) {
txfp = new(g) UNZFAM(this); txfp = new(g) UNZFAM(this);
...@@ -1226,9 +1225,9 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -1226,9 +1225,9 @@ PTDB BSONDEF::GetTable(PGLOBAL g, MODE m)
#endif // !GZ_SUPPORT #endif // !GZ_SUPPORT
} else if (map) } else if (map)
txfp = new(g) MAPFAM(this); txfp = new(g) MAPFAM(this);
else if (Pretty < 0) // BJsonfile else if (Pretty < 0) { // BJsonfile
txfp = new(g) BINFAM(this); txfp = new(g) BINFAM(this);
else } else
txfp = new(g) DOSFAM(this); txfp = new(g) DOSFAM(this);
// Txfp must be set for TDBBSN // Txfp must be set for TDBBSN
...@@ -1436,7 +1435,6 @@ bool TDBBSN::OpenDB(PGLOBAL g) ...@@ -1436,7 +1435,6 @@ bool TDBBSN::OpenDB(PGLOBAL g)
} // endif Use } // endif Use
if (Pretty < 0) { if (Pretty < 0) {
#if 0
/*******************************************************************/ /*******************************************************************/
/* Binary BJSON table. */ /* Binary BJSON table. */
/*******************************************************************/ /*******************************************************************/
...@@ -1450,7 +1448,7 @@ bool TDBBSN::OpenDB(PGLOBAL g) ...@@ -1450,7 +1448,7 @@ bool TDBBSN::OpenDB(PGLOBAL g)
if (!To_Kindex) { if (!To_Kindex) {
Txfp->Rewind(); // see comment in Work.log Txfp->Rewind(); // see comment in Work.log
} else // Table is to be accessed through a sorted index table } else // Table is to be accessed through a sorted index table
To_Kindex->Reset(); To_Kindex->Reset(); // TODO: NIY
return false; return false;
} // endif use } // endif use
...@@ -1469,14 +1467,12 @@ bool TDBBSN::OpenDB(PGLOBAL g) ...@@ -1469,14 +1467,12 @@ bool TDBBSN::OpenDB(PGLOBAL g)
/*********************************************************************/ /*********************************************************************/
size_t linelen = Lrecl; size_t linelen = Lrecl;
//To_Line = (char*)PlugSubAlloc(g, NULL, linelen); // Buffer should be the first allocated thing in G->Sarea
//memset(To_Line, 0, linelen); Txfp->AllocateBuffer(Bp->G);
To_Line = Txfp->GetBuf(); To_Line = Txfp->GetBuf();
memset(To_Line, 0, linelen);
Bp->MemSave();
xtrc(1, "OpenJSN: R%hd mode=%d To_Line=%p\n", Tdb_No, Mode, To_Line); xtrc(1, "OpenJSN: R%hd mode=%d To_Line=%p\n", Tdb_No, Mode, To_Line);
return false;
#endif // 0
strcpy(g->Message, "TDBBSN: Binary NIY");
return true;
} else if (TDBDOS::OpenDB(g)) } else if (TDBDOS::OpenDB(g))
return true; return true;
...@@ -1548,23 +1544,14 @@ int TDBBSN::ReadDB(PGLOBAL g) ...@@ -1548,23 +1544,14 @@ int TDBBSN::ReadDB(PGLOBAL g)
rc = RC_EF; rc = RC_EF;
} else { } else {
#if 0
// Here we get a movable Json binary tree // Here we get a movable Json binary tree
PJSON jsp; Bp->SubSet(); // Perhaps Useful when updating
SWAP* swp; Row = (PBVAL)To_Line;
Row = Bp->FindRow(g);
jsp = (PJSON)To_Line;
swp = new(g) SWAP(G, jsp);
swp->SwapJson(jsp, false); // Restore pointers from offsets
Row = jsp;
Row = FindRow(g);
SameRow = 0; SameRow = 0;
Fpos++; Fpos++;
M = 1; M = 1;
rc = RC_OK; rc = RC_OK;
#endif // 0
strcpy(g->Message, "TDBBSN: Binary NIY");
rc = RC_FX;
} // endif Pretty } // endif Pretty
} // endif ReadDB } // endif ReadDB
......
...@@ -298,14 +298,6 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) ...@@ -298,14 +298,6 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
tjnp->SetMode(MODE_READ); tjnp->SetMode(MODE_READ);
// Allocate the parse work memory // Allocate the parse work memory
#if 0
PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL));
memset(G, 0, sizeof(GLOBAL));
G->Sarea_Size = (size_t)tdp->Lrecl * (tdp->Pretty >= 0 ? 10 : 2);
G->Sarea = PlugSubAlloc(g, NULL, G->Sarea_Size);
PlugSubSet(G->Sarea, G->Sarea_Size);
G->jump_level = 0;
#endif // 0
G = PlugInit(NULL, (size_t)tdp->Lrecl * (tdp->Pretty >= 0 ? 10 : 2)); G = PlugInit(NULL, (size_t)tdp->Lrecl * (tdp->Pretty >= 0 ? 10 : 2));
tjnp->SetG(G); tjnp->SetG(G);
......
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