Skip to content

Commit 9523065

Browse files
committed
- 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
1 parent d44723e commit 9523065

File tree

10 files changed

+64
-97
lines changed

10 files changed

+64
-97
lines changed

storage/connect/filamzip.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
ZIPFAM::ZIPFAM(PDOSDEF tdp) : MAPFAM(tdp)
4949
{
5050
zipfile = NULL;
51-
zfn = tdp->Zipfn;
52-
target = tdp->Fn;
51+
//zfn = tdp->Fn;
52+
target = tdp->Entry;
5353
//*fn = 0;
5454
entryopen = false;
55-
multiple = tdp->Multiple;
55+
multiple = (target && !(strchr(target, '*') || strchr(target, '?'))) ? 0 : 1;
5656

5757
// Init the case mapping table.
5858
#if defined(__WIN__)
@@ -65,7 +65,7 @@ ZIPFAM::ZIPFAM(PDOSDEF tdp) : MAPFAM(tdp)
6565
ZIPFAM::ZIPFAM(PZIPFAM txfp) : MAPFAM(txfp)
6666
{
6767
zipfile = txfp->zipfile;
68-
zfn = txfp->zfn;
68+
//zfn = txfp->zfn;
6969
target = txfp->target;
7070
//strcpy(fn, txfp->fn);
7171
finfo = txfp->finfo;
@@ -129,7 +129,7 @@ int ZIPFAM::GetFileLength(PGLOBAL g)
129129
bool ZIPFAM::open(PGLOBAL g, const char *filename)
130130
{
131131
if (!zipfile && !(zipfile = unzOpen64(filename)))
132-
sprintf(g->Message, "Zipfile open error");
132+
sprintf(g->Message, "Zipfile open error on %s", filename);
133133

134134
return (zipfile == NULL);
135135
} // end of open
@@ -205,7 +205,7 @@ bool ZIPFAM::OpenTableFile(PGLOBAL g)
205205
/*********************************************************************/
206206
if (mode == MODE_READ) {
207207
// We used the file name relative to recorded datapath
208-
PlugSetPath(filename, zfn, Tdbp->GetPath());
208+
PlugSetPath(filename, To_File, Tdbp->GetPath());
209209

210210
bool b = open(g, filename);
211211

@@ -218,7 +218,7 @@ bool ZIPFAM::OpenTableFile(PGLOBAL g)
218218

219219
if (rc == UNZ_END_OF_LIST_OF_FILE) {
220220
sprintf(g->Message, "Target file %s not in %s", target, filename);
221-
return true;
221+
return false;
222222
} else if (rc != UNZ_OK) {
223223
sprintf(g->Message, "unzLocateFile rc=%d", rc);
224224
return true;
@@ -229,7 +229,7 @@ bool ZIPFAM::OpenTableFile(PGLOBAL g)
229229
return true;
230230
else if (rc == RC_NF) {
231231
sprintf(g->Message, "No match of %s in %s", target, filename);
232-
return true;
232+
return false;
233233
} // endif rc
234234

235235
} // endif multiple
@@ -258,7 +258,8 @@ bool ZIPFAM::OpenTableFile(PGLOBAL g)
258258
} // endif fp
259259

260260
To_Fb = fp; // Useful when closing
261-
} // endif b
261+
} else
262+
return true;
262263

263264
} else {
264265
strcpy(g->Message, "Only READ mode supported for ZIP files");

storage/connect/filamzip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class DllExport ZIPFAM : public MAPFAM {
5151

5252
// Members
5353
unzFile zipfile; // The ZIP container file
54-
PSZ zfn; // The ZIP file name
54+
//PSZ zfn; // The ZIP file name
5555
PSZ target; // The target file name
5656
unz_file_info finfo; // The current file info
5757
//char fn[FILENAME_MAX]; // The current file name

storage/connect/ha_connect.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@
171171
#define JSONMAX 10 // JSON Default max grp size
172172

173173
extern "C" {
174-
char version[]= "Version 1.04.0009 December 09, 2016";
174+
char version[]= "Version 1.05.0001 December 13, 2016";
175175
#if defined(__WIN__)
176-
char compver[]= "Version 1.04.0009 " __DATE__ " " __TIME__;
176+
char compver[]= "Version 1.05.0001 " __DATE__ " " __TIME__;
177177
char slash= '\\';
178178
#else // !__WIN__
179179
char slash= '/';
@@ -512,13 +512,13 @@ ha_create_table_option connect_table_option_list[]=
512512
HA_TOPTION_NUMBER("QUOTED", quoted, (ulonglong) -1, 0, 3, 1),
513513
HA_TOPTION_NUMBER("ENDING", ending, (ulonglong) -1, 0, INT_MAX32, 1),
514514
HA_TOPTION_NUMBER("COMPRESS", compressed, 0, 0, 2, 1),
515-
//HA_TOPTION_BOOL("COMPRESS", compressed, 0),
516515
HA_TOPTION_BOOL("MAPPED", mapped, 0),
517516
HA_TOPTION_BOOL("HUGE", huge, 0),
518517
HA_TOPTION_BOOL("SPLIT", split, 0),
519518
HA_TOPTION_BOOL("READONLY", readonly, 0),
520519
HA_TOPTION_BOOL("SEPINDEX", sepindex, 0),
521-
HA_TOPTION_END
520+
HA_TOPTION_BOOL("ZIPPED", zipped, 0),
521+
HA_TOPTION_END
522522
};
523523

524524

@@ -532,7 +532,6 @@ ha_create_table_option connect_field_option_list[]=
532532
{
533533
HA_FOPTION_NUMBER("FLAG", offset, (ulonglong) -1, 0, INT_MAX32, 1),
534534
HA_FOPTION_NUMBER("MAX_DIST", freq, 0, 0, INT_MAX32, 1), // BLK_INDX
535-
//HA_FOPTION_NUMBER("DISTRIB", opt, 0, 0, 2, 1), // used for BLK_INDX
536535
HA_FOPTION_NUMBER("FIELD_LENGTH", fldlen, 0, 0, INT_MAX32, 1),
537536
HA_FOPTION_STRING("DATE_FORMAT", dateformat),
538537
HA_FOPTION_STRING("FIELD_FORMAT", fieldformat),
@@ -678,7 +677,6 @@ static int connect_init_func(void *p)
678677
connect_hton= (handlerton *)p;
679678
connect_hton->state= SHOW_OPTION_YES;
680679
connect_hton->create= connect_create_handler;
681-
//connect_hton->flags= HTON_TEMPORARY_NOT_SUPPORTED | HTON_NO_PARTITION;
682680
connect_hton->flags= HTON_TEMPORARY_NOT_SUPPORTED;
683681
connect_hton->table_options= connect_table_option_list;
684682
connect_hton->field_options= connect_field_option_list;
@@ -1135,7 +1133,9 @@ bool GetBooleanTableOption(PGLOBAL g, PTOS options, char *opname, bool bdef)
11351133
opval= options->sepindex;
11361134
else if (!stricmp(opname, "Header"))
11371135
opval= (options->header != 0); // Is Boolean for some table types
1138-
else if (options->oplist)
1136+
else if (!stricmp(opname, "Zipped"))
1137+
opval = options->zipped;
1138+
else if (options->oplist)
11391139
if ((pv= GetListOption(g, opname, options->oplist)))
11401140
opval= (!*pv || *pv == 'y' || *pv == 'Y' || atoi(pv) != 0);
11411141

storage/connect/ha_connect.h

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,42 +83,9 @@ extern handlerton *connect_hton;
8383
8484
These can be specified in the CREATE TABLE:
8585
CREATE TABLE ( ... ) {...here...}
86-
*/
87-
#if 0 // moved to mycat.h
88-
typedef struct ha_table_option_struct TOS, *PTOS;
89-
90-
struct ha_table_option_struct {
91-
const char *type;
92-
const char *filename;
93-
const char *optname;
94-
const char *tabname;
95-
const char *tablist;
96-
const char *dbname;
97-
const char *separator;
98-
//const char *connect;
99-
const char *qchar;
100-
const char *module;
101-
const char *subtype;
102-
const char *catfunc;
103-
const char *srcdef;
104-
const char *colist;
105-
const char *oplist;
106-
const char *data_charset;
107-
ulonglong lrecl;
108-
ulonglong elements;
109-
//ulonglong estimate;
110-
ulonglong multiple;
111-
ulonglong header;
112-
ulonglong quoted;
113-
ulonglong ending;
114-
ulonglong compressed;
115-
bool mapped;
116-
bool huge;
117-
bool split;
118-
bool readonly;
119-
bool sepindex;
120-
};
121-
#endif // 0
86+
87+
------ Was moved to mycat.h ------
88+
*/
12289

12390
/**
12491
structure for CREATE TABLE options (field options)

storage/connect/mycat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct ha_table_option_struct {
6262
bool split;
6363
bool readonly;
6464
bool sepindex;
65+
bool zipped;
6566
};
6667

6768
// Possible value for catalog functions

storage/connect/tabdos.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ DOSDEF::DOSDEF(void)
9696
Pseudo = 3;
9797
Fn = NULL;
9898
Ofn = NULL;
99-
Zipfn = NULL;
99+
Entry = NULL;
100100
To_Indx = NULL;
101101
Recfm = RECFM_VAR;
102102
Mapped = false;
103-
Padded = false;
103+
Zipped = false;
104+
Padded = false;
104105
Huge = false;
105106
Accept = false;
106107
Eof = false;
@@ -131,20 +132,11 @@ bool DOSDEF::DefineAM(PGLOBAL g, LPCSTR am, int)
131132
: (am && !stricmp(am, "DBF")) ? "D" : "V";
132133

133134
if (*dfm != 'D')
134-
Zipfn = GetStringCatInfo(g, "Zipfile", NULL);
135-
136-
if (Zipfn && Multiple) {
137-
// Prevent Fn to default to table name
138-
Desc = GetStringCatInfo(g, "Filename", NULL);
139-
Fn = GetStringCatInfo(g, "Filename", "<%>");
140-
141-
if (!strcmp(Fn, "<%>"))
142-
Fn = NULL;
143-
144-
} else
145-
Desc = Fn = GetStringCatInfo(g, "Filename", NULL);
135+
Zipped = GetBoolCatInfo("Zipped", false);
146136

137+
Desc = Fn = GetStringCatInfo(g, "Filename", NULL);
147138
Ofn = GetStringCatInfo(g, "Optname", Fn);
139+
Entry = GetStringCatInfo(g, "Entry", NULL);
148140
GetCharCatInfo("Recfm", (PSZ)dfm, buf, sizeof(buf));
149141
Recfm = (toupper(*buf) == 'F') ? RECFM_FIX :
150142
(toupper(*buf) == 'B') ? RECFM_BIN :
@@ -350,15 +342,14 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
350342
/* Allocate table and file processing class of the proper type. */
351343
/* Column blocks will be allocated only when needed. */
352344
/*********************************************************************/
353-
if (Zipfn) {
345+
if (Zipped) {
354346
#if defined(ZIP_SUPPORT)
355347
if (Recfm == RECFM_VAR)
356348
txfp = new(g) ZIPFAM(this);
357349
else
358350
txfp = new(g) ZPXFAM(this);
359351

360352
tdbp = new(g) TDBDOS(this, txfp);
361-
return tdbp;
362353
#else // !ZIP_SUPPORT
363354
strcpy(g->Message, "ZIP not supported");
364355
return NULL;

storage/connect/tabdos.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */
5959

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

storage/connect/tabfmt.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, PTOS topt, bool info)
108108
goto skipit;
109109
} // endif info
110110

111+
if (GetIntegerTableOption(g, topt, "Multiple", 0)) {
112+
strcpy(g->Message, "Cannot find column definition for multiple table");
113+
return NULL;
114+
} // endif Multiple
115+
111116
// num_max = atoi(p+1); // Max num of record to test
112117
imax = hmax = nerr = 0;
113118

@@ -123,18 +128,16 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, PTOS topt, bool info)
123128
/*********************************************************************/
124129
tdp = new(g) CSVDEF;
125130
#if defined(ZIP_SUPPORT)
126-
tdp->Zipfn = GetStringTableOption(g, topt, "Zipfile", NULL);
127-
tdp->Multiple = GetIntegerTableOption(g, topt, "Multiple", 0);
131+
tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL);
132+
tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false);
128133
#endif // ZIP_SUPPORT
129-
tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);
134+
fn = tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);
130135

131-
if (!tdp->Fn && !tdp->Zipfn && !tdp->Multiple) {
136+
if (!tdp->Fn) {
132137
strcpy(g->Message, MSG(MISSING_FNAME));
133138
return NULL;
134139
} // endif Fn
135140

136-
fn = (tdp->Fn) ? tdp->Fn : "unnamed";
137-
138141
if (!(tdp->Lrecl = GetIntegerTableOption(g, topt, "Lrecl", 0)))
139142
tdp->Lrecl = 4096;
140143

@@ -174,7 +177,7 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, PTOS topt, bool info)
174177
htrc("File %s Sep=%c Qot=%c Header=%d maxerr=%d\n",
175178
SVP(tdp->Fn), tdp->Sep, tdp->Qot, tdp->Header, tdp->Maxerr);
176179

177-
if (tdp->Zipfn)
180+
if (tdp->Zipped)
178181
tdbp = new(g) TDBCSV(tdp, new(g) ZIPFAM(tdp));
179182
else
180183
tdbp = new(g) TDBCSV(tdp, new(g) DOSFAM(tdp));
@@ -493,16 +496,9 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
493496
/*******************************************************************/
494497
/* Allocate a file processing class of the proper type. */
495498
/*******************************************************************/
496-
if (Zipfn) {
499+
if (Zipped) {
497500
#if defined(ZIP_SUPPORT)
498501
txfp = new(g) ZIPFAM(this);
499-
500-
if (!Fmtd)
501-
tdbp = new(g) TDBCSV(this, txfp);
502-
else
503-
tdbp = new(g) TDBFMT(this, txfp);
504-
505-
return tdbp;
506502
#else // !ZIP_SUPPORT
507503
strcpy(g->Message, "ZIP not supported");
508504
return NULL;

0 commit comments

Comments
 (0)