Commit 040ccce8 authored by Olivier Bertrand's avatar Olivier Bertrand

Merge branch 'ob-10.1' into 10.1

parents e6da89ba 2f9db4ef
This diff is collapsed.
/*********** File AM Zip C++ Program Source Code File (.CPP) ***********/
/* PROGRAM NAME: FILAMZIP */
/* ------------- */
/* Version 1.1 */
/* Version 1.2 */
/* */
/* COPYRIGHT: */
/* ---------- */
......@@ -652,12 +652,18 @@ bool UNZIPUTL::openEntry(PGLOBAL g)
} // endif rc
size = finfo.uncompressed_size;
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) {
sprintf(g->Message, "unzReadCurrentFile rc = %d", rc);
unzCloseCurrentFile(zipfile);
free(memory);
delete[] memory;
memory = NULL;
entryopen = false;
} else {
......@@ -682,7 +688,7 @@ void UNZIPUTL::closeEntry()
} // endif entryopen
if (memory) {
free(memory);
delete[] memory;
memory = NULL;
} // endif memory
......
......@@ -39,6 +39,9 @@
//#include "select.h"
#include "xindex.h"
#if defined(MONGO_SUPPORT)
#include "filamtxt.h"
#include "tabdos.h"
#include "tabjson.h"
#include "tabext.h"
#include "tabmgo.h"
#endif // MONGO_SUPPORT
......@@ -1413,7 +1416,7 @@ PFIL FILTER::Copy(PTABS t)
/* Make selector json representation for Mongo tables. */
/***********************************************************************/
#if defined(MONGO_SUPPORT)
bool FILTER::MakeSelector(PGLOBAL g, PSTRG s)
bool FILTER::MakeSelector(PGLOBAL g, PSTRG s, bool m)
{
s->Append('{');
......@@ -1425,23 +1428,29 @@ bool FILTER::MakeSelector(PGLOBAL g, PSTRG s)
s->Append(Opc == OP_AND ? "and" : "or");
s->Append("\":[");
if (((PFIL)Arg(0))->MakeSelector(g, s))
if (((PFIL)Arg(0))->MakeSelector(g, s, m))
return true;
s->Append(',');
if (((PFIL)Arg(1))->MakeSelector(g, s))
if (((PFIL)Arg(1))->MakeSelector(g, s, m))
return true;
s->Append(']');
} else {
char buf[501];
char *pth, buf[501];
if (GetArgType(0) != TYPE_COLBLK)
return true;
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("\":{\"$");
switch (Opc) {
......
......@@ -62,7 +62,7 @@ class DllExport FILTER : public XOBJECT { /* Filter description block */
//virtual bool CheckLocal(PTDB);
//virtual int CheckSpcCol(PTDB tdbp, int n);
#if defined(MONGO_SUPPORT)
bool MakeSelector(PGLOBAL g, PSTRG s);
bool MakeSelector(PGLOBAL g, PSTRG s, bool m);
#endif // MONGO_SUPPORT
virtual void Print(PGLOBAL g, FILE *f, uint n);
virtual void Print(PGLOBAL g, char *ps, uint z);
......
......@@ -3111,7 +3111,7 @@ const COND *ha_connect::cond_push(const COND *cond)
} else if (x && cond)
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) {
tdbp->SetFilter(CondFilter(g, (Item *)cond));
......
This diff is collapsed.
......@@ -63,6 +63,7 @@ class DllExport MGOFAM : public DOSFAM {
virtual int RenameTempFile(PGLOBAL g) { return RC_OK; }
virtual int InitDelete(PGLOBAL g, int fpos, int spos);
bool Init(PGLOBAL g);
bool MakeCursor(PGLOBAL g);
void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k);
//static void *mgo_alloc(size_t n);
//static void *mgo_calloc(size_t n, size_t sz);
......@@ -85,11 +86,12 @@ class DllExport MGOFAM : public DOSFAM {
bson_error_t Error;
PFBLOCK To_Fbt; // Pointer to temp file block
MODE Mode;
const char *uristr;
const char *db_name;
const char *coll_name;
const char *options;
const char *filter;
const char *Uristr;
const char *Db_name;
const char *Coll_name;
const char *Options;
const char *Filter;
bool Done; // Init done
bool Pipe;
}; // end of class MGOFAM
......@@ -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->Schema = GetStringTableOption(g, topt, "Dbname", "test");
tdp->Options = GetStringTableOption(g, topt, "Colist", NULL);
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
tdp->Pretty = 0;
#else // !MONGO_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
......@@ -452,6 +453,7 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
Collname = GetStringCatInfo(g, "Tabname", Collname);
Schema = GetStringCatInfo(g, "Dbname", "test");
Options = GetStringCatInfo(g, "Colist", NULL);
Pipe = GetBoolCatInfo("Pipeline", false);
Pretty = 0;
#else // !MONGO_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
......@@ -481,7 +483,14 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
!(tmp == TMP_FORCE &&
(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 (m == MODE_READ || m == MODE_READX) {
txfp = new(g) UNZFAM(this);
......@@ -505,13 +514,6 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "GZ");
return NULL;
#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)
txfp = new(g) MAPFAM(this);
else
......@@ -746,6 +748,9 @@ bool TDBJSN::OpenDB(PGLOBAL g)
} // endif Use
if (Xcol && Txfp->GetAmType() != TYPE_AM_MGO)
To_Filter = NULL; // Imcompatible
return TDBDOS::OpenDB(g);
} // end of OpenDB
......@@ -922,9 +927,6 @@ int TDBJSN::WriteDB(PGLOBAL g)
int rc = TDBDOS::WriteDB(g);
#if USE_G
//if (rc == RC_FX)
// strcpy(g->Message, G->Message);
PlugSubSet(G, G->Sarea, G->Sarea_Size);
#endif
Row->Clear();
......@@ -1195,11 +1197,61 @@ bool JSONCOL::ParseJpath(PGLOBAL g)
return false;
} // 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. */
/***********************************************************************/
PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp)
{
{
if (Value->IsTypeNum()) {
strcpy(g->Message, "Cannot make Json for a numeric column");
Value->Reset();
......@@ -1910,6 +1962,9 @@ bool TDBJSON::OpenDB(PGLOBAL g)
return true;
} // endswitch Jmode
if (Xcol)
To_Filter = NULL; // Imcompatible
Use = USE_OPEN;
return false;
} // end of OpenDB
......
......@@ -66,6 +66,7 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
PSZ Collname; /* External collection name */
PSZ Schema; /* External schema (DB) name */
PSZ Options; /* Colist ; filter */
bool Pipe; /* True if Colist is a pipeline */
#endif // MONGO_SUPPORT
}; // end of JSONDEF
......@@ -78,6 +79,9 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
class DllExport TDBJSN : public TDBDOS {
friend class JSONCOL;
friend class JSONDEF;
#if defined(MONGO_SUPPORT)
friend class MGOFAM;
#endif // MONGO_SUPPORT
public:
// Constructor
TDBJSN(PJDEF tdp, PTXF txfp);
......@@ -96,6 +100,8 @@ class DllExport TDBJSN : public TDBDOS {
virtual PCOL InsertSpecialColumn(PCOL colp);
virtual int RowNumber(PGLOBAL g, bool b = FALSE)
{return (b) ? M : N;}
virtual bool CanBeFiltered(void)
{return Txfp->GetAmType() == TYPE_AM_MGO || !Xcol;}
// Database routines
virtual int Cardinality(PGLOBAL g);
......@@ -139,6 +145,7 @@ class DllExport TDBJSN : public TDBDOS {
class DllExport JSONCOL : public DOSCOL {
friend class TDBJSN;
friend class TDBJSON;
friend class MGOFAM;
public:
// Constructors
JSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i);
......@@ -150,6 +157,7 @@ class DllExport JSONCOL : public DOSCOL {
// Methods
virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
bool ParseJpath(PGLOBAL g);
char *GetJpath(PGLOBAL g, bool proj);
virtual void ReadColumn(PGLOBAL g);
virtual void WriteColumn(PGLOBAL g);
......
......@@ -481,6 +481,7 @@ void INCOL::AddCol(PGLOBAL g, PCOL colp, char *jp)
/***********************************************************************/
TDBMGO::TDBMGO(PMGODEF tdp) : TDBEXT(tdp)
{
G = NULL;
Uri = NULL;
Pool = NULL;
Client = NULL;
......@@ -490,6 +491,7 @@ TDBMGO::TDBMGO(PMGODEF tdp) : TDBEXT(tdp)
Query = NULL;
Opts = NULL;
Fpc = NULL;
Cnd = NULL;
if (tdp) {
Uristr = tdp->Uri;
......@@ -516,6 +518,7 @@ TDBMGO::TDBMGO(PMGODEF tdp) : TDBEXT(tdp)
TDBMGO::TDBMGO(TDBMGO *tdbp) : TDBEXT(tdbp)
{
G = tdbp->G;
Uri = tdbp->Uri;
Pool = tdbp->Pool;
Client = tdbp->Client;
......@@ -525,6 +528,7 @@ TDBMGO::TDBMGO(TDBMGO *tdbp) : TDBEXT(tdbp)
Query = tdbp->Query;
Opts = tdbp->Opts;
Fpc = tdbp->Fpc;
Cnd = tdbp->Cnd;
Uristr = tdbp->Uristr;
Db_name = tdbp->Db_name;;
Coll_name = tdbp->Coll_name;
......@@ -642,6 +646,8 @@ bool TDBMGO::Init(PGLOBAL g)
if (Done)
return false;
G = g;
if (Options && !Pipe) {
char *p = (char*)strchr(Options, ';');
......@@ -699,13 +705,33 @@ bool TDBMGO::Init(PGLOBAL g)
return false;
} // 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. */
/***********************************************************************/
bool TDBMGO::MakeCursor(PGLOBAL g)
bool TDBMGO::MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor)
{
const char *p;
PSTRG s;
PSTRG s = NULL;
if (Pipe) {
if (trace)
......@@ -724,7 +750,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g)
if (To_Filter) {
s->Append(",{\"$match\":");
if (To_Filter->MakeSelector(g, s)) {
if (To_Filter->MakeSelector(g, s, true)) {
strcpy(g->Message, "Failed making selector");
return true;
} else
......@@ -738,7 +764,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g)
for (PCOL cp = Columns; cp; cp = cp->GetNext()) {
s->Append(",\"");
s->Append(((PMGOCOL)cp)->Jpath);
s->Append(((PMGOCOL)cp)->GetProjPath(g));
s->Append("\":1");
} // endfor cp
......@@ -785,7 +811,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g)
if (Filter)
s->Append(',');
if (To_Filter->MakeSelector(g, s)) {
if (To_Filter->MakeSelector(g, s, true)) {
strcpy(g->Message, "Failed making selector");
return true;
} // endif Selector
......@@ -821,7 +847,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g)
for (PCOL cp = Columns; cp; cp = cp->GetNext()) {
s->Append(",\"");
s->Append(((PMGOCOL)cp)->Jpath);
s->Append(((PMGOCOL)cp)->GetProjPath(g));
s->Append("\":1");
} // endfor cp
......@@ -873,7 +899,7 @@ bool TDBMGO::OpenDB(PGLOBAL g)
} else if (Mode == MODE_INSERT)
MakeColumnGroups(g);
else if (MakeCursor(g))
else if (MakeCursor(g, Cursor))
return true;
} // endif Use
......@@ -1141,6 +1167,37 @@ MGOCOL::MGOCOL(MGOCOL *col1, PTDB tdbp) : EXTCOL(col1, tdbp)
Mbuf = col1->Mbuf;
} // 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. */
/***********************************************************************/
......
......@@ -131,6 +131,7 @@ class DllExport TDBMGO : public TDBEXT {
virtual PTDB Clone(PTABS t);
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual PCOL InsertSpecialColumn(PCOL colp);
virtual void SetFilter(PFIL fp);
virtual int RowNumber(PGLOBAL g, bool b = FALSE) {return N;}
// Database routines
......@@ -145,12 +146,13 @@ class DllExport TDBMGO : public TDBEXT {
protected:
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 MakeColumnGroups(PGLOBAL g);
bool DocWrite(PGLOBAL g, PINCOL icp);
// Members
PGLOBAL G; // Needed by SetFilter
mongoc_uri_t *Uri;
mongoc_client_pool_t *Pool; // Thread safe client pool
mongoc_client_t *Client; // The MongoDB client
......@@ -162,6 +164,7 @@ class DllExport TDBMGO : public TDBEXT {
bson_t *Opts; // MongoDB cursor options
bson_error_t Error;
PINCOL Fpc; // To insert INCOL classes
const Item *Cnd; // The first condition
const char *Uristr;
const char *Db_name;
const char *Coll_name;
......@@ -199,6 +202,7 @@ class DllExport MGOCOL : public EXTCOL {
protected:
// Default constructor not to be used
MGOCOL(void) {}
char *GetProjPath(PGLOBAL g);
char *Mini(PGLOBAL g, const bson_t *bson, bool b);
// Members
......
......@@ -61,7 +61,6 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block.
inline PFIL GetFilter(void) {return To_Filter;}
inline PCOL GetSetCols(void) {return To_SetCols;}
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 SetUse(TUSE n) {Use = n;}
inline void SetCondFil(PCFIL cfp) {To_CondFil = cfp;}
......@@ -78,6 +77,7 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block.
virtual AMT GetAmType(void) {return TYPE_AM_ERROR;}
virtual bool IsRemote(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 PTDB GetNext(void) {return Next;}
virtual PCATLG GetCat(void) {return NULL;}
......@@ -103,6 +103,7 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block.
virtual void ResetDB(void) {}
virtual void ResetSize(void) {MaxSize = -1;}
virtual int RowNumber(PGLOBAL g, bool b = false);
virtual bool CanBeFiltered(void) {return true;}
virtual PTDB Duplicate(PGLOBAL) {return NULL;}
virtual PTDB Clone(PTABS) {return this;}
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