diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 21a869cb9c560161edf8cc09565691baffe579f7..8243b2bc015a92183baef98bfee96f68fa877748 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -1742,25 +1742,13 @@ NULL Warnings: Error 1300 Invalid utf8 character string: 'FF' select hex(_utf8 0x616263FF); -hex(_utf8 0x616263FF) -NULL -Warnings: -Error 1300 Invalid utf8 character string: 'FF' +ERROR HY000: Invalid utf8 character string: 'FF' select hex(_utf8 X'616263FF'); -hex(_utf8 X'616263FF') -NULL -Warnings: -Error 1300 Invalid utf8 character string: 'FF' +ERROR HY000: Invalid utf8 character string: 'FF' select hex(_utf8 B'001111111111'); -hex(_utf8 B'001111111111') -NULL -Warnings: -Error 1300 Invalid utf8 character string: 'FF' +ERROR HY000: Invalid utf8 character string: 'FF' select (_utf8 X'616263FF'); -(_utf8 X'616263FF') -NULL -Warnings: -Error 1300 Invalid utf8 character string: 'FF' +ERROR HY000: Invalid utf8 character string: 'FF' set sql_mode=default; select hex(char(0xFF using utf8)); hex(char(0xFF using utf8)) @@ -1773,22 +1761,10 @@ hex(convert(0xFF using utf8)) Warnings: Warning 1300 Invalid utf8 character string: 'FF' select hex(_utf8 0x616263FF); -hex(_utf8 0x616263FF) -616263 -Warnings: -Warning 1300 Invalid utf8 character string: 'FF' +ERROR HY000: Invalid utf8 character string: 'FF' select hex(_utf8 X'616263FF'); -hex(_utf8 X'616263FF') -616263 -Warnings: -Warning 1300 Invalid utf8 character string: 'FF' +ERROR HY000: Invalid utf8 character string: 'FF' select hex(_utf8 B'001111111111'); -hex(_utf8 B'001111111111') -03 -Warnings: -Warning 1300 Invalid utf8 character string: 'FF' +ERROR HY000: Invalid utf8 character string: 'FF' select (_utf8 X'616263FF'); -(_utf8 X'616263FF') -abc -Warnings: -Warning 1300 Invalid utf8 character string: 'FF' +ERROR HY000: Invalid utf8 character string: 'FF' diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index b8aa6ac155e3d0833f38dbba0a3b9578d478daca..5c35bf82343f1eb8c538494f90749f8eef1581f2 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -1412,14 +1412,22 @@ DROP TABLE t1, t2; set sql_mode=traditional; select hex(char(0xFF using utf8)); select hex(convert(0xFF using utf8)); +--error ER_INVALID_CHARACTER_STRING select hex(_utf8 0x616263FF); +--error ER_INVALID_CHARACTER_STRING select hex(_utf8 X'616263FF'); +--error ER_INVALID_CHARACTER_STRING select hex(_utf8 B'001111111111'); +--error ER_INVALID_CHARACTER_STRING select (_utf8 X'616263FF'); set sql_mode=default; select hex(char(0xFF using utf8)); select hex(convert(0xFF using utf8)); +--error ER_INVALID_CHARACTER_STRING select hex(_utf8 0x616263FF); +--error ER_INVALID_CHARACTER_STRING select hex(_utf8 X'616263FF'); +--error ER_INVALID_CHARACTER_STRING select hex(_utf8 B'001111111111'); +--error ER_INVALID_CHARACTER_STRING select (_utf8 X'616263FF'); diff --git a/sql/item.cc b/sql/item.cc index 9c2130f237b1da185199b01bd4bab3d778ce3311..6fe1fbd62e2e88fa9aff5368aa1ed83279387b81 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4313,7 +4313,7 @@ bool Item::is_datetime() } -String *Item::check_well_formed_result(String *str) +String *Item::check_well_formed_result(String *str, bool send_error) { /* Check whether we got a well-formed string */ CHARSET_INFO *cs= str->charset(); @@ -4329,8 +4329,14 @@ String *Item::check_well_formed_result(String *str) uint diff= str->length() - wlen; set_if_smaller(diff, 3); octet2hex(hexbuf, str->ptr() + wlen, diff); - if (thd->variables.sql_mode & - (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)) + if (send_error) + { + my_error(ER_INVALID_CHARACTER_STRING, MYF(0), + cs->csname, hexbuf); + return 0; + } + if ((thd->variables.sql_mode & + (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES))) { level= MYSQL_ERROR::WARN_LEVEL_ERROR; null_value= 1; diff --git a/sql/item.h b/sql/item.h index 9cf9076d69dc2304dbac683e2647d05b9c1174da..38dd0599a35c2220ff16863f299059d61a7f192b 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1003,7 +1003,7 @@ public: bool is_datetime(); virtual Field::geometry_type get_geometry_type() const { return Field::GEOM_GEOMETRY; }; - String *check_well_formed_result(String *str); + String *check_well_formed_result(String *str, bool send_error= 0); }; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index adf14228e754ed5549756082cd31da3a23f3d988..ce64323464f98f6c171123956a03e64bf55e4d6a 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9935,15 +9935,11 @@ literal: str ? str->ptr() : "", str ? str->length() : 0, $1); - if ($$) + if (!$$ || !$$->check_well_formed_result(&$$->str_value, TRUE)) { - ((Item_string *) $$)->set_repertoire_from_value(); - if (!$$->check_well_formed_result(&$$->str_value)) - { - $$= new Item_null(); - $$->set_name(NULL, 0, system_charset_info); - } + MYSQL_YYABORT; } + ((Item_string *) $$)->set_repertoire_from_value(); } | UNDERSCORE_CHARSET BIN_NUM { @@ -9959,10 +9955,9 @@ literal: str ? str->ptr() : "", str ? str->length() : 0, $1); - if ($$ && !$$->check_well_formed_result(&$$->str_value)) + if (!$$ || !$$->check_well_formed_result(&$$->str_value, TRUE)) { - $$= new Item_null(); - $$->set_name(NULL, 0, system_charset_info); + MYSQL_YYABORT; } } | DATE_SYM text_literal { $$ = $2; }