Commit f590296c authored by Olivier Bertrand's avatar Olivier Bertrand

-- Finalize work on MongoDB access

   Implement discovery for the MongoDB Java Driver
   Create classes to minimize code and avoid dupicates
   Rearrange and rename implied files
  modified:   storage/connect/CMakeLists.txt
  renamed:    storage/connect/mongofam.cpp -> storage/connect/cmgfam.cpp
  renamed:    storage/connect/mongofam.h -> storage/connect/cmgfam.h
  modified:   storage/connect/cmgoconn.h
  modified:   storage/connect/javaconn.h
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jmgoconn.cpp
  modified:   storage/connect/jmgoconn.h
  modified:   storage/connect/mongo.cpp
  modified:   storage/connect/mongo.h
  renamed:    storage/connect/tabmgo.cpp -> storage/connect/tabcmg.cpp
  renamed:    storage/connect/tabmgo.h -> storage/connect/tabcmg.h
  modified:   storage/connect/tabjmg.cpp
  modified:   storage/connect/tabjmg.h
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabjson.h

-- Trace Sarea allocation and freeing
  modified:   storage/connect/connect.cc
  modified:   storage/connect/plugutil.cpp
  modified:   storage/connect/user_connect.cc

-- Null Json values where not mark as null in JSNX::SetJsonValue
   This was added in TYPE_NULL (declared as TYPE_VOID)
  modified:   storage/connect/json.cpp
  modified:   storage/connect/json.h
  modified:   storage/connect/jsonudf.cpp

-- Null JValues are ignored in JSNX::CalculateArray
   Also done in tabjson.cpp for JSONCOL::CalculateArray
  modified:   storage/connect/json.h
  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/tabjson.cpp

-- Null JSON values now represented by connect_json_null session variable
  modified:   storage/connect/json.cpp
  modified:   storage/connect/json.h
  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/tabjson.cpp

-- JVALUE has size = 1
  modified:   storage/connect/json.h

-- Fix by vuvova because Debian compilation failure.
  modified:   storage/connect/value.cpp
parent a9d32010
...@@ -316,8 +316,8 @@ ENDIF(CONNECT_WITH_ZIP) ...@@ -316,8 +316,8 @@ ENDIF(CONNECT_WITH_ZIP)
# INCLUDE_DIRECTORIES(${MONGO_INCLUDE_DIR}) # INCLUDE_DIRECTORIES(${MONGO_INCLUDE_DIR})
# SET(MONGO_LIBRARY ${MONGO_LIBRARIES}) # SET(MONGO_LIBRARY ${MONGO_LIBRARIES})
# SET(CONNECT_SOURCES ${CONNECT_SOURCES} # SET(CONNECT_SOURCES ${CONNECT_SOURCES}
# cmgoconn.cpp mongofam.cpp tabmgo.cpp # cmgoconn.cpp cmgfam.cpp tabcmg.cpp
# cmgoconn.h mongofam.h tabmgo.h) # cmgoconn.h cmgfam.h tabcmg.h)
# IF (NOT JAVA_FOUND AND JNI_FOUND) # IF (NOT JAVA_FOUND AND JNI_FOUND)
# SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongo.cpp mongo.h) # SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongo.cpp mongo.h)
# ENDIF (NOT JAVA_FOUND AND JNI_FOUND) # ENDIF (NOT JAVA_FOUND AND JNI_FOUND)
......
/************ MONGO FAM C++ Program Source Code File (.CPP) ************/ /************** CMGFAM C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: mongofam.cpp */ /* PROGRAM NAME: cmgfam.cpp */
/* ------------- */ /* ------------- */
/* Version 1.3 */ /* Version 1.4 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
...@@ -30,18 +30,18 @@ ...@@ -30,18 +30,18 @@
#include "filamtxt.h" #include "filamtxt.h"
#include "tabdos.h" #include "tabdos.h"
#include "tabjson.h" #include "tabjson.h"
#include "mongofam.h" #include "cmgfam.h"
#if defined(UNIX) || defined(UNIV_LINUX) #if defined(UNIX) || defined(UNIV_LINUX)
#include "osutil.h" #include "osutil.h"
#endif #endif
/* --------------------------- Class MGOFAM -------------------------- */ /* --------------------------- Class CMGFAM -------------------------- */
/***********************************************************************/ /***********************************************************************/
/* Constructors. */ /* Constructors. */
/***********************************************************************/ /***********************************************************************/
MGOFAM::MGOFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL) CMGFAM::CMGFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL)
{ {
Cmgp = NULL; Cmgp = NULL;
Pcg.Tdbp = NULL; Pcg.Tdbp = NULL;
...@@ -66,20 +66,20 @@ MGOFAM::MGOFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL) ...@@ -66,20 +66,20 @@ MGOFAM::MGOFAM(PJDEF tdp) : DOSFAM((PDOSDEF)NULL)
Mode = MODE_ANY; Mode = MODE_ANY;
Done = false; Done = false;
Lrecl = tdp->Lrecl + tdp->Ending; Lrecl = tdp->Lrecl + tdp->Ending;
} // end of MGOFAM standard constructor } // end of CMGFAM standard constructor
MGOFAM::MGOFAM(PMGOFAM tdfp) : DOSFAM(tdfp) CMGFAM::CMGFAM(PCMGFAM tdfp) : DOSFAM(tdfp)
{ {
Pcg = tdfp->Pcg; Pcg = tdfp->Pcg;
To_Fbt = tdfp->To_Fbt; To_Fbt = tdfp->To_Fbt;
Mode = tdfp->Mode; Mode = tdfp->Mode;
Done = tdfp->Done; Done = tdfp->Done;
} // end of MGOFAM copy constructor } // end of CMGFAM copy constructor
/***********************************************************************/ /***********************************************************************/
/* Reset: reset position values at the beginning of file. */ /* Reset: reset position values at the beginning of file. */
/***********************************************************************/ /***********************************************************************/
void MGOFAM::Reset(void) void CMGFAM::Reset(void)
{ {
TXTFAM::Reset(); TXTFAM::Reset();
Fpos = Tpos = Spos = 0; Fpos = Tpos = Spos = 0;
...@@ -88,7 +88,7 @@ void MGOFAM::Reset(void) ...@@ -88,7 +88,7 @@ void MGOFAM::Reset(void)
/***********************************************************************/ /***********************************************************************/
/* MGO GetFileLength: returns file size in number of bytes. */ /* MGO GetFileLength: returns file size in number of bytes. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::GetFileLength(PGLOBAL g) int CMGFAM::GetFileLength(PGLOBAL g)
{ {
return 0; return 0;
} // end of GetFileLength } // end of GetFileLength
...@@ -98,7 +98,7 @@ int MGOFAM::GetFileLength(PGLOBAL g) ...@@ -98,7 +98,7 @@ int MGOFAM::GetFileLength(PGLOBAL g)
/* This function can be called with a null argument to test the */ /* This function can be called with a null argument to test the */
/* availability of Cardinality implementation (1 yes, 0 no). */ /* availability of Cardinality implementation (1 yes, 0 no). */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::Cardinality(PGLOBAL g) int CMGFAM::Cardinality(PGLOBAL g)
{ {
if (!g) if (!g)
return 1; return 1;
...@@ -109,7 +109,7 @@ int MGOFAM::Cardinality(PGLOBAL g) ...@@ -109,7 +109,7 @@ int MGOFAM::Cardinality(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
/* Note: This function is not really implemented yet. */ /* Note: This function is not really implemented yet. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::MaxBlkSize(PGLOBAL, int s) int CMGFAM::MaxBlkSize(PGLOBAL, int s)
{ {
return s; return s;
} // end of MaxBlkSize } // end of MaxBlkSize
...@@ -117,7 +117,7 @@ int MGOFAM::MaxBlkSize(PGLOBAL, int s) ...@@ -117,7 +117,7 @@ int MGOFAM::MaxBlkSize(PGLOBAL, int s)
/***********************************************************************/ /***********************************************************************/
/* Init: initialize MongoDB processing. */ /* Init: initialize MongoDB processing. */
/***********************************************************************/ /***********************************************************************/
bool MGOFAM::Init(PGLOBAL g) bool CMGFAM::Init(PGLOBAL g)
{ {
if (Done) if (Done)
return false; return false;
...@@ -141,7 +141,7 @@ bool MGOFAM::Init(PGLOBAL g) ...@@ -141,7 +141,7 @@ bool MGOFAM::Init(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
/* OpenTableFile: Open a MongoDB table. */ /* OpenTableFile: Open a MongoDB table. */
/***********************************************************************/ /***********************************************************************/
bool MGOFAM::OpenTableFile(PGLOBAL g) bool CMGFAM::OpenTableFile(PGLOBAL g)
{ {
Mode = Tdbp->GetMode(); Mode = Tdbp->GetMode();
...@@ -165,7 +165,7 @@ bool MGOFAM::OpenTableFile(PGLOBAL g) ...@@ -165,7 +165,7 @@ bool MGOFAM::OpenTableFile(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
/* GetRowID: return the RowID of last read record. */ /* GetRowID: return the RowID of last read record. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::GetRowID(void) int CMGFAM::GetRowID(void)
{ {
return Rows; return Rows;
} // end of GetRowID } // end of GetRowID
...@@ -173,7 +173,7 @@ int MGOFAM::GetRowID(void) ...@@ -173,7 +173,7 @@ int MGOFAM::GetRowID(void)
/***********************************************************************/ /***********************************************************************/
/* GetPos: return the position of last read record. */ /* GetPos: return the position of last read record. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::GetPos(void) int CMGFAM::GetPos(void)
{ {
return Fpos; return Fpos;
} // end of GetPos } // end of GetPos
...@@ -181,7 +181,7 @@ int MGOFAM::GetPos(void) ...@@ -181,7 +181,7 @@ int MGOFAM::GetPos(void)
/***********************************************************************/ /***********************************************************************/
/* GetNextPos: return the position of next record. */ /* GetNextPos: return the position of next record. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::GetNextPos(void) int CMGFAM::GetNextPos(void)
{ {
return Fpos; // TODO return Fpos; // TODO
} // end of GetNextPos } // end of GetNextPos
...@@ -189,7 +189,7 @@ int MGOFAM::GetNextPos(void) ...@@ -189,7 +189,7 @@ int MGOFAM::GetNextPos(void)
/***********************************************************************/ /***********************************************************************/
/* SetPos: Replace the table at the specified position. */ /* SetPos: Replace the table at the specified position. */
/***********************************************************************/ /***********************************************************************/
bool MGOFAM::SetPos(PGLOBAL g, int pos) bool CMGFAM::SetPos(PGLOBAL g, int pos)
{ {
Fpos = pos; Fpos = pos;
Placed = true; Placed = true;
...@@ -199,25 +199,25 @@ bool MGOFAM::SetPos(PGLOBAL g, int pos) ...@@ -199,25 +199,25 @@ bool MGOFAM::SetPos(PGLOBAL g, int pos)
/***********************************************************************/ /***********************************************************************/
/* Record file position in case of UPDATE or DELETE. */ /* Record file position in case of UPDATE or DELETE. */
/***********************************************************************/ /***********************************************************************/
bool MGOFAM::RecordPos(PGLOBAL g) bool CMGFAM::RecordPos(PGLOBAL g)
{ {
strcpy(g->Message, "MGOFAM::RecordPos NIY"); strcpy(g->Message, "CMGFAM::RecordPos NIY");
return true; return true;
} // end of RecordPos } // end of RecordPos
/***********************************************************************/ /***********************************************************************/
/* Initialize Fpos and the current position for indexed DELETE. */ /* Initialize Fpos and the current position for indexed DELETE. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::InitDelete(PGLOBAL g, int fpos, int spos) int CMGFAM::InitDelete(PGLOBAL g, int fpos, int spos)
{ {
strcpy(g->Message, "MGOFAM::InitDelete NIY"); strcpy(g->Message, "CMGFAM::InitDelete NIY");
return RC_FX; return RC_FX;
} // end of InitDelete } // end of InitDelete
/***********************************************************************/ /***********************************************************************/
/* Skip one record in file. */ /* Skip one record in file. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::SkipRecord(PGLOBAL g, bool header) int CMGFAM::SkipRecord(PGLOBAL g, bool header)
{ {
return RC_OK; // Dummy return RC_OK; // Dummy
} // end of SkipRecord } // end of SkipRecord
...@@ -225,7 +225,7 @@ int MGOFAM::SkipRecord(PGLOBAL g, bool header) ...@@ -225,7 +225,7 @@ int MGOFAM::SkipRecord(PGLOBAL g, bool header)
/***********************************************************************/ /***********************************************************************/
/* ReadBuffer: Get next document from a collection. */ /* ReadBuffer: Get next document from a collection. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::ReadBuffer(PGLOBAL g) int CMGFAM::ReadBuffer(PGLOBAL g)
{ {
int rc = Cmgp->ReadNext(g); int rc = Cmgp->ReadNext(g);
...@@ -239,7 +239,7 @@ int MGOFAM::ReadBuffer(PGLOBAL g) ...@@ -239,7 +239,7 @@ int MGOFAM::ReadBuffer(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
/* WriteBuffer: File write routine for MGO access method. */ /* WriteBuffer: File write routine for MGO access method. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::WriteBuffer(PGLOBAL g) int CMGFAM::WriteBuffer(PGLOBAL g)
{ {
return Cmgp->Write(g); return Cmgp->Write(g);
} // end of WriteBuffer } // end of WriteBuffer
...@@ -247,7 +247,7 @@ int MGOFAM::WriteBuffer(PGLOBAL g) ...@@ -247,7 +247,7 @@ int MGOFAM::WriteBuffer(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
/* Data Base delete line routine for MGO and BLK access methods. */ /* Data Base delete line routine for MGO and BLK access methods. */
/***********************************************************************/ /***********************************************************************/
int MGOFAM::DeleteRecords(PGLOBAL g, int irc) int CMGFAM::DeleteRecords(PGLOBAL g, int irc)
{ {
return (irc == RC_OK) ? WriteBuffer(g) : RC_OK; return (irc == RC_OK) ? WriteBuffer(g) : RC_OK;
} // end of DeleteRecords } // end of DeleteRecords
...@@ -255,7 +255,7 @@ int MGOFAM::DeleteRecords(PGLOBAL g, int irc) ...@@ -255,7 +255,7 @@ int MGOFAM::DeleteRecords(PGLOBAL g, int irc)
/***********************************************************************/ /***********************************************************************/
/* Table file close routine for MGO access method. */ /* Table file close routine for MGO access method. */
/***********************************************************************/ /***********************************************************************/
void MGOFAM::CloseTableFile(PGLOBAL g, bool) void CMGFAM::CloseTableFile(PGLOBAL g, bool)
{ {
Cmgp->Close(); Cmgp->Close();
Done = false; Done = false;
...@@ -264,7 +264,7 @@ void MGOFAM::CloseTableFile(PGLOBAL g, bool) ...@@ -264,7 +264,7 @@ void MGOFAM::CloseTableFile(PGLOBAL g, bool)
/***********************************************************************/ /***********************************************************************/
/* Rewind routine for MGO access method. */ /* Rewind routine for MGO access method. */
/***********************************************************************/ /***********************************************************************/
void MGOFAM::Rewind(void) void CMGFAM::Rewind(void)
{ {
Cmgp->Rewind(); Cmgp->Rewind();
} // end of Rewind } // end of Rewind
......
/************** MongoFam H Declares Source Code File (.H) **************/ /*************** CMGFam H Declares Source Code File (.H) ***************/
/* Name: mongofam.h Version 1.4 */ /* Name: cmgfam.h Version 1.5 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */ /* (C) Copyright to the author Olivier BERTRAND 2017 */
/* */ /* */
...@@ -8,19 +8,19 @@ ...@@ -8,19 +8,19 @@
#include "cmgoconn.h" #include "cmgoconn.h"
typedef class TXTFAM *PTXF; typedef class TXTFAM *PTXF;
typedef class MGOFAM *PMGOFAM; typedef class CMGFAM *PCMGFAM;
typedef class MGODEF *PMGODEF; typedef class MGODEF *PMGODEF;
typedef class TDBMGO *PTDBMGO; typedef class TDBCMG *PTDBCMG;
/***********************************************************************/ /***********************************************************************/
/* This is the MongoDB Access Method class declaration. */ /* This is the MongoDB Access Method class declaration. */
/***********************************************************************/ /***********************************************************************/
class DllExport MGOFAM : public DOSFAM { class DllExport CMGFAM : public DOSFAM {
friend void mongo_init(bool); friend void mongo_init(bool);
public: public:
// Constructor // Constructor
MGOFAM(PJDEF tdp); CMGFAM(PJDEF tdp);
MGOFAM(PMGOFAM txfp); CMGFAM(PCMGFAM txfp);
// Implementation // Implementation
virtual AMT GetAmType(void) { return TYPE_AM_MGO; } virtual AMT GetAmType(void) { return TYPE_AM_MGO; }
...@@ -28,7 +28,7 @@ class DllExport MGOFAM : public DOSFAM { ...@@ -28,7 +28,7 @@ class DllExport MGOFAM : public DOSFAM {
virtual int GetPos(void); virtual int GetPos(void);
virtual int GetNextPos(void); virtual int GetNextPos(void);
void SetTdbp(PTDBDOS tdbp) { Tdbp = tdbp; } void SetTdbp(PTDBDOS tdbp) { Tdbp = tdbp; }
virtual PTXF Duplicate(PGLOBAL g) { return (PTXF)new(g) MGOFAM(this); } virtual PTXF Duplicate(PGLOBAL g) { return (PTXF)new(g) CMGFAM(this); }
void SetLrecl(int lrecl) { Lrecl = lrecl; } void SetLrecl(int lrecl) { Lrecl = lrecl; }
// Methods // Methods
...@@ -61,5 +61,5 @@ class DllExport MGOFAM : public DOSFAM { ...@@ -61,5 +61,5 @@ class DllExport MGOFAM : public DOSFAM {
PFBLOCK To_Fbt; // Pointer to temp file block PFBLOCK To_Fbt; // Pointer to temp file block
MODE Mode; MODE Mode;
bool Done; // Init done bool Done; // Init done
}; // end of class MGOFAM }; // end of class CMGFAM
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <mongoc.h> #include <mongoc.h>
// C connection to a MongoDB data source // C connection to a MongoDB data source
class TDBMGO; class TDBCMG;
class MGOCOL; class MGOCOL;
/***********************************************************************/ /***********************************************************************/
...@@ -18,7 +18,7 @@ class MGOCOL; ...@@ -18,7 +18,7 @@ class MGOCOL;
/***********************************************************************/ /***********************************************************************/
typedef class INCOL *PINCOL; typedef class INCOL *PINCOL;
typedef class MGODEF *PMGODEF; typedef class MGODEF *PMGODEF;
typedef class TDBMGO *PTDBMGO; typedef class TDBCMG *PTDBCMG;
typedef class MGOCOL *PMGOCOL; typedef class MGOCOL *PMGOCOL;
typedef struct mongo_parms { typedef struct mongo_parms {
...@@ -63,8 +63,8 @@ class INCOL : public BLOCK { ...@@ -63,8 +63,8 @@ class INCOL : public BLOCK {
/* CMgoConn class. */ /* CMgoConn class. */
/***********************************************************************/ /***********************************************************************/
class CMgoConn : public BLOCK { class CMgoConn : public BLOCK {
friend class TDBMGO; friend class TDBCMG;
friend class MGODISC; friend class CMGDISC;
public: public:
// Constructor // Constructor
CMgoConn(PGLOBAL g, PCPARM pcg); CMgoConn(PGLOBAL g, PCPARM pcg);
......
...@@ -80,7 +80,7 @@ PGLOBAL CntExit(PGLOBAL g) ...@@ -80,7 +80,7 @@ PGLOBAL CntExit(PGLOBAL g)
/* CntEndDB: DB termination semantic routine. */ /* CntEndDB: DB termination semantic routine. */
/***********************************************************************/ /***********************************************************************/
void CntEndDB(PGLOBAL g) void CntEndDB(PGLOBAL g)
{ {
PDBUSER dbuserp= PlgGetUser(g); PDBUSER dbuserp= PlgGetUser(g);
if (dbuserp) { if (dbuserp) {
...@@ -88,9 +88,14 @@ void CntEndDB(PGLOBAL g) ...@@ -88,9 +88,14 @@ void CntEndDB(PGLOBAL g)
delete dbuserp->Catalog; delete dbuserp->Catalog;
free(dbuserp); free(dbuserp);
} // endif dbuserp
} // end of CntEndDB if (trace)
htrc("CntEndDB: Freeing Dup\n");
g->Activityp->Aptr = NULL;
} // endif dbuserp
} // end of CntEndDB
/***********************************************************************/ /***********************************************************************/
/* CntCheckDB: Initialize a DB application session. */ /* CntCheckDB: Initialize a DB application session. */
......
...@@ -58,31 +58,10 @@ ...@@ -58,31 +58,10 @@
/* Miscellaneous Constants */ /* Miscellaneous Constants */
/***********************************************************************/ /***********************************************************************/
#define NO_IVAL -95684275 /* Used by GetIntegerOption */ #define NO_IVAL -95684275 /* Used by GetIntegerOption */
#define VMLANG 370 /* Size of olf VM lang blocks */
#define MAX_JUMP 24 /* Maximum jump level number */ #define MAX_JUMP 24 /* Maximum jump level number */
#define MAX_STR 4160 /* Maximum message length */ #define MAX_STR 4160 /* Maximum message length */
#define STR_SIZE 501 /* Length of char strings. */
#define STD_INPUT 0 /* Standard language input */
#define STD_OUTPUT 1 /* Standard language output */
#define ERROR_OUTPUT 2 /* Error message output */
#define DEBUG_OUTPUT 3 /* Debug info output */
#define PROMPT_OUTPUT 4 /* Prompt message output */
#define COPY_OUTPUT 5 /* Copy of language input */
#define STD_MSG 6 /* System message file */
#define DEBUG_MSG 7 /* Debug message file */
#define DUMMY 0 /* Dummy file index in Ldm block */
#define STDIN 1 /* stdin file index in Ldm block */
#define STDOUT 2 /* stdout file index in Ldm block */
#define STDERR 3 /* stderr file index in Ldm block */
#define STDEBUG 4 /* debug file index in Ldm block */
#define STDPRN 5 /* stdprn file index in Ldm block */
#define STDFREE 6 /* Free file index in Ldm block */
#define TYPE_SEM -2 /* Returned semantic function */
#define TYPE_DFONC -2 /* Indirect sem ref in FPARM */
#define TYPE_VOID -1 #define TYPE_VOID -1
#define TYPE_SBPAR -1 /* Phrase reference in FPARM */
#define TYPE_SEMX 0 /* Initial semantic function type? */
#define TYPE_ERROR 0 #define TYPE_ERROR 0
#define TYPE_STRING 1 #define TYPE_STRING 1
#define TYPE_DOUBLE 2 #define TYPE_DOUBLE 2
...@@ -96,22 +75,6 @@ ...@@ -96,22 +75,6 @@
#define TYPE_BIN 10 #define TYPE_BIN 10
#define TYPE_PCHAR 11 #define TYPE_PCHAR 11
#if defined(OS32)
#define SYS_STAMP "OS32"
#elif defined(UNIX) || defined(LINUX) || defined(UNIV_LINUX)
#define SYS_STAMP "UNIX"
#elif defined(OS16)
#define SYS_STAMP "OS16"
#elif defined(DOSR)
#define SYS_STAMP "DOSR"
#elif defined(WIN)
#define SYS_STAMP "WIN1"
#elif defined(__WIN__)
#define SYS_STAMP "WIN2"
#else
#define SYS_STAMP "XXXX"
#endif
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
...@@ -119,11 +82,6 @@ extern "C" { ...@@ -119,11 +82,6 @@ extern "C" {
/***********************************************************************/ /***********************************************************************/
/* Static variables */ /* Static variables */
/***********************************************************************/ /***********************************************************************/
#if defined(STORAGE)
char sys_stamp[5] = SYS_STAMP;
#else
extern char sys_stamp[];
#endif
/***********************************************************************/ /***********************************************************************/
/* File-Selection Indicators */ /* File-Selection Indicators */
......
...@@ -210,9 +210,9 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info); ...@@ -210,9 +210,9 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
PQRYRES VirColumns(PGLOBAL g, bool info); PQRYRES VirColumns(PGLOBAL g, bool info);
PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info); PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info);
PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info); PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info);
#if defined(MONGO_SUPPORT) #if defined(JDBC_SUPPORT) || defined(MONGO_SUPPORT)
PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ url, PTOS topt, bool info); PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ url, PTOS topt, bool info);
#endif // MONGO_SUPPORT #endif // JDBC_SUPPORT || MONGO_SUPPORT
int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v); 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,
...@@ -223,6 +223,7 @@ void mongo_init(bool); ...@@ -223,6 +223,7 @@ void mongo_init(bool);
USETEMP UseTemp(void); USETEMP UseTemp(void);
int GetConvSize(void); int GetConvSize(void);
TYPCONV GetTypeConv(void); TYPCONV GetTypeConv(void);
char *GetJsonNull(void);
uint GetJsonGrpSize(void); uint GetJsonGrpSize(void);
char *GetJavaWrapper(void); char *GetJavaWrapper(void);
uint GetWorkSize(void); uint GetWorkSize(void);
...@@ -332,6 +333,13 @@ static MYSQL_THDVAR_ENUM( ...@@ -332,6 +333,13 @@ static MYSQL_THDVAR_ENUM(
0, // def (no) 0, // def (no)
&xconv_typelib); // typelib &xconv_typelib); // typelib
// Null representation for JSON values
static MYSQL_THDVAR_STR(json_null,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
"Representation of Json null values",
// check_json_null, update_json_null,
NULL, NULL, "<null>");
// Estimate max number of rows for JSON aggregate functions // Estimate max number of rows for JSON aggregate functions
static MYSQL_THDVAR_UINT(json_grp_size, static MYSQL_THDVAR_UINT(json_grp_size,
PLUGIN_VAR_RQCMDARG, // opt PLUGIN_VAR_RQCMDARG, // opt
...@@ -343,7 +351,7 @@ static MYSQL_THDVAR_UINT(json_grp_size, ...@@ -343,7 +351,7 @@ static MYSQL_THDVAR_UINT(json_grp_size,
static MYSQL_THDVAR_STR(java_wrapper, static MYSQL_THDVAR_STR(java_wrapper,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
"Java wrapper class name", "Java wrapper class name",
// check_class_path, update_class_path, // check_java_wrapper, update_java_wrapper,
NULL, NULL, "wrappers/JdbcInterface"); NULL, NULL, "wrappers/JdbcInterface");
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
...@@ -383,6 +391,8 @@ bool ExactInfo(void) {return THDVAR(current_thd, exact_info);} ...@@ -383,6 +391,8 @@ bool ExactInfo(void) {return THDVAR(current_thd, exact_info);}
USETEMP UseTemp(void) {return (USETEMP)THDVAR(current_thd, use_tempfile);} USETEMP UseTemp(void) {return (USETEMP)THDVAR(current_thd, use_tempfile);}
int GetConvSize(void) {return THDVAR(current_thd, conv_size);} int GetConvSize(void) {return THDVAR(current_thd, conv_size);}
TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);} TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);}
char *GetJsonNull(void)
{return connect_hton ? THDVAR(current_thd, json_null) : NULL;}
uint GetJsonGrpSize(void) uint GetJsonGrpSize(void)
{return connect_hton ? THDVAR(current_thd, json_grp_size) : 10;} {return connect_hton ? THDVAR(current_thd, json_grp_size) : 10;}
uint GetWorkSize(void) {return THDVAR(current_thd, work_size);} uint GetWorkSize(void) {return THDVAR(current_thd, work_size);}
...@@ -5761,25 +5771,13 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5761,25 +5771,13 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if !defined(MONGO_SUPPORT) #if !defined(MONGO_SUPPORT)
driver = "JAVA"; driver = "JAVA";
// strcpy(g->Message, "No column discovery for Java MONGO tables yet");
// Temporarily use the JSONColumns function
qrp = JSONColumns(g, db, url, topt, fnc == FNC_COL);
#elif !defined(JDBC_SUPPORT) #elif !defined(JDBC_SUPPORT)
driver = "C"; driver = "C";
qrp = MGOColumns(g, db, url, topt, fnc == FNC_COL);
#else // MONGO_SUPPORT && JDBC_SUPPORT #else // MONGO_SUPPORT && JDBC_SUPPORT
if (!driver) if (!driver)
driver = "C"; driver = "C";
if (toupper(*driver) == 'C') {
qrp = MGOColumns(g, db, url, topt, fnc == FNC_COL);
} else {
// strcpy(g->Message, "No column discovery for Java MONGO tables yet");
// Temporarily use the JSONColumns function
qrp = JSONColumns(g, db, url, topt, fnc == FNC_COL);
} // endif driver
#endif // MONGO_SUPPORT && JDBC_SUPPORT #endif // MONGO_SUPPORT && JDBC_SUPPORT
qrp = MGOColumns(g, db, url, topt, fnc == FNC_COL);
break; break;
#endif // MONGO_SUPPORT || JDBC_SUPPORT #endif // MONGO_SUPPORT || JDBC_SUPPORT
#if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT) #if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT)
...@@ -7137,6 +7135,7 @@ static struct st_mysql_sys_var* connect_system_variables[]= { ...@@ -7137,6 +7135,7 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
#if defined(XMSG) #if defined(XMSG)
MYSQL_SYSVAR(errmsg_dir_path), MYSQL_SYSVAR(errmsg_dir_path),
#endif // XMSG #endif // XMSG
MYSQL_SYSVAR(json_null),
MYSQL_SYSVAR(json_grp_size), MYSQL_SYSVAR(json_grp_size),
#if defined(JDBC_SUPPORT) #if defined(JDBC_SUPPORT)
MYSQL_SYSVAR(jvm_path), MYSQL_SYSVAR(jvm_path),
......
...@@ -63,6 +63,7 @@ class JAVAConn; ...@@ -63,6 +63,7 @@ class JAVAConn;
/***********************************************************************/ /***********************************************************************/
class JAVAConn : public BLOCK { class JAVAConn : public BLOCK {
friend class TDBJMG; friend class TDBJMG;
friend class JMGDISC;
private: private:
JAVAConn(); // Standard (unused) constructor JAVAConn(); // Standard (unused) constructor
......
...@@ -1226,7 +1226,7 @@ bool JDBConn::SetParam(JDBCCOL *colp) ...@@ -1226,7 +1226,7 @@ bool JDBConn::SetParam(JDBCCOL *colp)
case 5: crp->Name = "Nullable"; break; case 5: crp->Name = "Nullable"; break;
} // endswitch i } // endswitch i
// Build the java string array // Build the java int array
jintArray val = env->NewIntArray(4); jintArray val = env->NewIntArray(4);
if (val == nullptr) { if (val == nullptr) {
......
...@@ -110,8 +110,8 @@ JMgoConn::JMgoConn(PGLOBAL g, PCSZ collname, PCSZ wrapper) ...@@ -110,8 +110,8 @@ JMgoConn::JMgoConn(PGLOBAL g, PCSZ collname, PCSZ wrapper)
deleteid = gcollid = countid = rewindid = nullptr; deleteid = gcollid = countid = rewindid = nullptr;
DiscFunc = "MongoDisconnect"; DiscFunc = "MongoDisconnect";
Fpc = NULL; Fpc = NULL;
m_Version = 0;
m_Fetch = 0; m_Fetch = 0;
m_Ncol = 0;
m_Version = 0; m_Version = 0;
} // end of JMgoConn } // end of JMgoConn
...@@ -122,13 +122,13 @@ void JMgoConn::AddJars(PSTRG jpop, char sep) ...@@ -122,13 +122,13 @@ void JMgoConn::AddJars(PSTRG jpop, char sep)
{ {
#if defined(DEVELOPMENT) #if defined(DEVELOPMENT)
if (m_Version == 2) { if (m_Version == 2) {
//jpop->Append(sep); jpop->Append(sep);
//jpop->Append("C:/Eclipse/workspace/MongoWrap2/bin"); jpop->Append("C:/Eclipse/workspace/MongoWrap2/bin");
jpop->Append(sep); jpop->Append(sep);
jpop->Append("C:/mongo-java-driver/mongo-java-driver-2.13.3.jar"); jpop->Append("C:/mongo-java-driver/mongo-java-driver-2.13.3.jar");
} else { } else {
//jpop->Append(sep); jpop->Append(sep);
//jpop->Append("C:/Eclipse/workspace/MongoWrap3/bin"); jpop->Append("C:/Eclipse/workspace/MongoWrap3/bin");
jpop->Append(sep); jpop->Append(sep);
jpop->Append("C:/mongo-java-driver/mongo-java-driver-3.4.2.jar"); jpop->Append("C:/mongo-java-driver/mongo-java-driver-3.4.2.jar");
} // endif m_Version } // endif m_Version
...@@ -495,13 +495,15 @@ int JMgoConn::Fetch(int pos) ...@@ -495,13 +495,15 @@ int JMgoConn::Fetch(int pos)
//else //else
// m_Fetch++; // m_Fetch++;
m_Rows += (int)rc; m_Ncol = (int)rc;
rc = MY_MIN(rc, 1);
m_Rows += rc;
} else } else
sprintf(g->Message, "Fetch: %s", Msg); sprintf(g->Message, "Fetch: %s", Msg);
//} // endif pos //} // endif pos
return (int)rc; return rc;
} // end of Fetch } // end of Fetch
/***********************************************************************/ /***********************************************************************/
......
...@@ -19,31 +19,6 @@ typedef class MGODEF *PMGODEF; ...@@ -19,31 +19,6 @@ typedef class MGODEF *PMGODEF;
typedef class TDBJMG *PTDBJMG; typedef class TDBJMG *PTDBJMG;
typedef class JMGCOL *PJMGCOL; typedef class JMGCOL *PJMGCOL;
#if 0
/***********************************************************************/
/* Class used to get the columns of a mongo collection. */
/***********************************************************************/
class MGODISC : public BLOCK {
public:
// Constructor
MGODISC(PGLOBAL g, int *lg);
// Functions
int GetColumns(PGLOBAL g, char *db, PTOS topt);
bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc,
char *pcn, char *pfmt, int i, int k, bool b);
// Members
BCOL bcol;
PBCOL bcp, fbcp, pbcp;
PMGODEF tdp;
TDBJMG *tmgp;
int *length;
int n, k, lvl;
bool all;
}; // end of MGODISC
#endif // 0
typedef struct JKCOL { typedef struct JKCOL {
JKCOL *Next; JKCOL *Next;
PJNCOL Jncolp; PJNCOL Jncolp;
...@@ -73,6 +48,7 @@ class JNCOL : public BLOCK { ...@@ -73,6 +48,7 @@ class JNCOL : public BLOCK {
/***********************************************************************/ /***********************************************************************/
class JMgoConn : public JAVAConn { class JMgoConn : public JAVAConn {
friend class TDBJMG; friend class TDBJMG;
friend class JMGDISC;
//friend class TDBXJDC; //friend class TDBXJDC;
//friend PQRYRES GetColumnInfo(PGLOBAL, char*&, char *, int, PVBLK&); //friend PQRYRES GetColumnInfo(PGLOBAL, char*&, char *, int, PVBLK&);
private: private:
...@@ -132,5 +108,6 @@ class JMgoConn : public JAVAConn { ...@@ -132,5 +108,6 @@ class JMgoConn : public JAVAConn {
jmethodID deleteid; // The CollDelete method ID jmethodID deleteid; // The CollDelete method ID
PJNCOL Fpc; // To JNCOL classes PJNCOL Fpc; // To JNCOL classes
int m_Fetch; int m_Fetch;
int m_Ncol;
int m_Version; // Java driver version (2 or 3) int m_Version; // Java driver version (2 or 3)
}; // end of JMgoConn class definition }; // end of JMgoConn class definition
/*************** json CPP Declares Source Code File (.H) ***************/ /*************** json CPP Declares Source Code File (.H) ***************/
/* Name: json.cpp Version 1.3 */ /* Name: json.cpp Version 1.4 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */ /* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */
/* */ /* */
...@@ -53,6 +53,8 @@ void trans_func(unsigned int u, _EXCEPTION_POINTERS* pExp) ...@@ -53,6 +53,8 @@ void trans_func(unsigned int u, _EXCEPTION_POINTERS* pExp)
char *GetExceptionDesc(PGLOBAL g, unsigned int e); char *GetExceptionDesc(PGLOBAL g, unsigned int e);
#endif // SE_CATCH #endif // SE_CATCH
char *GetJsonNull(void);
/***********************************************************************/ /***********************************************************************/
/* IsNum: check whether this string is all digits. */ /* IsNum: check whether this string is all digits. */
/***********************************************************************/ /***********************************************************************/
...@@ -537,7 +539,7 @@ PVAL ParseNumeric(PGLOBAL g, int& i, STRG& src) ...@@ -537,7 +539,7 @@ PVAL ParseNumeric(PGLOBAL g, int& i, STRG& src)
if (!has_e) if (!has_e)
goto err; goto err;
// passthru // fall through
case '-': case '-':
if (found_digit) if (found_digit)
goto err; goto err;
...@@ -827,7 +829,7 @@ bool JOUTSTR::Escape(const char *s) ...@@ -827,7 +829,7 @@ bool JOUTSTR::Escape(const char *s)
case '\r': case '\r':
case '\b': case '\b':
case '\f': WriteChr('\\'); case '\f': WriteChr('\\');
// passthru // fall through
default: default:
WriteChr(s[i]); WriteChr(s[i]);
break; break;
...@@ -963,6 +965,25 @@ return false; ...@@ -963,6 +965,25 @@ return false;
/* -------------------------- Class JOBJECT -------------------------- */ /* -------------------------- Class JOBJECT -------------------------- */
/***********************************************************************/
/* Return the number of pairs in this object. */
/***********************************************************************/
int JOBJECT::GetSize(bool b)
{
if (b) {
// Return only non null pairs
int n = 0;
for (PJPR jpp = First; jpp; jpp = jpp->Next)
if (jpp->Val && !jpp->Val->IsNull())
n++;
return n;
} else
return Size;
} // end of GetSize
/***********************************************************************/ /***********************************************************************/
/* Add a new pair to an Object. */ /* Add a new pair to an Object. */
/***********************************************************************/ /***********************************************************************/
...@@ -1046,7 +1067,7 @@ PSZ JOBJECT::GetText(PGLOBAL g, PSZ text) ...@@ -1046,7 +1067,7 @@ PSZ JOBJECT::GetText(PGLOBAL g, PSZ text)
PlugSubAlloc(g, NULL, strlen(text) + 1); PlugSubAlloc(g, NULL, strlen(text) + 1);
return text + n; return text + n;
} // end of GetValue; } // end of GetText;
/***********************************************************************/ /***********************************************************************/
/* Merge two objects. */ /* Merge two objects. */
...@@ -1087,7 +1108,7 @@ void JOBJECT::SetValue(PGLOBAL g, PJVAL jvp, PCSZ key) ...@@ -1087,7 +1108,7 @@ void JOBJECT::SetValue(PGLOBAL g, PJVAL jvp, PCSZ key)
} // end of SetValue } // end of SetValue
/***********************************************************************/ /***********************************************************************/
/* Delete a value corresponding to the given key. */ /* Delete a value corresponding to the given key. */
/***********************************************************************/ /***********************************************************************/
void JOBJECT::DeleteKey(PCSZ key) void JOBJECT::DeleteKey(PCSZ key)
{ {
...@@ -1117,6 +1138,25 @@ bool JOBJECT::IsNull(void) ...@@ -1117,6 +1138,25 @@ bool JOBJECT::IsNull(void)
/* -------------------------- Class JARRAY --------------------------- */ /* -------------------------- Class JARRAY --------------------------- */
/***********************************************************************/
/* Return the number of values in this object. */
/***********************************************************************/
int JARRAY::GetSize(bool b)
{
if (b) {
// Return only non null values
int n = 0;
for (PJVAL jvp = First; jvp; jvp = jvp->Next)
if (!jvp->IsNull())
n++;
return n;
} else
return Size;
} // end of GetSize
/***********************************************************************/ /***********************************************************************/
/* Make the array of values from the values list. */ /* Make the array of values from the values list. */
/***********************************************************************/ /***********************************************************************/
...@@ -1225,18 +1265,42 @@ bool JARRAY::SetValue(PGLOBAL g, PJVAL jvp, int n) ...@@ -1225,18 +1265,42 @@ bool JARRAY::SetValue(PGLOBAL g, PJVAL jvp, int n)
return false; return false;
} // end of SetValue } // end of SetValue
/***********************************************************************/
/* Return the text corresponding to all values. */
/***********************************************************************/
PSZ JARRAY::GetText(PGLOBAL g, PSZ text)
{
int n;
PJVAL jp;
if (!text) {
text = (char*)PlugSubAlloc(g, NULL, 0);
text[0] = 0;
n = 1;
} else
n = 0;
for (jp = First; jp; jp = jp->Next)
jp->GetText(g, text);
if (n)
PlugSubAlloc(g, NULL, strlen(text) + 1);
return text + n;
} // end of GetText;
/***********************************************************************/ /***********************************************************************/
/* Delete a Value from the Arrays Value list. */ /* Delete a Value from the Arrays Value list. */
/***********************************************************************/ /***********************************************************************/
bool JARRAY::DeleteValue(int n) bool JARRAY::DeleteValue(int n)
{ {
PJVAL jvp = GetValue(n); PJVAL jvp = GetValue(n);
if (jvp) { if (jvp) {
jvp->Del = true; jvp->Del = true;
return false; return false;
} else } else
return true; return true;
} // end of DeleteValue } // end of DeleteValue
...@@ -1286,7 +1350,7 @@ JTYP JVALUE::GetValType(void) ...@@ -1286,7 +1350,7 @@ JTYP JVALUE::GetValType(void)
else if (Value) else if (Value)
return (JTYP)Value->GetType(); return (JTYP)Value->GetType();
else else
return (JTYP)TYPE_VOID; return TYPE_NULL;
} // end of GetValType } // end of GetValType
...@@ -1350,7 +1414,7 @@ PSZ JVALUE::GetString(void) ...@@ -1350,7 +1414,7 @@ PSZ JVALUE::GetString(void)
/***********************************************************************/ /***********************************************************************/
PSZ JVALUE::GetText(PGLOBAL g, PSZ text) PSZ JVALUE::GetText(PGLOBAL g, PSZ text)
{ {
if (Jsp && Jsp->GetType() == TYPE_JOB) if (Jsp)
return Jsp->GetText(g, text); return Jsp->GetText(g, text);
char buf[32]; char buf[32];
...@@ -1358,8 +1422,8 @@ PSZ JVALUE::GetText(PGLOBAL g, PSZ text) ...@@ -1358,8 +1422,8 @@ PSZ JVALUE::GetText(PGLOBAL g, PSZ text)
if (s) if (s)
strcat(strcat(text, " "), s); strcat(strcat(text, " "), s);
else else if (GetJsonNull())
strcat(text, " <null>"); strcat(strcat(text, " "), GetJsonNull());
return text; return text;
} // end of GetText } // end of GetText
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#define X #define X
#endif #endif
enum JTYP {TYPE_STRG = TYPE_STRING, enum JTYP {TYPE_NULL = TYPE_VOID,
TYPE_STRG = TYPE_STRING,
TYPE_DBL = TYPE_DOUBLE, TYPE_DBL = TYPE_DOUBLE,
TYPE_BOOL = TYPE_TINY, TYPE_BOOL = TYPE_TINY,
TYPE_BINT = TYPE_BIGINT, TYPE_BINT = TYPE_BIGINT,
...@@ -146,6 +147,7 @@ class JSON : public BLOCK { ...@@ -146,6 +147,7 @@ class JSON : public BLOCK {
JSON(void) {Size = 0;} JSON(void) {Size = 0;}
int size(void) {return Size;} int size(void) {return Size;}
virtual int GetSize(bool b) {return Size;}
virtual void Clear(void) {Size = 0;} virtual void Clear(void) {Size = 0;}
virtual JTYP GetType(void) {return TYPE_JSON;} virtual JTYP GetType(void) {return TYPE_JSON;}
virtual JTYP GetValType(void) {X return TYPE_JSON;} virtual JTYP GetValType(void) {X return TYPE_JSON;}
...@@ -193,10 +195,11 @@ class JOBJECT : public JSON { ...@@ -193,10 +195,11 @@ class JOBJECT : public JSON {
using JSON::GetValue; using JSON::GetValue;
using JSON::SetValue; using JSON::SetValue;
virtual void Clear(void) {First = Last = NULL; Size = 0;} virtual void Clear(void) {First = Last = NULL; Size = 0;}
virtual JTYP GetType(void) {return TYPE_JOB;} virtual JTYP GetType(void) {return TYPE_JOB;}
virtual PJPR GetFirst(void) {return First;} virtual PJPR GetFirst(void) {return First;}
virtual PJPR AddPair(PGLOBAL g, PCSZ key); virtual int GetSize(bool b);
virtual PJPR AddPair(PGLOBAL g, PCSZ key);
virtual PJOB GetObject(void) {return this;} virtual PJOB GetObject(void) {return this;}
virtual PJVAL GetValue(const char* key); virtual PJVAL GetValue(const char* key);
virtual PJAR GetKeyList(PGLOBAL g); virtual PJAR GetKeyList(PGLOBAL g);
...@@ -222,11 +225,13 @@ class JARRAY : public JSON { ...@@ -222,11 +225,13 @@ class JARRAY : public JSON {
using JSON::GetValue; using JSON::GetValue;
using JSON::SetValue; using JSON::SetValue;
virtual void Clear(void) {First = Last = NULL; Size = 0;} virtual void Clear(void) {First = Last = NULL; Size = 0;}
virtual JTYP GetType(void) {return TYPE_JAR;} virtual JTYP GetType(void) {return TYPE_JAR;}
virtual PJAR GetArray(void) {return this;} virtual PJAR GetArray(void) {return this;}
PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL, int *x = NULL); virtual int GetSize(bool b);
PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL, int *x = NULL);
virtual void InitArray(PGLOBAL g); virtual void InitArray(PGLOBAL g);
virtual PJVAL GetValue(int i); virtual PJVAL GetValue(int i);
virtual PSZ GetText(PGLOBAL g, PSZ text);
virtual bool Merge(PGLOBAL g, PJSON jsp); virtual bool Merge(PGLOBAL g, PJSON jsp);
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i); virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i);
virtual bool DeleteValue(int n); virtual bool DeleteValue(int n);
...@@ -246,20 +251,20 @@ class JARRAY : public JSON { ...@@ -246,20 +251,20 @@ class JARRAY : public JSON {
class JVALUE : public JSON { class JVALUE : public JSON {
friend class JARRAY; friend class JARRAY;
friend class JSNX; friend class JSNX;
friend class JSONCOL;
friend PJVAL ParseValue(PGLOBAL, int&, STRG&, bool*); friend PJVAL ParseValue(PGLOBAL, int&, STRG&, bool*);
friend bool SerializeValue(JOUT *, PJVAL); friend bool SerializeValue(JOUT *, PJVAL);
public: public:
JVALUE(void) : JSON() JVALUE(void) : JSON() {Clear();}
{Jsp = NULL; Value = NULL; Next = NULL; Del = false;}
JVALUE(PJSON jsp) : JSON() JVALUE(PJSON jsp) : JSON()
{Jsp = jsp; Value = NULL; Next = NULL; Del = false;} {Jsp = jsp; Value = NULL; Next = NULL; Del = false; Size = 1;}
JVALUE(PGLOBAL g, PVAL valp); JVALUE(PGLOBAL g, PVAL valp);
JVALUE(PGLOBAL g, PCSZ strp); JVALUE(PGLOBAL g, PCSZ strp);
using JSON::GetValue; using JSON::GetValue;
using JSON::SetValue; using JSON::SetValue;
virtual void Clear(void) virtual void Clear(void)
{Jsp = NULL; Value = NULL; Next = NULL; Del = false; Size = 0;} {Jsp = NULL; Value = NULL; Next = NULL; Del = false; Size = 1;}
virtual JTYP GetType(void) {return TYPE_JVAL;} virtual JTYP GetType(void) {return TYPE_JVAL;}
virtual JTYP GetValType(void); virtual JTYP GetValType(void);
virtual PJOB GetObject(void); virtual PJOB GetObject(void);
......
This diff is collapsed.
...@@ -53,6 +53,18 @@ extern "C" { ...@@ -53,6 +53,18 @@ extern "C" {
DllExport char *json_array_delete(UDF_EXEC_ARGS); DllExport char *json_array_delete(UDF_EXEC_ARGS);
DllExport void json_array_delete_deinit(UDF_INIT*); DllExport void json_array_delete_deinit(UDF_INIT*);
DllExport my_bool jsonsum_int_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport long long jsonsum_int(UDF_INIT*, UDF_ARGS*, char*, char*);
DllExport void jsonsum_int_deinit(UDF_INIT*);
DllExport my_bool jsonsum_real_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport double jsonsum_real(UDF_INIT*, UDF_ARGS*, char*, char*);
DllExport void jsonsum_real_deinit(UDF_INIT*);
DllExport my_bool jsonavg_real_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport double jsonavg_real(UDF_INIT*, UDF_ARGS*, char*, char*);
DllExport void jsonavg_real_deinit(UDF_INIT*);
DllExport my_bool json_make_object_init(UDF_INIT*, UDF_ARGS*, char*); DllExport my_bool json_make_object_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *json_make_object(UDF_EXEC_ARGS); DllExport char *json_make_object(UDF_EXEC_ARGS);
DllExport void json_make_object_deinit(UDF_INIT*); DllExport void json_make_object_deinit(UDF_INIT*);
......
...@@ -19,11 +19,265 @@ ...@@ -19,11 +19,265 @@
#include "xtable.h" #include "xtable.h"
#include "tabext.h" #include "tabext.h"
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
#include "tabmgo.h" #include "tabcmg.h"
#endif // MONGO_SUPPORT #endif // MONGO_SUPPORT
#if defined(JDBC_SUPPORT) #if defined(JDBC_SUPPORT)
#include "tabjmg.h" #include "tabjmg.h"
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
#include "resource.h"
/***********************************************************************/
/* This should be an option. */
/***********************************************************************/
#define MAXCOL 200 /* Default max column nb in result */
#define TYPE_UNKNOWN 12 /* Must be greater than other types */
bool IsNum(PSZ s);
/***********************************************************************/
/* MGOColumns: construct the result blocks containing the description */
/* of all the columns of a document contained inside MongoDB. */
/***********************************************************************/
PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info)
{
static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT,
TYPE_INT, TYPE_SHORT, TYPE_SHORT, TYPE_STRING};
static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC,
FLD_LENGTH, FLD_SCALE, FLD_NULL, FLD_FORMAT};
unsigned int length[] = {0, 6, 8, 10, 10, 6, 6, 0};
int ncol = sizeof(buftyp) / sizeof(int);
int i, n = 0;
//PCSZ drv;
PBCOL bcp;
MGODISC *cmgd;
PQRYRES qrp;
PCOLRES crp;
if (info) {
length[0] = 128;
length[7] = 256;
goto skipit;
} // endif info
/*********************************************************************/
/* Open MongoDB. */
/*********************************************************************/
# if !defined(JDBC_SUPPORT)
cmgd = new(g) CMGDISC(g, (int*)length);
#elif !defined(MONGO_SUPPORT)
cmgd = new(g) JMGDISC(g, (int*)length);
#else
drv = GetStringTableOption(g, topt, "Driver", "C");
if (toupper(*drv) == 'C')
cmgd = new(g) CMGDISC(g, (int*)length);
else
cmgd = new(g) JMGDISC(g, (int*)length);
#endif
if ((n = cmgd->GetColumns(g, db, uri, topt)) < 0)
goto err;
skipit:
if (trace)
htrc("MGOColumns: n=%d len=%d\n", n, length[0]);
/*********************************************************************/
/* Allocate the structures used to refer to the result set. */
/*********************************************************************/
qrp = PlgAllocResult(g, ncol, n, IDS_COLUMNS + 3,
buftyp, fldtyp, length, false, false);
crp = qrp->Colresp->Next->Next->Next->Next->Next->Next;
crp->Name = "Nullable";
crp->Next->Name = "Bpath";
if (info || !qrp)
return qrp;
qrp->Nblin = n;
/*********************************************************************/
/* Now get the results into blocks. */
/*********************************************************************/
for (i = 0, bcp = cmgd->fbcp; bcp; i++, bcp = bcp->Next) {
if (bcp->Type == TYPE_UNKNOWN) // Void column
bcp->Type = TYPE_STRING;
crp = qrp->Colresp; // Column Name
crp->Kdata->SetValue(bcp->Name, i);
crp = crp->Next; // Data Type
crp->Kdata->SetValue(bcp->Type, i);
crp = crp->Next; // Type Name
crp->Kdata->SetValue(GetTypeName(bcp->Type), i);
crp = crp->Next; // Precision
crp->Kdata->SetValue(bcp->Len, i);
crp = crp->Next; // Length
crp->Kdata->SetValue(bcp->Len, i);
crp = crp->Next; // Scale (precision)
crp->Kdata->SetValue(bcp->Scale, i);
crp = crp->Next; // Nullable
crp->Kdata->SetValue(bcp->Cbn ? 1 : 0, i);
crp = crp->Next; // Field format
if (crp->Kdata)
crp->Kdata->SetValue(bcp->Fmt, i);
} // endfor i
/*********************************************************************/
/* Return the result pointer. */
/*********************************************************************/
return qrp;
err:
if (cmgd->tmgp)
cmgd->tmgp->CloseDB(g);
return NULL;
} // end of MGOColumns
/***********************************************************************/
/* Class used to get the columns of a mongo collection. */
/***********************************************************************/
MGODISC::MGODISC(PGLOBAL g, int *lg) {
length = lg;
fbcp = NULL;
pbcp = NULL;
tmgp = NULL;
drv = NULL;
i = ncol = lvl = 0;
all = false;
} // end of MGODISC constructor
/***********************************************************************/
/* Class used to get the columns of a mongo collection. */
/***********************************************************************/
int MGODISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt)
{
PCSZ level = GetStringTableOption(g, topt, "Level", NULL);
PMGODEF tdp;
if (level) {
lvl = atoi(level);
lvl = (lvl > 16) ? 16 : lvl;
} else
lvl = 0;
all = GetBooleanTableOption(g, topt, "Fullarray", false);
/*********************************************************************/
/* Open the MongoDB collection. */
/*********************************************************************/
tdp = new(g) MGODEF;
tdp->Uri = uri;
tdp->Driver = drv;
tdp->Tabname = GetStringTableOption(g, topt, "Name", NULL);
tdp->Tabname = GetStringTableOption(g, topt, "Tabname", tdp->Tabname);
tdp->Tabschema = GetStringTableOption(g, topt, "Dbname", db);
tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0;
tdp->Colist = GetStringTableOption(g, topt, "Colist", "all");
tdp->Filter = GetStringTableOption(g, topt, "Filter", NULL);
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
tdp->Version = GetIntegerTableOption(g, topt, "Version", 3);
tdp->Wrapname = (PSZ)GetStringTableOption(g, topt, "Wrapper",
(tdp->Version == 2) ? "Mongo2Interface" : "Mongo3Interface");
if (trace)
htrc("Uri %s coll=%s db=%s colist=%s filter=%s lvl=%d\n",
tdp->Uri, tdp->Tabname, tdp->Tabschema, tdp->Colist, tdp->Filter, lvl);
tmgp = tdp->GetTable(g, MODE_READ);
tmgp->SetMode(MODE_READ);
if (tmgp->OpenDB(g))
return -1;
bcol.Next = NULL;
bcol.Name = bcol.Fmt = NULL;
bcol.Type = TYPE_UNKNOWN;
bcol.Len = bcol.Scale = 0;
bcol.Found = true;
bcol.Cbn = false;
if (Init(g))
return -1;
/*********************************************************************/
/* Analyse the BSON tree and define columns. */
/*********************************************************************/
for (i = 1; ; i++) {
switch (tmgp->ReadDB(g)) {
case RC_EF:
return ncol;
case RC_FX:
return -1;
default:
GetDoc();
} // endswitch ReadDB
if (Find(g))
return -1;
// Missing columns can be null
for (bcp = fbcp; bcp; bcp = bcp->Next) {
bcp->Cbn |= !bcp->Found;
bcp->Found = false;
} // endfor bcp
} // endfor i
return ncol;
} // end of GetColumns
/***********************************************************************/
/* Add a new column in the column list. */
/***********************************************************************/
void MGODISC::AddColumn(PGLOBAL g, PCSZ colname, PCSZ fmt, int k)
{
// Check whether this column was already found
for (bcp = fbcp; bcp; bcp = bcp->Next)
if (!strcmp(colname, bcp->Name))
break;
if (bcp) {
if (bcp->Type != bcol.Type)
bcp->Type = TYPE_STRING;
if (k && *fmt && (!bcp->Fmt || strlen(bcp->Fmt) < strlen(fmt))) {
bcp->Fmt = PlugDup(g, fmt);
length[7] = MY_MAX(length[7], strlen(fmt));
} // endif *fmt
bcp->Len = MY_MAX(bcp->Len, bcol.Len);
bcp->Scale = MY_MAX(bcp->Scale, bcol.Scale);
bcp->Cbn |= bcol.Cbn;
bcp->Found = true;
} else {
// New column
bcp = (PBCOL)PlugSubAlloc(g, NULL, sizeof(BCOL));
*bcp = bcol;
bcp->Cbn |= (i > 1);
bcp->Name = PlugDup(g, colname);
length[0] = MY_MAX(length[0], strlen(colname));
if (k) {
bcp->Fmt = PlugDup(g, fmt);
length[7] = MY_MAX(length[7], strlen(fmt));
} else
bcp->Fmt = NULL;
if (pbcp) {
bcp->Next = pbcp->Next;
pbcp->Next = bcp;
} else
fbcp = bcp;
ncol++;
} // endif jcp
pbcp = bcp;
} // end of AddColumn
/* -------------------------- Class MGODEF --------------------------- */ /* -------------------------- Class MGODEF --------------------------- */
...@@ -91,7 +345,7 @@ PTDB MGODEF::GetTable(PGLOBAL g, MODE m) ...@@ -91,7 +345,7 @@ PTDB MGODEF::GetTable(PGLOBAL g, MODE m)
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
if (Driver && toupper(*Driver) == 'C') if (Driver && toupper(*Driver) == 'C')
return new(g) TDBMGO(this); return new(g) TDBCMG(this);
#endif // MONGO_SUPPORT #endif // MONGO_SUPPORT
#if defined(JDBC_SUPPORT) #if defined(JDBC_SUPPORT)
return new(g) TDBJMG(this); return new(g) TDBJMG(this);
...@@ -100,4 +354,3 @@ PTDB MGODEF::GetTable(PGLOBAL g, MODE m) ...@@ -100,4 +354,3 @@ PTDB MGODEF::GetTable(PGLOBAL g, MODE m)
return NULL; return NULL;
#endif // !JDBC_SUPPORT #endif // !JDBC_SUPPORT
} // end of GetTable } // end of GetTable
...@@ -25,15 +25,43 @@ typedef struct _bncol { ...@@ -25,15 +25,43 @@ typedef struct _bncol {
bool Found; bool Found;
} BCOL, *PBCOL; } BCOL, *PBCOL;
/***********************************************************************/
/* Class used to get the columns of a mongo collection. */
/***********************************************************************/
class MGODISC : public BLOCK {
public:
// Constructor
MGODISC(PGLOBAL g, int *lg);
// Methods
virtual bool Init(PGLOBAL g) { return false; }
virtual void GetDoc(void) {}
virtual bool Find(PGLOBAL g) = 0;
// Functions
int GetColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt);
void AddColumn(PGLOBAL g, PCSZ colname, PCSZ fmt, int k);
// Members
BCOL bcol;
PBCOL bcp, fbcp, pbcp;
PMGODEF tdp;
PTDB tmgp;
PCSZ drv;
int *length;
int i, ncol, lvl;
bool all;
}; // end of MGODISC
/***********************************************************************/ /***********************************************************************/
/* MongoDB table. */ /* MongoDB table. */
/***********************************************************************/ /***********************************************************************/
class DllExport MGODEF : public EXTDEF { /* Table description */ class DllExport MGODEF : public EXTDEF { /* Table description */
friend class TDBMGO; friend class TDBCMG;
friend class TDBJMG; friend class TDBJMG;
friend class TDBGOL; friend class TDBGOL;
friend class TDBJGL; friend class TDBJGL;
friend class MGOFAM; friend class CMGFAM;
friend class MGODISC; friend class MGODISC;
friend PQRYRES MGOColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool); friend PQRYRES MGOColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool);
public: public:
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
/* */ /* */
/* PROGRAM NAME: PLUGUTIL */ /* PROGRAM NAME: PLUGUTIL */
/* ------------- */ /* ------------- */
/* Version 2.9 */ /* Version 3.0 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 1993-2015 */ /* (C) Copyright to the author Olivier BERTRAND 1993-2017 */
/* */ /* */
/* WHAT THIS PROGRAM DOES: */ /* WHAT THIS PROGRAM DOES: */
/* ----------------------- */ /* ----------------------- */
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
#include "osutil.h" #include "osutil.h"
#include "global.h" #include "global.h"
#include "plgdbsem.h"
#if defined(NEWMSG) #if defined(NEWMSG)
#include "rcmsg.h" #include "rcmsg.h"
#endif // NEWMSG #endif // NEWMSG
...@@ -132,12 +133,12 @@ void htrc(char const *fmt, ...) ...@@ -132,12 +133,12 @@ void htrc(char const *fmt, ...)
/* Return value is the pointer to the Global structure. */ /* Return value is the pointer to the Global structure. */
/***********************************************************************/ /***********************************************************************/
PGLOBAL PlugInit(LPCSTR Language, uint worksize) PGLOBAL PlugInit(LPCSTR Language, uint worksize)
{ {
PGLOBAL g; PGLOBAL g;
if (trace > 1) if (trace > 1)
htrc("PlugInit: Language='%s'\n", htrc("PlugInit: Language='%s'\n",
((!Language) ? "Null" : (char*)Language)); ((!Language) ? "Null" : (char*)Language));
try { try {
g = new GLOBAL; g = new GLOBAL;
...@@ -146,53 +147,54 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize) ...@@ -146,53 +147,54 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize)
return NULL; return NULL;
} // end try/catch } // end try/catch
//if (!(g = (PGLOBAL)malloc(sizeof(GLOBAL)))) { g->Sarea = NULL;
// fprintf(stderr, MSG(GLOBAL_ERROR), (int)sizeof(GLOBAL)); g->Createas = 0;
// return NULL; g->Alchecked = 0;
// } else { g->Mrr = 0;
g->Sarea = NULL; g->Activityp = NULL;
g->Createas = 0; g->Xchk = NULL;
g->Alchecked = 0; g->N = 0;
g->Mrr = 0; g->More = 0;
g->Activityp = NULL; strcpy(g->Message, "");
g->Xchk = NULL;
g->N = 0; /*******************************************************************/
g->More = 0; /* Allocate the main work segment. */
strcpy(g->Message, ""); /*******************************************************************/
if (worksize && !(g->Sarea = PlugAllocMem(g, worksize))) {
/*******************************************************************/ char errmsg[MAX_STR];
/* Allocate the main work segment. */ sprintf(errmsg, MSG(WORK_AREA), g->Message);
/*******************************************************************/ strcpy(g->Message, errmsg);
if (worksize && !(g->Sarea = PlugAllocMem(g, worksize))) { g->Sarea_Size = 0;
char errmsg[MAX_STR]; } else
sprintf(errmsg, MSG(WORK_AREA), g->Message); g->Sarea_Size = worksize;
strcpy(g->Message, errmsg);
g->Sarea_Size = 0; g->jump_level = -1; /* New setting to allow recursive call of Plug */
} else return(g);
g->Sarea_Size = worksize; } /* end of PlugInit */
//} /* endif g */
g->jump_level = -1; /* New setting to allow recursive call of Plug */
return(g);
} /* end of PlugInit */
/***********************************************************************/ /***********************************************************************/
/* PlugExit: Terminate Plug operations. */ /* PlugExit: Terminate Plug operations. */
/***********************************************************************/ /***********************************************************************/
int PlugExit(PGLOBAL g) int PlugExit(PGLOBAL g)
{ {
int rc = 0; if (g) {
PDBUSER dup = PlgGetUser(g);
if (dup)
free(dup);
if (g->Sarea) {
if (trace)
htrc("Freeing Sarea size=%d\n", g->Sarea_Size);
if (!g) free(g->Sarea);
return rc; } // endif Sarea
if (g->Sarea) delete g;
free(g->Sarea); } // endif g
delete g; return 0;
return rc; } // end of PlugExit
} /* end of PlugExit */
/***********************************************************************/ /***********************************************************************/
/* Remove the file type from a file name. */ /* Remove the file type from a file name. */
...@@ -456,7 +458,7 @@ short GetLineLength(PGLOBAL g) ...@@ -456,7 +458,7 @@ short GetLineLength(PGLOBAL g)
/* Program for memory allocation of work and language areas. */ /* Program for memory allocation of work and language areas. */
/***********************************************************************/ /***********************************************************************/
void *PlugAllocMem(PGLOBAL g, uint size) void *PlugAllocMem(PGLOBAL g, uint size)
{ {
void *areap; /* Pointer to allocated area */ void *areap; /* Pointer to allocated area */
/*********************************************************************/ /*********************************************************************/
...@@ -465,16 +467,16 @@ void *PlugAllocMem(PGLOBAL g, uint size) ...@@ -465,16 +467,16 @@ void *PlugAllocMem(PGLOBAL g, uint size)
if (!(areap = malloc(size))) if (!(areap = malloc(size)))
sprintf(g->Message, MSG(MALLOC_ERROR), "malloc"); sprintf(g->Message, MSG(MALLOC_ERROR), "malloc");
if (trace > 1) { if (trace) {
if (areap) if (areap)
htrc("Memory of %u allocated at %p\n", size, areap); htrc("Memory of %u allocated at %p\n", size, areap);
else else
htrc("PlugAllocMem: %s\n", g->Message); htrc("PlugAllocMem: %s\n", g->Message);
} // endif trace } // endif trace
return (areap); return (areap);
} /* end of PlugAllocMem */ } // end of PlugAllocMem
/***********************************************************************/ /***********************************************************************/
/* Program for SubSet initialization of memory pools. */ /* Program for SubSet initialization of memory pools. */
......
/**************** tabmgo H Declares Source Code File (.H) **************/ /**************** tabcmg H Declares Source Code File (.H) **************/
/* Name: tabmgo.h Version 1.1 */ /* Name: tabcmg.h Version 1.2 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */ /* (C) Copyright to the author Olivier BERTRAND 2017 */
/* */ /* */
...@@ -11,45 +11,46 @@ ...@@ -11,45 +11,46 @@
/***********************************************************************/ /***********************************************************************/
/* Class used to get the columns of a mongo collection. */ /* Class used to get the columns of a mongo collection. */
/***********************************************************************/ /***********************************************************************/
class MGODISC : public BLOCK { class CMGDISC : public MGODISC {
public: public:
// Constructor // Constructor
MGODISC(PGLOBAL g, int *lg); CMGDISC(PGLOBAL g, int *lg) : MGODISC(g, lg) { drv = "C"; }
// Functions // Methods
int GetColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt); virtual void GetDoc(void);
//virtual bool Find(PGLOBAL g, int i, int k, bool b);
virtual bool Find(PGLOBAL g);
// BSON Function
//bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc,
// char *pcn, char *pfmt, int i, int k, bool b);
bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc, bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc,
char *pcn, char *pfmt, int i, int k, bool b); char *pcn, char *pfmt, int k, bool b);
// Members // Members
BCOL bcol; bson_iter_t iter;
PBCOL bcp, fbcp, pbcp; const bson_t *doc;
PMGODEF tdp; }; // end of CMGDISC
TDBMGO *tmgp;
int *length;
int n, k, lvl;
bool all;
}; // end of MGODISC
/* -------------------------- TDBMGO class --------------------------- */ /* -------------------------- TDBCMG class --------------------------- */
/***********************************************************************/ /***********************************************************************/
/* This is the MongoDB Table Type class declaration. */ /* This is the MongoDB Table Type class declaration. */
/* The table is a collection, each record being a document. */ /* The table is a collection, each record being a document. */
/***********************************************************************/ /***********************************************************************/
class DllExport TDBMGO : public TDBEXT { class DllExport TDBCMG : public TDBEXT {
friend class MGOCOL; friend class MGOCOL;
friend class MGODEF; friend class MGODEF;
friend class MGODISC; friend class CMGDISC;
friend PQRYRES MGOColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool); friend PQRYRES MGOColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool);
public: public:
// Constructor // Constructor
TDBMGO(MGODEF *tdp); TDBCMG(MGODEF *tdp);
TDBMGO(TDBMGO *tdbp); TDBCMG(TDBCMG *tdbp);
// Implementation // Implementation
virtual AMT GetAmType(void) {return TYPE_AM_MGO;} virtual AMT GetAmType(void) {return TYPE_AM_MGO;}
virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBMGO(this);} virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBCMG(this);}
// Methods // Methods
virtual PTDB Clone(PTABS t); virtual PTDB Clone(PTABS t);
...@@ -78,7 +79,7 @@ class DllExport TDBMGO : public TDBEXT { ...@@ -78,7 +79,7 @@ class DllExport TDBMGO : public TDBEXT {
int N; // The current Rownum int N; // The current Rownum
int B; // Array index base int B; // Array index base
bool Done; // Init done bool Done; // Init done
}; // end of class TDBMGO }; // end of class TDBCMG
/* --------------------------- MGOCOL class -------------------------- */ /* --------------------------- MGOCOL class -------------------------- */
...@@ -86,7 +87,7 @@ class DllExport TDBMGO : public TDBEXT { ...@@ -86,7 +87,7 @@ class DllExport TDBMGO : public TDBEXT {
/* Class MGOCOL: MongoDB access method column descriptor. */ /* Class MGOCOL: MongoDB access method column descriptor. */
/***********************************************************************/ /***********************************************************************/
class DllExport MGOCOL : public EXTCOL { class DllExport MGOCOL : public EXTCOL {
friend class TDBMGO; friend class TDBCMG;
friend class FILTER; friend class FILTER;
public: public:
// Constructors // Constructors
...@@ -106,7 +107,7 @@ class DllExport MGOCOL : public EXTCOL { ...@@ -106,7 +107,7 @@ class DllExport MGOCOL : public EXTCOL {
MGOCOL(void) {} MGOCOL(void) {}
// Members // Members
TDBMGO *Tmgp; // To the MGO table block TDBCMG *Tmgp; // To the MGO table block
char *Jpath; // The json path char *Jpath; // The json path
}; // end of class MGOCOL }; // end of class MGOCOL
......
...@@ -27,13 +27,108 @@ ...@@ -27,13 +27,108 @@
#include "mycat.h" // for FNC_COL #include "mycat.h" // for FNC_COL
#include "filter.h" #include "filter.h"
PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info);
/* -------------------------- Class JMGDISC -------------------------- */
/***********************************************************************/ /***********************************************************************/
/* This should be an option. */ /* Initialyze. */
/***********************************************************************/ /***********************************************************************/
#define MAXCOL 200 /* Default max column nb in result */ bool JMGDISC::Init(PGLOBAL g)
#define TYPE_UNKNOWN 12 /* Must be greater than other types */ {
if (!(Jcp = ((TDBJMG*)tmgp)->Jcp)) {
strcpy(g->Message, "Init: Jcp is NULL");
return true;
} else if (Jcp->gmID(g, columnid, "ColumnDesc",
"(Ljava/lang/Object;I[II)Ljava/lang/Object;"))
return true;
else if (Jcp->gmID(g, bvnameid, "ColDescName", "()Ljava/lang/String;"))
return true;
return false;
} // end of Init
/***********************************************************************/
/* Analyse passed document. */
/***********************************************************************/
bool JMGDISC::Find(PGLOBAL g)
{
return ColDesc(g, nullptr, NULL, NULL, Jcp->m_Ncol, 0);
} // end of Find
/***********************************************************************/
/* Analyse passed document. */
/***********************************************************************/
bool JMGDISC::ColDesc(PGLOBAL g, jobject obj, char *pcn, char *pfmt,
int ncol, int k)
{
const char *key;
char colname[65];
char fmt[129];
bool rc = true;
jint *n = nullptr;
jstring jkey;
jobject jres;
// Build the java int array
jintArray val = Jcp->env->NewIntArray(5);
if (val == nullptr) {
strcpy(g->Message, "Cannot allocate jint array");
return true;
} else if (!ncol)
n = Jcp->env->GetIntArrayElements(val, 0);
for (int i = 0; i < ncol; i++) {
jres = Jcp->env->CallObjectMethod(Jcp->job, columnid, obj, i, val, lvl - k);
n = Jcp->env->GetIntArrayElements(val, 0);
if (Jcp->Check(n[0])) {
sprintf(g->Message, "ColDesc: %s", Jcp->Msg);
goto err;
} else if (!n[0])
continue;
jkey = (jstring)Jcp->env->CallObjectMethod(Jcp->job, bvnameid);
key = Jcp->env->GetStringUTFChars(jkey, (jboolean)false);
if (pcn) {
strncpy(colname, pcn, 64);
colname[64] = 0;
strncat(strncat(colname, "_", 65), key, 65);
} else
strcpy(colname, key);
if (pfmt) {
strncpy(fmt, pfmt, 128);
fmt[128] = 0;
strncat(strncat(fmt, ".", 129), key, 129);
} else
strcpy(fmt, key);
PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info); if (!jres) {
bcol.Type = n[0];
bcol.Len = n[1];
bcol.Scale = n[2];
bcol.Cbn = n[3];
AddColumn(g, colname, fmt, k);
} else {
if (n[0] == 2 && !all)
n[4] = MY_MIN(n[4], 1);
if (ColDesc(g, jres, colname, fmt, n[4], k + 1))
goto err;
} // endif jres
} // endfor i
rc = false;
err:
Jcp->env->ReleaseIntArrayElements(val, n, 0);
return rc;
} // end of ColDesc
/* --------------------------- Class TDBJMG -------------------------- */ /* --------------------------- Class TDBJMG -------------------------- */
...@@ -82,16 +177,6 @@ TDBJMG::TDBJMG(PMGODEF tdp) : TDBEXT(tdp) ...@@ -82,16 +177,6 @@ TDBJMG::TDBJMG(PMGODEF tdp) : TDBEXT(tdp)
TDBJMG::TDBJMG(TDBJMG *tdbp) : TDBEXT(tdbp) TDBJMG::TDBJMG(TDBJMG *tdbp) : TDBEXT(tdbp)
{ {
Uri = tdbp->Uri; Uri = tdbp->Uri;
//Pool = tdbp->Pool;
//Client = tdbp->Client;
//Database = NULL;
//Collection = tdbp->Collection;
//Cursor = tdbp->Cursor;
//Query = tdbp->Query;
//Opts = tdbp->Opts;
//Fpc = tdbp->Fpc;
//Cnd = tdbp->Cnd;
//Uristr = tdbp->Uristr;
Db_name = tdbp->Db_name;; Db_name = tdbp->Db_name;;
Coll_name = tdbp->Coll_name; Coll_name = tdbp->Coll_name;
Options = tdbp->Options; Options = tdbp->Options;
...@@ -126,11 +211,7 @@ PTDB TDBJMG::Clone(PTABS t) ...@@ -126,11 +211,7 @@ PTDB TDBJMG::Clone(PTABS t)
/***********************************************************************/ /***********************************************************************/
PCOL TDBJMG::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) PCOL TDBJMG::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
{ {
PJMGCOL colp = new(g) JMGCOL(g, cdp, this, cprec, n); return new(g) JMGCOL(g, cdp, this, cprec, n);
//colp->Mbuf = (char*)PlugSubAlloc(g, NULL, colp->Long + 1);
return colp;
//return (colp->ParseJpath(g)) ? NULL : colp;
} // end of MakeCol } // end of MakeCol
/***********************************************************************/ /***********************************************************************/
...@@ -497,12 +578,12 @@ TDBJGL::TDBJGL(PMGODEF tdp) : TDBCAT(tdp) ...@@ -497,12 +578,12 @@ TDBJGL::TDBJGL(PMGODEF tdp) : TDBCAT(tdp)
Db = tdp->GetTabschema(); Db = tdp->GetTabschema();
} // end of TDBJCL constructor } // end of TDBJCL constructor
/***********************************************************************/ /***********************************************************************/
/* GetResult: Get the list the JSON file columns. */ /* GetResult: Get the list the MongoDB collection columns. */
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBJGL::GetResult(PGLOBAL g) PQRYRES TDBJGL::GetResult(PGLOBAL g)
{ {
return JSONColumns(g, Db, Uri, Topt, false); return MGOColumns(g, Db, Uri, Topt, false);
} // end of GetResult } // end of GetResult
/* -------------------------- End of mongo --------------------------- */ /* -------------------------- End of mongo --------------------------- */
...@@ -9,6 +9,31 @@ ...@@ -9,6 +9,31 @@
#include "jmgoconn.h" #include "jmgoconn.h"
#include "jdbccat.h" #include "jdbccat.h"
/***********************************************************************/
/* Class used to get the columns of a mongo collection. */
/***********************************************************************/
class JMGDISC : public MGODISC {
public:
// Constructor
JMGDISC(PGLOBAL g, int *lg) : MGODISC(g, lg)
{ drv = "Java"; Jcp = NULL; columnid = nullptr; }
// Methods
virtual bool Init(PGLOBAL g);
virtual void GetDoc(void) {}
virtual bool Find(PGLOBAL g);
protected:
// Function
bool ColDesc(PGLOBAL g, jobject obj, char *pcn, char *pfmt,
int ncol, int k);
// Members
JMgoConn *Jcp; // Points to a Mongo connection class
jmethodID columnid; // The ColumnDesc method ID
jmethodID bvnameid; // The ColDescName method ID
}; // end of JMGDISC
/* -------------------------- TDBJMG class --------------------------- */ /* -------------------------- TDBJMG class --------------------------- */
/***********************************************************************/ /***********************************************************************/
...@@ -18,7 +43,7 @@ ...@@ -18,7 +43,7 @@
class DllExport TDBJMG : public TDBEXT { class DllExport TDBJMG : public TDBEXT {
friend class JMGCOL; friend class JMGCOL;
friend class MGODEF; friend class MGODEF;
friend class MGODISC; friend class JMGDISC;
friend class JAVAConn; friend class JAVAConn;
friend PQRYRES MGOColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool); friend PQRYRES MGOColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool);
public: public:
......
/************* tabjson C++ Program Source Code File (.CPP) *************/ /************* tabjson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjson Version 1.4 */ /* PROGRAM NAME: tabjson Version 1.5 */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */ /* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */
/* This program are the JSON class DB execution routines. */ /* This program are the JSON class DB execution routines. */
/***********************************************************************/ /***********************************************************************/
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "jmgfam.h" #include "jmgfam.h"
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
#include "mongofam.h" #include "cmgfam.h"
#endif // MONGO_SUPPORT #endif // MONGO_SUPPORT
#include "tabmul.h" #include "tabmul.h"
#include "checklvl.h" #include "checklvl.h"
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
/***********************************************************************/ /***********************************************************************/
#define MAXCOL 200 /* Default max column nb in result */ #define MAXCOL 200 /* Default max column nb in result */
#define TYPE_UNKNOWN 12 /* Must be greater than other types */ #define TYPE_UNKNOWN 12 /* Must be greater than other types */
#define USE_G 1 /* Use recoverable memory if 1 */
/***********************************************************************/ /***********************************************************************/
/* External functions. */ /* External functions. */
...@@ -55,6 +54,7 @@ ...@@ -55,6 +54,7 @@
USETEMP UseTemp(void); USETEMP UseTemp(void);
bool IsNum(PSZ s); bool IsNum(PSZ s);
char *NextChr(PSZ s, char sep); char *NextChr(PSZ s, char sep);
char *GetJsonNull(void);
typedef struct _jncol { typedef struct _jncol {
struct _jncol *Next; struct _jncol *Next;
...@@ -199,12 +199,12 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) ...@@ -199,12 +199,12 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
} else if (tdp->Uri) { } else if (tdp->Uri) {
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT) #if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if !defined(JDBC_SUPPORT) #if !defined(JDBC_SUPPORT)
tjnp = new(g) TDBJSN(tdp, new(g) MGOFAM(tdp)); tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp));
#elif !defined(MONGO_SUPPORT) #elif !defined(MONGO_SUPPORT)
tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp));
#else #else
if (tdp->Driver && toupper(*tdp->Driver) == 'C') if (tdp->Driver && toupper(*tdp->Driver) == 'C')
tjnp = new(g) TDBJSN(tdp, new(g) MGOFAM(tdp)); tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp));
else else
tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp));
#endif #endif
...@@ -217,7 +217,6 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) ...@@ -217,7 +217,6 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
tjnp->SetMode(MODE_READ); tjnp->SetMode(MODE_READ);
#if USE_G
// Allocate the parse work memory // Allocate the parse work memory
PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL)); PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL));
memset(G, 0, sizeof(GLOBAL)); memset(G, 0, sizeof(GLOBAL));
...@@ -226,9 +225,6 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) ...@@ -226,9 +225,6 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
PlugSubSet(G, G->Sarea, G->Sarea_Size); PlugSubSet(G, G->Sarea, G->Sarea_Size);
G->jump_level = 0; G->jump_level = 0;
tjnp->SetG(G); tjnp->SetG(G);
#else
tjnp->SetG(g);
#endif
if (tjnp->OpenDB(g)) if (tjnp->OpenDB(g))
return NULL; return NULL;
...@@ -560,12 +556,12 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -560,12 +556,12 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
if (Uri) { if (Uri) {
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT) #if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if !defined(JDBC_SUPPORT) #if !defined(JDBC_SUPPORT)
txfp = new(g) MGOFAM(this); txfp = new(g) CMGFAM(this);
#elif !defined(MONGO_SUPPORT) #elif !defined(MONGO_SUPPORT)
txfp = new(g) JMGFAM(this); txfp = new(g) JMGFAM(this);
#else #else
if (Driver && toupper(*Driver) == 'C') if (Driver && toupper(*Driver) == 'C')
txfp = new(g) MGOFAM(this); txfp = new(g) CMGFAM(this);
else else
txfp = new(g) JMGFAM(this); txfp = new(g) JMGFAM(this);
#endif #endif
...@@ -602,7 +598,6 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -602,7 +598,6 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
// Txfp must be set for TDBDOS // Txfp must be set for TDBDOS
tdbp = new(g) TDBJSN(this, txfp); tdbp = new(g) TDBJSN(this, txfp);
#if USE_G
if (Lrecl) { if (Lrecl) {
// Allocate the parse work memory // Allocate the parse work memory
PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL)); PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL));
...@@ -616,9 +611,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -616,9 +611,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
strcpy(g->Message, "LRECL is not defined"); strcpy(g->Message, "LRECL is not defined");
return NULL; return NULL;
} // endif Lrecl } // endif Lrecl
#else
((TDBJSN*)tdbp)->G = g;
#endif
} else { } else {
if (Zipped) { if (Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
...@@ -903,10 +896,8 @@ int TDBJSN::ReadDB(PGLOBAL g) ...@@ -903,10 +896,8 @@ int TDBJSN::ReadDB(PGLOBAL g)
// Deferred reading failed // Deferred reading failed
return rc; return rc;
#if USE_G
// Recover the memory used for parsing // Recover the memory used for parsing
PlugSubSet(G, G->Sarea, G->Sarea_Size); PlugSubSet(G, G->Sarea, G->Sarea_Size);
#endif
if ((Row = ParseJson(G, To_Line, strlen(To_Line), &Pretty, &Comma))) { if ((Row = ParseJson(G, To_Line, strlen(To_Line), &Pretty, &Comma))) {
Row = FindRow(g); Row = FindRow(g);
...@@ -915,9 +906,7 @@ int TDBJSN::ReadDB(PGLOBAL g) ...@@ -915,9 +906,7 @@ int TDBJSN::ReadDB(PGLOBAL g)
M = 1; M = 1;
rc = RC_OK; rc = RC_OK;
} else if (Pretty != 1 || strcmp(To_Line, "]")) { } else if (Pretty != 1 || strcmp(To_Line, "]")) {
#if USE_G
strcpy(g->Message, G->Message); strcpy(g->Message, G->Message);
#endif
rc = RC_FX; rc = RC_FX;
} else } else
rc = RC_EF; rc = RC_EF;
...@@ -1030,9 +1019,7 @@ int TDBJSN::WriteDB(PGLOBAL g) ...@@ -1030,9 +1019,7 @@ int TDBJSN::WriteDB(PGLOBAL g)
{ {
int rc = TDBDOS::WriteDB(g); int rc = TDBDOS::WriteDB(g);
#if USE_G
PlugSubSet(G, G->Sarea, G->Sarea_Size); PlugSubSet(G, G->Sarea, G->Sarea_Size);
#endif
Row->Clear(); Row->Clear();
return rc; return rc;
} // end of WriteDB } // end of WriteDB
...@@ -1586,8 +1573,11 @@ PVAL JSONCOL::CalculateArray(PGLOBAL g, PJAR arp, int n) ...@@ -1586,8 +1573,11 @@ PVAL JSONCOL::CalculateArray(PGLOBAL g, PJAR arp, int n)
for (i = 0; i < ars; i++) { for (i = 0; i < ars; i++) {
jvrp = arp->GetValue(i); jvrp = arp->GetValue(i);
do { if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) do {
if (n < Nod - 1 && jvrp->GetJson()) { if (jvrp->IsNull()) {
jvrp->Value = AllocateValue(g, GetJsonNull(), TYPE_STRING);
jvp = jvrp;
} else if (n < Nod - 1 && jvrp->GetJson()) {
Tjp->NextSame = nextsame; Tjp->NextSame = nextsame;
jval.SetValue(GetColumnValue(g, jvrp->GetJson(), n + 1)); jval.SetValue(GetColumnValue(g, jvrp->GetJson(), n + 1));
jvp = &jval; jvp = &jval;
......
...@@ -40,7 +40,7 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */ ...@@ -40,7 +40,7 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
friend class JMGFAM; friend class JMGFAM;
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
friend class MGOFAM; friend class CMGFAM;
#endif // MONGO_SUPPORT #endif // MONGO_SUPPORT
friend PQRYRES JSONColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool); friend PQRYRES JSONColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool);
public: public:
...@@ -93,7 +93,7 @@ class DllExport TDBJSN : public TDBDOS { ...@@ -93,7 +93,7 @@ class DllExport TDBJSN : public TDBDOS {
friend class JMGFAM; friend class JMGFAM;
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
friend class MGOFAM; friend class CMGFAM;
#endif // MONGO_SUPPORT #endif // MONGO_SUPPORT
public: public:
// Constructor // Constructor
...@@ -163,7 +163,7 @@ class DllExport JSONCOL : public DOSCOL { ...@@ -163,7 +163,7 @@ class DllExport JSONCOL : public DOSCOL {
friend class JMGFAM; friend class JMGFAM;
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
#if defined(MONGO_SUPPORT) #if defined(MONGO_SUPPORT)
friend class MGOFAM; friend class CMGFAM;
#endif // MONGO_SUPPORT #endif // MONGO_SUPPORT
public: public:
// Constructors // Constructors
......
...@@ -111,7 +111,10 @@ bool user_connect::user_init() ...@@ -111,7 +111,10 @@ bool user_connect::user_init()
int rc= PlugExit(g); int rc= PlugExit(g);
g= NULL; g= NULL;
free(dup);
if (dup)
free(dup);
return true; return true;
} // endif g-> } // endif g->
...@@ -152,10 +155,14 @@ bool user_connect::CheckCleanup(bool force) ...@@ -152,10 +155,14 @@ bool user_connect::CheckCleanup(bool force)
PlugCleanup(g, true); PlugCleanup(g, true);
if (g->Sarea_Size != worksize) { if (g->Sarea_Size != worksize) {
if (g->Sarea) if (g->Sarea) {
free(g->Sarea); if (trace)
htrc("CheckCleanup: Free Sarea %d\n", g->Sarea_Size);
free(g->Sarea);
} // endif Size
// Check whether the work area size was changed // Check whether the work area could be allocated
if (!(g->Sarea = PlugAllocMem(g, worksize))) { if (!(g->Sarea = PlugAllocMem(g, worksize))) {
g->Sarea = PlugAllocMem(g, g->Sarea_Size); g->Sarea = PlugAllocMem(g, g->Sarea_Size);
SetWorkSize(g->Sarea_Size); // Was too big SetWorkSize(g->Sarea_Size); // Was too big
......
...@@ -119,6 +119,7 @@ ulonglong CharToNumber(const char *p, int n, ulonglong maxval, ...@@ -119,6 +119,7 @@ ulonglong CharToNumber(const char *p, int n, ulonglong maxval,
if (minus) *minus = true; if (minus) *minus = true;
} // endif Unsigned } // endif Unsigned
// Fall through
case '+': case '+':
p++; p++;
break; break;
...@@ -571,7 +572,7 @@ void VALUE::Printf(PGLOBAL g, FILE *f, uint n) ...@@ -571,7 +572,7 @@ void VALUE::Printf(PGLOBAL g, FILE *f, uint n)
if (Null) if (Null)
fprintf(f, "%s<null>\n", m); fprintf(f, "%s<null>\n", m);
else else
fprintf(f, strcat(strcat(GetCharString(buf), "\n"), m)); fprintf(f, "%s%s\n", m, GetCharString(buf));
} /* end of Printf */ } /* end of Printf */
...@@ -2566,7 +2567,7 @@ bool DTVAL::SetValue_pval(PVAL valp, bool chktype) ...@@ -2566,7 +2567,7 @@ bool DTVAL::SetValue_pval(PVAL valp, bool chktype)
} else if (valp->GetType() == TYPE_BIGINT && } else if (valp->GetType() == TYPE_BIGINT &&
!(valp->GetBigintValue() % 1000)) { !(valp->GetBigintValue() % 1000)) {
// Assuming that this timestamp is in milliseconds // Assuming that this timestamp is in milliseconds
Tval = valp->GetBigintValue() / 1000; Tval = (int)(valp->GetBigintValue() / 1000);
} else } else
Tval = valp->GetIntValue(); Tval = valp->GetIntValue();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment