Commit 531698e0 authored by Olivier Bertrand's avatar Olivier Bertrand

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
parent a2af3c0d
/*********** File AM Zip C++ Program Source Code File (.CPP) ***********/
/* PROGRAM NAME: FILAMZIP */
/* ------------- */
/* Version 1.2 */
/* Version 1.3 */
/* */
/* COPYRIGHT: */
/* ---------- */
......@@ -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. */
......
/************** 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
......
......@@ -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]) {
......@@ -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. */
......@@ -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
......@@ -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
......@@ -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
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment