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

Enable using multiple zip files
  modified:   storage/connect/filamzip.cpp
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/ha_connect.h
  modified:   storage/connect/mycat.h
  modified:   storage/connect/tabdos.cpp
  modified:   storage/connect/tabdos.h
  modified:   storage/connect/tabfmt.cpp
  modified:   storage/connect/tabjson.cpp
This commit is contained in:
Olivier Bertrand 2016-12-14 11:11:22 +01:00
parent 0e06a8357b
commit 8a3fc7c041
8 changed files with 39 additions and 78 deletions

View file

@ -48,11 +48,11 @@
ZIPFAM::ZIPFAM(PDOSDEF tdp) : MAPFAM(tdp)
{
zipfile = NULL;
zfn = tdp->Zipfn;
target = tdp->Fn;
zfn = tdp->Fn;
target = tdp->Entry;
//*fn = 0;
entryopen = false;
multiple = tdp->Multiple;
multiple = (target && !(strchr(target, '*') || strchr(target, '?'))) ? 0 : 1;
// Init the case mapping table.
#if defined(__WIN__)
@ -218,7 +218,7 @@ bool ZIPFAM::OpenTableFile(PGLOBAL g)
if (rc == UNZ_END_OF_LIST_OF_FILE) {
sprintf(g->Message, "Target file %s not in %s", target, filename);
return true;
return false;
} else if (rc != UNZ_OK) {
sprintf(g->Message, "unzLocateFile rc=%d", rc);
return true;
@ -229,7 +229,7 @@ bool ZIPFAM::OpenTableFile(PGLOBAL g)
return true;
else if (rc == RC_NF) {
sprintf(g->Message, "No match of %s in %s", target, filename);
return true;
return false;
} // endif rc
} // endif multiple

View file

@ -171,9 +171,9 @@
#define JSONMAX 10 // JSON Default max grp size
extern "C" {
char version[]= "Version 1.04.0009 December 09, 2016";
char version[]= "Version 1.05.0001 December 13, 2016";
#if defined(__WIN__)
char compver[]= "Version 1.04.0009 " __DATE__ " " __TIME__;
char compver[]= "Version 1.05.0001 " __DATE__ " " __TIME__;
char slash= '\\';
#else // !__WIN__
char slash= '/';
@ -512,13 +512,13 @@ ha_create_table_option connect_table_option_list[]=
HA_TOPTION_NUMBER("QUOTED", quoted, (ulonglong) -1, 0, 3, 1),
HA_TOPTION_NUMBER("ENDING", ending, (ulonglong) -1, 0, INT_MAX32, 1),
HA_TOPTION_NUMBER("COMPRESS", compressed, 0, 0, 2, 1),
//HA_TOPTION_BOOL("COMPRESS", compressed, 0),
HA_TOPTION_BOOL("MAPPED", mapped, 0),
HA_TOPTION_BOOL("HUGE", huge, 0),
HA_TOPTION_BOOL("SPLIT", split, 0),
HA_TOPTION_BOOL("READONLY", readonly, 0),
HA_TOPTION_BOOL("SEPINDEX", sepindex, 0),
HA_TOPTION_END
HA_TOPTION_BOOL("ZIPPED", zipped, 0),
HA_TOPTION_END
};
@ -532,7 +532,6 @@ ha_create_table_option connect_field_option_list[]=
{
HA_FOPTION_NUMBER("FLAG", offset, (ulonglong) -1, 0, INT_MAX32, 1),
HA_FOPTION_NUMBER("MAX_DIST", freq, 0, 0, INT_MAX32, 1), // BLK_INDX
//HA_FOPTION_NUMBER("DISTRIB", opt, 0, 0, 2, 1), // used for BLK_INDX
HA_FOPTION_NUMBER("FIELD_LENGTH", fldlen, 0, 0, INT_MAX32, 1),
HA_FOPTION_STRING("DATE_FORMAT", dateformat),
HA_FOPTION_STRING("FIELD_FORMAT", fieldformat),
@ -678,7 +677,6 @@ static int connect_init_func(void *p)
connect_hton= (handlerton *)p;
connect_hton->state= SHOW_OPTION_YES;
connect_hton->create= connect_create_handler;
//connect_hton->flags= HTON_TEMPORARY_NOT_SUPPORTED | HTON_NO_PARTITION;
connect_hton->flags= HTON_TEMPORARY_NOT_SUPPORTED;
connect_hton->table_options= connect_table_option_list;
connect_hton->field_options= connect_field_option_list;
@ -1135,7 +1133,9 @@ bool GetBooleanTableOption(PGLOBAL g, PTOS options, char *opname, bool bdef)
opval= options->sepindex;
else if (!stricmp(opname, "Header"))
opval= (options->header != 0); // Is Boolean for some table types
else if (options->oplist)
else if (!stricmp(opname, "Zipped"))
opval = options->zipped;
else if (options->oplist)
if ((pv= GetListOption(g, opname, options->oplist)))
opval= (!*pv || *pv == 'y' || *pv == 'Y' || atoi(pv) != 0);

View file

@ -83,42 +83,9 @@ extern handlerton *connect_hton;
These can be specified in the CREATE TABLE:
CREATE TABLE ( ... ) {...here...}
*/
#if 0 // moved to mycat.h
typedef struct ha_table_option_struct TOS, *PTOS;
struct ha_table_option_struct {
const char *type;
const char *filename;
const char *optname;
const char *tabname;
const char *tablist;
const char *dbname;
const char *separator;
//const char *connect;
const char *qchar;
const char *module;
const char *subtype;
const char *catfunc;
const char *srcdef;
const char *colist;
const char *oplist;
const char *data_charset;
ulonglong lrecl;
ulonglong elements;
//ulonglong estimate;
ulonglong multiple;
ulonglong header;
ulonglong quoted;
ulonglong ending;
ulonglong compressed;
bool mapped;
bool huge;
bool split;
bool readonly;
bool sepindex;
};
#endif // 0
------ Was moved to mycat.h ------
*/
/**
structure for CREATE TABLE options (field options)

View file

@ -62,6 +62,7 @@ struct ha_table_option_struct {
bool split;
bool readonly;
bool sepindex;
bool zipped;
};
// Possible value for catalog functions

View file

@ -96,11 +96,12 @@ DOSDEF::DOSDEF(void)
Pseudo = 3;
Fn = NULL;
Ofn = NULL;
Zipfn = NULL;
Entry = NULL;
To_Indx = NULL;
Recfm = RECFM_VAR;
Mapped = false;
Padded = false;
Zipped = false;
Padded = false;
Huge = false;
Accept = false;
Eof = false;
@ -131,20 +132,11 @@ bool DOSDEF::DefineAM(PGLOBAL g, LPCSTR am, int)
: (am && !stricmp(am, "DBF")) ? "D" : "V";
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);
Zipped = GetBoolCatInfo("Zipped", false);
Desc = Fn = GetStringCatInfo(g, "Filename", NULL);
Ofn = GetStringCatInfo(g, "Optname", Fn);
Entry = GetStringCatInfo(g, "Entry", NULL);
GetCharCatInfo("Recfm", (PSZ)dfm, buf, sizeof(buf));
Recfm = (toupper(*buf) == 'F') ? RECFM_FIX :
(toupper(*buf) == 'B') ? RECFM_BIN :
@ -350,7 +342,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
/* Allocate table and file processing class of the proper type. */
/* Column blocks will be allocated only when needed. */
/*********************************************************************/
if (Zipfn) {
if (Zipped) {
#if defined(ZIP_SUPPORT)
if (Recfm == RECFM_VAR)
txfp = new(g) ZIPFAM(this);
@ -358,7 +350,6 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
txfp = new(g) ZPXFAM(this);
tdbp = new(g) TDBDOS(this, txfp);
return tdbp;
#else // !ZIP_SUPPORT
strcpy(g->Message, "ZIP not supported");
return NULL;

View file

@ -59,7 +59,7 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */
// Methods
virtual int Indexable(void)
{return (!Multiple && !Zipfn && Compressed != 1) ? 1 : 0;}
{return (!Multiple && !Zipped && Compressed != 1) ? 1 : 0;}
virtual bool DeleteIndexFile(PGLOBAL g, PIXDEF pxdf);
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE mode);
@ -73,11 +73,12 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */
// Members
PSZ Fn; /* Path/Name of corresponding file */
PSZ Ofn; /* Base Path/Name of matching index files*/
PSZ Zipfn; /* Zip container name */
PSZ Entry; /* Zip entry name or pattern */
PIXDEF To_Indx; /* To index definitions blocks */
RECFM Recfm; /* 0:VAR, 1:FIX, 2:BIN, 3:VCT, 6:DBF */
bool Mapped; /* 0: disk file, 1: memory mapped file */
bool Padded; /* true for padded table file */
bool Zipped; /* true for zipped table file */
bool Padded; /* true for padded table file */
bool Huge; /* true for files larger than 2GB */
bool Accept; /* true if wrong lines are accepted */
bool Eof; /* true if an EOF (0xA) character exists */

View file

@ -123,12 +123,13 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, PTOS topt, bool info)
/*********************************************************************/
tdp = new(g) CSVDEF;
#if defined(ZIP_SUPPORT)
tdp->Zipfn = GetStringTableOption(g, topt, "Zipfile", NULL);
tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL);
tdp->Multiple = GetIntegerTableOption(g, topt, "Multiple", 0);
tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false);
#endif // ZIP_SUPPORT
tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);
if (!tdp->Fn && !tdp->Zipfn && !tdp->Multiple) {
if (!tdp->Fn) {
strcpy(g->Message, MSG(MISSING_FNAME));
return NULL;
} // endif Fn
@ -174,7 +175,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, PTOS topt, bool info)
htrc("File %s Sep=%c Qot=%c Header=%d maxerr=%d\n",
SVP(tdp->Fn), tdp->Sep, tdp->Qot, tdp->Header, tdp->Maxerr);
if (tdp->Zipfn)
if (tdp->Zipped)
tdbp = new(g) TDBCSV(tdp, new(g) ZIPFAM(tdp));
else
tdbp = new(g) TDBCSV(tdp, new(g) DOSFAM(tdp));
@ -493,7 +494,7 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
/*******************************************************************/
/* Allocate a file processing class of the proper type. */
/*******************************************************************/
if (Zipfn) {
if (Zipped) {
#if defined(ZIP_SUPPORT)
txfp = new(g) ZIPFAM(this);
@ -502,7 +503,6 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
else
tdbp = new(g) TDBFMT(this, txfp);
return tdbp;
#else // !ZIP_SUPPORT
strcpy(g->Message, "ZIP not supported");
return NULL;

View file

@ -102,12 +102,13 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
tdp = new(g) JSONDEF;
#if defined(ZIP_SUPPORT)
tdp->Zipfn = GetStringTableOption(g, topt, "Zipfile", NULL);
tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL);
tdp->Multiple = GetIntegerTableOption(g, topt, "Multiple", 0);
tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false);
#endif // ZIP_SUPPORT
tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);
if (!tdp->Fn && !tdp->Zipfn && !tdp->Multiple) {
if (!tdp->Fn) {
strcpy(g->Message, MSG(MISSING_FNAME));
return NULL;
} // endif Fn
@ -122,7 +123,7 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
tdp->Fn, tdp->Objname, tdp->Pretty, lvl);
if (tdp->Pretty == 2) {
if (tdp->Zipfn)
if (tdp->Zipped)
tjsp = new(g) TDBJSON(tdp, new(g) ZIPFAM(tdp));
else
tjsp = new(g) TDBJSON(tdp, new(g) MAPFAM(tdp));
@ -139,7 +140,7 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
tdp->Ending = GetIntegerTableOption(g, topt, "Ending", CRLF);
if (tdp->Zipfn)
if (tdp->Zipped)
tjnp = new(g) TDBJSN(tdp, new(g) ZIPFAM(tdp));
else
tjnp = new(g) TDBJSN(tdp, new(g) DOSFAM(tdp));
@ -424,7 +425,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
!(tmp == TMP_FORCE &&
(m == MODE_UPDATE || m == MODE_DELETE));
if (Zipfn) {
if (Zipped) {
#if defined(ZIP_SUPPORT)
txfp = new(g) ZIPFAM(this);
#else // !ZIP_SUPPORT
@ -462,7 +463,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
((TDBJSN*)tdbp)->G = g;
#endif
} else {
if (Zipfn)
if (Zipped)
txfp = new(g) ZIPFAM(this);
else
txfp = new(g) MAPFAM(this);
@ -471,7 +472,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
((TDBJSON*)tdbp)->G = g;
} // endif Pretty
if (Multiple && !Zipfn)
if (Multiple)
tdbp = new(g) TDBMUL(tdbp);
return tdbp;