Commit 2f9db4ef authored by Olivier Bertrand's avatar Olivier Bertrand

Fix MDEV-12631 valgrind warning for zipped tables

  modified:   storage/connect/filamzip.cpp

Add to STRING a member for testing OOM condition
  modified:   storage/connect/xtable.h

Work on MONGO type and add some of its features to JSON MGO tables
  modified:   storage/connect/filter.cpp
  modified:   storage/connect/filter.h
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/mongofam.cpp
  modified:   storage/connect/mongofam.h
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabjson.h
  modified:   storage/connect/tabmgo.cpp
  modified:   storage/connect/tabmgo.h
parent b6135bb5
This diff is collapsed.
/*********** File AM Zip C++ Program Source Code File (.CPP) ***********/ /*********** File AM Zip C++ Program Source Code File (.CPP) ***********/
/* PROGRAM NAME: FILAMZIP */ /* PROGRAM NAME: FILAMZIP */
/* ------------- */ /* ------------- */
/* Version 1.1 */ /* Version 1.2 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
...@@ -652,12 +652,18 @@ bool UNZIPUTL::openEntry(PGLOBAL g) ...@@ -652,12 +652,18 @@ bool UNZIPUTL::openEntry(PGLOBAL g)
} // endif rc } // endif rc
size = finfo.uncompressed_size; size = finfo.uncompressed_size;
memory = new char[size + 1];
try {
memory = new char[size + 1];
} catch (...) {
strcpy(g->Message, "Out of memory");
return true;
} // end try/catch
if ((rc = unzReadCurrentFile(zipfile, memory, size)) < 0) { if ((rc = unzReadCurrentFile(zipfile, memory, size)) < 0) {
sprintf(g->Message, "unzReadCurrentFile rc = %d", rc); sprintf(g->Message, "unzReadCurrentFile rc = %d", rc);
unzCloseCurrentFile(zipfile); unzCloseCurrentFile(zipfile);
free(memory); delete[] memory;
memory = NULL; memory = NULL;
entryopen = false; entryopen = false;
} else { } else {
...@@ -682,7 +688,7 @@ void UNZIPUTL::closeEntry() ...@@ -682,7 +688,7 @@ void UNZIPUTL::closeEntry()
} // endif entryopen } // endif entryopen
if (memory) { if (memory) {
free(memory); delete[] memory;
memory = NULL; memory = NULL;
} // endif memory } // endif memory
......
...@@ -39,6 +39,9 @@ ...@@ -39,6 +39,9 @@
//#include "select.h" //#include "select.h"
#include "xindex.h" #include "xindex.h"
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
#include "filamtxt.h"
#include "tabdos.h"
#include "tabjson.h"
#include "tabext.h" #include "tabext.h"
#include "tabmgo.h" #include "tabmgo.h"
#endif // MONGO_SUPPORT #endif // MONGO_SUPPORT
...@@ -1413,7 +1416,7 @@ PFIL FILTER::Copy(PTABS t) ...@@ -1413,7 +1416,7 @@ PFIL FILTER::Copy(PTABS t)
/* Make selector json representation for Mongo tables. */ /* Make selector json representation for Mongo tables. */
/***********************************************************************/ /***********************************************************************/
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
bool FILTER::MakeSelector(PGLOBAL g, PSTRG s) bool FILTER::MakeSelector(PGLOBAL g, PSTRG s, bool m)
{ {
s->Append('{'); s->Append('{');
...@@ -1425,23 +1428,29 @@ bool FILTER::MakeSelector(PGLOBAL g, PSTRG s) ...@@ -1425,23 +1428,29 @@ bool FILTER::MakeSelector(PGLOBAL g, PSTRG s)
s->Append(Opc == OP_AND ? "and" : "or"); s->Append(Opc == OP_AND ? "and" : "or");
s->Append("\":["); s->Append("\":[");
if (((PFIL)Arg(0))->MakeSelector(g, s)) if (((PFIL)Arg(0))->MakeSelector(g, s, m))
return true; return true;
s->Append(','); s->Append(',');
if (((PFIL)Arg(1))->MakeSelector(g, s)) if (((PFIL)Arg(1))->MakeSelector(g, s, m))
return true; return true;
s->Append(']'); s->Append(']');
} else { } else {
char buf[501]; char *pth, buf[501];
if (GetArgType(0) != TYPE_COLBLK) if (GetArgType(0) != TYPE_COLBLK)
return true; return true;
s->Append('"'); s->Append('"');
s->Append(((PMGOCOL)Arg(0))->Jpath);
if (m)
pth = ((PMGOCOL)Arg(0))->Jpath;
else if (!(pth = ((PJCOL)Arg(0))->GetJpath(g, false)))
return true;
s->Append(pth);
s->Append("\":{\"$"); s->Append("\":{\"$");
switch (Opc) { switch (Opc) {
......
...@@ -62,7 +62,7 @@ class DllExport FILTER : public XOBJECT { /* Filter description block */ ...@@ -62,7 +62,7 @@ class DllExport FILTER : public XOBJECT { /* Filter description block */
//virtual bool CheckLocal(PTDB); //virtual bool CheckLocal(PTDB);
//virtual int CheckSpcCol(PTDB tdbp, int n); //virtual int CheckSpcCol(PTDB tdbp, int n);
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
bool MakeSelector(PGLOBAL g, PSTRG s); bool MakeSelector(PGLOBAL g, PSTRG s, bool m);
#endif // MONGO_SUPPORT #endif // MONGO_SUPPORT
virtual void Print(PGLOBAL g, FILE *f, uint n); virtual void Print(PGLOBAL g, FILE *f, uint n);
virtual void Print(PGLOBAL g, char *ps, uint z); virtual void Print(PGLOBAL g, char *ps, uint z);
......
...@@ -3111,7 +3111,7 @@ const COND *ha_connect::cond_push(const COND *cond) ...@@ -3111,7 +3111,7 @@ const COND *ha_connect::cond_push(const COND *cond)
} else if (x && cond) } else if (x && cond)
tdbp->SetCondFil(filp); // Wrong filter tdbp->SetCondFil(filp); // Wrong filter
} else if (tty != TYPE_AM_JSN && tty != TYPE_AM_JSON) { } else if (tdbp->CanBeFiltered()) {
if (!tdbp->GetCond() || tdbp->GetCond() != cond) { if (!tdbp->GetCond() || tdbp->GetCond() != cond) {
tdbp->SetFilter(CondFilter(g, (Item *)cond)); tdbp->SetFilter(CondFilter(g, (Item *)cond));
......
This diff is collapsed.
...@@ -63,6 +63,7 @@ class DllExport MGOFAM : public DOSFAM { ...@@ -63,6 +63,7 @@ class DllExport MGOFAM : public DOSFAM {
virtual int RenameTempFile(PGLOBAL g) { return RC_OK; } virtual int RenameTempFile(PGLOBAL g) { return RC_OK; }
virtual int InitDelete(PGLOBAL g, int fpos, int spos); virtual int InitDelete(PGLOBAL g, int fpos, int spos);
bool Init(PGLOBAL g); bool Init(PGLOBAL g);
bool MakeCursor(PGLOBAL g);
void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k); void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k);
//static void *mgo_alloc(size_t n); //static void *mgo_alloc(size_t n);
//static void *mgo_calloc(size_t n, size_t sz); //static void *mgo_calloc(size_t n, size_t sz);
...@@ -85,11 +86,12 @@ class DllExport MGOFAM : public DOSFAM { ...@@ -85,11 +86,12 @@ class DllExport MGOFAM : public DOSFAM {
bson_error_t Error; bson_error_t Error;
PFBLOCK To_Fbt; // Pointer to temp file block PFBLOCK To_Fbt; // Pointer to temp file block
MODE Mode; MODE Mode;
const char *uristr; const char *Uristr;
const char *db_name; const char *Db_name;
const char *coll_name; const char *Coll_name;
const char *options; const char *Options;
const char *filter; const char *Filter;
bool Done; // Init done bool Done; // Init done
bool Pipe;
}; // end of class MGOFAM }; // end of class MGOFAM
...@@ -135,6 +135,7 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info) ...@@ -135,6 +135,7 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info)
tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname); tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname);
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test"); tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
tdp->Options = GetStringTableOption(g, topt, "Colist", NULL); tdp->Options = GetStringTableOption(g, topt, "Colist", NULL);
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
tdp->Pretty = 0; tdp->Pretty = 0;
#else // !MONGO_SUPPORT #else // !MONGO_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
...@@ -452,6 +453,7 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff) ...@@ -452,6 +453,7 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
Collname = GetStringCatInfo(g, "Tabname", Collname); Collname = GetStringCatInfo(g, "Tabname", Collname);
Schema = GetStringCatInfo(g, "Dbname", "test"); Schema = GetStringCatInfo(g, "Dbname", "test");
Options = GetStringCatInfo(g, "Colist", NULL); Options = GetStringCatInfo(g, "Colist", NULL);
Pipe = GetBoolCatInfo("Pipeline", false);
Pretty = 0; Pretty = 0;
#else // !MONGO_SUPPORT #else // !MONGO_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
...@@ -481,7 +483,14 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -481,7 +483,14 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
!(tmp == TMP_FORCE && !(tmp == TMP_FORCE &&
(m == MODE_UPDATE || m == MODE_DELETE)); (m == MODE_UPDATE || m == MODE_DELETE));
if (Zipped) { if (Uri) {
#if defined(MONGO_SUPPORT)
txfp = new(g) MGOFAM(this);
#else // !MONGO_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
return NULL;
#endif // !MONGO_SUPPORT
} else if (Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
if (m == MODE_READ || m == MODE_READX) { if (m == MODE_READ || m == MODE_READX) {
txfp = new(g) UNZFAM(this); txfp = new(g) UNZFAM(this);
...@@ -505,13 +514,6 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -505,13 +514,6 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "GZ"); sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "GZ");
return NULL; return NULL;
#endif // !GZ_SUPPORT #endif // !GZ_SUPPORT
} else if (Uri) {
#if defined(MONGO_SUPPORT)
txfp = new(g) MGOFAM(this);
#else // !MONGO_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
return NULL;
#endif // !MONGO_SUPPORT
} else if (map) } else if (map)
txfp = new(g) MAPFAM(this); txfp = new(g) MAPFAM(this);
else else
...@@ -746,6 +748,9 @@ bool TDBJSN::OpenDB(PGLOBAL g) ...@@ -746,6 +748,9 @@ bool TDBJSN::OpenDB(PGLOBAL g)
} // endif Use } // endif Use
if (Xcol && Txfp->GetAmType() != TYPE_AM_MGO)
To_Filter = NULL; // Imcompatible
return TDBDOS::OpenDB(g); return TDBDOS::OpenDB(g);
} // end of OpenDB } // end of OpenDB
...@@ -922,9 +927,6 @@ int TDBJSN::WriteDB(PGLOBAL g) ...@@ -922,9 +927,6 @@ int TDBJSN::WriteDB(PGLOBAL g)
int rc = TDBDOS::WriteDB(g); int rc = TDBDOS::WriteDB(g);
#if USE_G #if USE_G
//if (rc == RC_FX)
// strcpy(g->Message, G->Message);
PlugSubSet(G, G->Sarea, G->Sarea_Size); PlugSubSet(G, G->Sarea, G->Sarea_Size);
#endif #endif
Row->Clear(); Row->Clear();
...@@ -1195,12 +1197,62 @@ bool JSONCOL::ParseJpath(PGLOBAL g) ...@@ -1195,12 +1197,62 @@ bool JSONCOL::ParseJpath(PGLOBAL g)
return false; return false;
} // end of ParseJpath } // end of ParseJpath
/***********************************************************************/
/* Get Jpath converted to Mongo path. */
/***********************************************************************/
char *JSONCOL::GetJpath(PGLOBAL g, bool proj)
{
if (Jpath) {
char *p1, *p2, *mgopath;
int i = 0;
if (strcmp(Jpath, "*"))
mgopath = PlugDup(g, Jpath);
else
return NULL;
for (p1 = p2 = mgopath; *p1; p1++)
if (i) { // Inside []
if (isdigit(*p1)) {
if (!proj)
*p2++ = *p1;
i = 2;
} else if (*p1 == ']' && i == 2) {
if (proj && *(p1 + 1) == ':')
p1++;
i = 0;
} else if (proj)
i = 2;
else
return NULL;
} else switch (*p1) {
case ':': *p2++ = '.'; break;
case '[': i = 1; break;
case '*':
if (*(p2 - 1) == '.' && !*(p1 + 1)) {
p2--; // Suppress last :*
break;
} // endif p2
default: *p2++ = *p1; break;
} // endswitch p1;
*p2 = 0;
return mgopath;
} else
return NULL;
} // end of GetJpath
/***********************************************************************/ /***********************************************************************/
/* MakeJson: Serialize the json item and set value to it. */ /* MakeJson: Serialize the json item and set value to it. */
/***********************************************************************/ /***********************************************************************/
PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp) PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp)
{ {
if (Value->IsTypeNum()) { if (Value->IsTypeNum()) {
strcpy(g->Message, "Cannot make Json for a numeric column"); strcpy(g->Message, "Cannot make Json for a numeric column");
Value->Reset(); Value->Reset();
} else } else
...@@ -1910,8 +1962,11 @@ bool TDBJSON::OpenDB(PGLOBAL g) ...@@ -1910,8 +1962,11 @@ bool TDBJSON::OpenDB(PGLOBAL g)
return true; return true;
} // endswitch Jmode } // endswitch Jmode
Use = USE_OPEN; if (Xcol)
return false; To_Filter = NULL; // Imcompatible
Use = USE_OPEN;
return false;
} // end of OpenDB } // end of OpenDB
/***********************************************************************/ /***********************************************************************/
...@@ -1921,7 +1976,7 @@ int TDBJSON::ReadDB(PGLOBAL) ...@@ -1921,7 +1976,7 @@ int TDBJSON::ReadDB(PGLOBAL)
{ {
int rc; int rc;
N++; N++;
if (NextSame) { if (NextSame) {
SameRow = NextSame; SameRow = NextSame;
......
...@@ -63,9 +63,10 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */ ...@@ -63,9 +63,10 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
bool Strict; /* Strict syntax checking */ bool Strict; /* Strict syntax checking */
const char *Uri; /* MongoDB connection URI */ const char *Uri; /* MongoDB connection URI */
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
PSZ Collname; /* External collection name */ PSZ Collname; /* External collection name */
PSZ Schema; /* External schema (DB) name */ PSZ Schema; /* External schema (DB) name */
PSZ Options; /* Colist ; filter */ PSZ Options; /* Colist ; filter */
bool Pipe; /* True if Colist is a pipeline */
#endif // MONGO_SUPPORT #endif // MONGO_SUPPORT
}; // end of JSONDEF }; // end of JSONDEF
...@@ -78,6 +79,9 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */ ...@@ -78,6 +79,9 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
class DllExport TDBJSN : public TDBDOS { class DllExport TDBJSN : public TDBDOS {
friend class JSONCOL; friend class JSONCOL;
friend class JSONDEF; friend class JSONDEF;
#if defined(MONGO_SUPPORT)
friend class MGOFAM;
#endif // MONGO_SUPPORT
public: public:
// Constructor // Constructor
TDBJSN(PJDEF tdp, PTXF txfp); TDBJSN(PJDEF tdp, PTXF txfp);
...@@ -96,6 +100,8 @@ class DllExport TDBJSN : public TDBDOS { ...@@ -96,6 +100,8 @@ class DllExport TDBJSN : public TDBDOS {
virtual PCOL InsertSpecialColumn(PCOL colp); virtual PCOL InsertSpecialColumn(PCOL colp);
virtual int RowNumber(PGLOBAL g, bool b = FALSE) virtual int RowNumber(PGLOBAL g, bool b = FALSE)
{return (b) ? M : N;} {return (b) ? M : N;}
virtual bool CanBeFiltered(void)
{return Txfp->GetAmType() == TYPE_AM_MGO || !Xcol;}
// Database routines // Database routines
virtual int Cardinality(PGLOBAL g); virtual int Cardinality(PGLOBAL g);
...@@ -139,6 +145,7 @@ class DllExport TDBJSN : public TDBDOS { ...@@ -139,6 +145,7 @@ class DllExport TDBJSN : public TDBDOS {
class DllExport JSONCOL : public DOSCOL { class DllExport JSONCOL : public DOSCOL {
friend class TDBJSN; friend class TDBJSN;
friend class TDBJSON; friend class TDBJSON;
friend class MGOFAM;
public: public:
// Constructors // Constructors
JSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i); JSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i);
...@@ -148,20 +155,21 @@ class DllExport JSONCOL : public DOSCOL { ...@@ -148,20 +155,21 @@ class DllExport JSONCOL : public DOSCOL {
virtual int GetAmType(void) {return Tjp->GetAmType();} virtual int GetAmType(void) {return Tjp->GetAmType();}
// Methods // Methods
virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
bool ParseJpath(PGLOBAL g); bool ParseJpath(PGLOBAL g);
virtual void ReadColumn(PGLOBAL g); char *GetJpath(PGLOBAL g, bool proj);
virtual void WriteColumn(PGLOBAL g); virtual void ReadColumn(PGLOBAL g);
virtual void WriteColumn(PGLOBAL g);
protected: protected:
bool CheckExpand(PGLOBAL g, int i, PSZ nm, bool b); bool CheckExpand(PGLOBAL g, int i, PSZ nm, bool b);
bool SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm); bool SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm);
PVAL GetColumnValue(PGLOBAL g, PJSON row, int i); PVAL GetColumnValue(PGLOBAL g, PJSON row, int i);
PVAL ExpandArray(PGLOBAL g, PJAR arp, int n); PVAL ExpandArray(PGLOBAL g, PJAR arp, int n);
PVAL CalculateArray(PGLOBAL g, PJAR arp, int n); PVAL CalculateArray(PGLOBAL g, PJAR arp, int n);
PVAL MakeJson(PGLOBAL g, PJSON jsp); PVAL MakeJson(PGLOBAL g, PJSON jsp);
void SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n); void SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n);
PJSON GetRow(PGLOBAL g); PJSON GetRow(PGLOBAL g);
// Default constructor not to be used // Default constructor not to be used
JSONCOL(void) {} JSONCOL(void) {}
......
...@@ -481,6 +481,7 @@ void INCOL::AddCol(PGLOBAL g, PCOL colp, char *jp) ...@@ -481,6 +481,7 @@ void INCOL::AddCol(PGLOBAL g, PCOL colp, char *jp)
/***********************************************************************/ /***********************************************************************/
TDBMGO::TDBMGO(PMGODEF tdp) : TDBEXT(tdp) TDBMGO::TDBMGO(PMGODEF tdp) : TDBEXT(tdp)
{ {
G = NULL;
Uri = NULL; Uri = NULL;
Pool = NULL; Pool = NULL;
Client = NULL; Client = NULL;
...@@ -490,6 +491,7 @@ TDBMGO::TDBMGO(PMGODEF tdp) : TDBEXT(tdp) ...@@ -490,6 +491,7 @@ TDBMGO::TDBMGO(PMGODEF tdp) : TDBEXT(tdp)
Query = NULL; Query = NULL;
Opts = NULL; Opts = NULL;
Fpc = NULL; Fpc = NULL;
Cnd = NULL;
if (tdp) { if (tdp) {
Uristr = tdp->Uri; Uristr = tdp->Uri;
...@@ -516,6 +518,7 @@ TDBMGO::TDBMGO(PMGODEF tdp) : TDBEXT(tdp) ...@@ -516,6 +518,7 @@ TDBMGO::TDBMGO(PMGODEF tdp) : TDBEXT(tdp)
TDBMGO::TDBMGO(TDBMGO *tdbp) : TDBEXT(tdbp) TDBMGO::TDBMGO(TDBMGO *tdbp) : TDBEXT(tdbp)
{ {
G = tdbp->G;
Uri = tdbp->Uri; Uri = tdbp->Uri;
Pool = tdbp->Pool; Pool = tdbp->Pool;
Client = tdbp->Client; Client = tdbp->Client;
...@@ -525,6 +528,7 @@ TDBMGO::TDBMGO(TDBMGO *tdbp) : TDBEXT(tdbp) ...@@ -525,6 +528,7 @@ TDBMGO::TDBMGO(TDBMGO *tdbp) : TDBEXT(tdbp)
Query = tdbp->Query; Query = tdbp->Query;
Opts = tdbp->Opts; Opts = tdbp->Opts;
Fpc = tdbp->Fpc; Fpc = tdbp->Fpc;
Cnd = tdbp->Cnd;
Uristr = tdbp->Uristr; Uristr = tdbp->Uristr;
Db_name = tdbp->Db_name;; Db_name = tdbp->Db_name;;
Coll_name = tdbp->Coll_name; Coll_name = tdbp->Coll_name;
...@@ -642,6 +646,8 @@ bool TDBMGO::Init(PGLOBAL g) ...@@ -642,6 +646,8 @@ bool TDBMGO::Init(PGLOBAL g)
if (Done) if (Done)
return false; return false;
G = g;
if (Options && !Pipe) { if (Options && !Pipe) {
char *p = (char*)strchr(Options, ';'); char *p = (char*)strchr(Options, ';');
...@@ -699,13 +705,33 @@ bool TDBMGO::Init(PGLOBAL g) ...@@ -699,13 +705,33 @@ bool TDBMGO::Init(PGLOBAL g)
return false; return false;
} // end of Init } // end of Init
/***********************************************************************/
/* On update the filter can be made by Cond_Push after MakeCursor. */
/***********************************************************************/
void TDBMGO::SetFilter(PFIL fp)
{
To_Filter = fp;
if (fp && Cursor && Cnd != Cond) {
mongoc_cursor_t *cursor = NULL;
if (!MakeCursor(G, cursor)) {
mongoc_cursor_destroy(Cursor);
Cursor = cursor;
} else if (cursor)
mongoc_cursor_destroy(cursor);
} // endif Cursor
} // end of SetFilter
/***********************************************************************/ /***********************************************************************/
/* OpenDB: Data Base open routine for MONGO access method. */ /* OpenDB: Data Base open routine for MONGO access method. */
/***********************************************************************/ /***********************************************************************/
bool TDBMGO::MakeCursor(PGLOBAL g) bool TDBMGO::MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor)
{ {
const char *p; const char *p;
PSTRG s; PSTRG s = NULL;
if (Pipe) { if (Pipe) {
if (trace) if (trace)
...@@ -724,7 +750,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g) ...@@ -724,7 +750,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g)
if (To_Filter) { if (To_Filter) {
s->Append(",{\"$match\":"); s->Append(",{\"$match\":");
if (To_Filter->MakeSelector(g, s)) { if (To_Filter->MakeSelector(g, s, true)) {
strcpy(g->Message, "Failed making selector"); strcpy(g->Message, "Failed making selector");
return true; return true;
} else } else
...@@ -738,7 +764,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g) ...@@ -738,7 +764,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g)
for (PCOL cp = Columns; cp; cp = cp->GetNext()) { for (PCOL cp = Columns; cp; cp = cp->GetNext()) {
s->Append(",\""); s->Append(",\"");
s->Append(((PMGOCOL)cp)->Jpath); s->Append(((PMGOCOL)cp)->GetProjPath(g));
s->Append("\":1"); s->Append("\":1");
} // endfor cp } // endfor cp
...@@ -785,7 +811,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g) ...@@ -785,7 +811,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g)
if (Filter) if (Filter)
s->Append(','); s->Append(',');
if (To_Filter->MakeSelector(g, s)) { if (To_Filter->MakeSelector(g, s, true)) {
strcpy(g->Message, "Failed making selector"); strcpy(g->Message, "Failed making selector");
return true; return true;
} // endif Selector } // endif Selector
...@@ -821,7 +847,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g) ...@@ -821,7 +847,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g)
for (PCOL cp = Columns; cp; cp = cp->GetNext()) { for (PCOL cp = Columns; cp; cp = cp->GetNext()) {
s->Append(",\""); s->Append(",\"");
s->Append(((PMGOCOL)cp)->Jpath); s->Append(((PMGOCOL)cp)->GetProjPath(g));
s->Append("\":1"); s->Append("\":1");
} // endfor cp } // endfor cp
...@@ -873,7 +899,7 @@ bool TDBMGO::OpenDB(PGLOBAL g) ...@@ -873,7 +899,7 @@ bool TDBMGO::OpenDB(PGLOBAL g)
} else if (Mode == MODE_INSERT) } else if (Mode == MODE_INSERT)
MakeColumnGroups(g); MakeColumnGroups(g);
else if (MakeCursor(g)) else if (MakeCursor(g, Cursor))
return true; return true;
} // endif Use } // endif Use
...@@ -1141,6 +1167,37 @@ MGOCOL::MGOCOL(MGOCOL *col1, PTDB tdbp) : EXTCOL(col1, tdbp) ...@@ -1141,6 +1167,37 @@ MGOCOL::MGOCOL(MGOCOL *col1, PTDB tdbp) : EXTCOL(col1, tdbp)
Mbuf = col1->Mbuf; Mbuf = col1->Mbuf;
} // end of MGOCOL copy constructor } // end of MGOCOL copy constructor
/***********************************************************************/
/* Get projection path. */
/***********************************************************************/
char *MGOCOL::GetProjPath(PGLOBAL g)
{
if (Jpath) {
char *p1, *p2, *projpath = PlugDup(g, Jpath);
int i = 0;
for (p1 = p2 = projpath; *p1; p1++)
if (*p1 == '.') {
if (!i)
*p2++ = *p1;
i = 1;
} else if (i) {
if (!isdigit(*p1)) {
*p2++ = *p1;
i = 0;
} // endif p1
} else
*p2++ = *p1;
*p2 = 0;
return projpath;
} else
return NULL;
} // end of GetProjPath
/***********************************************************************/ /***********************************************************************/
/* Mini: used to suppress blanks to json strings. */ /* Mini: used to suppress blanks to json strings. */
/***********************************************************************/ /***********************************************************************/
......
...@@ -131,6 +131,7 @@ class DllExport TDBMGO : public TDBEXT { ...@@ -131,6 +131,7 @@ class DllExport TDBMGO : public TDBEXT {
virtual PTDB Clone(PTABS t); virtual PTDB Clone(PTABS t);
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual PCOL InsertSpecialColumn(PCOL colp); virtual PCOL InsertSpecialColumn(PCOL colp);
virtual void SetFilter(PFIL fp);
virtual int RowNumber(PGLOBAL g, bool b = FALSE) {return N;} virtual int RowNumber(PGLOBAL g, bool b = FALSE) {return N;}
// Database routines // Database routines
...@@ -145,12 +146,13 @@ class DllExport TDBMGO : public TDBEXT { ...@@ -145,12 +146,13 @@ class DllExport TDBMGO : public TDBEXT {
protected: protected:
bool Init(PGLOBAL g); bool Init(PGLOBAL g);
bool MakeCursor(PGLOBAL g); bool MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor);
void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k); void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k);
void MakeColumnGroups(PGLOBAL g); void MakeColumnGroups(PGLOBAL g);
bool DocWrite(PGLOBAL g, PINCOL icp); bool DocWrite(PGLOBAL g, PINCOL icp);
// Members // Members
PGLOBAL G; // Needed by SetFilter
mongoc_uri_t *Uri; mongoc_uri_t *Uri;
mongoc_client_pool_t *Pool; // Thread safe client pool mongoc_client_pool_t *Pool; // Thread safe client pool
mongoc_client_t *Client; // The MongoDB client mongoc_client_t *Client; // The MongoDB client
...@@ -162,6 +164,7 @@ class DllExport TDBMGO : public TDBEXT { ...@@ -162,6 +164,7 @@ class DllExport TDBMGO : public TDBEXT {
bson_t *Opts; // MongoDB cursor options bson_t *Opts; // MongoDB cursor options
bson_error_t Error; bson_error_t Error;
PINCOL Fpc; // To insert INCOL classes PINCOL Fpc; // To insert INCOL classes
const Item *Cnd; // The first condition
const char *Uristr; const char *Uristr;
const char *Db_name; const char *Db_name;
const char *Coll_name; const char *Coll_name;
...@@ -199,6 +202,7 @@ class DllExport MGOCOL : public EXTCOL { ...@@ -199,6 +202,7 @@ class DllExport MGOCOL : public EXTCOL {
protected: protected:
// Default constructor not to be used // Default constructor not to be used
MGOCOL(void) {} MGOCOL(void) {}
char *GetProjPath(PGLOBAL g);
char *Mini(PGLOBAL g, const bson_t *bson, bool b); char *Mini(PGLOBAL g, const bson_t *bson, bool b);
// Members // Members
......
...@@ -61,7 +61,6 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block. ...@@ -61,7 +61,6 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block.
inline PFIL GetFilter(void) {return To_Filter;} inline PFIL GetFilter(void) {return To_Filter;}
inline PCOL GetSetCols(void) {return To_SetCols;} inline PCOL GetSetCols(void) {return To_SetCols;}
inline void SetSetCols(PCOL colp) {To_SetCols = colp;} inline void SetSetCols(PCOL colp) {To_SetCols = colp;}
inline void SetFilter(PFIL fp) {To_Filter = fp;}
inline void SetOrig(PTDB txp) {To_Orig = txp;} inline void SetOrig(PTDB txp) {To_Orig = txp;}
inline void SetUse(TUSE n) {Use = n;} inline void SetUse(TUSE n) {Use = n;}
inline void SetCondFil(PCFIL cfp) {To_CondFil = cfp;} inline void SetCondFil(PCFIL cfp) {To_CondFil = cfp;}
...@@ -78,6 +77,7 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block. ...@@ -78,6 +77,7 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block.
virtual AMT GetAmType(void) {return TYPE_AM_ERROR;} virtual AMT GetAmType(void) {return TYPE_AM_ERROR;}
virtual bool IsRemote(void) {return false;} virtual bool IsRemote(void) {return false;}
virtual bool IsIndexed(void) {return false;} virtual bool IsIndexed(void) {return false;}
virtual void SetFilter(PFIL fp) {To_Filter = fp;}
virtual int GetTdb_No(void) {return Tdb_No;} virtual int GetTdb_No(void) {return Tdb_No;}
virtual PTDB GetNext(void) {return Next;} virtual PTDB GetNext(void) {return Next;}
virtual PCATLG GetCat(void) {return NULL;} virtual PCATLG GetCat(void) {return NULL;}
...@@ -103,6 +103,7 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block. ...@@ -103,6 +103,7 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block.
virtual void ResetDB(void) {} virtual void ResetDB(void) {}
virtual void ResetSize(void) {MaxSize = -1;} virtual void ResetSize(void) {MaxSize = -1;}
virtual int RowNumber(PGLOBAL g, bool b = false); virtual int RowNumber(PGLOBAL g, bool b = false);
virtual bool CanBeFiltered(void) {return true;}
virtual PTDB Duplicate(PGLOBAL) {return NULL;} virtual PTDB Duplicate(PGLOBAL) {return NULL;}
virtual PTDB Clone(PTABS) {return this;} virtual PTDB Clone(PTABS) {return this;}
virtual PTDB Copy(PTABS t); virtual PTDB Copy(PTABS t);
......
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