Commit 0149f9c2 authored by Olivier Bertrand's avatar Olivier Bertrand

Add MONGO table type

  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
parent 95af77b1
......@@ -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= '\\';
......@@ -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:
......
......@@ -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
......@@ -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
/***********************************************************************/
......@@ -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:
......@@ -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
......
......@@ -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) */
......
......@@ -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);
......@@ -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;
......@@ -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;
......
......@@ -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)
......@@ -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;}
......@@ -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
......
This diff is collapsed.
/**************** tabmgo H Declares Source Code File (.H) **************/
/* Name: tabmgo.h Version 1.0 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* */
/* This file contains the MongoDB classes declares. */
/***********************************************************************/
#include "osutil.h"
#include "block.h"
#include "colblk.h"
/***********************************************************************/
/* Include MongoDB library header files. */
/***********************************************************************/
#include <bson.h>
#include <bcon.h>
#include <mongoc.h>
typedef class MGODEF *PMGODEF;
typedef class TDBMGO *PTDBMGO;
typedef class MGOCOL *PMGOCOL;
/***********************************************************************/
/* MongoDB table. */
/***********************************************************************/
class DllExport MGODEF : public EXTDEF { /* Table description */
friend class TDBMGO;
friend class MGOFAM;
public:
// Constructor
MGODEF(void);
// Implementation
virtual const char *GetType(void) { return "MONGO"; }
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE m);
protected:
// Members
const char *Uri; /* MongoDB connection URI */
char *Colist; /* Options list */
char *Filter; /* Filtering query */
int Level; /* Used for catalog table */
int Base; /* The array index base */
}; // end of MGODEF
/* -------------------------- TDBMGO class --------------------------- */
/***********************************************************************/
/* This is the MongoDB Access Method class declaration. */
/* The table is a collection, each record being a document. */
/***********************************************************************/
class DllExport TDBMGO : public TDBEXT {
friend class MGOCOL;
friend class MGODEF;
public:
// Constructor
TDBMGO(PMGODEF tdp);
TDBMGO(TDBMGO *tdbp);
// Implementation
virtual AMT GetAmType(void) { return TYPE_AM_MGO; }
virtual PTDB Duplicate(PGLOBAL g) { return (PTDB)new(g) TDBMGO(this); }
// Methods
virtual PTDB Clone(PTABS t);
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual PCOL InsertSpecialColumn(PCOL colp);
virtual int RowNumber(PGLOBAL g, bool b = FALSE) {return N;}
// Database routines
virtual int Cardinality(PGLOBAL g);
virtual int GetMaxSize(PGLOBAL g);
virtual bool OpenDB(PGLOBAL g);
virtual int ReadDB(PGLOBAL g);
virtual int WriteDB(PGLOBAL g);
virtual int DeleteDB(PGLOBAL g, int irc);
virtual void CloseDB(PGLOBAL g);
virtual bool ReadKey(PGLOBAL g, OPVAL op, const key_range *kr);
protected:
bool Init(PGLOBAL g);
void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k);
// Members
mongoc_uri_t *Uri;
mongoc_client_pool_t *Pool; // Thread safe client pool
mongoc_client_t *Client; // The MongoDB client
mongoc_database_t *Database; // The MongoDB database
mongoc_collection_t *Collection; // The MongoDB collection
mongoc_cursor_t *Cursor;
const bson_t *Document;
bson_t *Query; // MongoDB cursor filter
bson_t *Opts; // MongoDB cursor options
bson_error_t Error;
const char *Uristr;
const char *Db_name;
const char *Coll_name;
const char *Options; // The MongoDB options
const char *Filter; // The filtering query
int Fpos; // The current row index
int N; // The current Rownum
int B; // Array index base
bool Done; // Init done
}; // end of class TDBMGO
/* --------------------------- MGOCOL class -------------------------- */
/***********************************************************************/
/* Class MGOCOL: MongoDB access method column descriptor. */
/***********************************************************************/
class DllExport MGOCOL : public EXTCOL {
friend class TDBMGO;
public:
// Constructors
MGOCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i);
MGOCOL(MGOCOL *colp, PTDB tdbp); // Constructor used in copy process
// Implementation
virtual int GetAmType(void) { return Tmgp->GetAmType(); }
// Methods
virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
virtual void ReadColumn(PGLOBAL g);
virtual void WriteColumn(PGLOBAL g);
protected:
// Default constructor not to be used
MGOCOL(void) {}
// Members
TDBMGO *Tmgp; // To the MGO table block
bson_iter_t Iter; // Used to retrieve column value
bson_iter_t Desc; // Descendant iter
char *Jpath; // The json path
}; // end of class MGOCOL
#if 0
/***********************************************************************/
/* This is the class declaration for the MONGO catalog table. */
/***********************************************************************/
class DllExport TDBGOL : public TDBCAT {
public:
// Constructor
TDBGOL(PMGODEF tdp);
protected:
// Specific routines
virtual PQRYRES GetResult(PGLOBAL g);
// Members
PTOS Topt;
char *Db;
char *Dsn;
}; // end of class TDBGOL
#endif // 0
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