From cd337a3730828e3287b0b291430940209bc52594 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Wed, 3 May 2017 01:06:00 +0200 Subject: [PATCH] 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 --- storage/connect/catalog.h | 3 - storage/connect/connect.cc | 8 +- storage/connect/ha_connect.cc | 55 ++++----- storage/connect/ha_connect.h | 2 +- storage/connect/mongofam.cpp | 5 +- storage/connect/mycat.cc | 33 ------ storage/connect/mycat.h | 5 - .../connect/mysql-test/connect/disabled.def | 6 +- storage/connect/plgdbutl.cpp | 19 +-- storage/connect/plugutil.cpp | 19 ++- storage/connect/reldef.cpp | 7 +- storage/connect/tabjson.cpp | 6 +- storage/connect/tabmgo.cpp | 112 +++++++++--------- storage/connect/tabmgo.h | 8 +- storage/connect/tabmul.cpp | 61 ++++++---- storage/connect/tabmul.h | 4 +- 16 files changed, 173 insertions(+), 180 deletions(-) diff --git a/storage/connect/catalog.h b/storage/connect/catalog.h index 70304c410cc..d53df6b3aa5 100644 --- a/storage/connect/catalog.h +++ b/storage/connect/catalog.h @@ -68,11 +68,9 @@ class DllExport CATALOG { bool GetDefHuge(void) {return DefHuge;} void SetDefHuge(bool b) {DefHuge = b;} char *GetCbuf(void) {return Cbuf;} -//char *GetDataPath(void) {return (char*)DataPath;} // Methods virtual void Reset(void) {} -//virtual void SetDataPath(PGLOBAL g, const char *path) {} virtual bool CheckName(PGLOBAL, char*) {return true;} virtual bool ClearName(PGLOBAL, PSZ) {return true;} virtual PRELDEF MakeOneTableDesc(PGLOBAL, LPCSTR, LPCSTR) {return NULL;} @@ -102,7 +100,6 @@ class DllExport CATALOG { int Cblen; /* Length of suballoc. buffer */ CURTAB Ctb; /* Used to enumerate tables */ bool DefHuge; /* true: tables default to huge */ -//LPCSTR DataPath; /* Is the Path of DB data dir */ }; // end of class CATALOG #endif // __CATALOG__H diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index 84782515a15..c9360523591 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -117,11 +117,10 @@ bool CntCheckDB(PGLOBAL g, PHC handler, const char *pathname) handler); // Set the database path for this table - handler->SetDataPath(g, pathname); + if (handler->SetDataPath(g, pathname)) + return true; if (dbuserp->Catalog) { -// ((MYCAT *)dbuserp->Catalog)->SetHandler(handler); done later -// ((MYCAT *)dbuserp->Catalog)->SetDataPath(g, pathname); return false; // Nothing else to do } // endif Catalog @@ -138,9 +137,6 @@ bool CntCheckDB(PGLOBAL g, PHC handler, const char *pathname) if (!(dbuserp->Catalog= new MYCAT(handler))) return true; -//((MYCAT *)dbuserp->Catalog)->SetDataPath(g, pathname); -//dbuserp->UseTemp= TMP_AUTO; - /*********************************************************************/ /* All is correct. */ /*********************************************************************/ diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 7a718c931d0..9be8a4e4300 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -212,7 +212,7 @@ PQRYRES VirColumns(PGLOBAL g, bool info); PQRYRES JSONColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info); PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info); #if defined(MONGO_SUPPORT) -PQRYRES MGOColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info); +PQRYRES MGOColumns(PGLOBAL g, char *db, PTOS topt, bool info); #endif // MONGO_SUPPORT int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v); void PushWarning(PGLOBAL g, THD *thd, int level); @@ -1751,9 +1751,9 @@ void ha_connect::AddColName(char *cp, Field *fp) /***********************************************************************/ /* This function sets the current database path. */ /***********************************************************************/ -void ha_connect::SetDataPath(PGLOBAL g, const char *path) +bool ha_connect::SetDataPath(PGLOBAL g, const char *path) { - datapath= SetPath(g, path); + return (!(datapath= SetPath(g, path))); } // end of SetDataPath /****************************************************************************/ @@ -2709,6 +2709,8 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) if (x) return NULL; + else + pb0= pb1= pb2= ph0= ph1= ph2= NULL; if (trace) htrc("Cond: Ftype=%d name=%s\n", cond_item->functype(), @@ -4004,8 +4006,12 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos) tdbp->SetFilter(NULL); rc= rnd_next(buf); - } else - rc= HA_ERR_KEY_NOT_FOUND; + } else { + PGLOBAL g = GetPlug((table) ? table->in_use : NULL, xp); + strcpy(g->Message, "Not supported by this table type"); + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + rc= HA_ERR_INTERNAL_ERROR; + } // endif SetRecpos DBUG_RETURN(rc); } // end of rnd_pos @@ -4071,9 +4077,13 @@ int ha_connect::info(uint flag) } // endif xmod // This is necessary for getting file length - if (table) - SetDataPath(g, table->s->db.str); - else + if (table) { + if (SetDataPath(g, table->s->db.str)) { + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + } // endif SetDataPath + + } else DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Should never happen if (!(tdbp= GetTDB(g))) @@ -5562,13 +5572,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, break; #if defined(MONGO_SUPPORT) case TAB_MONGO: - dsn = strz(g, create_info->connect_string); - - if (!dsn) - strcpy(g->Message, "Missing URI"); - else - ok = true; - + ok = true; break; #endif // MONGO_SUPPORT case TAB_VIR: @@ -5595,12 +5599,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd, char *cnm, *rem, *dft, *xtra, *key, *fmt; int i, len, prec, dec, typ, flg; - // if (cat) - // cat->SetDataPath(g, table_s->db.str); - // else - // return HA_ERR_INTERNAL_ERROR; // Should never happen - - dpath = SetPath(g, table_s->db.str); + if (!(dpath = SetPath(g, table_s->db.str))) { + rc = HA_ERR_INTERNAL_ERROR; + goto err; + } // endif dpath if (src && ttp != TAB_PIVOT && ttp != TAB_ODBC && ttp != TAB_JDBC) { qrp = SrcColumns(g, host, db, user, pwd, src, port); @@ -5716,7 +5718,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, break; #if defined(MONGO_SUPPORT) case TAB_MONGO: - qrp = MGOColumns(g, (char*)db, dsn, topt, fnc == FNC_COL); + qrp = MGOColumns(g, (char*)db, topt, fnc == FNC_COL); break; #endif // MONGO_SUPPORT #if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT) @@ -6521,11 +6523,10 @@ int ha_connect::create(const char *name, TABLE *table_arg, PDBUSER dup= PlgGetUser(g); PCATLG cat= (dup) ? dup->Catalog : NULL; - SetDataPath(g, table_arg->s->db.str); - - if (cat) { -// cat->SetDataPath(g, table_arg->s->db.str); - + if (SetDataPath(g, table_arg->s->db.str)) { + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + rc = HA_ERR_INTERNAL_ERROR; + } else if (cat) { #if defined(WITH_PARTITION_STORAGE_ENGINE) if (part_info) strncpy(partname, diff --git a/storage/connect/ha_connect.h b/storage/connect/ha_connect.h index cb15d371b5c..2c5290301c4 100644 --- a/storage/connect/ha_connect.h +++ b/storage/connect/ha_connect.h @@ -199,7 +199,7 @@ public: bool IsUnique(uint n); char *GetDataPath(void) {return (char*)datapath;} - void SetDataPath(PGLOBAL g, const char *path); + bool SetDataPath(PGLOBAL g, const char *path); PTDB GetTDB(PGLOBAL g); int OpenTable(PGLOBAL g, bool del= false); bool CheckColumnList(PGLOBAL g); diff --git a/storage/connect/mongofam.cpp b/storage/connect/mongofam.cpp index 074dc9f9f2e..dcd96b6fd13 100644 --- a/storage/connect/mongofam.cpp +++ b/storage/connect/mongofam.cpp @@ -767,6 +767,9 @@ void MGOFAM::CloseTableFile(PGLOBAL g, bool) /***********************************************************************/ void MGOFAM::Rewind(void) { - // TODO implement me + mongoc_cursor_t *cursor = mongoc_cursor_clone(Cursor); + + mongoc_cursor_destroy(Cursor); + Cursor = cursor; } // end of Rewind diff --git a/storage/connect/mycat.cc b/storage/connect/mycat.cc index d589c9fc2b3..0104213ed92 100644 --- a/storage/connect/mycat.cc +++ b/storage/connect/mycat.cc @@ -484,39 +484,6 @@ void MYCAT::Reset(void) { } // end of Reset -#if 0 -/***********************************************************************/ -/* This function sets the current database path. */ -/***********************************************************************/ -void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path) - { - if (path) { - size_t len= strlen(path) + (*path != '.' ? 4 : 1); - char *buf= (char*)PlugSubAlloc(g, NULL, len); - - if (PlugIsAbsolutePath(path)) - { - strcpy(buf, path); - *datapath= buf; - return; - } - - if (*path != '.') { -#if defined(__WIN__) - char *s= "\\"; -#else // !__WIN__ - char *s= "/"; -#endif // !__WIN__ - strcat(strcat(strcat(strcpy(buf, "."), s), path), s); - } else - strcpy(buf, path); - - *datapath= buf; - } // endif path - - } // end of SetDataPath -#endif // 0 - /***********************************************************************/ /* GetTableDesc: retrieve a table descriptor. */ /* Look for a table descriptor matching the name and type. */ diff --git a/storage/connect/mycat.h b/storage/connect/mycat.h index a3682b31f17..b6bdd5e5e11 100644 --- a/storage/connect/mycat.h +++ b/storage/connect/mycat.h @@ -98,10 +98,7 @@ class MYCAT : public CATALOG { // Methods void Reset(void); -//void SetDataPath(PGLOBAL g, const char *path) -// {SetPath(g, &DataPath, path);} bool StoreIndex(PGLOBAL, PTABDEF) {return false;} // Temporary -// PRELDEF GetTableDesc(PGLOBAL g, LPCSTR name, PRELDEF GetTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR type, PRELDEF *prp = NULL); PTDB GetTable(PGLOBAL g, PTABLE tablep, @@ -109,9 +106,7 @@ class MYCAT : public CATALOG { void ClearDB(PGLOBAL g); protected: -// PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am); PRELDEF MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am); - //void SetPath(PGLOBAL g, LPCSTR *datapath, const char *path); // Members ha_connect *Hc; // The Connect handler diff --git a/storage/connect/mysql-test/connect/disabled.def b/storage/connect/mysql-test/connect/disabled.def index 5e15e0806ba..217e61e00b6 100644 --- a/storage/connect/mysql-test/connect/disabled.def +++ b/storage/connect/mysql-test/connect/disabled.def @@ -9,7 +9,9 @@ # Do not use any TAB characters for whitespace. # ############################################################################## -#jdbc : Variable settings depend on machine configuration -#jdbc_new : Variable settings depend on machine configuration +jdbc : Variable settings depend on machine configuration +jdbc_new : Variable settings depend on machine configuration jdbc_oracle : Variable settings depend on machine configuration jdbc_postgresql : Variable settings depend on machine configuration +json_mgo : Need MongoDB running and its C Driver installed +mongo : Need MongoDB running and its C Driver installed diff --git a/storage/connect/plgdbutl.cpp b/storage/connect/plgdbutl.cpp index eaa53bd478d..f4fa64499ff 100644 --- a/storage/connect/plgdbutl.cpp +++ b/storage/connect/plgdbutl.cpp @@ -387,26 +387,27 @@ char *SetPath(PGLOBAL g, const char *path) char *buf= NULL; if (path) { - size_t len= strlen(path) + (*path != '.' ? 4 : 1); + size_t len = strlen(path) + (*path != '.' ? 4 : 1); + + if (!(buf = (char*)PlgDBSubAlloc(g, NULL, len))) + return NULL; - buf= (char*)PlugSubAlloc(g, NULL, len); - if (PlugIsAbsolutePath(path)) { - strcpy(buf, path); - return buf; - } // endif path + strcpy(buf, path); + return buf; + } // endif path if (*path != '.') { #if defined(__WIN__) - char *s= "\\"; + char *s = "\\"; #else // !__WIN__ - char *s= "/"; + char *s = "/"; #endif // !__WIN__ strcat(strcat(strcat(strcpy(buf, "."), s), path), s); } else strcpy(buf, path); - } // endif path + } // endif path return buf; } // end of SetPath diff --git a/storage/connect/plugutil.cpp b/storage/connect/plugutil.cpp index c5c160073ee..4326adf8cd1 100644 --- a/storage/connect/plugutil.cpp +++ b/storage/connect/plugutil.cpp @@ -139,10 +139,17 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize) htrc("PlugInit: Language='%s'\n", ((!Language) ? "Null" : (char*)Language)); - if (!(g = (PGLOBAL)malloc(sizeof(GLOBAL)))) { - fprintf(stderr, MSG(GLOBAL_ERROR), (int)sizeof(GLOBAL)); - return NULL; - } else { + try { + g = new GLOBAL; + } catch (...) { + fprintf(stderr, MSG(GLOBAL_ERROR), (int)sizeof(GLOBAL)); + return NULL; + } // end try/catch + + //if (!(g = (PGLOBAL)malloc(sizeof(GLOBAL)))) { + // fprintf(stderr, MSG(GLOBAL_ERROR), (int)sizeof(GLOBAL)); + // return NULL; + // } else { g->Sarea = NULL; g->Createas = 0; g->Alchecked = 0; @@ -164,7 +171,7 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize) } else g->Sarea_Size = worksize; - } /* endif g */ + //} /* endif g */ g->jump_level = -1; /* New setting to allow recursive call of Plug */ return(g); @@ -183,7 +190,7 @@ int PlugExit(PGLOBAL g) if (g->Sarea) free(g->Sarea); - free(g); + delete g; return rc; } /* end of PlugExit */ diff --git a/storage/connect/reldef.cpp b/storage/connect/reldef.cpp index 5bb7848ab1c..c9d920318fb 100644 --- a/storage/connect/reldef.cpp +++ b/storage/connect/reldef.cpp @@ -277,8 +277,13 @@ int TABDEF::GetColCatInfo(PGLOBAL g) // Take care of the column definitions i= poff= nof= nlg= 0; +#if defined(__WIN__) // Offsets of HTML and DIR tables start from 0, DBF at 1 - loff= (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0; + loff= (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0; +#else // !__WIN__ + // Offsets of HTML tables start from 0, DIR and DBF at 1 + loff = (tc == TAB_DBF || tc == TAB_DIR) ? 1 : (tc == TAB_XML) ? -1 : 0; +#endif // !__WIN__ while (true) { // Default Offset depends on table type diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index 2c5db0a23fb..76afd2d2e25 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -746,10 +746,10 @@ bool TDBJSN::OpenDB(PGLOBAL g) return true; } // endswitch Jmode - } // endif Use + if (Xcol && Txfp->GetAmType() != TYPE_AM_MGO) + To_Filter = NULL; // Imcompatible - if (Xcol && Txfp->GetAmType() != TYPE_AM_MGO) - To_Filter = NULL; // Imcompatible + } // endif Use return TDBDOS::OpenDB(g); } // end of OpenDB diff --git a/storage/connect/tabmgo.cpp b/storage/connect/tabmgo.cpp index 998a4944bb1..158dbb95f4c 100644 --- a/storage/connect/tabmgo.cpp +++ b/storage/connect/tabmgo.cpp @@ -39,7 +39,7 @@ /* MGOColumns: construct the result blocks containing the description */ /* of all the columns of a document contained inside MongoDB. */ /***********************************************************************/ -PQRYRES MGOColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info) +PQRYRES MGOColumns(PGLOBAL g, char *db, PTOS topt, bool info) { static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_SHORT, TYPE_SHORT, TYPE_STRING}; @@ -64,7 +64,7 @@ PQRYRES MGOColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info) /*********************************************************************/ mgd = new(g) MGODISC(g, (int*)length); - if ((n = mgd->GetColumns(g, db, dsn, topt)) < 0) + if ((n = mgd->GetColumns(g, db, topt)) < 0) goto err; skipit: @@ -142,7 +142,7 @@ MGODISC::MGODISC(PGLOBAL g, int *lg) { /***********************************************************************/ /* Class used to get the columns of a mongo collection. */ /***********************************************************************/ -int MGODISC::GetColumns(PGLOBAL g, char *db, char *dsn, PTOS topt) +int MGODISC::GetColumns(PGLOBAL g, char *db, PTOS topt) { bson_iter_t iter; const bson_t *doc; @@ -153,16 +153,11 @@ int MGODISC::GetColumns(PGLOBAL g, char *db, char *dsn, PTOS topt) lvl = (lvl > 16) ? 16 : lvl; all = GetBooleanTableOption(g, topt, "Fullarray", false); - if (!dsn) { - strcpy(g->Message, "Missing URI"); - return -1; - } // endif dsn - /*********************************************************************/ /* Open the MongoDB collection. */ /*********************************************************************/ tdp = new(g) MGODEF; - tdp->Uri = dsn; + tdp->Uri = GetStringTableOption(g, topt, "Connect", "mongodb://localhost:27017"); tdp->Tabname = GetStringTableOption(g, topt, "Name", NULL); tdp->Tabname = GetStringTableOption(g, topt, "Tabname", tdp->Tabname); tdp->Tabschema = GetStringTableOption(g, topt, "Dbname", db); @@ -397,7 +392,7 @@ bool MGODEF::DefineAM(PGLOBAL g, LPCSTR, int poff) else if (!Tabschema) Tabschema = GetStringCatInfo(g, "Dbname", "*"); - Uri = GetStringCatInfo(g, "Connect", NULL); + Uri = GetStringCatInfo(g, "Connect", "mongodb://localhost:27017"); Colist = GetStringCatInfo(g, "Colist", NULL); Filter = GetStringCatInfo(g, "Filter", NULL); Base = GetIntCatInfo("Base", 0) ? 1 : 0; @@ -713,13 +708,13 @@ void TDBMGO::SetFilter(PFIL fp) To_Filter = fp; if (fp && Cursor && Cnd != Cond) { - mongoc_cursor_t *cursor = NULL; + mongoc_cursor_t *cursor = MakeCursor(G); - if (!MakeCursor(G, cursor)) { + if (cursor) { mongoc_cursor_destroy(Cursor); Cursor = cursor; - } else if (cursor) - mongoc_cursor_destroy(cursor); + } else + htrc("SetFilter: %s\n", G->Message); } // endif Cursor @@ -728,10 +723,11 @@ void TDBMGO::SetFilter(PFIL fp) /***********************************************************************/ /* OpenDB: Data Base open routine for MONGO access method. */ /***********************************************************************/ -bool TDBMGO::MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor) +mongoc_cursor_t *TDBMGO::MakeCursor(PGLOBAL g) { - const char *p; - PSTRG s = NULL; + const char *p; + mongoc_cursor_t *cursor; + PSTRG s = NULL; if (Pipe) { if (trace) @@ -741,7 +737,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor) if (!p) { strcpy(g->Message, "Missing ] in pipeline"); - return true; + return NULL; } else *(char*)p = 0; @@ -752,7 +748,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor) if (To_Filter->MakeSelector(g, s, true)) { strcpy(g->Message, "Failed making selector"); - return true; + return NULL; } else s->Append('}'); @@ -779,15 +775,15 @@ bool TDBMGO::MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor) if (!Query) { sprintf(g->Message, "Wrong pipeline: %s", Error.message); - return true; + return NULL; } // endif Query - Cursor = mongoc_collection_aggregate(Collection, MONGOC_QUERY_NONE, + cursor = mongoc_collection_aggregate(Collection, MONGOC_QUERY_NONE, Query, NULL, NULL); - if (mongoc_cursor_error(Cursor, &Error)) { + if (mongoc_cursor_error(cursor, &Error)) { sprintf(g->Message, "Mongo aggregate Failure: %s", Error.message); - return true; + return NULL; } // endif cursor } else { @@ -813,7 +809,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor) if (To_Filter->MakeSelector(g, s, true)) { strcpy(g->Message, "Failed making selector"); - return true; + return NULL; } // endif Selector To_Filter = NULL; // Not needed anymore @@ -827,7 +823,7 @@ bool TDBMGO::MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor) if (!Query) { sprintf(g->Message, "Wrong filter: %s", Error.message); - return true; + return NULL; } // endif Query } else @@ -858,13 +854,13 @@ bool TDBMGO::MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor) if (!Opts) { sprintf(g->Message, "Wrong options: %s", Error.message); - return true; + return NULL; } // endif Opts - Cursor = mongoc_collection_find_with_opts(Collection, Query, Opts, NULL); + cursor = mongoc_collection_find_with_opts(Collection, Query, Opts, NULL); } // endif Pipe - return false; + return cursor; } // end of MakeCursor /***********************************************************************/ @@ -876,34 +872,38 @@ bool TDBMGO::OpenDB(PGLOBAL g) /*******************************************************************/ /* Table already open replace it at its beginning. */ /*******************************************************************/ + mongoc_cursor_t *cursor = mongoc_cursor_clone(Cursor); + + mongoc_cursor_destroy(Cursor); + Cursor = cursor; Fpos = -1; - } else { - /*******************************************************************/ - /* First opening. */ - /*******************************************************************/ - if (Pipe && Mode != MODE_READ) { - strcpy(g->Message, "Pipeline tables are read only"); - return true; - } // endif Pipe - - if (Init(g)) - return true; - - if (Mode == MODE_DELETE && !Next) { - // Delete all documents - if (!mongoc_collection_remove(Collection, MONGOC_REMOVE_NONE, - Query, NULL, &Error)) { - sprintf(g->Message, "Mongo remove all: %s", Error.message); - return true; - } // endif remove - - } else if (Mode == MODE_INSERT) - MakeColumnGroups(g); - else if (MakeCursor(g, Cursor)) - return true; - + return false; } // endif Use + /*********************************************************************/ + /* First opening. */ + /*********************************************************************/ + if (Pipe && Mode != MODE_READ) { + strcpy(g->Message, "Pipeline tables are read only"); + return true; + } // endif Pipe + + if (Init(g)) + return true; + + if (Mode == MODE_DELETE && !Next) { + // Delete all documents + if (!mongoc_collection_remove(Collection, MONGOC_REMOVE_NONE, + Query, NULL, &Error)) { + sprintf(g->Message, "Mongo remove all: %s", Error.message); + return true; + } // endif remove + + } else if (Mode == MODE_INSERT) + MakeColumnGroups(g); + else if (!(Cursor = MakeCursor(g))) + return true; + return false; } // end of OpenDB @@ -1081,6 +1081,12 @@ int TDBMGO::WriteDB(PGLOBAL g) } // endif iter if (b) { + if (trace) { + char *str = bson_as_json(query, NULL); + htrc("update query: %s\n", str); + bson_free(str); + } // endif trace + if (Mode == MODE_UPDATE) { bson_t child; bson_t *update = bson_new(); diff --git a/storage/connect/tabmgo.h b/storage/connect/tabmgo.h index dd84f0ee4db..4131283e39a 100644 --- a/storage/connect/tabmgo.h +++ b/storage/connect/tabmgo.h @@ -48,7 +48,7 @@ public: MGODISC(PGLOBAL g, int *lg); // Functions - int GetColumns(PGLOBAL g, char *db, char *dsn, PTOS topt); + int GetColumns(PGLOBAL g, char *db, PTOS topt); bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc, char *pcn, char *pfmt, int i, int k, bool b); @@ -69,7 +69,7 @@ class DllExport MGODEF : public EXTDEF { /* Table description */ friend class TDBMGO; friend class MGOFAM; friend class MGODISC; - friend PQRYRES MGOColumns(PGLOBAL, char *, char *, PTOS, bool); + friend PQRYRES MGOColumns(PGLOBAL, char *, PTOS, bool); public: // Constructor MGODEF(void); @@ -117,7 +117,7 @@ class DllExport TDBMGO : public TDBEXT { friend class MGOCOL; friend class MGODEF; friend class MGODISC; - friend PQRYRES MGOColumns(PGLOBAL, char *, char *, PTOS, bool); + friend PQRYRES MGOColumns(PGLOBAL, char *, PTOS, bool); public: // Constructor TDBMGO(PMGODEF tdp); @@ -146,7 +146,7 @@ public: protected: bool Init(PGLOBAL g); - bool MakeCursor(PGLOBAL g, mongoc_cursor_t *cursor); + mongoc_cursor_t *MakeCursor(PGLOBAL g); void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k); void MakeColumnGroups(PGLOBAL g); bool DocWrite(PGLOBAL g, PINCOL icp); diff --git a/storage/connect/tabmul.cpp b/storage/connect/tabmul.cpp index ea04e4cf731..b3a3ee20317 100644 --- a/storage/connect/tabmul.cpp +++ b/storage/connect/tabmul.cpp @@ -603,8 +603,9 @@ bool TDBMSD::InitFileNames(PGLOBAL g) bool DIRDEF::DefineAM(PGLOBAL g, LPCSTR, int) { Desc = Fn = GetStringCatInfo(g, "Filename", NULL); - Incl = (GetIntCatInfo("Subdir", 0) != 0); - Huge = (GetIntCatInfo("Huge", 0) != 0); + Incl = GetBoolCatInfo("Subdir", false); + Huge = GetBoolCatInfo("Huge", false); + Nodir = GetBoolCatInfo("Nodir", true); return false; } // end of DefineAM @@ -654,12 +655,14 @@ void TDBDIR::Init(void) TDBDIR::TDBDIR(PDIRDEF tdp) : TDBASE(tdp) { To_File = tdp->Fn; + Nodir = tdp->Nodir; Init(); } // end of TDBDIR standard constructor TDBDIR::TDBDIR(PSZ fpat) : TDBASE((PTABDEF)NULL) { To_File = fpat; + Nodir = true; Init(); } // end of TDBDIR constructor @@ -812,27 +815,32 @@ int TDBDIR::ReadDB(PGLOBAL g) int rc = RC_OK; #if defined(__WIN__) - if (hSearch == INVALID_HANDLE_VALUE) { - /*******************************************************************/ - /* Start searching files in the target directory. The use of the */ - /* Path function is required when called from TDBSDR. */ - /*******************************************************************/ - hSearch = FindFirstFile(Path(g), &FileData); + do { + if (hSearch == INVALID_HANDLE_VALUE) { + /*****************************************************************/ + /* Start searching files in the target directory. The use of */ + /* the Path function is required when called from TDBSDR. */ + /*****************************************************************/ + hSearch = FindFirstFile(Path(g), &FileData); - if (hSearch == INVALID_HANDLE_VALUE) - rc = RC_EF; - else - iFile++; + if (hSearch == INVALID_HANDLE_VALUE) { + rc = RC_EF; + break; + } else + iFile++; - } else { - if (!FindNextFile(hSearch, &FileData)) { - // Restore file name and type pattern - _splitpath(To_File, NULL, NULL, Fname, Ftype); - rc = RC_EF; - } else - iFile++; + } else { + if (!FindNextFile(hSearch, &FileData)) { + // Restore file name and type pattern + _splitpath(To_File, NULL, NULL, Fname, Ftype); + rc = RC_EF; + break; + } else + iFile++; - } // endif hSearch + } // endif hSearch + + } while (Nodir && FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); if (rc == RC_OK) _splitpath(FileData.cFileName, NULL, NULL, Fname, Ftype); @@ -1225,8 +1233,9 @@ int TDBSDR::ReadDB(PGLOBAL g) retry: do { if (Sub->H == INVALID_HANDLE_VALUE) { - _makepath(Fpath, Drive, Direc, "*", "."); - Sub->H = FindFirstFile(Fpath, &FileData); +// _makepath(Fpath, Drive, Direc, "*", "."); why was this made? + _makepath(Fpath, Drive, Direc, "*", NULL); + Sub->H = FindFirstFile(Fpath, &FileData); } else if (!FindNextFile(Sub->H, &FileData)) { FindClose(Sub->H); Sub->H = INVALID_HANDLE_VALUE; @@ -1234,8 +1243,9 @@ int TDBSDR::ReadDB(PGLOBAL g) break; } // endif findnext - } while(!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - || *FileData.cFileName== '.'); + } while(!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || + (*FileData.cFileName == '.' && + (!FileData.cFileName[1] || FileData.cFileName[1] == '.'))); if (Sub->H == INVALID_HANDLE_VALUE) { // No more sub-directories. Are we in a sub-directory? @@ -1289,7 +1299,8 @@ int TDBSDR::ReadDB(PGLOBAL g) if (lstat(Fpath, &Fileinfo) < 0) { sprintf(g->Message, "%s: %s", Fpath, strerror(errno)); rc = RC_FX; - } else if (S_ISDIR(Fileinfo.st_mode) && *Entry->d_name != '.') { + } else if (S_ISDIR(Fileinfo.st_mode) && strcmp(Entry->d_name, "." + && strcmp(Entry->d_name, "..") { // Look in the name sub-directory if (!Sub->Next) { PSUBDIR sup; diff --git a/storage/connect/tabmul.h b/storage/connect/tabmul.h index 3c0ab1a4aa5..7426f3cc01f 100644 --- a/storage/connect/tabmul.h +++ b/storage/connect/tabmul.h @@ -118,7 +118,8 @@ class DllExport DIRDEF : public TABDEF { /* Directory listing table */ // Members PSZ Fn; /* Path/Name of file search */ bool Incl; /* true to include sub-directories */ - bool Huge; /* true if files can be larger than 2GB */ + bool Huge; /* true if files can be larger than 2GB */ + bool Nodir; /* true to exclude directories */ }; // end of DIRDEF /***********************************************************************/ @@ -175,6 +176,7 @@ public: char Direc[_MAX_DIR]; // Search path char Fname[_MAX_FNAME]; // File name char Ftype[_MAX_EXT]; // File extention + bool Nodir; // Exclude directories from file list }; // end of class TDBDIR /***********************************************************************/