|
| 1 | +# |
| 2 | +# BUG#47863 |
| 3 | +# This test verifies if the session variable 'binlog_format' |
| 4 | +# is read-only inside a transaction and in sub-statements. |
| 5 | +# |
| 6 | + |
| 7 | +source include/have_innodb.inc; |
| 8 | +source include/have_binlog_format_row.inc; |
| 9 | + |
| 10 | +set @save_binlog_format= @@global.binlog_format; |
| 11 | +create table t1 (a int) engine= myisam; |
| 12 | +create table t2 (a int) engine= innodb; |
| 13 | + |
| 14 | +SELECT @@session.binlog_format; |
| 15 | +SET AUTOCOMMIT=1; |
| 16 | +--echo # Test that the session variable 'binlog_format' |
| 17 | +--echo # is writable outside a transaction. |
| 18 | +set @@session.binlog_format= statement; |
| 19 | +SELECT @@session.binlog_format; |
| 20 | + |
| 21 | +begin; |
| 22 | +--echo # Test that the session variable 'binlog_format' is read-only |
| 23 | +--echo # inside a transaction with no preceding updates. |
| 24 | +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT |
| 25 | + set @@session.binlog_format= mixed; |
| 26 | + |
| 27 | + insert into t2 values (1); |
| 28 | +--echo # Test that the session variable 'binlog_format' is read-only |
| 29 | +--echo # inside a transaction with preceding transactional updates. |
| 30 | +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT |
| 31 | + set @@session.binlog_format= row; |
| 32 | +commit; |
| 33 | + |
| 34 | +begin; |
| 35 | + insert into t1 values (2); |
| 36 | +--echo # Test that the session variable 'binlog_format' is read-only |
| 37 | +--echo # inside a transaction with preceding non-transactional updates. |
| 38 | +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT |
| 39 | + set @@session.binlog_format= statement; |
| 40 | +commit; |
| 41 | + |
| 42 | +--echo # Test that the session variable 'binlog_format' is writable |
| 43 | +--echo # when AUTOCOMMIT=0, before a transaction has started. |
| 44 | +set AUTOCOMMIT=0; |
| 45 | +set @@session.binlog_format= row; |
| 46 | +SELECT @@session.binlog_format; |
| 47 | + |
| 48 | +insert into t1 values (4); |
| 49 | +--echo # Test that the session variable 'binlog_format' is read-only inside an |
| 50 | +--echo # AUTOCOMMIT=0 transaction with preceding non-transactional updates. |
| 51 | +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT |
| 52 | +set @@session.binlog_format= statement; |
| 53 | +SELECT @@session.binlog_format; |
| 54 | +commit; |
| 55 | + |
| 56 | +insert into t2 values (5); |
| 57 | +--echo # Test that the session variable 'binlog_format' is read-only inside an |
| 58 | +--echo # AUTOCOMMIT=0 transaction with preceding transactional updates. |
| 59 | +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT |
| 60 | +set @@session.binlog_format= row; |
| 61 | +SELECT @@session.binlog_format; |
| 62 | +commit; |
| 63 | + |
| 64 | +begin; |
| 65 | + insert into t2 values (6); |
| 66 | +--echo # Test that the global variable 'binlog_format' is writable |
| 67 | +--echo # inside a transaction. |
| 68 | + SELECT @@global.binlog_format; |
| 69 | + set @@global.binlog_format= statement; |
| 70 | + SELECT @@global.binlog_format; |
| 71 | +commit; |
| 72 | + |
| 73 | +set @@global.binlog_format= @save_binlog_format; |
| 74 | + |
| 75 | +create table t3(a int, b int) engine= innodb; |
| 76 | +create table t4(a int) engine= innodb; |
| 77 | +create table t5(a int) engine= innodb; |
| 78 | +delimiter |; |
| 79 | +eval create trigger tr2 after insert on t3 for each row begin |
| 80 | + insert into t4(a) values(1); |
| 81 | + set @@session.binlog_format= statement; |
| 82 | + insert into t4(a) values(2); |
| 83 | + insert into t5(a) values(3); |
| 84 | +end | |
| 85 | +delimiter ;| |
| 86 | + |
| 87 | +--echo # Test that the session variable 'binlog_format' is read-only |
| 88 | +--echo # in sub-statements. |
| 89 | +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT |
| 90 | +insert into t3(a,b) values(1,1); |
| 91 | +SELECT @@session.binlog_format; |
| 92 | + |
| 93 | +drop table t1; |
| 94 | +drop table t2; |
| 95 | +drop table t3; |
| 96 | +drop table t4; |
| 97 | +drop table t5; |
| 98 | + |
0 commit comments