Commit 33e74b14 authored by unknown's avatar unknown

Merge fixes for #8248, #5569.


mysql-test/r/func_str.result:
  Update results
mysql-test/t/func_str.test:
  Merge test
sql/item_strfunc.cc:
  Set charset on output string
sql/item_strfunc.h:
  Merge
sql/sql_parse.cc:
  Merge
vio/viosocket.c:
  Merge
parents 6b6e5d4a 22f839cd
...@@ -697,6 +697,13 @@ quote(ltrim(concat(' ', 'a'))) ...@@ -697,6 +697,13 @@ quote(ltrim(concat(' ', 'a')))
select quote(trim(concat(' ', 'a'))); select quote(trim(concat(' ', 'a')));
quote(trim(concat(' ', 'a'))) quote(trim(concat(' ', 'a')))
'a' 'a'
CREATE TABLE t1 SELECT 1 UNION SELECT 2 UNION SELECT 3;
SELECT QUOTE('A') FROM t1;
QUOTE('A')
'A'
'A'
'A'
DROP TABLE t1;
select trim(null from 'kate') as "must_be_null"; select trim(null from 'kate') as "must_be_null";
must_be_null must_be_null
NULL NULL
......
...@@ -195,6 +195,17 @@ select trim(trailing 'foo' from 'foo'); ...@@ -195,6 +195,17 @@ select trim(trailing 'foo' from 'foo');
select trim(leading 'foo' from 'foo'); select trim(leading 'foo' from 'foo');
# #
# crashing bug with QUOTE() and LTRIM() or TRIM() fixed
# Bug #7495
#
select quote(ltrim(concat(' ', 'a')));
select quote(trim(concat(' ', 'a')));
# Bad results from QUOTE(). Bug #8248
CREATE TABLE t1 SELECT 1 UNION SELECT 2 UNION SELECT 3;
SELECT QUOTE('A') FROM t1;
DROP TABLE t1;
# Test collation and coercibility # Test collation and coercibility
# #
......
...@@ -2614,18 +2614,13 @@ String *Item_func_quote::val_str(String *str) ...@@ -2614,18 +2614,13 @@ String *Item_func_quote::val_str(String *str)
for (from= (char*) arg->ptr(), end= from + arg_length; from < end; from++) for (from= (char*) arg->ptr(), end= from + arg_length; from < end; from++)
new_length+= get_esc_bit(escmask, (uchar) *from); new_length+= get_esc_bit(escmask, (uchar) *from);
/* if (tmp_value.alloc(new_length))
We have to use realloc() instead of alloc() as we want to keep the
old result in arg
*/
if (arg->realloc(new_length))
goto null; goto null;
/* /*
As 'arg' and 'str' may be the same string, we must replace characters We replace characters from the end to the beginning
from the end to the beginning
*/ */
to= (char*) arg->ptr() + new_length - 1; to= (char*) tmp_value.ptr() + new_length - 1;
*to--= '\''; *to--= '\'';
for (start= (char*) arg->ptr(),end= start + arg_length; end-- != start; to--) for (start= (char*) arg->ptr(),end= start + arg_length; end-- != start; to--)
{ {
...@@ -2653,10 +2648,10 @@ String *Item_func_quote::val_str(String *str) ...@@ -2653,10 +2648,10 @@ String *Item_func_quote::val_str(String *str)
} }
} }
*to= '\''; *to= '\'';
arg->length(new_length); tmp_value.length(new_length);
str->set_charset(collation.collation); tmp_value.set_charset(collation.collation);
null_value= 0; null_value= 0;
return arg; return &tmp_value;
null: null:
null_value= 1; null_value= 1;
......
...@@ -588,6 +588,7 @@ class Item_func_inet_ntoa : public Item_str_func ...@@ -588,6 +588,7 @@ class Item_func_inet_ntoa : public Item_str_func
class Item_func_quote :public Item_str_func class Item_func_quote :public Item_str_func
{ {
String tmp_value;
public: public:
Item_func_quote(Item *a) :Item_str_func(a) {} Item_func_quote(Item *a) :Item_str_func(a) {}
const char *func_name() const { return "quote"; } const char *func_name() const { return "quote"; }
......
...@@ -660,6 +660,8 @@ static int check_connection(THD *thd) ...@@ -660,6 +660,8 @@ static int check_connection(THD *thd)
DBUG_PRINT("info", DBUG_PRINT("info",
("New connection received on %s", vio_description(net->vio))); ("New connection received on %s", vio_description(net->vio)));
vio_in_addr(net->vio,&thd->remote.sin_addr);
if (!thd->host) // If TCP/IP connection if (!thd->host) // If TCP/IP connection
{ {
char ip[30]; char ip[30];
...@@ -704,7 +706,6 @@ static int check_connection(THD *thd) ...@@ -704,7 +706,6 @@ static int check_connection(THD *thd)
DBUG_PRINT("info",("Host: %s",thd->host)); DBUG_PRINT("info",("Host: %s",thd->host));
thd->host_or_ip= thd->host; thd->host_or_ip= thd->host;
thd->ip= 0; thd->ip= 0;
bzero((char*) &thd->remote, sizeof(struct sockaddr));
} }
vio_keepalive(net->vio, TRUE); vio_keepalive(net->vio, TRUE);
ulong pkt_len= 0; ulong pkt_len= 0;
......
...@@ -276,7 +276,7 @@ void vio_in_addr(Vio *vio, struct in_addr *in) ...@@ -276,7 +276,7 @@ void vio_in_addr(Vio *vio, struct in_addr *in)
{ {
DBUG_ENTER("vio_in_addr"); DBUG_ENTER("vio_in_addr");
if (vio->localhost) if (vio->localhost)
bzero((char*) in, sizeof(*in)); /* This should never be executed */ bzero((char*) in, sizeof(*in));
else else
*in=vio->remote.sin_addr; *in=vio->remote.sin_addr;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
...@@ -259,7 +259,7 @@ void vio_ssl_in_addr(Vio *vio, struct in_addr *in) ...@@ -259,7 +259,7 @@ void vio_ssl_in_addr(Vio *vio, struct in_addr *in)
{ {
DBUG_ENTER("vio_ssl_in_addr"); DBUG_ENTER("vio_ssl_in_addr");
if (vio->localhost) if (vio->localhost)
bzero((char*) in, sizeof(*in)); /* This should never be executed */ bzero((char*) in, sizeof(*in));
else else
*in=vio->remote.sin_addr; *in=vio->remote.sin_addr;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
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