Skip to content

Commit

Permalink
- Make function strz return null when LEX_STRING is null
Browse files Browse the repository at this point in the history
  modified:   storage/connect/ha_connect.cc

- Use NOTE instead of WARNING in connect_assisted_discovery
  This because MariaDB raise an error when doing so
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/tabrest.cpp

- Make MONGO tables recognize STRINGIFY and JsonAllPath
  modified:   storage/connect/mongo.cpp
  modified:   storage/connect/mongo.h
  modified:   storage/connect/tabcmg.h
  modified:   storage/connect/tabjmg.cpp
  modified:   storage/connect/tabcmg.cpp
  modified:   storage/connect/tabjmg.h

- Fix OBJECT option for Pretty != 2 JSN and BSON tables
  Accept all syntaxes  for the OBJECT option
  modified:   storage/connect/tabbson.cpp
  modified:   storage/connect/tabjson.cpp

- Use my_snprintf in function xcurl (by vuvova)
  modified:   storage/connect/tabrest.cpp

- Format dates entered as integer when formatted
  modified:   storage/connect/value.cpp
  modified:   storage/connect/value.h
  • Loading branch information
Buggynours committed Jun 23, 2021
1 parent 5f64276 commit ed70f76
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 85 deletions.
30 changes: 17 additions & 13 deletions storage/connect/ha_connect.cc
Expand Up @@ -290,10 +290,14 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
/****************************************************************************/
static char *strz(PGLOBAL g, LEX_STRING &ls)
{
char *str= (char*)PlugSubAlloc(g, NULL, ls.length + 1);
char* str= NULL;

if (ls.str) {
str= (char*)PlugSubAlloc(g, NULL, ls.length + 1);
memcpy(str, ls.str, ls.length);
str[ls.length] = 0;
} // endif str

memcpy(str, ls.str, ls.length);
str[ls.length]= 0;
return str;
} // end of strz

Expand Down Expand Up @@ -5625,7 +5629,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#endif // JAVA_SUPPORT
uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL);
bool bif, ok= false, dbf= false;
TABTYPE ttp= TAB_UNDEF;
TABTYPE ttp= TAB_UNDEF, ttr=TAB_UNDEF;
PQRYRES qrp= NULL;
PCOLRES crp;
PCONNECT xp= NULL;
Expand Down Expand Up @@ -5707,21 +5711,21 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
topt->type= (src) ? "MYSQL" : (tab) ? "PROXY" : "DOS";
ttp= GetTypeID(topt->type);
sprintf(g->Message, "No table_type. Was set to %s", topt->type);
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, 0, g->Message);
} else if (ttp == TAB_NIY) {
sprintf(g->Message, "Unsupported table type %s", topt->type);
rc= HA_ERR_INTERNAL_ERROR;
goto err;
#if defined(REST_SUPPORT)
} else if (topt->http) {
if (ttp == TAB_UNDEF) {
topt->type = "JSON";
ttp= GetTypeID(topt->type);
sprintf(g->Message, "No table_type. Was set to %s", topt->type);
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
} // endif ttp
ttr= TAB_JSON;
strcpy(g->Message, "No table_type. Was set to JSON");
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, 0, g->Message);
} else
ttr= ttp;

switch (ttp) {
switch (ttr) {
case TAB_JSON:
#if defined(BSON_SUPPORT)
case TAB_BSON:
Expand Down Expand Up @@ -5956,7 +5960,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if defined(REST_SUPPORT)
case TAB_REST:
if (!topt->http)
sprintf(g->Message, "Missing %s HTTP address", topt->type);
strcpy(g->Message, "Missing REST HTTP option");
else
ok = true;

Expand Down Expand Up @@ -6176,7 +6180,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,

// Restore language type
if (ttp == TAB_REST)
ttp = GetTypeID(topt->type);
ttp = ttr;

for (i= 0; !rc && i < qrp->Nblin; i++) {
typ= len= prec= dec= flg= 0;
Expand Down
8 changes: 5 additions & 3 deletions storage/connect/mongo.cpp
@@ -1,6 +1,6 @@
/************** mongo C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: mongo Version 1.0 */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* PROGRAM NAME: mongo Version 1.1 */
/* (C) Copyright to the author Olivier BERTRAND 2021 */
/* These programs are the MGODEF class execution routines. */
/***********************************************************************/

Expand Down Expand Up @@ -36,6 +36,7 @@
bool MakeSelector(PGLOBAL g, PFIL fp, PSTRG s);
bool IsNum(PSZ s);
int GetDefaultDepth(void);
bool JsonAllPath(void);

/***********************************************************************/
/* Make selector json representation for Mongo tables. */
Expand Down Expand Up @@ -350,7 +351,7 @@ void MGODISC::AddColumn(PGLOBAL g, PCSZ colname, PCSZ fmt, int k)
bcp->Name = PlugDup(g, colname);
length[0] = MY_MAX(length[0], (signed)strlen(colname));

if (k) {
if (k || JsonAllPath()) {
bcp->Fmt = PlugDup(g, fmt);
length[7] = MY_MAX(length[7], (signed)strlen(fmt));
} else
Expand Down Expand Up @@ -395,6 +396,7 @@ bool MGODEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
Uri = GetStringCatInfo(g, "Connect", "mongodb://localhost:27017");
Colist = GetStringCatInfo(g, "Colist", NULL);
Filter = GetStringCatInfo(g, "Filter", NULL);
Strfy = GetStringCatInfo(g, "Stringify", NULL);
Base = GetIntCatInfo("Base", 0) ? 1 : 0;
Version = GetIntCatInfo("Version", 3);

Expand Down
5 changes: 3 additions & 2 deletions storage/connect/mongo.h
@@ -1,7 +1,7 @@
/**************** mongo H Declares Source Code File (.H) ***************/
/* Name: mongo.h Version 1.0 */
/* Name: mongo.h Version 1.1 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* (C) Copyright to the author Olivier BERTRAND 2021 */
/* */
/* This file contains the common MongoDB classes declares. */
/***********************************************************************/
Expand Down Expand Up @@ -82,6 +82,7 @@ class DllExport MGODEF : public EXTDEF { /* Table description */
PSZ Wrapname; /* Java wrapper name */
PCSZ Colist; /* Options list */
PCSZ Filter; /* Filtering query */
PCSZ Strfy; /* Stringify column */
int Base; /* The array index base */
int Version; /* The Java driver version */
bool Pipe; /* True is Colist is a pipeline */
Expand Down
92 changes: 66 additions & 26 deletions storage/connect/tabbson.cpp
@@ -1,5 +1,5 @@
/************* tabbson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabbson Version 1.1 */
/* PROGRAM NAME: tabbson Version 1.2 */
/* (C) Copyright to the author Olivier BERTRAND 2020 - 2021 */
/* This program are the BSON class DB execution routines. */
/***********************************************************************/
Expand Down Expand Up @@ -193,7 +193,11 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
if (!(tdp->Database = SetPath(g, db)))
return 0;

tdp->Objname = GetStringTableOption(g, topt, "Object", NULL);
if ((tdp->Objname = GetStringTableOption(g, topt, "Object", NULL))) {
if (*tdp->Objname == '$') tdp->Objname++;
if (*tdp->Objname == '.') tdp->Objname++;
} // endif Objname

tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0;
tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2);
tdp->Xcol = GetStringTableOption(g, topt, "Expand", NULL);
Expand Down Expand Up @@ -603,33 +607,51 @@ void BSONDISC::AddColumn(PGLOBAL g)
/***********************************************************************/
PBVAL BTUTIL::FindRow(PGLOBAL g)
{
char *p, *objpath;
char *p, *objpath = PlugDup(g, Tp->Objname);
char *sep = (Tp->Sep == ':') ? ":[" : ".[";
bool bp = false, b = false;
PBVAL jsp = Tp->Row;
PBVAL val = NULL;

for (objpath = PlugDup(g, Tp->Objname); jsp && objpath; objpath = p) {
if ((p = strchr(objpath, Tp->Sep)))
for (; jsp && objpath; objpath = p, bp = b) {
if ((p = strpbrk(objpath + 1, sep))) {
b = (*p == '[');
*p++ = 0;
} // endif p

if (*objpath != '[' && !IsNum(objpath)) { // objpass is a key
if (!bp && *objpath != '[' && !IsNum(objpath)) { // objpass is a key
val = (jsp->Type == TYPE_JOB) ?
GetKeyValue(jsp, objpath) : NULL;
} else {
if (*objpath == '[') {
if (objpath[strlen(objpath) - 1] == ']')
objpath++;
else
if (bp || *objpath == '[') { // Old style
if (objpath[strlen(objpath) - 1] != ']') {
sprintf(g->Message, "Invalid Table path %s", Tp->Objname);
return NULL;
} // endif [
} else if (!bp)
objpath++;

} // endif bp

val = (jsp->Type == TYPE_JAR) ?
GetArrayValue(GetArray(jsp), atoi(objpath) - Tp->B) : NULL;
GetArrayValue(jsp, atoi(objpath) - Tp->B) : NULL;
} // endif objpath

// jsp = (val) ? val->GetJson() : NULL;
jsp = val;
} // endfor objpath

if (jsp && jsp->Type != TYPE_JOB) {
if (jsp->Type == TYPE_JAR) {
jsp = GetArrayValue(jsp, Tp->B);

if (jsp->Type != TYPE_JOB)
jsp = NULL;

} else
jsp = NULL;

} // endif Type

return jsp;
} // end of FindRow

Expand All @@ -653,17 +675,22 @@ PBVAL BTUTIL::MakeTopTree(PGLOBAL g, int type)
if (Tp->Objname) {
if (!Tp->Row) {
// Parse and allocate Objpath item(s)
char* p;
char *objpath = PlugDup(g, Tp->Objname);
char *p, *objpath = PlugDup(g, Tp->Objname);
char *sep = (Tp->Sep == ':') ? ":[" : ".[";
int i;
bool bp = false, b = false;
PBVAL objp = NULL;
PBVAL arp = NULL;

for (; objpath; objpath = p) {
if ((p = strchr(objpath, Tp->Sep)))
for (; objpath; objpath = p, bp = b) {
if ((p = strpbrk(objpath + 1, sep))) {
b = (*p == '[');
*p++ = 0;
} // endif p

if (*objpath != '[' && !IsNum(objpath)) {

if (!bp && *objpath != '[' && !IsNum(objpath)) {
// objpass is a key
objp = NewVal(TYPE_JOB);

if (!top)
Expand All @@ -675,15 +702,15 @@ PBVAL BTUTIL::MakeTopTree(PGLOBAL g, int type)
val = NewVal();
SetKeyValue(objp, MOF(val), objpath);
} else {
if (*objpath == '[') {
if (bp || *objpath == '[') {
// Old style
if (objpath[strlen(objpath) - 1] != ']') {
sprintf(g->Message, "Invalid Table path %s", Tp->Objname);
return NULL;
} else
} else if (!bp)
objpath++;

} // endif objpath
} // endif bp

if (!top)
top = NewVal(TYPE_JAR);
Expand Down Expand Up @@ -755,10 +782,16 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
break;
case TYPE_DATE:
if (jvp->Type == TYPE_STRG) {
if (!((DTVAL*)vp)->IsFormatted())
((DTVAL*)vp)->SetFormat(g, "YYYY-MM-DDThh:mm:ssZ", 20, 0);
PSZ dat = GetString(jvp);

if (!IsNum(dat)) {
if (!((DTVAL*)vp)->IsFormatted())
((DTVAL*)vp)->SetFormat(g, "YYYY-MM-DDThh:mm:ssZ", 20, 0);

vp->SetValue_psz(dat);
} else
vp->SetValue(atoi(dat));

vp->SetValue_psz(GetString(jvp));
} else
vp->SetValue(GetInteger(jvp));

Expand Down Expand Up @@ -1156,7 +1189,12 @@ bool BSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
G = g;
Schema = GetStringCatInfo(g, "DBname", Schema);
Jmode = (JMODE)GetIntCatInfo("Jmode", MODE_OBJECT);
Objname = GetStringCatInfo(g, "Object", NULL);

if ((Objname = GetStringCatInfo(g, "Object", NULL))) {
if (*Objname == '$') Objname++;
if (*Objname == '.') Objname++;
} // endif Objname

Xcol = GetStringCatInfo(g, "Expand", NULL);
Pretty = GetIntCatInfo("Pretty", 2);
Limit = GetIntCatInfo("Limit", 50);
Expand Down Expand Up @@ -1935,6 +1973,10 @@ bool BSONCOL::ParseJpath(PGLOBAL g)
// Analyse intermediate array processing
if (SetArrayOptions(g, p, i, Nodes[i - 1].Key))
return true;
else if (Xpd && Tbp->Mode == MODE_DELETE) {
strcpy(g->Message, "Cannot delete expanded columns");
return true;
} // endif Xpd

} else if (*p == '*') {
// Return JSON
Expand Down Expand Up @@ -2237,8 +2279,6 @@ int TDBBSON::MakeDocument(PGLOBAL g)
return RC_FX;

if ((objpath = PlugDup(g, Objname))) {
if (*objpath == '$') objpath++;
if (*objpath == '.') objpath++;
p1 = (*objpath == '[') ? objpath++ : NULL;

/*********************************************************************/
Expand Down
7 changes: 5 additions & 2 deletions storage/connect/tabcmg.cpp
@@ -1,5 +1,5 @@
/************** tabcmg C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabcmg Version 1.2 */
/* PROGRAM NAME: tabcmg Version 1.3 */
/* (C) Copyright to the author Olivier BERTRAND 2017 - 2021 */
/* This program are the C MongoDB class DB execution routines. */
/***********************************************************************/
Expand Down Expand Up @@ -192,6 +192,7 @@ TDBCMG::TDBCMG(MGODEF *tdp) : TDBEXT(tdp)
Pcg.Line = NULL;
Pcg.Pipe = tdp->Pipe && tdp->Colist != NULL;
B = tdp->Base ? 1 : 0;
Strfy = tdp->Strfy;
} else {
Pcg.Uristr = NULL;
Pcg.Db_name = NULL;
Expand All @@ -200,6 +201,7 @@ TDBCMG::TDBCMG(MGODEF *tdp) : TDBEXT(tdp)
Pcg.Filter = NULL;
Pcg.Line = NULL;
Pcg.Pipe = false;
Strfy = NULL;
B = 0;
} // endif tdp

Expand All @@ -213,6 +215,7 @@ TDBCMG::TDBCMG(TDBCMG *tdbp) : TDBEXT(tdbp)
Cmgp = tdbp->Cmgp;
Cnd = tdbp->Cnd;
Pcg = tdbp->Pcg;
Strfy = tdbp->Strfy;
B = tdbp->B;
Fpos = tdbp->Fpos;
N = tdbp->N;
Expand Down Expand Up @@ -394,7 +397,7 @@ MGOCOL::MGOCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i)
: EXTCOL(cdp, tdbp, cprec, i, "MGO")
{
Tmgp = (PTDBCMG)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp);
Sgfy = false;
Sgfy = (Tmgp->Strfy && !stricmp(Tmgp->Strfy, Name));

if ((Jpath = cdp->GetFmt())) {
int n = strlen(Jpath) - 1;
Expand Down
1 change: 1 addition & 0 deletions storage/connect/tabcmg.h
Expand Up @@ -75,6 +75,7 @@ class DllExport TDBCMG : public TDBEXT {
CMgoConn *Cmgp; // Points to a C Mongo connection class
CMGOPARM Pcg; // Parms passed to Cmgp
const Item *Cnd; // The first condition
PCSZ Strfy; // The stringified column
int Fpos; // The current row index
int N; // The current Rownum
int B; // Array index base
Expand Down
9 changes: 6 additions & 3 deletions storage/connect/tabjmg.cpp
@@ -1,6 +1,6 @@
/************** tabjmg C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjmg Version 1.2 */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* PROGRAM NAME: tabjmg Version 1.3 */
/* (C) Copyright to the author Olivier BERTRAND 2021 */
/* This file contains the MongoDB classes using the Java Driver. */
/***********************************************************************/

Expand Down Expand Up @@ -166,6 +166,7 @@ TDBJMG::TDBJMG(PMGODEF tdp) : TDBEXT(tdp)
Coll_name = tdp->Tabname;
Options = tdp->Colist;
Filter = tdp->Filter;
Strfy = tdp->Strfy;
B = tdp->Base ? 1 : 0;
Pipe = tdp->Pipe && Options != NULL;
} else {
Expand All @@ -177,6 +178,7 @@ TDBJMG::TDBJMG(PMGODEF tdp) : TDBEXT(tdp)
Coll_name = NULL;
Options = NULL;
Filter = NULL;
Strfy = NULL;
B = 0;
Pipe = false;
} // endif tdp
Expand All @@ -197,6 +199,7 @@ TDBJMG::TDBJMG(TDBJMG *tdbp) : TDBEXT(tdbp)
Coll_name = tdbp->Coll_name;
Options = tdbp->Options;
Filter = tdbp->Filter;
Strfy = tdbp->Strfy;
B = tdbp->B;
Fpos = tdbp->Fpos;
N = tdbp->N;
Expand Down Expand Up @@ -420,7 +423,7 @@ JMGCOL::JMGCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i)
: EXTCOL(cdp, tdbp, cprec, i, "MGO")
{
Tmgp = (PTDBJMG)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp);
Sgfy = false;
Sgfy = (Tmgp->Strfy && !stricmp(Tmgp->Strfy, Name));

if ((Jpath = cdp->GetFmt())) {
int n = strlen(Jpath) - 1;
Expand Down

0 comments on commit ed70f76

Please sign in to comment.