Commit 218280bc authored by Sergei Golubchik's avatar Sergei Golubchik

make append_query_string() more usable:

simplify the prototype and move it to sql_string.h
parent c73a0638
......@@ -41,7 +41,6 @@
// REPORT_EXCEPT_NOT_FOUND,
// find_item_in_list,
// RESOLVED_AGAINST_ALIAS, ...
#include "log_event.h" // append_query_string
#include "sql_expression_cache.h"
const String my_null_string("NULL", 4, default_charset_info);
......@@ -3749,8 +3748,9 @@ const String *Item_param::query_val_str(THD *thd, String* str) const
case LONG_DATA_VALUE:
{
str->length(0);
append_query_string(thd, value.cs_info.character_set_client, &str_value,
str);
append_query_string(value.cs_info.character_set_client, str,
str_value.ptr(), str_value.length(),
thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES);
break;
}
case NULL_VALUE:
......
......@@ -687,37 +687,35 @@ char *str_to_hex(char *to, const char *from, uint len)
#ifndef MYSQL_CLIENT
/**
Append a version of the 'from' string suitable for use in a query to
Append a version of the 'str' string suitable for use in a query to
the 'to' string. To generate a correct escaping, the character set
information in 'csinfo' is used.
*/
int
append_query_string(THD *thd, CHARSET_INFO *csinfo,
String const *from, String *to)
int append_query_string(CHARSET_INFO *csinfo, String *to,
const char *str, size_t len, bool no_backslash)
{
char *beg, *ptr;
uint32 const orig_len= to->length();
if (to->reserve(orig_len + from->length() * 2 + 4))
if (to->reserve(orig_len + len * 2 + 4))
return 1;
beg= (char*) to->ptr() + to->length();
ptr= beg;
if (csinfo->escape_with_backslash_is_dangerous)
ptr= str_to_hex(ptr, from->ptr(), from->length());
ptr= str_to_hex(ptr, str, len);
else
{
*ptr++= '\'';
if (!(thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES))
if (!no_backslash)
{
ptr+= escape_string_for_mysql(csinfo, ptr, 0,
from->ptr(), from->length());
ptr+= escape_string_for_mysql(csinfo, ptr, 0, str, len);
}
else
{
const char *frm_str= from->ptr();
const char *frm_str= str;
for (; frm_str < (from->ptr() + from->length()); frm_str++)
for (; frm_str < (str + len); frm_str++)
{
/* Using '' way to represent "'" */
if (*frm_str == '\'')
......
......@@ -4766,9 +4766,6 @@ class Heartbeat_log_event: public Log_event
bool slave_execute_deferred_events(THD *thd);
#endif
int append_query_string(THD *thd, CHARSET_INFO *csinfo,
String const *from, String *to);
bool rpl_get_position_info(const char **log_file_name, ulonglong *log_pos,
const char **group_relay_log_name,
ulonglong *relay_log_pos);
......
......@@ -27,7 +27,7 @@
// prepare_create_field
#include "sql_acl.h" // *_ACL
#include "sql_array.h" // Dynamic_array
#include "log_event.h" // append_query_string, Query_log_event
#include "log_event.h" // Query_log_event
#include "sql_derived.h" // mysql_handle_derived
#ifdef USE_PRAGMA_IMPLEMENTATION
......@@ -160,7 +160,8 @@ sp_get_item_value(THD *thd, Item *item, String *str)
buf.append(result->charset()->csname);
if (cs->escape_with_backslash_is_dangerous)
buf.append(' ');
append_query_string(thd, cs, result, &buf);
append_query_string(cs, &buf, result->ptr(), result->length(),
thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES);
buf.append(" COLLATE '");
buf.append(item->collation.collation->name);
buf.append('\'');
......
......@@ -1014,7 +1014,7 @@ well_formed_copy_nchars(CHARSET_INFO *to_cs,
/*
Append characters to a single-quoted string '...', escaping special
characters as necessary.
characters with backslashes as necessary.
Does not add the enclosing quotes, this is left up to caller.
*/
#define APPEND(X) if (append(X)) return 1; else break
......
......@@ -568,4 +568,7 @@ static inline bool check_if_only_end_space(CHARSET_INFO *cs,
return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
}
int append_query_string(CHARSET_INFO *csinfo, String *to,
const char *str, size_t len, bool no_backslash);
#endif /* SQL_STRING_INCLUDED */
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