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)
This commit is contained in:
parent
69f1a3215e
commit
21479a6bb3
@ -469,6 +469,26 @@ DROP EVENT ev1;
|
||||
|
||||
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
|
||||
#
|
||||
# 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
|
||||
|
@ -148,6 +148,21 @@ help 'impossible_category_1';
|
||||
source_category_name name is_it_category
|
||||
impossible_category_1 impossible_function_1 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_keyword engine=innodb;
|
||||
alter table mysql.help_topic engine=innodb;
|
||||
|
@ -459,6 +459,25 @@ DROP EVENT ev1;
|
||||
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 # End of tests
|
||||
|
@ -61,6 +61,12 @@ help '%function_7';
|
||||
help '%category_2';
|
||||
help 'impossible_function_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
|
||||
|
@ -647,7 +647,7 @@ SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen,
|
||||
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;
|
||||
SQL_SELECT *select;
|
||||
@ -823,3 +823,12 @@ error2:
|
||||
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;
|
||||
}
|
||||
|
34
sql/table.cc
34
sql/table.cc
@ -3384,18 +3384,23 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res)
|
||||
{
|
||||
char buff[MAX_FIELD_WIDTH], *to;
|
||||
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);
|
||||
if (!(length= str.length()))
|
||||
if ((rc= !str.length() ||
|
||||
!(to= strmake_root(mem, str.ptr(), str.length()))))
|
||||
{
|
||||
res->length(0);
|
||||
return 1;
|
||||
goto ex;
|
||||
}
|
||||
if (!(to= strmake_root(mem, str.ptr(), length)))
|
||||
length= 0; // Safety fix
|
||||
res->set(to, length, field->charset());
|
||||
return 0;
|
||||
res->set(to, str.length(), field->charset());
|
||||
|
||||
ex:
|
||||
thd->variables.sql_mode= sql_mode_backup;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@ -3414,17 +3419,10 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res)
|
||||
|
||||
char *get_field(MEM_ROOT *mem, Field *field)
|
||||
{
|
||||
char buff[MAX_FIELD_WIDTH], *to;
|
||||
String str(buff,sizeof(buff),&my_charset_bin);
|
||||
uint length;
|
||||
|
||||
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;
|
||||
String str;
|
||||
bool rc= get_field(mem, field, &str);
|
||||
DBUG_ASSERT(rc || str.ptr()[str.length()] == '\0');
|
||||
return rc ? NullS : (char *) str.ptr();
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user