Commit cba001b7 authored by unknown's avatar unknown

Merge olga.mysql.com:/home/igor/mysql-4.1-opt

into  olga.mysql.com:/home/igor/mysql-5.0-opt


mysql-test/r/func_str.result:
  Auto merged
mysql-test/t/func_str.test:
  Auto merged
sql/item.h:
  Auto merged
sql/item_strfunc.cc:
  Auto merged
sql/item_strfunc.h:
  Auto merged
parents 665d46e1 8cb368bc
...@@ -1038,6 +1038,21 @@ select * from t1 where f1='test' and (f2= sha("TEST") or f2= sha("test")); ...@@ -1038,6 +1038,21 @@ select * from t1 where f1='test' and (f2= sha("TEST") or f2= sha("test"));
f1 f2 f1 f2
test a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 test a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
drop table t1; drop table t1;
CREATE TABLE t1 (a varchar(10));
INSERT INTO t1 VALUES ('abc'), ('xyz');
SELECT a, CONCAT(a,' ',a) AS c FROM t1
HAVING LEFT(c,LENGTH(c)-INSTR(REVERSE(c)," ")) = a;
a c
abc abc abc
xyz xyz xyz
SELECT a, CONCAT(a,' ',a) AS c FROM t1
HAVING LEFT(CONCAT(a,' ',a),
LENGTH(CONCAT(a,' ',a))-
INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a;
a c
abc abc abc
xyz xyz xyz
DROP TABLE t1;
End of 4.1 tests End of 4.1 tests
create table t1 (d decimal default null); create table t1 (d decimal default null);
insert into t1 values (null); insert into t1 values (null);
......
...@@ -685,6 +685,23 @@ select * from t1 where f1='test' and (f2= sha("test") or f2= sha("TEST")); ...@@ -685,6 +685,23 @@ select * from t1 where f1='test' and (f2= sha("test") or f2= sha("TEST"));
select * from t1 where f1='test' and (f2= sha("TEST") or f2= sha("test")); select * from t1 where f1='test' and (f2= sha("TEST") or f2= sha("test"));
drop table t1; drop table t1;
#
# Bug#18243: REVERSE changes its argument
#
CREATE TABLE t1 (a varchar(10));
INSERT INTO t1 VALUES ('abc'), ('xyz');
SELECT a, CONCAT(a,' ',a) AS c FROM t1
HAVING LEFT(c,LENGTH(c)-INSTR(REVERSE(c)," ")) = a;
SELECT a, CONCAT(a,' ',a) AS c FROM t1
HAVING LEFT(CONCAT(a,' ',a),
LENGTH(CONCAT(a,' ',a))-
INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a;
DROP TABLE t1;
--echo End of 4.1 tests --echo End of 4.1 tests
# #
......
...@@ -697,9 +697,16 @@ class Item { ...@@ -697,9 +697,16 @@ class Item {
Any new item which can be NULL must implement this call. Any new item which can be NULL must implement this call.
*/ */
virtual bool is_null() { return 0; } virtual bool is_null() { return 0; }
/* /*
it is "top level" item of WHERE clause and we do not need correct NULL Inform the item that there will be no distinction between its result
handling being FALSE or NULL.
NOTE
This function will be called for eg. Items that are top-level AND-parts
of the WHERE clause. Items implementing this function (currently
Item_cond_and and subquery-related item) enable special optimizations
when they are "top level".
*/ */
virtual void top_level_item() {} virtual void top_level_item() {}
/* /*
......
...@@ -752,44 +752,47 @@ String *Item_func_reverse::val_str(String *str) ...@@ -752,44 +752,47 @@ String *Item_func_reverse::val_str(String *str)
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
String *res = args[0]->val_str(str); String *res = args[0]->val_str(str);
char *ptr,*end; char *ptr, *end, *tmp;
if ((null_value=args[0]->null_value)) if ((null_value=args[0]->null_value))
return 0; return 0;
/* An empty string is a special case as the string pointer may be null */ /* An empty string is a special case as the string pointer may be null */
if (!res->length()) if (!res->length())
return &my_empty_string; return &my_empty_string;
res=copy_if_not_alloced(str,res,res->length()); if (tmp_value.alloced_length() < res->length() &&
ptr = (char *) res->ptr(); tmp_value.realloc(res->length()))
end=ptr+res->length(); {
null_value= 1;
return 0;
}
tmp_value.length(res->length());
tmp_value.set_charset(res->charset());
ptr= (char *) res->ptr();
end= ptr + res->length();
tmp= (char *) tmp_value.ptr() + tmp_value.length();
#ifdef USE_MB #ifdef USE_MB
if (use_mb(res->charset())) if (use_mb(res->charset()))
{ {
String tmpstr;
tmpstr.copy(*res);
char *tmp = (char *) tmpstr.ptr() + tmpstr.length();
register uint32 l; register uint32 l;
while (ptr < end) while (ptr < end)
{ {
if ((l=my_ismbchar(res->charset(), ptr,end))) if ((l= my_ismbchar(res->charset(),ptr,end)))
tmp-=l, memcpy(tmp,ptr,l), ptr+=l; {
tmp-= l;
memcpy(tmp,ptr,l);
ptr+= l;
}
else else
*--tmp=*ptr++; *--tmp= *ptr++;
} }
memcpy((char *) res->ptr(),(char *) tmpstr.ptr(), res->length());
} }
else else
#endif /* USE_MB */ #endif /* USE_MB */
{ {
char tmp;
while (ptr < end) while (ptr < end)
{ *--tmp= *ptr++;
tmp=*ptr;
*ptr++=*--end;
*end=tmp;
}
} }
return res; return &tmp_value;
} }
......
...@@ -102,6 +102,7 @@ class Item_func_concat_ws :public Item_str_func ...@@ -102,6 +102,7 @@ class Item_func_concat_ws :public Item_str_func
class Item_func_reverse :public Item_str_func class Item_func_reverse :public Item_str_func
{ {
String tmp_value;
public: public:
Item_func_reverse(Item *a) :Item_str_func(a) {} Item_func_reverse(Item *a) :Item_str_func(a) {}
String *val_str(String *); String *val_str(String *);
......
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