Commit d44723e6 authored by Olivier Bertrand's avatar Olivier Bertrand

- MDEV-11295: developing handling files contained in ZIP file.

  A first experimental and limited implementation.
  modified:   storage/connect/CMakeLists.txt
  modified:   storage/connect/filamap.cpp
  new file:   storage/connect/filamzip.cpp
  new file:   storage/connect/filamzip.h
  modified:   storage/connect/ha_connect.cc
  new file:   storage/connect/ioapi.c
  new file:   storage/connect/ioapi.h
  modified:   storage/connect/mycat.cc
  modified:   storage/connect/plgdbsem.h
  modified:   storage/connect/plgdbutl.cpp
  modified:   storage/connect/tabdos.cpp
  modified:   storage/connect/tabdos.h
  modified:   storage/connect/tabfmt.cpp
  modified:   storage/connect/tabfmt.h
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabjson.h
  new file:   storage/connect/tabzip.cpp
  new file:   storage/connect/tabzip.h
  new file:   storage/connect/unzip.c
  new file:   storage/connect/unzip.h
  new file:   storage/connect/zip.c
parent 599d8cc2
...@@ -279,6 +279,18 @@ IF(CONNECT_WITH_JDBC) ...@@ -279,6 +279,18 @@ IF(CONNECT_WITH_JDBC)
ENDIF() ENDIF()
ENDIF(CONNECT_WITH_JDBC) ENDIF(CONNECT_WITH_JDBC)
#
# ZIP
#
OPTION(CONNECT_WITH_ZIP "Compile CONNECT storage engine with ZIP support" ON)
IF(CONNECT_WITH_ZIP)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} filamzip.cpp tabzip.cpp unzip.c ioapi.c zip.c
filamzip.h tabzip.h ioapi.h unzip.h zip.h)
add_definitions(-DZIP_SUPPORT -DNOCRYPT)
ENDIF(CONNECT_WITH_ZIP)
# #
# XMAP # XMAP
......
...@@ -87,7 +87,7 @@ int MAPFAM::GetFileLength(PGLOBAL g) ...@@ -87,7 +87,7 @@ int MAPFAM::GetFileLength(PGLOBAL g)
{ {
int len; int len;
len = (To_Fb) ? To_Fb->Length : TXTFAM::GetFileLength(g); len = (To_Fb && To_Fb->Count) ? To_Fb->Length : TXTFAM::GetFileLength(g);
if (trace) if (trace)
htrc("Mapped file length=%d\n", len); htrc("Mapped file length=%d\n", len);
...@@ -413,7 +413,7 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc) ...@@ -413,7 +413,7 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc)
if (Tpos == Spos) { if (Tpos == Spos) {
/*******************************************************************/ /*******************************************************************/
/* First line to delete. Move of eventual preceeding lines is */ /* First line to delete. Move of eventual preceding lines is */
/* not required here, just setting of future Spos and Tpos. */ /* not required here, just setting of future Spos and Tpos. */
/*******************************************************************/ /*******************************************************************/
Tpos = Spos = Fpos; Tpos = Spos = Fpos;
...@@ -498,7 +498,7 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc) ...@@ -498,7 +498,7 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc)
void MAPFAM::CloseTableFile(PGLOBAL g, bool) void MAPFAM::CloseTableFile(PGLOBAL g, bool)
{ {
PlugCloseFile(g, To_Fb); PlugCloseFile(g, To_Fb);
To_Fb = NULL; // To get correct file size in Cardinality //To_Fb = NULL; // To get correct file size in Cardinality
if (trace) if (trace)
htrc("MAP Close: closing %s count=%d\n", htrc("MAP Close: closing %s count=%d\n",
......
This diff is collapsed.
/************** filamzip H Declares Source Code File (.H) **************/
/* Name: filamzip.h Version 1.0 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2016 */
/* */
/* This file contains the ZIP file access method classes declares. */
/***********************************************************************/
#ifndef __FILAMZIP_H
#define __FILAMZIP_H
#include "block.h"
#include "filamap.h"
#include "unzip.h"
#define DLLEXPORT extern "C"
typedef class ZIPFAM *PZIPFAM;
typedef class ZPXFAM *PZPXFAM;
/***********************************************************************/
/* This is the ZIP file access method. */
/***********************************************************************/
class DllExport ZIPFAM : public MAPFAM {
public:
// Constructor
ZIPFAM(PDOSDEF tdp);
ZIPFAM(PZIPFAM txfp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_ZIP;}
virtual PTXF Duplicate(PGLOBAL g) {return (PTXF) new(g) ZIPFAM(this);}
// Methods
virtual int GetFileLength(PGLOBAL g);
virtual int Cardinality(PGLOBAL g) {return (g) ? 10 : 1;}
//virtual int MaxBlkSize(PGLOBAL g, int s) {return s;}
virtual bool OpenTableFile(PGLOBAL g);
virtual bool DeferReading(void) {return false;}
virtual int ReadBuffer(PGLOBAL g);
//virtual int WriteBuffer(PGLOBAL g);
//virtual int DeleteRecords(PGLOBAL g, int irc);
//virtual void CloseTableFile(PGLOBAL g, bool abort);
void close(void);
protected:
bool open(PGLOBAL g, const char *filename);
bool openEntry(PGLOBAL g);
void closeEntry(void);
bool WildMatch(PSZ pat, PSZ str);
int findEntry(PGLOBAL g, bool next);
// Members
unzFile zipfile; // The ZIP container file
PSZ zfn; // The ZIP file name
PSZ target; // The target file name
unz_file_info finfo; // The current file info
//char fn[FILENAME_MAX]; // The current file name
bool entryopen; // True when open current entry
int multiple; // Multiple targets
char mapCaseTable[256];
}; // end of ZIPFAM
/***********************************************************************/
/* This is the fixed ZIP file access method. */
/***********************************************************************/
class DllExport ZPXFAM : public ZIPFAM {
public:
// Constructor
ZPXFAM(PDOSDEF tdp);
ZPXFAM(PZPXFAM txfp);
// Implementation
virtual PTXF Duplicate(PGLOBAL g) {return (PTXF) new(g) ZPXFAM(this);}
// Methods
virtual int ReadBuffer(PGLOBAL g);
protected:
// Members
int Lrecl;
}; // end of ZPXFAM
#endif // __FILAMZIP_H
...@@ -171,9 +171,9 @@ ...@@ -171,9 +171,9 @@
#define JSONMAX 10 // JSON Default max grp size #define JSONMAX 10 // JSON Default max grp size
extern "C" { extern "C" {
char version[]= "Version 1.04.0008 October 20, 2016"; char version[]= "Version 1.04.0009 December 09, 2016";
#if defined(__WIN__) #if defined(__WIN__)
char compver[]= "Version 1.04.0008 " __DATE__ " " __TIME__; char compver[]= "Version 1.04.0009 " __DATE__ " " __TIME__;
char slash= '\\'; char slash= '\\';
#else // !__WIN__ #else // !__WIN__
char slash= '/'; char slash= '/';
...@@ -4165,7 +4165,8 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn, bool quick) ...@@ -4165,7 +4165,8 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn, bool quick)
case TAB_DIR: case TAB_DIR:
case TAB_MAC: case TAB_MAC:
case TAB_WMI: case TAB_WMI:
case TAB_OEM: case TAB_ZIP:
case TAB_OEM:
#ifdef NO_EMBEDDED_ACCESS_CHECKS #ifdef NO_EMBEDDED_ACCESS_CHECKS
return false; return false;
#endif #endif
...@@ -5173,13 +5174,13 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5173,13 +5174,13 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
char v=0, spc= ',', qch= 0; char v=0, spc= ',', qch= 0;
const char *fncn= "?"; const char *fncn= "?";
const char *user, *fn, *db, *host, *pwd, *sep, *tbl, *src; const char *user, *fn, *db, *host, *pwd, *sep, *tbl, *src;
const char *col, *ocl, *rnk, *pic, *fcl, *skc; const char *col, *ocl, *rnk, *pic, *fcl, *skc, *zfn;
char *tab, *dsn, *shm, *dpath; char *tab, *dsn, *shm, *dpath;
#if defined(__WIN__) #if defined(__WIN__)
char *nsp= NULL, *cls= NULL; char *nsp= NULL, *cls= NULL;
#endif // __WIN__ #endif // __WIN__
int port= 0, hdr= 0, mxr= 0, mxe= 0, rc= 0; //int hdr, mxe;
int cop __attribute__((unused))= 0, lrecl= 0; int port = 0, mxr = 0, rc = 0, mul = 0, lrecl = 0;
#if defined(ODBC_SUPPORT) #if defined(ODBC_SUPPORT)
POPARM sop= NULL; POPARM sop= NULL;
char *ucnc= NULL; char *ucnc= NULL;
...@@ -5211,7 +5212,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5211,7 +5212,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
if (!g) if (!g)
return HA_ERR_INTERNAL_ERROR; return HA_ERR_INTERNAL_ERROR;
user= host= pwd= tbl= src= col= ocl= pic= fcl= skc= rnk= dsn= NULL; user= host= pwd= tbl= src= col= ocl= pic= fcl= skc= rnk= zfn= dsn= NULL;
// Get the useful create options // Get the useful create options
ttp= GetTypeID(topt->type); ttp= GetTypeID(topt->type);
...@@ -5224,7 +5225,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5224,7 +5225,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
sep= topt->separator; sep= topt->separator;
spc= (!sep) ? ',' : *sep; spc= (!sep) ? ',' : *sep;
qch= topt->qchar ? *topt->qchar : (signed)topt->quoted >= 0 ? '"' : 0; qch= topt->qchar ? *topt->qchar : (signed)topt->quoted >= 0 ? '"' : 0;
hdr= (int)topt->header; mul = (int)topt->multiple;
tbl= topt->tablist; tbl= topt->tablist;
col= topt->colist; col= topt->colist;
...@@ -5260,11 +5261,13 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5260,11 +5261,13 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
// prop = GetListOption(g, "Properties", topt->oplist, NULL); // prop = GetListOption(g, "Properties", topt->oplist, NULL);
tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL); tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL);
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
mxe= atoi(GetListOption(g,"maxerr", topt->oplist, "0"));
#if defined(PROMPT_OK) #if defined(PROMPT_OK)
cop= atoi(GetListOption(g, "checkdsn", topt->oplist, "0")); cop= atoi(GetListOption(g, "checkdsn", topt->oplist, "0"));
#endif // PROMPT_OK #endif // PROMPT_OK
} else { #if defined(ZIP_SUPPORT)
zfn = GetListOption(g, "Zipfile", topt->oplist, NULL);
#endif // ZIP_SUPPORT
} else {
host= "localhost"; host= "localhost";
user= (ttp == TAB_ODBC ? NULL : "root"); user= (ttp == TAB_ODBC ? NULL : "root");
} // endif option_list } // endif option_list
...@@ -5471,7 +5474,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5471,7 +5474,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
case TAB_XML: case TAB_XML:
#endif // LIBXML2_SUPPORT || DOMDOC_SUPPORT #endif // LIBXML2_SUPPORT || DOMDOC_SUPPORT
case TAB_JSON: case TAB_JSON:
if (!fn) if (!fn && !zfn && !mul)
sprintf(g->Message, "Missing %s file name", topt->type); sprintf(g->Message, "Missing %s file name", topt->type);
else else
ok= true; ok= true;
...@@ -5585,7 +5588,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5585,7 +5588,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
NULL, port, fnc == FNC_COL); NULL, port, fnc == FNC_COL);
break; break;
case TAB_CSV: case TAB_CSV:
qrp= CSVColumns(g, dpath, fn, spc, qch, hdr, mxe, fnc == FNC_COL); qrp = CSVColumns(g, dpath, topt, fnc == FNC_COL);
break; break;
#if defined(__WIN__) #if defined(__WIN__)
case TAB_WMI: case TAB_WMI:
......
/* ioapi.h -- IO base function header for compress/uncompress .zip
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
For more info read MiniZip_info.txt
*/
#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
#define _CRT_SECURE_NO_WARNINGS
#endif
#if defined(__APPLE__) || defined(IOAPI_NO_64)
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
#define FTELLO_FUNC(stream) ftello(stream)
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
#else
#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
#define FTELLO_FUNC(stream) ftello64(stream)
#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
#endif
#include "ioapi.h"
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
{
if (pfilefunc->zfile_func64.zopen64_file != NULL)
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
else
{
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
}
}
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
{
if (pfilefunc->zfile_func64.zseek64_file != NULL)
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
else
{
uLong offsetTruncated = (uLong)offset;
if (offsetTruncated != offset)
return -1;
else
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
}
}
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
{
if (pfilefunc->zfile_func64.zseek64_file != NULL)
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
else
{
uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
if ((tell_uLong) == MAXU32)
return (ZPOS64_T)-1;
else
return tell_uLong;
}
}
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
{
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
}
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
{
FILE* file = NULL;
const char* mode_fopen = NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
mode_fopen = "rb";
else
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
mode_fopen = "r+b";
else
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
mode_fopen = "wb";
if ((filename!=NULL) && (mode_fopen != NULL))
file = fopen(filename, mode_fopen);
return file;
}
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
{
FILE* file = NULL;
const char* mode_fopen = NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
mode_fopen = "rb";
else
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
mode_fopen = "r+b";
else
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
mode_fopen = "wb";
if ((filename!=NULL) && (mode_fopen != NULL))
file = FOPEN_FUNC((const char*)filename, mode_fopen);
return file;
}
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
{
uLong ret;
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
{
uLong ret;
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
{
long ret;
ret = ftell((FILE *)stream);
return ret;
}
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
{
ZPOS64_T ret;
ret = FTELLO_FUNC((FILE *)stream);
return ret;
}
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
{
int fseek_origin=0;
long ret;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR :
fseek_origin = SEEK_CUR;
break;
case ZLIB_FILEFUNC_SEEK_END :
fseek_origin = SEEK_END;
break;
case ZLIB_FILEFUNC_SEEK_SET :
fseek_origin = SEEK_SET;
break;
default: return -1;
}
ret = 0;
if (fseek((FILE *)stream, offset, fseek_origin) != 0)
ret = -1;
return ret;
}
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
{
int fseek_origin=0;
long ret;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR :
fseek_origin = SEEK_CUR;
break;
case ZLIB_FILEFUNC_SEEK_END :
fseek_origin = SEEK_END;
break;
case ZLIB_FILEFUNC_SEEK_SET :
fseek_origin = SEEK_SET;
break;
default: return -1;
}
ret = 0;
if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
ret = -1;
return ret;
}
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
{
int ret;
ret = fclose((FILE *)stream);
return ret;
}
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
{
int ret;
ret = ferror((FILE *)stream);
return ret;
}
void fill_fopen_filefunc (pzlib_filefunc_def)
zlib_filefunc_def* pzlib_filefunc_def;
{
pzlib_filefunc_def->zopen_file = fopen_file_func;
pzlib_filefunc_def->zread_file = fread_file_func;
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
pzlib_filefunc_def->ztell_file = ftell_file_func;
pzlib_filefunc_def->zseek_file = fseek_file_func;
pzlib_filefunc_def->zclose_file = fclose_file_func;
pzlib_filefunc_def->zerror_file = ferror_file_func;
pzlib_filefunc_def->opaque = NULL;
}
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
{
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
pzlib_filefunc_def->zread_file = fread_file_func;
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
pzlib_filefunc_def->zclose_file = fclose_file_func;
pzlib_filefunc_def->zerror_file = ferror_file_func;
pzlib_filefunc_def->opaque = NULL;
}
/* ioapi.h -- IO base function header for compress/uncompress .zip
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
For more info read MiniZip_info.txt
Changes
Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
More if/def section may be needed to support other platforms
Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
(but you should use iowin32.c for windows instead)
*/
#ifndef _ZLIBIOAPI64_H
#define _ZLIBIOAPI64_H
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
// Linux needs this to support file operation on files larger then 4+GB
// But might need better if/def to select just the platforms that needs them.
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64
#endif
#ifndef __USE_LARGEFILE64
#define __USE_LARGEFILE64
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#ifndef _FILE_OFFSET_BIT
#define _FILE_OFFSET_BIT 64
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include "zlib.h"
#if defined(USE_FILE32API)
#define fopen64 fopen
#define ftello64 ftell
#define fseeko64 fseek
#else
#ifdef __FreeBSD__
#define fopen64 fopen
#define ftello64 ftello
#define fseeko64 fseeko
#endif
#ifdef _MSC_VER
#define fopen64 fopen
#if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
#define ftello64 _ftelli64
#define fseeko64 _fseeki64
#else // old MSC
#define ftello64 ftell
#define fseeko64 fseek
#endif
#endif
#endif
/*
#ifndef ZPOS64_T
#ifdef _WIN32
#define ZPOS64_T fpos_t
#else
#include <stdint.h>
#define ZPOS64_T uint64_t
#endif
#endif
*/
#ifdef HAVE_MINIZIP64_CONF_H
#include "mz64conf.h"
#endif
/* a type choosen by DEFINE */
#ifdef HAVE_64BIT_INT_CUSTOM
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
#else
#ifdef HAS_STDINT_H
#include "stdint.h"
typedef uint64_t ZPOS64_T;
#else
/* Maximum unsigned 32-bit value used as placeholder for zip64 */
#define MAXU32 0xffffffff
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 ZPOS64_T;
#else
typedef unsigned long long int ZPOS64_T;
#endif
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define ZLIB_FILEFUNC_SEEK_CUR (1)
#define ZLIB_FILEFUNC_SEEK_END (2)
#define ZLIB_FILEFUNC_SEEK_SET (0)
#define ZLIB_FILEFUNC_MODE_READ (1)
#define ZLIB_FILEFUNC_MODE_WRITE (2)
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
#define ZLIB_FILEFUNC_MODE_CREATE (8)
#ifndef ZCALLBACK
#if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
#define ZCALLBACK CALLBACK
#else
#define ZCALLBACK
#endif
#endif
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
/* here is the "old" 32 bits structure structure */
typedef struct zlib_filefunc_def_s
{
open_file_func zopen_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell_file_func ztell_file;
seek_file_func zseek_file;
close_file_func zclose_file;
testerror_file_func zerror_file;
voidpf opaque;
} zlib_filefunc_def;
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
typedef struct zlib_filefunc64_def_s
{
open64_file_func zopen64_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell64_file_func ztell64_file;
seek64_file_func zseek64_file;
close_file_func zclose_file;
testerror_file_func zerror_file;
voidpf opaque;
} zlib_filefunc64_def;
void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
/* now internal definition, only for zip.c and unzip.h */
typedef struct zlib_filefunc64_32_def_s
{
zlib_filefunc64_def zfile_func64;
open_file_func zopen32_file;
tell_file_func ztell32_file;
seek_file_func zseek32_file;
} zlib_filefunc64_32_def;
#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
#ifdef __cplusplus
}
#endif
#endif
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
/*************** Mycat CC Program Source Code File (.CC) ***************/ /*************** Mycat CC Program Source Code File (.CC) ***************/
/* PROGRAM NAME: MYCAT */ /* PROGRAM NAME: MYCAT */
/* ------------- */ /* ------------- */
/* Version 1.4 */ /* Version 1.5 */
/* */ /* */
/* Author: Olivier Bertrand 2012 - 2016 */ /* Author: Olivier Bertrand 2012 - 2016 */
/* */ /* */
...@@ -95,6 +95,9 @@ ...@@ -95,6 +95,9 @@
#if defined(XML_SUPPORT) #if defined(XML_SUPPORT)
#include "tabxml.h" #include "tabxml.h"
#endif // XML_SUPPORT #endif // XML_SUPPORT
#if defined(ZIP_SUPPORT)
#include "tabzip.h"
#endif // ZIP_SUPPORT
#include "mycat.h" #include "mycat.h"
/***********************************************************************/ /***********************************************************************/
...@@ -154,7 +157,10 @@ TABTYPE GetTypeID(const char *type) ...@@ -154,7 +157,10 @@ TABTYPE GetTypeID(const char *type)
#endif #endif
: (!stricmp(type, "VIR")) ? TAB_VIR : (!stricmp(type, "VIR")) ? TAB_VIR
: (!stricmp(type, "JSON")) ? TAB_JSON : (!stricmp(type, "JSON")) ? TAB_JSON
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY; #ifdef ZIP_SUPPORT
: (!stricmp(type, "ZIP")) ? TAB_ZIP
#endif
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
} // end of GetTypeID } // end of GetTypeID
/***********************************************************************/ /***********************************************************************/
...@@ -175,6 +181,7 @@ bool IsFileType(TABTYPE type) ...@@ -175,6 +181,7 @@ bool IsFileType(TABTYPE type)
case TAB_INI: case TAB_INI:
case TAB_VEC: case TAB_VEC:
case TAB_JSON: case TAB_JSON:
// case TAB_ZIP:
isfile= true; isfile= true;
break; break;
default: default:
...@@ -575,7 +582,10 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) ...@@ -575,7 +582,10 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
#endif // PIVOT_SUPPORT #endif // PIVOT_SUPPORT
case TAB_VIR: tdp= new(g) VIRDEF; break; case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break; case TAB_JSON: tdp= new(g) JSONDEF; break;
default: #if defined(ZIP_SUPPORT)
case TAB_ZIP: tdp= new(g) ZIPDEF; break;
#endif // ZIP_SUPPORT
default:
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name); sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
} // endswitch } // endswitch
......
/************** PlgDBSem H Declares Source Code File (.H) **************/ /************** PlgDBSem H Declares Source Code File (.H) **************/
/* Name: PLGDBSEM.H Version 3.6 */ /* Name: PLGDBSEM.H Version 3.7 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 1998-2015 */ /* (C) Copyright to the author Olivier BERTRAND 1998-2016 */
/* */ /* */
/* This file contains the PlugDB++ application type definitions. */ /* This file contains the CONNECT storage engine definitions. */
/***********************************************************************/ /***********************************************************************/
/***********************************************************************/ /***********************************************************************/
...@@ -49,7 +49,8 @@ enum BLKTYP {TYPE_TABLE = 50, /* Table Name/Srcdef/... Block */ ...@@ -49,7 +49,8 @@ enum BLKTYP {TYPE_TABLE = 50, /* Table Name/Srcdef/... Block */
TYPE_FB_MAP = 23, /* Mapped file block (storage) */ TYPE_FB_MAP = 23, /* Mapped file block (storage) */
TYPE_FB_HANDLE = 24, /* File block (handle) */ TYPE_FB_HANDLE = 24, /* File block (handle) */
TYPE_FB_XML = 21, /* DOM XML file block */ TYPE_FB_XML = 21, /* DOM XML file block */
TYPE_FB_XML2 = 27}; /* libxml2 XML file block */ TYPE_FB_XML2 = 27, /* libxml2 XML file block */
TYPE_FB_ZIP = 28}; /* ZIP file block */
enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */
TAB_DOS = 1, /* Fixed column offset, variable LRECL */ TAB_DOS = 1, /* Fixed column offset, variable LRECL */
...@@ -78,7 +79,8 @@ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */ ...@@ -78,7 +79,8 @@ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */
TAB_JCT = 24, /* Junction tables NIY */ TAB_JCT = 24, /* Junction tables NIY */
TAB_DMY = 25, /* DMY Dummy tables NIY */ TAB_DMY = 25, /* DMY Dummy tables NIY */
TAB_JDBC = 26, /* Table accessed via JDBC */ TAB_JDBC = 26, /* Table accessed via JDBC */
TAB_NIY = 27}; /* Table not implemented yet */ TAB_ZIP = 27, /* ZIP file info table */
TAB_NIY = 28}; /* Table not implemented yet */
enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */ enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_ROWID = 1, /* ROWID type (special column) */ TYPE_AM_ROWID = 1, /* ROWID type (special column) */
...@@ -140,7 +142,8 @@ enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */ ...@@ -140,7 +142,8 @@ enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_MYSQL = 192, /* MYSQL access method type no */ TYPE_AM_MYSQL = 192, /* MYSQL access method type no */
TYPE_AM_MYX = 193, /* MYSQL EXEC access method type */ TYPE_AM_MYX = 193, /* MYSQL EXEC access method type */
TYPE_AM_CAT = 195, /* Catalog access method type no */ TYPE_AM_CAT = 195, /* Catalog access method type no */
TYPE_AM_OUT = 200}; /* Output relations (storage) */ TYPE_AM_ZIP = 198, /* ZIP access method type no */
TYPE_AM_OUT = 200}; /* Output relations (storage) */
enum RECFM {RECFM_NAF = -2, /* Not a file */ enum RECFM {RECFM_NAF = -2, /* Not a file */
RECFM_OEM = -1, /* OEM file access method */ RECFM_OEM = -1, /* OEM file access method */
......
...@@ -68,6 +68,9 @@ ...@@ -68,6 +68,9 @@
#include "tabcol.h" // header of XTAB and COLUMN classes #include "tabcol.h" // header of XTAB and COLUMN classes
#include "valblk.h" #include "valblk.h"
#include "rcmsg.h" #include "rcmsg.h"
#ifdef ZIP_SUPPORT
#include "filamzip.h"
#endif // ZIP_SUPPORT
/***********************************************************************/ /***********************************************************************/
/* DB static variables. */ /* DB static variables. */
...@@ -934,7 +937,16 @@ int PlugCloseFile(PGLOBAL g __attribute__((unused)), PFBLOCK fp, bool all) ...@@ -934,7 +937,16 @@ int PlugCloseFile(PGLOBAL g __attribute__((unused)), PFBLOCK fp, bool all)
CloseXML2File(g, fp, all); CloseXML2File(g, fp, all);
break; break;
#endif // LIBXML2_SUPPORT #endif // LIBXML2_SUPPORT
default: #ifdef ZIP_SUPPORT
case TYPE_FB_ZIP:
((PZIPFAM)fp->File)->close();
fp->Memory = NULL;
fp->Mode = MODE_ANY;
fp->Count = 0;
fp->File = NULL;
break;
#endif // ZIP_SUPPORT
default:
rc = RC_FX; rc = RC_FX;
} // endswitch Type } // endswitch Type
......
/************* TabDos C++ Program Source Code File (.CPP) **************/ /************* TabDos C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: TABDOS */ /* PROGRAM NAME: TABDOS */
/* ------------- */ /* ------------- */
/* Version 4.9.1 */ /* Version 4.9.2 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
...@@ -54,6 +54,9 @@ ...@@ -54,6 +54,9 @@
#if defined(GZ_SUPPORT) #if defined(GZ_SUPPORT)
#include "filamgz.h" #include "filamgz.h"
#endif // GZ_SUPPORT #endif // GZ_SUPPORT
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif // ZIP_SUPPORT
#include "tabdos.h" #include "tabdos.h"
#include "tabfix.h" #include "tabfix.h"
#include "tabmul.h" #include "tabmul.h"
...@@ -93,6 +96,7 @@ DOSDEF::DOSDEF(void) ...@@ -93,6 +96,7 @@ DOSDEF::DOSDEF(void)
Pseudo = 3; Pseudo = 3;
Fn = NULL; Fn = NULL;
Ofn = NULL; Ofn = NULL;
Zipfn = NULL;
To_Indx = NULL; To_Indx = NULL;
Recfm = RECFM_VAR; Recfm = RECFM_VAR;
Mapped = false; Mapped = false;
...@@ -126,7 +130,20 @@ bool DOSDEF::DefineAM(PGLOBAL g, LPCSTR am, int) ...@@ -126,7 +130,20 @@ bool DOSDEF::DefineAM(PGLOBAL g, LPCSTR am, int)
: (am && (*am == 'B' || *am == 'b')) ? "B" : (am && (*am == 'B' || *am == 'b')) ? "B"
: (am && !stricmp(am, "DBF")) ? "D" : "V"; : (am && !stricmp(am, "DBF")) ? "D" : "V";
Desc = Fn = GetStringCatInfo(g, "Filename", NULL); if (*dfm != 'D')
Zipfn = GetStringCatInfo(g, "Zipfile", NULL);
if (Zipfn && Multiple) {
// Prevent Fn to default to table name
Desc = GetStringCatInfo(g, "Filename", NULL);
Fn = GetStringCatInfo(g, "Filename", "<%>");
if (!strcmp(Fn, "<%>"))
Fn = NULL;
} else
Desc = Fn = GetStringCatInfo(g, "Filename", NULL);
Ofn = GetStringCatInfo(g, "Optname", Fn); Ofn = GetStringCatInfo(g, "Optname", Fn);
GetCharCatInfo("Recfm", (PSZ)dfm, buf, sizeof(buf)); GetCharCatInfo("Recfm", (PSZ)dfm, buf, sizeof(buf));
Recfm = (toupper(*buf) == 'F') ? RECFM_FIX : Recfm = (toupper(*buf) == 'F') ? RECFM_FIX :
...@@ -333,7 +350,20 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode) ...@@ -333,7 +350,20 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
/* Allocate table and file processing class of the proper type. */ /* Allocate table and file processing class of the proper type. */
/* Column blocks will be allocated only when needed. */ /* Column blocks will be allocated only when needed. */
/*********************************************************************/ /*********************************************************************/
if (Recfm == RECFM_DBF) { if (Zipfn) {
#if defined(ZIP_SUPPORT)
if (Recfm == RECFM_VAR)
txfp = new(g) ZIPFAM(this);
else
txfp = new(g) ZPXFAM(this);
tdbp = new(g) TDBDOS(this, txfp);
return tdbp;
#else // !ZIP_SUPPORT
strcpy(g->Message, "ZIP not supported");
return NULL;
#endif // !ZIP_SUPPORT
} else if (Recfm == RECFM_DBF) {
if (Catfunc == FNC_NO) { if (Catfunc == FNC_NO) {
if (map) if (map)
txfp = new(g) DBMFAM(this); txfp = new(g) DBMFAM(this);
......
...@@ -28,6 +28,7 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */ ...@@ -28,6 +28,7 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */
friend class TDBFIX; friend class TDBFIX;
friend class TXTFAM; friend class TXTFAM;
friend class DBFBASE; friend class DBFBASE;
friend class ZIPFAM;
public: public:
// Constructor // Constructor
DOSDEF(void); DOSDEF(void);
...@@ -58,7 +59,7 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */ ...@@ -58,7 +59,7 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */
// Methods // Methods
virtual int Indexable(void) virtual int Indexable(void)
{return (!Multiple && Compressed != 1) ? 1 : 0;} {return (!Multiple && !Zipfn && Compressed != 1) ? 1 : 0;}
virtual bool DeleteIndexFile(PGLOBAL g, PIXDEF pxdf); virtual bool DeleteIndexFile(PGLOBAL g, PIXDEF pxdf);
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE mode); virtual PTDB GetTable(PGLOBAL g, MODE mode);
...@@ -72,7 +73,8 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */ ...@@ -72,7 +73,8 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */
// Members // Members
PSZ Fn; /* Path/Name of corresponding file */ PSZ Fn; /* Path/Name of corresponding file */
PSZ Ofn; /* Base Path/Name of matching index files*/ PSZ Ofn; /* Base Path/Name of matching index files*/
PIXDEF To_Indx; /* To index definitions blocks */ PSZ Zipfn; /* Zip container name */
PIXDEF To_Indx; /* To index definitions blocks */
RECFM Recfm; /* 0:VAR, 1:FIX, 2:BIN, 3:VCT, 6:DBF */ RECFM Recfm; /* 0:VAR, 1:FIX, 2:BIN, 3:VCT, 6:DBF */
bool Mapped; /* 0: disk file, 1: memory mapped file */ bool Mapped; /* 0: disk file, 1: memory mapped file */
bool Padded; /* true for padded table file */ bool Padded; /* true for padded table file */
......
/************* TabFmt C++ Program Source Code File (.CPP) **************/ /************* TabFmt C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: TABFMT */ /* PROGRAM NAME: TABFMT */
/* ------------- */ /* ------------- */
/* Version 3.9.1 */ /* Version 3.9.2 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
...@@ -54,6 +54,9 @@ ...@@ -54,6 +54,9 @@
#if defined(GZ_SUPPORT) #if defined(GZ_SUPPORT)
#include "filamgz.h" #include "filamgz.h"
#endif // GZ_SUPPORT #endif // GZ_SUPPORT
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif // ZIP_SUPPORT
#include "tabfmt.h" #include "tabfmt.h"
#include "tabmul.h" #include "tabmul.h"
#define NO_FUNC #define NO_FUNC
...@@ -78,20 +81,24 @@ USETEMP UseTemp(void); ...@@ -78,20 +81,24 @@ USETEMP UseTemp(void);
/* of types (TYPE_STRING < TYPE_DOUBLE < TYPE_INT) (1 < 2 < 7). */ /* of types (TYPE_STRING < TYPE_DOUBLE < TYPE_INT) (1 < 2 < 7). */
/* If these values are changed, this will have to be revisited. */ /* If these values are changed, this will have to be revisited. */
/***********************************************************************/ /***********************************************************************/
PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, PQRYRES CSVColumns(PGLOBAL g, char *dp, PTOS topt, bool info)
char q, int hdr, int mxr, bool info)
{ {
static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING,
TYPE_INT, TYPE_INT, TYPE_SHORT}; TYPE_INT, TYPE_INT, TYPE_SHORT};
static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME,
FLD_PREC, FLD_LENGTH, FLD_SCALE}; FLD_PREC, FLD_LENGTH, FLD_SCALE};
static unsigned int length[] = {6, 6, 8, 10, 10, 6}; static unsigned int length[] = {6, 6, 8, 10, 10, 6};
char *p, *colname[MAXCOL], dechar, filename[_MAX_PATH], buf[4096]; const char *fn;
char sep, q;
int rc, mxr;
bool hdr;
char *p, *colname[MAXCOL], dechar, buf[8];
int i, imax, hmax, n, nerr, phase, blank, digit, dec, type; int i, imax, hmax, n, nerr, phase, blank, digit, dec, type;
int ncol = sizeof(buftyp) / sizeof(int); int ncol = sizeof(buftyp) / sizeof(int);
int num_read = 0, num_max = 10000000; // Statistics int num_read = 0, num_max = 10000000; // Statistics
int len[MAXCOL], typ[MAXCOL], prc[MAXCOL]; int len[MAXCOL], typ[MAXCOL], prc[MAXCOL];
FILE *infile; PCSVDEF tdp;
PTDBCSV tdbp;
PQRYRES qrp; PQRYRES qrp;
PCOLRES crp; PCOLRES crp;
...@@ -102,26 +109,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, ...@@ -102,26 +109,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep,
} // endif info } // endif info
// num_max = atoi(p+1); // Max num of record to test // num_max = atoi(p+1); // Max num of record to test
#if defined(__WIN__)
if (sep == ',' || strnicmp(setlocale(LC_NUMERIC, NULL), "French", 6))
dechar = '.';
else
dechar = ',';
#else // !__WIN__
dechar = '.';
#endif // !__WIN__
if (trace)
htrc("File %s sep=%c q=%c hdr=%d mxr=%d\n",
SVP(fn), sep, q, hdr, mxr);
if (!fn) {
strcpy(g->Message, MSG(MISSING_FNAME));
return NULL;
} // endif fn
imax = hmax = nerr = 0; imax = hmax = nerr = 0;
mxr = MY_MAX(0, mxr);
for (i = 0; i < MAXCOL; i++) { for (i = 0; i < MAXCOL; i++) {
colname[i] = NULL; colname[i] = NULL;
...@@ -131,12 +119,73 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, ...@@ -131,12 +119,73 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep,
} // endfor i } // endfor i
/*********************************************************************/ /*********************************************************************/
/* Open the input file. */ /* Get the CSV table description block. */
/*********************************************************************/ /*********************************************************************/
PlugSetPath(filename, fn, dp); tdp = new(g) CSVDEF;
#if defined(ZIP_SUPPORT)
tdp->Zipfn = GetStringTableOption(g, topt, "Zipfile", NULL);
tdp->Multiple = GetIntegerTableOption(g, topt, "Multiple", 0);
#endif // ZIP_SUPPORT
tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);
if (!tdp->Fn && !tdp->Zipfn && !tdp->Multiple) {
strcpy(g->Message, MSG(MISSING_FNAME));
return NULL;
} // endif Fn
fn = (tdp->Fn) ? tdp->Fn : "unnamed";
if (!(tdp->Lrecl = GetIntegerTableOption(g, topt, "Lrecl", 0)))
tdp->Lrecl = 4096;
if (!(infile= global_fopen(g, MSGID_CANNOT_OPEN, filename, "r"))) p = GetStringTableOption(g, topt, "Separator", ",");
return NULL; tdp->Sep = (strlen(p) == 2 && p[0] == '\\' && p[1] == 't') ? '\t' : *p;
#if defined(__WIN__)
if (tdp->Sep == ',' || strnicmp(setlocale(LC_NUMERIC, NULL), "French", 6))
dechar = '.';
else
dechar = ',';
#else // !__WIN__
dechar = '.';
#endif // !__WIN__
sep = tdp->Sep;
tdp->Quoted = GetIntegerTableOption(g, topt, "Quoted", -1);
p = GetStringTableOption(g, topt, "Qchar", "");
tdp->Qot = *p;
if (tdp->Qot && tdp->Quoted < 0)
tdp->Quoted = 0;
else if (!tdp->Qot && tdp->Quoted >= 0)
tdp->Qot = '"';
q = tdp->Qot;
hdr = GetBooleanTableOption(g, topt, "Header", false);
tdp->Maxerr = GetIntegerTableOption(g, topt, "Maxerr", 0);
tdp->Accept = GetBooleanTableOption(g, topt, "Accept", false);
if (tdp->Accept && tdp->Maxerr == 0)
tdp->Maxerr = INT_MAX32; // Accept all bad lines
mxr = MY_MAX(0, tdp->Maxerr);
if (trace)
htrc("File %s Sep=%c Qot=%c Header=%d maxerr=%d\n",
SVP(tdp->Fn), tdp->Sep, tdp->Qot, tdp->Header, tdp->Maxerr);
if (tdp->Zipfn)
tdbp = new(g) TDBCSV(tdp, new(g) ZIPFAM(tdp));
else
tdbp = new(g) TDBCSV(tdp, new(g) DOSFAM(tdp));
tdbp->SetMode(MODE_READ);
/*********************************************************************/
/* Open the CSV file. */
/*********************************************************************/
if (tdbp->OpenDB(g))
return NULL;
if (hdr) { if (hdr) {
/*******************************************************************/ /*******************************************************************/
...@@ -144,16 +193,8 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, ...@@ -144,16 +193,8 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep,
/*******************************************************************/ /*******************************************************************/
phase = 0; phase = 0;
if (fgets(buf, sizeof(buf), infile)) { if ((rc = tdbp->ReadDB(g)) == RC_OK) {
n = strlen(buf) + 1; p = PlgDBDup(g, tdbp->To_Line);
buf[n - 2] = '\0';
#if !defined(__WIN__)
// The file can be imported from Windows
if (buf[n - 3] == '\r')
buf[n - 3] = 0;
#endif // UNIX
p = (char*)PlugSubAlloc(g, NULL, n);
memcpy(p, buf, n);
//skip leading blanks //skip leading blanks
for (; *p == ' '; p++) ; for (; *p == ' '; p++) ;
...@@ -165,10 +206,11 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, ...@@ -165,10 +206,11 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep,
} // endif q } // endif q
colname[0] = p; colname[0] = p;
} else { } else if (rc == RC_EF) {
sprintf(g->Message, MSG(FILE_IS_EMPTY), fn); sprintf(g->Message, MSG(FILE_IS_EMPTY), fn);
goto err; goto err;
} // endif's } else
goto err;
for (i = 1; *p; p++) for (i = 1; *p; p++)
if (phase == 1 && *p == q) { if (phase == 1 && *p == q) {
...@@ -201,15 +243,8 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, ...@@ -201,15 +243,8 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep,
/*******************************************************************/ /*******************************************************************/
/* Now start the reading process. Read one line. */ /* Now start the reading process. Read one line. */
/*******************************************************************/ /*******************************************************************/
if (fgets(buf, sizeof(buf), infile)) { if ((rc = tdbp->ReadDB(g)) == RC_OK) {
n = strlen(buf); } else if (rc == RC_EF) {
buf[n - 1] = '\0';
#if !defined(__WIN__)
// The file can be imported from Windows
if (buf[n - 2] == '\r')
buf[n - 2] = 0;
#endif // UNIX
} else if (feof(infile)) {
sprintf(g->Message, MSG(EOF_AFTER_LINE), num_read -1); sprintf(g->Message, MSG(EOF_AFTER_LINE), num_read -1);
break; break;
} else { } else {
...@@ -222,7 +257,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, ...@@ -222,7 +257,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep,
/*******************************************************************/ /*******************************************************************/
i = n = phase = blank = digit = dec = 0; i = n = phase = blank = digit = dec = 0;
for (p = buf; *p; p++) for (p = tdbp->To_Line; *p; p++)
if (*p == sep) { if (*p == sep) {
if (phase != 1) { if (phase != 1) {
if (i == MAXCOL - 1) { if (i == MAXCOL - 1) {
...@@ -331,7 +366,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, ...@@ -331,7 +366,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep,
htrc("\n"); htrc("\n");
} // endif trace } // endif trace
fclose(infile); tdbp->CloseDB(g);
skipit: skipit:
if (trace) if (trace)
...@@ -381,7 +416,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, ...@@ -381,7 +416,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep,
return qrp; return qrp;
err: err:
fclose(infile); tdbp->CloseDB(g);
return NULL; return NULL;
} // end of CSVCColumns } // end of CSVCColumns
...@@ -458,7 +493,21 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode) ...@@ -458,7 +493,21 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
/*******************************************************************/ /*******************************************************************/
/* Allocate a file processing class of the proper type. */ /* Allocate a file processing class of the proper type. */
/*******************************************************************/ /*******************************************************************/
if (map) { if (Zipfn) {
#if defined(ZIP_SUPPORT)
txfp = new(g) ZIPFAM(this);
if (!Fmtd)
tdbp = new(g) TDBCSV(this, txfp);
else
tdbp = new(g) TDBFMT(this, txfp);
return tdbp;
#else // !ZIP_SUPPORT
strcpy(g->Message, "ZIP not supported");
return NULL;
#endif // !ZIP_SUPPORT
} else if (map) {
// Should be now compatible with UNIX // Should be now compatible with UNIX
txfp = new(g) MAPFAM(this); txfp = new(g) MAPFAM(this);
} else if (Compressed) { } else if (Compressed) {
...@@ -1476,21 +1525,16 @@ void CSVCOL::WriteColumn(PGLOBAL g) ...@@ -1476,21 +1525,16 @@ void CSVCOL::WriteColumn(PGLOBAL g)
/* TDBCCL class constructor. */ /* TDBCCL class constructor. */
/***********************************************************************/ /***********************************************************************/
TDBCCL::TDBCCL(PCSVDEF tdp) : TDBCAT(tdp) TDBCCL::TDBCCL(PCSVDEF tdp) : TDBCAT(tdp)
{ {
Fn = tdp->GetFn(); Topt = tdp->GetTopt();
Hdr = tdp->Header; } // end of TDBCCL constructor
Mxr = tdp->Maxerr;
Qtd = tdp->Quoted;
Sep = tdp->Sep;
} // end of TDBCCL constructor
/***********************************************************************/ /***********************************************************************/
/* GetResult: Get the list the CSV file columns. */ /* GetResult: Get the list the CSV file columns. */
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBCCL::GetResult(PGLOBAL g) PQRYRES TDBCCL::GetResult(PGLOBAL g)
{ {
return CSVColumns(g, ((PTABDEF)To_Def)->GetPath(), return CSVColumns(g, ((PTABDEF)To_Def)->GetPath(), Topt, false);
Fn, Sep, Qtd, Hdr, Mxr, false);
} // end of GetResult } // end of GetResult
/* ------------------------ End of TabFmt ---------------------------- */ /* ------------------------ End of TabFmt ---------------------------- */
/*************** TabFmt H Declares Source Code File (.H) ***************/ /*************** TabFmt H Declares Source Code File (.H) ***************/
/* Name: TABFMT.H Version 2.4 */ /* Name: TABFMT.H Version 2.5 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2001-2014 */ /* (C) Copyright to the author Olivier BERTRAND 2001-2016 */
/* */ /* */
/* This file contains the CSV and FMT classes declares. */ /* This file contains the CSV and FMT classes declares. */
/***********************************************************************/ /***********************************************************************/
...@@ -13,8 +13,7 @@ typedef class TDBFMT *PTDBFMT; ...@@ -13,8 +13,7 @@ typedef class TDBFMT *PTDBFMT;
/***********************************************************************/ /***********************************************************************/
/* Functions used externally. */ /* Functions used externally. */
/***********************************************************************/ /***********************************************************************/
PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, PQRYRES CSVColumns(PGLOBAL g, char *dp, PTOS topt, bool info);
char q, int hdr, int mxr, bool info);
/***********************************************************************/ /***********************************************************************/
/* CSV table. */ /* CSV table. */
...@@ -22,7 +21,8 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep, ...@@ -22,7 +21,8 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, const char *fn, char sep,
class DllExport CSVDEF : public DOSDEF { /* Logical table description */ class DllExport CSVDEF : public DOSDEF { /* Logical table description */
friend class TDBCSV; friend class TDBCSV;
friend class TDBCCL; friend class TDBCCL;
public: friend PQRYRES CSVColumns(PGLOBAL, char *, PTOS, bool);
public:
// Constructor // Constructor
CSVDEF(void); CSVDEF(void);
...@@ -50,9 +50,10 @@ class DllExport CSVDEF : public DOSDEF { /* Logical table description */ ...@@ -50,9 +50,10 @@ class DllExport CSVDEF : public DOSDEF { /* Logical table description */
/* This is the DOS/UNIX Access Method class declaration for files */ /* This is the DOS/UNIX Access Method class declaration for files */
/* that are CSV files with columns separated by the Sep character. */ /* that are CSV files with columns separated by the Sep character. */
/***********************************************************************/ /***********************************************************************/
class TDBCSV : public TDBDOS { class DllExport TDBCSV : public TDBDOS {
friend class CSVCOL; friend class CSVCOL;
public: friend PQRYRES CSVColumns(PGLOBAL, char *, PTOS, bool);
public:
// Constructor // Constructor
TDBCSV(PCSVDEF tdp, PTXF txfp); TDBCSV(PCSVDEF tdp, PTXF txfp);
TDBCSV(PGLOBAL g, PTDBCSV tdbp); TDBCSV(PGLOBAL g, PTDBCSV tdbp);
...@@ -101,7 +102,7 @@ class TDBCSV : public TDBDOS { ...@@ -101,7 +102,7 @@ class TDBCSV : public TDBDOS {
/* Class CSVCOL: CSV access method column descriptor. */ /* Class CSVCOL: CSV access method column descriptor. */
/* This A.M. is used for Comma Separated V(?) files. */ /* This A.M. is used for Comma Separated V(?) files. */
/***********************************************************************/ /***********************************************************************/
class CSVCOL : public DOSCOL { class DllExport CSVCOL : public DOSCOL {
friend class TDBCSV; friend class TDBCSV;
friend class TDBFMT; friend class TDBFMT;
public: public:
...@@ -129,7 +130,7 @@ class CSVCOL : public DOSCOL { ...@@ -129,7 +130,7 @@ class CSVCOL : public DOSCOL {
/* This is the DOS/UNIX Access Method class declaration for files */ /* This is the DOS/UNIX Access Method class declaration for files */
/* whose record format is described by a Format keyword. */ /* whose record format is described by a Format keyword. */
/***********************************************************************/ /***********************************************************************/
class TDBFMT : public TDBCSV { class DllExport TDBFMT : public TDBCSV {
friend class CSVCOL; friend class CSVCOL;
//friend class FMTCOL; //friend class FMTCOL;
public: public:
...@@ -173,7 +174,7 @@ class TDBFMT : public TDBCSV { ...@@ -173,7 +174,7 @@ class TDBFMT : public TDBCSV {
/***********************************************************************/ /***********************************************************************/
/* This is the class declaration for the CSV catalog table. */ /* This is the class declaration for the CSV catalog table. */
/***********************************************************************/ /***********************************************************************/
class TDBCCL : public TDBCAT { class DllExport TDBCCL : public TDBCAT {
public: public:
// Constructor // Constructor
TDBCCL(PCSVDEF tdp); TDBCCL(PCSVDEF tdp);
...@@ -183,11 +184,7 @@ class TDBCCL : public TDBCAT { ...@@ -183,11 +184,7 @@ class TDBCCL : public TDBCAT {
virtual PQRYRES GetResult(PGLOBAL g); virtual PQRYRES GetResult(PGLOBAL g);
// Members // Members
char *Fn; // The CSV file (path) name PTOS Topt;
bool Hdr; // true if first line contains headers }; // end of class TDBCCL
int Mxr; // Maximum number of bad records
int Qtd; // Quoting level for quoted fields
char Sep; // Separator for standard CSV files
}; // end of class TDBCCL
/* ------------------------- End of TabFmt.H ------------------------- */ /* ------------------------- End of TabFmt.H ------------------------- */
/************* tabjson C++ Program Source Code File (.CPP) *************/ /************* tabjson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjson Version 1.2 */ /* PROGRAM NAME: tabjson Version 1.3 */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2016 */ /* (C) Copyright to the author Olivier BERTRAND 2014 - 2016 */
/* This program are the JSON class DB execution routines. */ /* This program are the JSON class DB execution routines. */
/***********************************************************************/ /***********************************************************************/
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
#if defined(GZ_SUPPORT) #if defined(GZ_SUPPORT)
#include "filamgz.h" #include "filamgz.h"
#endif // GZ_SUPPORT #endif // GZ_SUPPORT
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif // ZIP_SUPPORT
#include "tabmul.h" #include "tabmul.h"
#include "checklvl.h" #include "checklvl.h"
#include "resource.h" #include "resource.h"
...@@ -67,7 +70,7 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info) ...@@ -67,7 +70,7 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC,
FLD_LENGTH, FLD_SCALE, FLD_NULL, FLD_FORMAT}; FLD_LENGTH, FLD_SCALE, FLD_NULL, FLD_FORMAT};
static unsigned int length[] = {0, 6, 8, 10, 10, 6, 6, 0}; static unsigned int length[] = {0, 6, 8, 10, 10, 6, 6, 0};
char *fn, colname[65], fmt[129]; char colname[65], fmt[129];
int i, j, lvl, n = 0; int i, j, lvl, n = 0;
int ncol = sizeof(buftyp) / sizeof(int); int ncol = sizeof(buftyp) / sizeof(int);
PVAL valp; PVAL valp;
...@@ -94,16 +97,21 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info) ...@@ -94,16 +97,21 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
/*********************************************************************/ /*********************************************************************/
/* Open the input file. */ /* Open the input file. */
/*********************************************************************/ /*********************************************************************/
if (!(fn = GetStringTableOption(g, topt, "Filename", NULL))) { lvl = GetIntegerTableOption(g, topt, "Level", 0);
strcpy(g->Message, MSG(MISSING_FNAME)); lvl = (lvl < 0) ? 0 : (lvl > 16) ? 16 : lvl;
return NULL;
} else {
lvl = GetIntegerTableOption(g, topt, "Level", 0);
lvl = (lvl < 0) ? 0 : (lvl > 16) ? 16 : lvl;
} // endif fn
tdp = new(g) JSONDEF; tdp = new(g) JSONDEF;
tdp->Fn = fn; #if defined(ZIP_SUPPORT)
tdp->Zipfn = GetStringTableOption(g, topt, "Zipfile", NULL);
tdp->Multiple = GetIntegerTableOption(g, topt, "Multiple", 0);
#endif // ZIP_SUPPORT
tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);
if (!tdp->Fn && !tdp->Zipfn && !tdp->Multiple) {
strcpy(g->Message, MSG(MISSING_FNAME));
return NULL;
} // endif Fn
tdp->Database = SetPath(g, db); tdp->Database = SetPath(g, db);
tdp->Objname = GetStringTableOption(g, topt, "Object", NULL); tdp->Objname = GetStringTableOption(g, topt, "Object", NULL);
tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0; tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0;
...@@ -114,7 +122,10 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info) ...@@ -114,7 +122,10 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
tdp->Fn, tdp->Objname, tdp->Pretty, lvl); tdp->Fn, tdp->Objname, tdp->Pretty, lvl);
if (tdp->Pretty == 2) { if (tdp->Pretty == 2) {
tjsp = new(g) TDBJSON(tdp, new(g) MAPFAM(tdp)); if (tdp->Zipfn)
tjsp = new(g) TDBJSON(tdp, new(g) ZIPFAM(tdp));
else
tjsp = new(g) TDBJSON(tdp, new(g) MAPFAM(tdp));
if (tjsp->MakeDocument(g)) if (tjsp->MakeDocument(g))
return NULL; return NULL;
...@@ -127,10 +138,28 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info) ...@@ -127,10 +138,28 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
} // endif lrecl } // endif lrecl
tdp->Ending = GetIntegerTableOption(g, topt, "Ending", CRLF); tdp->Ending = GetIntegerTableOption(g, topt, "Ending", CRLF);
tjnp = new(g) TDBJSN(tdp, new(g) DOSFAM(tdp));
if (tdp->Zipfn)
tjnp = new(g) TDBJSN(tdp, new(g) ZIPFAM(tdp));
else
tjnp = new(g) TDBJSN(tdp, new(g) DOSFAM(tdp));
tjnp->SetMode(MODE_READ); tjnp->SetMode(MODE_READ);
if (tjnp->OpenDB(g)) #if USE_G
// Allocate the parse work memory
PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL));
memset(G, 0, sizeof(GLOBAL));
G->Sarea_Size = tdp->Lrecl * 10;
G->Sarea = PlugSubAlloc(g, NULL, G->Sarea_Size);
PlugSubSet(G, G->Sarea, G->Sarea_Size);
G->jump_level = -1;
tjnp->SetG(G);
#else
tjnp->SetG(g);
#endif
if (tjnp->OpenDB(g))
return NULL; return NULL;
switch (tjnp->ReadDB(g)) { switch (tjnp->ReadDB(g)) {
...@@ -395,7 +424,14 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -395,7 +424,14 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
!(tmp == TMP_FORCE && !(tmp == TMP_FORCE &&
(m == MODE_UPDATE || m == MODE_DELETE)); (m == MODE_UPDATE || m == MODE_DELETE));
if (Compressed) { if (Zipfn) {
#if defined(ZIP_SUPPORT)
txfp = new(g) ZIPFAM(this);
#else // !ZIP_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP");
return NULL;
#endif // !ZIP_SUPPORT
} else if (Compressed) {
#if defined(GZ_SUPPORT) #if defined(GZ_SUPPORT)
if (Compressed == 1) if (Compressed == 1)
txfp = new(g) GZFAM(this); txfp = new(g) GZFAM(this);
...@@ -426,12 +462,16 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -426,12 +462,16 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
((TDBJSN*)tdbp)->G = g; ((TDBJSN*)tdbp)->G = g;
#endif #endif
} else { } else {
txfp = new(g) MAPFAM(this); if (Zipfn)
txfp = new(g) ZIPFAM(this);
else
txfp = new(g) MAPFAM(this);
tdbp = new(g) TDBJSON(this, txfp); tdbp = new(g) TDBJSON(this, txfp);
((TDBJSON*)tdbp)->G = g; ((TDBJSON*)tdbp)->G = g;
} // endif Pretty } // endif Pretty
if (Multiple) if (Multiple && !Zipfn)
tdbp = new(g) TDBMUL(tdbp); tdbp = new(g) TDBMUL(tdbp);
return tdbp; return tdbp;
......
...@@ -78,7 +78,8 @@ class TDBJSN : public TDBDOS { ...@@ -78,7 +78,8 @@ class TDBJSN : public TDBDOS {
virtual AMT GetAmType(void) {return TYPE_AM_JSN;} virtual AMT GetAmType(void) {return TYPE_AM_JSN;}
virtual bool SkipHeader(PGLOBAL g); virtual bool SkipHeader(PGLOBAL g);
virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBJSN(this);} virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBJSN(this);}
PJSON GetRow(void) {return Row;} PJSON GetRow(void) {return Row;}
void SetG(PGLOBAL g) {G = g;}
// Methods // Methods
virtual PTDB CopyOne(PTABS t); virtual PTDB CopyOne(PTABS t);
......
/************* TabZip C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: TABZIP Version 1.0 */
/* (C) Copyright to the author Olivier BERTRAND 2016 */
/* This program are the TABZIP class DB execution routines. */
/***********************************************************************/
/***********************************************************************/
/* Include relevant sections of the MariaDB header file. */
/***********************************************************************/
#include <my_global.h>
/***********************************************************************/
/* Include application header files: */
/* global.h is header containing all global declarations. */
/* plgdbsem.h is header containing the DB application declarations. */
/* (x)table.h is header containing the TDBASE declarations. */
/* tabzip.h is header containing the TABZIP classes declarations. */
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
#include "xtable.h"
#include "filamtxt.h"
#include "filamzip.h"
#include "resource.h" // for IDS_COLUMNS
#include "tabdos.h"
#include "tabzip.h"
/* -------------------------- Class ZIPDEF --------------------------- */
/************************************************************************/
/* DefineAM: define specific AM block values. */
/************************************************************************/
bool ZIPDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
//target = GetStringCatInfo(g, "Target", NULL);
return DOSDEF::DefineAM(g, "ZIP", poff);
} // end of DefineAM
/***********************************************************************/
/* GetTable: makes a new Table Description Block. */
/***********************************************************************/
PTDB ZIPDEF::GetTable(PGLOBAL g, MODE m)
{
return new(g) TDBZIP(this);
} // end of GetTable
/* ------------------------------------------------------------------- */
/***********************************************************************/
/* Implementation of the TDBZIP class. */
/***********************************************************************/
TDBZIP::TDBZIP(PZIPDEF tdp) : TDBASE(tdp)
{
zipfile = NULL;
zfn = tdp->Fn;
//target = tdp->target;
nexterr = UNZ_OK;
} // end of TDBZIP standard constructor
/***********************************************************************/
/* Allocate ZIP column description block. */
/***********************************************************************/
PCOL TDBZIP::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
{
return new(g) ZIPCOL(cdp, this, cprec, n);
} // end of MakeCol
/***********************************************************************/
/* open a zip file. */
/* param: filename path and the filename of the zip file to open. */
/* return: true if open, false otherwise. */
/***********************************************************************/
bool TDBZIP::open(PGLOBAL g, const char *filename)
{
if (!zipfile && !(zipfile = unzOpen64(filename)))
sprintf(g->Message, "Zipfile open error");
return (zipfile == NULL);
} // end of open
/***********************************************************************/
/* Close the zip file. */
/***********************************************************************/
void TDBZIP::close()
{
if (zipfile) {
unzClose(zipfile);
zipfile = NULL;
} // endif zipfile
} // end of close
/***********************************************************************/
/* ZIP Cardinality: returns table size in number of rows. */
/***********************************************************************/
int TDBZIP::Cardinality(PGLOBAL g)
{
if (!g)
return 1;
else if (Cardinal < 0) {
if (!open(g, zfn)) {
unz_global_info64 ginfo;
int err = unzGetGlobalInfo64(zipfile, &ginfo);
Cardinal = (err == UNZ_OK) ? ginfo.number_entry : 0;
} else
Cardinal = 0;
} // endif Cardinal
return Cardinal;
} // end of Cardinality
/***********************************************************************/
/* ZIP GetMaxSize: returns file size estimate in number of lines. */
/***********************************************************************/
int TDBZIP::GetMaxSize(PGLOBAL g)
{
if (MaxSize < 0)
MaxSize = Cardinality(g);
return MaxSize;
} // end of GetMaxSize
/***********************************************************************/
/* ZIP Access Method opening routine. */
/***********************************************************************/
bool TDBZIP::OpenDB(PGLOBAL g)
{
if (Use == USE_OPEN)
// Table already open
return false;
Use = USE_OPEN; // To be clean
return open(g, zfn);
} // end of OpenDB
/***********************************************************************/
/* ReadDB: Data Base read routine for ZIP access method. */
/***********************************************************************/
int TDBZIP::ReadDB(PGLOBAL g)
{
if (nexterr == UNZ_END_OF_LIST_OF_FILE)
return RC_EF;
else if (nexterr != UNZ_OK) {
sprintf(g->Message, "unzGoToNextFile error %d", nexterr);
return RC_FX;
} // endif nexterr
int err = unzGetCurrentFileInfo64(zipfile, &finfo, fn,
sizeof(fn), NULL, 0, NULL, 0);
if (err != UNZ_OK) {
sprintf(g->Message, "unzGetCurrentFileInfo64 error %d", err);
return RC_FX;
} // endif err
nexterr = unzGoToNextFile(zipfile);
return RC_OK;
} // end of ReadDB
/***********************************************************************/
/* WriteDB: Data Base write routine for ZIP access method. */
/***********************************************************************/
int TDBZIP::WriteDB(PGLOBAL g)
{
strcpy(g->Message, "ZIP tables are read only");
return RC_FX;
} // end of WriteDB
/***********************************************************************/
/* Data Base delete line routine for ZIP access method. */
/***********************************************************************/
int TDBZIP::DeleteDB(PGLOBAL g, int irc)
{
strcpy(g->Message, "Delete not enabled for ZIP tables");
return RC_FX;
} // end of DeleteDB
/***********************************************************************/
/* Data Base close routine for ZIP access method. */
/***********************************************************************/
void TDBZIP::CloseDB(PGLOBAL g)
{
close();
Use = USE_READY; // Just to be clean
} // end of CloseDB
/* ---------------------------- ZIPCOL ------------------------------- */
/***********************************************************************/
/* ZIPCOL public constructor. */
/***********************************************************************/
ZIPCOL::ZIPCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am)
: COLBLK(cdp, tdbp, i)
{
if (cprec) {
Next = cprec->GetNext();
cprec->SetNext(this);
} else {
Next = tdbp->GetColumns();
tdbp->SetColumns(this);
} // endif cprec
Tdbz = (TDBZIP*)tdbp;
flag = cdp->GetOffset();
} // end of ZIPCOL constructor
/***********************************************************************/
/* ReadColumn: */
/***********************************************************************/
void ZIPCOL::ReadColumn(PGLOBAL g)
{
switch (flag) {
case 1:
Value->SetValue(Tdbz->finfo.compressed_size);
break;
case 2:
Value->SetValue(Tdbz->finfo.uncompressed_size);
break;
case 3:
Value->SetValue((int)Tdbz->finfo.compression_method);
break;
default:
Value->SetValue_psz((PSZ)Tdbz->fn);
} // endswitch flag
} // end of ReadColumn
/* -------------------------- End of tabzip -------------------------- */
/*************** tabzip H Declares Source Code File (.H) ***************/
/* Name: tabzip.h Version 1.0 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2016 */
/* */
/* This file contains the ZIP classe declares. */
/***********************************************************************/
#include "osutil.h"
#include "block.h"
#include "colblk.h"
#include "xtable.h"
#include "unzip.h"
typedef class ZIPDEF *PZIPDEF;
typedef class TDBZIP *PTDBZIP;
typedef class ZIPCOL *PZIPCOL;
/***********************************************************************/
/* ZIP table: display info about a ZIP file. */
/***********************************************************************/
class DllExport ZIPDEF : public DOSDEF { /* Table description */
friend class TDBZIP;
friend class ZIPFAM;
public:
// Constructor
ZIPDEF(void) {}
// Implementation
virtual const char *GetType(void) {return "ZIP";}
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE m);
protected:
// Members
PSZ target; // The inside file to query
}; // end of ZIPDEF
/***********************************************************************/
/* This is the ZIP Access Method class declaration. */
/***********************************************************************/
class DllExport TDBZIP : public TDBASE {
friend class ZIPCOL;
public:
// Constructor
TDBZIP(PZIPDEF tdp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_ZIP;}
// Methods
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual int Cardinality(PGLOBAL g);
virtual int GetMaxSize(PGLOBAL g);
virtual int GetRecpos(void) {return 0;}
// Database routines
virtual bool OpenDB(PGLOBAL g);
virtual int ReadDB(PGLOBAL g);
virtual int WriteDB(PGLOBAL g);
virtual int DeleteDB(PGLOBAL g, int irc);
virtual void CloseDB(PGLOBAL g);
protected:
bool open(PGLOBAL g, const char *filename);
void close(void);
// Members
unzFile zipfile; // The ZIP container file
PSZ zfn; // The ZIP file name
//PSZ target;
unz_file_info64 finfo; // The current file info
char fn[FILENAME_MAX]; // The current file name
int nexterr; // Next file error
}; // end of class TDBZIP
/***********************************************************************/
/* Class ZIPCOL: ZIP access method column descriptor. */
/***********************************************************************/
class DllExport ZIPCOL : public COLBLK {
friend class TDBZIP;
public:
// Constructors
ZIPCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am = "ZIP");
// Implementation
virtual int GetAmType(void) { return TYPE_AM_ZIP; }
// Methods
virtual void ReadColumn(PGLOBAL g);
protected:
// Default constructor not to be used
ZIPCOL(void) {}
// Members
TDBZIP *Tdbz;
int flag;
}; // end of class ZIPCOL
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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