MCPcopy Create free account
hub / github.com/MariaDB/server / ParseJpath

Method ParseJpath

storage/connect/tabjson.cpp:1506–1593  ·  view source on GitHub ↗

/ Parse the eventual passed Jpath information. */ This information can be specified in the Fieldfmt column option */ when creating the table. It permits to indicate the position of */ the node corresponding to that column. */ /

Source from the content-addressed store, hash-verified

1504/* the node corresponding to that column. */
1505/***********************************************************************/
1506bool JSONCOL::ParseJpath(PGLOBAL g)
1507{
1508 char *p, *p1 = NULL, *p2 = NULL, *pbuf = NULL;
1509 int i;
1510 bool a;
1511
1512 if (Parsed)
1513 return false; // Already done
1514 else if (InitValue(g))
1515 return true;
1516 else if (!Jpath)
1517 Jpath = Name;
1518
1519 if (To_Tdb->GetOrig()) {
1520 // This is an updated column, get nodes from origin
1521 for (PJCOL colp = (PJCOL)Tjp->GetColumns(); colp;
1522 colp = (PJCOL)colp->GetNext())
1523 if (!stricmp(Name, colp->GetName())) {
1524 Nod = colp->Nod;
1525 Nodes = colp->Nodes;
1526 Xpd = colp->Xpd;
1527 goto fin;
1528 } // endif Name
1529
1530 snprintf(g->Message, sizeof(g->Message), "Cannot parse updated column %s", Name);
1531 return true;
1532 } // endif To_Orig
1533
1534 pbuf = PlugDup(g, Jpath);
1535 if (*pbuf == '$') pbuf++;
1536 if (*pbuf == Sep) pbuf++;
1537 if (*pbuf == '[') p1 = pbuf++;
1538
1539 // Estimate the required number of nodes
1540 for (i = 0, p = pbuf; (p = NextChr(p, Sep)); i++, p++)
1541 Nod++; // One path node found
1542
1543 Nodes = (PJNODE)PlugSubAlloc(g, NULL, (++Nod) * sizeof(JNODE));
1544 memset(Nodes, 0, (Nod) * sizeof(JNODE));
1545
1546 // Analyze the Jpath for this column
1547 for (i = 0, p = pbuf; p && i < Nod; i++, p = (p2 ? p2 : NULL)) {
1548 a = (p1 != NULL);
1549 p1 = strchr(p, '[');
1550 p2 = strchr(p, Sep);
1551
1552 if (!p2)
1553 p2 = p1;
1554 else if (p1) {
1555 if (p1 < p2)
1556 p2 = p1;
1557 else if (p1 == p2 + 1)
1558 *p2++ = 0; // Old syntax .[ or :[
1559 else
1560 p1 = NULL;
1561
1562 } // endif p1
1563

Callers 1

MakeColMethod · 0.45

Calls 9

PlugDupFunction · 0.85
NextChrFunction · 0.85
PlugSubAllocFunction · 0.85
IsNumFunction · 0.85
safe_strcpyFunction · 0.85
AllocateValueFunction · 0.85
GetColumnsMethod · 0.45
GetNextMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected