← Back to team overview

maria-developers team mailing list archive

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

 

Hello Sergei,

Please review a patch for mdev-9524.

Thanks.
diff --git a/mysql-test/r/events_1.result b/mysql-test/r/events_1.result
index e03ccf51..4e7ff52 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/t/events_1.test b/mysql-test/t/events_1.test
index bf5a356..250b0d0 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/sql/event_data_objects.cc b/sql/event_data_objects.cc
index 09256a3..45fca08 100644
--- a/sql/event_data_objects.cc
+++ b/sql/event_data_objects.cc
@@ -263,8 +263,17 @@ Event_basic::load_string_fields(Field **fields, ...)
       ret= TRUE;
       break;
     }
+    /*
+      TODO: add a get_field() version returning the result in
+      a LEX_STRING parameter.
+    */
     field_value->length= strlen(field_value->str);
 
+    // Trim trailing spaces, e.g. for MODE_PAD_CHAR_TO_FULL_LENGTH
+    CHARSET_INFO *cs= fields[field_name]->charset();
+    field_value->length= cs->cset->lengthsp(cs, field_value->str,
+                                                field_value->length);
+    field_value->str[field_value->length]= '\0';
     field_name= (enum enum_events_table_field) va_arg(args, int);
   }
   va_end(args);
diff --git a/sql/sp.cc b/sql/sp.cc
index 4b65f83..5883820 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -231,6 +231,7 @@ bool load_charset(MEM_ROOT *mem_root,
     return TRUE;
   }
 
+  cs_name.strip_sp(); // For MODE_PAD_CHAR_TO_FULL_LENGTH
   *cs= get_charset_by_csname(cs_name.c_ptr(), MY_CS_PRIMARY, MYF(0));
 
   if (*cs == NULL)
@@ -257,6 +258,7 @@ bool load_collation(MEM_ROOT *mem_root,
     return TRUE;
   }
 
+  cl_name.strip_sp(); // For MODE_PAD_CHAR_TO_FULL_LENGTH
   *cl= get_charset_by_name(cl_name.c_ptr(), MYF(0));
 
   if (*cl == NULL)

Follow ups