summaryrefslogtreecommitdiff
path: root/storage/connect/restget.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2019-07-30 22:45:04 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2019-07-30 22:45:04 +0200
commite4797a991f7597892608e9327adfc1ca7841e62d (patch)
tree53d855c91c20c50889a24c275fb7151376cd0b70 /storage/connect/restget.cpp
parent4e583a276fa0efe67f0185604b062668db707af0 (diff)
downloadmariadb-git-e4797a991f7597892608e9327adfc1ca7841e62d.tar.gz
In CONNECT version 1.6.10 NOSQL facility is enhanced by a new way to retrieve NOSQL data.
In addition to files and Mongo collections, JSON as well as XML and CSV data can be retrieved from the net as answers from REST queries. Because it uses and external package (cpprestsdk) this is currently available only to MariaDB servers compiled from source. -- Add the REST support when Microsoft Casablanca package (cpprestsdk) is installed. -- Also include some changes specific to MariaDB 10.3. modified: storage/connect/CMakeLists.txt -- Add conditional REST support -- Added string options HTTP and URI. -- Added added internal table type TAB_REST. modified: storage/connect/ha_connect.cc modified: storage/connect/mycat.cc modified: storage/connect/mycat.h modified: storage/connect/plgdbsem.h -- Fix MDEV-19648 Variable connect_conv_size doesn't change -- Change Variable wrong block parameter from 8169 to 1. -- Also change connect_conv_size default value to 1024. modified: storage/connect/ha_connect.cc -- Avoid possible buffer overflow -- In particular by the function ShowValue. modified: storage/connect/tabdos.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/value.cpp modified: storage/connect/value.h -- Add some cast to avoid some compiler warnings modified: storage/connect/filamdbf.cpp -- Fix some C++ error modified: storage/connect/javaconn.cpp modified: storage/connect/jmgoconn.cpp modified: storage/connect/plugutil.cpp -- Miscellaneous Typo and warning suppressing changes modified: storage/connect/connect.cpp modified: storage/connect/connect.h modified: storage/connect/filamvct.cpp modified: storage/connect/inihandl.cpp modified: storage/connect/jsonudf.cpp modified: storage/connect/libdoc.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/user_connect.cc modified: storage/connect/user_connect.h -- Update failing test results and disbling modified: storage/connect/mysql-test/connect/disabled.def modified: storage/connect/mysql-test/connect/r/dir.result modified: storage/connect/mysql-test/connect/r/grant.result modified: storage/connect/mysql-test/connect/r/jdbc.result modified: storage/connect/mysql-test/connect/r/jdbc_postgresql.result modified: storage/connect/mysql-test/connect/r/xml.result modified: storage/connect/mysql-test/connect/r/xml2.result modified: storage/connect/mysql-test/connect/r/xml2_mult.result modified: storage/connect/mysql-test/connect/r/xml_mult.result -- Add an option modified: storage/connect/mysql-test/connect/t/grant.test
Diffstat (limited to 'storage/connect/restget.cpp')
-rw-r--r--storage/connect/restget.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/storage/connect/restget.cpp b/storage/connect/restget.cpp
new file mode 100644
index 00000000000..955e5f97fbc
--- /dev/null
+++ b/storage/connect/restget.cpp
@@ -0,0 +1,87 @@
+/************* Restget C++ Program Source Code File (.CPP) *************/
+/* Adapted from the sample program of the Casablanca tutorial. */
+/* Copyright Olivier Bertrand 2019. */
+/***********************************************************************/
+#include <cpprest/filestream.h>
+#include <cpprest/http_client.h>
+#if defined(MARIADB)
+#include <my_global.h>
+#else
+#include "mini_global.h"
+#endif
+
+using namespace utility::conversions; // String conversions utilities
+using namespace web; // Common features like URIs.
+using namespace web::http; // Common HTTP functionality
+using namespace web::http::client; // HTTP client features
+using namespace concurrency::streams; // Asynchronous streams
+
+#include "global.h"
+
+
+/***********************************************************************/
+/* Make a local copy of the requested file. */
+/***********************************************************************/
+int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
+{
+ int rc= 0;
+ auto fileStream= std::make_shared<ostream>();
+
+ if (!http || !fn) {
+ strcpy(g->Message, "Missing http or filename");
+ return 2;
+ } // endif
+
+ //std::string sfn(fn);
+ //auto wfn= to_string_t(sfn);
+ //rc= 0;
+
+ // Open stream to output file.
+ pplx::task<void> requestTask=
+ fstream::open_ostream(to_string_t(fn))
+ .then([=](ostream outFile) {
+ *fileStream= outFile;
+
+ // Create http_client to send the request.
+ http_client client(to_string_t(http));
+
+ if (uri)
+ {
+ // Build request URI and start the request.
+ uri_builder builder(to_string_t(uri));
+ return client.request(methods::GET, builder.to_string());
+ }
+ else
+ return client.request(methods::GET);
+ })
+
+ // Handle response headers arriving.
+ .then([=](http_response response) {
+#if defined(DEVELOPMENT)
+ fprintf(stderr, "Received response status code:%u\n",
+ response.status_code());
+#endif // DEVELOPMENT
+
+ // Write response body into the file.
+ return response.body().read_to_end(fileStream->streambuf());
+ })
+
+ // Close the file stream.
+ .then([=](size_t) { return fileStream->close(); });
+
+ // Wait for all the outstanding I/O to complete and handle any exceptions
+ try
+ {
+ requestTask.wait();
+ }
+ catch (const std::exception &e)
+ {
+#if defined(DEVELOPMENT)
+ fprintf(stderr, "Error exception: %s\n", e.what());
+#endif // DEVELOPMENT
+ sprintf(g->Message, "Error exception: %s", e.what());
+ rc= 1;
+ } // end try/catch
+
+ return rc;
+} // end of restGetFile \ No newline at end of file