mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
- 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
This commit is contained in:
@@ -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 *dft, char *xtra, int flag, bool dbf, char v)
|
||||||
{
|
{
|
||||||
char var = (len > 255) ? 'V' : v;
|
char var = (len > 255) ? 'V' : v;
|
||||||
bool error= false;
|
bool q, error= false;
|
||||||
const char *type= PLGtoMYSQLtype(typ, dbf, var);
|
const char *type= PLGtoMYSQLtype(typ, dbf, var);
|
||||||
|
|
||||||
error|= sql->append('`');
|
error|= sql->append('`');
|
||||||
@@ -4661,7 +4661,12 @@ static bool add_field(String *sql, const char *field_name, int typ,
|
|||||||
if (dft && *dft) {
|
if (dft && *dft) {
|
||||||
error|= sql->append(" DEFAULT ");
|
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("'");
|
||||||
error|= sql->append_for_single_quote(dft, strlen(dft));
|
error|= sql->append_for_single_quote(dft, strlen(dft));
|
||||||
error|= sql->append("'");
|
error|= sql->append("'");
|
||||||
|
@@ -312,18 +312,19 @@ err:
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
char *ParseString(PGLOBAL g, int& i, STRG& src)
|
char *ParseString(PGLOBAL g, int& i, STRG& src)
|
||||||
{
|
{
|
||||||
char *p, *s = src.str;
|
char *s = src.str;
|
||||||
|
uchar *p;
|
||||||
int n = 0, len = src.len;
|
int n = 0, len = src.len;
|
||||||
|
|
||||||
// The size to allocate is not known yet
|
// The size to allocate is not known yet
|
||||||
p = (char*)PlugSubAlloc(g, NULL, 0);
|
p = (uchar*)PlugSubAlloc(g, NULL, 0);
|
||||||
|
|
||||||
for (; i < len; i++)
|
for (; i < len; i++)
|
||||||
switch (s[i]) {
|
switch (s[i]) {
|
||||||
case '"':
|
case '"':
|
||||||
p[n++] = 0;
|
p[n++] = 0;
|
||||||
PlugSubAlloc(g, NULL, n);
|
PlugSubAlloc(g, NULL, n);
|
||||||
return p;
|
return (char*)p;
|
||||||
case '\\':
|
case '\\':
|
||||||
if (++i < len) {
|
if (++i < len) {
|
||||||
if (s[i] == 'u') {
|
if (s[i] == 'u') {
|
||||||
@@ -675,12 +676,13 @@ bool JOUTSTR::Escape(const char *s)
|
|||||||
|
|
||||||
for (unsigned int i = 0; i < strlen(s); i++)
|
for (unsigned int i = 0; i < strlen(s); i++)
|
||||||
switch (s[i]) {
|
switch (s[i]) {
|
||||||
|
case '"':
|
||||||
|
case '\\':
|
||||||
case '\t':
|
case '\t':
|
||||||
case '\n':
|
case '\n':
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\b':
|
case '\b':
|
||||||
case '\f':
|
case '\f': WriteChr('\\');
|
||||||
case '"': WriteChr('\\');
|
|
||||||
// passthru
|
// passthru
|
||||||
default:
|
default:
|
||||||
WriteChr(s[i]);
|
WriteChr(s[i]);
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/************* tabjson C++ Program Source Code File (.CPP) *************/
|
/************* 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 */
|
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2015 */
|
||||||
/* This program are the JSON class DB execution routines. */
|
/* This program are the JSON class DB execution routines. */
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
|
@@ -1141,20 +1141,17 @@ int TDBMYSQL::WriteDB(PGLOBAL g)
|
|||||||
int rc;
|
int rc;
|
||||||
uint len = Query->GetLength();
|
uint len = Query->GetLength();
|
||||||
char buf[64];
|
char buf[64];
|
||||||
bool b, oom = false;
|
bool oom = false;
|
||||||
|
|
||||||
// Make the Insert command value list
|
// Make the Insert command value list
|
||||||
for (PCOL colp = Columns; colp; colp = colp->GetNext()) {
|
for (PCOL colp = Columns; colp; colp = colp->GetNext()) {
|
||||||
if (!colp->GetValue()->IsNull()) {
|
if (!colp->GetValue()->IsNull()) {
|
||||||
if ((b = colp->GetResultType() == TYPE_STRING ||
|
if (colp->GetResultType() == TYPE_STRING ||
|
||||||
colp->GetResultType() == TYPE_DATE))
|
colp->GetResultType() == TYPE_DATE)
|
||||||
oom |= Query->Append('\'');
|
oom |= Query->Append_quoted(colp->GetValue()->GetCharString(buf));
|
||||||
|
else
|
||||||
oom |= Query->Append(colp->GetValue()->GetCharString(buf));
|
oom |= Query->Append(colp->GetValue()->GetCharString(buf));
|
||||||
|
|
||||||
if (b)
|
|
||||||
oom |= Query->Append('\'');
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
oom |= Query->Append("NULL");
|
oom |= Query->Append("NULL");
|
||||||
|
|
||||||
|
@@ -443,8 +443,13 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns)
|
|||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
p = (PSZ)PlugSubAlloc(g, NULL, 1 + valp->GetValLen());
|
p = (PSZ)PlugSubAlloc(g, NULL, 1 + valp->GetValLen());
|
||||||
|
|
||||||
if ((sp = valp->GetCharString(p)) != p)
|
if ((sp = valp->GetCharString(p)) != p) {
|
||||||
|
if (sp)
|
||||||
strcpy (p, sp);
|
strcpy (p, sp);
|
||||||
|
else
|
||||||
|
*p = 0;
|
||||||
|
|
||||||
|
} // endif sp
|
||||||
|
|
||||||
vp = new(g) TYPVAL<PSZ>(g, p, valp->GetValLen(), valp->GetValPrec());
|
vp = new(g) TYPVAL<PSZ>(g, p, valp->GetValLen(), valp->GetValPrec());
|
||||||
break;
|
break;
|
||||||
|
@@ -346,6 +346,31 @@ bool STRING::Append(char c)
|
|||||||
return false;
|
return false;
|
||||||
} // end of Append
|
} // 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. */
|
/* Resize to given length but only when last suballocated. */
|
||||||
/* New size should be greater than string length. */
|
/* New size should be greater than string length. */
|
||||||
|
@@ -138,6 +138,7 @@ class DllExport STRING : public BLOCK {
|
|||||||
bool Append(STRING &str);
|
bool Append(STRING &str);
|
||||||
bool Append(char c);
|
bool Append(char c);
|
||||||
bool Resize(uint n);
|
bool Resize(uint n);
|
||||||
|
bool Append_quoted(PSZ s);
|
||||||
inline void Trim(void) {(void)Resize(Length + 1);}
|
inline void Trim(void) {(void)Resize(Length + 1);}
|
||||||
inline void Chop(void) {if (Length) Strp[--Length] = 0;}
|
inline void Chop(void) {if (Length) Strp[--Length] = 0;}
|
||||||
inline void RepLast(char c) {if (Length) Strp[Length-1] = c;}
|
inline void RepLast(char c) {if (Length) Strp[Length-1] = c;}
|
||||||
|
Reference in New Issue
Block a user