mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Fix search for json subtable in tabjson.cpp
This commit is contained in:
@@ -1995,8 +1995,9 @@ int TDBJSON::MakeNewDoc(PGLOBAL g)
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
int TDBJSON::MakeDocument(PGLOBAL g)
|
int TDBJSON::MakeDocument(PGLOBAL g)
|
||||||
{
|
{
|
||||||
char *p, *memory, *objpath, *key = NULL;
|
char *p, *p1, *p2, *memory, *objpath, *key = NULL;
|
||||||
int len, i = 0;
|
int len, i = 0;
|
||||||
|
my_bool a;
|
||||||
MODE mode = Mode;
|
MODE mode = Mode;
|
||||||
PJSON jsp;
|
PJSON jsp;
|
||||||
PJOB objp = NULL;
|
PJOB objp = NULL;
|
||||||
@@ -2039,22 +2040,39 @@ int TDBJSON::MakeDocument(PGLOBAL g)
|
|||||||
if ((objpath = PlugDup(g, Objname))) {
|
if ((objpath = PlugDup(g, Objname))) {
|
||||||
if (*objpath == '$') objpath++;
|
if (*objpath == '$') objpath++;
|
||||||
if (*objpath == '.') objpath++;
|
if (*objpath == '.') objpath++;
|
||||||
|
p1 = p2 = NULL;
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
/* Find the table in the tree structure. */
|
/* Find the table in the tree structure. */
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
for (; jsp && objpath; objpath = p) {
|
for (p = objpath; jsp && p; p = (p2 ? p2 : NULL)) {
|
||||||
if ((p = strchr(objpath, Sep)))
|
a = (p1 != NULL);
|
||||||
*p++ = 0;
|
p1 = strchr(p, '[');
|
||||||
|
p2 = strchr(p, '.');
|
||||||
|
|
||||||
if (*objpath != '[' && !IsNum(objpath)) {
|
if (!p2)
|
||||||
// objpass is a key
|
p2 = p1;
|
||||||
|
else if (p1) {
|
||||||
|
if (p1 < p2)
|
||||||
|
p2 = p1;
|
||||||
|
else if (p1 == p2 + 1)
|
||||||
|
*p2++ = 0; // Old syntax .[
|
||||||
|
else
|
||||||
|
p1 = NULL;
|
||||||
|
|
||||||
|
} // endif p1
|
||||||
|
|
||||||
|
if (p2)
|
||||||
|
*p2++ = 0;
|
||||||
|
|
||||||
|
if (!a && *p && *p != '[' && !IsNum(p)) {
|
||||||
|
// obj is a key
|
||||||
if (jsp->GetType() != TYPE_JOB) {
|
if (jsp->GetType() != TYPE_JOB) {
|
||||||
strcpy(g->Message, "Table path does not match the json file");
|
strcpy(g->Message, "Table path does not match the json file");
|
||||||
return RC_FX;
|
return RC_FX;
|
||||||
} // endif Type
|
} // endif Type
|
||||||
|
|
||||||
key = objpath;
|
key = p;
|
||||||
objp = jsp->GetObject();
|
objp = jsp->GetObject();
|
||||||
arp = NULL;
|
arp = NULL;
|
||||||
val = objp->GetValue(key);
|
val = objp->GetValue(key);
|
||||||
@@ -2065,15 +2083,15 @@ int TDBJSON::MakeDocument(PGLOBAL g)
|
|||||||
} // endif val
|
} // endif val
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (*objpath == '[') {
|
if (*p == '[') {
|
||||||
// Old style
|
// Old style
|
||||||
if (objpath[strlen(objpath) - 1] != ']') {
|
if (p[strlen(p) - 1] != ']') {
|
||||||
sprintf(g->Message, "Invalid Table path %s", Objname);
|
sprintf(g->Message, "Invalid Table path near %s", p);
|
||||||
return RC_FX;
|
return RC_FX;
|
||||||
} else
|
} else
|
||||||
objpath++;
|
p++;
|
||||||
|
|
||||||
} // endif objpath
|
} // endif p
|
||||||
|
|
||||||
if (jsp->GetType() != TYPE_JAR) {
|
if (jsp->GetType() != TYPE_JAR) {
|
||||||
strcpy(g->Message, "Table path does not match the json file");
|
strcpy(g->Message, "Table path does not match the json file");
|
||||||
@@ -2082,7 +2100,7 @@ int TDBJSON::MakeDocument(PGLOBAL g)
|
|||||||
|
|
||||||
arp = jsp->GetArray();
|
arp = jsp->GetArray();
|
||||||
objp = NULL;
|
objp = NULL;
|
||||||
i = atoi(objpath) - B;
|
i = atoi(p) - B;
|
||||||
val = arp->GetValue(i);
|
val = arp->GetValue(i);
|
||||||
|
|
||||||
if (!val) {
|
if (!val) {
|
||||||
@@ -2093,7 +2111,7 @@ int TDBJSON::MakeDocument(PGLOBAL g)
|
|||||||
} // endif
|
} // endif
|
||||||
|
|
||||||
jsp = val->GetJson();
|
jsp = val->GetJson();
|
||||||
} // endfor objpath
|
} // endfor p
|
||||||
|
|
||||||
} // endif objpath
|
} // endif objpath
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user