Commit 613cbb62 authored by unknown's avatar unknown

func_str.result, func_str.test:

  Adding test case.
item_strfunc.cc:
  bug#11728 string function LEFT, strange undocumented behaviour
  Fixing LEFT and RIGHT return NULL if the second
  argument is NULL.


sql/item_strfunc.cc:
  bug#11728 string function LEFT, strange undocumented behaviour
  Fixing LEFT and RIGHT return NULL if the second
  argument is NULL.
mysql-test/t/func_str.test:
  Adding test case.
mysql-test/r/func_str.result:
  Adding test case.
parent 0b399f1d
...@@ -33,6 +33,9 @@ instr('hello','HE') instr('hello',binary 'HE') instr(binary 'hello','HE') ...@@ -33,6 +33,9 @@ instr('hello','HE') instr('hello',binary 'HE') instr(binary 'hello','HE')
select position(binary 'll' in 'hello'),position('a' in binary 'hello'); select position(binary 'll' in 'hello'),position('a' in binary 'hello');
position(binary 'll' in 'hello') position('a' in binary 'hello') position(binary 'll' in 'hello') position('a' in binary 'hello')
3 0 3 0
select left('hello',null), right('hello',null);
left('hello',null) right('hello',null)
NULL NULL
select left('hello',2),right('hello',2),substring('hello',2,2),mid('hello',1,5) ; select left('hello',2),right('hello',2),substring('hello',2,2),mid('hello',1,5) ;
left('hello',2) right('hello',2) substring('hello',2,2) mid('hello',1,5) left('hello',2) right('hello',2) substring('hello',2,2) mid('hello',1,5)
he lo el hello he lo el hello
......
...@@ -19,6 +19,11 @@ select hex(char(256)); ...@@ -19,6 +19,11 @@ select hex(char(256));
select locate('he','hello'),locate('he','hello',2),locate('lo','hello',2) ; select locate('he','hello'),locate('he','hello',2),locate('lo','hello',2) ;
select instr('hello','HE'), instr('hello',binary 'HE'), instr(binary 'hello','HE'); select instr('hello','HE'), instr('hello',binary 'HE'), instr(binary 'hello','HE');
select position(binary 'll' in 'hello'),position('a' in binary 'hello'); select position(binary 'll' in 'hello'),position('a' in binary 'hello');
#
# Bug#11728 string function LEFT,
# strange undocumented behaviour, strict mode
#
select left('hello',null), right('hello',null);
select left('hello',2),right('hello',2),substring('hello',2,2),mid('hello',1,5) ; select left('hello',2),right('hello',2),substring('hello',2,2),mid('hello',1,5) ;
select concat('',left(right(concat('what ',concat('is ','happening')),9),4),'',substring('monty',5,1)) ; select concat('',left(right(concat('what ',concat('is ','happening')),9),4),'',substring('monty',5,1)) ;
select substring_index('www.tcx.se','.',-2),substring_index('www.tcx.se','.',1); select substring_index('www.tcx.se','.',-2),substring_index('www.tcx.se','.',1);
......
...@@ -1038,7 +1038,7 @@ String *Item_func_left::val_str(String *str) ...@@ -1038,7 +1038,7 @@ String *Item_func_left::val_str(String *str)
long length =(long) args[1]->val_int(); long length =(long) args[1]->val_int();
uint char_pos; uint char_pos;
if ((null_value=args[0]->null_value)) if ((null_value=(args[0]->null_value || args[1]->null_value)))
return 0; return 0;
if (length <= 0) if (length <= 0)
return &my_empty_string; return &my_empty_string;
...@@ -1078,7 +1078,7 @@ String *Item_func_right::val_str(String *str) ...@@ -1078,7 +1078,7 @@ String *Item_func_right::val_str(String *str)
String *res =args[0]->val_str(str); String *res =args[0]->val_str(str);
long length =(long) args[1]->val_int(); long length =(long) args[1]->val_int();
if ((null_value=args[0]->null_value)) if ((null_value=(args[0]->null_value || args[1]->null_value)))
return 0; /* purecov: inspected */ return 0; /* purecov: inspected */
if (length <= 0) if (length <= 0)
return &my_empty_string; /* purecov: inspected */ return &my_empty_string; /* purecov: inspected */
......
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