1# This test case verifies that the mysqlbinlog --base64-output=X flags
2# work as expected, and that BINLOG statements with row events fail if
3# they are not preceded by BINLOG statements with Format description
4# events.
5#
6# See also BUG#32407.
7
8
9# BINLOG statement does not work in embedded mode.
10source include/not_embedded.inc;
11
12disable_warnings;
13DROP TABLE IF EXISTS t1;
14enable_warnings;
15
16# Test to show BUG#32407.  This reads a binlog created with the
17# mysql-5.1-telco-6.1 tree, specifically at the tag
18# mysql-5.1.15-ndb-6.1.23, and applies it to the database.  The test
19# should fail before BUG#32407 was fixed and succeed afterwards.
20--echo ==== Test BUG#32407 ====
21
22# The binlog contains row events equivalent to:
23# CREATE TABLE t1 (a int) engine = myisam
24# INSERT INTO t1 VALUES (1), (1)
25exec $MYSQL_BINLOG suite/binlog/std_data/bug32407.001 | $MYSQL;
26# The above line should succeed and t1 should contain two ones
27select * from t1;
28
29
30# Test that a BINLOG statement encoding a row event fails unless a
31# Format_description_event as been supplied with an earlier BINLOG
32# statement.
33--echo ==== Test BINLOG statement w/o FD event ====
34
35# This is a binlog statement consisting of one Table_map_log_event and
36# one Write_rows_log_event.  Together, they correspond to the
37# following query:
38# INSERT INTO TABLE test.t1 VALUES (2)
39
40error ER_NO_FORMAT_DESCRIPTION_EVENT_BEFORE_BINLOG_STATEMENT;
41BINLOG '
42SVtYRxMBAAAAKQAAADQBAAAAABAAAAAAAAAABHRlc3QAAnQxAAEDAAE=
43SVtYRxcBAAAAIgAAAFYBAAAQABAAAAAAAAEAAf/+AgAAAA==
44';
45# The above line should fail and 2 should not be in the table
46select * from t1;
47
48
49# Test that it works to read a Format_description_log_event with a
50# BINLOG statement, followed by a row-event in base64 from the same
51# version.
52--echo ==== Test BINLOG statement with FD event ====
53
54# This is a binlog statement containing a Format_description_log_event
55# from the same version as the Table_map and Write_rows_log_event.
56BINLOG '
57ODdYRw8BAAAAZgAAAGoAAAABAAQANS4xLjIzLXJjLWRlYnVnLWxvZwAAAAAAAAAAAAAAAAAAAAAA
58AAAAAAAAAAAAAAAAAAA4N1hHEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC
59';
60
61# This is a Table_map_log_event+Write_rows_log_event corresponding to:
62# INSERT INTO TABLE test.t1 VALUES (3)
63BINLOG '
64TFtYRxMBAAAAKQAAAH8BAAAAABAAAAAAAAAABHRlc3QAAnQxAAEDAAE=
65TFtYRxcBAAAAIgAAAKEBAAAQABAAAAAAAAEAAf/+AwAAAA==
66';
67# The above line should succeed and 3 should be in the table
68select * from t1;
69
70
71# Test that mysqlbinlog stops with an error message when the
72# --base64-output=never flag is used on a binlog with base64 events.
73--echo ==== Test --base64-output=never on a binlog with row events ====
74
75# mysqlbinlog should fail
76--replace_regex /#[0-9][0-9][0-9][0-9][0-9][0-9] .*/<#>/   /SET \@\@session.pseudo_thread_id.*/<#>/
77error 1;
78exec $MYSQL_BINLOG --base64-output=never suite/binlog/std_data/bug32407.001;
79# the above line should output the query log event and then stop
80
81
82# Test that the following fails cleanly: "First, read a
83# Format_description event which has N event types. Then, read an
84# event of type M>N"
85--echo ==== Test non-matching FD event and Row event ====
86
87# This is the Format_description_log_event from
88# bug32407.001, encoded in base64. It contains only the old
89# row events (number of event types is 22)
90BINLOG '
914CdYRw8BAAAAYgAAAGYAAAAAAAQANS4xLjE1LW5kYi02LjEuMjQtZGVidWctbG9nAAAAAAAAAAAA
92AAAAAAAAAAAAAAAAAADgJ1hHEzgNAAgAEgAEBAQEEgAATwAEGggICAg=
93';
94
95# The following is a Write_rows_log_event with event type 23, i.e.,
96# not supported by the Format_description_log_event above.  It
97# corresponds to the following query:
98# INSERT INTO t1 VALUES (5)
99error 1149;
100BINLOG '
101Dl1YRxMBAAAAKQAAADQBAAAAABAAAAAAAAAABHRlc3QAAnQxAAEDAAE=
102Dl1YRxcBAAAAIgAAAFYBAAAQABAAAAAAAAEAAf/+BQAAAA==
103';
104# the above line should fail and 5 should not be in the binlog.
105select * from t1;
106
107# Test that BUG#37426 is triggered.
108
109CREATE TABLE char128_utf8 (
110    i1 INT NOT NULL,
111    c CHAR(128) CHARACTER SET utf8 NOT NULL,
112    i2 INT NOT NULL);
113CREATE TABLE char63_utf8 (
114      i1 INT NOT NULL,
115      c CHAR(63) CHARACTER SET utf8 NOT NULL,
116      i2 INT NOT NULL);
117
118#
119# This is the format description log event
120#
121
122BINLOG '
123MuNkSA8BAAAAZgAAAGoAAAAAAAQANS4xLjI1LXJjLWRlYnVnLWxvZwAAAAAAAAAAAAAAAAAAAAAA
124AAAAAAAAAAAAAAAAAAAy42RIEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC
125';
126
127# ... this event corresponding to
128#
129#    INSERT INTO char63_utf8 VALUES ( 1, "123", 1 )
130#
131# The binlog event below shall not trigger the bug check
132
133BINLOG '
1343u9kSBMBAAAANgAAAJYBAAAAABAAAAAAAAAABHRlc3QAC2NoYXI2M191dGY4AAMD/gMC/r0A
1353u9kSBcBAAAAKgAAAMABAAAQABAAAAAAAAEAA//4AQAAAAMxMjMBAAAA
136';
137SELECT * FROM char63_utf8;
138
139# ... and this is an event corresponding to
140#
141#    INSERT INTO char128_utf8 VALUES ( 1, "123", 1 )
142#
143# The binlog event below shall trigger the bug check and produce an error
144#
145
146error ER_UNKNOWN_ERROR;
147BINLOG '
148iONkSBMBAAAANwAAAJkBAAAAABAAAAAAAAAABHRlc3QADGNoYXIxMjhfdXRmOAADA/4DAv6AAA==
149iONkSBcBAAAAKwAAAMQBAAAQABAAAAAAAAEAA//4AQAAAAMAMTIzAQAAAA==
150';
151
152drop table t1, char63_utf8, char128_utf8;
153
154call mtr.add_suppression("Slave SQL.*master suffers from this bug: http:..bugs.mysql.com.bug.php.id=37426.* Error_code: 1105");
155call mtr.add_suppression("Slave SQL.*Table definition on master and slave does not match: Column 1 size mismatch.* Error_code: 1535");
156call mtr.add_suppression("Slave SQL.*Column 1 of table .test.char128_utf8. cannot be converted.* Error_code: 1677");
157
158--echo #
159--echo # Bug #54393: crash and/or valgrind errors in
160--echo # mysql_client_binlog_statement
161--echo #
162--error ER_SYNTAX_ERROR
163BINLOG '';
164--error ER_BASE64_DECODE_ERROR
165BINLOG '123';
166--error ER_BASE64_DECODE_ERROR
167BINLOG '-2079193929';
168--error ER_BASE64_DECODE_ERROR
169BINLOG 'xç↓%~∙D╒ƒ╡';
170