diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2015-01-23 17:54:53 +0100 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2015-01-23 17:54:53 +0100 |
commit | dc091a29352bf034ce699395f26a939020c9422e (patch) | |
tree | 0fd65ef8802e1ee5771c71c879b1c83cb3905764 | |
parent | e57677238379624fc4aa1ff5b2852acfad5c2372 (diff) | |
download | mariadb-git-dc091a29352bf034ce699395f26a939020c9422e.tar.gz |
- Fix MDEV-7489 (in add_field)
modified:
storage/connect/ha_connect.cc
- Fix MDEV-7494 (adding Insert_quoted in the STRING class)
modified:
storage/connect/tabmysql.cpp
storage/connect/xobject.cpp
storage/connect/xobject.h
- Fix MDEV-7498 in value.cpp (AllocateValue)
modified:
storage/connect/value.cpp
- Handle backslash in Json serialize + uchar + typo.
modified:
storage/connect/json.cpp
storage/connect/tabjson.cpp
-rw-r--r-- | storage/connect/ha_connect.cc | 9 | ||||
-rw-r--r-- | storage/connect/json.cpp | 14 | ||||
-rw-r--r-- | storage/connect/tabjson.cpp | 2 | ||||
-rw-r--r-- | storage/connect/tabmysql.cpp | 15 | ||||
-rw-r--r-- | storage/connect/value.cpp | 9 | ||||
-rw-r--r-- | storage/connect/xobject.cpp | 25 | ||||
-rw-r--r-- | storage/connect/xobject.h | 1 |
7 files changed, 55 insertions, 20 deletions
diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index a0ac4668eba..0a448b74830 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -4620,7 +4620,7 @@ static bool add_field(String *sql, const char *field_name, int typ, char *dft, char *xtra, int flag, bool dbf, char v) { char var = (len > 255) ? 'V' : v; - bool error= false; + bool q, error= false; const char *type= PLGtoMYSQLtype(typ, dbf, var); error|= sql->append('`'); @@ -4661,7 +4661,12 @@ static bool add_field(String *sql, const char *field_name, int typ, if (dft && *dft) { error|= sql->append(" DEFAULT "); - if (!IsTypeNum(typ)) { + if (typ == TYPE_DATE) + q = (strspn(dft, "0123456789 -:/") == strlen(dft)); + else + q = !IsTypeNum(typ); + + if (q) { error|= sql->append("'"); error|= sql->append_for_single_quote(dft, strlen(dft)); error|= sql->append("'"); diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp index 983f45d9cee..c924ed3d558 100644 --- a/storage/connect/json.cpp +++ b/storage/connect/json.cpp @@ -312,18 +312,19 @@ err: /***********************************************************************/
char *ParseString(PGLOBAL g, int& i, STRG& src)
{
- char *p, *s = src.str;
- int n = 0, len = src.len;
+ char *s = src.str;
+ uchar *p;
+ int n = 0, len = src.len;
// The size to allocate is not known yet
- p = (char*)PlugSubAlloc(g, NULL, 0);
+ p = (uchar*)PlugSubAlloc(g, NULL, 0);
for (; i < len; i++)
switch (s[i]) {
case '"':
p[n++] = 0;
PlugSubAlloc(g, NULL, n);
- return p;
+ return (char*)p;
case '\\':
if (++i < len) {
if (s[i] == 'u') {
@@ -675,12 +676,13 @@ bool JOUTSTR::Escape(const char *s) for (unsigned int i = 0; i < strlen(s); i++)
switch (s[i]) {
+ case '"':
+ case '\\':
case '\t':
case '\n':
case '\r':
case '\b':
- case '\f':
- case '"': WriteChr('\\');
+ case '\f': WriteChr('\\');
// passthru
default:
WriteChr(s[i]);
diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index a3c56965794..ce731971e33 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -1,5 +1,5 @@ /************* tabjson C++ Program Source Code File (.CPP) *************/ -/* PROGRAM NAME: tabxjson Version 1.0 */ +/* PROGRAM NAME: tabjson Version 1.0 */ /* (C) Copyright to the author Olivier BERTRAND 2014 - 2015 */ /* This program are the JSON class DB execution routines. */ /***********************************************************************/ diff --git a/storage/connect/tabmysql.cpp b/storage/connect/tabmysql.cpp index 54627ba43fd..33a4dd67d38 100644 --- a/storage/connect/tabmysql.cpp +++ b/storage/connect/tabmysql.cpp @@ -1141,19 +1141,16 @@ int TDBMYSQL::WriteDB(PGLOBAL g) int rc; uint len = Query->GetLength(); char buf[64]; - bool b, oom = false; + bool oom = false; // Make the Insert command value list for (PCOL colp = Columns; colp; colp = colp->GetNext()) { if (!colp->GetValue()->IsNull()) { - if ((b = colp->GetResultType() == TYPE_STRING || - colp->GetResultType() == TYPE_DATE)) - oom |= Query->Append('\''); - - oom |= Query->Append(colp->GetValue()->GetCharString(buf)); - - if (b) - oom |= Query->Append('\''); + if (colp->GetResultType() == TYPE_STRING || + colp->GetResultType() == TYPE_DATE) + oom |= Query->Append_quoted(colp->GetValue()->GetCharString(buf)); + else + oom |= Query->Append(colp->GetValue()->GetCharString(buf)); } else oom |= Query->Append("NULL"); diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 1cc40473433..e80c31a2baa 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -443,8 +443,13 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns) case TYPE_STRING: p = (PSZ)PlugSubAlloc(g, NULL, 1 + valp->GetValLen()); - if ((sp = valp->GetCharString(p)) != p) - strcpy (p, sp); + if ((sp = valp->GetCharString(p)) != p) { + if (sp) + strcpy (p, sp); + else + *p = 0; + + } // endif sp vp = new(g) TYPVAL<PSZ>(g, p, valp->GetValLen(), valp->GetValPrec()); break; diff --git a/storage/connect/xobject.cpp b/storage/connect/xobject.cpp index 4ddd4f5b30f..b9a0236e7c8 100644 --- a/storage/connect/xobject.cpp +++ b/storage/connect/xobject.cpp @@ -347,6 +347,31 @@ bool STRING::Append(char c) } // end of Append /***********************************************************************/ +/* Append a quoted PSZ to a STRING. */ +/***********************************************************************/ +bool STRING::Append_quoted(PSZ s) +{ + bool b = Append('\''); + + if (s) for (char *p = s; !b && *p; p++) + switch (*p) { + case '\'':
+ case '\\':
+ case '\t':
+ case '\n':
+ case '\r':
+ case '\b':
+ case '\f': b |= Append('\\');
+ // passthru
+ default:
+ b |= Append(*p);
+ break;
+ } // endswitch *p
+
+ return (b |= Append('\''));
+} // end of Append_quoted + +/***********************************************************************/ /* Resize to given length but only when last suballocated. */ /* New size should be greater than string length. */ /***********************************************************************/ diff --git a/storage/connect/xobject.h b/storage/connect/xobject.h index bb7b0150ed8..3660ee86918 100644 --- a/storage/connect/xobject.h +++ b/storage/connect/xobject.h @@ -138,6 +138,7 @@ class DllExport STRING : public BLOCK { bool Append(STRING &str); bool Append(char c); bool Resize(uint n); + bool Append_quoted(PSZ s); inline void Trim(void) {(void)Resize(Length + 1);} inline void Chop(void) {if (Length) Strp[--Length] = 0;} inline void RepLast(char c) {if (Length) Strp[Length-1] = c;} |