Skip to content

Commit

Permalink
- MDEV-11295: developing handling files contained in ZIP file.
Browse files Browse the repository at this point in the history
  Fix bug using multiple zip files
  modified:   storage/connect/filamzip.cpp
  modified:   storage/connect/filamzip.h
  modified:   storage/connect/tabfmt.cpp
  modified:   storage/connect/tabjson.cpp

- Add error msg when trying to make discovery on multiple tables
  modified:   storage/connect/tabfmt.cpp
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabxml.cpp
  • Loading branch information
Buggynours committed Dec 14, 2016
1 parent 8a3fc7c commit b3d2ac3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
11 changes: 6 additions & 5 deletions storage/connect/filamzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
ZIPFAM::ZIPFAM(PDOSDEF tdp) : MAPFAM(tdp)
{
zipfile = NULL;
zfn = tdp->Fn;
//zfn = tdp->Fn;
target = tdp->Entry;
//*fn = 0;
entryopen = false;
Expand All @@ -65,7 +65,7 @@ ZIPFAM::ZIPFAM(PDOSDEF tdp) : MAPFAM(tdp)
ZIPFAM::ZIPFAM(PZIPFAM txfp) : MAPFAM(txfp)
{
zipfile = txfp->zipfile;
zfn = txfp->zfn;
//zfn = txfp->zfn;
target = txfp->target;
//strcpy(fn, txfp->fn);
finfo = txfp->finfo;
Expand Down Expand Up @@ -129,7 +129,7 @@ int ZIPFAM::GetFileLength(PGLOBAL g)
bool ZIPFAM::open(PGLOBAL g, const char *filename)
{
if (!zipfile && !(zipfile = unzOpen64(filename)))
sprintf(g->Message, "Zipfile open error");
sprintf(g->Message, "Zipfile open error on %s", filename);

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

bool b = open(g, filename);

Expand Down Expand Up @@ -258,7 +258,8 @@ bool ZIPFAM::OpenTableFile(PGLOBAL g)
} // endif fp

To_Fb = fp; // Useful when closing
} // endif b
} else
return true;

} else {
strcpy(g->Message, "Only READ mode supported for ZIP files");
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/filamzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DllExport ZIPFAM : public MAPFAM {

// Members
unzFile zipfile; // The ZIP container file
PSZ zfn; // The ZIP file name
//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
Expand Down
16 changes: 6 additions & 10 deletions storage/connect/tabfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, PTOS topt, bool info)
goto skipit;
} // endif info

if (GetIntegerTableOption(g, topt, "Multiple", 0)) {
strcpy(g->Message, "Cannot find column definition for multiple table");
return NULL;
} // endif Multiple

// num_max = atoi(p+1); // Max num of record to test
imax = hmax = nerr = 0;

Expand All @@ -124,18 +129,15 @@ PQRYRES CSVColumns(PGLOBAL g, char *dp, PTOS topt, bool info)
tdp = new(g) CSVDEF;
#if defined(ZIP_SUPPORT)
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);
fn = tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);

if (!tdp->Fn) {
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;

Expand Down Expand Up @@ -497,12 +499,6 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
if (Zipped) {
#if defined(ZIP_SUPPORT)
txfp = new(g) ZIPFAM(this);

if (!Fmtd)
tdbp = new(g) TDBCSV(this, txfp);
else
tdbp = new(g) TDBFMT(this, txfp);

#else // !ZIP_SUPPORT
strcpy(g->Message, "ZIP not supported");
return NULL;
Expand Down
8 changes: 6 additions & 2 deletions storage/connect/tabjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
goto skipit;
} // endif info

/*********************************************************************/
if (GetIntegerTableOption(g, topt, "Multiple", 0)) {
strcpy(g->Message, "Cannot find column definition for multiple table");
return NULL;
} // endif Multiple

/*********************************************************************/
/* Open the input file. */
/*********************************************************************/
lvl = GetIntegerTableOption(g, topt, "Level", 0);
Expand All @@ -103,7 +108,6 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
tdp = new(g) JSONDEF;
#if defined(ZIP_SUPPORT)
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);
Expand Down
7 changes: 6 additions & 1 deletion storage/connect/tabxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
goto skipit;
} // endif info

/*********************************************************************/
if (GetIntegerTableOption(g, topt, "Multiple", 0)) {
strcpy(g->Message, "Cannot find column definition for multiple table");
return NULL;
} // endif Multiple

/*********************************************************************/
/* Open the input file. */
/*********************************************************************/
if (!(fn = GetStringTableOption(g, topt, "Filename", NULL))) {
Expand Down

0 comments on commit b3d2ac3

Please sign in to comment.