summaryrefslogtreecommitdiff
path: root/storage/connect/cmgoconn.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2017-08-05 18:08:51 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2017-08-05 18:08:51 +0200
commitd8f99f165bf4f88cb9b0ccb0c58d8a129bf4f18c (patch)
tree230c5bcb4313827db5574673b72eb60d2d06c08e /storage/connect/cmgoconn.cpp
parentdf3fd420e5999b568993e7d3a9a372ec29bca7d0 (diff)
downloadmariadb-git-d8f99f165bf4f88cb9b0ccb0c58d8a129bf4f18c.tar.gz
- Add FBLOCK when opening ODBC, JSON and MONGO tables.
This to have automatic closing in case of thrown error. modified: storage/connect/cmgoconn.cpp modified: storage/connect/cmgoconn.h modified: storage/connect/filamzip.cpp modified: storage/connect/javaconn.cpp modified: storage/connect/javaconn.h modified: storage/connect/odbconn.cpp modified: storage/connect/odbconn.h modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp - Fix INCOL bug when inserting several lines to MONGO tables modified: storage/connect/cmgoconn.cpp modified: storage/connect/tabcmg.cpp modified: storage/connect/tabjmg.cpp - MONGO_SUPPORT is set for both MongoDB drivers CMGO_SUPPORT is set only when the C driver is available modified: storage/connect/CMakeLists.txt modified: storage/connect/filter.h modified: storage/connect/filter.h modified: storage/connect/ha_connect.cc modified: storage/connect/mongo.cpp modified: storage/connect/mycat.cc modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h - Separate enums JCATINFO and modified: storage/connect/javaconn.h modified: storage/connect/jdbconn.cpp - Fix crash when executing JDBC catfunc=driver modified: storage/connect/jdbconn.cpp - Report an error when the Mongo driver if explicitly specified and not supported. modified: storage/connect/mongo.cpp - Fix bug causing catalog JSON tables to fail modified: storage/connect/tabjson.cpp - Protect by mutex the Ready variable of the TBLTBM table type modified: storage/connect/tabtbl.cpp - Put testing of Thread TBL tables in a separate test With added case and modified old case that could avoid the test to fail. modified: storage/connect/mysql-test/connect/r/tbl.result modified: storage/connect/mysql-test/connect/t/tbl.test new file: storage/connect/mysql-test/connect/r/tbl_thread.result new file: storage/connect/mysql-test/connect/t/tbl_thread.test - jmongo3.test no more exists deleted: storage/connect/mysql-test/connect/t/jmongo3.test - Add new tests for the MONGO feature (disabled) modified: storage/connect/mysql-test/connect/disabled.def new file: storage/connect/mysql-test/connect/r/json_java_2.result new file: storage/connect/mysql-test/connect/r/json_java_3.result new file: storage/connect/mysql-test/connect/r/json_mongo_c.result new file: storage/connect/mysql-test/connect/r/mongo_c.result new file: storage/connect/mysql-test/connect/r/mongo_java_2.result new file: storage/connect/mysql-test/connect/r/mongo_java_3.result new file: storage/connect/mysql-test/connect/std_data/Mongo2.jar new file: storage/connect/mysql-test/connect/std_data/cities.json new file: storage/connect/mysql-test/connect/t/json_java_2.test new file: storage/connect/mysql-test/connect/t/json_java_3.test new file: storage/connect/mysql-test/connect/t/json_mongo_c.test new file: storage/connect/mysql-test/connect/t/mongo.inc new file: storage/connect/mysql-test/connect/t/mongo_c.test new file: storage/connect/mysql-test/connect/t/mongo_java_2.test new file: storage/connect/mysql-test/connect/t/mongo_java_3.test new file: storage/connect/mysql-test/connect/t/mongo_test.inc
Diffstat (limited to 'storage/connect/cmgoconn.cpp')
-rw-r--r--storage/connect/cmgoconn.cpp63
1 files changed, 55 insertions, 8 deletions
diff --git a/storage/connect/cmgoconn.cpp b/storage/connect/cmgoconn.cpp
index 8367708d4ac..fdd59040257 100644
--- a/storage/connect/cmgoconn.cpp
+++ b/storage/connect/cmgoconn.cpp
@@ -92,6 +92,32 @@ void INCOL::AddCol(PGLOBAL g, PCOL colp, char *jp)
} // end of AddCol
+/***********************************************************************/
+/* Clear. */
+/***********************************************************************/
+void INCOL::Init(void)
+{
+ bson_init(Child);
+
+ for (PKC kp = Klist; kp; kp = kp->Next)
+ if (kp->Incolp)
+ kp->Incolp->Init();
+
+} // end of init
+
+/***********************************************************************/
+/* Destroy. */
+/***********************************************************************/
+void INCOL::Destroy(void)
+{
+ bson_destroy(Child);
+
+ for (PKC kp = Klist; kp; kp = kp->Next)
+ if (kp->Incolp)
+ kp->Incolp->Destroy();
+
+} // end of Destroy
+
/* -------------------------- Class CMgoConn ------------------------- */
/***********************************************************************/
@@ -109,6 +135,7 @@ CMgoConn::CMgoConn(PGLOBAL g, PCPARM pcg)
Query = NULL;
Opts = NULL;
Fpc = NULL;
+ fp = NULL;
m_Connected = false;
} // end of CMgoConn standard constructor
@@ -149,6 +176,24 @@ bool CMgoConn::Connect(PGLOBAL g)
return true;
} // endif Collection
+ /*********************************************************************/
+ /* Link a Fblock. This make possible to automatically close it */
+ /* in case of error (throw). */
+ /*********************************************************************/
+ PDBUSER dbuserp = (PDBUSER)g->Activityp->Aptr;
+
+ fp = (PFBLOCK)PlugSubAlloc(g, NULL, sizeof(FBLOCK));
+ fp->Type = TYPE_FB_MONGO;
+ fp->Fname = NULL;
+ fp->Next = dbuserp->Openlist;
+ dbuserp->Openlist = fp;
+ fp->Count = 1;
+ fp->Length = 0;
+ fp->Memory = NULL;
+ fp->Mode = MODE_ANY;
+ fp->File = this;
+ fp->Handle = 0;
+
m_Connected = true;
return false;
} // end of Connect
@@ -493,19 +538,19 @@ bool CMgoConn::DocWrite(PGLOBAL g, PINCOL icp)
bool isdoc = !kp->Incolp->Array;
if (isdoc)
- BSON_APPEND_DOCUMENT_BEGIN(&icp->Child, kp->Key, &kp->Incolp->Child);
+ BSON_APPEND_DOCUMENT_BEGIN(icp->Child, kp->Key, kp->Incolp->Child);
else
- BSON_APPEND_ARRAY_BEGIN(&icp->Child, kp->Key, &kp->Incolp->Child);
+ BSON_APPEND_ARRAY_BEGIN(icp->Child, kp->Key, kp->Incolp->Child);
if (DocWrite(g, kp->Incolp))
return true;
if (isdoc)
- bson_append_document_end(&icp->Child, &kp->Incolp->Child);
+ bson_append_document_end(icp->Child, kp->Incolp->Child);
else
- bson_append_array_end(&icp->Child, &kp->Incolp->Child);
+ bson_append_array_end(icp->Child, kp->Incolp->Child);
- } else if (AddValue(g, kp->Colp, &icp->Child, kp->Key, false))
+ } else if (AddValue(g, kp->Colp, icp->Child, kp->Key, false))
return true;
return false;
@@ -520,19 +565,19 @@ int CMgoConn::Write(PGLOBAL g)
PTDB tp = Pcg->Tdbp;
if (tp->GetMode() == MODE_INSERT) {
- bson_init(&Fpc->Child);
+ Fpc->Init();
if (DocWrite(g, Fpc))
return RC_FX;
if (trace) {
- char *str = bson_as_json(&Fpc->Child, NULL);
+ char *str = bson_as_json(Fpc->Child, NULL);
htrc("Inserting: %s\n", str);
bson_free(str);
} // endif trace
if (!mongoc_collection_insert(Collection, MONGOC_INSERT_NONE,
- &Fpc->Child, NULL, &Error)) {
+ Fpc->Child, NULL, &Error)) {
sprintf(g->Message, "Mongo insert: %s", Error.message);
rc = RC_FX;
} // endif insert
@@ -641,6 +686,8 @@ void CMgoConn::Close(void)
if (Client) mongoc_client_pool_push(Pool, Client);
if (Pool) mongoc_client_pool_destroy(Pool);
if (Uri) mongoc_uri_destroy(Uri);
+ if (Fpc) Fpc->Destroy();
+ if (fp) fp->Count = 0;
} // end of Close
/***********************************************************************/