Compiling JSON UDFs in a Separate Library
The CONNECT storage engine has been deprecated.
#include "my_global.h"
#include "mysqld.h"
#include "plugin.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include "global.h"
extern "C" int GetTraceValue(void) { return 0; }
uint GetJsonGrpSize(void) { return 100; }
/***********************************************************************/
/* These replace missing function of the (not used) DTVAL class. */
/***********************************************************************/
typedef struct _datpar *PDTP;
PDTP MakeDateFormat(PGLOBAL, PSZ, bool, bool, int) { return NULL; }
int ExtractDate(char*, PDTP, int, int val[6]) { return 0; }
#ifdef __WIN__
my_bool CloseFileHandle(HANDLE h)
{
return !CloseHandle(h);
} /* end of CloseFileHandle */
#else /* UNIX */
my_bool CloseFileHandle(HANDLE h)
{
return (close(h)) ? TRUE : FALSE;
} /* end of CloseFileHandle */
int GetLastError()
{
return errno;
} /* end of GetLastError */
#endif // UNIX
/***********************************************************************/
/* Program for sub-allocating one item in a storage area. */
/* Note: This function is equivalent to PlugSubAlloc except that in */
/* case of insufficient memory, it returns NULL instead of doing a */
/* long jump. The caller must test the return value for error. */
/***********************************************************************/
void *PlgDBSubAlloc(PGLOBAL g, void *memp, size_t size)
{
PPOOLHEADER pph; // Points on area header.
if (!memp) // Allocation is to be done in the Sarea
memp = g->Sarea;
size = ((size + 7) / 8) * 8; /* Round up size to multiple of 8 */
pph = (PPOOLHEADER)memp;
if ((uint)size > pph->FreeBlk) { /* Not enough memory left in pool */
sprintf(g->Message,
"Not enough memory in Work area for request of %d (used=%d free=%d)",
(int)size, pph->To_Free, pph->FreeBlk);
return NULL;
} // endif size
// Do the suballocation the simplest way
memp = MakePtr(memp, pph->To_Free); // Points to sub_allocated block
pph->To_Free += size; // New offset of pool free block
pph->FreeBlk -= size; // New size of pool free block
return (memp);
} // end of PlgDBSubAllocLast updated
Was this helpful?

