Commit 2113cab7 authored by Olivier Bertrand's avatar Olivier Bertrand

Make REST tables default file name. Commit before continuing BSON development

parent 24c18ce8
...@@ -101,17 +101,19 @@ BDOC::BDOC(PGLOBAL G) : BJSON(G, NULL) ...@@ -101,17 +101,19 @@ BDOC::BDOC(PGLOBAL G) : BJSON(G, NULL)
jp = NULL; jp = NULL;
s = NULL; s = NULL;
len = 0; len = 0;
pretty = 3;
pty[0] = pty[1] = pty[2] = true; pty[0] = pty[1] = pty[2] = true;
comma = false;
} // end of BDOC constructor } // end of BDOC constructor
/***********************************************************************/ /***********************************************************************/
/* Parse a json string. */ /* Parse a json string. */
/* Note: when pretty is not known, the caller set pretty to 3. */ /* Note: when pretty is not known, the caller set pretty to 3. */
/***********************************************************************/ /***********************************************************************/
PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng)
{ {
int i, pretty = (ptyp) ? *ptyp : 3; int i;
bool b = false; bool b = false, ptyp = (bool *)pty;
PBVAL bvp = NULL; PBVAL bvp = NULL;
s = js; s = js;
...@@ -121,8 +123,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -121,8 +123,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
if (!s || !len) { if (!s || !len) {
strcpy(g->Message, "Void JSON object"); strcpy(g->Message, "Void JSON object");
return NULL; return NULL;
} else if (comma) } // endif s
*comma = false;
// Trying to guess the pretty format // Trying to guess the pretty format
if (s[0] == '[' && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))) if (s[0] == '[' && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')))
...@@ -136,7 +137,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -136,7 +137,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
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);
else else
bvp->To_Val = ParseArray(++i); bvp->To_Val = ParseArray(++i);
...@@ -144,7 +145,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -144,7 +145,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
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);
bvp->Type = TYPE_JAR; bvp->Type = TYPE_JAR;
} else { } else {
bvp->To_Val = ParseObject(++i); bvp->To_Val = ParseObject(++i);
...@@ -159,9 +160,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -159,9 +160,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
break; break;
case ',': case ',':
if (bvp->Type != TYPE_UNKNOWN && (pretty == 1 || pretty == 3)) { if (bvp->Type != TYPE_UNKNOWN && (pretty == 1 || pretty == 3)) {
if (comma) comma = true;
*comma = true;
pty[0] = pty[2] = false; pty[0] = pty[2] = false;
break; break;
} // endif pretty } // endif pretty
...@@ -179,7 +178,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -179,7 +178,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
default: default:
if (bvp->Type != TYPE_UNKNOWN) { if (bvp->Type != TYPE_UNKNOWN) {
bvp->To_Val = ParseAsArray(i, pretty, ptyp); bvp->To_Val = ParseAsArray(i);
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;
...@@ -191,12 +190,10 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -191,12 +190,10 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
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 (pretty == 3) {
*ptyp = 3; // Not recognized pretty
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
if (pty[i]) { if (pty[i]) {
*ptyp = i; pretty = i;
break; break;
} // endif pty } // endif pty
...@@ -218,12 +215,12 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma) ...@@ -218,12 +215,12 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng, int* ptyp, bool* comma)
/***********************************************************************/ /***********************************************************************/
/* Parse several items as being in an array. */ /* Parse several items as being in an array. */
/***********************************************************************/ /***********************************************************************/
OFFSET BDOC::ParseAsArray(int& i, int pretty, int* ptyp) { OFFSET BDOC::ParseAsArray(int& i) {
if (pty[0] && (!pretty || pretty > 2)) { if (pty[0] && (!pretty || pretty > 2)) {
OFFSET jsp; OFFSET jsp;
if ((jsp = ParseArray((i = 0))) && ptyp && pretty == 3) if ((jsp = ParseArray((i = 0))) && pretty == 3)
*ptyp = (pty[0]) ? 0 : 3; pretty = (pty[0]) ? 0 : 3;
return jsp; return jsp;
} else } else
......
...@@ -167,7 +167,12 @@ class BDOC : public BJSON { ...@@ -167,7 +167,12 @@ class BDOC : public BJSON {
public: public:
BDOC(PGLOBAL G); BDOC(PGLOBAL G);
PBVAL ParseJson(PGLOBAL g, char* s, size_t n, int* prty = NULL, bool* b = NULL); bool GetComma(void) { return comma; }
int GetPretty(void) { return pretty; }
void SetPretty(int pty) { pretty = pty; }
// Methods
PBVAL ParseJson(PGLOBAL g, char* s, size_t n);
PSZ Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty); PSZ Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty);
protected: protected:
...@@ -176,7 +181,7 @@ class BDOC : public BJSON { ...@@ -176,7 +181,7 @@ class BDOC : public BJSON {
PBVAL ParseValue(int& i); PBVAL ParseValue(int& i);
OFFSET ParseString(int& i); OFFSET ParseString(int& i);
void ParseNumeric(int& i, PBVAL bvp); void ParseNumeric(int& i, PBVAL bvp);
OFFSET ParseAsArray(int& i, int pretty, int* ptyp); OFFSET ParseAsArray(int& i);
bool SerializeArray(OFFSET arp, bool b); bool SerializeArray(OFFSET arp, bool b);
bool SerializeObject(OFFSET obp); bool SerializeObject(OFFSET obp);
bool SerializeValue(PBVAL vp); bool SerializeValue(PBVAL vp);
...@@ -185,7 +190,9 @@ class BDOC : public BJSON { ...@@ -185,7 +190,9 @@ class BDOC : public BJSON {
JOUT* jp; // Used with serialize JOUT* jp; // Used with serialize
char* s; // The Json string to parse char* s; // The Json string to parse
int len; // The Json string length int len; // The Json string length
int pretty; // The pretty style of the file to parse
bool pty[3]; // Used to guess what pretty is bool pty[3]; // Used to guess what pretty is
bool comma; // True if Pretty = 1
// Default constructor not to be used // Default constructor not to be used
BDOC(void) {} BDOC(void) {}
......
...@@ -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 18, 2020"; char version[]= "Version 1.07.0002 December 19, 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= '\\';
...@@ -5701,14 +5701,20 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5701,14 +5701,20 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
goto err; goto err;
#if defined(REST_SUPPORT) #if defined(REST_SUPPORT)
} else if (topt->http) { } else if (topt->http) {
switch (ttp) { if (ttp == TAB_UNDEF) {
topt->type = "JSON";
ttp= GetTypeID(topt->type);
sprintf(g->Message, "No table_type. Was set to %s", topt->type);
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
} // endif ttp
switch (ttp) {
case TAB_JSON: case TAB_JSON:
#if defined(BSON_SUPPORT) #if defined(BSON_SUPPORT)
case TAB_BSON: case TAB_BSON:
#endif // BSON_SUPPORT #endif // BSON_SUPPORT
case TAB_XML: case TAB_XML:
case TAB_CSV: case TAB_CSV:
case TAB_UNDEF:
ttp = TAB_REST; ttp = TAB_REST;
break; break;
default: default:
...@@ -5894,7 +5900,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5894,7 +5900,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if defined(BSON_SUPPORT) #if defined(BSON_SUPPORT)
case TAB_BSON: case TAB_BSON:
#endif // BSON_SUPPORT #endif // BSON_SUPPORT
dsn= strz(g, create_info->connect_string); dsn= strz(g, create_info->connect_string);
if (!fn && !zfn && !mul && !dsn) if (!fn && !zfn && !mul && !dsn)
sprintf(g->Message, "Missing %s file name", topt->type); sprintf(g->Message, "Missing %s file name", topt->type);
...@@ -6132,10 +6138,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -6132,10 +6138,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
} // endif !nblin } // endif !nblin
// Restore language type // Restore language type
if (ttp == TAB_REST) { if (ttp == TAB_REST)
ttp = GetTypeID(topt->type); ttp = GetTypeID(topt->type);
ttp = (ttp == TAB_UNDEF) ? TAB_JSON : ttp;
} // endif ttp
for (i= 0; !rc && i < qrp->Nblin; i++) { for (i= 0; !rc && i < qrp->Nblin; i++) {
typ= len= prec= dec= flg= 0; typ= len= prec= dec= flg= 0;
...@@ -6436,6 +6440,9 @@ int ha_connect::create(const char *name, TABLE *table_arg, ...@@ -6436,6 +6440,9 @@ int ha_connect::create(const char *name, TABLE *table_arg,
// Check table type // Check table type
if (type == TAB_UNDEF) { if (type == TAB_UNDEF) {
options->type= (options->srcdef) ? "MYSQL" : options->type= (options->srcdef) ? "MYSQL" :
#if defined(BSON_SUPPORT)
(options->http) ? "JSON" :
#endif // BSON_SUPPORT
(options->tabname) ? "PROXY" : "DOS"; (options->tabname) ? "PROXY" : "DOS";
type= GetTypeID(options->type); type= GetTypeID(options->type);
sprintf(g->Message, "No table_type. Will be set to %s", options->type); sprintf(g->Message, "No table_type. Will be set to %s", options->type);
......
...@@ -626,9 +626,11 @@ PBVAL BTUTIL::FindRow(PGLOBAL g) ...@@ -626,9 +626,11 @@ PBVAL BTUTIL::FindRow(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
/* Parse the read line. */ /* Parse the read line. */
/***********************************************************************/ /***********************************************************************/
PBVAL BTUTIL::ParseLine(PGLOBAL g, int *pretty, bool *comma) PBVAL BTUTIL::ParseLine(PGLOBAL g, int prty, bool cma)
{ {
return ParseJson(g, Tp->To_Line, strlen(Tp->To_Line), pretty, comma); pretty = prty;
comma = cma;
return ParseJson(g, Tp->To_Line, strlen(Tp->To_Line));
} // end of ParseLine } // end of ParseLine
/***********************************************************************/ /***********************************************************************/
...@@ -1296,6 +1298,7 @@ TDBBSN::TDBBSN(PGLOBAL g, PBDEF tdp, PTXF txfp) : TDBDOS(tdp, txfp) ...@@ -1296,6 +1298,7 @@ TDBBSN::TDBBSN(PGLOBAL g, PBDEF tdp, PTXF txfp) : TDBDOS(tdp, txfp)
SameRow = 0; SameRow = 0;
Xval = -1; Xval = -1;
Comma = false; Comma = false;
Bp->SetPretty(Pretty);
} // end of TDBBSN standard constructor } // end of TDBBSN standard constructor
TDBBSN::TDBBSN(TDBBSN* tdbp) : TDBDOS(NULL, tdbp) TDBBSN::TDBBSN(TDBBSN* tdbp) : TDBDOS(NULL, tdbp)
...@@ -1527,7 +1530,7 @@ int TDBBSN::ReadDB(PGLOBAL g) ...@@ -1527,7 +1530,7 @@ int TDBBSN::ReadDB(PGLOBAL g)
// Recover the memory used for parsing // Recover the memory used for parsing
Bp->SubSet(); Bp->SubSet();
if ((Row = Bp->ParseLine(g, &Pretty, &Comma))) { if ((Row = Bp->ParseLine(g, Pretty, Comma))) {
Top = Row; Top = Row;
Row = Bp->FindRow(g); Row = Bp->FindRow(g);
SameRow = 0; SameRow = 0;
...@@ -2081,6 +2084,7 @@ TDBBSON::TDBBSON(PGLOBAL g, PBDEF tdp, PTXF txfp) : TDBBSN(g, tdp, txfp) ...@@ -2081,6 +2084,7 @@ TDBBSON::TDBBSON(PGLOBAL g, PBDEF tdp, PTXF txfp) : TDBBSN(g, tdp, txfp)
Docp = NULL; Docp = NULL;
Multiple = tdp->Multiple; Multiple = tdp->Multiple;
Done = Changed = false; Done = Changed = false;
Bp->SetPretty(2);
} // end of TDBBSON standard constructor } // end of TDBBSON standard constructor
TDBBSON::TDBBSON(PBTDB tdbp) : TDBBSN(tdbp) TDBBSON::TDBBSON(PBTDB tdbp) : TDBBSN(tdbp)
...@@ -2165,7 +2169,7 @@ int TDBBSON::MakeDocument(PGLOBAL g) ...@@ -2165,7 +2169,7 @@ int TDBBSON::MakeDocument(PGLOBAL g)
/* Parse the json file and allocate its tree structure. */ /* Parse the json file and allocate its tree structure. */
/*********************************************************************/ /*********************************************************************/
g->Message[0] = 0; g->Message[0] = 0;
jsp = Top = Bp->ParseJson(g, memory, len, &Pretty); jsp = Top = Bp->ParseJson(g, memory, len);
Txfp->CloseTableFile(g, false); Txfp->CloseTableFile(g, false);
Mode = mode; // Restore saved Mode Mode = mode; // Restore saved Mode
......
...@@ -110,7 +110,7 @@ class BTUTIL : public BDOC { ...@@ -110,7 +110,7 @@ class BTUTIL : public BDOC {
// Utility functions // Utility functions
PBVAL FindRow(PGLOBAL g); PBVAL FindRow(PGLOBAL g);
PBVAL ParseLine(PGLOBAL g, int *pretty, bool *comma); PBVAL ParseLine(PGLOBAL g, int prty, bool cma);
PBVAL MakeTopTree(PGLOBAL g, int type); PBVAL MakeTopTree(PGLOBAL g, int type);
PSZ SerialVal(PGLOBAL g, PBVAL top, int pretty); PSZ SerialVal(PGLOBAL g, PBVAL top, int pretty);
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
/***********************************************************************/ /***********************************************************************/
#if defined(MARIADB) #if defined(MARIADB)
#include <my_global.h> // All MariaDB stuff #include <my_global.h> // All MariaDB stuff
#include <mysqld.h>
#include <sql_error.h>
#else // !MARIADB OEM module #else // !MARIADB OEM module
#include "mini-global.h" #include "mini-global.h"
#define _MAX_PATH 260 #define _MAX_PATH 260
...@@ -45,6 +47,12 @@ ...@@ -45,6 +47,12 @@
#include "tabfmt.h" #include "tabfmt.h"
#include "tabrest.h" #include "tabrest.h"
#if defined(connect_EXPORTS)
#define PUSH_WARNING(M) push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, M)
#else
#define PUSH_WARNING(M) htrc(M)
#endif
#if defined(__WIN__) || defined(_WINDOWS) #if defined(__WIN__) || defined(_WINDOWS)
#define popen _popen #define popen _popen
#define pclose _pclose #define pclose _pclose
...@@ -223,6 +231,8 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info) ...@@ -223,6 +231,8 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
fn = filename; fn = filename;
tp->filename = PlugDup(g, fn); tp->filename = PlugDup(g, fn);
sprintf(g->Message, "No file name. Table will use %s", fn);
PUSH_WARNING(g->Message);
} // endif fn } // endif fn
// We used the file name relative to recorded datapath // We used the file name relative to recorded datapath
......
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