Commit 21479a6b authored by Alexander Barkov's avatar Alexander Barkov

MDEV-9524 Cannot load from mysql.event when sql_mode is set to PAD_CHAR_TO_FULL_LENGTH

The patch fixes the problem with loading information from system tables
(e.g. event and help related tables) when PAD_CHAR_TO_FULL_LENGTH is enabled,
as well as includes some additional minor improvements:
- refactoring in get_field() to return an error rather than success
  if strmake_root() failed
- removing of duplicate code in similar functions:
  char *get_field(MEM_ROOT *mem, Field *field)
  bool get_field(MEM_ROOT *mem, Field *field, String *res)
parent 69f1a321
...@@ -469,6 +469,26 @@ DROP EVENT ev1; ...@@ -469,6 +469,26 @@ DROP EVENT ev1;
SHOW EVENTS; SHOW EVENTS;
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
#
# MDEV-9524 Cannot load from mysql.event when sql_mode is set to PAD_CHAR_TO_FULL_LENGTH
#
CREATE TABLE t1 (a INT);
CREATE EVENT ev1 ON SCHEDULE EVERY 5 SECOND DO DELETE FROM t1;
SHOW EVENTS;
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
events_test ev1 root@localhost SYSTEM RECURRING NULL 5 # # NULL ENABLED 1 latin1 latin1_swedish_ci latin1_swedish_ci
SET sql_mode=PAD_CHAR_TO_FULL_LENGTH;
SHOW EVENTS;
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
events_test ev1 root@localhost SYSTEM RECURRING NULL 5 # # NULL ENABLED 1 latin1 latin1_swedish_ci latin1_swedish_ci
DROP EVENT ev1;
CREATE EVENT ev1 ON SCHEDULE EVERY 5 SECOND DO DELETE FROM t1;
SHOW EVENTS;
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
events_test ev1 root@localhost SYSTEM RECURRING NULL 5 # # NULL ENABLED 1 latin1 latin1_swedish_ci latin1_swedish_ci
DROP EVENT ev1;
DROP TABLE t1;
SET sql_mode=DEFAULT;
# #
# End of tests # End of tests
......
...@@ -148,6 +148,21 @@ help 'impossible_category_1'; ...@@ -148,6 +148,21 @@ help 'impossible_category_1';
source_category_name name is_it_category source_category_name name is_it_category
impossible_category_1 impossible_function_1 N impossible_category_1 impossible_function_1 N
impossible_category_1 impossible_function_2 N impossible_category_1 impossible_function_2 N
# MDEV-9524 Cannot load from mysql.event when sql_mode is set to PAD_CHAR_TO_FULL_LENGTH
help 'impossible_function_1';
name description example
impossible_function_1 description of
impossible_function1
example of
impossible_function1
SET sql_mode=PAD_CHAR_TO_FULL_LENGTH;
help 'impossible_function_1';
name description example
impossible_function_1 description of
impossible_function1
example of
impossible_function1
SET sql_mode=DEFAULT;
alter table mysql.help_relation engine=innodb; alter table mysql.help_relation engine=innodb;
alter table mysql.help_keyword engine=innodb; alter table mysql.help_keyword engine=innodb;
alter table mysql.help_topic engine=innodb; alter table mysql.help_topic engine=innodb;
......
...@@ -459,6 +459,25 @@ DROP EVENT ev1; ...@@ -459,6 +459,25 @@ DROP EVENT ev1;
SHOW EVENTS; SHOW EVENTS;
--echo #
--echo # MDEV-9524 Cannot load from mysql.event when sql_mode is set to PAD_CHAR_TO_FULL_LENGTH
--echo #
CREATE TABLE t1 (a INT);
CREATE EVENT ev1 ON SCHEDULE EVERY 5 SECOND DO DELETE FROM t1;
--replace_column 8 # 9 #
SHOW EVENTS;
SET sql_mode=PAD_CHAR_TO_FULL_LENGTH;
--replace_column 8 # 9 #
SHOW EVENTS;
DROP EVENT ev1;
CREATE EVENT ev1 ON SCHEDULE EVERY 5 SECOND DO DELETE FROM t1;
--replace_column 8 # 9 #
SHOW EVENTS;
DROP EVENT ev1;
DROP TABLE t1;
SET sql_mode=DEFAULT;
--echo --echo
--echo # --echo #
--echo # End of tests --echo # End of tests
......
...@@ -61,6 +61,12 @@ help '%function_7'; ...@@ -61,6 +61,12 @@ help '%function_7';
help '%category_2'; help '%category_2';
help 'impossible_function_1'; help 'impossible_function_1';
help 'impossible_category_1'; help 'impossible_category_1';
--echo # MDEV-9524 Cannot load from mysql.event when sql_mode is set to PAD_CHAR_TO_FULL_LENGTH
help 'impossible_function_1';
SET sql_mode=PAD_CHAR_TO_FULL_LENGTH;
help 'impossible_function_1';
SET sql_mode=DEFAULT;
############## ##############
--disable_warnings --disable_warnings
......
...@@ -647,7 +647,7 @@ SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen, ...@@ -647,7 +647,7 @@ SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen,
TRUE Error and send_error already commited TRUE Error and send_error already commited
*/ */
bool mysqld_help(THD *thd, const char *mask) static bool mysqld_help_internal(THD *thd, const char *mask)
{ {
Protocol *protocol= thd->protocol; Protocol *protocol= thd->protocol;
SQL_SELECT *select; SQL_SELECT *select;
...@@ -823,3 +823,12 @@ error2: ...@@ -823,3 +823,12 @@ error2:
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
bool mysqld_help(THD *thd, const char *mask)
{
ulonglong sql_mode_backup= thd->variables.sql_mode;
thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
bool rc= mysqld_help_internal(thd, mask);
thd->variables.sql_mode= sql_mode_backup;
return rc;
}
...@@ -3384,18 +3384,23 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res) ...@@ -3384,18 +3384,23 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res)
{ {
char buff[MAX_FIELD_WIDTH], *to; char buff[MAX_FIELD_WIDTH], *to;
String str(buff,sizeof(buff),&my_charset_bin); String str(buff,sizeof(buff),&my_charset_bin);
uint length; bool rc;
THD *thd= field->get_thd();
ulonglong sql_mode_backup= thd->variables.sql_mode;
thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
field->val_str(&str); field->val_str(&str);
if (!(length= str.length())) if ((rc= !str.length() ||
!(to= strmake_root(mem, str.ptr(), str.length()))))
{ {
res->length(0); res->length(0);
return 1; goto ex;
} }
if (!(to= strmake_root(mem, str.ptr(), length))) res->set(to, str.length(), field->charset());
length= 0; // Safety fix
res->set(to, length, field->charset()); ex:
return 0; thd->variables.sql_mode= sql_mode_backup;
return rc;
} }
...@@ -3414,17 +3419,10 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res) ...@@ -3414,17 +3419,10 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res)
char *get_field(MEM_ROOT *mem, Field *field) char *get_field(MEM_ROOT *mem, Field *field)
{ {
char buff[MAX_FIELD_WIDTH], *to; String str;
String str(buff,sizeof(buff),&my_charset_bin); bool rc= get_field(mem, field, &str);
uint length; DBUG_ASSERT(rc || str.ptr()[str.length()] == '\0');
return rc ? NullS : (char *) str.ptr();
field->val_str(&str);
length= str.length();
if (!length || !(to= (char*) alloc_root(mem,length+1)))
return NullS;
memcpy(to,str.ptr(),(uint) length);
to[length]=0;
return to;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment