Skip to content

Commit ed70f76

Browse files
committed
- Make function strz return null when LEX_STRING is null
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
1 parent 5f64276 commit ed70f76

File tree

12 files changed

+201
-85
lines changed

12 files changed

+201
-85
lines changed

storage/connect/ha_connect.cc

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,14 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
290290
/****************************************************************************/
291291
static char *strz(PGLOBAL g, LEX_STRING &ls)
292292
{
293-
char *str= (char*)PlugSubAlloc(g, NULL, ls.length + 1);
293+
char* str= NULL;
294+
295+
if (ls.str) {
296+
str= (char*)PlugSubAlloc(g, NULL, ls.length + 1);
297+
memcpy(str, ls.str, ls.length);
298+
str[ls.length] = 0;
299+
} // endif str
294300

295-
memcpy(str, ls.str, ls.length);
296-
str[ls.length]= 0;
297301
return str;
298302
} // end of strz
299303

@@ -5625,7 +5629,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
56255629
#endif // JAVA_SUPPORT
56265630
uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL);
56275631
bool bif, ok= false, dbf= false;
5628-
TABTYPE ttp= TAB_UNDEF;
5632+
TABTYPE ttp= TAB_UNDEF, ttr=TAB_UNDEF;
56295633
PQRYRES qrp= NULL;
56305634
PCOLRES crp;
56315635
PCONNECT xp= NULL;
@@ -5707,21 +5711,21 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
57075711
topt->type= (src) ? "MYSQL" : (tab) ? "PROXY" : "DOS";
57085712
ttp= GetTypeID(topt->type);
57095713
sprintf(g->Message, "No table_type. Was set to %s", topt->type);
5710-
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
5714+
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, 0, g->Message);
57115715
} else if (ttp == TAB_NIY) {
57125716
sprintf(g->Message, "Unsupported table type %s", topt->type);
57135717
rc= HA_ERR_INTERNAL_ERROR;
57145718
goto err;
57155719
#if defined(REST_SUPPORT)
57165720
} else if (topt->http) {
57175721
if (ttp == TAB_UNDEF) {
5718-
topt->type = "JSON";
5719-
ttp= GetTypeID(topt->type);
5720-
sprintf(g->Message, "No table_type. Was set to %s", topt->type);
5721-
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
5722-
} // endif ttp
5722+
ttr= TAB_JSON;
5723+
strcpy(g->Message, "No table_type. Was set to JSON");
5724+
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, 0, g->Message);
5725+
} else
5726+
ttr= ttp;
57235727

5724-
switch (ttp) {
5728+
switch (ttr) {
57255729
case TAB_JSON:
57265730
#if defined(BSON_SUPPORT)
57275731
case TAB_BSON:
@@ -5956,7 +5960,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
59565960
#if defined(REST_SUPPORT)
59575961
case TAB_REST:
59585962
if (!topt->http)
5959-
sprintf(g->Message, "Missing %s HTTP address", topt->type);
5963+
strcpy(g->Message, "Missing REST HTTP option");
59605964
else
59615965
ok = true;
59625966

@@ -6176,7 +6180,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
61766180

61776181
// Restore language type
61786182
if (ttp == TAB_REST)
6179-
ttp = GetTypeID(topt->type);
6183+
ttp = ttr;
61806184

61816185
for (i= 0; !rc && i < qrp->Nblin; i++) {
61826186
typ= len= prec= dec= flg= 0;

storage/connect/mongo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/************** mongo C++ Program Source Code File (.CPP) **************/
2-
/* PROGRAM NAME: mongo Version 1.0 */
3-
/* (C) Copyright to the author Olivier BERTRAND 2017 */
2+
/* PROGRAM NAME: mongo Version 1.1 */
3+
/* (C) Copyright to the author Olivier BERTRAND 2021 */
44
/* These programs are the MGODEF class execution routines. */
55
/***********************************************************************/
66

@@ -36,6 +36,7 @@
3636
bool MakeSelector(PGLOBAL g, PFIL fp, PSTRG s);
3737
bool IsNum(PSZ s);
3838
int GetDefaultDepth(void);
39+
bool JsonAllPath(void);
3940

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

353-
if (k) {
354+
if (k || JsonAllPath()) {
354355
bcp->Fmt = PlugDup(g, fmt);
355356
length[7] = MY_MAX(length[7], (signed)strlen(fmt));
356357
} else
@@ -395,6 +396,7 @@ bool MGODEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
395396
Uri = GetStringCatInfo(g, "Connect", "mongodb://localhost:27017");
396397
Colist = GetStringCatInfo(g, "Colist", NULL);
397398
Filter = GetStringCatInfo(g, "Filter", NULL);
399+
Strfy = GetStringCatInfo(g, "Stringify", NULL);
398400
Base = GetIntCatInfo("Base", 0) ? 1 : 0;
399401
Version = GetIntCatInfo("Version", 3);
400402

storage/connect/mongo.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**************** mongo H Declares Source Code File (.H) ***************/
2-
/* Name: mongo.h Version 1.0 */
2+
/* Name: mongo.h Version 1.1 */
33
/* */
4-
/* (C) Copyright to the author Olivier BERTRAND 2017 */
4+
/* (C) Copyright to the author Olivier BERTRAND 2021 */
55
/* */
66
/* This file contains the common MongoDB classes declares. */
77
/***********************************************************************/
@@ -82,6 +82,7 @@ class DllExport MGODEF : public EXTDEF { /* Table description */
8282
PSZ Wrapname; /* Java wrapper name */
8383
PCSZ Colist; /* Options list */
8484
PCSZ Filter; /* Filtering query */
85+
PCSZ Strfy; /* Stringify column */
8586
int Base; /* The array index base */
8687
int Version; /* The Java driver version */
8788
bool Pipe; /* True is Colist is a pipeline */

storage/connect/tabbson.cpp

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/************* tabbson C++ Program Source Code File (.CPP) *************/
2-
/* PROGRAM NAME: tabbson Version 1.1 */
2+
/* PROGRAM NAME: tabbson Version 1.2 */
33
/* (C) Copyright to the author Olivier BERTRAND 2020 - 2021 */
44
/* This program are the BSON class DB execution routines. */
55
/***********************************************************************/
@@ -193,7 +193,11 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
193193
if (!(tdp->Database = SetPath(g, db)))
194194
return 0;
195195

196-
tdp->Objname = GetStringTableOption(g, topt, "Object", NULL);
196+
if ((tdp->Objname = GetStringTableOption(g, topt, "Object", NULL))) {
197+
if (*tdp->Objname == '$') tdp->Objname++;
198+
if (*tdp->Objname == '.') tdp->Objname++;
199+
} // endif Objname
200+
197201
tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0;
198202
tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2);
199203
tdp->Xcol = GetStringTableOption(g, topt, "Expand", NULL);
@@ -603,33 +607,51 @@ void BSONDISC::AddColumn(PGLOBAL g)
603607
/***********************************************************************/
604608
PBVAL BTUTIL::FindRow(PGLOBAL g)
605609
{
606-
char *p, *objpath;
610+
char *p, *objpath = PlugDup(g, Tp->Objname);
611+
char *sep = (Tp->Sep == ':') ? ":[" : ".[";
612+
bool bp = false, b = false;
607613
PBVAL jsp = Tp->Row;
608614
PBVAL val = NULL;
609615

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

614-
if (*objpath != '[' && !IsNum(objpath)) { // objpass is a key
622+
if (!bp && *objpath != '[' && !IsNum(objpath)) { // objpass is a key
615623
val = (jsp->Type == TYPE_JOB) ?
616624
GetKeyValue(jsp, objpath) : NULL;
617625
} else {
618-
if (*objpath == '[') {
619-
if (objpath[strlen(objpath) - 1] == ']')
620-
objpath++;
621-
else
626+
if (bp || *objpath == '[') { // Old style
627+
if (objpath[strlen(objpath) - 1] != ']') {
628+
sprintf(g->Message, "Invalid Table path %s", Tp->Objname);
622629
return NULL;
623-
} // endif [
630+
} else if (!bp)
631+
objpath++;
632+
633+
} // endif bp
624634

625635
val = (jsp->Type == TYPE_JAR) ?
626-
GetArrayValue(GetArray(jsp), atoi(objpath) - Tp->B) : NULL;
636+
GetArrayValue(jsp, atoi(objpath) - Tp->B) : NULL;
627637
} // endif objpath
628638

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

643+
if (jsp && jsp->Type != TYPE_JOB) {
644+
if (jsp->Type == TYPE_JAR) {
645+
jsp = GetArrayValue(jsp, Tp->B);
646+
647+
if (jsp->Type != TYPE_JOB)
648+
jsp = NULL;
649+
650+
} else
651+
jsp = NULL;
652+
653+
} // endif Type
654+
633655
return jsp;
634656
} // end of FindRow
635657

@@ -653,17 +675,22 @@ PBVAL BTUTIL::MakeTopTree(PGLOBAL g, int type)
653675
if (Tp->Objname) {
654676
if (!Tp->Row) {
655677
// Parse and allocate Objpath item(s)
656-
char* p;
657-
char *objpath = PlugDup(g, Tp->Objname);
678+
char *p, *objpath = PlugDup(g, Tp->Objname);
679+
char *sep = (Tp->Sep == ':') ? ":[" : ".[";
658680
int i;
681+
bool bp = false, b = false;
659682
PBVAL objp = NULL;
660683
PBVAL arp = NULL;
661684

662-
for (; objpath; objpath = p) {
663-
if ((p = strchr(objpath, Tp->Sep)))
685+
for (; objpath; objpath = p, bp = b) {
686+
if ((p = strpbrk(objpath + 1, sep))) {
687+
b = (*p == '[');
664688
*p++ = 0;
689+
} // endif p
665690

666-
if (*objpath != '[' && !IsNum(objpath)) {
691+
692+
if (!bp && *objpath != '[' && !IsNum(objpath)) {
693+
// objpass is a key
667694
objp = NewVal(TYPE_JOB);
668695

669696
if (!top)
@@ -675,15 +702,15 @@ PBVAL BTUTIL::MakeTopTree(PGLOBAL g, int type)
675702
val = NewVal();
676703
SetKeyValue(objp, MOF(val), objpath);
677704
} else {
678-
if (*objpath == '[') {
705+
if (bp || *objpath == '[') {
679706
// Old style
680707
if (objpath[strlen(objpath) - 1] != ']') {
681708
sprintf(g->Message, "Invalid Table path %s", Tp->Objname);
682709
return NULL;
683-
} else
710+
} else if (!bp)
684711
objpath++;
685712

686-
} // endif objpath
713+
} // endif bp
687714

688715
if (!top)
689716
top = NewVal(TYPE_JAR);
@@ -755,10 +782,16 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
755782
break;
756783
case TYPE_DATE:
757784
if (jvp->Type == TYPE_STRG) {
758-
if (!((DTVAL*)vp)->IsFormatted())
759-
((DTVAL*)vp)->SetFormat(g, "YYYY-MM-DDThh:mm:ssZ", 20, 0);
785+
PSZ dat = GetString(jvp);
786+
787+
if (!IsNum(dat)) {
788+
if (!((DTVAL*)vp)->IsFormatted())
789+
((DTVAL*)vp)->SetFormat(g, "YYYY-MM-DDThh:mm:ssZ", 20, 0);
790+
791+
vp->SetValue_psz(dat);
792+
} else
793+
vp->SetValue(atoi(dat));
760794

761-
vp->SetValue_psz(GetString(jvp));
762795
} else
763796
vp->SetValue(GetInteger(jvp));
764797

@@ -1156,7 +1189,12 @@ bool BSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
11561189
G = g;
11571190
Schema = GetStringCatInfo(g, "DBname", Schema);
11581191
Jmode = (JMODE)GetIntCatInfo("Jmode", MODE_OBJECT);
1159-
Objname = GetStringCatInfo(g, "Object", NULL);
1192+
1193+
if ((Objname = GetStringCatInfo(g, "Object", NULL))) {
1194+
if (*Objname == '$') Objname++;
1195+
if (*Objname == '.') Objname++;
1196+
} // endif Objname
1197+
11601198
Xcol = GetStringCatInfo(g, "Expand", NULL);
11611199
Pretty = GetIntCatInfo("Pretty", 2);
11621200
Limit = GetIntCatInfo("Limit", 50);
@@ -1935,6 +1973,10 @@ bool BSONCOL::ParseJpath(PGLOBAL g)
19351973
// Analyse intermediate array processing
19361974
if (SetArrayOptions(g, p, i, Nodes[i - 1].Key))
19371975
return true;
1976+
else if (Xpd && Tbp->Mode == MODE_DELETE) {
1977+
strcpy(g->Message, "Cannot delete expanded columns");
1978+
return true;
1979+
} // endif Xpd
19381980

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

22392281
if ((objpath = PlugDup(g, Objname))) {
2240-
if (*objpath == '$') objpath++;
2241-
if (*objpath == '.') objpath++;
22422282
p1 = (*objpath == '[') ? objpath++ : NULL;
22432283

22442284
/*********************************************************************/

storage/connect/tabcmg.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/************** tabcmg C++ Program Source Code File (.CPP) *************/
2-
/* PROGRAM NAME: tabcmg Version 1.2 */
2+
/* PROGRAM NAME: tabcmg Version 1.3 */
33
/* (C) Copyright to the author Olivier BERTRAND 2017 - 2021 */
44
/* This program are the C MongoDB class DB execution routines. */
55
/***********************************************************************/
@@ -192,6 +192,7 @@ TDBCMG::TDBCMG(MGODEF *tdp) : TDBEXT(tdp)
192192
Pcg.Line = NULL;
193193
Pcg.Pipe = tdp->Pipe && tdp->Colist != NULL;
194194
B = tdp->Base ? 1 : 0;
195+
Strfy = tdp->Strfy;
195196
} else {
196197
Pcg.Uristr = NULL;
197198
Pcg.Db_name = NULL;
@@ -200,6 +201,7 @@ TDBCMG::TDBCMG(MGODEF *tdp) : TDBEXT(tdp)
200201
Pcg.Filter = NULL;
201202
Pcg.Line = NULL;
202203
Pcg.Pipe = false;
204+
Strfy = NULL;
203205
B = 0;
204206
} // endif tdp
205207

@@ -213,6 +215,7 @@ TDBCMG::TDBCMG(TDBCMG *tdbp) : TDBEXT(tdbp)
213215
Cmgp = tdbp->Cmgp;
214216
Cnd = tdbp->Cnd;
215217
Pcg = tdbp->Pcg;
218+
Strfy = tdbp->Strfy;
216219
B = tdbp->B;
217220
Fpos = tdbp->Fpos;
218221
N = tdbp->N;
@@ -394,7 +397,7 @@ MGOCOL::MGOCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i)
394397
: EXTCOL(cdp, tdbp, cprec, i, "MGO")
395398
{
396399
Tmgp = (PTDBCMG)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp);
397-
Sgfy = false;
400+
Sgfy = (Tmgp->Strfy && !stricmp(Tmgp->Strfy, Name));
398401

399402
if ((Jpath = cdp->GetFmt())) {
400403
int n = strlen(Jpath) - 1;

storage/connect/tabcmg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class DllExport TDBCMG : public TDBEXT {
7575
CMgoConn *Cmgp; // Points to a C Mongo connection class
7676
CMGOPARM Pcg; // Parms passed to Cmgp
7777
const Item *Cnd; // The first condition
78+
PCSZ Strfy; // The stringified column
7879
int Fpos; // The current row index
7980
int N; // The current Rownum
8081
int B; // Array index base

storage/connect/tabjmg.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/************** tabjmg C++ Program Source Code File (.CPP) *************/
2-
/* PROGRAM NAME: tabjmg Version 1.2 */
3-
/* (C) Copyright to the author Olivier BERTRAND 2017 */
2+
/* PROGRAM NAME: tabjmg Version 1.3 */
3+
/* (C) Copyright to the author Olivier BERTRAND 2021 */
44
/* This file contains the MongoDB classes using the Java Driver. */
55
/***********************************************************************/
66

@@ -166,6 +166,7 @@ TDBJMG::TDBJMG(PMGODEF tdp) : TDBEXT(tdp)
166166
Coll_name = tdp->Tabname;
167167
Options = tdp->Colist;
168168
Filter = tdp->Filter;
169+
Strfy = tdp->Strfy;
169170
B = tdp->Base ? 1 : 0;
170171
Pipe = tdp->Pipe && Options != NULL;
171172
} else {
@@ -177,6 +178,7 @@ TDBJMG::TDBJMG(PMGODEF tdp) : TDBEXT(tdp)
177178
Coll_name = NULL;
178179
Options = NULL;
179180
Filter = NULL;
181+
Strfy = NULL;
180182
B = 0;
181183
Pipe = false;
182184
} // endif tdp
@@ -197,6 +199,7 @@ TDBJMG::TDBJMG(TDBJMG *tdbp) : TDBEXT(tdbp)
197199
Coll_name = tdbp->Coll_name;
198200
Options = tdbp->Options;
199201
Filter = tdbp->Filter;
202+
Strfy = tdbp->Strfy;
200203
B = tdbp->B;
201204
Fpos = tdbp->Fpos;
202205
N = tdbp->N;
@@ -420,7 +423,7 @@ JMGCOL::JMGCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i)
420423
: EXTCOL(cdp, tdbp, cprec, i, "MGO")
421424
{
422425
Tmgp = (PTDBJMG)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp);
423-
Sgfy = false;
426+
Sgfy = (Tmgp->Strfy && !stricmp(Tmgp->Strfy, Name));
424427

425428
if ((Jpath = cdp->GetFmt())) {
426429
int n = strlen(Jpath) - 1;

0 commit comments

Comments
 (0)