mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
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 compile flags needed on Windows /MD or /MDd (debug) -- Also include some changes needed on Linux modified: storage/connect/CMakeLists.txt - Add the xtrc tracing function modified: storage/connect/global.h modified: storage/connect/plugutil.cpp - Modify tracing to use xtrc and some typo modified: storage/connect/array.cpp modified: storage/connect/block.h modified: storage/connect/restget.cpp - Fix compilation error when ZIP is not supported modified: storage/connect/ha_connect.cc modified: storage/connect/tabfmt.cpp - Add some tracing + typo modified: storage/connect/mycat.cc modified: storage/connect/tabjson.cpp - Add conditional code based on MARIADB This to be able to use the same code in CONNECT and EOM modules modified: storage/connect/osutil.h modified: storage/connect/tabrest.cpp - Replace PlugSetPath by some concat (crashed on Fedora) + typo modified: storage/connect/reldef.cpp - Try to fix test failures modified: zlib/CMakeLists.txt
This commit is contained in:
@@ -68,6 +68,10 @@ ELSE(NOT UNIX)
|
|||||||
tabwmi.cpp tabwmi.h tabmac.cpp tabmac.h macutil.cpp macutil.h)
|
tabwmi.cpp tabwmi.h tabmac.cpp tabmac.h macutil.cpp macutil.h)
|
||||||
# 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(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
|
||||||
|
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
|
||||||
|
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD")
|
||||||
|
SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD")
|
||||||
SET(IPHLPAPI_LIBRARY iphlpapi.lib)
|
SET(IPHLPAPI_LIBRARY iphlpapi.lib)
|
||||||
IF(MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES Clang))
|
IF(MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES Clang))
|
||||||
# Connect does not work with clang-cl
|
# Connect does not work with clang-cl
|
||||||
@@ -315,6 +319,12 @@ IF(CONNECT_WITH_REST)
|
|||||||
FIND_PACKAGE(cpprestsdk)
|
FIND_PACKAGE(cpprestsdk)
|
||||||
IF (cpprestsdk_FOUND)
|
IF (cpprestsdk_FOUND)
|
||||||
MESSAGE(STATUS "=====> cpprestsdk found")
|
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)
|
||||||
|
MESSAGE (STATUS ${REST_LIBRARY})
|
||||||
|
ENDIF(UNIX)
|
||||||
SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h)
|
SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h)
|
||||||
add_definitions(-DREST_SUPPORT)
|
add_definitions(-DREST_SUPPORT)
|
||||||
ELSE(NOT cpprestsdk_FOUND)
|
ELSE(NOT cpprestsdk_FOUND)
|
||||||
@@ -341,7 +351,7 @@ MYSQL_ADD_PLUGIN(connect ${CONNECT_SOURCES}
|
|||||||
COMPONENT connect-engine
|
COMPONENT connect-engine
|
||||||
RECOMPILE_FOR_EMBEDDED
|
RECOMPILE_FOR_EMBEDDED
|
||||||
LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY}
|
LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY}
|
||||||
${ODBC_LIBRARY} ${JDBC_LIBRARY} ${MONGOC_LIBRARY} ${IPHLPAPI_LIBRARY})
|
${ODBC_LIBRARY} ${JDBC_LIBRARY} ${MONGOC_LIBRARY} ${IPHLPAPI_LIBRARY} ${REST_LIBRARY})
|
||||||
|
|
||||||
IF(NOT TARGET connect)
|
IF(NOT TARGET connect)
|
||||||
RETURN()
|
RETURN()
|
||||||
@@ -377,3 +387,4 @@ IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND)
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/JdbcInterface.jar
|
${CMAKE_CURRENT_BINARY_DIR}/JdbcInterface.jar
|
||||||
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
|
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/************* Array C++ Functions Source Code File (.CPP) *************/
|
/************* Array C++ Functions Source Code File (.CPP) *************/
|
||||||
/* Name: ARRAY.CPP Version 2.3 */
|
/* Name: ARRAY.CPP Version 2.3 */
|
||||||
/* */
|
/* */
|
||||||
/* (C) Copyright to the author Olivier BERTRAND 2005-2017 */
|
/* (C) Copyright to the author Olivier BERTRAND 2005-2019 */
|
||||||
/* */
|
/* */
|
||||||
/* This file contains the XOBJECT derived class ARRAY functions. */
|
/* This file contains the XOBJECT derived class ARRAY functions. */
|
||||||
/* ARRAY is used for elaborate type of processing, such as sorting */
|
/* ARRAY is used for elaborate type of processing, such as sorting */
|
||||||
@@ -82,8 +82,7 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp)
|
|||||||
if ((valtyp = pp->Type) != TYPE_STRING)
|
if ((valtyp = pp->Type) != TYPE_STRING)
|
||||||
len = 1;
|
len = 1;
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, "valtyp=%d len=%d\n", valtyp, len);
|
||||||
htrc("valtyp=%d len=%d\n", valtyp, len);
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
/* Firstly check the list and count the number of values in it. */
|
/* Firstly check the list and count the number of values in it. */
|
||||||
@@ -151,6 +150,9 @@ ARRAY::ARRAY(PGLOBAL g, int type, int size, int length, int prec)
|
|||||||
Type = type;
|
Type = type;
|
||||||
Xsize = -1;
|
Xsize = -1;
|
||||||
Len = 1;
|
Len = 1;
|
||||||
|
X = 0;
|
||||||
|
Inf = 0;
|
||||||
|
Sup = 0;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
@@ -287,11 +289,7 @@ bool ARRAY::AddValue(PGLOBAL g, PSZ strp)
|
|||||||
return true;
|
return true;
|
||||||
} // endif Type
|
} // endif Type
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, " adding string(%d): '%s'\n", Nval, strp);
|
||||||
htrc(" adding string(%d): '%s'\n", Nval, strp);
|
|
||||||
|
|
||||||
//Value->SetValue_psz(strp);
|
|
||||||
//Vblp->SetValue(valp, Nval++);
|
|
||||||
Vblp->SetValue(strp, Nval++);
|
Vblp->SetValue(strp, Nval++);
|
||||||
return false;
|
return false;
|
||||||
} // end of AddValue
|
} // end of AddValue
|
||||||
@@ -306,9 +304,7 @@ bool ARRAY::AddValue(PGLOBAL g, void *p)
|
|||||||
return true;
|
return true;
|
||||||
} // endif Type
|
} // endif Type
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, " adding pointer(%d): %p\n", Nval, p);
|
||||||
htrc(" adding pointer(%d): %p\n", Nval, p);
|
|
||||||
|
|
||||||
Vblp->SetValue((PSZ)p, Nval++);
|
Vblp->SetValue((PSZ)p, Nval++);
|
||||||
return false;
|
return false;
|
||||||
} // end of AddValue
|
} // end of AddValue
|
||||||
@@ -323,11 +319,7 @@ bool ARRAY::AddValue(PGLOBAL g, short n)
|
|||||||
return true;
|
return true;
|
||||||
} // endif Type
|
} // endif Type
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, " adding SHORT(%d): %hd\n", Nval, n);
|
||||||
htrc(" adding SHORT(%d): %hd\n", Nval, n);
|
|
||||||
|
|
||||||
//Value->SetValue(n);
|
|
||||||
//Vblp->SetValue(valp, Nval++);
|
|
||||||
Vblp->SetValue(n, Nval++);
|
Vblp->SetValue(n, Nval++);
|
||||||
return false;
|
return false;
|
||||||
} // end of AddValue
|
} // end of AddValue
|
||||||
@@ -342,11 +334,7 @@ bool ARRAY::AddValue(PGLOBAL g, int n)
|
|||||||
return true;
|
return true;
|
||||||
} // endif Type
|
} // endif Type
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, " adding int(%d): %d\n", Nval, n);
|
||||||
htrc(" adding int(%d): %d\n", Nval, n);
|
|
||||||
|
|
||||||
//Value->SetValue(n);
|
|
||||||
//Vblp->SetValue(valp, Nval++);
|
|
||||||
Vblp->SetValue(n, Nval++);
|
Vblp->SetValue(n, Nval++);
|
||||||
return false;
|
return false;
|
||||||
} // end of AddValue
|
} // end of AddValue
|
||||||
@@ -361,9 +349,7 @@ bool ARRAY::AddValue(PGLOBAL g, double d)
|
|||||||
return true;
|
return true;
|
||||||
} // endif Type
|
} // endif Type
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, " adding float(%d): %lf\n", Nval, d);
|
||||||
htrc(" adding float(%d): %lf\n", Nval, d);
|
|
||||||
|
|
||||||
Value->SetValue(d);
|
Value->SetValue(d);
|
||||||
Vblp->SetValue(Value, Nval++);
|
Vblp->SetValue(Value, Nval++);
|
||||||
return false;
|
return false;
|
||||||
@@ -380,10 +366,7 @@ bool ARRAY::AddValue(PGLOBAL g, PXOB xp)
|
|||||||
return true;
|
return true;
|
||||||
} // endif Type
|
} // endif Type
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, " adding (%d) from xp=%p\n", Nval, xp);
|
||||||
htrc(" adding (%d) from xp=%p\n", Nval, xp);
|
|
||||||
|
|
||||||
//AddValue(xp->GetValue());
|
|
||||||
Vblp->SetValue(xp->GetValue(), Nval++);
|
Vblp->SetValue(xp->GetValue(), Nval++);
|
||||||
return false;
|
return false;
|
||||||
} // end of AddValue
|
} // end of AddValue
|
||||||
@@ -399,9 +382,7 @@ bool ARRAY::AddValue(PGLOBAL g, PVAL vp)
|
|||||||
return true;
|
return true;
|
||||||
} // endif Type
|
} // endif Type
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, " adding (%d) from vp=%p\n", Nval, vp);
|
||||||
htrc(" adding (%d) from vp=%p\n", Nval, vp);
|
|
||||||
|
|
||||||
Vblp->SetValue(vp, Nval++);
|
Vblp->SetValue(vp, Nval++);
|
||||||
return false;
|
return false;
|
||||||
} // end of AddValue
|
} // end of AddValue
|
||||||
@@ -990,9 +971,7 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g)
|
|||||||
len += strlen(tp);
|
len += strlen(tp);
|
||||||
} // enfor i
|
} // enfor i
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, "Arraylist: len=%d\n", len);
|
||||||
htrc("Arraylist: len=%d\n", len);
|
|
||||||
|
|
||||||
p = (char *)PlugSubAlloc(g, NULL, len);
|
p = (char *)PlugSubAlloc(g, NULL, len);
|
||||||
strcpy(p, "(");
|
strcpy(p, "(");
|
||||||
|
|
||||||
@@ -1003,9 +982,7 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g)
|
|||||||
strcat(p, (++i == Nval) ? ")" : ",");
|
strcat(p, (++i == Nval) ? ")" : ",");
|
||||||
} // enfor i
|
} // enfor i
|
||||||
|
|
||||||
if (trace(1))
|
xtrc(1, "Arraylist: newlen=%d\n", strlen(p));
|
||||||
htrc("Arraylist: newlen=%d\n", strlen(p));
|
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
} // end of MakeArrayList
|
} // end of MakeArrayList
|
||||||
|
|
||||||
|
@@ -38,9 +38,7 @@ typedef class BLOCK *PBLOCK;
|
|||||||
class DllExport BLOCK {
|
class DllExport BLOCK {
|
||||||
public:
|
public:
|
||||||
void * operator new(size_t size, PGLOBAL g, void *p = NULL) {
|
void * operator new(size_t size, PGLOBAL g, void *p = NULL) {
|
||||||
if (trace(256))
|
xtrc(256, "New BLOCK: size=%d g=%p p=%p\n", size, g, p);
|
||||||
htrc("New BLOCK: size=%d g=%p p=%p\n", size, g, p);
|
|
||||||
|
|
||||||
return (PlugSubAlloc(g, p, size));
|
return (PlugSubAlloc(g, p, size));
|
||||||
} // end of new
|
} // end of new
|
||||||
|
|
||||||
|
@@ -224,6 +224,7 @@ DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t);
|
|||||||
DllExport char *PlugDup(PGLOBAL g, const char *str);
|
DllExport char *PlugDup(PGLOBAL g, const char *str);
|
||||||
DllExport void *MakePtr(void *, OFFSET);
|
DllExport void *MakePtr(void *, OFFSET);
|
||||||
DllExport void htrc(char const *fmt, ...);
|
DllExport void htrc(char const *fmt, ...);
|
||||||
|
DllExport void xtrc(uint, char const* fmt, ...);
|
||||||
DllExport uint GetTraceValue(void);
|
DllExport uint GetTraceValue(void);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
@@ -241,7 +241,9 @@ int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v);
|
|||||||
void PushWarning(PGLOBAL g, THD *thd, int level);
|
void PushWarning(PGLOBAL g, THD *thd, int level);
|
||||||
bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, PCSZ host, PCSZ db,
|
bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, PCSZ host, PCSZ db,
|
||||||
PCSZ tab, PCSZ src, int port);
|
PCSZ tab, PCSZ src, int port);
|
||||||
|
#if defined(ZIP_SUPPORT)
|
||||||
bool ZipLoadFile(PGLOBAL, PCSZ, PCSZ, PCSZ, bool, bool);
|
bool ZipLoadFile(PGLOBAL, PCSZ, PCSZ, PCSZ, bool, bool);
|
||||||
|
#endif // ZIP_SUPPORT
|
||||||
bool ExactInfo(void);
|
bool ExactInfo(void);
|
||||||
#if defined(CMGO_SUPPORT)
|
#if defined(CMGO_SUPPORT)
|
||||||
//void mongo_init(bool);
|
//void mongo_init(bool);
|
||||||
@@ -6730,6 +6732,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
|
|||||||
if (trace(1))
|
if (trace(1))
|
||||||
htrc("xchk=%p createas=%d\n", g->Xchk, g->Createas);
|
htrc("xchk=%p createas=%d\n", g->Xchk, g->Createas);
|
||||||
|
|
||||||
|
#if defined(ZIP_SUPPORT)
|
||||||
if (options->zipped) {
|
if (options->zipped) {
|
||||||
// Check whether the zip entry must be made from a file
|
// Check whether the zip entry must be made from a file
|
||||||
PCSZ fn= GetListOption(g, "Load", options->oplist, NULL);
|
PCSZ fn= GetListOption(g, "Load", options->oplist, NULL);
|
||||||
@@ -6759,6 +6762,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
|
|||||||
} // endif fn
|
} // endif fn
|
||||||
|
|
||||||
} // endif zipped
|
} // endif zipped
|
||||||
|
#endif // ZIP_SUPPORT
|
||||||
|
|
||||||
// To check whether indexes have to be made or remade
|
// To check whether indexes have to be made or remade
|
||||||
if (!g->Xchk) {
|
if (!g->Xchk) {
|
||||||
|
33
storage/connect/mini-global.h
Normal file
33
storage/connect/mini-global.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/***********************************************************************/
|
||||||
|
/* Definitions needed by the included files. */
|
||||||
|
/***********************************************************************/
|
||||||
|
#if !defined(MY_GLOBAL_H)
|
||||||
|
#define MY_GLOBAL_H
|
||||||
|
typedef unsigned int uint;
|
||||||
|
typedef unsigned int uint32;
|
||||||
|
typedef unsigned short ushort;
|
||||||
|
typedef unsigned long ulong;
|
||||||
|
typedef unsigned long DWORD;
|
||||||
|
typedef char *LPSTR;
|
||||||
|
typedef const char *LPCSTR;
|
||||||
|
typedef int BOOL;
|
||||||
|
#if defined(_WINDOWS)
|
||||||
|
typedef void *HANDLE;
|
||||||
|
#else
|
||||||
|
typedef int HANDLE;
|
||||||
|
#endif
|
||||||
|
typedef char *PSZ;
|
||||||
|
typedef const char *PCSZ;
|
||||||
|
typedef unsigned char BYTE;
|
||||||
|
typedef unsigned char uchar;
|
||||||
|
typedef long long longlong;
|
||||||
|
typedef unsigned long long ulonglong;
|
||||||
|
typedef char my_bool;
|
||||||
|
struct charset_info_st {};
|
||||||
|
typedef const charset_info_st CHARSET_INFO;
|
||||||
|
#define FALSE 0
|
||||||
|
#define TRUE 1
|
||||||
|
#define Item char
|
||||||
|
#define MY_MAX(a,b) ((a>b)?(a):(b))
|
||||||
|
#define MY_MIN(a,b) ((a<b)?(a):(b))
|
||||||
|
#endif // MY_GLOBAL_H
|
@@ -95,7 +95,7 @@
|
|||||||
#endif // ZIP_SUPPORT
|
#endif // ZIP_SUPPORT
|
||||||
#if defined(REST_SUPPORT)
|
#if defined(REST_SUPPORT)
|
||||||
#include "tabrest.h"
|
#include "tabrest.h"
|
||||||
#endif // REST_SUPPORT
|
#endif // Rest_SUPPORT
|
||||||
#include "mycat.h"
|
#include "mycat.h"
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
@@ -104,11 +104,9 @@
|
|||||||
#if defined(__WIN__)
|
#if defined(__WIN__)
|
||||||
extern "C" HINSTANCE s_hModule; // Saved module handle
|
extern "C" HINSTANCE s_hModule; // Saved module handle
|
||||||
#endif // !__WIN__
|
#endif // !__WIN__
|
||||||
|
|
||||||
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
||||||
bool MongoEnabled(void);
|
bool MongoEnabled(void);
|
||||||
#endif // JAVA_SUPPORT || CMGO_SUPPORT
|
#endif // JAVA_SUPPORT || CMGO_SUPPORT
|
||||||
|
|
||||||
PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
|
PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
@@ -488,14 +486,21 @@ void MYCAT::Reset(void)
|
|||||||
PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
|
PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
|
||||||
LPCSTR type, PRELDEF *)
|
LPCSTR type, PRELDEF *)
|
||||||
{
|
{
|
||||||
|
PRELDEF tdp= NULL;
|
||||||
|
|
||||||
if (trace(1))
|
if (trace(1))
|
||||||
printf("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type));
|
htrc("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);
|
tdp= MakeTableDesc(g, tablep, type);
|
||||||
|
|
||||||
|
if (trace(1))
|
||||||
|
htrc("GetTableDesc: tdp=%p\n", tdp);
|
||||||
|
|
||||||
|
return tdp;
|
||||||
} // end of GetTableDesc
|
} // end of GetTableDesc
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
@@ -510,7 +515,7 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
|
|||||||
PRELDEF tdp= NULL;
|
PRELDEF tdp= NULL;
|
||||||
|
|
||||||
if (trace(1))
|
if (trace(1))
|
||||||
printf("MakeTableDesc: name=%s schema=%s am=%s\n",
|
htrc("MakeTableDesc: name=%s schema=%s am=%s\n",
|
||||||
name, SVP(schema), SVP(am));
|
name, SVP(schema), SVP(am));
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
@@ -578,6 +583,9 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
|
|||||||
if (tdp && tdp->Define(g, this, name, schema, am))
|
if (tdp && tdp->Define(g, this, name, schema, am))
|
||||||
tdp= NULL;
|
tdp= NULL;
|
||||||
|
|
||||||
|
if (trace(1))
|
||||||
|
htrc("Table %s made\n", am);
|
||||||
|
|
||||||
return tdp;
|
return tdp;
|
||||||
} // end of MakeTableDesc
|
} // end of MakeTableDesc
|
||||||
|
|
||||||
@@ -591,24 +599,27 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type)
|
|||||||
// LPCSTR name= tablep->GetName();
|
// LPCSTR name= tablep->GetName();
|
||||||
|
|
||||||
if (trace(1))
|
if (trace(1))
|
||||||
printf("GetTableDB: name=%s\n", tablep->GetName());
|
htrc("GetTableDB: name=%s\n", tablep->GetName());
|
||||||
|
|
||||||
// Look for the description of the requested table
|
// Look for the description of the requested table
|
||||||
tdp= GetTableDesc(g, tablep, type);
|
tdp= GetTableDesc(g, tablep, type);
|
||||||
|
|
||||||
if (tdp) {
|
if (tdp) {
|
||||||
if (trace(1))
|
if (trace(1))
|
||||||
printf("tdb=%p type=%s\n", tdp, tdp->GetType());
|
htrc("tdb=%p type=%s\n", tdp, tdp->GetType());
|
||||||
|
|
||||||
if (tablep->GetSchema())
|
if (tablep->GetSchema())
|
||||||
tdp->Database = SetPath(g, tablep->GetSchema());
|
tdp->Database = SetPath(g, tablep->GetSchema());
|
||||||
|
|
||||||
|
if (trace(2))
|
||||||
|
htrc("Going to get table...\n");
|
||||||
|
|
||||||
tdbp= tdp->GetTable(g, mode);
|
tdbp= tdp->GetTable(g, mode);
|
||||||
} // endif tdp
|
} // endif tdp
|
||||||
|
|
||||||
if (tdbp) {
|
if (tdbp) {
|
||||||
if (trace(1))
|
if (trace(1))
|
||||||
printf("tdbp=%p name=%s amtype=%d\n", tdbp, tdbp->GetName(),
|
htrc("tdbp=%p name=%s amtype=%d\n", tdbp, tdbp->GetName(),
|
||||||
tdbp->GetAmType());
|
tdbp->GetAmType());
|
||||||
tablep->SetTo_Tdb(tdbp);
|
tablep->SetTo_Tdb(tdbp);
|
||||||
tdbp->SetTable(tablep);
|
tdbp->SetTable(tablep);
|
||||||
|
@@ -3,7 +3,11 @@
|
|||||||
#define __OSUTIL_H__
|
#define __OSUTIL_H__
|
||||||
|
|
||||||
#if defined(UNIX) || defined(UNIV_LINUX)
|
#if defined(UNIX) || defined(UNIV_LINUX)
|
||||||
|
#if defined(MARIADB)
|
||||||
#include "my_global.h"
|
#include "my_global.h"
|
||||||
|
#else
|
||||||
|
#include "mini-global.h"
|
||||||
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
@@ -2,11 +2,11 @@
|
|||||||
/* */
|
/* */
|
||||||
/* PROGRAM NAME: PLUGUTIL */
|
/* PROGRAM NAME: PLUGUTIL */
|
||||||
/* ------------- */
|
/* ------------- */
|
||||||
/* Version 3.0 */
|
/* Version 3.1 */
|
||||||
/* */
|
/* */
|
||||||
/* COPYRIGHT: */
|
/* COPYRIGHT: */
|
||||||
/* ---------- */
|
/* ---------- */
|
||||||
/* (C) Copyright to the author Olivier BERTRAND 1993-2017 */
|
/* (C) Copyright to the author Olivier BERTRAND 1993-2019 */
|
||||||
/* */
|
/* */
|
||||||
/* WHAT THIS PROGRAM DOES: */
|
/* WHAT THIS PROGRAM DOES: */
|
||||||
/* ----------------------- */
|
/* ----------------------- */
|
||||||
@@ -110,6 +110,21 @@ ACTIVITY defActivity = { /* Describes activity and language */
|
|||||||
#include "rcmsg.h"
|
#include "rcmsg.h"
|
||||||
#endif // UNIX
|
#endif // UNIX
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* Conditional tracing output function. */
|
||||||
|
/**************************************************************************/
|
||||||
|
void xtrc(uint x, char const *fmt, ...)
|
||||||
|
{
|
||||||
|
if (GetTraceValue() & x) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
} // endif x
|
||||||
|
|
||||||
|
} // end of xtrc
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/* Tracing output function. */
|
/* Tracing output function. */
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -118,12 +133,7 @@ void htrc(char const *fmt, ...)
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
||||||
|
|
||||||
//if (trace == 1)
|
|
||||||
// vfprintf(debug, fmt, ap);
|
|
||||||
//else
|
|
||||||
vfprintf(stderr, fmt, ap);
|
vfprintf(stderr, fmt, ap);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
} // end of htrc
|
} // end of htrc
|
||||||
|
|
||||||
|
@@ -457,6 +457,10 @@ int TABDEF::GetColCatInfo(PGLOBAL g)
|
|||||||
recln = MY_MAX(recln, Hc->GetIntegerOption("Lrecl"));
|
recln = MY_MAX(recln, Hc->GetIntegerOption("Lrecl"));
|
||||||
Hc->SetIntegerOption("Lrecl", recln);
|
Hc->SetIntegerOption("Lrecl", recln);
|
||||||
((PDOSDEF)this)->SetLrecl(recln);
|
((PDOSDEF)this)->SetLrecl(recln);
|
||||||
|
|
||||||
|
if (trace(1))
|
||||||
|
htrc("Lrecl set to %d\n", recln);
|
||||||
|
|
||||||
} // endif Lrecl
|
} // endif Lrecl
|
||||||
|
|
||||||
// Attach the column definition to the tabdef
|
// Attach the column definition to the tabdef
|
||||||
@@ -487,15 +491,16 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g)
|
|||||||
PCATLG cat = Cat;
|
PCATLG cat = Cat;
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
/* Ensure that the .dll doesn't have a path. */
|
/* Ensure that the module name doesn't have a path. */
|
||||||
/* This is done to ensure that only approved dll from the system */
|
/* This is done to ensure that only approved libs from the system */
|
||||||
/* directories are used (to make this even remotely secure). */
|
/* directories are used (to make this even remotely secure). */
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
if (check_valid_path(Module, strlen(Module))) {
|
if (check_valid_path(Module, strlen(Module))) {
|
||||||
strcpy(g->Message, "Module cannot contain a path");
|
strcpy(g->Message, "Module cannot contain a path");
|
||||||
return NULL;
|
return NULL;
|
||||||
} else
|
} else
|
||||||
PlugSetPath(soname, Module, GetPluginDir());
|
// PlugSetPath(soname, Module, GetPluginDir()); // Crashes on Fedora
|
||||||
|
strncat(strcpy(soname, GetPluginDir()), Module, _MAX_PATH);
|
||||||
|
|
||||||
#if defined(__WIN__)
|
#if defined(__WIN__)
|
||||||
// Is the DLL already loaded?
|
// Is the DLL already loaded?
|
||||||
|
4
storage/connect/rest.def
Normal file
4
storage/connect/rest.def
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
LIBRARY REST2
|
||||||
|
EXPORTS
|
||||||
|
GetREST @1
|
||||||
|
ColREST @2
|
33
storage/connect/rest.h
Normal file
33
storage/connect/rest.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/***********************************************************************/
|
||||||
|
/* Definitions needed by the included files. */
|
||||||
|
/***********************************************************************/
|
||||||
|
#if !defined(MY_GLOBAL_H)
|
||||||
|
#define MY_GLOBAL_H
|
||||||
|
typedef unsigned int uint;
|
||||||
|
typedef unsigned int uint32;
|
||||||
|
typedef unsigned short ushort;
|
||||||
|
typedef unsigned long ulong;
|
||||||
|
typedef unsigned long DWORD;
|
||||||
|
typedef char *LPSTR;
|
||||||
|
typedef const char *LPCSTR;
|
||||||
|
typedef int BOOL;
|
||||||
|
#if defined(_WINDOWS)
|
||||||
|
typedef void *HANDLE;
|
||||||
|
#else
|
||||||
|
typedef int HANDLE;
|
||||||
|
#endif
|
||||||
|
typedef char *PSZ;
|
||||||
|
typedef const char *PCSZ;
|
||||||
|
typedef unsigned char BYTE;
|
||||||
|
typedef unsigned char uchar;
|
||||||
|
typedef long long longlong;
|
||||||
|
typedef unsigned long long ulonglong;
|
||||||
|
typedef char my_bool;
|
||||||
|
struct charset_info_st {};
|
||||||
|
typedef const charset_info_st CHARSET_INFO;
|
||||||
|
#define FALSE 0
|
||||||
|
#define TRUE 1
|
||||||
|
#define Item char
|
||||||
|
#define MY_MAX(a,b) ((a>b)?(a):(b))
|
||||||
|
#define MY_MIN(a,b) ((a<b)?(a):(b))
|
||||||
|
#endif // MY_GLOBAL_H
|
@@ -7,7 +7,8 @@
|
|||||||
#if defined(MARIADB)
|
#if defined(MARIADB)
|
||||||
#include <my_global.h>
|
#include <my_global.h>
|
||||||
#else
|
#else
|
||||||
#include "mini_global.h"
|
#include "mini-global.h"
|
||||||
|
#define _OS_H_INCLUDED // Prevent os.h to be called
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace utility::conversions; // String conversions utilities
|
using namespace utility::conversions; // String conversions utilities
|
||||||
@@ -18,6 +19,7 @@ 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. */
|
||||||
@@ -32,56 +34,56 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn)
|
|||||||
return 2;
|
return 2;
|
||||||
} // endif
|
} // endif
|
||||||
|
|
||||||
//std::string sfn(fn);
|
xt = GetTraceValue();
|
||||||
//auto wfn= to_string_t(sfn);
|
xtrc(515, "restGetFile: fn=%s\n", fn);
|
||||||
//rc= 0;
|
|
||||||
|
|
||||||
// Open stream to output file.
|
// Open stream to output file.
|
||||||
pplx::task<void> requestTask=
|
pplx::task<void> requestTask = fstream::open_ostream(to_string_t(fn))
|
||||||
fstream::open_ostream(to_string_t(fn))
|
|
||||||
.then([=](ostream outFile) {
|
.then([=](ostream outFile) {
|
||||||
*fileStream= outFile;
|
*fileStream= outFile;
|
||||||
|
|
||||||
|
if (xt & 515)
|
||||||
|
htrc("Outfile isopen=%d\n", outFile.is_open());
|
||||||
|
|
||||||
// Create http_client to send the request.
|
// Create http_client to send the request.
|
||||||
http_client client(to_string_t(http));
|
http_client client(to_string_t(http));
|
||||||
|
|
||||||
if (uri)
|
if (uri) {
|
||||||
{
|
|
||||||
// Build request URI and start the request.
|
// Build request URI and start the request.
|
||||||
uri_builder builder(to_string_t(uri));
|
uri_builder builder(to_string_t(uri));
|
||||||
return client.request(methods::GET, builder.to_string());
|
return client.request(methods::GET, builder.to_string());
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return client.request(methods::GET);
|
return client.request(methods::GET);
|
||||||
})
|
})
|
||||||
|
|
||||||
// Handle response headers arriving.
|
// Handle response headers arriving.
|
||||||
.then([=](http_response response) {
|
.then([=](http_response response) {
|
||||||
#if defined(DEVELOPMENT)
|
if (xt & 515)
|
||||||
fprintf(stderr, "Received response status code:%u\n",
|
htrc("Received response status code:%u\n",
|
||||||
response.status_code());
|
response.status_code());
|
||||||
#endif // DEVELOPMENT
|
|
||||||
|
|
||||||
// Write response body into the file.
|
// Write response body into the file.
|
||||||
return response.body().read_to_end(fileStream->streambuf());
|
return response.body().read_to_end(fileStream->streambuf());
|
||||||
})
|
})
|
||||||
|
|
||||||
// Close the file stream.
|
// Close the file stream.
|
||||||
.then([=](size_t) { return fileStream->close(); });
|
.then([=](size_t n) {
|
||||||
|
if (xt & 515)
|
||||||
|
htrc("Return size=%u\n", n);
|
||||||
|
|
||||||
|
return fileStream->close();
|
||||||
|
});
|
||||||
|
|
||||||
// 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");
|
||||||
catch (const std::exception &e)
|
} catch (const std::exception &e) {
|
||||||
{
|
xtrc(515, "Error exception: %s\n", e.what());
|
||||||
#if defined(DEVELOPMENT)
|
|
||||||
fprintf(stderr, "Error exception: %s\n", e.what());
|
|
||||||
#endif // DEVELOPMENT
|
|
||||||
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);
|
||||||
return rc;
|
return rc;
|
||||||
} // end of restGetFile
|
} // end of restGetFile
|
@@ -189,9 +189,11 @@ PQRYRES CSVColumns(PGLOBAL g, PCSZ dp, PTOS topt, bool info)
|
|||||||
htrc("File %s Sep=%c Qot=%c Header=%d maxerr=%d\n",
|
htrc("File %s Sep=%c Qot=%c Header=%d maxerr=%d\n",
|
||||||
SVP(tdp->Fn), tdp->Sep, tdp->Qot, tdp->Header, tdp->Maxerr);
|
SVP(tdp->Fn), tdp->Sep, tdp->Qot, tdp->Header, tdp->Maxerr);
|
||||||
|
|
||||||
|
#if defined(ZIP_SUPPORT)
|
||||||
if (tdp->Zipped)
|
if (tdp->Zipped)
|
||||||
tcvp = new(g)TDBCSV(tdp, new(g)UNZFAM(tdp));
|
tcvp = new(g)TDBCSV(tdp, new(g)UNZFAM(tdp));
|
||||||
else
|
else
|
||||||
|
#endif // ZIP_SUPPORT
|
||||||
tcvp = new(g) TDBCSV(tdp, new(g) DOSFAM(tdp));
|
tcvp = new(g) TDBCSV(tdp, new(g) DOSFAM(tdp));
|
||||||
|
|
||||||
tcvp->SetMode(MODE_READ);
|
tcvp->SetMode(MODE_READ);
|
||||||
|
@@ -604,6 +604,9 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
|
PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
|
||||||
{
|
{
|
||||||
|
if (trace(1))
|
||||||
|
htrc("JSON GetTable Pretty=%d Uri=%s\n", Pretty, SVP(Uri));
|
||||||
|
|
||||||
if (Catfunc == FNC_COL)
|
if (Catfunc == FNC_COL)
|
||||||
return new(g)TDBJCL(this);
|
return new(g)TDBJCL(this);
|
||||||
|
|
||||||
|
@@ -1,13 +1,23 @@
|
|||||||
/*************** Rest C++ Program Source Code File (.CPP) **************/
|
/*************** Rest C++ Program Source Code File (.CPP) **************/
|
||||||
/* PROGRAM NAME: Rest Version 1.3 */
|
/* PROGRAM NAME: Rest Version 1.5 */
|
||||||
/* (C) Copyright to the author Olivier BERTRAND 2018 - 2019 */
|
/* (C) Copyright to the author Olivier BERTRAND 2018 - 2019 */
|
||||||
/* This program is the REST OEM (Web API support) module definition. */
|
/* This program is the REST Web API support for MariaDB. */
|
||||||
|
/* When compiled without MARIADB defined, it is the EOM module code. */
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
/* Definitions needed by the included files. */
|
/* Definitions needed by the included files. */
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
|
#if defined(MARIADB)
|
||||||
#include <my_global.h> // All MariaDB stuff
|
#include <my_global.h> // All MariaDB stuff
|
||||||
|
#else // !MARIADB OEM module
|
||||||
|
#include "mini-global.h"
|
||||||
|
#define _MAX_PATH 260
|
||||||
|
#if !defined(__WIN__)
|
||||||
|
#define __stdcall
|
||||||
|
#endif // !__WIN__
|
||||||
|
#define _OS_H_INCLUDED // Prevent os.h to be called
|
||||||
|
#endif // !MARIADB
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
/* Include application header files: */
|
/* Include application header files: */
|
||||||
@@ -19,12 +29,12 @@
|
|||||||
#include "plgdbsem.h"
|
#include "plgdbsem.h"
|
||||||
#include "xtable.h"
|
#include "xtable.h"
|
||||||
#include "filamtxt.h"
|
#include "filamtxt.h"
|
||||||
#include "plgxml.h"
|
|
||||||
#include "tabdos.h"
|
#include "tabdos.h"
|
||||||
#include "tabfmt.h"
|
#include "plgxml.h"
|
||||||
#include "tabjson.h"
|
|
||||||
#include "tabrest.h"
|
|
||||||
#include "tabxml.h"
|
#include "tabxml.h"
|
||||||
|
#include "tabjson.h"
|
||||||
|
#include "tabfmt.h"
|
||||||
|
#include "tabrest.h"
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
/* Get the file from the Web. */
|
/* Get the file from the Web. */
|
||||||
@@ -38,19 +48,55 @@ static PCSZ slash= "/";
|
|||||||
#define stricmp strcasecmp
|
#define stricmp strcasecmp
|
||||||
#endif // !__WIN__
|
#endif // !__WIN__
|
||||||
|
|
||||||
|
#if !defined(MARIADB)
|
||||||
|
/***********************************************************************/
|
||||||
|
/* DB static variables. */
|
||||||
|
/***********************************************************************/
|
||||||
|
int TDB::Tnum;
|
||||||
|
int DTVAL::Shift;
|
||||||
|
int CSORT::Limit = 0;
|
||||||
|
double CSORT::Lg2 = log(2.0);
|
||||||
|
size_t CSORT::Cpn[1000] = { 0 };
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
/* These functions are exported from the REST library. */
|
||||||
|
/***********************************************************************/
|
||||||
|
extern "C" {
|
||||||
|
PTABDEF __stdcall GetREST(PGLOBAL, void*);
|
||||||
|
PQRYRES __stdcall ColREST(PGLOBAL, PTOS, char*, char*, bool);
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
/* This function returns a table definition class. */
|
||||||
|
/***********************************************************************/
|
||||||
|
PTABDEF __stdcall GetREST(PGLOBAL g, void *memp)
|
||||||
|
{
|
||||||
|
return new(g, memp) RESTDEF;
|
||||||
|
} // end of GetREST
|
||||||
|
#endif // !MARIADB
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
/* Return the columns definition to MariaDB. */
|
/* Return the columns definition to MariaDB. */
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
|
#if defined(MARIADB)
|
||||||
PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
|
PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
|
||||||
|
#else // !MARIADB
|
||||||
|
PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
|
||||||
|
#endif // !MARIADB
|
||||||
{
|
{
|
||||||
PQRYRES qrp= NULL;
|
PQRYRES qrp= NULL;
|
||||||
char filename[_MAX_PATH];
|
char filename[_MAX_PATH + 1]; // MAX PATH ???
|
||||||
PCSZ http, uri, fn, ftype;
|
PCSZ http, uri, fn, ftype;
|
||||||
|
|
||||||
http = GetStringTableOption(g, tp, "Http", NULL);
|
http = GetStringTableOption(g, tp, "Http", NULL);
|
||||||
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)
|
||||||
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");
|
||||||
|
#endif // !MARIADB
|
||||||
|
|
||||||
// We used the file name relative to recorded datapath
|
// We used the file name relative to recorded datapath
|
||||||
strcat(strcat(strcat(strcpy(filename, "."), slash), db), slash);
|
strcat(strcat(strcat(strcpy(filename, "."), slash), db), slash);
|
||||||
@@ -78,41 +124,60 @@ PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
|
bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
|
||||||
{
|
{
|
||||||
char filename[_MAX_PATH];
|
char filename[_MAX_PATH + 1];
|
||||||
TABTYPE type= GetTypeID(am);
|
int rc = 0, n;
|
||||||
|
LPCSTR ftype;
|
||||||
|
|
||||||
switch (type) {
|
#if defined(MARIADB)
|
||||||
case TAB_JSON:
|
ftype = GetStringCatInfo(g, "Type", "JSON");
|
||||||
case TAB_XML:
|
#else // !MARIADB
|
||||||
case TAB_CSV:
|
// OEM tables must specify the file type
|
||||||
break;
|
ftype = GetStringCatInfo(g, "Ftype", "JSON");
|
||||||
default:
|
#endif // !MARIADB
|
||||||
|
|
||||||
|
if (trace(1))
|
||||||
|
htrc("ftype = %s am = %s\n", ftype, SVP(am));
|
||||||
|
|
||||||
|
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);
|
||||||
sprintf(g->Message, "Unsupported REST table type %s", am);
|
sprintf(g->Message, "Unsupported REST table type %s", am);
|
||||||
return true;
|
return true;
|
||||||
} // endswitch type
|
} // endif n
|
||||||
|
|
||||||
Http = GetStringCatInfo(g, "Http", NULL);
|
Http = GetStringCatInfo(g, "Http", NULL);
|
||||||
Uri = GetStringCatInfo(g, "Uri", NULL);
|
Uri = GetStringCatInfo(g, "Uri", NULL);
|
||||||
Fn = GetStringCatInfo(g, "Filename", "rest.json");
|
Fn = GetStringCatInfo(g, "Filename", "rest.json");
|
||||||
|
|
||||||
// We used the file name relative to recorded datapath
|
// We used the file name relative to recorded datapath
|
||||||
PlugSetPath(filename, Fn, GetPath());
|
//PlugSetPath(filename, Fn, GetPath());
|
||||||
|
strncat(strcpy(filename, GetPath()), Fn, _MAX_PATH);
|
||||||
|
|
||||||
// Retrieve the file from the web and copy it locally
|
// Retrieve the file from the web and copy it locally
|
||||||
if (Http && restGetFile(g, Http, Uri, filename)) {}
|
rc = restGetFile(g, Http, Uri, filename);
|
||||||
else if (type == TAB_JSON)
|
|
||||||
Tdp= new (g) JSONDEF;
|
if (trace(1))
|
||||||
else if (type == TAB_XML)
|
htrc("Return from restGetFile: rc=%d\n", rc);
|
||||||
Tdp= new (g) XMLDEF;
|
|
||||||
else if (type == TAB_CSV)
|
if (rc)
|
||||||
Tdp= new (g) CSVDEF;
|
return true;
|
||||||
else
|
else switch (n) {
|
||||||
sprintf(g->Message, "Unsupported REST table type %s", am);
|
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
|
// 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))
|
||||||
|
htrc("Tdp defined\n", rc);
|
||||||
|
|
||||||
// Return true in case of error
|
// Return true in case of error
|
||||||
return (Tdp == NULL);
|
return (Tdp == NULL);
|
||||||
} // end of DefineAM
|
} // end of DefineAM
|
||||||
@@ -122,6 +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 (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");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
@@ -146,3 +145,6 @@ elseif(UNIX)
|
|||||||
set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
|
set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
RESTRICT_SYMBOL_EXPORTS(zlib)
|
||||||
|
Reference in New Issue
Block a user