summaryrefslogtreecommitdiff
path: root/storage/connect
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2017-05-06 00:08:20 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2017-05-06 00:08:20 +0200
commit531698e0da307943dff5ee6830a241d6829345cd (patch)
tree2eb30c76fcfafe9f1fe2e67a712114b127958ba0 /storage/connect
parenta2af3c0d44d919051c08b63cb10bed546d5f92a3 (diff)
downloadmariadb-git-531698e0da307943dff5ee6830a241d6829345cd.tar.gz
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
Diffstat (limited to 'storage/connect')
-rw-r--r--storage/connect/filamzip.cpp65
-rw-r--r--storage/connect/filamzip.h3
-rw-r--r--storage/connect/json.cpp24
-rw-r--r--storage/connect/tabjson.cpp9
4 files changed, 80 insertions, 21 deletions
diff --git a/storage/connect/filamzip.cpp b/storage/connect/filamzip.cpp
index 17ca84d9d5c..92de5117638 100644
--- a/storage/connect/filamzip.cpp
+++ b/storage/connect/filamzip.cpp
@@ -1,7 +1,7 @@
/*********** File AM Zip C++ Program Source Code File (.CPP) ***********/
/* PROGRAM NAME: FILAMZIP */
/* ------------- */
-/* Version 1.2 */
+/* Version 1.3 */
/* */
/* COPYRIGHT: */
/* ---------- */
@@ -634,6 +634,28 @@ bool UNZIPUTL::OpenTable(PGLOBAL g, MODE mode, char *fn)
} // 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. */
/***********************************************************************/
bool UNZIPUTL::openEntry(PGLOBAL g)
@@ -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. */
diff --git a/storage/connect/filamzip.h b/storage/connect/filamzip.h
index 2f9e491f621..ba1d8658dc4 100644
--- a/storage/connect/filamzip.h
+++ b/storage/connect/filamzip.h
@@ -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
diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp
index 6817439a635..2aca1377d69 100644
--- a/storage/connect/json.cpp
+++ b/storage/connect/json.cpp
@@ -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
diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp
index 9450f8d76aa..22f9b592952 100644
--- a/storage/connect/tabjson.cpp
+++ b/storage/connect/tabjson.cpp
@@ -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: