Skip to content

Commit

Permalink
Add MONGO table type
Browse files Browse the repository at this point in the history
  new file:   storage/connect/tabmgo.cpp
  new file:   storage/connect/tabmgo.h
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/mycat.cc
  modified:   storage/connect/plgdbsem.h

Fix crash when dbname is null forJSON MGO tables
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabjson.h
  • Loading branch information
Buggynours committed Apr 17, 2017
1 parent 95af77b commit 0149f9c
Show file tree
Hide file tree
Showing 7 changed files with 1,097 additions and 10 deletions.
5 changes: 3 additions & 2 deletions storage/connect/ha_connect.cc
Expand Up @@ -172,7 +172,7 @@
#define JSONMAX 10 // JSON Default max grp size

extern "C" {
char version[]= "Version 1.06.0001 April 7, 2017";
char version[]= "Version 1.06.0001 April 17, 2017";
#if defined(__WIN__)
char compver[]= "Version 1.06.0001 " __DATE__ " " __TIME__;
char slash= '\\';
Expand Down Expand Up @@ -4236,7 +4236,8 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn, bool quick)
case TAB_ODBC:
case TAB_JDBC:
case TAB_MYSQL:
case TAB_DIR:
case TAB_MONGO:
case TAB_DIR:
case TAB_MAC:
case TAB_WMI:
case TAB_ZIP:
Expand Down
12 changes: 11 additions & 1 deletion storage/connect/mycat.cc
Expand Up @@ -96,6 +96,9 @@
#if defined(XML_SUPPORT)
#include "tabxml.h"
#endif // XML_SUPPORT
#if defined(MONGO_SUPPORT)
#include "tabmgo.h"
#endif // MONGO_SUPPORT
#if defined(ZIP_SUPPORT)
#include "tabzip.h"
#endif // ZIP_SUPPORT
Expand Down Expand Up @@ -161,7 +164,10 @@ TABTYPE GetTypeID(const char *type)
#ifdef ZIP_SUPPORT
: (!stricmp(type, "ZIP")) ? TAB_ZIP
#endif
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
#ifdef MONGO_SUPPORT
: (!stricmp(type, "MONGO")) ? TAB_MONGO
#endif
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
} // end of GetTypeID

/***********************************************************************/
Expand Down Expand Up @@ -307,6 +313,7 @@ int GetIndexType(TABTYPE type)
case TAB_MYSQL:
case TAB_ODBC:
case TAB_JDBC:
case TAB_MONGO:
xtyp= 2;
break;
case TAB_VIR:
Expand Down Expand Up @@ -583,6 +590,9 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
#endif // PIVOT_SUPPORT
case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break;
#if defined(MONGO_SUPPORT)
case TAB_MONGO: tdp = new(g) MGODEF; break;
#endif // MONGO_SUPPORT
#if defined(ZIP_SUPPORT)
case TAB_ZIP: tdp= new(g) ZIPDEF; break;
#endif // ZIP_SUPPORT
Expand Down
3 changes: 2 additions & 1 deletion storage/connect/plgdbsem.h
Expand Up @@ -80,7 +80,8 @@ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */
TAB_DMY = 25, /* DMY Dummy tables NIY */
TAB_JDBC = 26, /* Table accessed via JDBC */
TAB_ZIP = 27, /* ZIP file info table */
TAB_NIY = 28}; /* Table not implemented yet */
TAB_MONGO = 28, /* Table retrieved from MongoDB */
TAB_NIY = 30}; /* Table not implemented yet */

enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_ROWID = 1, /* ROWID type (special column) */
Expand Down
4 changes: 1 addition & 3 deletions storage/connect/tabjson.cpp
Expand Up @@ -129,7 +129,7 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info)
htrc("File %s objname=%s pretty=%d lvl=%d\n",
tdp->Fn, tdp->Objname, tdp->Pretty, lvl);

if (tdp->Uri = dsn) {
if ((tdp->Uri = dsn) && *tdp->Uri) {
#if defined(MONGO_SUPPORT)
tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);
tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname);
Expand Down Expand Up @@ -576,7 +576,6 @@ TDBJSN::TDBJSN(PJDEF tdp, PTXF txfp) : TDBDOS(tdp, txfp)
if (tdp) {
Jmode = tdp->Jmode;
Objname = tdp->Objname;
Amtype = (tdp->Uri ? TYPE_AM_MGO : TYPE_AM_JSN);
Xcol = tdp->Xcol;
Limit = tdp->Limit;
Pretty = tdp->Pretty;
Expand All @@ -585,7 +584,6 @@ TDBJSN::TDBJSN(PJDEF tdp, PTXF txfp) : TDBDOS(tdp, txfp)
} else {
Jmode = MODE_OBJECT;
Objname = NULL;
Amtype = TYPE_AM_JSN;
Xcol = NULL;
Limit = 1;
Pretty = 0;
Expand Down
5 changes: 2 additions & 3 deletions storage/connect/tabjson.h
Expand Up @@ -59,7 +59,7 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
int Limit; /* Limit of multiple values */
int Pretty; /* Depends on file structure */
int Level; /* Used for catalog table */
int Base; /* Tne array index base */
int Base; /* The array index base */
bool Strict; /* Strict syntax checking */
const char *Uri; /* MongoDB connection URI */
#if defined(MONGO_SUPPORT)
Expand All @@ -84,7 +84,7 @@ class DllExport TDBJSN : public TDBDOS {
TDBJSN(TDBJSN *tdbp);

// Implementation
virtual AMT GetAmType(void) {return Amtype;}
virtual AMT GetAmType(void) {return TYPE_AM_JSN;}
virtual bool SkipHeader(PGLOBAL g);
virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBJSN(this);}
PJSON GetRow(void) {return Row;}
Expand Down Expand Up @@ -116,7 +116,6 @@ class DllExport TDBJSN : public TDBDOS {
PJSON Val; // The value of the current row
PJCOL Colp; // The multiple column
JMODE Jmode; // MODE_OBJECT by default
AMT Amtype; // Access method type
char *Objname; // The table object name
char *Xcol; // Name of expandable column
int Fpos; // The current row index
Expand Down

0 comments on commit 0149f9c

Please sign in to comment.