summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2014-03-26 09:42:33 +0100
committerSergei Golubchik <sergii@pisem.net>2014-03-26 09:42:33 +0100
commit218280bcd76eb8cbe083157433d709ff7a0e3580 (patch)
treebe2d0157628b7059a309243fe625e36653926c8e
parentc73a0638c233f421bc17705d94e934d8fccfbe19 (diff)
downloadmariadb-git-218280bcd76eb8cbe083157433d709ff7a0e3580.tar.gz
make append_query_string() more usable:
simplify the prototype and move it to sql_string.h
-rw-r--r--sql/item.cc6
-rw-r--r--sql/log_event.cc20
-rw-r--r--sql/log_event.h3
-rw-r--r--sql/sp_head.cc5
-rw-r--r--sql/sql_string.cc2
-rw-r--r--sql/sql_string.h3
6 files changed, 19 insertions, 20 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 0fbd58567ef..8b2b09c68d3 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -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:
diff --git a/sql/log_event.cc b/sql/log_event.cc
index e1f48bf9a4e..ce88aa2a301 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -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 == '\'')
diff --git a/sql/log_event.h b/sql/log_event.h
index 06da034dc58..bba1b907a57 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -4766,9 +4766,6 @@ private:
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);
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 84e2c3069c3..92f7ac020f5 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -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('\'');
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index a2d4349f747..bcc811e426d 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -1014,7 +1014,7 @@ outp:
/*
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
diff --git a/sql/sql_string.h b/sql/sql_string.h
index 77712c09805..bc9e7f11bd6 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -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 */