Commit 613cbb62 authored by unknown's avatar unknown
Browse files

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
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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');
position(binary 'll' in 'hello')	position('a' in binary 'hello')
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) ;
left('hello',2)	right('hello',2)	substring('hello',2,2)	mid('hello',1,5)
he	lo	el	hello
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,11 @@ select hex(char(256));
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 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 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);
+2 −2
Original line number Diff line number Diff line
@@ -1038,7 +1038,7 @@ String *Item_func_left::val_str(String *str)
  long length  =(long) args[1]->val_int();
  uint char_pos;

  if ((null_value=args[0]->null_value))
  if ((null_value=(args[0]->null_value || args[1]->null_value)))
    return 0;
  if (length <= 0)
    return &my_empty_string;
@@ -1078,7 +1078,7 @@ String *Item_func_right::val_str(String *str)
  String *res  =args[0]->val_str(str);
  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 */
  if (length <= 0)
    return &my_empty_string; /* purecov: inspected */