Commit c73a0638 authored by Sergei Golubchik's avatar Sergei Golubchik

remove append_escaped(), use String::append_for_single_quote() instead

parent d0c6a05e
...@@ -1080,7 +1080,7 @@ int collect_string(String *element, ...@@ -1080,7 +1080,7 @@ int collect_string(String *element,
else else
info->found = 1; info->found = 1;
info->str->append('\''); info->str->append('\'');
if (append_escaped(info->str, element)) if (info->str->append_for_single_quote(element))
return 1; return 1;
info->str->append('\''); info->str->append('\'');
return 0; return 0;
...@@ -1239,56 +1239,3 @@ uint check_ulonglong(const char *str, uint length) ...@@ -1239,56 +1239,3 @@ uint check_ulonglong(const char *str, uint length)
return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger; return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
} /* check_ulonlong */ } /* check_ulonlong */
/*
Quote special characters in a string.
SYNOPSIS
append_escaped(to_str, from_str)
to_str (in) A pointer to a String.
from_str (to) A pointer to an allocated string
DESCRIPTION
append_escaped() takes a String type variable, where it appends
escaped the second argument. Only characters that require escaping
will be escaped.
RETURN VALUES
0 Success
1 Out of memory
*/
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;
}
...@@ -365,6 +365,4 @@ class analyse: public Procedure ...@@ -365,6 +365,4 @@ class analyse: public Procedure
List<Item> &field_list); List<Item> &field_list);
}; };
bool append_escaped(String *to_str, String *from_str);
#endif /* SQL_ANALYSE_INCLUDED */ #endif /* SQL_ANALYSE_INCLUDED */
...@@ -67,7 +67,6 @@ ...@@ -67,7 +67,6 @@
// table_to_filename // table_to_filename
// mysql_*_alter_copy_data // mysql_*_alter_copy_data
#include "opt_range.h" // store_key_image_to_rec #include "opt_range.h" // store_key_image_to_rec
#include "sql_analyse.h" // append_escaped
#include "sql_alter.h" // Alter_table_ctx #include "sql_alter.h" // Alter_table_ctx
#include <algorithm> #include <algorithm>
...@@ -1935,10 +1934,9 @@ static int add_uint(File fptr, ulonglong number) ...@@ -1935,10 +1934,9 @@ static int add_uint(File fptr, ulonglong number)
*/ */
static int add_quoted_string(File fptr, const char *quotestr) static int add_quoted_string(File fptr, const char *quotestr)
{ {
String orgstr(quotestr, system_charset_info);
String escapedstr; String escapedstr;
int err= add_string(fptr, "'"); int err= add_string(fptr, "'");
err+= append_escaped(&escapedstr, &orgstr); err+= escapedstr.append_for_single_quote(quotestr);
err+= add_string(fptr, escapedstr.c_ptr_safe()); err+= add_string(fptr, escapedstr.c_ptr_safe());
return err + add_string(fptr, "'"); return err + add_string(fptr, "'");
} }
......
...@@ -496,7 +496,16 @@ class String ...@@ -496,7 +496,16 @@ class String
return FALSE; return FALSE;
} }
void print(String *print); void print(String *print);
bool append_for_single_quote(const char *st, uint len); bool append_for_single_quote(const char *st, uint len);
bool append_for_single_quote(const String *s)
{
return append_for_single_quote(s->ptr(), s->length());
}
bool append_for_single_quote(const char *st)
{
return append_for_single_quote(st, strlen(st));
}
/* Swap two string objects. Efficient way to exchange data without memcpy. */ /* Swap two string objects. Efficient way to exchange data without memcpy. */
void swap(String &s); void swap(String &s);
......
...@@ -1004,7 +1004,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part, ...@@ -1004,7 +1004,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part,
uint blob_length= uint2korr(ptr); uint blob_length= uint2korr(ptr);
blob.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH, blob.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH,
blob_length, &my_charset_bin); blob_length, &my_charset_bin);
if (append_escaped(to, &blob)) if (to->append_for_single_quote(&blob))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
else if (part->key_part_flag & HA_VAR_LENGTH_PART) else if (part->key_part_flag & HA_VAR_LENGTH_PART)
...@@ -1013,7 +1013,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part, ...@@ -1013,7 +1013,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part,
uint var_length= uint2korr(ptr); uint var_length= uint2korr(ptr);
varchar.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH, varchar.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH,
var_length, &my_charset_bin); var_length, &my_charset_bin);
if (append_escaped(to, &varchar)) if (to->append_for_single_quote(&varchar))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
else else
...@@ -1025,7 +1025,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part, ...@@ -1025,7 +1025,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part,
if (field->result_type() == STRING_RESULT) if (field->result_type() == STRING_RESULT)
{ {
if (append_escaped(to, res)) if (to->append_for_single_quote(res))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
else if (to->append(res->ptr(), res->length())) else if (to->append(res->ptr(), res->length()))
......
...@@ -925,7 +925,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part, ...@@ -925,7 +925,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part,
uint blob_length= uint2korr(ptr); uint blob_length= uint2korr(ptr);
blob.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH, blob.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH,
blob_length, &my_charset_bin); blob_length, &my_charset_bin);
if (append_escaped(to, &blob)) if (to->append_for_single_quote(&blob))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
else if (part->key_part_flag & HA_VAR_LENGTH_PART) else if (part->key_part_flag & HA_VAR_LENGTH_PART)
...@@ -934,7 +934,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part, ...@@ -934,7 +934,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part,
uint var_length= uint2korr(ptr); uint var_length= uint2korr(ptr);
varchar.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH, varchar.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH,
var_length, &my_charset_bin); var_length, &my_charset_bin);
if (append_escaped(to, &varchar)) if (to->append_for_single_quote(&varchar))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
else else
...@@ -946,7 +946,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part, ...@@ -946,7 +946,7 @@ static bool emit_key_part_element(String *to, KEY_PART_INFO *part,
if (field->result_type() == STRING_RESULT) if (field->result_type() == STRING_RESULT)
{ {
if (append_escaped(to, res)) if (to->append_for_single_quote(res))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
else if (to->append(res->ptr(), res->length())) else if (to->append(res->ptr(), res->length()))
......
...@@ -7909,7 +7909,7 @@ int spider_db_open_item_string( ...@@ -7909,7 +7909,7 @@ int spider_db_open_item_string(
tmp_str.mem_calc(); tmp_str.mem_calc();
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
if ( if (
append_escaped(str->get_str(), tmp_str2) || str->get_str()->append_for_single_quote(tmp_str2) ||
str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN) str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)
) )
DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM);
...@@ -9029,7 +9029,7 @@ int spider_db_udf_ping_table_append_mon_next( ...@@ -9029,7 +9029,7 @@ int spider_db_udf_ping_table_append_mon_next(
str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN);
str->q_append(SPIDER_SQL_PING_TABLE_STR, SPIDER_SQL_PING_TABLE_LEN); str->q_append(SPIDER_SQL_PING_TABLE_STR, SPIDER_SQL_PING_TABLE_LEN);
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
append_escaped(str->get_str(), child_table_name_str.get_str()); str->get_str()->append_for_single_quote(child_table_name_str.get_str());
str->mem_calc(); str->mem_calc();
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
...@@ -9040,7 +9040,7 @@ int spider_db_udf_ping_table_append_mon_next( ...@@ -9040,7 +9040,7 @@ int spider_db_udf_ping_table_append_mon_next(
str->q_append(limit_str, limit_str_length); str->q_append(limit_str, limit_str_length);
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
append_escaped(str->get_str(), where_clause_str.get_str()); str->get_str()->append_for_single_quote(where_clause_str.get_str());
str->mem_calc(); str->mem_calc();
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
...@@ -9093,7 +9093,7 @@ int spider_db_udf_ping_table_append_select( ...@@ -9093,7 +9093,7 @@ int spider_db_udf_ping_table_append_select(
)) ))
DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM);
if (use_where) if (use_where)
append_escaped(str->get_str(), where_str->get_str()); str->get_str()->append_for_single_quote(where_str->get_str());
str->mem_calc(); str->mem_calc();
str->q_append(SPIDER_SQL_LIMIT_STR, SPIDER_SQL_LIMIT_LEN); str->q_append(SPIDER_SQL_LIMIT_STR, SPIDER_SQL_LIMIT_LEN);
str->q_append(limit_str, limit_str_length); str->q_append(limit_str, limit_str_length);
......
...@@ -3717,7 +3717,7 @@ int spider_db_mysql_util::append_escaped_util( ...@@ -3717,7 +3717,7 @@ int spider_db_mysql_util::append_escaped_util(
) { ) {
DBUG_ENTER("spider_db_mysql_util::append_escaped_util"); DBUG_ENTER("spider_db_mysql_util::append_escaped_util");
DBUG_PRINT("info",("spider this=%p", this)); DBUG_PRINT("info",("spider this=%p", this));
append_escaped(to->get_str(), from); to->get_str()->append_for_single_quote(from);
to->mem_calc(); to->mem_calc();
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment