Commit 100be0b6 authored by Olivier Bertrand's avatar Olivier Bertrand

Update JSON UDFs to version 1.04.0004

  modified:   storage/connect/json.cpp
  modified:   storage/connect/json.h
  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/mysql-test/connect/r/json_udf.result
  modified:   storage/connect/mysql-test/connect/std_data/biblio.json
  modified:   storage/connect/mysql-test/connect/t/json_udf.inc
  modified:   storage/connect/mysql-test/connect/t/json_udf.test
  modified:   storage/connect/tabjson.cpp
parent 608ad38a
This diff is collapsed.
...@@ -41,10 +41,10 @@ typedef struct { ...@@ -41,10 +41,10 @@ typedef struct {
int len; int len;
} STRG, *PSG; } STRG, *PSG;
PJSON ParseJson(PGLOBAL g, char *s, int n, int prty = 2, bool *b = NULL); PJSON ParseJson(PGLOBAL g, char *s, int n, int *prty = NULL, bool *b = NULL);
PJAR ParseArray(PGLOBAL g, int& i, STRG& src); PJAR ParseArray(PGLOBAL g, int& i, STRG& src, bool *pty);
PJOB ParseObject(PGLOBAL g, int& i, STRG& src); PJOB ParseObject(PGLOBAL g, int& i, STRG& src, bool *pty);
PJVAL ParseValue(PGLOBAL g, int& i, STRG& src); PJVAL ParseValue(PGLOBAL g, int& i, STRG& src, bool *pty);
char *ParseString(PGLOBAL g, int& i, STRG& src); char *ParseString(PGLOBAL g, int& i, STRG& src);
PVAL ParseNumeric(PGLOBAL g, int& i, STRG& src); PVAL ParseNumeric(PGLOBAL g, int& i, STRG& src);
PSZ Serialize(PGLOBAL g, PJSON jsp, char *fn, int pretty); PSZ Serialize(PGLOBAL g, PJSON jsp, char *fn, int pretty);
...@@ -57,14 +57,16 @@ bool SerializeValue(JOUT *js, PJVAL jvp); ...@@ -57,14 +57,16 @@ bool SerializeValue(JOUT *js, PJVAL jvp);
/***********************************************************************/ /***********************************************************************/
class JOUT : public BLOCK { class JOUT : public BLOCK {
public: public:
JOUT(PGLOBAL gp) : BLOCK() {g = gp;} JOUT(PGLOBAL gp) : BLOCK() {g = gp; Pretty = 3;}
virtual bool WriteStr(const char *s) = 0; virtual bool WriteStr(const char *s) = 0;
virtual bool WriteChr(const char c) = 0; virtual bool WriteChr(const char c) = 0;
virtual bool Escape(const char *s) = 0; virtual bool Escape(const char *s) = 0;
int Prty(void) {return Pretty;}
// Member // Member
PGLOBAL g; PGLOBAL g;
int Pretty;
}; // end of class JOUT }; // end of class JOUT
/***********************************************************************/ /***********************************************************************/
...@@ -89,7 +91,7 @@ class JOUTSTR : public JOUT { ...@@ -89,7 +91,7 @@ class JOUTSTR : public JOUT {
/***********************************************************************/ /***********************************************************************/
class JOUTFILE : public JOUT { class JOUTFILE : public JOUT {
public: public:
JOUTFILE(PGLOBAL g, FILE *str) : JOUT(g) {Stream = str;} JOUTFILE(PGLOBAL g, FILE *str, int pty) : JOUT(g) {Stream = str; Pretty = pty;}
virtual bool WriteStr(const char *s); virtual bool WriteStr(const char *s);
virtual bool WriteChr(const char c); virtual bool WriteChr(const char c);
...@@ -104,7 +106,7 @@ class JOUTFILE : public JOUT { ...@@ -104,7 +106,7 @@ class JOUTFILE : public JOUT {
/***********************************************************************/ /***********************************************************************/
class JOUTPRT : public JOUTFILE { class JOUTPRT : public JOUTFILE {
public: public:
JOUTPRT(PGLOBAL g, FILE *str) : JOUTFILE(g, str) {M = 0; B = false;} JOUTPRT(PGLOBAL g, FILE *str) : JOUTFILE(g, str, 2) {M = 0; B = false;}
virtual bool WriteStr(const char *s); virtual bool WriteStr(const char *s);
virtual bool WriteChr(const char c); virtual bool WriteChr(const char c);
...@@ -120,7 +122,7 @@ class JOUTPRT : public JOUTFILE { ...@@ -120,7 +122,7 @@ class JOUTPRT : public JOUTFILE {
class JPAIR : public BLOCK { class JPAIR : public BLOCK {
friend class JOBJECT; friend class JOBJECT;
friend class JSNX; friend class JSNX;
friend PJOB ParseObject(PGLOBAL, int&, STRG&); friend PJOB ParseObject(PGLOBAL, int&, STRG&, bool*);
friend bool SerializeObject(JOUT *, PJOB); friend bool SerializeObject(JOUT *, PJOB);
public: public:
JPAIR(PSZ key) : BLOCK() {Key = key; Val = NULL; Next = NULL;} JPAIR(PSZ key) : BLOCK() {Key = key; Val = NULL; Next = NULL;}
...@@ -182,7 +184,7 @@ class JSON : public BLOCK { ...@@ -182,7 +184,7 @@ class JSON : public BLOCK {
/* Class JOBJECT: contains a list of value pairs. */ /* Class JOBJECT: contains a list of value pairs. */
/***********************************************************************/ /***********************************************************************/
class JOBJECT : public JSON { class JOBJECT : public JSON {
friend PJOB ParseObject(PGLOBAL, int&, STRG&); friend PJOB ParseObject(PGLOBAL, int&, STRG&, bool*);
friend bool SerializeObject(JOUT *, PJOB); friend bool SerializeObject(JOUT *, PJOB);
friend class JSNX; friend class JSNX;
public: public:
...@@ -212,7 +214,7 @@ class JOBJECT : public JSON { ...@@ -212,7 +214,7 @@ class JOBJECT : public JSON {
/* Class JARRAY. */ /* Class JARRAY. */
/***********************************************************************/ /***********************************************************************/
class JARRAY : public JSON { class JARRAY : public JSON {
friend PJAR ParseArray(PGLOBAL, int&, STRG&); friend PJAR ParseArray(PGLOBAL, int&, STRG&, bool*);
public: public:
JARRAY(void) : JSON() {Alloc = 0; First = Last = NULL; Mvals = NULL;} JARRAY(void) : JSON() {Alloc = 0; First = Last = NULL; Mvals = NULL;}
...@@ -243,7 +245,7 @@ class JARRAY : public JSON { ...@@ -243,7 +245,7 @@ class JARRAY : public JSON {
class JVALUE : public JSON { class JVALUE : public JSON {
friend class JARRAY; friend class JARRAY;
friend class JSNX; friend class JSNX;
friend PJVAL ParseValue(PGLOBAL, int&, STRG&); friend PJVAL ParseValue(PGLOBAL, int&, STRG&, bool*);
friend bool SerializeValue(JOUT *, PJVAL); friend bool SerializeValue(JOUT *, PJVAL);
public: public:
JVALUE(void) : JSON() JVALUE(void) : JSON()
...@@ -269,13 +271,14 @@ class JVALUE : public JSON { ...@@ -269,13 +271,14 @@ class JVALUE : public JSON {
virtual double GetFloat(void); virtual double GetFloat(void);
virtual PSZ GetString(void); virtual PSZ GetString(void);
virtual PSZ GetText(PGLOBAL g, PSZ text); virtual PSZ GetText(PGLOBAL g, PSZ text);
virtual void SetValue(PVAL valp) {Value = valp;} virtual void SetValue(PVAL valp) {Value = valp; Jsp = NULL;}
virtual void SetValue(PJSON jsp) {Jsp = jsp;} virtual void SetValue(PJSON jsp) {Jsp = jsp; Value = NULL;}
virtual void SetString(PGLOBAL g, PSZ s, short c = 0); virtual void SetString(PGLOBAL g, PSZ s, short c = 0);
virtual void SetInteger(PGLOBAL g, int n); virtual void SetInteger(PGLOBAL g, int n);
virtual void SetBigint(PGLOBAL g, longlong ll); virtual void SetBigint(PGLOBAL g, longlong ll);
virtual void SetFloat(PGLOBAL g, double f); virtual void SetFloat(PGLOBAL g, double f);
virtual bool IsNull(void); virtual void SetTiny(PGLOBAL g, char f);
virtual bool IsNull(void);
protected: protected:
PJSON Jsp; // To the json value PJSON Jsp; // To the json value
......
This diff is collapsed.
...@@ -24,12 +24,10 @@ ...@@ -24,12 +24,10 @@
"ISBN": "9782840825685", "ISBN": "9782840825685",
"LANG": "fr", "LANG": "fr",
"SUBJECT": "applications", "SUBJECT": "applications",
"AUTHOR": [ "AUTHOR": {
{ "FIRSTNAME": "William J.",
"FIRSTNAME": "William J.", "LASTNAME": "Pardi"
"LASTNAME": "Pardi" },
}
],
"TITLE": "XML en Action", "TITLE": "XML en Action",
"TRANSLATION": "adapté de l'anglais par", "TRANSLATION": "adapté de l'anglais par",
"TRANSLATOR": { "TRANSLATOR": {
......
...@@ -11,11 +11,38 @@ if (!$HA_CONNECT_SO) { ...@@ -11,11 +11,38 @@ if (!$HA_CONNECT_SO) {
CREATE FUNCTION json_array RETURNS STRING SONAME 'ha_connect'; CREATE FUNCTION json_array RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_array_add RETURNS STRING SONAME 'ha_connect'; CREATE FUNCTION json_array_add RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_array_add_values RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_array_delete RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_object RETURNS STRING SONAME 'ha_connect'; CREATE FUNCTION json_object RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_object_nonull RETURNS STRING SONAME 'ha_connect'; CREATE FUNCTION json_object_nonull RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_object_add RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_object_delete RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_object_list RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jsonvalue RETURNS STRING SONAME 'ha_connect'; CREATE FUNCTION jsonvalue RETURNS STRING SONAME 'ha_connect';
CREATE AGGREGATE FUNCTION json_array_grp RETURNS STRING SONAME 'ha_connect'; CREATE AGGREGATE FUNCTION json_array_grp RETURNS STRING SONAME 'ha_connect';
CREATE AGGREGATE FUNCTION json_object_grp RETURNS STRING SONAME 'ha_connect'; CREATE AGGREGATE FUNCTION json_object_grp RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_item_merge RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_get_item RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jsonget_string RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jsonget_int RETURNS INTEGER SONAME 'ha_connect';
CREATE FUNCTION jsonget_real RETURNS REAL SONAME 'ha_connect';
CREATE FUNCTION jsonlocate RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_locate_all RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_file RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jfile_make RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION json_serialize RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_array RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_array_add_values RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_array_add RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_array_delete RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_object RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_object_nonull RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_object_add RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_object_delete RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_object_list RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_get_item RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_item_merge RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION jbin_file RETURNS STRING SONAME 'ha_connect';
--enable_query_log --enable_query_log
--disable_query_log
DROP FUNCTION jsonvalue;
DROP FUNCTION json_array;
DROP FUNCTION json_array_add;
DROP FUNCTION json_array_add_values;
DROP FUNCTION json_array_delete;
DROP FUNCTION json_object;
DROP FUNCTION json_object_nonull;
DROP FUNCTION json_object_add;
DROP FUNCTION json_object_delete;
DROP FUNCTION json_object_list;
DROP FUNCTION json_array_grp;
DROP FUNCTION json_object_grp;
DROP FUNCTION json_item_merge;
DROP FUNCTION json_get_item;
DROP FUNCTION JsonGet_string;
DROP FUNCTION JsonGet_int;
DROP FUNCTION JsonGet_real;
DROP FUNCTION jsonlocate;
DROP FUNCTION json_locate_all;
DROP FUNCTION json_file;
DROP FUNCTION json_serialize;
DROP FUNCTION jfile_make;
DROP FUNCTION jbin_array;
DROP FUNCTION jbin_array_add_values;
DROP FUNCTION jbin_array_add;
DROP FUNCTION jbin_array_delete;
DROP FUNCTION jbin_object;
DROP FUNCTION jbin_object_nonull;
DROP FUNCTION jbin_object_add;
DROP FUNCTION jbin_object_delete;
DROP FUNCTION jbin_object_list;
DROP FUNCTION jbin_get_item;
DROP FUNCTION jbin_item_merge;
DROP FUNCTION jbin_file;
--enable_query_log
...@@ -659,7 +659,7 @@ int TDBJSN::ReadDB(PGLOBAL g) ...@@ -659,7 +659,7 @@ int TDBJSN::ReadDB(PGLOBAL g)
if (!IsRead() && ((rc = ReadBuffer(g)) != RC_OK)) { if (!IsRead() && ((rc = ReadBuffer(g)) != RC_OK)) {
// Deferred reading failed // Deferred reading failed
} else if (!(Row = ParseJson(g, To_Line, } else if (!(Row = ParseJson(g, To_Line,
strlen(To_Line), Pretty, &Comma))) { strlen(To_Line), &Pretty, &Comma))) {
rc = (Pretty == 1 && !strcmp(To_Line, "]")) ? RC_EF : RC_FX; rc = (Pretty == 1 && !strcmp(To_Line, "]")) ? RC_EF : RC_FX;
} else { } else {
Row = FindRow(g); Row = FindRow(g);
...@@ -1384,7 +1384,7 @@ void JSONCOL::WriteColumn(PGLOBAL g) ...@@ -1384,7 +1384,7 @@ void JSONCOL::WriteColumn(PGLOBAL g)
if (Nodes[Nod-1].Op == OP_XX) { if (Nodes[Nod-1].Op == OP_XX) {
s = Value->GetCharValue(); s = Value->GetCharValue();
if (!(jsp = ParseJson(g, s, (int)strlen(s), 0))) { if (!(jsp = ParseJson(g, s, (int)strlen(s)))) {
strcpy(g->Message, s); strcpy(g->Message, s);
longjmp(g->jumper[g->jump_level], 666); longjmp(g->jumper[g->jump_level], 666);
} // endif jsp } // endif jsp
...@@ -1522,7 +1522,7 @@ int TDBJSON::MakeDocument(PGLOBAL g) ...@@ -1522,7 +1522,7 @@ int TDBJSON::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 = ParseJson(g, memory, len, Pretty); jsp = Top = ParseJson(g, memory, len, &Pretty);
Txfp->CloseTableFile(g, false); Txfp->CloseTableFile(g, false);
Mode = mode; // Restore saved Mode Mode = mode; // Restore saved Mode
......
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