Commit 63c9bb32 authored by Leonard Zhou's avatar Leonard Zhou

BUG#39526 sql_mode not retained in binary log for CREATE PROCEDURE

      
Set wrong sql_mode when creating a procedure. 
So that the sql_mode can't be writen into binary log correctly.
      
Restore the current session sql_mode right before generating the binlog event
when creating a procedure.

mysql-test/suite/binlog/r/binlog_sql_mode.result:
  Test result
mysql-test/suite/binlog/t/binlog_sql_mode.test:
  Test file for sql_mode testing
sql/sp.cc:
  Restore the current session sql_mode right before generating the binlog event.
parent d61f114f
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
SET @old_sql_mode= @@global.sql_mode;
SET @old_binlog_format=@@session.binlog_format;
SET SESSION sql_mode=8;
Initialization
RESET MASTER;
CREATE TABLE t1 (id INT);
CREATE PROCEDURE testProc() SELECT * FROM t1;
CREATE VIEW testView as SELECT * from t1;
CREATE FUNCTION testFunc()
RETURNS INT
BEGIN
return 1;
END;|
CREATE TRIGGER testTrig BEFORE INSERT ON t1
FOR EACH ROW BEGIN
UPDATE t1 SET id = id +1;
END;|
CREATE EVENT testEvent ON SCHEDULE
EVERY 1 DAY
DO
BEGIN
UPDATE t1 SET id = id +1;
END;|
Chceck Result
select
(@a:=load_file("MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug39526.binlog"))
is not null;
(@a:=load_file("MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug39526.binlog"))
is not null
1
*** String sql_mode=0 is found: 0 ***
Clean Up
DROP PROCEDURE testProc;
DROP FUNCTION testFunc;
DROP TRIGGER testTrig;
DROP EVENT testEvent;
DROP VIEW testView;
DROP TABLE t1;
SET @@global.sql_mode= @old_sql_mode;
SET @@session.binlog_format=@old_binlog_format;
# ==== Purpose ====
#
# Test that sql_mode can correct restore before generating the binlog event
# when creating CREATEable objects.
#
# ==== Method ====
#
# Scan binlog file to check if the sql_mode is still set to 0 before generating binlog event
#
-- source include/master-slave.inc
-- source include/have_log_bin.inc
# BUG#39526 sql_mode not retained in binary log for CREATE PROCEDURE
SET @old_sql_mode= @@global.sql_mode;
SET @old_binlog_format=@@session.binlog_format;
let $MYSQLD_DATADIR= `select @@datadir`;
SET SESSION sql_mode=8;
--echo Initialization
RESET MASTER;
CREATE TABLE t1 (id INT);
CREATE PROCEDURE testProc() SELECT * FROM t1;
CREATE VIEW testView as SELECT * from t1;
DELIMITER |;
CREATE FUNCTION testFunc()
RETURNS INT
BEGIN
return 1;
END;|
DELIMITER ;|
DELIMITER |;
CREATE TRIGGER testTrig BEFORE INSERT ON t1
FOR EACH ROW BEGIN
UPDATE t1 SET id = id +1;
END;|
DELIMITER ;|
DELIMITER |;
CREATE EVENT testEvent ON SCHEDULE
EVERY 1 DAY
DO
BEGIN
UPDATE t1 SET id = id +1;
END;|
DELIMITER ;|
--echo Chceck Result
let $MYSQLD_DATADIR= `select @@datadir`;
--exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug39526.binlog
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval select
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug39526.binlog"))
is not null;
let $s_mode_unsigned= `select @a like "%@@session.sql_mode=0%" /* must return 0 */`;
echo *** String sql_mode=0 is found: $s_mode_unsigned ***;
--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug39526.binlog
--echo Clean Up
DROP PROCEDURE testProc;
DROP FUNCTION testFunc;
DROP TRIGGER testTrig;
DROP EVENT testEvent;
DROP VIEW testView;
DROP TABLE t1;
SET @@global.sql_mode= @old_sql_mode;
SET @@session.binlog_format=@old_binlog_format;
......@@ -936,10 +936,12 @@ sp_create_routine(THD *thd, int type, sp_head *sp)
ret= SP_INTERNAL_ERROR;
goto done;
}
/* restore sql_mode when binloging */
thd->variables.sql_mode= saved_mode;
/* Such a statement can always go directly to binlog, no trans cache */
thd->binlog_query(THD::MYSQL_QUERY_TYPE,
log_query.c_ptr(), log_query.length(), FALSE, FALSE);
thd->variables.sql_mode= 0;
}
}
......
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