mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
make append_query_string() more usable:
simplify the prototype and move it to sql_string.h
This commit is contained in:
@ -41,7 +41,6 @@
|
|||||||
// REPORT_EXCEPT_NOT_FOUND,
|
// REPORT_EXCEPT_NOT_FOUND,
|
||||||
// find_item_in_list,
|
// find_item_in_list,
|
||||||
// RESOLVED_AGAINST_ALIAS, ...
|
// RESOLVED_AGAINST_ALIAS, ...
|
||||||
#include "log_event.h" // append_query_string
|
|
||||||
#include "sql_expression_cache.h"
|
#include "sql_expression_cache.h"
|
||||||
|
|
||||||
const String my_null_string("NULL", 4, default_charset_info);
|
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:
|
case LONG_DATA_VALUE:
|
||||||
{
|
{
|
||||||
str->length(0);
|
str->length(0);
|
||||||
append_query_string(thd, value.cs_info.character_set_client, &str_value,
|
append_query_string(value.cs_info.character_set_client, str,
|
||||||
str);
|
str_value.ptr(), str_value.length(),
|
||||||
|
thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NULL_VALUE:
|
case NULL_VALUE:
|
||||||
|
@ -687,37 +687,35 @@ char *str_to_hex(char *to, const char *from, uint len)
|
|||||||
#ifndef MYSQL_CLIENT
|
#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
|
the 'to' string. To generate a correct escaping, the character set
|
||||||
information in 'csinfo' is used.
|
information in 'csinfo' is used.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int append_query_string(CHARSET_INFO *csinfo, String *to,
|
||||||
append_query_string(THD *thd, CHARSET_INFO *csinfo,
|
const char *str, size_t len, bool no_backslash)
|
||||||
String const *from, String *to)
|
|
||||||
{
|
{
|
||||||
char *beg, *ptr;
|
char *beg, *ptr;
|
||||||
uint32 const orig_len= to->length();
|
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;
|
return 1;
|
||||||
|
|
||||||
beg= (char*) to->ptr() + to->length();
|
beg= (char*) to->ptr() + to->length();
|
||||||
ptr= beg;
|
ptr= beg;
|
||||||
if (csinfo->escape_with_backslash_is_dangerous)
|
if (csinfo->escape_with_backslash_is_dangerous)
|
||||||
ptr= str_to_hex(ptr, from->ptr(), from->length());
|
ptr= str_to_hex(ptr, str, len);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*ptr++= '\'';
|
*ptr++= '\'';
|
||||||
if (!(thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES))
|
if (!no_backslash)
|
||||||
{
|
{
|
||||||
ptr+= escape_string_for_mysql(csinfo, ptr, 0,
|
ptr+= escape_string_for_mysql(csinfo, ptr, 0, str, len);
|
||||||
from->ptr(), from->length());
|
|
||||||
}
|
}
|
||||||
else
|
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 "'" */
|
/* Using '' way to represent "'" */
|
||||||
if (*frm_str == '\'')
|
if (*frm_str == '\'')
|
||||||
|
@ -4766,9 +4766,6 @@ private:
|
|||||||
bool slave_execute_deferred_events(THD *thd);
|
bool slave_execute_deferred_events(THD *thd);
|
||||||
#endif
|
#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,
|
bool rpl_get_position_info(const char **log_file_name, ulonglong *log_pos,
|
||||||
const char **group_relay_log_name,
|
const char **group_relay_log_name,
|
||||||
ulonglong *relay_log_pos);
|
ulonglong *relay_log_pos);
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
// prepare_create_field
|
// prepare_create_field
|
||||||
#include "sql_acl.h" // *_ACL
|
#include "sql_acl.h" // *_ACL
|
||||||
#include "sql_array.h" // Dynamic_array
|
#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
|
#include "sql_derived.h" // mysql_handle_derived
|
||||||
|
|
||||||
#ifdef USE_PRAGMA_IMPLEMENTATION
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
||||||
@ -160,7 +160,8 @@ sp_get_item_value(THD *thd, Item *item, String *str)
|
|||||||
buf.append(result->charset()->csname);
|
buf.append(result->charset()->csname);
|
||||||
if (cs->escape_with_backslash_is_dangerous)
|
if (cs->escape_with_backslash_is_dangerous)
|
||||||
buf.append(' ');
|
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(" COLLATE '");
|
||||||
buf.append(item->collation.collation->name);
|
buf.append(item->collation.collation->name);
|
||||||
buf.append('\'');
|
buf.append('\'');
|
||||||
|
@ -1014,7 +1014,7 @@ outp:
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Append characters to a single-quoted string '...', escaping special
|
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.
|
Does not add the enclosing quotes, this is left up to caller.
|
||||||
*/
|
*/
|
||||||
#define APPEND(X) if (append(X)) return 1; else break
|
#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;
|
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 */
|
#endif /* SQL_STRING_INCLUDED */
|
||||||
|
Reference in New Issue
Block a user