summaryrefslogtreecommitdiff
path: root/storage/connect
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2019-08-19 18:06:34 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2019-08-19 18:06:34 +0200
commitc0f9042500b5034b3f6fff96321dfa9eeb36957d (patch)
tree11ce4b5a6c5ccbb214577cf901267c82ec04bdcb /storage/connect
parent4d93c7f3b0bfc59da369702c2eca725f1e362305 (diff)
downloadmariadb-git-c0f9042500b5034b3f6fff96321dfa9eeb36957d.tar.gz
Some small changes.
=================== - Modify tracing to use htrc to be compatible with old versions when this code is used to make an EOM module. modified: storage/connect/restget.cpp modified: storage/connect/tabrest.cpp - Path apparently not needed for the cpprest lib on Linux modified: storage/connect/CMakeLists.txt
Diffstat (limited to 'storage/connect')
-rw-r--r--storage/connect/CMakeLists.txt4
-rw-r--r--storage/connect/restget.cpp25
-rw-r--r--storage/connect/tabrest.cpp43
3 files changed, 39 insertions, 33 deletions
diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt
index 6fd3b5e3018..fd006e104c1 100644
--- a/storage/connect/CMakeLists.txt
+++ b/storage/connect/CMakeLists.txt
@@ -321,8 +321,8 @@ IF(CONNECT_WITH_REST)
MESSAGE(STATUS "=====> cpprestsdk found")
IF(UNIX)
# INCLUDE_DIRECTORIES(${CPPRESTSDK_INCLUDE_DIR})
-# Edit next line to set the path to libcpprest.so
- SET(REST_LIBRARY -L/usr/lib64 -lcpprest)
+# If needed edit next line to set the path to libcpprest.so
+ SET(REST_LIBRARY -lcpprest)
MESSAGE (STATUS ${REST_LIBRARY})
ENDIF(UNIX)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h)
diff --git a/storage/connect/restget.cpp b/storage/connect/restget.cpp
index d5ceb7b8a39..6b184ae6926 100644
--- a/storage/connect/restget.cpp
+++ b/storage/connect/restget.cpp
@@ -19,14 +19,13 @@ using namespace concurrency::streams; // Asynchronous streams
#include "global.h"
-static uint xt = 0; // Used by lamda expressions
-
/***********************************************************************/
/* Make a local copy of the requested file. */
/***********************************************************************/
int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
{
int rc = 0;
+ bool xt = trace(515);
auto fileStream = std::make_shared<ostream>();
if (!http || !fn) {
@@ -34,15 +33,15 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
return 2;
} // endif
- xt = GetTraceValue();
- xtrc(515, "restGetFile: fn=%s\n", fn);
+ if (xt)
+ htrc("restGetFile: fn=%s\n", fn);
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(to_string_t(fn))
.then([=](ostream outFile) {
*fileStream= outFile;
- if (xt & 515)
+ if (xt)
htrc("Outfile isopen=%d\n", outFile.is_open());
// Create http_client to send the request.
@@ -58,7 +57,7 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
// Handle response headers arriving.
.then([=](http_response response) {
- if (xt & 515)
+ if (xt)
htrc("Received response status code:%u\n",
response.status_code());
@@ -68,7 +67,7 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
// Close the file stream.
.then([=](size_t n) {
- if (xt & 515)
+ if (xt)
htrc("Return size=%u\n", n);
return fileStream->close();
@@ -77,13 +76,19 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
// Wait for all the outstanding I/O to complete and handle any exceptions
try {
requestTask.wait();
- xtrc(515, "In Wait\n");
+
+ if (xt)
+ htrc("In Wait\n");
+
} catch (const std::exception &e) {
- xtrc(515, "Error exception: %s\n", e.what());
+ if (xt)
+ htrc("Error exception: %s\n", e.what());
sprintf(g->Message, "Error exception: %s", e.what());
rc= 1;
} // end try/catch
- xtrc(515, "restget done: rc=%d\n", rc);
+ if (xt)
+ htrc("restget done: rc=%d\n", rc);
+
return rc;
} // end of restGetFile
diff --git a/storage/connect/tabrest.cpp b/storage/connect/tabrest.cpp
index eef90f0dc1d..9e1a643c89f 100644
--- a/storage/connect/tabrest.cpp
+++ b/storage/connect/tabrest.cpp
@@ -92,10 +92,10 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
uri = GetStringTableOption(g, tp, "Uri", NULL);
fn = GetStringTableOption(g, tp, "Filename", "rest.json");
#if defined(MARIADB)
- ftype = GetStringTableOption(g, tp, "Type", "JSON");
+ ftype = GetStringTableOption(g, tp, "Type", "JSON");
#else // !MARIADB
- // OEM tables must specify the file type
- ftype = GetStringTableOption(g, tp, "Ftype", "JSON");
+ // OEM tables must specify the file type
+ ftype = GetStringTableOption(g, tp, "Ftype", "JSON");
#endif // !MARIADB
// We used the file name relative to recorded datapath
@@ -126,21 +126,21 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
char filename[_MAX_PATH + 1];
int rc = 0, n;
- LPCSTR ftype;
+ LPCSTR ftype;
#if defined(MARIADB)
- ftype = GetStringCatInfo(g, "Type", "JSON");
+ ftype = GetStringCatInfo(g, "Type", "JSON");
#else // !MARIADB
// OEM tables must specify the file type
ftype = GetStringCatInfo(g, "Ftype", "JSON");
#endif // !MARIADB
- if (trace(1))
- htrc("ftype = %s am = %s\n", ftype, SVP(am));
+ if (trace(515))
+ htrc("ftype = %s am = %s\n", ftype, SVP(am));
- n = (!stricmp(ftype, "JSON")) ? 1
- : (!stricmp(ftype, "XML")) ? 2
- : (!stricmp(ftype, "CSV")) ? 3 : 0;
+ n = (!stricmp(ftype, "JSON")) ? 1
+ : (!stricmp(ftype, "XML")) ? 2
+ : (!stricmp(ftype, "CSV")) ? 3 : 0;
if (n == 0) {
htrc("DefineAM: Unsupported REST table type %s", am);
@@ -159,24 +159,24 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
// Retrieve the file from the web and copy it locally
rc = restGetFile(g, Http, Uri, filename);
- if (trace(1))
- htrc("Return from restGetFile: rc=%d\n", rc);
+ if (trace(515))
+ htrc("Return from restGetFile: rc=%d\n", rc);
if (rc)
return true;
- else switch (n) {
- case 1: Tdp = new (g) JSONDEF; break;
- case 2: Tdp = new (g) XMLDEF; break;
- case 3: Tdp = new (g) CSVDEF; break;
- default: Tdp = NULL;
- } // endswitch n
+ else switch (n) {
+ case 1: Tdp = new (g) JSONDEF; break;
+ case 2: Tdp = new (g) XMLDEF; break;
+ case 3: Tdp = new (g) CSVDEF; break;
+ default: Tdp = NULL;
+ } // endswitch n
// Do make the table/view definition
if (Tdp && Tdp->Define(g, Cat, Name, Schema, "REST"))
Tdp = NULL; // Error occured
- if (trace(1))
- htrc("Tdp defined\n", rc);
+ if (trace(515))
+ htrc("Tdp defined\n", rc);
// Return true in case of error
return (Tdp == NULL);
@@ -187,7 +187,8 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
/***********************************************************************/
PTDB RESTDEF::GetTable(PGLOBAL g, MODE m)
{
- xtrc(515, "REST GetTable mode=%d\n", m);
+ if (trace(515))
+ htrc("REST GetTable mode=%d\n", m);
if (m != MODE_READ && m != MODE_READX) {
strcpy(g->Message, "REST tables are currently read only");