Commit 9a07f30b authored by Olivier Bertrand's avatar Olivier Bertrand

Fix some Json and Bson bugs

parent 1d627ce4
...@@ -784,6 +784,12 @@ PVAL BCUTIL::MakeBson(PGLOBAL g, PBVAL jsp) ...@@ -784,6 +784,12 @@ PVAL BCUTIL::MakeBson(PGLOBAL g, PBVAL jsp)
{ {
if (Cp->Value->IsTypeNum()) { if (Cp->Value->IsTypeNum()) {
strcpy(g->Message, "Cannot make Json for a numeric column"); strcpy(g->Message, "Cannot make Json for a numeric column");
if (!Cp->Warned) {
PushWarning(g, Tp);
Cp->Warned = true;
} // endif Warned
Cp->Value->Reset(); Cp->Value->Reset();
#if 0 #if 0
} else if (Value->GetType() == TYPE_BIN) { } else if (Value->GetType() == TYPE_BIN) {
...@@ -1635,6 +1641,7 @@ BSONCOL::BSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) ...@@ -1635,6 +1641,7 @@ BSONCOL::BSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i)
Xnod = -1; Xnod = -1;
Xpd = false; Xpd = false;
Parsed = false; Parsed = false;
Warned = false;
} // end of BSONCOL constructor } // end of BSONCOL constructor
/***********************************************************************/ /***********************************************************************/
...@@ -1653,6 +1660,7 @@ BSONCOL::BSONCOL(BSONCOL* col1, PTDB tdbp) : DOSCOL(col1, tdbp) ...@@ -1653,6 +1660,7 @@ BSONCOL::BSONCOL(BSONCOL* col1, PTDB tdbp) : DOSCOL(col1, tdbp)
Xnod = col1->Xnod; Xnod = col1->Xnod;
Xpd = col1->Xpd; Xpd = col1->Xpd;
Parsed = col1->Parsed; Parsed = col1->Parsed;
Warned = col1->Warned;
} // end of BSONCOL copy constructor } // end of BSONCOL copy constructor
/***********************************************************************/ /***********************************************************************/
...@@ -1986,8 +1994,10 @@ void BSONCOL::ReadColumn(PGLOBAL g) ...@@ -1986,8 +1994,10 @@ void BSONCOL::ReadColumn(PGLOBAL g)
if (!Tbp->SameRow || Xnod >= Tbp->SameRow) if (!Tbp->SameRow || Xnod >= Tbp->SameRow)
Value->SetValue_pval(Cp->GetColumnValue(g, Tbp->Row, 0)); Value->SetValue_pval(Cp->GetColumnValue(g, Tbp->Row, 0));
#if defined(DEVELOPMENT)
if (Xpd && Value->IsNull() && !((PBDEF)Tbp->To_Def)->Accept) if (Xpd && Value->IsNull() && !((PBDEF)Tbp->To_Def)->Accept)
throw("Null expandable JSON value"); htrc("Null expandable JSON value for column %s\n", Name);
#endif // DEVELOPMENT
// Set null when applicable // Set null when applicable
if (!Nullable) if (!Nullable)
...@@ -2274,8 +2284,10 @@ int TDBBSON::MakeDocument(PGLOBAL g) ...@@ -2274,8 +2284,10 @@ int TDBBSON::MakeDocument(PGLOBAL g)
Docp = Bp->NewVal(TYPE_JAR); Docp = Bp->NewVal(TYPE_JAR);
Bp->AddArrayValue(Docp, jsp); Bp->AddArrayValue(Docp, jsp);
Bp->SetArrayValue(arp, Docp, i); Bp->SetArrayValue(arp, Docp, i);
} else } else {
Top = Docp = Bp->NewVal(TYPE_JAR); Top = Docp = Bp->NewVal(TYPE_JAR);
Bp->AddArrayValue(Docp, jsp);
} // endif's
} // endif jsp } // endif jsp
......
...@@ -265,6 +265,7 @@ class DllExport BSONCOL : public DOSCOL { ...@@ -265,6 +265,7 @@ class DllExport BSONCOL : public DOSCOL {
char Sep; // The Jpath separator char Sep; // The Jpath separator
bool Xpd; // True for expandable column bool Xpd; // True for expandable column
bool Parsed; // True when parsed bool Parsed; // True when parsed
bool Warned; // True when warning issued
}; // end of class BSONCOL }; // end of class BSONCOL
/* -------------------------- TDBBSON class -------------------------- */ /* -------------------------- TDBBSON class -------------------------- */
......
...@@ -1255,6 +1255,7 @@ JSONCOL::JSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) ...@@ -1255,6 +1255,7 @@ JSONCOL::JSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i)
Xnod = -1; Xnod = -1;
Xpd = false; Xpd = false;
Parsed = false; Parsed = false;
Warned = false;
} // end of JSONCOL constructor } // end of JSONCOL constructor
/***********************************************************************/ /***********************************************************************/
...@@ -1273,6 +1274,7 @@ JSONCOL::JSONCOL(JSONCOL *col1, PTDB tdbp) : DOSCOL(col1, tdbp) ...@@ -1273,6 +1274,7 @@ JSONCOL::JSONCOL(JSONCOL *col1, PTDB tdbp) : DOSCOL(col1, tdbp)
Xnod = col1->Xnod; Xnod = col1->Xnod;
Xpd = col1->Xpd; Xpd = col1->Xpd;
Parsed = col1->Parsed; Parsed = col1->Parsed;
Warned = col1->Warned;
} // end of JSONCOL copy constructor } // end of JSONCOL copy constructor
/***********************************************************************/ /***********************************************************************/
...@@ -1606,6 +1608,12 @@ PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp) ...@@ -1606,6 +1608,12 @@ PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp)
{ {
if (Value->IsTypeNum()) { if (Value->IsTypeNum()) {
strcpy(g->Message, "Cannot make Json for a numeric column"); strcpy(g->Message, "Cannot make Json for a numeric column");
if (!Warned) {
PushWarning(g, Tjp);
Warned = true;
} // endif Warned
Value->Reset(); Value->Reset();
#if 0 #if 0
} else if (Value->GetType() == TYPE_BIN) { } else if (Value->GetType() == TYPE_BIN) {
...@@ -1703,8 +1711,8 @@ void JSONCOL::ReadColumn(PGLOBAL g) ...@@ -1703,8 +1711,8 @@ void JSONCOL::ReadColumn(PGLOBAL g)
if (!Tjp->SameRow || Xnod >= Tjp->SameRow) if (!Tjp->SameRow || Xnod >= Tjp->SameRow)
Value->SetValue_pval(GetColumnValue(g, Tjp->Row, 0)); Value->SetValue_pval(GetColumnValue(g, Tjp->Row, 0));
if (Xpd && Value->IsNull() && !((PJDEF)Tjp->To_Def)->Accept) // if (Xpd && Value->IsNull() && !((PJDEF)Tjp->To_Def)->Accept)
throw("Null expandable JSON value"); // throw("Null expandable JSON value");
// Set null when applicable // Set null when applicable
if (!Nullable) if (!Nullable)
......
...@@ -192,7 +192,8 @@ class DllExport TDBJSN : public TDBDOS { ...@@ -192,7 +192,8 @@ class DllExport TDBJSN : public TDBDOS {
char Sep; // The Jpath separator char Sep; // The Jpath separator
bool Strict; // Strict syntax checking bool Strict; // Strict syntax checking
bool Comma; // Row has final comma bool Comma; // Row has final comma
}; // end of class TDBJSN bool Xpdable; // False: expandable columns are NULL
}; // end of class TDBJSN
/* -------------------------- JSONCOL class -------------------------- */ /* -------------------------- JSONCOL class -------------------------- */
...@@ -247,7 +248,8 @@ class DllExport JSONCOL : public DOSCOL { ...@@ -247,7 +248,8 @@ class DllExport JSONCOL : public DOSCOL {
char Sep; // The Jpath separator char Sep; // The Jpath separator
bool Xpd; // True for expandable column bool Xpd; // True for expandable column
bool Parsed; // True when parsed bool Parsed; // True when parsed
}; // end of class JSONCOL bool Warned; // True when warning issued
}; // end of class JSONCOL
/* -------------------------- TDBJSON class -------------------------- */ /* -------------------------- TDBJSON class -------------------------- */
......
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