summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2016-06-21 21:26:31 +0400
committerAlexander Barkov <bar@mariadb.org>2016-06-21 21:26:31 +0400
commit21479a6bb3cc37ffa1fb4f53a0ab71d22c7ad445 (patch)
tree1e2905aa5c6df07103c0f2e09e70f12b02796ad8
parent69f1a3215e5062eb6c06ed35ec38e1d824efbef6 (diff)
downloadmariadb-git-21479a6bb3cc37ffa1fb4f53a0ab71d22c7ad445.tar.gz
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)
-rw-r--r--mysql-test/r/events_1.result20
-rw-r--r--mysql-test/r/help.result15
-rw-r--r--mysql-test/t/events_1.test19
-rw-r--r--mysql-test/t/help.test6
-rw-r--r--sql/sql_help.cc11
-rw-r--r--sql/table.cc34
6 files changed, 86 insertions, 19 deletions
diff --git a/mysql-test/r/events_1.result b/mysql-test/r/events_1.result
index e03ccf51d8b..4e7ff526eca 100644
--- a/mysql-test/r/events_1.result
+++ b/mysql-test/r/events_1.result
@@ -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
diff --git a/mysql-test/r/help.result b/mysql-test/r/help.result
index 16719cc8193..319a1ba3e85 100644
--- a/mysql-test/r/help.result
+++ b/mysql-test/r/help.result
@@ -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;
diff --git a/mysql-test/t/events_1.test b/mysql-test/t/events_1.test
index bf5a356cee3..250b0d004dc 100644
--- a/mysql-test/t/events_1.test
+++ b/mysql-test/t/events_1.test
@@ -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
diff --git a/mysql-test/t/help.test b/mysql-test/t/help.test
index 71821e46771..881299a216c 100644
--- a/mysql-test/t/help.test
+++ b/mysql-test/t/help.test
@@ -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
diff --git a/sql/sql_help.cc b/sql/sql_help.cc
index afeb9395a55..f509d8b8f99 100644
--- a/sql/sql_help.cc
+++ b/sql/sql_help.cc
@@ -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;
+}
diff --git a/sql/table.cc b/sql/table.cc
index 5dae23116cc..e357d508e9e 100644
--- a/sql/table.cc
+++ b/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();
}
/*