Include all changes made on 10.2

This commit is contained in:
Olivier Bertrand 2019-08-22 16:16:23 +02:00
parent 06b3715f26
commit 7628fd3c6e
19 changed files with 1597 additions and 1477 deletions

View file

@ -40,10 +40,6 @@ user_connect.h valblk.h value.h xindex.h xobject.h xtable.h)
add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS -Dconnect_EXPORTS)
add_definitions( -DHUGE_SUPPORT -DGZ_SUPPORT )
macro(DISABLE_WARNING W)
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-error=${W}")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-${W}" DEBUG)
endmacro()
#
# OS specific C flags, definitions and source files.
@ -51,15 +47,14 @@ endmacro()
IF(UNIX)
MY_CHECK_AND_SET_COMPILER_FLAG("-Wall -Wmissing-declarations")
if(NOT WITH_WARNINGS)
DISABLE_WARNING("unused-function")
DISABLE_WARNING("unused-variable")
DISABLE_WARNING("unused-value")
DISABLE_WARNING("parentheses")
DISABLE_WARNING("strict-aliasing")
DISABLE_WARNING("misleading-indentation")
DISABLE_WARNING("format-truncation")
DISABLE_WARNING("implicit-fallthrough")
DISABLE_WARNING("type-limits")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-function")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-variable")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-value")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-parentheses")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-strict-aliasing")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-misleading-indentation")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-format-truncation")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-implicit-fallthrough")
endif(NOT WITH_WARNINGS)
add_definitions( -DUNIX -DLINUX -DUBUNTU )
@ -73,6 +68,10 @@ ELSE(NOT UNIX)
tabwmi.cpp tabwmi.h tabmac.cpp tabmac.h macutil.cpp macutil.h)
# Add exception handling to the CONNECT project)
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)
IF(MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES Clang))
# Connect does not work with clang-cl
@ -118,7 +117,6 @@ IF(CONNECT_WITH_LIBXML2)
FIND_PACKAGE(LibXml2)
IF (LIBXML2_FOUND)
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
SET(ZLIB_LIBRARY "z") # see ZLIB_INCLUDE_DIR below
SET(XML_LIBRARY ${LIBXML2_LIBRARIES})
SET(CONNECT_SOURCES ${CONNECT_SOURCES} libdoc.cpp libdoc.h)
add_definitions(-DLIBXML2_SUPPORT)
@ -173,8 +171,7 @@ IF(CONNECT_WITH_ODBC)
# the library 'libiodbc' gets compiled with 'sql'h.
# This will also need changes in the sources (e.g. #include <isql.h>).
find_file(ODBC_INCLUDES sql.h
PATHS
find_path(ODBC_INCLUDE_DIR sql.h
/usr/include
/usr/include/odbc
/usr/local/include
@ -184,7 +181,7 @@ IF(CONNECT_WITH_ODBC)
#"C:/Program Files/Microsoft SDKs/Windows/v7.0A/include"
#"C:/Program Files/Microsoft SDKs/Windows/v6.0a/include"
#"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/include"
DOC "Specify the path to sql.h."
DOC "Specify the directory containing sql.h."
)
find_library(ODBC_LIBRARY
@ -203,10 +200,9 @@ IF(CONNECT_WITH_ODBC)
DOC "Specify the ODBC driver manager library here."
)
mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDES)
mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDE_DIR)
IF(ODBC_INCLUDES AND ODBC_LIBRARY)
get_filename_component(ODBC_INCLUDE_DIR "${ODBC_INCLUDES}" PATH)
IF(ODBC_INCLUDE_DIR AND ODBC_LIBRARY)
set(CMAKE_REQUIRED_LIBRARIES ${ODBC_LIBRARY})
set(CMAKE_REQUIRED_INCLUDES ${ODBC_INCLUDE_DIR})
CHECK_CXX_SOURCE_COMPILES(
@ -316,19 +312,25 @@ ENDIF(CONNECT_WITH_MONGO)
# REST
#
#OPTION(CONNECT_WITH_REST "Compile CONNECT storage engine with REST support" ON)
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")
IF(UNIX)
# INCLUDE_DIRECTORIES(${CPPRESTSDK_INCLUDE_DIR})
# 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)
add_definitions(-DREST_SUPPORT)
ELSE(NOT cpprestsdk_FOUND)
MESSAGE(STATUS "=====> cpprestsdk package not found")
ENDIF (cpprestsdk_FOUND)
ENDIF(CONNECT_WITH_ZIP)
ENDIF(CONNECT_WITH_REST)
#
# XMAP
@ -349,40 +351,31 @@ MYSQL_ADD_PLUGIN(connect ${CONNECT_SOURCES}
COMPONENT connect-engine
RECOMPILE_FOR_EMBEDDED
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)
RETURN()
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 (libmongoc-1.0_FOUND)
SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS
"/DELAYLOAD:libbson-1.0.dll /DELAYLOAD:libmongoc-1.0.dll")
SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS
"/DELAYLOAD:libbson-1.0.dll /DELAYLOAD:libmongoc-1.0.dll")
ENDIF(libmongoc-1.0_FOUND)
# Install some extra files that belong to connect engine
INSTALL(FILES "$<TARGET_FILE_DIR:connect>/ha_connect.lib"
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
ENDIF(WIN32)
IF(MSVC)
# Temporarily disable "conversion from size_t .."
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267")
# Install some extra files that belong to connect engine
IF(WIN32)
# install ha_connect.lib
GET_TARGET_PROPERTY(CONNECT_LOCATION connect LOCATION)
STRING(REPLACE "dll" "lib" CONNECT_LIB ${CONNECT_LOCATION})
IF(CMAKE_CONFIGURATION_TYPES)
STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${CMAKE_INSTALL_CONFIG_NAME}"
CONNECT_LIB ${CONNECT_LIB})
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996")
string(REPLACE "/permissive-" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ENDIF()
INSTALL(FILES ${CONNECT_LIB}
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
ENDIF(WIN32)
IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND)
# TODO: Find how to compile and install the java wrapper classes
@ -394,3 +387,4 @@ IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND)
${CMAKE_CURRENT_BINARY_DIR}/JdbcInterface.jar
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
ENDIF()

View file

@ -1,7 +1,7 @@
/************* Array C++ Functions Source Code File (.CPP) *************/
/* 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. */
/* ARRAY is used for elaborate type of processing, such as sorting */
@ -67,7 +67,7 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp); // avoid gcc warning
/* MakeValueArray: Makes a value array from a value list. */
/***********************************************************************/
PARRAY MakeValueArray(PGLOBAL g, PPARM pp)
{
{
int n, valtyp = 0;
size_t len = 0;
PARRAY par;
@ -82,8 +82,7 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp)
if ((valtyp = pp->Type) != TYPE_STRING)
len = 1;
if (trace(1))
htrc("valtyp=%d len=%d\n", valtyp, len);
xtrc(1, "valtyp=%d len=%d\n", valtyp, len);
/*********************************************************************/
/* Firstly check the list and count the number of values in it. */
@ -127,13 +126,13 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp)
// Integer stored inside pp->Value
par->AddValue(g, parmp->Intval);
break;
} // endswitch valtyp
} // endswitch valtyp
/*********************************************************************/
/* Send back resulting array. */
/*********************************************************************/
return par;
} // end of MakeValueArray
} // end of MakeValueArray
/* -------------------------- Class ARRAY ---------------------------- */
@ -151,6 +150,9 @@ ARRAY::ARRAY(PGLOBAL g, int type, int size, int length, int prec)
Type = type;
Xsize = -1;
Len = 1;
X = 0;
Inf = 0;
Sup = 0;
switch (type) {
case TYPE_STRING:
@ -281,130 +283,109 @@ void ARRAY::Empty(void)
/* Add a string element to an array. */
/***********************************************************************/
bool ARRAY::AddValue(PGLOBAL g, PSZ strp)
{
{
if (Type != TYPE_STRING) {
sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "CHAR");
return true;
} // endif Type
} // endif Type
if (trace(1))
htrc(" adding string(%d): '%s'\n", Nval, strp);
//Value->SetValue_psz(strp);
//Vblp->SetValue(valp, Nval++);
xtrc(1, " adding string(%d): '%s'\n", Nval, strp);
Vblp->SetValue(strp, Nval++);
return false;
} // end of AddValue
} // end of AddValue
/***********************************************************************/
/* Add a char pointer element to an array. */
/***********************************************************************/
bool ARRAY::AddValue(PGLOBAL g, void *p)
{
{
if (Type != TYPE_PCHAR) {
sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "PCHAR");
return true;
} // endif Type
if (trace(1))
htrc(" adding pointer(%d): %p\n", Nval, p);
} // endif Type
xtrc(1, " adding pointer(%d): %p\n", Nval, p);
Vblp->SetValue((PSZ)p, Nval++);
return false;
} // end of AddValue
} // end of AddValue
/***********************************************************************/
/* Add a short integer element to an array. */
/***********************************************************************/
bool ARRAY::AddValue(PGLOBAL g, short n)
{
{
if (Type != TYPE_SHORT) {
sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "SHORT");
return true;
} // endif Type
} // endif Type
if (trace(1))
htrc(" adding SHORT(%d): %hd\n", Nval, n);
//Value->SetValue(n);
//Vblp->SetValue(valp, Nval++);
xtrc(1, " adding SHORT(%d): %hd\n", Nval, n);
Vblp->SetValue(n, Nval++);
return false;
} // end of AddValue
} // end of AddValue
/***********************************************************************/
/* Add an integer element to an array. */
/***********************************************************************/
bool ARRAY::AddValue(PGLOBAL g, int n)
{
{
if (Type != TYPE_INT) {
sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "INTEGER");
return true;
} // endif Type
} // endif Type
if (trace(1))
htrc(" adding int(%d): %d\n", Nval, n);
//Value->SetValue(n);
//Vblp->SetValue(valp, Nval++);
xtrc(1, " adding int(%d): %d\n", Nval, n);
Vblp->SetValue(n, Nval++);
return false;
} // end of AddValue
} // end of AddValue
/***********************************************************************/
/* Add a double float element to an array. */
/***********************************************************************/
bool ARRAY::AddValue(PGLOBAL g, double d)
{
{
if (Type != TYPE_DOUBLE) {
sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "DOUBLE");
return true;
} // endif Type
if (trace(1))
htrc(" adding float(%d): %lf\n", Nval, d);
} // endif Type
xtrc(1, " adding float(%d): %lf\n", Nval, d);
Value->SetValue(d);
Vblp->SetValue(Value, Nval++);
return false;
} // end of AddValue
} // end of AddValue
/***********************************************************************/
/* Add the value of a XOBJECT block to an array. */
/***********************************************************************/
bool ARRAY::AddValue(PGLOBAL g, PXOB xp)
{
if (Type != xp->GetResultType()) {
sprintf(g->Message, MSG(ADD_BAD_TYPE),
GetTypeName(xp->GetResultType()), GetTypeName(Type));
return true;
} // endif Type
{
if (Type != xp->GetResultType()) {
sprintf(g->Message, MSG(ADD_BAD_TYPE),
GetTypeName(xp->GetResultType()), GetTypeName(Type));
return true;
} // endif Type
if (trace(1))
htrc(" adding (%d) from xp=%p\n", Nval, xp);
//AddValue(xp->GetValue());
Vblp->SetValue(xp->GetValue(), Nval++);
return false;
} // end of AddValue
xtrc(1, " adding (%d) from xp=%p\n", Nval, xp);
Vblp->SetValue(xp->GetValue(), Nval++);
return false;
} // end of AddValue
/***********************************************************************/
/* Add a value to an array. */
/***********************************************************************/
bool ARRAY::AddValue(PGLOBAL g, PVAL vp)
{
{
if (Type != vp->GetType()) {
sprintf(g->Message, MSG(ADD_BAD_TYPE),
GetTypeName(vp->GetType()), GetTypeName(Type));
return true;
} // endif Type
if (trace(1))
htrc(" adding (%d) from vp=%p\n", Nval, vp);
} // endif Type
xtrc(1, " adding (%d) from vp=%p\n", Nval, vp);
Vblp->SetValue(vp, Nval++);
return false;
} // end of AddValue
} // end of AddValue
/***********************************************************************/
/* Retrieve the nth value of the array. */
@ -973,7 +954,7 @@ int ARRAY::BlockTest(PGLOBAL, int opc, int opm,
/* MakeArrayList: Makes a value list from an SQL IN array (in work). */
/***********************************************************************/
PSZ ARRAY::MakeArrayList(PGLOBAL g)
{
{
char *p, *tp;
int i;
size_t z, len = 2;
@ -988,11 +969,9 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g)
Value->SetValue_pvblk(Vblp, i);
Value->Prints(g, tp, z);
len += strlen(tp);
} // enfor i
if (trace(1))
htrc("Arraylist: len=%d\n", len);
} // enfor i
xtrc(1, "Arraylist: len=%d\n", len);
p = (char *)PlugSubAlloc(g, NULL, len);
strcpy(p, "(");
@ -1001,19 +980,17 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g)
Value->Prints(g, tp, z);
strcat(p, tp);
strcat(p, (++i == Nval) ? ")" : ",");
} // enfor i
if (trace(1))
htrc("Arraylist: newlen=%d\n", strlen(p));
} // enfor i
xtrc(1, "Arraylist: newlen=%d\n", strlen(p));
return p;
} // end of MakeArrayList
} // end of MakeArrayList
/***********************************************************************/
/* Make file output of ARRAY contents. */
/***********************************************************************/
void ARRAY::Printf(PGLOBAL g, FILE *f, uint n)
{
{
char m[64];
int lim = MY_MIN(Nval,10);
@ -1035,19 +1012,19 @@ void ARRAY::Printf(PGLOBAL g, FILE *f, uint n)
} else
fprintf(f, "%sVALLST: numval=%d\n", m, Nval);
} // end of Printf
} // end of Printf
/***********************************************************************/
/* Make string output of ARRAY contents. */
/***********************************************************************/
void ARRAY::Prints(PGLOBAL, char *ps, uint z)
{
{
if (z < 16)
return;
sprintf(ps, "ARRAY: type=%d\n", Type);
// More to be implemented later
} // end of Prints
} // end of Prints
/* -------------------------- Class MULAR ---------------------------- */

View file

@ -38,9 +38,7 @@ typedef class BLOCK *PBLOCK;
class DllExport BLOCK {
public:
void * operator new(size_t size, PGLOBAL g, void *p = NULL) {
if (trace(256))
htrc("New BLOCK: size=%d g=%p p=%p\n", size, g, p);
xtrc(256, "New BLOCK: size=%d g=%p p=%p\n", size, g, p);
return (PlugSubAlloc(g, p, size));
} // end of new

View file

@ -224,6 +224,7 @@ DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t);
DllExport char *PlugDup(PGLOBAL g, const char *str);
DllExport void *MakePtr(void *, OFFSET);
DllExport void htrc(char const *fmt, ...);
DllExport void xtrc(uint, char const* fmt, ...);
DllExport uint GetTraceValue(void);
#if defined(__cplusplus)

View file

@ -164,13 +164,13 @@
/***********************************************************************/
/* Initialize the ha_connect static members. */
/***********************************************************************/
#define SZCONV 1024 // Default TEXT conversion size
#define SZCONV 1024 // Default converted text size
#define SZWORK 67108864 // Default work area size 64M
#define SZWMIN 4194304 // Minimum work area size 4M
#define JSONMAX 10 // JSON Default max grp size
extern "C" {
char version[]= "Version 1.06.0010 June 21, 2019";
char version[]= "Version 1.06.0010 August 22, 2019";
#if defined(__WIN__)
char compver[]= "Version 1.06.0010 " __DATE__ " " __TIME__;
char slash= '\\';
@ -241,7 +241,9 @@ int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v);
void PushWarning(PGLOBAL g, THD *thd, int level);
bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, PCSZ host, PCSZ db,
PCSZ tab, PCSZ src, int port);
#if defined(ZIP_SUPPORT)
bool ZipLoadFile(PGLOBAL, PCSZ, PCSZ, PCSZ, bool, bool);
#endif // ZIP_SUPPORT
bool ExactInfo(void);
#if defined(CMGO_SUPPORT)
//void mongo_init(bool);
@ -994,11 +996,11 @@ static PCONNECT GetUser(THD *thd, PCONNECT xp)
pthread_mutex_unlock(&usrmut);
if (!xp) {
xp = new user_connect(thd);
xp= new user_connect(thd);
if (xp->user_init()) {
delete xp;
xp = NULL;
xp= NULL;
} // endif user_init
} // endif xp
@ -1146,48 +1148,48 @@ PCSZ GetListOption(PGLOBAL g, PCSZ opname, PCSZ oplist, PCSZ def)
return (char*)def;
char key[16], val[256];
char *pv, *pn, *pk = (char*)oplist;
PCSZ opval = def;
char *pv, *pn, *pk= (char*)oplist;
PCSZ opval= def;
int n;
while (*pk == ' ')
pk++;
for (; pk; pk = pn) {
pn = strchr(pk, ',');
pv = strchr(pk, '=');
for (; pk; pk= pn) {
pn= strchr(pk, ',');
pv= strchr(pk, '=');
if (pv && (!pn || pv < pn)) {
n = MY_MIN(static_cast<size_t>(pv - pk), sizeof(key) - 1);
n= MY_MIN(static_cast<size_t>(pv - pk), sizeof(key) - 1);
memcpy(key, pk, n);
while (n && key[n - 1] == ' ')
n--;
key[n] = 0;
key[n]= 0;
while (*(++pv) == ' ');
n = MY_MIN((pn ? pn - pv : strlen(pv)), sizeof(val) - 1);
n= MY_MIN((pn ? pn - pv : strlen(pv)), sizeof(val) - 1);
memcpy(val, pv, n);
while (n && val[n - 1] == ' ')
n--;
val[n] = 0;
val[n]= 0;
} else {
n = MY_MIN((pn ? pn - pk : strlen(pk)), sizeof(key) - 1);
n= MY_MIN((pn ? pn - pk : strlen(pk)), sizeof(key) - 1);
memcpy(key, pk, n);
while (n && key[n - 1] == ' ')
n--;
key[n] = 0;
val[0] = 0;
key[n]= 0;
val[0]= 0;
} // endif pv
if (!stricmp(opname, key)) {
opval = PlugDup(g, val);
opval= PlugDup(g, val);
break;
} else if (!pn)
break;
@ -1235,7 +1237,7 @@ PCSZ GetStringTableOption(PGLOBAL g, PTOS options, PCSZ opname, PCSZ sdef)
else if (!stricmp(opname, "Colist"))
opval= options->colist;
else if (!stricmp(opname, "Filter"))
opval = options->filter;
opval= options->filter;
else if (!stricmp(opname, "Data_charset"))
opval= options->data_charset;
else if (!stricmp(opname, "Http") || !stricmp(opname, "URL"))
@ -1272,7 +1274,7 @@ bool GetBooleanTableOption(PGLOBAL g, PTOS options, PCSZ opname, bool bdef)
else if (!stricmp(opname, "Header"))
opval= (options->header != 0); // Is Boolean for some table types
else if (!stricmp(opname, "Zipped"))
opval = options->zipped;
opval= options->zipped;
else if (options->oplist)
if ((pv= GetListOption(g, opname, options->oplist)))
opval= (!*pv || *pv == 'y' || *pv == 'Y' || atoi(pv) != 0);
@ -1366,8 +1368,8 @@ PCSZ ha_connect::GetStringOption(PCSZ opname, PCSZ sdef)
} else if (!stricmp(opname, "Query_String")) {
// This escapes everything and returns a wrong query
// opval = thd_query_string(table->in_use)->str;
opval = (PCSZ)PlugSubAlloc(xp->g, NULL,
// opval= thd_query_string(table->in_use)->str;
opval= (PCSZ)PlugSubAlloc(xp->g, NULL,
thd_query_string(table->in_use)->length + 1);
strcpy((char*)opval, thd_query_string(table->in_use)->str);
// sprintf((char*)opval, "%s", thd_query_string(table->in_use)->str);
@ -1388,7 +1390,7 @@ PCSZ ha_connect::GetStringOption(PCSZ opname, PCSZ sdef)
|| !stricmp(opname, "filename")
|| !stricmp(opname, "optname")
|| !stricmp(opname, "entry")))
opval = GetRealString(opval);
opval= GetRealString(opval);
if (!opval) {
if (sdef && !strcmp(sdef, "*")) {
@ -1517,7 +1519,7 @@ PFOS ha_connect::GetFieldOptionStruct(Field *fdp)
void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
{
const char *cp;
char *chset, v = 0;
char *chset, v= 0;
ha_field_option_struct *fop;
Field* fp;
Field* *fldp;
@ -1569,7 +1571,7 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
pcf->Fieldfmt= NULL;
} // endif fop
chset = (char *)fp->charset()->name;
chset= (char *)fp->charset()->name;
switch (fp->type()) {
case MYSQL_TYPE_BLOB:
@ -2075,10 +2077,10 @@ bool ha_connect::CheckColumnList(PGLOBAL g)
} catch (int n) {
if (trace(1))
htrc("Exception %d: %s\n", n, g->Message);
brc = true;
brc= true;
} catch (const char *msg) {
strcpy(g->Message, msg);
brc = true;
brc= true;
} // end catch
return brc;
@ -2205,9 +2207,9 @@ int ha_connect::MakeRecord(char *buf)
rc= fp->store(p, strlen(p), charset, CHECK_FIELD_WARN);
break;
case TYPE_BIN:
p = value->GetCharValue();
charset = &my_charset_bin;
rc = fp->store(p, strlen(p), charset, CHECK_FIELD_WARN);
p= value->GetCharValue();
charset= &my_charset_bin;
rc= fp->store(p, strlen(p), charset, CHECK_FIELD_WARN);
break;
case TYPE_DOUBLE:
rc= fp->store(value->GetFloatValue());
@ -2456,7 +2458,7 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q,
kfp= &table->key_info[active_index];
old_map= dbug_tmp_use_all_columns(table, table->write_set);
for (i = 0; i <= 1; i++) {
for (i= 0; i <= 1; i++) {
if (ranges[i] == NULL)
continue;
@ -2837,7 +2839,7 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond)
/***********************************************************************/
PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
{
AMT tty = filp->Type;
AMT tty= filp->Type;
char *body= filp->Body;
char *havg= filp->Having;
unsigned int i;
@ -2854,7 +2856,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
if (cond->type() == COND::COND_ITEM) {
char *pb0, *pb1, *pb2, *ph0= 0, *ph1= 0, *ph2= 0;
bool bb = false, bh = false;
bool bb= false, bh= false;
Item_cond *cond_item= (Item_cond *)cond;
if (x)
@ -2913,13 +2915,13 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
bb |= filp->Bd;
bh |= filp->Hv;
filp->Bd = filp->Hv = false;
filp->Bd= filp->Hv= false;
} else
return NULL;
if (bb) {
strcpy(pb1, ")");
filp->Bd = bb;
filp->Bd= bb;
} else
*pb0= 0;
@ -2927,13 +2929,13 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
if (bb && bh && vop == OP_OR) {
// Cannot or'ed a where clause with a having clause
bb= bh= 0;
*pb0 = 0;
*ph0 = 0;
*pb0= 0;
*ph0= 0;
} else if (bh) {
strcpy(ph1, ")");
filp->Hv= bh;
} else
*ph0 = 0;
*ph0= 0;
} // endif havg
@ -2946,7 +2948,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
Item_func *condf= (Item_func *)cond;
Item* *args= condf->arguments();
filp->Bd = filp->Hv = false;
filp->Bd= filp->Hv= false;
if (trace(1))
htrc("Func type=%d argnum=%d\n", condf->functype(),
@ -2962,10 +2964,10 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
case Item_func::GT_FUNC: vop= OP_GT; break;
case Item_func::LIKE_FUNC:
vop= OP_LIKE;
neg = ((Item_func_opt_neg *)condf)->negated;
neg= ((Item_func_opt_neg *)condf)->negated;
break;
case Item_func::ISNOTNULL_FUNC:
neg = true;
neg= true;
// fall through
case Item_func::ISNULL_FUNC: vop= OP_NULL; break;
case Item_func::IN_FUNC: vop= OP_IN; /* fall through */
@ -3023,12 +3025,12 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
} else {
bool h;
fnm = filp->Chk(pField->field->field_name.str, &h);
fnm= filp->Chk(pField->field->field_name.str, &h);
if (h && i && !ishav)
return NULL; // Having should be col VOP arg
else
ishav = h;
ishav= h;
} // endif's
@ -3079,7 +3081,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
if (!x) {
const char *p;
char *s = (ishav) ? havg : body;
char *s= (ishav) ? havg : body;
uint j, k, n;
// Append the value to the filter
@ -3136,37 +3138,37 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
strcat(s, "'}");
break;
default:
j = strlen(s);
s[j++] = '\'';
p = res->ptr();
n = res->length();
j= strlen(s);
s[j++]= '\'';
p= res->ptr();
n= res->length();
for (k = 0; k < n; k++) {
for (k= 0; k < n; k++) {
if (p[k] == '\'')
s[j++] = '\'';
s[j++]= '\'';
s[j++] = p[k];
s[j++]= p[k];
} // endfor k
s[j++] = '\'';
s[j] = 0;
s[j++]= '\'';
s[j]= 0;
} // endswitch field type
} else {
j = strlen(s);
s[j++] = '\'';
p = res->ptr();
n = res->length();
j= strlen(s);
s[j++]= '\'';
p= res->ptr();
n= res->length();
for (k = 0; k < n; k++) {
for (k= 0; k < n; k++) {
if (p[k] == '\'')
s[j++] = '\'';
s[j++]= '\'';
s[j++] = p[k];
s[j++]= p[k];
} // endfor k
s[j++] = '\'';
s[j] = 0;
s[j++]= '\'';
s[j]= 0;
} // endif tty
break;
@ -3190,7 +3192,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
} // endif's Type
if (!x) {
char *s = (ishav) ? havg : body;
char *s= (ishav) ? havg : body;
if (!i)
strcat(s, GetValStr(vop, neg));
@ -3204,11 +3206,11 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
} // endfor i
if (x)
filp->Op = vop;
filp->Op= vop;
else if (ishav)
filp->Hv = true;
filp->Hv= true;
else
filp->Bd = true;
filp->Bd= true;
} else {
if (trace(1))
@ -3258,21 +3260,21 @@ const COND *ha_connect::cond_push(const COND *cond)
PCFIL filp;
int rc;
if ((filp = tdbp->GetCondFil()) && tdbp->GetCond() == cond &&
if ((filp= tdbp->GetCondFil()) && tdbp->GetCond() == cond &&
filp->Idx == active_index && filp->Type == tty)
goto fin;
filp = new(g) CONDFIL(active_index, tty);
rc = filp->Init(g, this);
filp= new(g) CONDFIL(active_index, tty);
rc= filp->Init(g, this);
if (rc == RC_INFO) {
filp->Having = (char*)PlugSubAlloc(g, NULL, 256);
*filp->Having = 0;
filp->Having= (char*)PlugSubAlloc(g, NULL, 256);
*filp->Having= 0;
} else if (rc == RC_FX)
goto fin;
filp->Body = (char*)PlugSubAlloc(g, NULL, (x) ? 128 : 0);
*filp->Body = 0;
filp->Body= (char*)PlugSubAlloc(g, NULL, (x) ? 128 : 0);
*filp->Body= 0;
if (CheckCond(g, filp, cond)) {
if (filp->Having && strlen(filp->Having) > 255)
@ -3286,7 +3288,7 @@ const COND *ha_connect::cond_push(const COND *cond)
if (!x)
PlugSubAlloc(g, NULL, strlen(filp->Body) + 1);
else
cond = NULL; // Does this work?
cond= NULL; // Does this work?
tdbp->SetCondFil(filp);
} else if (x && cond)
@ -3336,8 +3338,8 @@ ha_rows ha_connect::records()
int ha_connect::check(THD* thd, HA_CHECK_OPT* check_opt)
{
int rc = HA_ADMIN_OK;
PGLOBAL g = ((table && table->in_use) ? GetPlug(table->in_use, xp) :
int rc= HA_ADMIN_OK;
PGLOBAL g= ((table && table->in_use) ? GetPlug(table->in_use, xp) :
(xp) ? xp->g : NULL);
DBUG_ENTER("ha_connect::check");
@ -3347,32 +3349,32 @@ int ha_connect::check(THD* thd, HA_CHECK_OPT* check_opt)
// Do not close the table if it was opened yet (possible?)
if (IsOpened()) {
if (IsPartitioned() && CheckColumnList(g)) // map can have been changed
rc = HA_ADMIN_CORRUPT;
rc= HA_ADMIN_CORRUPT;
else if (tdbp->OpenDB(g)) // Rewind table
rc = HA_ADMIN_CORRUPT;
rc= HA_ADMIN_CORRUPT;
} else if (xp->CheckQuery(valid_query_id)) {
tdbp = NULL; // Not valid anymore
tdbp= NULL; // Not valid anymore
if (OpenTable(g, false))
rc = HA_ADMIN_CORRUPT;
rc= HA_ADMIN_CORRUPT;
} else // possible?
DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR);
if (rc == HA_ADMIN_OK) {
TABTYPE type = GetTypeID(GetStringOption("Type", "*"));
TABTYPE type= GetTypeID(GetStringOption("Type", "*"));
if (IsFileType(type)) {
if (check_opt->flags & T_MEDIUM) {
// TO DO
do {
if ((rc = CntReadNext(g, tdbp)) == RC_FX)
if ((rc= CntReadNext(g, tdbp)) == RC_FX)
break;
} while (rc != RC_EF);
rc = (rc == RC_EF) ? HA_ADMIN_OK : HA_ADMIN_CORRUPT;
rc= (rc == RC_EF) ? HA_ADMIN_OK : HA_ADMIN_CORRUPT;
} else if (check_opt->flags & T_EXTEND) {
// TO DO
} // endif's flags
@ -3400,7 +3402,7 @@ bool ha_connect::get_error_message(int error, String* buf)
DBUG_ENTER("ha_connect::get_error_message");
if (xp && xp->g) {
PGLOBAL g = xp->g;
PGLOBAL g= xp->g;
if (trace(1))
htrc("GEM(%d): %s\n", error, g->Message);
@ -3509,32 +3511,32 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT*)
try {
// Ignore error on the opt file
dup->Check &= ~CHK_OPT;
tdbp = GetTDB(g);
tdbp= GetTDB(g);
dup->Check |= CHK_OPT;
if (tdbp && !tdbp->IsRemote()) {
bool dop = IsTypeIndexable(GetRealType(NULL));
bool dox = (tdbp->GetDef()->Indexable() == 1);
bool dop= IsTypeIndexable(GetRealType(NULL));
bool dox= (tdbp->GetDef()->Indexable() == 1);
if ((rc = ((PTDBASE)tdbp)->ResetTableOpt(g, dop, dox))) {
if ((rc= ((PTDBASE)tdbp)->ResetTableOpt(g, dop, dox))) {
if (rc == RC_INFO) {
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
rc = 0;
rc= 0;
} else
rc = HA_ERR_CRASHED_ON_USAGE; // Table must be repaired
rc= HA_ERR_CRASHED_ON_USAGE; // Table must be repaired
} // endif rc
} else if (!tdbp)
rc = HA_ERR_INTERNAL_ERROR;
rc= HA_ERR_INTERNAL_ERROR;
} catch (int n) {
if (trace(1))
htrc("Exception %d: %s\n", n, g->Message);
rc = HA_ERR_INTERNAL_ERROR;
rc= HA_ERR_INTERNAL_ERROR;
} catch (const char *msg) {
strcpy(g->Message, msg);
rc = HA_ERR_INTERNAL_ERROR;
rc= HA_ERR_INTERNAL_ERROR;
} // end catch
if (rc)
@ -4234,7 +4236,7 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos)
tdbp->SetFilter(NULL);
rc= rnd_next(buf);
} else {
PGLOBAL g = GetPlug((table) ? table->in_use : NULL, xp);
PGLOBAL g= GetPlug((table) ? table->in_use : NULL, xp);
// strcpy(g->Message, "Not supported by this table type");
my_message(ER_ILLEGAL_HA, g->Message, MYF(0));
rc= HA_ERR_INTERNAL_ERROR;
@ -4318,12 +4320,12 @@ int ha_connect::info(uint flag)
} else
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Should never happen
if (!(tdbp = GetTDB(g))) {
if (!(tdbp= GetTDB(g))) {
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
} // endif tdbp
valid_info = false;
valid_info= false;
} // endif tdbp
if (!valid_info) {
@ -4603,13 +4605,13 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
// newmode= MODE_UPDATE; // To be checked
// break;
case SQLCOM_DELETE_MULTI:
*cras = true;
*cras= true;
case SQLCOM_DELETE:
case SQLCOM_TRUNCATE:
newmode= MODE_DELETE;
break;
case SQLCOM_UPDATE_MULTI:
*cras = true;
*cras= true;
case SQLCOM_UPDATE:
newmode= MODE_UPDATE;
break;
@ -4637,7 +4639,7 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
break;
// } // endif partitioned
case SQLCOM_REPAIR: // TODO implement it
newmode = MODE_UPDATE;
newmode= MODE_UPDATE;
break;
default:
htrc("Unsupported sql_command=%d\n", thd_sql_command(thd));
@ -4836,7 +4838,7 @@ int ha_connect::external_lock(THD *thd, int lock_type)
DBUG_RETURN(0);
} else if (g->Xchk) {
if (!tdbp) {
if (!(tdbp = GetTDB(g))) {
if (!(tdbp= GetTDB(g))) {
// DBUG_RETURN(HA_ERR_INTERNAL_ERROR); causes assert error
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
DBUG_RETURN(0);
@ -5060,7 +5062,7 @@ THR_LOCK_DATA **ha_connect::store_lock(THD *,
{
if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
lock.type=lock_type;
*to++ = &lock;
*to++= &lock;
return to;
}
@ -5337,7 +5339,7 @@ static bool add_field(String *sql, const char *field_name, int typ, int len,
int dec, char *key, uint tm, const char *rem, char *dft,
char *xtra, char *fmt, int flag, bool dbf, char v)
{
char var = (len > 255) ? 'V' : v;
char var= (len > 255) ? 'V' : v;
bool q, error= false;
const char *type= PLGtoMYSQLtype(typ, dbf, var);
@ -5381,9 +5383,9 @@ static bool add_field(String *sql, const char *field_name, int typ, int len,
error|= sql->append(" DEFAULT ");
if (typ == TYPE_DATE)
q = (strspn(dft, "0123456789 -:/") == strlen(dft));
q= (strspn(dft, "0123456789 -:/") == strlen(dft));
else
q = !IsTypeNum(typ);
q= !IsTypeNum(typ);
if (q) {
error|= sql->append("'");
@ -5540,8 +5542,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
PCSZ nsp= NULL, cls= NULL;
#endif // __WIN__
//int hdr, mxe;
int port = 0, mxr = 0, rc = 0, mul = 0, lrecl = 0;
//PCSZ tabtyp = NULL;
int port= 0, mxr= 0, rc= 0, mul= 0, lrecl= 0;
//PCSZ tabtyp= NULL;
#if defined(ODBC_SUPPORT)
POPARM sop= NULL;
PCSZ ucnc= NULL;
@ -5605,7 +5607,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#endif // __WIN__
port= atoi(GetListOption(g, "port", topt->oplist, "0"));
#if defined(ODBC_SUPPORT)
// tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL);
// tabtyp= GetListOption(g, "Tabtype", topt->oplist, NULL);
mxr= atoi(GetListOption(g,"maxres", topt->oplist, "0"));
cto= atoi(GetListOption(g,"ConnectTimeout", topt->oplist, "-1"));
qto= atoi(GetListOption(g,"QueryTimeout", topt->oplist, "-1"));
@ -5622,9 +5624,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if defined(ZIP_SUPPORT)
zfn= GetListOption(g, "Zipfile", topt->oplist, NULL);
#endif // ZIP_SUPPORT
}
else
{
} else {
host= "localhost";
user= ((ttp == TAB_ODBC || ttp == TAB_JDBC) ? NULL : "root");
} // endif option_list
@ -5639,8 +5639,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
ttp= GetTypeID(topt->type);
sprintf(g->Message, "No table_type. Was set to %s", topt->type);
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
}
else if (ttp == TAB_NIY) {
} else if (ttp == TAB_NIY) {
sprintf(g->Message, "Unsupported table type %s", topt->type);
rc= HA_ERR_INTERNAL_ERROR;
goto err;
@ -5693,7 +5692,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if defined(PROMPT_OK)
} else if (!stricmp(thd->main_security_ctx.host, "localhost")
&& cop == 1) {
if ((dsn = ODBCCheckConnection(g, dsn, cop)) != NULL) {
if ((dsn= ODBCCheckConnection(g, dsn, cop)) != NULL) {
thd->make_lex_string(&create_info->connect_string, dsn, strlen(dsn));
ok= true;
} // endif dsn
@ -5729,7 +5728,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
jdef->SetName(create_info->alias.str);
sjp= (PJPARM)PlugSubAlloc(g, NULL, sizeof(JDBCPARM));
sjp->Driver= driver;
// sjp->Properties = prop;
// sjp->Properties= prop;
sjp->Fsize= 0;
sjp->Scrollable= false;
@ -6027,7 +6026,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
if (fnc != FNC_NO || src || ttp == TAB_PIVOT) {
// Catalog like table
for (crp = qrp->Colresp; !rc && crp; crp = crp->Next) {
for (crp= qrp->Colresp; !rc && crp; crp= crp->Next) {
cnm= (ttp == TAB_PIVOT) ? crp->Name : encode(g, crp->Name);
typ= crp->Type;
len= crp->Length;
@ -6060,8 +6059,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
goto err;
} // endif !nblin
for (i = 0; !rc && i < qrp->Nblin; i++) {
typ= len = prec = dec = 0;
for (i= 0; !rc && i < qrp->Nblin; i++) {
typ= len= prec= dec= 0;
tm= NOT_NULL_FLAG;
cnm= (char*)"noname";
dft= xtra= key= fmt= tn= NULL;
@ -6449,7 +6448,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
host= mydef->GetHostname();
if (mydef->GetTabschema())
db = mydef->GetTabschema();
db= mydef->GetTabschema();
if (mydef->GetTabname())
tab= mydef->GetTabname();
@ -6532,7 +6531,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
} // endif type JSON
if (type == TAB_CSV) {
const char *sep = options->separator;
const char *sep= options->separator;
if (sep && strlen(sep) > 1) {
sprintf(g->Message, "Invalid separator %s", sep);
@ -6732,16 +6731,17 @@ int ha_connect::create(const char *name, TABLE *table_arg,
htrc("xchk=%p createas=%d\n", g->Xchk, g->Createas);
if (options->zipped) {
#if defined(ZIP_SUPPORT)
// 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);
if (fn) {
char zbuf[_MAX_PATH], buf[_MAX_PATH], dbpath[_MAX_PATH];
PCSZ entry = GetListOption(g, "Entry", options->oplist, NULL);
PCSZ a = GetListOption(g, "Append", options->oplist, "NO");
bool append = *a == '1' || *a == 'Y' || *a == 'y' || !stricmp(a, "ON");
PCSZ m = GetListOption(g, "Mulentries", options->oplist, "NO");
bool mul = *m == '1' || *m == 'Y' || *m == 'y' || !stricmp(m, "ON");
PCSZ entry= GetListOption(g, "Entry", options->oplist, NULL);
PCSZ a= GetListOption(g, "Append", options->oplist, "NO");
bool append= *a == '1' || *a == 'Y' || *a == 'y' || !stricmp(a, "ON");
PCSZ m= GetListOption(g, "Mulentries", options->oplist, "NO");
bool mul= *m == '1' || *m == 'Y' || *m == 'y' || !stricmp(m, "ON");
if (!entry && !mul) {
my_message(ER_UNKNOWN_ERROR, "Missing entry name", MYF(0));
@ -6758,7 +6758,10 @@ int ha_connect::create(const char *name, TABLE *table_arg,
} // endif LoadFile
} // endif fn
#else // !ZIP_SUPPORT
my_message(ER_UNKNOWN_ERROR, "Option ZIP not supported", MYF(0));
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
#endif // !ZIP_SUPPORT
} // endif zipped
// To check whether indexes have to be made or remade
@ -6809,7 +6812,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
if (SetDataPath(g, table_arg->s->db.str)) {
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
rc = HA_ERR_INTERNAL_ERROR;
rc= HA_ERR_INTERNAL_ERROR;
} else if (cat) {
if (part_info)
strncpy(partname,
@ -7153,7 +7156,7 @@ ha_connect::check_if_supported_inplace_alter(TABLE *altered_table,
/*
ALTER TABLE tbl_name CONVERT TO CHARACTER SET .. and
ALTER TABLE table_name DEFAULT CHARSET = .. most likely
ALTER TABLE table_name DEFAULT CHARSET= .. most likely
change column charsets and so not supported in-place through
old API.

View 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

View file

@ -122,11 +122,11 @@ char *GetPluginDir(void)
/***********************************************************************/
TABTYPE GetTypeID(const char *type)
{
return (!type) ? TAB_UNDEF
return (!type) ? TAB_UNDEF
: (!stricmp(type, "DOS")) ? TAB_DOS
: (!stricmp(type, "FIX")) ? TAB_FIX
: (!stricmp(type, "BIN")) ? TAB_BIN
: (!stricmp(type, "CSV")) ? TAB_CSV
: (!stricmp(type, "CSV")) ? TAB_CSV
: (!stricmp(type, "FMT")) ? TAB_FMT
: (!stricmp(type, "DBF")) ? TAB_DBF
#if defined(XML_SUPPORT)
@ -138,30 +138,30 @@ TABTYPE GetTypeID(const char *type)
: (!stricmp(type, "ODBC")) ? TAB_ODBC
#endif
#if defined(JAVA_SUPPORT)
: (!stricmp(type, "JDBC")) ? TAB_JDBC
: (!stricmp(type, "JDBC")) ? TAB_JDBC
#endif
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
: (!stricmp(type, "MONGO") && MongoEnabled()) ? TAB_MONGO
: (!stricmp(type, "MONGO") && MongoEnabled()) ? TAB_MONGO
#endif
: (!stricmp(type, "MYSQL")) ? TAB_MYSQL
: (!stricmp(type, "MYSQL")) ? TAB_MYSQL
: (!stricmp(type, "MYPRX")) ? TAB_MYSQL
: (!stricmp(type, "DIR")) ? TAB_DIR
#if defined(__WIN__)
: (!stricmp(type, "MAC")) ? TAB_MAC
: (!stricmp(type, "WMI")) ? TAB_WMI
: (!stricmp(type, "MAC")) ? TAB_MAC
: (!stricmp(type, "WMI")) ? TAB_WMI
#endif
: (!stricmp(type, "TBL")) ? TAB_TBL
: (!stricmp(type, "XCOL")) ? TAB_XCL
: (!stricmp(type, "OCCUR")) ? TAB_OCCUR
: (!stricmp(type, "TBL")) ? TAB_TBL
: (!stricmp(type, "XCOL")) ? TAB_XCL
: (!stricmp(type, "OCCUR")) ? TAB_OCCUR
: (!stricmp(type, "CATLG")) ? TAB_PRX // Legacy
: (!stricmp(type, "PROXY")) ? TAB_PRX
: (!stricmp(type, "PIVOT")) ? TAB_PIVOT
: (!stricmp(type, "VIR")) ? TAB_VIR
: (!stricmp(type, "JSON")) ? TAB_JSON
#if defined(ZIP_SUPPORT)
: (!stricmp(type, "ZIP")) ? TAB_ZIP
: (!stricmp(type, "ZIP")) ? TAB_ZIP
#endif
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
} // end of GetTypeID
/***********************************************************************/
@ -171,11 +171,11 @@ bool IsFileType(TABTYPE type)
{
bool isfile;
switch (type) {
switch (type) {
case TAB_DOS:
case TAB_FIX:
case TAB_BIN:
case TAB_CSV:
case TAB_CSV:
case TAB_FMT:
case TAB_DBF:
case TAB_XML:
@ -201,7 +201,7 @@ bool IsExactType(TABTYPE type)
{
bool exact;
switch (type) {
switch (type) {
case TAB_FIX:
case TAB_BIN:
case TAB_DBF:
@ -226,7 +226,7 @@ bool IsTypeNullable(TABTYPE type)
{
bool nullable;
switch (type) {
switch (type) {
case TAB_MAC:
case TAB_DIR:
nullable= false;
@ -246,7 +246,7 @@ bool IsTypeFixed(TABTYPE type)
{
bool fix;
switch (type) {
switch (type) {
case TAB_FIX:
case TAB_BIN:
case TAB_VEC:
@ -268,7 +268,7 @@ bool IsTypeIndexable(TABTYPE type)
{
bool idx;
switch (type) {
switch (type) {
case TAB_DOS:
case TAB_CSV:
case TAB_FMT:
@ -294,7 +294,7 @@ int GetIndexType(TABTYPE type)
{
int xtyp;
switch (type) {
switch (type) {
case TAB_DOS:
case TAB_CSV:
case TAB_FMT:
@ -307,9 +307,9 @@ int GetIndexType(TABTYPE type)
break;
case TAB_MYSQL:
case TAB_ODBC:
case TAB_JDBC:
case TAB_MONGO:
xtyp= 2;
case TAB_JDBC:
case TAB_MONGO:
xtyp= 2;
break;
case TAB_VIR:
xtyp= 3;
@ -381,7 +381,7 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info)
return NULL;
} else
PlugSetPath(soname, module, GetPluginDir());
// The exported name is always in uppercase
for (int i = 0; ; i++) {
c = subtype[i];
@ -458,7 +458,7 @@ CATALOG::CATALOG(void)
memset(&Ctb, 0, sizeof(CURTAB));
Cbuf= NULL;
Cblen= 0;
DefHuge= false;
DefHuge= false;
} // end of CATALOG constructor
/* -------------------------- Class MYCAT ---------------------------- */
@ -468,7 +468,7 @@ CATALOG::CATALOG(void)
/***********************************************************************/
MYCAT::MYCAT(PHC hc) : CATALOG()
{
Hc= hc;
Hc= hc;
DefHuge= false;
} // end of MYCAT constructor
@ -485,16 +485,23 @@ void MYCAT::Reset(void)
/***********************************************************************/
PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
LPCSTR type, PRELDEF *)
{
if (trace(1))
printf("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type));
{
PRELDEF tdp= NULL;
// If not specified get the type of this table
if (trace(1))
htrc("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type));
// If not specified get the type of this table
//if (!type)
// type= Hc->GetStringOption("Type","*");
return MakeTableDesc(g, tablep, type);
} // end of GetTableDesc
tdp= MakeTableDesc(g, tablep, type);
if (trace(1))
htrc("GetTableDesc: tdp=%p\n", tdp);
return tdp;
} // end of GetTableDesc
/***********************************************************************/
/* MakeTableDesc: make a table/view description. */
@ -503,22 +510,22 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
{
TABTYPE tc;
LPCSTR name= (PSZ)PlugDup(g, tablep->GetName());
LPCSTR schema= (PSZ)PlugDup(g, tablep->GetSchema());
LPCSTR name= (PSZ)PlugDup(g, tablep->GetName());
LPCSTR schema= (PSZ)PlugDup(g, tablep->GetSchema());
PRELDEF tdp= NULL;
if (trace(1))
printf("MakeTableDesc: name=%s schema=%s am=%s\n",
name, SVP(schema), SVP(am));
if (trace(1))
htrc("MakeTableDesc: name=%s schema=%s am=%s\n",
name, SVP(schema), SVP(am));
/*********************************************************************/
/* Get a unique enum identifier for types. */
/*********************************************************************/
if (!am) {
tc= Hc->GetRealType();
am= Hc->GetStringOption("Type","*");
} else
tc= GetTypeID(am);
if (!am) {
tc= Hc->GetRealType();
am= Hc->GetStringOption("Type","*");
} else
tc= GetTypeID(am);
switch (tc) {
case TAB_FIX:
@ -533,49 +540,52 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
case TAB_XML: tdp= new(g) XMLDEF; break;
#endif // XML_SUPPORT
#if defined(VCT_SUPPORT)
case TAB_VEC: tdp = new(g) VCTDEF; break;
case TAB_VEC: tdp = new(g) VCTDEF; break;
#endif // VCT_SUPPORT
#if defined(ODBC_SUPPORT)
case TAB_ODBC: tdp= new(g) ODBCDEF; break;
#endif // ODBC_SUPPORT
#if defined(JAVA_SUPPORT)
case TAB_JDBC: tdp= new(g) JDBCDEF; break;
case TAB_JDBC: tdp= new(g) JDBCDEF; break;
#endif // JAVA_SUPPORT
#if defined(__WIN__)
case TAB_MAC: tdp= new(g) MACDEF; break;
case TAB_WMI: tdp= new(g) WMIDEF; break;
#endif // __WIN__
case TAB_OEM: tdp= new(g) OEMDEF; break;
case TAB_TBL: tdp= new(g) TBLDEF; break;
case TAB_XCL: tdp= new(g) XCLDEF; break;
case TAB_PRX: tdp= new(g) PRXDEF; break;
case TAB_OCCUR: tdp= new(g) OCCURDEF; break;
case TAB_MYSQL: tdp= new(g) MYSQLDEF; break;
case TAB_TBL: tdp= new(g) TBLDEF; break;
case TAB_XCL: tdp= new(g) XCLDEF; break;
case TAB_PRX: tdp= new(g) PRXDEF; break;
case TAB_OCCUR: tdp= new(g) OCCURDEF; break;
case TAB_MYSQL: tdp= new(g) MYSQLDEF; break;
case TAB_PIVOT: tdp= new(g) PIVOTDEF; break;
case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break;
#if defined(ZIP_SUPPORT)
case TAB_ZIP: tdp = new(g) ZIPDEF; break;
case TAB_ZIP: tdp = new(g) ZIPDEF; break;
#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)
case TAB_MONGO:
if (MongoEnabled()) {
tdp = new(g) MGODEF;
break;
} // endif enabled
// fall through
case TAB_MONGO:
if (MongoEnabled()) {
tdp = new(g) MGODEF;
break;
} // endif enabled
// fall through
#endif // JAVA_SUPPORT || CMGO_SUPPORT
default:
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
default:
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
} // endswitch
// Do make the table/view definition
if (tdp && tdp->Define(g, this, name, schema, am))
tdp= NULL;
if (trace(1))
htrc("Table %s made\n", am);
return tdp;
} // end of MakeTableDesc
@ -588,26 +598,29 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type)
PTDB tdbp= NULL;
// LPCSTR name= tablep->GetName();
if (trace(1))
printf("GetTableDB: name=%s\n", tablep->GetName());
if (trace(1))
htrc("GetTableDB: name=%s\n", tablep->GetName());
// Look for the description of the requested table
tdp= GetTableDesc(g, tablep, type);
if (tdp) {
if (trace(1))
printf("tdb=%p type=%s\n", tdp, tdp->GetType());
if (trace(1))
htrc("tdb=%p type=%s\n", tdp, tdp->GetType());
if (tablep->GetSchema())
tdp->Database = SetPath(g, tablep->GetSchema());
if (trace(2))
htrc("Going to get table...\n");
if (tablep->GetSchema())
tdp->Database = SetPath(g, tablep->GetSchema());
tdbp= tdp->GetTable(g, mode);
} // endif tdp
} // endif tdp
if (tdbp) {
if (trace(1))
printf("tdbp=%p name=%s amtype=%d\n", tdbp, tdbp->GetName(),
tdbp->GetAmType());
if (trace(1))
htrc("tdbp=%p name=%s amtype=%d\n", tdbp, tdbp->GetName(),
tdbp->GetAmType());
tablep->SetTo_Tdb(tdbp);
tdbp->SetTable(tablep);
tdbp->SetMode(mode);

View file

@ -26,7 +26,7 @@ fname ftype size
boys .txt 282
boyswin .txt 288
INSERT INTO t1 VALUES ('','','','');
ERROR 22007: Incorrect double value: '' for column 'size' at row 1
ERROR 22007: Incorrect double value: '' for column `test`.`t1`.`size` at row 1
DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.txt';
ERROR HY000: Cannot get column info for table type DIR

View file

@ -158,47 +158,47 @@ TRANSLATOR NULL
PUBLISHER Eyrolles Paris
DATEPUB 1998
SELECT LOAD_FILE('MYSQLD_DATADIR/test/xsample2.xml') AS xml;
xml <?xml version="1.0" encoding="UTF-8"?>
<BIBLIO SUBJECT="XML">
<BOOK ISBN="9782212090819" LANG="fr" SUBJECT="applications">
<AUTHOR>
<FIRSTNAME>Jean-Christophe</FIRSTNAME>
<LASTNAME>Bernadac</LASTNAME>
</AUTHOR>
<AUTHOR>
<FIRSTNAME>François</FIRSTNAME>
<LASTNAME>Knab</LASTNAME>
</AUTHOR>
<TITLE>Construire une application XML</TITLE>
<PUBLISHER>
<NAME>Eyrolles</NAME>
<PLACE>Paris</PLACE>
</PUBLISHER>
<DATEPUB>1999</DATEPUB>
</BOOK>
<BOOK ISBN="9782840825685" LANG="fr" SUBJECT="applications">
<AUTHOR>
<FIRSTNAME>William J.</FIRSTNAME>
<LASTNAME>Pardi</LASTNAME>
</AUTHOR>
<TRANSLATOR PREFIX="adapté de l'anglais par">
<FIRSTNAME>James</FIRSTNAME>
<LASTNAME>Guerin</LASTNAME>
</TRANSLATOR>
<TITLE>XML en Action</TITLE>
<PUBLISHER>
<NAME>Microsoft Press</NAME>
<PLACE>Paris</PLACE>
</PUBLISHER>
<DATEPUB>1999</DATEPUB>
</BOOK>
<BOOK ISBN="9782212090529" LANG="fr" SUBJECT="général">
<AUTHOR>Alain Michard</AUTHOR>
<TITLE>XML, Langage et Applications</TITLE>
<PUBLISHER>Eyrolles Paris</PUBLISHER>
<DATEPUB>1998</DATEPUB>
</BOOK>
</BIBLIO>
xml <?xml version="1.0" encoding="UTF-8"?>
<BIBLIO SUBJECT="XML">
<BOOK ISBN="9782212090819" LANG="fr" SUBJECT="applications">
<AUTHOR>
<FIRSTNAME>Jean-Christophe</FIRSTNAME>
<LASTNAME>Bernadac</LASTNAME>
</AUTHOR>
<AUTHOR>
<FIRSTNAME>François</FIRSTNAME>
<LASTNAME>Knab</LASTNAME>
</AUTHOR>
<TITLE>Construire une application XML</TITLE>
<PUBLISHER>
<NAME>Eyrolles</NAME>
<PLACE>Paris</PLACE>
</PUBLISHER>
<DATEPUB>1999</DATEPUB>
</BOOK>
<BOOK ISBN="9782840825685" LANG="fr" SUBJECT="applications">
<AUTHOR>
<FIRSTNAME>William J.</FIRSTNAME>
<LASTNAME>Pardi</LASTNAME>
</AUTHOR>
<TRANSLATOR PREFIX="adapté de l'anglais par">
<FIRSTNAME>James</FIRSTNAME>
<LASTNAME>Guerin</LASTNAME>
</TRANSLATOR>
<TITLE>XML en Action</TITLE>
<PUBLISHER>
<NAME>Microsoft Press</NAME>
<PLACE>Paris</PLACE>
</PUBLISHER>
<DATEPUB>1999</DATEPUB>
</BOOK>
<BOOK ISBN="9782212090529" LANG="fr" SUBJECT="général">
<AUTHOR>Alain Michard</AUTHOR>
<TITLE>XML, Langage et Applications</TITLE>
<PUBLISHER>Eyrolles Paris</PUBLISHER>
<DATEPUB>1998</DATEPUB>
</BOOK>
</BIBLIO>
DROP TABLE t1;
#
@ -323,7 +323,7 @@ HEX(c) 3F3F3F3F3F3F3F
Warnings:
Level Warning
Code 1366
Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column 'c' at row 1
Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1
Level Warning
Code 1105
Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1
@ -374,7 +374,7 @@ INSERT INTO t1 VALUES (_cp1251 0xC0C1C2C3);
Warnings:
Level Warning
Code 1105
Message Com error: Unable to save character to 'iso-8859-1' encoding.
Message Com error: Unable to save character to 'iso-8859-1' encoding.
INSERT INTO t1 VALUES ('&<>"\'');
SELECT node, hex(node) FROM t1;
@ -383,11 +383,11 @@ hex(node) 263C3E2227
DROP TABLE t1;
SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml');
SELECT CAST(@a AS CHAR CHARACTER SET latin1);
CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
<!-- Created by the MariaDB CONNECT Storage Engine-->
<t1>
<line>
<node>&amp;&lt;&gt;"'</node>
</line>
</t1>
CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
<!-- Created by the MariaDB CONNECT Storage Engine-->
<t1>
<line>
<node>&amp;&lt;&gt;"'</node>
</line>
</t1>

View file

@ -325,7 +325,7 @@ HEX(c) 3F3F3F3F3F3F3F
Warnings:
Level Warning
Code 1366
Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column 'c' at row 1
Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1
Level Warning
Code 1105
Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1

View file

@ -3,7 +3,11 @@
#define __OSUTIL_H__
#if defined(UNIX) || defined(UNIV_LINUX)
#if defined(MARIADB)
#include "my_global.h"
#else
#include "mini-global.h"
#endif
#include <errno.h>
#include <stddef.h>
#include "os.h"

View file

@ -2,11 +2,11 @@
/* */
/* PROGRAM NAME: PLUGUTIL */
/* ------------- */
/* Version 3.0 */
/* Version 3.1 */
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 1993-2017 */
/* (C) Copyright to the author Olivier BERTRAND 1993-2019 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
@ -110,22 +110,32 @@ ACTIVITY defActivity = { /* Describes activity and language */
#include "rcmsg.h"
#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. */
/**************************************************************************/
void htrc(char const *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
void htrc(char const* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
//if (trace == 1)
// vfprintf(debug, fmt, ap);
//else
vfprintf(stderr, fmt, ap);
va_end (ap);
} // end of htrc
vfprintf(stderr, fmt, ap);
va_end(ap);
} // end of htrc
/***********************************************************************/
/* Plug initialization routine. */

View file

@ -81,51 +81,51 @@ RELDEF::RELDEF(void)
/* This function return a pointer to the Table Option Struct. */
/***********************************************************************/
PTOS RELDEF::GetTopt(void)
{
return Hc->GetTableOptionStruct();
} // end of GetTopt
{
return Hc->GetTableOptionStruct();
} // end of GetTopt
/***********************************************************************/
/* This function sets an integer table information. */
/***********************************************************************/
bool RELDEF::SetIntCatInfo(PCSZ what, int n)
{
return Hc->SetIntegerOption(what, n);
} // end of SetIntCatInfo
{
return Hc->SetIntegerOption(what, n);
} // end of SetIntCatInfo
/***********************************************************************/
/* This function returns integer table information. */
/***********************************************************************/
int RELDEF::GetIntCatInfo(PCSZ what, int idef)
{
int n= Hc->GetIntegerOption(what);
{
int n= Hc->GetIntegerOption(what);
return (n == NO_IVAL) ? idef : n;
} // end of GetIntCatInfo
return (n == NO_IVAL) ? idef : n;
} // end of GetIntCatInfo
/***********************************************************************/
/* This function returns Boolean table information. */
/***********************************************************************/
bool RELDEF::GetBoolCatInfo(PCSZ what, bool bdef)
{
bool b= Hc->GetBooleanOption(what, bdef);
{
bool b= Hc->GetBooleanOption(what, bdef);
return b;
} // end of GetBoolCatInfo
return b;
} // end of GetBoolCatInfo
/***********************************************************************/
/* This function returns size catalog information. */
/***********************************************************************/
int RELDEF::GetSizeCatInfo(PCSZ what, PCSZ sdef)
{
char c;
PCSZ s;
{
char c;
PCSZ s;
int i, n= 0;
if (!(s= Hc->GetStringOption(what)))
s= sdef;
if (!(s= Hc->GetStringOption(what)))
s= sdef;
if ((i= sscanf(s, " %d %c ", &n, &c)) == 2)
if ((i= sscanf(s, " %d %c ", &n, &c)) == 2)
switch (toupper(c)) {
case 'M':
n *= 1024;
@ -141,41 +141,41 @@ int RELDEF::GetSizeCatInfo(PCSZ what, PCSZ sdef)
/* This function sets char table information in buf. */
/***********************************************************************/
int RELDEF::GetCharCatInfo(PCSZ what, PCSZ sdef, char *buf, int size)
{
PCSZ s= Hc->GetStringOption(what);
{
PCSZ s= Hc->GetStringOption(what);
strncpy(buf, ((s) ? s : sdef), size);
return size;
} // end of GetCharCatInfo
strncpy(buf, ((s) ? s : sdef), size);
return size;
} // end of GetCharCatInfo
/***********************************************************************/
/* To be used by any TDB's. */
/***********************************************************************/
bool RELDEF::Partitioned(void)
{
return Hc->IsPartitioned();
} // end of Partitioned
{
return Hc->IsPartitioned();
} // end of Partitioned
/***********************************************************************/
/* This function returns string table information. */
/* Default parameter is "*" to get the handler default. */
/***********************************************************************/
char *RELDEF::GetStringCatInfo(PGLOBAL g, PCSZ what, PCSZ sdef)
{
char *sval = NULL;
PCSZ name, s= Hc->GetStringOption(what, sdef);
if (s) {
{
char *sval = NULL;
PCSZ name, s= Hc->GetStringOption(what, sdef);
if (s) {
if (!Hc->IsPartitioned() ||
(stricmp(what, "filename") && stricmp(what, "tabname")
&& stricmp(what, "connect")))
sval= PlugDup(g, s);
sval= PlugDup(g, s);
else
sval= (char*)s;
} else if (!stricmp(what, "filename")) {
// Return default file name
PCSZ ftype= Hc->GetStringOption("Type", "*");
PCSZ ftype= Hc->GetStringOption("Type", "*");
int i, n;
if (IsFileType(GetTypeID(ftype))) {
@ -183,7 +183,7 @@ char *RELDEF::GetStringCatInfo(PGLOBAL g, PCSZ what, PCSZ sdef)
sval= (char*)PlugSubAlloc(g, NULL, strlen(name) + 12);
strcat(strcpy(sval, name), ".");
n= strlen(sval);
// Fold ftype to lower case
for (i= 0; i < 12; i++)
if (!ftype[i]) {
@ -196,8 +196,8 @@ char *RELDEF::GetStringCatInfo(PGLOBAL g, PCSZ what, PCSZ sdef)
} // endif s
return sval;
} // end of GetStringCatInfo
return sval;
} // end of GetStringCatInfo
/* --------------------------- Class TABDEF -------------------------- */
@ -223,14 +223,14 @@ TABDEF::TABDEF(void)
/***********************************************************************/
/* Define: initialize the table definition block from XDB file. */
/***********************************************************************/
bool TABDEF::Define(PGLOBAL g, PCATLG cat,
LPCSTR name, LPCSTR schema, LPCSTR am)
bool TABDEF::Define(PGLOBAL g, PCATLG cat,
LPCSTR name, LPCSTR schema, LPCSTR am)
{
int poff = 0;
Hc = ((MYCAT*)cat)->GetHandler();
Name = (PSZ)name;
Schema = (PSZ)Hc->GetDBName(schema);
Hc = ((MYCAT*)cat)->GetHandler();
Name = (PSZ)name;
Schema = (PSZ)Hc->GetDBName(schema);
Cat = cat;
Catfunc = GetFuncID(GetStringCatInfo(g, "Catfunc", NULL));
Elemt = GetIntCatInfo("Elements", 0);
@ -263,14 +263,14 @@ PCSZ TABDEF::GetPath(void)
/* This function returns column table information. */
/***********************************************************************/
int TABDEF::GetColCatInfo(PGLOBAL g)
{
char *type= GetStringCatInfo(g, "Type", "*");
{
char *type= GetStringCatInfo(g, "Type", "*");
char c, fty, eds;
int i, n, loff, poff, nof, nlg;
void *field= NULL;
int i, n, loff, poff, nof, nlg;
void *field= NULL;
TABTYPE tc;
PCOLDEF cdp, lcdp= NULL, tocols= NULL;
PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO));
PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO));
memset(pcf, 0, sizeof(COLINFO));
@ -278,33 +278,33 @@ int TABDEF::GetColCatInfo(PGLOBAL g)
tc= (Catfunc == FNC_NO) ? GetTypeID(type) : TAB_PRX;
// Take care of the column definitions
i= poff= nof= nlg= 0;
i= poff= nof= nlg= 0;
#if defined(__WIN__)
// Offsets of HTML and DIR tables start from 0, DBF at 1
loff= (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0;
// Offsets of HTML and DIR tables start from 0, DBF at 1
loff= (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0;
#else // !__WIN__
// Offsets of HTML tables start from 0, DIR and DBF at 1
loff = (tc == TAB_DBF || tc == TAB_DIR) ? 1 : (tc == TAB_XML) ? -1 : 0;
// Offsets of HTML tables start from 0, DIR and DBF at 1
loff = (tc == TAB_DBF || tc == TAB_DIR) ? 1 : (tc == TAB_XML) ? -1 : 0;
#endif // !__WIN__
while (true) {
// Default Offset depends on table type
switch (tc) {
// Default Offset depends on table type
switch (tc) {
case TAB_DOS:
case TAB_FIX:
case TAB_BIN:
case TAB_VEC:
case TAB_DBF:
poff= loff + nof; // Default next offset
nlg= MY_MAX(nlg, poff); // Default lrecl
poff= loff + nof; // Default next offset
nlg= MY_MAX(nlg, poff); // Default lrecl
break;
case TAB_CSV:
case TAB_FMT:
nlg+= nof;
nlg+= nof;
case TAB_DIR:
case TAB_XML:
poff= loff + (pcf->Flags & U_VIRTUAL ? 0 : 1);
poff= loff + (pcf->Flags & U_VIRTUAL ? 0 : 1);
break;
case TAB_INI:
case TAB_MAC:
@ -316,39 +316,39 @@ int TABDEF::GetColCatInfo(PGLOBAL g)
poff = 0; // Offset represents an independant flag
break;
default: // VCT PLG ODBC JDBC MYSQL WMI...
poff = 0; // NA
poff = 0; // NA
break;
} // endswitch tc
} // endswitch tc
// do {
field= Hc->GetColumnOption(g, field, pcf);
// do {
field= Hc->GetColumnOption(g, field, pcf);
// } while (field && (*pcf->Name =='*' /*|| pcf->Flags & U_VIRTUAL*/));
if (tc == TAB_DBF && pcf->Type == TYPE_DATE && !pcf->Datefmt) {
// DBF date format defaults to 'YYYMMDD'
pcf->Datefmt= "YYYYMMDD";
pcf->Length= 8;
} // endif tc
if (tc == TAB_DBF && pcf->Type == TYPE_DATE && !pcf->Datefmt) {
// DBF date format defaults to 'YYYMMDD'
pcf->Datefmt= "YYYYMMDD";
pcf->Length= 8;
} // endif tc
if (!field)
break;
if (!field)
break;
// Allocate the column description block
cdp= new(g) COLDEF;
if ((nof= cdp->Define(g, NULL, pcf, poff)) < 0)
return -1; // Error, probably unhandled type
else
loff= cdp->GetOffset();
return -1; // Error, probably unhandled type
else
loff= cdp->GetOffset();
switch (tc) {
case TAB_VEC:
cdp->SetOffset(0); // Not to have shift
case TAB_BIN:
// BIN/VEC are packed by default
switch (tc) {
case TAB_VEC:
cdp->SetOffset(0); // Not to have shift
case TAB_BIN:
// BIN/VEC are packed by default
if (nof) {
// Field width is the internal representation width
// that can also depend on the column format
// Field width is the internal representation width
// that can also depend on the column format
fty = cdp->Decode ? 'C' : 'X';
eds = 0;
n = 0;
@ -371,38 +371,38 @@ int TABDEF::GetColCatInfo(PGLOBAL g)
if (n)
nof = n;
else switch (fty) {
case 'X':
case 'X':
if (eds && IsTypeChar(cdp->Buf_Type))
nof = sizeof(longlong);
else
nof= cdp->Clen;
break;
case 'C': break;
case 'R':
case 'F': nof = sizeof(float); break;
case 'I': nof = sizeof(int); break;
case 'D': nof = sizeof(double); break;
case 'S': nof = sizeof(short); break;
case 'T': nof = sizeof(char); break;
case 'G': nof = sizeof(longlong); break;
default: /* Wrong format */
case 'C': break;
case 'R':
case 'F': nof = sizeof(float); break;
case 'I': nof = sizeof(int); break;
case 'D': nof = sizeof(double); break;
case 'S': nof = sizeof(short); break;
case 'T': nof = sizeof(char); break;
case 'G': nof = sizeof(longlong); break;
default: /* Wrong format */
sprintf(g->Message, "Invalid format %c", fty);
return -1;
} // endswitch fty
} // endswitch fty
} // endif nof
default:
break;
} // endswitch tc
break;
} // endswitch tc
if (lcdp)
lcdp->SetNext(cdp);
else
tocols= cdp;
if (lcdp)
lcdp->SetNext(cdp);
else
tocols= cdp;
lcdp= cdp;
lcdp= cdp;
i++;
} // endwhile
@ -410,31 +410,31 @@ int TABDEF::GetColCatInfo(PGLOBAL g)
if (i != GetDegree())
SetDegree(i);
if (GetDefType() == TYPE_AM_DOS) {
int ending, recln= 0;
if (GetDefType() == TYPE_AM_DOS) {
int ending, recln= 0;
// Was commented because sometimes ending is 0 even when
// not specified (for instance if quoted is specified)
// if ((ending= Hc->GetIntegerOption("Ending")) < 0) {
if ((ending= Hc->GetIntegerOption("Ending")) <= 0) {
// Was commented because sometimes ending is 0 even when
// not specified (for instance if quoted is specified)
// if ((ending= Hc->GetIntegerOption("Ending")) < 0) {
if ((ending= Hc->GetIntegerOption("Ending")) <= 0) {
ending= (tc == TAB_BIN || tc == TAB_VEC) ? 0 : CRLF;
Hc->SetIntegerOption("Ending", ending);
} // endif ending
Hc->SetIntegerOption("Ending", ending);
} // endif ending
// Calculate the default record size
switch (tc) {
// Calculate the default record size
switch (tc) {
case TAB_FIX:
case TAB_BIN:
recln= nlg + ending; // + length of line ending
break;
case TAB_VEC:
recln= nlg;
// if ((k= (pak < 0) ? 8 : pak) > 1)
// See above for detailed comment
// Round up lrecl to multiple of 8 or pak
// recln= ((recln + k - 1) / k) * k;
break;
case TAB_DOS:
case TAB_DBF:
@ -443,26 +443,30 @@ int TABDEF::GetColCatInfo(PGLOBAL g)
case TAB_CSV:
case TAB_FMT:
// The number of separators (assuming an extra one can exist)
// recln= poff * ((qotd) ? 3 : 1); to be investigated
recln= nlg + poff * 3; // To be safe
// recln= poff * ((qotd) ? 3 : 1); to be investigated
recln= nlg + poff * 3; // To be safe
default:
break;
} // endswitch tc
// lrecl must be at least recln to avoid buffer overflow
if (trace(1))
htrc("Lrecl: Calculated=%d defined=%d\n",
recln, Hc->GetIntegerOption("Lrecl"));
// lrecl must be at least recln to avoid buffer overflow
if (trace(1))
htrc("Lrecl: Calculated=%d defined=%d\n",
recln, Hc->GetIntegerOption("Lrecl"));
recln = MY_MAX(recln, Hc->GetIntegerOption("Lrecl"));
Hc->SetIntegerOption("Lrecl", recln);
((PDOSDEF)this)->SetLrecl(recln);
} // endif Lrecl
recln = MY_MAX(recln, Hc->GetIntegerOption("Lrecl"));
Hc->SetIntegerOption("Lrecl", recln);
((PDOSDEF)this)->SetLrecl(recln);
// Attach the column definition to the tabdef
SetCols(tocols);
return poff;
} // end of GetColCatInfo
if (trace(1))
htrc("Lrecl set to %d\n", recln);
} // endif Lrecl
// Attach the column definition to the tabdef
SetCols(tocols);
return poff;
} // end of GetColCatInfo
/***********************************************************************/
/* SetIndexInfo: retrieve index description from the table structure. */
@ -487,16 +491,17 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g)
PCATLG cat = Cat;
/*********************************************************************/
/* Ensure that the .dll doesn't have a path. */
/* This is done to ensure that only approved dll from the system */
/* Ensure that the module name doesn't have a path. */
/* This is done to ensure that only approved libs from the system */
/* directories are used (to make this even remotely secure). */
/*********************************************************************/
if (check_valid_path(Module, strlen(Module))) {
strcpy(g->Message, "Module cannot contain a path");
return NULL;
} else
PlugSetPath(soname, Module, GetPluginDir());
// PlugSetPath(soname, Module, GetPluginDir()); // Crashes on Fedora
strncat(strcpy(soname, GetPluginDir()), Module, _MAX_PATH);
#if defined(__WIN__)
// Is the DLL already loaded?
if (!Hdll && !(Hdll = GetModuleHandle(soname)))
@ -522,31 +527,31 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g)
// Get the function returning an instance of the external DEF class
if (!(getdef = (XGETDEF)GetProcAddress((HINSTANCE)Hdll, getname))) {
char buf[256];
DWORD rc = GetLastError();
char buf[256];
DWORD rc = GetLastError();
sprintf(g->Message, MSG(PROCADD_ERROR), rc, getname);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, rc, 0,
(LPTSTR)buf, sizeof(buf), NULL);
strcat(strcat(g->Message, ": "), buf);
FreeLibrary((HMODULE)Hdll);
sprintf(g->Message, MSG(PROCADD_ERROR), rc, getname);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, rc, 0,
(LPTSTR)buf, sizeof(buf), NULL);
strcat(strcat(g->Message, ": "), buf);
FreeLibrary((HMODULE)Hdll);
return NULL;
} // endif getdef
#else // !__WIN__
const char *error = NULL;
#if 0 // Don't know what all this stuff does
Dl_info dl_info;
// The OEM lib must retrieve exported CONNECT variables
#if 0 // Don't know what all this stuff does
Dl_info dl_info;
// The OEM lib must retrieve exported CONNECT variables
if (dladdr(&connect_hton, &dl_info)) {
if (dlopen(dl_info.dli_fname, RTLD_NOLOAD | RTLD_NOW | RTLD_GLOBAL) == 0) {
error = dlerror();
sprintf(g->Message, "dlopen failed: %s, OEM not supported", SVP(error));
return NULL;
} // endif dlopen
} else {
error = dlerror();
sprintf(g->Message, "dladdr failed: %s, OEM not supported", SVP(error));
@ -626,7 +631,7 @@ bool OEMDEF::DefineAM(PGLOBAL g, LPCSTR, int)
char *desc = (char*)PlugSubAlloc(g, NULL, strlen(Module)
+ strlen(Subtype) + 3);
sprintf(desc, "%s(%s)", Module, Subtype);
Desc = desc;
Desc = desc;
return false;
} // end of DefineAM
@ -701,17 +706,17 @@ PTDB OEMDEF::GetTable(PGLOBAL g, MODE mode)
txfp = new(g) FIXFAM(defp);
} else if (rfm == RECFM_VCT) {
#if defined(VCT_SUPPORT)
assert(Pxdef->GetDefType() == TYPE_AM_VCT);
assert(Pxdef->GetDefType() == TYPE_AM_VCT);
if (map)
txfp = new(g) VCMFAM((PVCTDEF)defp);
else
txfp = new(g) VCTFAM((PVCTDEF)defp);
#else // !VCT_SUPPORT
strcpy(g->Message, "VCT no more supported");
return NULL;
strcpy(g->Message, "VCT no more supported");
return NULL;
#endif // !VCT_SUPPORT
} // endif's
} // endif's
((PTDBDOS)tdbp)->SetTxfp(txfp);
} // endif Txfp

View file

@ -7,7 +7,8 @@
#if defined(MARIADB)
#include <my_global.h>
#else
#include "mini_global.h"
#include "mini-global.h"
#define _OS_H_INCLUDED // Prevent os.h to be called
#endif
using namespace utility::conversions; // String conversions utilities
@ -18,70 +19,76 @@ 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>();
int rc = 0;
bool xt = trace(515);
auto fileStream = std::make_shared<ostream>();
if (!http || !fn) {
strcpy(g->Message, "Missing http or filename");
return 2;
} // endif
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;
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;
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 (xt)
htrc("Outfile isopen=%d\n", outFile.is_open());
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);
})
// Create http_client to send the request.
http_client client(to_string_t(http));
// Handle response headers arriving.
.then([=](http_response response) {
#if defined(DEVELOPMENT)
fprintf(stderr, "Received response status code:%u\n",
response.status_code());
#endif // DEVELOPMENT
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);
})
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Handle response headers arriving.
.then([=](http_response response) {
if (xt)
htrc("Received response status code:%u\n",
response.status_code());
// Close the file stream.
.then([=](size_t) { return fileStream->close(); });
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then([=](size_t n) {
if (xt)
htrc("Return size=%u\n", n);
return fileStream->close();
});
// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
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());
if (xt)
htrc("In Wait\n");
} catch (const std::exception &e) {
if (xt)
htrc("Error exception: %s\n", e.what());
sprintf(g->Message, "Error exception: %s", e.what());
rc= 1;
} // end try/catch
if (xt)
htrc("restget done: rc=%d\n", rc);
return rc;
} // end of restGetFile
} // end of restGetFile

View file

@ -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",
SVP(tdp->Fn), tdp->Sep, tdp->Qot, tdp->Header, tdp->Maxerr);
#if defined(ZIP_SUPPORT)
if (tdp->Zipped)
tcvp = new(g)TDBCSV(tdp, new(g)UNZFAM(tdp));
else
#endif // ZIP_SUPPORT
tcvp = new(g) TDBCSV(tdp, new(g) DOSFAM(tdp));
tcvp->SetMode(MODE_READ);

View file

@ -641,7 +641,9 @@ bool TDBJDBC::OpenDB(PGLOBAL g)
Cnp->InitValue(g);
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;
} else if (n) {
Jcp->m_Rows = n;

File diff suppressed because it is too large Load diff

View file

@ -1,13 +1,23 @@
/*************** 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 */
/* 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. */
/***********************************************************************/
#if defined(MARIADB)
#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: */
@ -19,12 +29,12 @@
#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 "plgxml.h"
#include "tabxml.h"
#include "tabjson.h"
#include "tabfmt.h"
#include "tabrest.h"
/***********************************************************************/
/* Get the file from the Web. */
@ -32,25 +42,61 @@
int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn);
#if defined(__WIN__)
static PCSZ slash= "\\";
static PCSZ slash = "\\";
#else // !__WIN__
static PCSZ slash= "/";
static PCSZ slash = "/";
#define stricmp strcasecmp
#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. */
/***********************************************************************/
#if defined(MARIADB)
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;
char filename[_MAX_PATH];
char filename[_MAX_PATH + 1]; // 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");
http = GetStringTableOption(g, tp, "Http", NULL);
uri = GetStringTableOption(g, tp, "Uri", NULL);
fn = GetStringTableOption(g, tp, "Filename", "rest.json");
#if defined(MARIADB)
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
strcat(strcat(strcat(strcpy(filename, "."), slash), db), slash);
@ -60,11 +106,11 @@ PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
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);
qrp = XMLColumns(g, db, tab, tp, info);
else if (!stricmp(ftype, "JSON"))
qrp= JSONColumns(g, db, NULL, tp, info);
qrp = JSONColumns(g, db, NULL, tp, info);
else if (!stricmp(ftype, "CSV"))
qrp= CSVColumns(g, NULL, tp, info);
qrp = CSVColumns(g, NULL, tp, info);
else
sprintf(g->Message, "Usupported file type %s", ftype);
@ -78,40 +124,59 @@ PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
/***********************************************************************/
bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
char filename[_MAX_PATH];
TABTYPE type= GetTypeID(am);
char filename[_MAX_PATH + 1];
int rc = 0, n;
LPCSTR ftype;
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
#if defined(MARIADB)
ftype = GetStringCatInfo(g, "Type", "JSON");
#else // !MARIADB
// OEM tables must specify the file type
ftype = GetStringCatInfo(g, "Ftype", "JSON");
#endif // !MARIADB
Http= GetStringCatInfo(g, "Http", NULL);
Uri= GetStringCatInfo(g, "Uri", NULL);
Fn= GetStringCatInfo(g, "Filename", "rest.json");
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;
if (n == 0) {
htrc("DefineAM: Unsupported REST table type %s", am);
sprintf(g->Message, "Unsupported REST table type %s", am);
return true;
} // endif n
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());
//PlugSetPath(filename, Fn, GetPath());
strncat(strcpy(filename, GetPath()), Fn, _MAX_PATH);
// 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);
rc = restGetFile(g, Http, Uri, filename);
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
// Do make the table/view definition
if (Tdp && Tdp->Define(g, Cat, Name, Schema, "REST"))
Tdp= NULL; // Error occured
Tdp = NULL; // Error occured
if (trace(515))
htrc("Tdp defined\n", rc);
// Return true in case of error
return (Tdp == NULL);
@ -122,10 +187,13 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
/***********************************************************************/
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
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");
return NULL;
} // endif m
return Tdp->GetTable(g, m); // Leave file type do the job
} // end of GetTable

View file

@ -281,7 +281,7 @@ bool TDBTBL::InitTableList(PGLOBAL g)
} // 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;
//NumTables = n;