summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <ram@gw.mysql.r18.ru>2004-11-11 18:20:40 +0400
committerunknown <ram@gw.mysql.r18.ru>2004-11-11 18:20:40 +0400
commitbaf1c89e3d66bd4d66555b3662d522adbabca505 (patch)
tree6b57f72f8cff40c685e9fb23d0a866ab7a2af6c5
parentce62fb28c0d101ecf1971f388dcdfce1b3145158 (diff)
downloadmariadb-git-baf1c89e3d66bd4d66555b3662d522adbabca505.tar.gz
A fix (bug #6564: QUOTE(NULL) returns NULL, not the string 'NULL')
-rw-r--r--mysql-test/r/func_str.result5
-rw-r--r--mysql-test/t/func_str.test6
-rw-r--r--sql/item_strfunc.cc14
3 files changed, 21 insertions, 4 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result
index b4d1be5bd54..d38a2edfa1a 100644
--- a/mysql-test/r/func_str.result
+++ b/mysql-test/r/func_str.result
@@ -167,6 +167,9 @@ length(quote(concat(char(0),"test")))
select hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235))));
hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235))))
27E0E3E6E7E8EAEB27
+select concat('a', quote(NULL));
+concat('a', quote(NULL))
+aNULL
select reverse("");
reverse("")
@@ -278,7 +281,7 @@ insert into t1 values ('one'),(NULL),('two'),('four');
select a, quote(a), isnull(quote(a)), quote(a) is null, ifnull(quote(a), 'n') from t1;
a quote(a) isnull(quote(a)) quote(a) is null ifnull(quote(a), 'n')
one 'one' 0 0 'one'
-NULL NULL 1 1 n
+NULL NULL 0 0 NULL
two 'two' 0 0 'two'
four 'four' 0 0 'four'
drop table t1;
diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test
index ba6a8b55236..1ae4db3a42a 100644
--- a/mysql-test/t/func_str.test
+++ b/mysql-test/t/func_str.test
@@ -70,6 +70,12 @@ select length(quote(concat(char(0),"test")));
select hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235))));
#
+# Bug #6564: QUOTE(NULL
+#
+
+select concat('a', quote(NULL));
+
+#
# Wrong usage of functions
#
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 9248cbc0217..53a9d3fe219 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2142,9 +2142,12 @@ String* Item_func_inet_ntoa::val_str(String* str)
This function is very useful when you want to generate SQL statements
- RETURN VALUES
+ NOTE
+ QUOTE(NULL) returns the string 'NULL' (4 letters, without quotes).
+
+ RETURN VALUES
str Quoted string
- NULL Argument to QUOTE() was NULL or out of memory.
+ NULL Out of memory.
*/
#define get_esc_bit(mask, num) (1 & (*((mask) + ((num) >> 3))) >> ((num) & 7))
@@ -2168,7 +2171,12 @@ String *Item_func_quote::val_str(String *str)
String *arg= args[0]->val_str(str);
uint arg_length, new_length;
if (!arg) // Null argument
- goto null;
+ {
+ str->copy("NULL", 4); // Return the string 'NULL'
+ null_value= 0;
+ return str;
+ }
+
arg_length= arg->length();
new_length= arg_length+2; /* for beginning and ending ' signs */