summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2018-06-21 12:54:28 +0400
committerAlexander Barkov <bar@mariadb.com>2018-06-21 12:54:28 +0400
commitbcc2100f9d0bd1a2c21acd0de831e9dd1b8a703e (patch)
treea2e91e854ce56a86fca49481a63f424ad47d97ac
parent9dc81f7d387050dd62f2307b15c63c3a3f5ea1b0 (diff)
downloadmariadb-git-bcc2100f9d0bd1a2c21acd0de831e9dd1b8a703e.tar.gz
MDEV-16471 mysqldump throws "Variable 'sql_mode' can't be set to the value of 'NULL' (1231)"
-rw-r--r--mysql-test/main/sql_mode.result24
-rw-r--r--mysql-test/main/sql_mode.test23
-rw-r--r--sql/item.cc13
-rw-r--r--sql/item.h8
-rw-r--r--sql/sys_vars.ic3
5 files changed, 69 insertions, 2 deletions
diff --git a/mysql-test/main/sql_mode.result b/mysql-test/main/sql_mode.result
index 02574c1c545..238bae2efd8 100644
--- a/mysql-test/main/sql_mode.result
+++ b/mysql-test/main/sql_mode.result
@@ -780,3 +780,27 @@ END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'error;
END' at line 4
+#
+# End of 10.2 tests
+#
+#
+# Start of 10.3 tests
+#
+#
+# MDEV-16471 mysqldump throws "Variable 'sql_mode' can't be set to the value of 'NULL' (1231)"
+#
+SET sql_mode='ORACLE,EMPTY_STRING_IS_NULL';
+SELECT @@sql_mode;
+@@sql_mode
+PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,EMPTY_STRING_IS_NULL,SIMULTANEOUS_ASSIGNMENT
+SELECT '' AS empty;
+empty
+NULL
+SET sql_mode='';
+SELECT @@sql_mode;
+@@sql_mode
+
+SET sql_mode=DEFAULT;
+#
+# End of 10.3 tests
+#
diff --git a/mysql-test/main/sql_mode.test b/mysql-test/main/sql_mode.test
index 9f38dc935e7..8cf50f73f6f 100644
--- a/mysql-test/main/sql_mode.test
+++ b/mysql-test/main/sql_mode.test
@@ -554,3 +554,26 @@ BEGIN
END;
$$
DELIMITER ;$$
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
+
+--echo #
+--echo # Start of 10.3 tests
+--echo #
+
+--echo #
+--echo # MDEV-16471 mysqldump throws "Variable 'sql_mode' can't be set to the value of 'NULL' (1231)"
+--echo #
+
+SET sql_mode='ORACLE,EMPTY_STRING_IS_NULL';
+SELECT @@sql_mode;
+SELECT '' AS empty;
+SET sql_mode='';
+SELECT @@sql_mode;
+SET sql_mode=DEFAULT;
+
+--echo #
+--echo # End of 10.3 tests
+--echo #
diff --git a/sql/item.cc b/sql/item.cc
index 65a9fdf46c5..11ef4e3a457 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -202,6 +202,19 @@ String *Item::val_str_ascii(String *str)
}
+String *Item::val_str_ascii_revert_empty_string_is_null(THD *thd, String *str)
+{
+ String *res= val_str_ascii(str);
+ if (!res && (thd->variables.sql_mode & MODE_EMPTY_STRING_IS_NULL))
+ {
+ null_value= false;
+ str->set("", 0, &my_charset_latin1);
+ return str;
+ }
+ return res;
+}
+
+
String *Item::val_str(String *str, String *converter, CHARSET_INFO *cs)
{
String *res= val_str(str);
diff --git a/sql/item.h b/sql/item.h
index 0ee60afb3be..3607f5f9bbd 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1171,7 +1171,13 @@ public:
Similar to val_str()
*/
virtual String *val_str_ascii(String *str);
-
+
+ /*
+ Returns the result of val_str_ascii(), translating NULLs back
+ to empty strings (if MODE_EMPTY_STRING_IS_NULL is set).
+ */
+ String *val_str_ascii_revert_empty_string_is_null(THD *thd, String *str);
+
/*
Returns the val_str() value converted to the given character set.
*/
diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic
index 498204deb92..c0b7950518b 100644
--- a/sql/sys_vars.ic
+++ b/sql/sys_vars.ic
@@ -1354,7 +1354,8 @@ public:
if (var->value->result_type() == STRING_RESULT)
{
- if (!(res=var->value->val_str_ascii(&str)))
+ if (!(res= var->value->val_str_ascii_revert_empty_string_is_null(thd,
+ &str)))
return true;
else
{