List:Commits« Previous MessageNext Message »
From:Leonard Zhou Date:February 28 2009 1:36am
Subject:bzr commit into mysql-5.1-bugteam branch (leonard:2825) Bug#39526
View as plain text  
#At file:///home/zhl/mysql/rep/5.1/bug39526/

 2825 Leonard Zhou	2009-02-28
      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.
added:
  mysql-test/suite/binlog/r/binlog_sql_mode.result
  mysql-test/suite/binlog/t/binlog_sql_mode.test
modified:
  sql/sp.cc

per-file messages:
  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.
=== added file 'mysql-test/suite/binlog/r/binlog_sql_mode.result'
--- a/mysql-test/suite/binlog/r/binlog_sql_mode.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_sql_mode.result	2009-02-28 01:35:18 +0000
@@ -0,0 +1,46 @@
+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;

=== added file 'mysql-test/suite/binlog/t/binlog_sql_mode.test'
--- a/mysql-test/suite/binlog/t/binlog_sql_mode.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_sql_mode.test	2009-02-28 01:35:18 +0000
@@ -0,0 +1,76 @@
+# ==== 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;

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2008-07-15 01:43:12 +0000
+++ b/sql/sp.cc	2009-02-28 01:35:18 +0000
@@ -936,10 +936,12 @@ sp_create_routine(THD *thd, int type, 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;
     }
 
   }

Thread
bzr commit into mysql-5.1-bugteam branch (leonard:2825) Bug#39526Leonard Zhou2 Mar