summaryrefslogtreecommitdiff
path: root/storage/connect/tabjson.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2015-05-17 15:22:42 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2015-05-17 15:22:42 +0200
commita82171c9aa8a2edece5802e5e30ddace9c1a4a33 (patch)
tree69eb1c8b2662f4bc90957f268179c2d0ccb80931 /storage/connect/tabjson.cpp
parentb9c910909c3e04ceab8d0d514ba6213015787c5a (diff)
downloadmariadb-git-a82171c9aa8a2edece5802e5e30ddace9c1a4a33.tar.gz
In BIN table date_format now imply by default field_format='C'.
modified: storage/connect/tabfix.cpp modified: storage/connect/reldef.cpp Json array index (position) is now 0 based by default. This corresponds to what all json applications and functions do. Also fix ROWNUM calculation. modified: storage/connect/jsonudf.cpp modified: storage/connect/mysql-test/connect/r/json.result modified: storage/connect/mysql-test/connect/t/json.test modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h
Diffstat (limited to 'storage/connect/tabjson.cpp')
-rw-r--r--storage/connect/tabjson.cpp68
1 files changed, 32 insertions, 36 deletions
diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp
index f22bdd15528..0ce326f5c2a 100644
--- a/storage/connect/tabjson.cpp
+++ b/storage/connect/tabjson.cpp
@@ -372,6 +372,7 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
Pretty = GetIntCatInfo("Pretty", 2);
Level = GetIntCatInfo("Level", 0);
Limit = GetIntCatInfo("Limit", 10);
+ Base = GetIntCatInfo("Base", 0);
return DOSDEF::DefineAM(g, "DOS", poff);
} // end of DefineAM
@@ -440,6 +441,7 @@ TDBJSN::TDBJSN(PJDEF tdp, PTXF txfp) : TDBDOS(tdp, txfp)
Xcol = tdp->Xcol;
Limit = tdp->Limit;
Pretty = tdp->Pretty;
+ B = tdp->Base ? 1 : 0;
Strict = tdp->Strict;
} else {
Jmode = MODE_OBJECT;
@@ -447,11 +449,12 @@ TDBJSN::TDBJSN(PJDEF tdp, PTXF txfp) : TDBDOS(tdp, txfp)
Xcol = NULL;
Limit = 1;
Pretty = 0;
+ B = 1;
Strict = false;
} // endif tdp
Fpos = -1;
- N = 0;
+ N = M = 0;
NextSame = 0;
SameRow = 0;
Xval = -1;
@@ -469,6 +472,7 @@ TDBJSN::TDBJSN(TDBJSN *tdbp) : TDBDOS(NULL, tdbp)
Xcol = tdbp->Xcol;
Fpos = tdbp->Fpos;
N = tdbp->N;
+ M = tdbp->M;
Limit = tdbp->Limit;
NextSame = tdbp->NextSame;
SameRow = tdbp->SameRow;
@@ -563,7 +567,7 @@ PJSON TDBJSN::FindRow(PGLOBAL g)
jsp->GetObject()->GetValue(objpath) : NULL;
} else if (objpath[strlen(objpath)-1] == ']') {
val = (jsp->GetType() == TYPE_JAR) ?
- jsp->GetArray()->GetValue(atoi(objpath+1) - 1) : NULL;
+ jsp->GetArray()->GetValue(atoi(objpath+1) - B) : NULL;
} else
val = NULL;
@@ -649,6 +653,7 @@ int TDBJSN::ReadDB(PGLOBAL g)
if (NextSame) {
SameRow = NextSame;
NextSame = 0;
+ M++;
return RC_OK;
} else if ((rc = TDBDOS::ReadDB(g)) == RC_OK)
if (!IsRead() && ((rc = ReadBuffer(g)) != RC_OK)) {
@@ -660,6 +665,7 @@ int TDBJSN::ReadDB(PGLOBAL g)
Row = FindRow(g);
SameRow = 0;
Fpos++;
+ M = 1;
rc = RC_OK;
} // endif's
@@ -708,7 +714,7 @@ int TDBJSN::MakeTopTree(PGLOBAL g, PJSON jsp)
val->SetValue(arp);
val = new(g) JVALUE;
- i = atoi(objpath+1) - 1;
+ i = atoi(objpath+1) - B;
arp->SetValue(g, val, i);
arp->InitArray(g);
} else {
@@ -856,8 +862,8 @@ bool JSONCOL::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm)
return true;
else if (jnp->Op != OP_EXP) {
if (b) {
- // Return 1st value
- jnp->Rank = 1;
+ // Return 1st value (B is the index base)
+ jnp->Rank = 1 - Tjp->B;
jnp->Op = OP_EQ;
} else if (!Value->IsTypeNum()) {
jnp->CncVal = AllocateValue(g, (void*)", ", TYPE_STRING);
@@ -868,13 +874,9 @@ bool JSONCOL::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm)
} // endif OP
} else if (dg) {
- if (atoi(p) > 0) {
- // Return nth value
- jnp->Rank = atoi(p);
- jnp->Op = OP_EQ;
- } else // Ignore array
- jnp->Op = OP_NULL;
-
+ // Return nth value
+ jnp->Rank = atoi(p) - Tjp->B;
+ jnp->Op = OP_EQ;
} else if (n == 1) {
// Set the Op value;
switch (*p) {
@@ -1118,16 +1120,12 @@ PVAL JSONCOL::GetColumnValue(PGLOBAL g, PJSON row, int i)
arp = (PJAR)row;
if (!Nodes[i].Key) {
- if (Nodes[i].Op != OP_NULL) {
- if (Nodes[i].Rank) {
- val = arp->GetValue(Nodes[i].Rank - 1);
- } else if (Nodes[i].Op == OP_EXP) {
- return ExpandArray(g, arp, i);
- } else
- return CalculateArray(g, arp, i);
-
- } else
- val = NULL;
+ if (Nodes[i].Op == OP_EQ)
+ val = arp->GetValue(Nodes[i].Rank);
+ else if (Nodes[i].Op == OP_EXP)
+ return ExpandArray(g, arp, i);
+ else
+ return CalculateArray(g, arp, i);
} else if (i < Nod-1) {
strcpy(g->Message, "Unexpected array");
@@ -1289,16 +1287,12 @@ PJSON JSONCOL::GetRow(PGLOBAL g)
break;
case TYPE_JAR:
if (!Nodes[i].Key) {
- if (Nodes[i].Op != OP_NULL) {
- arp = (PJAR)row;
-
- if (Nodes[i].Rank)
- val = arp->GetValue(Nodes[i].Rank - 1);
- else
- val = arp->GetValue(Nodes[i].Rx);
+ arp = (PJAR)row;
- } else
- val = NULL;
+ if (Nodes[i].Op == OP_EQ)
+ val = arp->GetValue(Nodes[i].Rank);
+ else
+ val = arp->GetValue(Nodes[i].Rx);
} else {
strcpy(g->Message, "Unexpected array");
@@ -1390,8 +1384,8 @@ void JSONCOL::WriteColumn(PGLOBAL g)
} // endif jsp
if (arp) {
- if (Nod > 1 && Nodes[Nod-2].Rank)
- arp->SetValue(g, new(g) JVALUE(jsp), Nodes[Nod-2].Rank-1);
+ if (Nod > 1 && Nodes[Nod-2].Op == OP_EQ)
+ arp->SetValue(g, new(g) JVALUE(jsp), Nodes[Nod-2].Rank);
else
arp->AddValue(g, new(g) JVALUE(jsp));
@@ -1411,8 +1405,8 @@ void JSONCOL::WriteColumn(PGLOBAL g)
case TYPE_INT:
case TYPE_DOUBLE:
if (arp) {
- if (Nodes[Nod-1].Rank)
- arp->SetValue(g, new(g) JVALUE(g, Value), Nodes[Nod-1].Rank-1);
+ if (Nodes[Nod-1].Op == OP_EQ)
+ arp->SetValue(g, new(g) JVALUE(g, Value), Nodes[Nod-1].Rank);
else
arp->AddValue(g, new(g) JVALUE(g, Value));
@@ -1562,7 +1556,7 @@ int TDBJSON::MakeDocument(PGLOBAL g)
arp = jsp->GetArray();
objp = NULL;
- i = atoi(objpath+1) - 1;
+ i = atoi(objpath+1) - B;
val = arp->GetValue(i);
if (!val) {
@@ -1750,6 +1744,7 @@ int TDBJSON::ReadDB(PGLOBAL)
if (NextSame) {
SameRow = NextSame;
NextSame = false;
+ M++;
rc = RC_OK;
} else if (++Fpos < (signed)Doc->size()) {
Row = Doc->GetValue(Fpos);
@@ -1758,6 +1753,7 @@ int TDBJSON::ReadDB(PGLOBAL)
Row = ((PJVAL)Row)->GetJson();
SameRow = 0;
+ M = 1;
rc = RC_OK;
} else
rc = RC_EF;