From ef0829ef40eb4136eed4282057baa4126dd66b69 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sat, 1 May 2021 22:29:38 +0200 Subject: - Major update of the json/bson/mongo table types programs. Fix several bugs, chiefly concerning CURL operations. modified: storage/connect/bson.cpp modified: storage/connect/cmgfam.cpp modified: storage/connect/cmgoconn.cpp modified: storage/connect/cmgoconn.h modified: storage/connect/colblk.h modified: storage/connect/ha_connect.cc modified: storage/connect/jmgfam.cpp modified: storage/connect/jmgoconn.cpp modified: storage/connect/jmgoconn.h modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/mysql-test/connect/r/bson_mongo_c.result modified: storage/connect/mysql-test/connect/r/json_mongo_c.result modified: storage/connect/mysql-test/connect/r/mongo_c.result modified: storage/connect/mysql-test/connect/r/mongo_java_2.result modified: storage/connect/mysql-test/connect/r/mongo_java_3.result modified: storage/connect/mysql-test/connect/std_data/Mongo2.jar modified: storage/connect/mysql-test/connect/std_data/Mongo3.jar modified: storage/connect/tabbson.cpp modified: storage/connect/tabbson.h modified: storage/connect/tabcmg.cpp modified: storage/connect/tabcmg.h modified: storage/connect/tabjmg.cpp modified: storage/connect/tabjmg.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h --- storage/connect/tabcmg.cpp | 155 +++++++++++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 62 deletions(-) (limited to 'storage/connect/tabcmg.cpp') diff --git a/storage/connect/tabcmg.cpp b/storage/connect/tabcmg.cpp index f2ff721627c..1552bdde58a 100644 --- a/storage/connect/tabcmg.cpp +++ b/storage/connect/tabcmg.cpp @@ -1,6 +1,6 @@ /************** tabcmg C++ Program Source Code File (.CPP) *************/ -/* PROGRAM NAME: tabcmg Version 1.1 */ -/* (C) Copyright to the author Olivier BERTRAND 2017 */ +/* PROGRAM NAME: tabcmg Version 1.2 */ +/* (C) Copyright to the author Olivier BERTRAND 2017 - 2021 */ /* This program are the C MongoDB class DB execution routines. */ /***********************************************************************/ @@ -84,69 +84,80 @@ bool CMGDISC::FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc, bcol.Cbn = false; - if (BSON_ITER_HOLDS_UTF8(iter)) { - bcol.Type = TYPE_STRING; - bcol.Len = strlen(bson_iter_utf8(iter, NULL)); - } else if (BSON_ITER_HOLDS_INT32(iter)) { - bcol.Type = TYPE_INT; - bcol.Len = 11; // bson_iter_int32(iter) - } else if (BSON_ITER_HOLDS_INT64(iter)) { - bcol.Type = TYPE_BIGINT; - bcol.Len = 22; // bson_iter_int64(iter) - } else if (BSON_ITER_HOLDS_DOUBLE(iter)) { - bcol.Type = TYPE_DOUBLE; - bcol.Len = 12; - bcol.Scale = 6; // bson_iter_double(iter) - } else if (BSON_ITER_HOLDS_DATE_TIME(iter)) { - bcol.Type = TYPE_DATE; - bcol.Len = 19; // bson_iter_date_time(iter) - } else if (BSON_ITER_HOLDS_BOOL(iter)) { - bcol.Type = TYPE_TINY; - bcol.Len = 1; - } else if (BSON_ITER_HOLDS_OID(iter)) { - bcol.Type = TYPE_STRING; - bcol.Len = 24; // bson_iter_oid(iter) - } else if (BSON_ITER_HOLDS_DECIMAL128(iter)) { - bcol.Type = TYPE_DECIM; - bcol.Len = 32; // bson_iter_decimal128(iter, &dec) - } else if (BSON_ITER_HOLDS_DOCUMENT(iter)) { - if (lvl < 0) - continue; - else if (lvl <= k) { + switch (bson_iter_type(iter)) { + case BSON_TYPE_UTF8: bcol.Type = TYPE_STRING; - bcol.Len = 512; - } else { - bson_iter_t child; - - if (bson_iter_recurse(iter, &child)) - if (FindInDoc(g, &child, NULL, colname, fmt, k + 1, false)) - return true; - - newcol = false; - } // endif lvl - - } else if (BSON_ITER_HOLDS_ARRAY(iter)) { - if (lvl < 0) - continue; - else if (lvl <= k) { + bcol.Len = strlen(bson_iter_utf8(iter, NULL)); + break; + case BSON_TYPE_INT32: + bcol.Type = TYPE_INT; + bcol.Len = 11; // bson_iter_int32(iter) + break; + case BSON_TYPE_INT64: + bcol.Type = TYPE_BIGINT; + bcol.Len = 22; // bson_iter_int64(iter) + break; + case BSON_TYPE_DOUBLE: + bcol.Type = TYPE_DOUBLE; + bcol.Len = 12; + bcol.Scale = 6; // bson_iter_double(iter) + break; + case BSON_TYPE_DATE_TIME: + bcol.Type = TYPE_DATE; + bcol.Len = 19; // bson_iter_date_time(iter) + break; + case BSON_TYPE_BOOL: + bcol.Type = TYPE_TINY; + bcol.Len = 1; + break; + case BSON_TYPE_OID: bcol.Type = TYPE_STRING; - bcol.Len = 512; - } else { - bson_t *arr; - bson_iter_t itar; - const uint8_t *data = NULL; - uint32_t len = 0; - - bson_iter_array(iter, &len, &data); - arr = bson_new_from_data(data, len); - - if (FindInDoc(g, &itar, arr, colname, fmt, k + 1, !all)) - return true; + bcol.Len = 24; // bson_iter_oid(iter) + break; + case BSON_TYPE_DECIMAL128: + bcol.Type = TYPE_DECIM; + bcol.Len = 32; // bson_iter_decimal128(iter, &dec) + break; + case BSON_TYPE_DOCUMENT: + if (lvl < 0) + continue; + else if (lvl <= k) { + bcol.Type = TYPE_STRING; + bcol.Len = 512; + } else { + bson_iter_t child; + + if (bson_iter_recurse(iter, &child)) + if (FindInDoc(g, &child, NULL, colname, fmt, k + 1, false)) + return true; + + newcol = false; + } // endif lvl + + break; + case BSON_TYPE_ARRAY: + if (lvl < 0) + continue; + else if (lvl <= k) { + bcol.Type = TYPE_STRING; + bcol.Len = 512; + } else { + bson_t* arr; + bson_iter_t itar; + const uint8_t* data = NULL; + uint32_t len = 0; + + bson_iter_array(iter, &len, &data); + arr = bson_new_from_data(data, len); + + if (FindInDoc(g, &itar, arr, colname, fmt, k + 1, !all)) + return true; - newcol = false; - } // endif lvl + newcol = false; + } // endif lvl - } // endif's + break; + } // endswitch iter if (newcol) AddColumn(g, colname, fmt, k); @@ -178,6 +189,7 @@ TDBCMG::TDBCMG(MGODEF *tdp) : TDBEXT(tdp) Pcg.Coll_name = tdp->Tabname; Pcg.Options = tdp->Colist; Pcg.Filter = tdp->Filter; + Pcg.Line = NULL; Pcg.Pipe = tdp->Pipe && tdp->Colist != NULL; B = tdp->Base ? 1 : 0; } else { @@ -186,6 +198,7 @@ TDBCMG::TDBCMG(MGODEF *tdp) : TDBEXT(tdp) Pcg.Coll_name = NULL; Pcg.Options = NULL; Pcg.Filter = NULL; + Pcg.Line = NULL; Pcg.Pipe = false; B = 0; } // endif tdp @@ -381,7 +394,21 @@ MGOCOL::MGOCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) : EXTCOL(cdp, tdbp, cprec, i, "MGO") { Tmgp = (PTDBCMG)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp); - Jpath = cdp->GetFmt() ? cdp->GetFmt() : cdp->GetName(); + Sgfy = false; + + if ((Jpath = cdp->GetFmt())) { + int n = strlen(Jpath) - 1; + + if (Jpath[n] == '*') { + Jpath = PlugDup(g, cdp->GetFmt()); + if (Jpath[n - 1] == '.') n--; + Jpath[n] = 0; + Sgfy = true; + } // endif Jpath + + } else + Jpath = cdp->GetName(); + } // end of MGOCOL constructor /***********************************************************************/ @@ -392,6 +419,7 @@ MGOCOL::MGOCOL(MGOCOL *col1, PTDB tdbp) : EXTCOL(col1, tdbp) { Tmgp = col1->Tmgp; Jpath = col1->Jpath; + Sgfy = col1->Sgfy; } // end of MGOCOL copy constructor /***********************************************************************/ @@ -419,6 +447,9 @@ PSZ MGOCOL::GetJpath(PGLOBAL g, bool proj) } else *p2++ = *p1; + if (*(p2 - 1) == '.') + p2--; + *p2 = 0; return projpath; } else -- cgit v1.2.1 From ed70f76cf7cbe2195909c5e495a4b18347a7c58c Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 24 Jun 2021 00:46:12 +0200 Subject: - Make function strz return null when LEX_STRING is null modified: storage/connect/ha_connect.cc - Use NOTE instead of WARNING in connect_assisted_discovery This because MariaDB raise an error when doing so modified: storage/connect/ha_connect.cc modified: storage/connect/tabrest.cpp - Make MONGO tables recognize STRINGIFY and JsonAllPath modified: storage/connect/mongo.cpp modified: storage/connect/mongo.h modified: storage/connect/tabcmg.h modified: storage/connect/tabjmg.cpp modified: storage/connect/tabcmg.cpp modified: storage/connect/tabjmg.h - Fix OBJECT option for Pretty != 2 JSN and BSON tables Accept all syntaxes for the OBJECT option modified: storage/connect/tabbson.cpp modified: storage/connect/tabjson.cpp - Use my_snprintf in function xcurl (by vuvova) modified: storage/connect/tabrest.cpp - Format dates entered as integer when formatted modified: storage/connect/value.cpp modified: storage/connect/value.h --- storage/connect/tabcmg.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'storage/connect/tabcmg.cpp') diff --git a/storage/connect/tabcmg.cpp b/storage/connect/tabcmg.cpp index 1552bdde58a..608445bb1ab 100644 --- a/storage/connect/tabcmg.cpp +++ b/storage/connect/tabcmg.cpp @@ -1,5 +1,5 @@ /************** tabcmg C++ Program Source Code File (.CPP) *************/ -/* PROGRAM NAME: tabcmg Version 1.2 */ +/* PROGRAM NAME: tabcmg Version 1.3 */ /* (C) Copyright to the author Olivier BERTRAND 2017 - 2021 */ /* This program are the C MongoDB class DB execution routines. */ /***********************************************************************/ @@ -192,6 +192,7 @@ TDBCMG::TDBCMG(MGODEF *tdp) : TDBEXT(tdp) Pcg.Line = NULL; Pcg.Pipe = tdp->Pipe && tdp->Colist != NULL; B = tdp->Base ? 1 : 0; + Strfy = tdp->Strfy; } else { Pcg.Uristr = NULL; Pcg.Db_name = NULL; @@ -200,6 +201,7 @@ TDBCMG::TDBCMG(MGODEF *tdp) : TDBEXT(tdp) Pcg.Filter = NULL; Pcg.Line = NULL; Pcg.Pipe = false; + Strfy = NULL; B = 0; } // endif tdp @@ -213,6 +215,7 @@ TDBCMG::TDBCMG(TDBCMG *tdbp) : TDBEXT(tdbp) Cmgp = tdbp->Cmgp; Cnd = tdbp->Cnd; Pcg = tdbp->Pcg; + Strfy = tdbp->Strfy; B = tdbp->B; Fpos = tdbp->Fpos; N = tdbp->N; @@ -394,7 +397,7 @@ MGOCOL::MGOCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) : EXTCOL(cdp, tdbp, cprec, i, "MGO") { Tmgp = (PTDBCMG)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp); - Sgfy = false; + Sgfy = (Tmgp->Strfy && !stricmp(Tmgp->Strfy, Name)); if ((Jpath = cdp->GetFmt())) { int n = strlen(Jpath) - 1; -- cgit v1.2.1 From 0f18135ec8f90f5736829fb36cab3da9196fd09f Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sat, 24 Jul 2021 16:28:57 +0200 Subject: - Make user variable prefix recognized by IsArgJson and IsJson modified: storage/connect/bsonudf.cpp modified: storage/connect/jsonudf.cpp - Stringify option is now a ; separated list of columns modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/mongo.h modified: storage/connect/tabbson.cpp modified: storage/connect/tabcmg.cpp modified: storage/connect/tabcmg.h modified: storage/connect/tabjmg.cpp modified: storage/connect/tabjmg.h modified: storage/connect/tabjson.cpp - PrepareColist not a static function anymore (+ typo) modified: storage/connect/taboccur.cpp - JDVC: Recognize schema (database) from a wrapper server modified: storage/connect/tabjdbc.cpp --- storage/connect/tabcmg.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'storage/connect/tabcmg.cpp') diff --git a/storage/connect/tabcmg.cpp b/storage/connect/tabcmg.cpp index 608445bb1ab..56d705f42ca 100644 --- a/storage/connect/tabcmg.cpp +++ b/storage/connect/tabcmg.cpp @@ -27,6 +27,7 @@ #include "filter.h" PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info); +bool Stringified(PCSZ, char*); /* -------------------------- Class CMGDISC -------------------------- */ @@ -397,7 +398,7 @@ MGOCOL::MGOCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) : EXTCOL(cdp, tdbp, cprec, i, "MGO") { Tmgp = (PTDBCMG)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp); - Sgfy = (Tmgp->Strfy && !stricmp(Tmgp->Strfy, Name)); + Sgfy = Stringified(Tmgp->Strfy, Name); if ((Jpath = cdp->GetFmt())) { int n = strlen(Jpath) - 1; -- cgit v1.2.1