Commit e4797a99 authored by Olivier Bertrand's avatar Olivier Bertrand

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
parent 4e583a27
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
SET(CONNECT_PLUGIN_STATIC "connect") SET(CONNECT_PLUGIN_STATIC "connect")
SET(CONNECT_PLUGIN_DYNAMIC "connect") SET(CONNECT_PLUGIN_DYNAMIC "connect")
...@@ -69,6 +69,10 @@ ELSE(NOT UNIX) ...@@ -69,6 +69,10 @@ ELSE(NOT UNIX)
# Add exception handling to the CONNECT project) # Add exception handling to the CONNECT project)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
SET(IPHLPAPI_LIBRARY iphlpapi.lib) SET(IPHLPAPI_LIBRARY iphlpapi.lib)
IF(MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES Clang))
# Connect does not work with clang-cl
RETURN()
ENDIF()
ENDIF(UNIX) ENDIF(UNIX)
...@@ -109,7 +113,6 @@ IF(CONNECT_WITH_LIBXML2) ...@@ -109,7 +113,6 @@ IF(CONNECT_WITH_LIBXML2)
FIND_PACKAGE(LibXml2) FIND_PACKAGE(LibXml2)
IF (LIBXML2_FOUND) IF (LIBXML2_FOUND)
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
SET(ZLIB_LIBRARY "z") # see ZLIB_INCLUDE_DIR below
SET(XML_LIBRARY ${LIBXML2_LIBRARIES}) SET(XML_LIBRARY ${LIBXML2_LIBRARIES})
SET(CONNECT_SOURCES ${CONNECT_SOURCES} libdoc.cpp libdoc.h) SET(CONNECT_SOURCES ${CONNECT_SOURCES} libdoc.cpp libdoc.h)
add_definitions(-DLIBXML2_SUPPORT) add_definitions(-DLIBXML2_SUPPORT)
...@@ -301,6 +304,24 @@ IF(CONNECT_WITH_MONGO) ...@@ -301,6 +304,24 @@ IF(CONNECT_WITH_MONGO)
ENDIF(CONNECT_WITH_MONGO) ENDIF(CONNECT_WITH_MONGO)
#
# REST
#
OPTION(CONNECT_WITH_REST "Compile CONNECT storage engine with REST support" ON)
IF(CONNECT_WITH_REST)
MESSAGE(STATUS "=====> REST support is ON")
FIND_PACKAGE(cpprestsdk)
IF (cpprestsdk_FOUND)
MESSAGE(STATUS "=====> cpprestsdk found")
SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h)
add_definitions(-DREST_SUPPORT)
ELSE(NOT cpprestsdk_FOUND)
MESSAGE(STATUS "=====> cpprestsdk package not found")
ENDIF (cpprestsdk_FOUND)
ENDIF(CONNECT_WITH_REST)
# #
# XMAP # XMAP
# #
...@@ -326,14 +347,6 @@ IF(NOT TARGET connect) ...@@ -326,14 +347,6 @@ IF(NOT TARGET connect)
RETURN() RETURN()
ENDIF() ENDIF()
# Don't link with bundled zlib and systel libxml2 at the same time.
# System libxml2 uses system zlib, might conflict with the bundled one.
IF (XML_LIBRARY AND BUILD_BUNDLED_ZLIB)
GET_PROPERTY(INCS TARGET connect PROPERTY INCLUDE_DIRECTORIES)
LIST(REMOVE_ITEM INCS ${ZLIB_INCLUDE_DIR})
SET_PROPERTY(TARGET connect PROPERTY INCLUDE_DIRECTORIES ${INCS})
ENDIF()
IF(WIN32) IF(WIN32)
IF (libmongoc-1.0_FOUND) IF (libmongoc-1.0_FOUND)
SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/**************** Cnt H Declares Source Code File (.H) *****************/ /**************** Cnt H Declares Source Code File (.H) *****************/
/* Name: CONNECT.H Version 2.4 */ /* Name: CONNECT.H Version 2.4 */
......
This diff is collapsed.
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/** @file ha_connect.h /** @file ha_connect.h
Author Olivier Bertrand Author Olivier Bertrand
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
/****************************************************************************/ /****************************************************************************/
#include "mycat.h" #include "mycat.h"
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
bool MongoEnabled(void);
#endif // JAVA_SUPPORT || CMGO_SUPPORT
/****************************************************************************/ /****************************************************************************/
/* Structures used to pass info between CONNECT and ha_connect. */ /* Structures used to pass info between CONNECT and ha_connect. */
/****************************************************************************/ /****************************************************************************/
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include "my_global.h" #include "my_global.h"
...@@ -194,7 +194,7 @@ static void PROFILE_Save( FILE *file, PROFILESECTION *section ) ...@@ -194,7 +194,7 @@ static void PROFILE_Save( FILE *file, PROFILESECTION *section )
} }
for (key = section->key; key; key = key->next) for (key = section->key; key; key = key->next)
if (key->name[0]) { if (key->name && key->name[0]) {
fprintf(file, "%s", SVP(key->name)); fprintf(file, "%s", SVP(key->name));
if (key->value) if (key->value)
......
...@@ -272,7 +272,7 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, ...@@ -272,7 +272,7 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options,
if (MakeSelector(g, filp, s)) { if (MakeSelector(g, filp, s)) {
strcpy(g->Message, "Failed making selector"); strcpy(g->Message, "Failed making selector");
return NULL; return true;
} else } else
s->Append('}'); s->Append('}');
...@@ -340,7 +340,7 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, ...@@ -340,7 +340,7 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options,
if (MakeSelector(g, filp, s)) { if (MakeSelector(g, filp, s)) {
strcpy(g->Message, "Failed making selector"); strcpy(g->Message, "Failed making selector");
return NULL; return true;
} // endif Selector } // endif Selector
tdbp->SetFilter(NULL); // Not needed anymore tdbp->SetFilter(NULL); // Not needed anymore
...@@ -813,4 +813,3 @@ PSZ JMgoConn::GetColumnValue(PSZ path) ...@@ -813,4 +813,3 @@ PSZ JMgoConn::GetColumnValue(PSZ path)
return fld; return fld;
} // end of GetColumnValue } // end of GetColumnValue
/****************** jsonudf C++ Program Source Code File (.CPP) ******************/ /****************** jsonudf C++ Program Source Code File (.CPP) ******************/
/* PROGRAM NAME: jsonudf Version 1.7 */ /* PROGRAM NAME: jsonudf Version 1.8 */
/* (C) Copyright to the author Olivier BERTRAND 2015-2018 */ /* (C) Copyright to the author Olivier BERTRAND 2015-2019 */
/* This program are the JSON User Defined Functions . */ /* This program are the JSON User Defined Functions . */
/*********************************************************************************/ /*********************************************************************************/
...@@ -1686,7 +1686,7 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) ...@@ -1686,7 +1686,7 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i)
} // endif *s } // endif *s
if (n < 1) if (n < 1)
return "Key"; return (PCSZ) "Key";
if (!b) { if (!b) {
if ((p = (PSZ)PlgDBSubAlloc(g, NULL, n + 1))) { if ((p = (PSZ)PlgDBSubAlloc(g, NULL, n + 1))) {
...@@ -1703,7 +1703,7 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) ...@@ -1703,7 +1703,7 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i)
return s; return s;
} // endif count } // endif count
return "Key"; return (PCSZ) "Key";
} // end of MakeKey } // end of MakeKey
/*********************************************************************************/ /*********************************************************************************/
......
...@@ -1035,7 +1035,7 @@ PXNODE XML2NODE::AddChildNode(PGLOBAL g, PCSZ name, PXNODE np) ...@@ -1035,7 +1035,7 @@ PXNODE XML2NODE::AddChildNode(PGLOBAL g, PCSZ name, PXNODE np)
// If name has the format m[n] only m is taken as node name // If name has the format m[n] only m is taken as node name
if ((p = strchr(pn, '['))) if ((p = strchr(pn, '[')))
p = BufAlloc(g, pn, p - pn); p = BufAlloc(g, pn, int(p - pn));
else else
p = pn; p = pn;
......
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/*************** Mycat CC Program Source Code File (.CC) ***************/ /*************** Mycat CC Program Source Code File (.CC) ***************/
/* PROGRAM NAME: MYCAT */ /* PROGRAM NAME: MYCAT */
/* ------------- */ /* ------------- */
/* Version 1.6 */ /* Version 1.7 */
/* */ /* */
/* Author: Olivier Bertrand 2012 - 2018 */ /* Author: Olivier Bertrand 2012 - 2019 */
/* */ /* */
/* WHAT THIS PROGRAM DOES: */ /* WHAT THIS PROGRAM DOES: */
/* ----------------------- */ /* ----------------------- */
...@@ -93,6 +93,9 @@ ...@@ -93,6 +93,9 @@
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
#include "tabzip.h" #include "tabzip.h"
#endif // ZIP_SUPPORT #endif // ZIP_SUPPORT
#if defined(REST_SUPPORT)
#include "tabrest.h"
#endif // REST_SUPPORT
#include "mycat.h" #include "mycat.h"
/***********************************************************************/ /***********************************************************************/
...@@ -160,7 +163,7 @@ TABTYPE GetTypeID(const char *type) ...@@ -160,7 +163,7 @@ TABTYPE GetTypeID(const char *type)
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
: (!stricmp(type, "ZIP")) ? TAB_ZIP : (!stricmp(type, "ZIP")) ? TAB_ZIP
#endif #endif
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY; : (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
} // end of GetTypeID } // end of GetTypeID
/***********************************************************************/ /***********************************************************************/
...@@ -181,6 +184,7 @@ bool IsFileType(TABTYPE type) ...@@ -181,6 +184,7 @@ bool IsFileType(TABTYPE type)
case TAB_INI: case TAB_INI:
case TAB_VEC: case TAB_VEC:
case TAB_JSON: case TAB_JSON:
case TAB_REST:
// case TAB_ZIP: // case TAB_ZIP:
isfile= true; isfile= true;
break; break;
...@@ -488,8 +492,8 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep, ...@@ -488,8 +492,8 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
printf("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type)); printf("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type));
// If not specified get the type of this table // If not specified get the type of this table
if (!type) //if (!type)
type= Hc->GetStringOption("Type","*"); // type= Hc->GetStringOption("Type","*");
return MakeTableDesc(g, tablep, type); return MakeTableDesc(g, tablep, type);
} // end of GetTableDesc } // end of GetTableDesc
...@@ -501,8 +505,8 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep, ...@@ -501,8 +505,8 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
{ {
TABTYPE tc; TABTYPE tc;
LPCSTR name = (PSZ)PlugDup(g, tablep->GetName()); LPCSTR name= (PSZ)PlugDup(g, tablep->GetName());
LPCSTR schema = (PSZ)PlugDup(g, tablep->GetSchema()); LPCSTR schema= (PSZ)PlugDup(g, tablep->GetSchema());
PRELDEF tdp= NULL; PRELDEF tdp= NULL;
if (trace(1)) if (trace(1))
...@@ -512,7 +516,11 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) ...@@ -512,7 +516,11 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
/*********************************************************************/ /*********************************************************************/
/* Get a unique enum identifier for types. */ /* Get a unique enum identifier for types. */
/*********************************************************************/ /*********************************************************************/
tc= GetTypeID(am); if (!am) {
tc = Hc->GetRealType();
am = Hc->GetStringOption("Type", "*");
} else
tc = GetTypeID(am);
switch (tc) { switch (tc) {
case TAB_FIX: case TAB_FIX:
...@@ -549,8 +557,11 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) ...@@ -549,8 +557,11 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
case TAB_VIR: tdp= new(g) VIRDEF; break; case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break; case TAB_JSON: tdp= new(g) JSONDEF; break;
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
case TAB_ZIP: tdp = new(g) ZIPDEF; break; case TAB_ZIP: tdp= new(g) ZIPDEF; break;
#endif // ZIP_SUPPORT #endif // ZIP_SUPPORT
#if defined(REST_SUPPORT)
case TAB_REST: tdp= new(g) RESTDEF; break;
#endif // REST_SUPPORT
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
case TAB_MONGO: case TAB_MONGO:
if (MongoEnabled()) { if (MongoEnabled()) {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/**************** MYCAT H Declares Source Code File (.H) ***************/ /**************** MYCAT H Declares Source Code File (.H) ***************/
/* Name: MYCAT.H Version 2.3 */ /* Name: MYCAT.H Version 2.3 */
...@@ -50,7 +50,9 @@ struct ha_table_option_struct { ...@@ -50,7 +50,9 @@ struct ha_table_option_struct {
const char *filter; const char *filter;
const char *oplist; const char *oplist;
const char *data_charset; const char *data_charset;
ulonglong lrecl; const char *http;
const char *uri;
ulonglong lrecl;
ulonglong elements; ulonglong elements;
//ulonglong estimate; //ulonglong estimate;
ulonglong multiple; ulonglong multiple;
......
...@@ -82,7 +82,8 @@ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */ ...@@ -82,7 +82,8 @@ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */
TAB_JDBC = 26, /* Table accessed via JDBC */ TAB_JDBC = 26, /* Table accessed via JDBC */
TAB_ZIP = 27, /* ZIP file info table */ TAB_ZIP = 27, /* ZIP file info table */
TAB_MONGO = 28, /* Table retrieved from MongoDB */ TAB_MONGO = 28, /* Table retrieved from MongoDB */
TAB_NIY = 30}; /* Table not implemented yet */ TAB_REST = 29, /* Table retrieved from Rest query */
TAB_NIY = 30}; /* Table not implemented yet */
enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */ enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_ROWID = 1, /* ROWID type (special column) */ TYPE_AM_ROWID = 1, /* ROWID type (special column) */
...@@ -400,6 +401,7 @@ typedef class VCTDEF *PVCTDEF; ...@@ -400,6 +401,7 @@ typedef class VCTDEF *PVCTDEF;
typedef class PIVOTDEF *PPIVOTDEF; typedef class PIVOTDEF *PPIVOTDEF;
typedef class DOMDEF *PDOMDEF; typedef class DOMDEF *PDOMDEF;
typedef class DIRDEF *PDIRDEF; typedef class DIRDEF *PDIRDEF;
typedef class RESTDEF *PRESTDEF;
typedef class OEMDEF *POEMDEF; typedef class OEMDEF *POEMDEF;
typedef class COLCRT *PCOLCRT; typedef class COLCRT *PCOLCRT;
typedef class COLDEF *PCOLDEF; typedef class COLDEF *PCOLDEF;
......
/************* 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
...@@ -641,7 +641,9 @@ bool TDBJDBC::OpenDB(PGLOBAL g) ...@@ -641,7 +641,9 @@ bool TDBJDBC::OpenDB(PGLOBAL g)
Cnp->InitValue(g); Cnp->InitValue(g);
if ((n = Jcp->GetResultSize(Query->GetStr(), Cnp)) < 0) { if ((n = Jcp->GetResultSize(Query->GetStr(), Cnp)) < 0) {
sprintf(g->Message, "Cannot get result size rc=%d", n); char* msg = PlugDup(g, g->Message);
sprintf(g->Message, "Get result size: %s (rc=%d)", msg, n);
return true; return true;
} else if (n) { } else if (n) {
Jcp->m_Rows = n; Jcp->m_Rows = n;
......
...@@ -572,7 +572,7 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -572,7 +572,7 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Sep = *GetStringCatInfo(g, "Separator", "."); Sep = *GetStringCatInfo(g, "Separator", ".");
Accept = GetBoolCatInfo("Accept", false); Accept = GetBoolCatInfo("Accept", false);
// Don't use url as uri when called from REST OEM module // Don't use url as MONGO uri when called from REST
if (stricmp(am, "REST") && (Uri = GetStringCatInfo(g, "Connect", NULL))) { if (stricmp(am, "REST") && (Uri = GetStringCatInfo(g, "Connect", NULL))) {
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
Collname = GetStringCatInfo(g, "Name", Collname = GetStringCatInfo(g, "Name",
......
/*************** Rest C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: Rest Version 1.3 */
/* (C) Copyright to the author Olivier BERTRAND 2018 - 2019 */
/* This program is the REST OEM (Web API support) module definition. */
/***********************************************************************/
/***********************************************************************/
/* Definitions needed by the included files. */
/***********************************************************************/
#include <my_global.h> // All MariaDB stuff
/***********************************************************************/
/* Include application header files: */
/* global.h is header containing all global declarations. */
/* plgdbsem.h is header containing the DB application declarations. */
/* (x)table.h is header containing the TDBASE declarations. */
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
#include "xtable.h"
#include "filamtxt.h"
#include "plgxml.h"
#include "tabdos.h"
#include "tabfmt.h"
#include "tabjson.h"
#include "tabrest.h"
#include "tabxml.h"
/***********************************************************************/
/* Get the file from the Web. */
/***********************************************************************/
int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn);
#if defined(__WIN__)
static PCSZ slash= "\\";
#else // !__WIN__
static PCSZ slash= "/";
#define stricmp strcasecmp
#endif // !__WIN__
/***********************************************************************/
/* Return the columns definition to MariaDB. */
/***********************************************************************/
PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
{
PQRYRES qrp= NULL;
char filename[_MAX_PATH];
PCSZ http, uri, fn, ftype;
http= GetStringTableOption(g, tp, "Http", NULL);
uri= GetStringTableOption(g, tp, "Uri", NULL);
fn= GetStringTableOption(g, tp, "Filename", "rest.json");
ftype = GetStringTableOption(g, tp, "Type", "JSON");
// We used the file name relative to recorded datapath
strcat(strcat(strcat(strcpy(filename, "."), slash), db), slash);
strncat(filename, fn, _MAX_PATH);
// Retrieve the file from the web and copy it locally
if (http && restGetFile(g, http, uri, filename)) {
// sprintf(g->Message, "Failed to get file at %s", http);
} else if (!stricmp(ftype, "XML"))
qrp= XMLColumns(g, db, tab, tp, info);
else if (!stricmp(ftype, "JSON"))
qrp= JSONColumns(g, db, NULL, tp, info);
else if (!stricmp(ftype, "CSV"))
qrp= CSVColumns(g, NULL, tp, info);
else
sprintf(g->Message, "Usupported file type %s", ftype);
return qrp;
} // end of RESTColumns
/* -------------------------- Class RESTDEF -------------------------- */
/***********************************************************************/
/* DefineAM: define specific AM block values. */
/***********************************************************************/
bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
char filename[_MAX_PATH];
TABTYPE type= GetTypeID(am);
switch (type) {
case TAB_JSON:
case TAB_XML:
case TAB_CSV:
break;
default:
sprintf(g->Message, "Unsupported REST table type %s", am);
return true;
} // endswitch type
Http= GetStringCatInfo(g, "Http", NULL);
Uri= GetStringCatInfo(g, "Uri", NULL);
Fn= GetStringCatInfo(g, "Filename", "rest.json");
// We used the file name relative to recorded datapath
PlugSetPath(filename, Fn, GetPath());
// Retrieve the file from the web and copy it locally
if (Http && restGetFile(g, Http, Uri, filename)) {}
else if (type == TAB_JSON)
Tdp= new (g) JSONDEF;
else if (type == TAB_XML)
Tdp= new (g) XMLDEF;
else if (type == TAB_CSV)
Tdp= new (g) CSVDEF;
else
sprintf(g->Message, "Unsupported REST table type %s", am);
// Do make the table/view definition
if (Tdp && Tdp->Define(g, Cat, Name, Schema, "REST"))
Tdp= NULL; // Error occured
// Return true in case of error
return (Tdp == NULL);
} // end of DefineAM
/***********************************************************************/
/* GetTable: makes a new Table Description Block. */
/***********************************************************************/
PTDB RESTDEF::GetTable(PGLOBAL g, MODE m)
{
if (m != MODE_READ && m != MODE_READX) {
strcpy(g->Message, "REST tables are currently read only");
return NULL;
} // endif m
return Tdp->GetTable(g, m); // Leave file type do the job
} // end of GetTable
/* ---------------------- End of Class RESTDEF ----------------------- */
/*************** TabRest H Declares Source Code File (.H) **************/
/* Name: tabrest.h Version 1.0 */
/* (C) Copyright to the author Olivier BERTRAND 2019 */
/* This file contains the common tabrest classes declares. */
/***********************************************************************/
#pragma once
/***********************************************************************/
/* Restest table. */
/***********************************************************************/
class RESTDEF : public TABDEF { /* Table description */
public:
// Constructor
RESTDEF(void) { Tdp = NULL; Http = Uri = Fn = NULL; }
// Implementation
virtual const char *GetType(void) { return "REST"; }
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE m);
protected:
// Members
PRELDEF Tdp;
PCSZ Http; /* Web connection HTTP */
PCSZ Uri; /* Web connection URI */
PCSZ Fn; /* The intermediate file name */
}; // end of class RESTDEF
...@@ -232,7 +232,7 @@ bool TDBTBL::InitTableList(PGLOBAL g) ...@@ -232,7 +232,7 @@ bool TDBTBL::InitTableList(PGLOBAL g)
{ {
int n; int n;
uint sln; uint sln;
char *scs; const char *scs;
PTABLE tp, tabp; PTABLE tp, tabp;
PCOL colp; PCOL colp;
PTBLDEF tdp = (PTBLDEF)To_Def; PTBLDEF tdp = (PTBLDEF)To_Def;
...@@ -281,7 +281,7 @@ bool TDBTBL::InitTableList(PGLOBAL g) ...@@ -281,7 +281,7 @@ bool TDBTBL::InitTableList(PGLOBAL g)
} // endfor tp } // endfor tp
hc->get_table()->s->connect_string.str = scs; hc->get_table()->s->connect_string.str = (char*)scs;
hc->get_table()->s->connect_string.length = sln; hc->get_table()->s->connect_string.length = sln;
//NumTables = n; //NumTables = n;
......
...@@ -1880,7 +1880,7 @@ void XMULCOL::ReadColumn(PGLOBAL g) ...@@ -1880,7 +1880,7 @@ void XMULCOL::ReadColumn(PGLOBAL g)
if (N > Tdbp->Limit) { if (N > Tdbp->Limit) {
N = Tdbp->Limit; N = Tdbp->Limit;
sprintf(g->Message, "Mutiple values limited to %d", Tdbp->Limit); sprintf(g->Message, "Multiple values limited to %d", Tdbp->Limit);
PushWarning(g, Tdbp); PushWarning(g, Tdbp);
} // endif N } // endif N
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/** /**
@file user_connect.cc @file user_connect.cc
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/** @file user_connect.h /** @file user_connect.h
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment