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;
reset master;
create table t1(n char(30));
set @i1:=12345678901234, @i2:=-12345678901234, @i3:=0, @i4:=-1;
set @s1:='This is a test', @r1:=12.5, @r2:=-12.5;
set @n1:=null;
set @s2:='', @s3:='abc\'def', @s4:= 'abc\\def', @s5:= 'abc''def';
insert into t1 values (@i1), (@i2), (@i3), (@i4);
insert into t1 values (@r1), (@r2);
insert into t1 values (@s1), (@s2), (@s3), (@s4), (@s5);
insert into t1 values (@n1);
insert into t1 values (@n2);
insert into t1 values (@a:=0), (@a:=@a+1), (@a:=@a+1);
insert into t1 values (@a+(@b:=@a+1));
set @q:='abc';
insert t1 values (@q), (@q:=concat(@q, 'n1')), (@q:=concat(@q, 'n2'));
set @a:=5;
insert into t1 values (@a),(@a);
insert into t1 values (@a),(@a),(@a*5);
select * from t1;
n
12345678901234
-12345678901234
0
-1
12.5
-12.5
This is a test

abc'def
abc\def
abc'def
NULL
NULL
0
1
2
5
abc
abcn1
abcn1n2
5
5
NULL
NULL
NULL
select * from t1;
n
12345678901234
-12345678901234
0
-1
12.5
-12.5
This is a test

abc'def
abc\def
abc'def
NULL
NULL
0
1
2
5
abc
abcn1
abcn1n2
5
5
NULL
NULL
NULL
show binlog events from 98;
Log_name	Pos	Event_type	Server_id	End_log_pos	Info
slave-bin.000001	#	Query	1	#	use `test`; create table t1(n char(30))
slave-bin.000001	#	User var	2	#	@`i1`=12345678901234
slave-bin.000001	#	User var	2	#	@`i2`=-12345678901234
slave-bin.000001	#	User var	2	#	@`i3`=0
slave-bin.000001	#	User var	2	#	@`i4`=-1
slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (@i1), (@i2), (@i3), (@i4)
slave-bin.000001	#	User var	2	#	@`r1`=12.5
slave-bin.000001	#	User var	2	#	@`r2`=-12.5
slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (@r1), (@r2)
slave-bin.000001	#	User var	2	#	@`s1`=_latin1 0x5468697320697320612074657374 COLLATE latin1_swedish_ci
slave-bin.000001	#	User var	2	#	@`s2`=_latin1 "" COLLATE latin1_swedish_ci
slave-bin.000001	#	User var	2	#	@`s3`=_latin1 0x61626327646566 COLLATE latin1_swedish_ci
slave-bin.000001	#	User var	2	#	@`s4`=_latin1 0x6162635C646566 COLLATE latin1_swedish_ci
slave-bin.000001	#	User var	2	#	@`s5`=_latin1 0x61626327646566 COLLATE latin1_swedish_ci
slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (@s1), (@s2), (@s3), (@s4), (@s5)
slave-bin.000001	#	User var	2	#	@`n1`=NULL
slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (@n1)
slave-bin.000001	#	User var	2	#	@`n2`=NULL
slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (@n2)
slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (@a:=0), (@a:=@a+1), (@a:=@a+1)
slave-bin.000001	#	User var	2	#	@`a`=2
slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (@a+(@b:=@a+1))
slave-bin.000001	#	User var	2	#	@`q`=_latin1 0x616263 COLLATE latin1_swedish_ci
slave-bin.000001	#	Query	1	#	use `test`; insert t1 values (@q), (@q:=concat(@q, 'n1')), (@q:=concat(@q, 'n2'))
slave-bin.000001	#	User var	2	#	@`a`=5
slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (@a),(@a)
slave-bin.000001	#	User var	2	#	@`a`=NULL
slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (@a),(@a),(@a*5)
insert into t1 select * FROM (select @var1 union  select @var2) AS t2;
drop table t1;
End of 4.1 tests.
DROP TABLE IF EXISTS t20;
DROP TABLE IF EXISTS t21;
DROP PROCEDURE IF EXISTS test.insert;
CREATE TABLE t20 (a VARCHAR(20));
CREATE TABLE t21 (a VARCHAR(20));
CREATE PROCEDURE test.insert()
BEGIN
IF (@VAR)
THEN
INSERT INTO test.t20 VALUES ('SP_TRUE');
ELSE
INSERT INTO test.t20 VALUES ('SP_FALSE');
END IF;
END|
CREATE TRIGGER test.insert_bi BEFORE INSERT
ON test.t20 FOR EACH ROW
BEGIN
IF (@VAR)
THEN
INSERT INTO test.t21 VALUES ('TRIG_TRUE');
ELSE
INSERT INTO test.t21 VALUES ('TRIG_FALSE');
END IF;
END|
SET @VAR=0;
CALL test.insert();
SET @VAR=1;
CALL test.insert();
On master: Check the tables for correct data
SELECT * FROM t20;
a
SP_FALSE
SP_TRUE
SELECT * FROM t21;
a
TRIG_FALSE
TRIG_TRUE
On slave: Check the tables for correct data and it matches master
SELECT * FROM t20;
a
SP_FALSE
SP_TRUE
SELECT * FROM t21;
a
TRIG_FALSE
TRIG_TRUE
DROP TABLE t20;
DROP TABLE t21;
DROP PROCEDURE test.insert;
DROP TABLE IF EXISTS t1;
DROP FUNCTION IF EXISTS test.square;
CREATE TABLE t1 (i INT);
CREATE FUNCTION test.square() RETURNS INTEGER DETERMINISTIC RETURN (@var * @var);
SET @var = 1;
INSERT INTO t1 VALUES (square());
SET @var = 2;
INSERT INTO t1 VALUES (square());
SET @var = 3;
INSERT INTO t1 VALUES (square());
SET @var = 4;
INSERT INTO t1 VALUES (square());
SET @var = 5;
INSERT INTO t1 VALUES (square());
On master: Retrieve the values from the table
SELECT * FROM t1;
i
1
4
9
16
25
On slave: Retrieve the values from the table and verify they are the same as on master
SELECT * FROM t1;
i
1
4
9
16
25
DROP TABLE t1;
DROP FUNCTION test.square;
DROP TABLE IF EXISTS t1;
DROP FUNCTION IF EXISTS f1;
DROP FUNCTION IF EXISTS f2;
CREATE TABLE t1(a int);
CREATE FUNCTION f1() returns int deterministic
BEGIN
return @a;
END |
CREATE FUNCTION f2() returns int deterministic
BEGIN
IF (@b > 0) then
SET @c = (@a + @b);
else
SET @c = (@a - 1);
END if;
return @c;
END |
SET @a=500;
INSERT INTO t1 values(f1());
SET @b = 125;
SET @c = 1;
INSERT INTO t1 values(f2());
On master: Retrieve the values from the table
SELECT * from t1;
a
500
625
On slave: Check the tables for correct data and it matches master
SELECT * from t1;
a
500
625
DROP TABLE t1;
DROP FUNCTION f1;
DROP FUNCTION f2;
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
CREATE TABLE t1 (i int);
CREATE TABLE t2 (k int);
CREATE trigger t1_bi before INSERT on t1 for each row
BEGIN
INSERT INTO t2 values (@a);
SET @a:=42;
INSERT INTO t2 values (@a);
END |
SET @a:=100;
INSERT INTO t1 values (5);
On master: Check to see that data was inserted correctly in both tables
SELECT * from t1;
i
5
SELECT * from t2;
k
100
42
On slave: Check the tables for correct data and it matches master
SELECT * from t1;
i
5
SELECT * from t2;
k
100
42
drop table t1, t2;
reset master;
create table t1 (a int);
prepare s from "insert into t1 values (@a),(?)";
set @a=98;
execute s using @a;
prepare s from "insert into t1 values (?)";
set @a=99;
execute s using @a;
prepare s from "insert into t1 select 100 limit ?";
set @a=100;
execute s using @a;
show binlog events from 98;
Log_name	Pos	Event_type	Server_id	End_log_pos	Info
slave-bin.000001	98	Query	1	184	use `test`; create table t1 (a int)
slave-bin.000001	184	User var	2	226	@`a`=98
slave-bin.000001	226	Query	1	320	use `test`; insert into t1 values (@a),(98)
slave-bin.000001	320	Query	1	409	use `test`; insert into t1 values (99)
slave-bin.000001	409	Query	1	507	use `test`; insert into t1 select 100 limit 100
select * from t1;
a
98
98
99
100
drop table t1;
create table t1(a int, b int);
prepare s1 from 'insert into t1 values (@x:=@x+1, ?)';
set @x=1;
execute s1 using @x;
select * from t1;
a	b
2	1
select * from t1;
a	b
2	1
drop table t1;
create table t1(a int);
insert into t1 values (1),(2);
prepare s1 from 'insert into t1 select a from t1 limit ?';
set @x='1.1';
execute s1 using @x;
select * from t1;
a
1
2
1
select * from t1;
a
1
2
1
drop table t1;
End of 5.0 tests.
DROP FUNCTION IF EXISTS f1;
DROP FUNCTION IF EXISTS f2;
CREATE TABLE t1 (i INT);
CREATE FUNCTION f1() RETURNS INT RETURN @a;
CREATE FUNCTION f2() RETURNS INT
BEGIN
INSERT INTO t1 VALUES (10 + @a);
RETURN 0;
END|
SET @a:=123;
SELECT f1(), f2();
f1()	f2()
123	0
On master: Check to see that data was inserted correctly 
INSERT INTO t1 VALUES(f1());
SELECT * FROM t1;
i
133
123
On slave: Check the table for correct data and it matches master
SELECT * FROM t1;
i
133
123
DROP FUNCTION f1;
DROP FUNCTION f2;
DROP TABLE t1;
stop slave;
