mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
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
This commit is contained in:
@@ -321,8 +321,8 @@ IF(CONNECT_WITH_REST)
|
|||||||
MESSAGE(STATUS "=====> cpprestsdk found")
|
MESSAGE(STATUS "=====> cpprestsdk found")
|
||||||
IF(UNIX)
|
IF(UNIX)
|
||||||
# INCLUDE_DIRECTORIES(${CPPRESTSDK_INCLUDE_DIR})
|
# INCLUDE_DIRECTORIES(${CPPRESTSDK_INCLUDE_DIR})
|
||||||
# Edit next line to set the path to libcpprest.so
|
# If needed edit next line to set the path to libcpprest.so
|
||||||
SET(REST_LIBRARY -L/usr/lib64 -lcpprest)
|
SET(REST_LIBRARY -lcpprest)
|
||||||
MESSAGE (STATUS ${REST_LIBRARY})
|
MESSAGE (STATUS ${REST_LIBRARY})
|
||||||
ENDIF(UNIX)
|
ENDIF(UNIX)
|
||||||
SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h)
|
SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h)
|
||||||
|
@@ -19,14 +19,13 @@ using namespace concurrency::streams; // Asynchronous streams
|
|||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
static uint xt = 0; // Used by lamda expressions
|
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
/* Make a local copy of the requested file. */
|
/* Make a local copy of the requested file. */
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
|
int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
bool xt = trace(515);
|
||||||
auto fileStream = std::make_shared<ostream>();
|
auto fileStream = std::make_shared<ostream>();
|
||||||
|
|
||||||
if (!http || !fn) {
|
if (!http || !fn) {
|
||||||
@@ -34,15 +33,15 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
|
|||||||
return 2;
|
return 2;
|
||||||
} // endif
|
} // endif
|
||||||
|
|
||||||
xt = GetTraceValue();
|
if (xt)
|
||||||
xtrc(515, "restGetFile: fn=%s\n", fn);
|
htrc("restGetFile: fn=%s\n", fn);
|
||||||
|
|
||||||
// Open stream to output file.
|
// Open stream to output file.
|
||||||
pplx::task<void> requestTask = fstream::open_ostream(to_string_t(fn))
|
pplx::task<void> requestTask = fstream::open_ostream(to_string_t(fn))
|
||||||
.then([=](ostream outFile) {
|
.then([=](ostream outFile) {
|
||||||
*fileStream= outFile;
|
*fileStream= outFile;
|
||||||
|
|
||||||
if (xt & 515)
|
if (xt)
|
||||||
htrc("Outfile isopen=%d\n", outFile.is_open());
|
htrc("Outfile isopen=%d\n", outFile.is_open());
|
||||||
|
|
||||||
// Create http_client to send the request.
|
// 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.
|
// Handle response headers arriving.
|
||||||
.then([=](http_response response) {
|
.then([=](http_response response) {
|
||||||
if (xt & 515)
|
if (xt)
|
||||||
htrc("Received response status code:%u\n",
|
htrc("Received response status code:%u\n",
|
||||||
response.status_code());
|
response.status_code());
|
||||||
|
|
||||||
@@ -68,7 +67,7 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
|
|||||||
|
|
||||||
// Close the file stream.
|
// Close the file stream.
|
||||||
.then([=](size_t n) {
|
.then([=](size_t n) {
|
||||||
if (xt & 515)
|
if (xt)
|
||||||
htrc("Return size=%u\n", n);
|
htrc("Return size=%u\n", n);
|
||||||
|
|
||||||
return fileStream->close();
|
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
|
// Wait for all the outstanding I/O to complete and handle any exceptions
|
||||||
try {
|
try {
|
||||||
requestTask.wait();
|
requestTask.wait();
|
||||||
xtrc(515, "In Wait\n");
|
|
||||||
|
if (xt)
|
||||||
|
htrc("In Wait\n");
|
||||||
|
|
||||||
} catch (const std::exception &e) {
|
} 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());
|
sprintf(g->Message, "Error exception: %s", e.what());
|
||||||
rc= 1;
|
rc= 1;
|
||||||
} // end try/catch
|
} // end try/catch
|
||||||
|
|
||||||
xtrc(515, "restget done: rc=%d\n", rc);
|
if (xt)
|
||||||
|
htrc("restget done: rc=%d\n", rc);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
} // end of restGetFile
|
} // end of restGetFile
|
||||||
|
@@ -92,10 +92,10 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
|
|||||||
uri = GetStringTableOption(g, tp, "Uri", NULL);
|
uri = GetStringTableOption(g, tp, "Uri", NULL);
|
||||||
fn = GetStringTableOption(g, tp, "Filename", "rest.json");
|
fn = GetStringTableOption(g, tp, "Filename", "rest.json");
|
||||||
#if defined(MARIADB)
|
#if defined(MARIADB)
|
||||||
ftype = GetStringTableOption(g, tp, "Type", "JSON");
|
ftype = GetStringTableOption(g, tp, "Type", "JSON");
|
||||||
#else // !MARIADB
|
#else // !MARIADB
|
||||||
// OEM tables must specify the file type
|
// OEM tables must specify the file type
|
||||||
ftype = GetStringTableOption(g, tp, "Ftype", "JSON");
|
ftype = GetStringTableOption(g, tp, "Ftype", "JSON");
|
||||||
#endif // !MARIADB
|
#endif // !MARIADB
|
||||||
|
|
||||||
// We used the file name relative to recorded datapath
|
// 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];
|
char filename[_MAX_PATH + 1];
|
||||||
int rc = 0, n;
|
int rc = 0, n;
|
||||||
LPCSTR ftype;
|
LPCSTR ftype;
|
||||||
|
|
||||||
#if defined(MARIADB)
|
#if defined(MARIADB)
|
||||||
ftype = GetStringCatInfo(g, "Type", "JSON");
|
ftype = GetStringCatInfo(g, "Type", "JSON");
|
||||||
#else // !MARIADB
|
#else // !MARIADB
|
||||||
// OEM tables must specify the file type
|
// OEM tables must specify the file type
|
||||||
ftype = GetStringCatInfo(g, "Ftype", "JSON");
|
ftype = GetStringCatInfo(g, "Ftype", "JSON");
|
||||||
#endif // !MARIADB
|
#endif // !MARIADB
|
||||||
|
|
||||||
if (trace(1))
|
if (trace(515))
|
||||||
htrc("ftype = %s am = %s\n", ftype, SVP(am));
|
htrc("ftype = %s am = %s\n", ftype, SVP(am));
|
||||||
|
|
||||||
n = (!stricmp(ftype, "JSON")) ? 1
|
n = (!stricmp(ftype, "JSON")) ? 1
|
||||||
: (!stricmp(ftype, "XML")) ? 2
|
: (!stricmp(ftype, "XML")) ? 2
|
||||||
: (!stricmp(ftype, "CSV")) ? 3 : 0;
|
: (!stricmp(ftype, "CSV")) ? 3 : 0;
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
htrc("DefineAM: Unsupported REST table type %s", am);
|
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
|
// Retrieve the file from the web and copy it locally
|
||||||
rc = restGetFile(g, Http, Uri, filename);
|
rc = restGetFile(g, Http, Uri, filename);
|
||||||
|
|
||||||
if (trace(1))
|
if (trace(515))
|
||||||
htrc("Return from restGetFile: rc=%d\n", rc);
|
htrc("Return from restGetFile: rc=%d\n", rc);
|
||||||
|
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return true;
|
||||||
else switch (n) {
|
else switch (n) {
|
||||||
case 1: Tdp = new (g) JSONDEF; break;
|
case 1: Tdp = new (g) JSONDEF; break;
|
||||||
case 2: Tdp = new (g) XMLDEF; break;
|
case 2: Tdp = new (g) XMLDEF; break;
|
||||||
case 3: Tdp = new (g) CSVDEF; break;
|
case 3: Tdp = new (g) CSVDEF; break;
|
||||||
default: Tdp = NULL;
|
default: Tdp = NULL;
|
||||||
} // endswitch n
|
} // endswitch n
|
||||||
|
|
||||||
// Do make the table/view definition
|
// Do make the table/view definition
|
||||||
if (Tdp && Tdp->Define(g, Cat, Name, Schema, "REST"))
|
if (Tdp && Tdp->Define(g, Cat, Name, Schema, "REST"))
|
||||||
Tdp = NULL; // Error occured
|
Tdp = NULL; // Error occured
|
||||||
|
|
||||||
if (trace(1))
|
if (trace(515))
|
||||||
htrc("Tdp defined\n", rc);
|
htrc("Tdp defined\n", rc);
|
||||||
|
|
||||||
// Return true in case of error
|
// Return true in case of error
|
||||||
return (Tdp == NULL);
|
return (Tdp == NULL);
|
||||||
@@ -187,7 +187,8 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
PTDB RESTDEF::GetTable(PGLOBAL g, MODE m)
|
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) {
|
if (m != MODE_READ && m != MODE_READX) {
|
||||||
strcpy(g->Message, "REST tables are currently read only");
|
strcpy(g->Message, "REST tables are currently read only");
|
||||||
|
Reference in New Issue
Block a user