Skip to content

Commit d75d61c

Browse files
committed
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
1 parent fd166e0 commit d75d61c

File tree

4 files changed

+82
-22
lines changed

4 files changed

+82
-22
lines changed

storage/connect/filamzip.cpp

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*********** File AM Zip C++ Program Source Code File (.CPP) ***********/
22
/* PROGRAM NAME: FILAMZIP */
33
/* ------------- */
4-
/* Version 1.2 */
4+
/* Version 1.3 */
55
/* */
66
/* COPYRIGHT: */
77
/* ---------- */
@@ -602,7 +602,7 @@ bool UNZIPUTL::OpenTable(PGLOBAL g, MODE mode, char *fn)
602602
if (openEntry(g))
603603
return true;
604604

605-
if (size > 0) {
605+
if (size > 0) {
606606
/*******************************************************************/
607607
/* Link a Fblock. This make possible to automatically close it */
608608
/* in case of error g->jump. */
@@ -633,6 +633,28 @@ bool UNZIPUTL::OpenTable(PGLOBAL g, MODE mode, char *fn)
633633
return false;
634634
} // end of OpenTableFile
635635

636+
/***********************************************************************/
637+
/* Insert only if the entry does not exist. */
638+
/***********************************************************************/
639+
bool UNZIPUTL::IsInsertOk(PGLOBAL g, char *fn)
640+
{
641+
bool ok = true, b = open(g, fn);
642+
643+
if (!b) {
644+
if (!target || *target == 0) {
645+
unz_global_info64 ginfo;
646+
int err = unzGetGlobalInfo64(zipfile, &ginfo);
647+
648+
ok = !(err == UNZ_OK && ginfo.number_entry > 0);
649+
} else // Check if the target exist
650+
ok = (unzLocateFile(zipfile, target, 0) != UNZ_OK);
651+
652+
unzClose(zipfile);
653+
} // endif b
654+
655+
return ok;
656+
} // end of IsInsertOk
657+
636658
/***********************************************************************/
637659
/* Open target in zip file. */
638660
/***********************************************************************/
@@ -1006,6 +1028,25 @@ bool ZIPFAM::OpenTableFile(PGLOBAL g)
10061028
{
10071029
char filename[_MAX_PATH];
10081030
MODE mode = Tdbp->GetMode();
1031+
int len = TXTFAM::GetFileLength(g);
1032+
1033+
// We used the file name relative to recorded datapath
1034+
PlugSetPath(filename, To_File, Tdbp->GetPath());
1035+
1036+
if (len < 0)
1037+
return true;
1038+
else if (!append && len > 0) {
1039+
strcpy(g->Message, "No insert into existing zip file");
1040+
return true;
1041+
} else if (append && len > 0) {
1042+
UNZIPUTL *zutp = new(g) UNZIPUTL(target, false);
1043+
1044+
if (!zutp->IsInsertOk(g, filename)) {
1045+
strcpy(g->Message, "No insert into existing entry");
1046+
return true;
1047+
} // endif Ok
1048+
1049+
} // endif's
10091050

10101051
/*********************************************************************/
10111052
/* Allocate the ZIP utility class. */
@@ -1065,15 +1106,31 @@ ZPXFAM::ZPXFAM(PDOSDEF tdp) : FIXFAM(tdp)
10651106
target = tdp->GetEntry();
10661107
append = tdp->GetAppend();
10671108
//Lrecl = tdp->GetLrecl();
1068-
} // end of UZXFAM standard constructor
1109+
} // end of ZPXFAM standard constructor
10691110

10701111
/***********************************************************************/
10711112
/* OpenTableFile: Open a DOS/UNIX table file from a ZIP file. */
10721113
/***********************************************************************/
10731114
bool ZPXFAM::OpenTableFile(PGLOBAL g)
10741115
{
1075-
char filename[_MAX_PATH];
1076-
MODE mode = Tdbp->GetMode();
1116+
char filename[_MAX_PATH];
1117+
MODE mode = Tdbp->GetMode();
1118+
int len = TXTFAM::GetFileLength(g);
1119+
1120+
if (len < 0)
1121+
return true;
1122+
else if (!append && len > 0) {
1123+
strcpy(g->Message, "No insert into existing zip file");
1124+
return true;
1125+
} else if (append && len > 0) {
1126+
UNZIPUTL *zutp = new(g) UNZIPUTL(target, false);
1127+
1128+
if (!zutp->IsInsertOk(g, filename)) {
1129+
strcpy(g->Message, "No insert into existing entry");
1130+
return true;
1131+
} // endif Ok
1132+
1133+
} // endif's
10771134

10781135
/*********************************************************************/
10791136
/* Allocate the ZIP utility class. */

storage/connect/filamzip.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/************** filamzip H Declares Source Code File (.H) **************/
2-
/* Name: filamzip.h Version 1.1 */
2+
/* Name: filamzip.h Version 1.2 */
33
/* */
44
/* (C) Copyright to the author Olivier BERTRAND 2016-2017 */
55
/* */
@@ -77,6 +77,7 @@ class DllExport UNZIPUTL : public BLOCK {
7777
bool WildMatch(PSZ pat, PSZ str);
7878
int findEntry(PGLOBAL g, bool next);
7979
int nextEntry(PGLOBAL g);
80+
bool IsInsertOk(PGLOBAL g, char *fn);
8081

8182
// Members
8283
unzFile zipfile; // The ZIP container file
@@ -181,6 +182,7 @@ class DllExport ZIPFAM : public DOSFAM {
181182
ZIPUTIL *zutp;
182183
PSZ target;
183184
bool append;
185+
//bool replace;
184186
}; // end of ZIPFAM
185187

186188
/***********************************************************************/

storage/connect/json.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,16 @@ PJVAL ParseValue(PGLOBAL g, int& i, STRG& src, bool *pty)
309309
PJVAL jvp = new(g) JVALUE;
310310

311311
for (; i < len; i++)
312-
switch (s[i]) {
313-
case '\n':
314-
pty[0] = pty[1] = false;
315-
case '\r':
316-
case ' ':
317-
case '\t':
318-
break;
319-
default:
320-
goto suite;
321-
} // endswitch
312+
switch (s[i]) {
313+
case '\n':
314+
pty[0] = pty[1] = false;
315+
case '\r':
316+
case ' ':
317+
case '\t':
318+
break;
319+
default:
320+
goto suite;
321+
} // endswitch
322322

323323
suite:
324324
switch (s[i]) {
@@ -1345,7 +1345,7 @@ void JVALUE::SetTiny(PGLOBAL g, char n)
13451345
{
13461346
Value = AllocateValue(g, &n, TYPE_TINY);
13471347
Jsp = NULL;
1348-
} // end of SetInteger
1348+
} // end of SetTiny
13491349

13501350
/***********************************************************************/
13511351
/* Set the Value's value as the given big integer. */
@@ -1379,6 +1379,6 @@ void JVALUE::SetString(PGLOBAL g, PSZ s, short c)
13791379
/***********************************************************************/
13801380
bool JVALUE::IsNull(void)
13811381
{
1382-
return (Jsp) ? Jsp->IsNull() : (Value) ? Value->IsZero() : true;
1382+
return (Jsp) ? Jsp->IsNull() : (Value) ? Value->IsNull() : true;
13831383
} // end of IsNull
13841384

storage/connect/tabjson.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,11 +1294,11 @@ void JSONCOL::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n)
12941294
// } // endif Type
12951295

12961296
default:
1297-
vp->Reset();
1298-
} // endswitch Type
1297+
vp->SetNull(true);
1298+
} // endswitch Type
12991299

13001300
} else
1301-
vp->Reset();
1301+
vp->SetNull(true);
13021302

13031303
} // end of SetJsonValue
13041304

@@ -1312,7 +1312,7 @@ void JSONCOL::ReadColumn(PGLOBAL g)
13121312

13131313
// Set null when applicable
13141314
if (Nullable)
1315-
Value->SetNull(Value->IsZero());
1315+
Value->SetNull(Value->IsNull());
13161316

13171317
} // end of ReadColumn
13181318

@@ -1637,6 +1637,7 @@ void JSONCOL::WriteColumn(PGLOBAL g)
16371637
// Passthru
16381638
case TYPE_DATE:
16391639
case TYPE_INT:
1640+
case TYPE_TINY:
16401641
case TYPE_SHORT:
16411642
case TYPE_BIGINT:
16421643
case TYPE_DOUBLE:

0 commit comments

Comments
 (0)