Skip to content

Commit

Permalink
Fix MDEV-12603 Insert replaces values in ZIP file
Browse files Browse the repository at this point in the history
  modified:   storage/connect/filamzip.cpp
  modified:   storage/connect/filamzip.h

Fix MDEV-12686 Handle null in json
Fix MDEV-12688 Insert does not handle type TINYINT
  modified:   storage/connect/json.cpp
  modified:   storage/connect/tabjson.cpp
  • Loading branch information
Buggynours committed May 5, 2017
1 parent a2af3c0 commit 531698e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 21 deletions.
65 changes: 61 additions & 4 deletions storage/connect/filamzip.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*********** File AM Zip C++ Program Source Code File (.CPP) ***********/
/* PROGRAM NAME: FILAMZIP */
/* ------------- */
/* Version 1.2 */
/* Version 1.3 */
/* */
/* COPYRIGHT: */
/* ---------- */
Expand Down Expand Up @@ -633,6 +633,28 @@ bool UNZIPUTL::OpenTable(PGLOBAL g, MODE mode, char *fn)
return false;
} // end of OpenTableFile

/***********************************************************************/
/* Insert only if the entry does not exist. */
/***********************************************************************/
bool UNZIPUTL::IsInsertOk(PGLOBAL g, char *fn)
{
bool ok = true, b = open(g, fn);

if (!b) {
if (!target || *target == 0) {
unz_global_info64 ginfo;
int err = unzGetGlobalInfo64(zipfile, &ginfo);

ok = !(err == UNZ_OK && ginfo.number_entry > 0);
} else // Check if the target exist
ok = (unzLocateFile(zipfile, target, 0) != UNZ_OK);

unzClose(zipfile);
} // endif b

return ok;
} // end of IsInsertOk

/***********************************************************************/
/* Open target in zip file. */
/***********************************************************************/
Expand Down Expand Up @@ -1006,6 +1028,25 @@ bool ZIPFAM::OpenTableFile(PGLOBAL g)
{
char filename[_MAX_PATH];
MODE mode = Tdbp->GetMode();
int len = TXTFAM::GetFileLength(g);

// We used the file name relative to recorded datapath
PlugSetPath(filename, To_File, Tdbp->GetPath());

if (len < 0)
return true;
else if (!append && len > 0) {
strcpy(g->Message, "No insert into existing zip file");
return true;
} else if (append && len > 0) {
UNZIPUTL *zutp = new(g) UNZIPUTL(target, false);

if (!zutp->IsInsertOk(g, filename)) {
strcpy(g->Message, "No insert into existing entry");
return true;
} // endif Ok

} // endif's

/*********************************************************************/
/* Allocate the ZIP utility class. */
Expand Down Expand Up @@ -1065,15 +1106,31 @@ ZPXFAM::ZPXFAM(PDOSDEF tdp) : FIXFAM(tdp)
target = tdp->GetEntry();
append = tdp->GetAppend();
//Lrecl = tdp->GetLrecl();
} // end of UZXFAM standard constructor
} // end of ZPXFAM standard constructor

/***********************************************************************/
/* OpenTableFile: Open a DOS/UNIX table file from a ZIP file. */
/***********************************************************************/
bool ZPXFAM::OpenTableFile(PGLOBAL g)
{
char filename[_MAX_PATH];
MODE mode = Tdbp->GetMode();
char filename[_MAX_PATH];
MODE mode = Tdbp->GetMode();
int len = TXTFAM::GetFileLength(g);

if (len < 0)
return true;
else if (!append && len > 0) {
strcpy(g->Message, "No insert into existing zip file");
return true;
} else if (append && len > 0) {
UNZIPUTL *zutp = new(g) UNZIPUTL(target, false);

if (!zutp->IsInsertOk(g, filename)) {
strcpy(g->Message, "No insert into existing entry");
return true;
} // endif Ok

} // endif's

/*********************************************************************/
/* Allocate the ZIP utility class. */
Expand Down
3 changes: 2 additions & 1 deletion storage/connect/filamzip.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************** filamzip H Declares Source Code File (.H) **************/
/* Name: filamzip.h Version 1.1 */
/* Name: filamzip.h Version 1.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2016-2017 */
/* */
Expand Down Expand Up @@ -77,6 +77,7 @@ class DllExport UNZIPUTL : public BLOCK {
bool WildMatch(PSZ pat, PSZ str);
int findEntry(PGLOBAL g, bool next);
int nextEntry(PGLOBAL g);
bool IsInsertOk(PGLOBAL g, char *fn);

// Members
unzFile zipfile; // The ZIP container file
Expand Down
24 changes: 12 additions & 12 deletions storage/connect/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,16 @@ PJVAL ParseValue(PGLOBAL g, int& i, STRG& src, bool *pty)
PJVAL jvp = new(g) JVALUE;

for (; i < len; i++)
switch (s[i]) {
case '\n':
pty[0] = pty[1] = false;
case '\r':
case ' ':
case '\t':
break;
default:
goto suite;
} // endswitch
switch (s[i]) {
case '\n':
pty[0] = pty[1] = false;
case '\r':
case ' ':
case '\t':
break;
default:
goto suite;
} // endswitch

suite:
switch (s[i]) {
Expand Down Expand Up @@ -1432,7 +1432,7 @@ void JVALUE::SetTiny(PGLOBAL g, char n)
{
Value = AllocateValue(g, &n, TYPE_TINY);
Jsp = NULL;
} // end of SetInteger
} // end of SetTiny

/***********************************************************************/
/* Set the Value's value as the given big integer. */
Expand Down Expand Up @@ -1466,6 +1466,6 @@ void JVALUE::SetString(PGLOBAL g, PSZ s, short c)
/***********************************************************************/
bool JVALUE::IsNull(void)
{
return (Jsp) ? Jsp->IsNull() : (Value) ? Value->IsZero() : true;
return (Jsp) ? Jsp->IsNull() : (Value) ? Value->IsNull() : true;
} // end of IsNull

9 changes: 5 additions & 4 deletions storage/connect/tabjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,11 +1193,11 @@ void JSONCOL::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n)
// } // endif Type

default:
vp->Reset();
} // endswitch Type
vp->SetNull(true);
} // endswitch Type

} else
vp->Reset();
vp->SetNull(true);

} // end of SetJsonValue

Expand All @@ -1211,7 +1211,7 @@ void JSONCOL::ReadColumn(PGLOBAL g)

// Set null when applicable
if (Nullable)
Value->SetNull(Value->IsZero());
Value->SetNull(Value->IsNull());

} // end of ReadColumn

Expand Down Expand Up @@ -1548,6 +1548,7 @@ void JSONCOL::WriteColumn(PGLOBAL g)
// Passthru
case TYPE_DATE:
case TYPE_INT:
case TYPE_TINY:
case TYPE_SHORT:
case TYPE_BIGINT:
case TYPE_DOUBLE:
Expand Down

0 comments on commit 531698e

Please sign in to comment.