Skip to content

Commit cd337a3

Browse files
committed
Fix MDEV-12587 MariaDB CONNECT DIR Type
- Subfolder Option: SELECT Query Never Ends modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h Work on MDEV-12667 Crash when using JSON tables modified: storage/connect/tabmgo.cpp modified: storage/connect/connect.cc modified: storage/connect/ha_connect.cc modified: storage/connect/ha_connect.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.cpp Work on MONGO and MGO types modified: storage/connect/mongofam.cpp modified: storage/connect/tabmgo.cpp modified: storage/connect/tabmgo.h Change Base offset for DIR tables on Linux modified: storage/connect/reldef.cpp Typo modified: storage/connect/catalog.h modified: storage/connect/mycat.cc modified: storage/connect/mycat.h Disable all json tests modified: storage/connect/mysql-test/connect/disabled.def
1 parent 2f9db4e commit cd337a3

File tree

16 files changed

+169
-176
lines changed

16 files changed

+169
-176
lines changed

storage/connect/catalog.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ class DllExport CATALOG {
6868
bool GetDefHuge(void) {return DefHuge;}
6969
void SetDefHuge(bool b) {DefHuge = b;}
7070
char *GetCbuf(void) {return Cbuf;}
71-
//char *GetDataPath(void) {return (char*)DataPath;}
7271

7372
// Methods
7473
virtual void Reset(void) {}
75-
//virtual void SetDataPath(PGLOBAL g, const char *path) {}
7674
virtual bool CheckName(PGLOBAL, char*) {return true;}
7775
virtual bool ClearName(PGLOBAL, PSZ) {return true;}
7876
virtual PRELDEF MakeOneTableDesc(PGLOBAL, LPCSTR, LPCSTR) {return NULL;}
@@ -102,7 +100,6 @@ class DllExport CATALOG {
102100
int Cblen; /* Length of suballoc. buffer */
103101
CURTAB Ctb; /* Used to enumerate tables */
104102
bool DefHuge; /* true: tables default to huge */
105-
//LPCSTR DataPath; /* Is the Path of DB data dir */
106103
}; // end of class CATALOG
107104

108105
#endif // __CATALOG__H

storage/connect/connect.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,10 @@ bool CntCheckDB(PGLOBAL g, PHC handler, const char *pathname)
117117
handler);
118118

119119
// Set the database path for this table
120-
handler->SetDataPath(g, pathname);
120+
if (handler->SetDataPath(g, pathname))
121+
return true;
121122

122123
if (dbuserp->Catalog) {
123-
// ((MYCAT *)dbuserp->Catalog)->SetHandler(handler); done later
124-
// ((MYCAT *)dbuserp->Catalog)->SetDataPath(g, pathname);
125124
return false; // Nothing else to do
126125
} // endif Catalog
127126

@@ -138,9 +137,6 @@ bool CntCheckDB(PGLOBAL g, PHC handler, const char *pathname)
138137
if (!(dbuserp->Catalog= new MYCAT(handler)))
139138
return true;
140139

141-
//((MYCAT *)dbuserp->Catalog)->SetDataPath(g, pathname);
142-
//dbuserp->UseTemp= TMP_AUTO;
143-
144140
/*********************************************************************/
145141
/* All is correct. */
146142
/*********************************************************************/

storage/connect/ha_connect.cc

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ PQRYRES VirColumns(PGLOBAL g, bool info);
212212
PQRYRES JSONColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info);
213213
PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info);
214214
#if defined(MONGO_SUPPORT)
215-
PQRYRES MGOColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info);
215+
PQRYRES MGOColumns(PGLOBAL g, char *db, PTOS topt, bool info);
216216
#endif // MONGO_SUPPORT
217217
int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v);
218218
void PushWarning(PGLOBAL g, THD *thd, int level);
@@ -1751,9 +1751,9 @@ void ha_connect::AddColName(char *cp, Field *fp)
17511751
/***********************************************************************/
17521752
/* This function sets the current database path. */
17531753
/***********************************************************************/
1754-
void ha_connect::SetDataPath(PGLOBAL g, const char *path)
1754+
bool ha_connect::SetDataPath(PGLOBAL g, const char *path)
17551755
{
1756-
datapath= SetPath(g, path);
1756+
return (!(datapath= SetPath(g, path)));
17571757
} // end of SetDataPath
17581758

17591759
/****************************************************************************/
@@ -2709,6 +2709,8 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
27092709

27102710
if (x)
27112711
return NULL;
2712+
else
2713+
pb0= pb1= pb2= ph0= ph1= ph2= NULL;
27122714

27132715
if (trace)
27142716
htrc("Cond: Ftype=%d name=%s\n", cond_item->functype(),
@@ -4004,8 +4006,12 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos)
40044006

40054007
tdbp->SetFilter(NULL);
40064008
rc= rnd_next(buf);
4007-
} else
4008-
rc= HA_ERR_KEY_NOT_FOUND;
4009+
} else {
4010+
PGLOBAL g = GetPlug((table) ? table->in_use : NULL, xp);
4011+
strcpy(g->Message, "Not supported by this table type");
4012+
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
4013+
rc= HA_ERR_INTERNAL_ERROR;
4014+
} // endif SetRecpos
40094015

40104016
DBUG_RETURN(rc);
40114017
} // end of rnd_pos
@@ -4071,9 +4077,13 @@ int ha_connect::info(uint flag)
40714077
} // endif xmod
40724078

40734079
// This is necessary for getting file length
4074-
if (table)
4075-
SetDataPath(g, table->s->db.str);
4076-
else
4080+
if (table) {
4081+
if (SetDataPath(g, table->s->db.str)) {
4082+
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
4083+
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
4084+
} // endif SetDataPath
4085+
4086+
} else
40774087
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Should never happen
40784088

40794089
if (!(tdbp= GetTDB(g)))
@@ -5562,13 +5572,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
55625572
break;
55635573
#if defined(MONGO_SUPPORT)
55645574
case TAB_MONGO:
5565-
dsn = strz(g, create_info->connect_string);
5566-
5567-
if (!dsn)
5568-
strcpy(g->Message, "Missing URI");
5569-
else
5570-
ok = true;
5571-
5575+
ok = true;
55725576
break;
55735577
#endif // MONGO_SUPPORT
55745578
case TAB_VIR:
@@ -5595,12 +5599,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
55955599
char *cnm, *rem, *dft, *xtra, *key, *fmt;
55965600
int i, len, prec, dec, typ, flg;
55975601

5598-
// if (cat)
5599-
// cat->SetDataPath(g, table_s->db.str);
5600-
// else
5601-
// return HA_ERR_INTERNAL_ERROR; // Should never happen
5602-
5603-
dpath = SetPath(g, table_s->db.str);
5602+
if (!(dpath = SetPath(g, table_s->db.str))) {
5603+
rc = HA_ERR_INTERNAL_ERROR;
5604+
goto err;
5605+
} // endif dpath
56045606

56055607
if (src && ttp != TAB_PIVOT && ttp != TAB_ODBC && ttp != TAB_JDBC) {
56065608
qrp = SrcColumns(g, host, db, user, pwd, src, port);
@@ -5716,7 +5718,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
57165718
break;
57175719
#if defined(MONGO_SUPPORT)
57185720
case TAB_MONGO:
5719-
qrp = MGOColumns(g, (char*)db, dsn, topt, fnc == FNC_COL);
5721+
qrp = MGOColumns(g, (char*)db, topt, fnc == FNC_COL);
57205722
break;
57215723
#endif // MONGO_SUPPORT
57225724
#if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT)
@@ -6521,11 +6523,10 @@ int ha_connect::create(const char *name, TABLE *table_arg,
65216523
PDBUSER dup= PlgGetUser(g);
65226524
PCATLG cat= (dup) ? dup->Catalog : NULL;
65236525

6524-
SetDataPath(g, table_arg->s->db.str);
6525-
6526-
if (cat) {
6527-
// cat->SetDataPath(g, table_arg->s->db.str);
6528-
6526+
if (SetDataPath(g, table_arg->s->db.str)) {
6527+
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
6528+
rc = HA_ERR_INTERNAL_ERROR;
6529+
} else if (cat) {
65296530
#if defined(WITH_PARTITION_STORAGE_ENGINE)
65306531
if (part_info)
65316532
strncpy(partname,

storage/connect/ha_connect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class ha_connect: public handler
199199
bool IsUnique(uint n);
200200
char *GetDataPath(void) {return (char*)datapath;}
201201

202-
void SetDataPath(PGLOBAL g, const char *path);
202+
bool SetDataPath(PGLOBAL g, const char *path);
203203
PTDB GetTDB(PGLOBAL g);
204204
int OpenTable(PGLOBAL g, bool del= false);
205205
bool CheckColumnList(PGLOBAL g);

storage/connect/mongofam.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,9 @@ void MGOFAM::CloseTableFile(PGLOBAL g, bool)
767767
/***********************************************************************/
768768
void MGOFAM::Rewind(void)
769769
{
770-
// TODO implement me
770+
mongoc_cursor_t *cursor = mongoc_cursor_clone(Cursor);
771+
772+
mongoc_cursor_destroy(Cursor);
773+
Cursor = cursor;
771774
} // end of Rewind
772775

storage/connect/mycat.cc

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -484,39 +484,6 @@ void MYCAT::Reset(void)
484484
{
485485
} // end of Reset
486486

487-
#if 0
488-
/***********************************************************************/
489-
/* This function sets the current database path. */
490-
/***********************************************************************/
491-
void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path)
492-
{
493-
if (path) {
494-
size_t len= strlen(path) + (*path != '.' ? 4 : 1);
495-
char *buf= (char*)PlugSubAlloc(g, NULL, len);
496-
497-
if (PlugIsAbsolutePath(path))
498-
{
499-
strcpy(buf, path);
500-
*datapath= buf;
501-
return;
502-
}
503-
504-
if (*path != '.') {
505-
#if defined(__WIN__)
506-
char *s= "\\";
507-
#else // !__WIN__
508-
char *s= "/";
509-
#endif // !__WIN__
510-
strcat(strcat(strcat(strcpy(buf, "."), s), path), s);
511-
} else
512-
strcpy(buf, path);
513-
514-
*datapath= buf;
515-
} // endif path
516-
517-
} // end of SetDataPath
518-
#endif // 0
519-
520487
/***********************************************************************/
521488
/* GetTableDesc: retrieve a table descriptor. */
522489
/* Look for a table descriptor matching the name and type. */

storage/connect/mycat.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,15 @@ class MYCAT : public CATALOG {
9898

9999
// Methods
100100
void Reset(void);
101-
//void SetDataPath(PGLOBAL g, const char *path)
102-
// {SetPath(g, &DataPath, path);}
103101
bool StoreIndex(PGLOBAL, PTABDEF) {return false;} // Temporary
104-
// PRELDEF GetTableDesc(PGLOBAL g, LPCSTR name,
105102
PRELDEF GetTableDesc(PGLOBAL g, PTABLE tablep,
106103
LPCSTR type, PRELDEF *prp = NULL);
107104
PTDB GetTable(PGLOBAL g, PTABLE tablep,
108105
MODE mode = MODE_READ, LPCSTR type = NULL);
109106
void ClearDB(PGLOBAL g);
110107

111108
protected:
112-
// PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am);
113109
PRELDEF MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am);
114-
//void SetPath(PGLOBAL g, LPCSTR *datapath, const char *path);
115110

116111
// Members
117112
ha_connect *Hc; // The Connect handler

storage/connect/mysql-test/connect/disabled.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
# Do not use any TAB characters for whitespace.
1010
#
1111
##############################################################################
12-
#jdbc : Variable settings depend on machine configuration
13-
#jdbc_new : Variable settings depend on machine configuration
12+
jdbc : Variable settings depend on machine configuration
13+
jdbc_new : Variable settings depend on machine configuration
1414
jdbc_oracle : Variable settings depend on machine configuration
1515
jdbc_postgresql : Variable settings depend on machine configuration
16+
json_mgo : Need MongoDB running and its C Driver installed
17+
mongo : Need MongoDB running and its C Driver installed

storage/connect/plgdbutl.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,26 +387,27 @@ char *SetPath(PGLOBAL g, const char *path)
387387
char *buf= NULL;
388388

389389
if (path) {
390-
size_t len= strlen(path) + (*path != '.' ? 4 : 1);
390+
size_t len = strlen(path) + (*path != '.' ? 4 : 1);
391+
392+
if (!(buf = (char*)PlgDBSubAlloc(g, NULL, len)))
393+
return NULL;
391394

392-
buf= (char*)PlugSubAlloc(g, NULL, len);
393-
394395
if (PlugIsAbsolutePath(path)) {
395-
strcpy(buf, path);
396-
return buf;
397-
} // endif path
396+
strcpy(buf, path);
397+
return buf;
398+
} // endif path
398399

399400
if (*path != '.') {
400401
#if defined(__WIN__)
401-
char *s= "\\";
402+
char *s = "\\";
402403
#else // !__WIN__
403-
char *s= "/";
404+
char *s = "/";
404405
#endif // !__WIN__
405406
strcat(strcat(strcat(strcpy(buf, "."), s), path), s);
406407
} else
407408
strcpy(buf, path);
408409

409-
} // endif path
410+
} // endif path
410411

411412
return buf;
412413
} // end of SetPath

storage/connect/plugutil.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,17 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize)
139139
htrc("PlugInit: Language='%s'\n",
140140
((!Language) ? "Null" : (char*)Language));
141141

142-
if (!(g = (PGLOBAL)malloc(sizeof(GLOBAL)))) {
143-
fprintf(stderr, MSG(GLOBAL_ERROR), (int)sizeof(GLOBAL));
144-
return NULL;
145-
} else {
142+
try {
143+
g = new GLOBAL;
144+
} catch (...) {
145+
fprintf(stderr, MSG(GLOBAL_ERROR), (int)sizeof(GLOBAL));
146+
return NULL;
147+
} // end try/catch
148+
149+
//if (!(g = (PGLOBAL)malloc(sizeof(GLOBAL)))) {
150+
// fprintf(stderr, MSG(GLOBAL_ERROR), (int)sizeof(GLOBAL));
151+
// return NULL;
152+
// } else {
146153
g->Sarea = NULL;
147154
g->Createas = 0;
148155
g->Alchecked = 0;
@@ -164,7 +171,7 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize)
164171
} else
165172
g->Sarea_Size = worksize;
166173

167-
} /* endif g */
174+
//} /* endif g */
168175

169176
g->jump_level = -1; /* New setting to allow recursive call of Plug */
170177
return(g);
@@ -183,7 +190,7 @@ int PlugExit(PGLOBAL g)
183190
if (g->Sarea)
184191
free(g->Sarea);
185192

186-
free(g);
193+
delete g;
187194
return rc;
188195
} /* end of PlugExit */
189196

0 commit comments

Comments
 (0)