mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Merge branch '10.5' into 10.6
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*************** json CPP Declares Source Code File (.H) ***************/
|
||||
/* Name: json.cpp Version 1.5 */
|
||||
/* Name: json.cpp Version 1.6 */
|
||||
/* */
|
||||
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2020 */
|
||||
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2021 */
|
||||
/* */
|
||||
/* This file contains the JSON classes functions. */
|
||||
/***********************************************************************/
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#define ARGS MY_MIN(24,(int)len-i),s+MY_MAX(i-3,0)
|
||||
|
||||
#if defined(__WIN__)
|
||||
#if defined(_WIN32)
|
||||
#define EL "\r\n"
|
||||
#else
|
||||
#define EL "\n"
|
||||
@@ -55,6 +55,7 @@ char *GetExceptionDesc(PGLOBAL g, unsigned int e);
|
||||
|
||||
char *GetJsonNull(void);
|
||||
int GetDefaultPrec(void);
|
||||
int PrepareColist(char*);
|
||||
|
||||
/***********************************************************************/
|
||||
/* IsNum: check whether this string is all digits. */
|
||||
@@ -77,6 +78,24 @@ bool IsNum(PSZ s)
|
||||
return true;
|
||||
} // end of IsNum
|
||||
|
||||
/***********************************************************************/
|
||||
/* IsArray: check whether this is a Mongo array path. */
|
||||
/***********************************************************************/
|
||||
bool IsArray(PSZ s)
|
||||
{
|
||||
char* p = s;
|
||||
|
||||
if (!p || !*p)
|
||||
return false;
|
||||
else for (; *p; p++)
|
||||
if (*p == '.')
|
||||
break;
|
||||
else if (!isdigit(*p))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
} // end of IsArray
|
||||
|
||||
/***********************************************************************/
|
||||
/* NextChr: return the first found '[' or Sep pointer. */
|
||||
/***********************************************************************/
|
||||
@@ -93,6 +112,27 @@ char* NextChr(PSZ s, char sep)
|
||||
return p2;
|
||||
} // end of NextChr
|
||||
|
||||
/***********************************************************************/
|
||||
/* Stringified: check that this column is in the stringified list. */
|
||||
/***********************************************************************/
|
||||
bool Stringified(PCSZ strfy, char *colname)
|
||||
{
|
||||
if (strfy) {
|
||||
char *p, colist[512];
|
||||
int n;
|
||||
|
||||
strncpy(colist, strfy, sizeof(colist) - 1);
|
||||
n = PrepareColist(colist);
|
||||
|
||||
for (p = colist; n && p; p += (strlen(p) + 1), n--)
|
||||
if (!stricmp(p, colname))
|
||||
return true;
|
||||
|
||||
} // endif strfy
|
||||
|
||||
return false;
|
||||
} // end of Stringified
|
||||
|
||||
#if 0
|
||||
/***********************************************************************/
|
||||
/* Allocate a VAL structure, make sure common field and Nd are zeroed. */
|
||||
@@ -227,6 +267,7 @@ PSZ Serialize(PGLOBAL g, PJSON jsp, char* fn, int pretty) {
|
||||
|
||||
try {
|
||||
jdp = new(g) JDOC; // MUST BE ALLOCATED BEFORE jp !!!!!
|
||||
jdp->dfp = GetDefaultPrec();
|
||||
|
||||
if (!jsp) {
|
||||
strcpy(g->Message, "Null json tree");
|
||||
@@ -987,8 +1028,8 @@ bool JDOC::SerializeValue(PJVAL jvp)
|
||||
case TYPE_BINT:
|
||||
sprintf(buf, "%lld", jvp->LLn);
|
||||
return js->WriteStr(buf);
|
||||
case TYPE_DBL:
|
||||
sprintf(buf, "%.*lf", jvp->Nd, jvp->F);
|
||||
case TYPE_DBL: // dfp to limit to the default number of decimals
|
||||
sprintf(buf, "%.*f", MY_MIN(jvp->Nd, dfp), jvp->F);
|
||||
return js->WriteStr(buf);
|
||||
case TYPE_NULL:
|
||||
return js->WriteStr("null");
|
||||
@@ -1326,9 +1367,9 @@ bool JARRAY::Merge(PGLOBAL g, PJSON jsp)
|
||||
} // end of Merge
|
||||
|
||||
/***********************************************************************/
|
||||
/* Set the nth Value of the Array Value list. */
|
||||
/* Set the nth Value of the Array Value list or add it. */
|
||||
/***********************************************************************/
|
||||
bool JARRAY::SetArrayValue(PGLOBAL g, PJVAL jvp, int n)
|
||||
void JARRAY::SetArrayValue(PGLOBAL g, PJVAL jvp, int n)
|
||||
{
|
||||
int i = 0;
|
||||
PJVAL jp, *jpp = &First;
|
||||
@@ -1339,7 +1380,6 @@ bool JARRAY::SetArrayValue(PGLOBAL g, PJVAL jvp, int n)
|
||||
|
||||
*jpp = jvp;
|
||||
jvp->Next = (jp ? jp->Next : NULL);
|
||||
return false;
|
||||
} // end of SetValue
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -1417,7 +1457,7 @@ bool JARRAY::IsNull(void)
|
||||
/***********************************************************************/
|
||||
JVALUE::JVALUE(PJSON jsp) : JSON()
|
||||
{
|
||||
if (jsp->GetType() == TYPE_JVAL) {
|
||||
if (jsp && jsp->GetType() == TYPE_JVAL) {
|
||||
PJVAL jvp = (PJVAL)jsp;
|
||||
|
||||
// Val = ((PJVAL)jsp)->GetVal();
|
||||
@@ -1434,7 +1474,7 @@ JVALUE::JVALUE(PJSON jsp) : JSON()
|
||||
} else {
|
||||
Jsp = jsp;
|
||||
// Val = NULL;
|
||||
DataType = TYPE_JSON;
|
||||
DataType = Jsp ? TYPE_JSON : TYPE_NULL;
|
||||
Nd = 0;
|
||||
} // endif Type
|
||||
|
||||
|
Reference in New Issue
Block a user