diff options
author | unknown <timour@mysql.com> | 2004-12-28 11:57:56 +0200 |
---|---|---|
committer | unknown <timour@mysql.com> | 2004-12-28 11:57:56 +0200 |
commit | 8487aa5abc384de074681f71e67a8b7b0570baf2 (patch) | |
tree | ef1944be254fd19762ac926af21196cbee1448d9 | |
parent | 47efc5f335d117cd0fbe3d1e633936ae70442933 (diff) | |
download | mariadb-git-8487aa5abc384de074681f71e67a8b7b0570baf2.tar.gz |
Fix for BUG#7455.
The fix checks if the trim string argument is NULL. If so, the standard
mandates that the function result must be also NULL.
mysql-test/r/func_str.result:
added test result
mysql-test/t/func_str.test:
Added test for NULL arguments.
sql/item_strfunc.cc:
Test if the trim argument is NULL.
-rw-r--r-- | mysql-test/r/func_str.result | 6 | ||||
-rw-r--r-- | mysql-test/t/func_str.test | 8 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 11 |
3 files changed, 24 insertions, 1 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 1c560dfa8b4..8348ef12b0d 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -697,3 +697,9 @@ quote(ltrim(concat(' ', 'a'))) select quote(trim(concat(' ', 'a'))); quote(trim(concat(' ', 'a'))) 'a' +select trim(null from 'kate') as "must_be_null"; +must_be_null +NULL +select trim('xyz' from null) as "must_be_null"; +must_be_null +NULL diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 5477a0ccb30..a5d95332caa 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -435,3 +435,11 @@ drop table t1; select quote(ltrim(concat(' ', 'a'))); select quote(trim(concat(' ', 'a'))); + +# +# Bug#7455 unexpected result: TRIM(<NULL> FROM <whatever>) gives NOT NULL +# According to ANSI if one of the TRIM arguments is NULL, then the result +# must be NULL too. +# +select trim(null from 'kate') as "must_be_null"; +select trim('xyz' from null) as "must_be_null"; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 068878652e4..2a63c5355a4 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1302,9 +1302,18 @@ String *Item_func_trim::val_str(String *str) return 0; /* purecov: inspected */ char buff[MAX_FIELD_WIDTH]; String tmp(buff,sizeof(buff),res->charset()); - String *remove_str= (arg_count==2) ? args[1]->val_str(&tmp) : &remove; uint remove_length; LINT_INIT(remove_length); + String *remove_str; /* The string to remove from res. */ + + if (arg_count == 2) + { + remove_str= args[1]->val_str(&tmp); + if ((null_value= args[1]->null_value)) + return 0; + } + else + remove_str= &remove; /* Default value. */ if (!remove_str || (remove_length=remove_str->length()) == 0 || remove_length > res->length()) |