diff options
author | unknown <jani@ua141d10.elisa.omakaista.fi> | 2005-01-11 19:40:33 +0200 |
---|---|---|
committer | unknown <jani@ua141d10.elisa.omakaista.fi> | 2005-01-11 19:40:33 +0200 |
commit | 22de48855756432c954069d79e17940fae32b8e6 (patch) | |
tree | 462ed973de22902342a5c4f90fcba974d3651de8 /sql/sql_analyse.cc | |
parent | 7bb97a4ad8aee442d657de23093d1c9f4a2013d5 (diff) | |
download | mariadb-git-22de48855756432c954069d79e17940fae32b8e6.tar.gz |
Fixed Bug#2813, "analyse does not quot string values in enams from string".
Diffstat (limited to 'sql/sql_analyse.cc')
-rw-r--r-- | sql/sql_analyse.cc | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 1e0aebbc1ec..5265857f3b1 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -59,6 +59,7 @@ int compare_ulonglong2(void* cmp_arg __attribute__((unused)), return compare_ulonglong(s,t); } +static bool append_escaped(String *to_str, String *from_str); Procedure * proc_analyse_init(THD *thd, ORDER *param, select_result *result, @@ -890,7 +891,8 @@ int collect_string(String *element, else info->found = 1; info->str->append('\''); - info->str->append(*element); + if (append_escaped(info->str, element)) + return 1; info->str->append('\''); return 0; } // collect_string @@ -1025,3 +1027,58 @@ uint check_ulonglong(const char *str, uint length) while (*cmp && *cmp++ == *str++) ; return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger; } /* check_ulonlong */ + + + +/* + FUNCTION: append_escaped() + + DESCRIPTION + append_escaped() takes a String type variable, where it appends + escaped the second argument. Only characters that require escaping + will be escaped. + + ARGUMENTS + A pointer to a String variable, where results will be appended + A pointer to a String variable, which is appended to the result + String, escaping those characters that require it. + + RETURN VALUES + 0 Success + 1 Out of memory +*/ + +static bool append_escaped(String *to_str, String *from_str) +{ + char *from, *end, c; + + if (to_str->realloc(to_str->length() + from_str->length())) + return 1; + + from= (char*) from_str->ptr(); + end= from + from_str->length(); + for (; from < end; from++) + { + c= *from; + switch (c) { + case '\0': + c= '0'; + break; + case '\032': + c= 'Z'; + break; + case '\\': + case '\'': + break; + default: + goto normal_character; + } + if (to_str->append('\\')) + return 1; + + normal_character: + if (to_str->append(c)) + return 1; + } + return 0; +} |