Fix MDEV-12603 Insert replaces values in ZIP file

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
This commit is contained in:
Olivier Bertrand 2017-05-05 23:56:16 +02:00
parent fd166e0377
commit d75d61cd6f
4 changed files with 82 additions and 22 deletions

View file

@ -1,7 +1,7 @@
/*********** File AM Zip C++ Program Source Code File (.CPP) ***********/
/* PROGRAM NAME: FILAMZIP */
/* ------------- */
/* Version 1.2 */
/* Version 1.3 */
/* */
/* COPYRIGHT: */
/* ---------- */
@ -602,7 +602,7 @@ bool UNZIPUTL::OpenTable(PGLOBAL g, MODE mode, char *fn)
if (openEntry(g))
return true;
if (size > 0) {
if (size > 0) {
/*******************************************************************/
/* Link a Fblock. This make possible to automatically close it */
/* in case of error g->jump. */
@ -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. */
/***********************************************************************/
@ -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. */
@ -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. */

View file

@ -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 */
/* */
@ -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
@ -181,6 +182,7 @@ class DllExport ZIPFAM : public DOSFAM {
ZIPUTIL *zutp;
PSZ target;
bool append;
//bool replace;
}; // end of ZIPFAM
/***********************************************************************/

View file

@ -309,16 +309,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]) {
@ -1345,7 +1345,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. */
@ -1379,6 +1379,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

View file

@ -1294,11 +1294,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
@ -1312,7 +1312,7 @@ void JSONCOL::ReadColumn(PGLOBAL g)
// Set null when applicable
if (Nullable)
Value->SetNull(Value->IsZero());
Value->SetNull(Value->IsNull());
} // end of ReadColumn
@ -1637,6 +1637,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: