Skip to content

Commit

Permalink
- Fix MDEV-7489 (in add_field)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Buggynours committed Jan 23, 2015
1 parent e576772 commit dc091a2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 20 deletions.
9 changes: 7 additions & 2 deletions storage/connect/ha_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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('`');
Expand Down Expand Up @@ -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("'");
Expand Down
14 changes: 8 additions & 6 deletions storage/connect/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,19 @@ PJVAL ParseValue(PGLOBAL g, int& i, STRG& src)
/***********************************************************************/
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') {
Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/tabjson.cpp
Original file line number Diff line number Diff line change
@@ -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. */
/***********************************************************************/
Expand Down
15 changes: 6 additions & 9 deletions storage/connect/tabmysql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 7 additions & 2 deletions storage/connect/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions storage/connect/xobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,31 @@ bool STRING::Append(char c)
return false;
} // 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. */
Expand Down
1 change: 1 addition & 0 deletions storage/connect/xobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
Expand Down

0 comments on commit dc091a2

Please sign in to comment.