#
# Test if dynamic replication database filter rules are properly evaluated.
#

source include/have_binlog_format_statement.inc;
source include/master-slave.inc;

connection slave;
--error ER_SLAVE_MUST_STOP
SET @@GLOBAL.replicate_do_db="db1";
--error ER_SLAVE_MUST_STOP
SET @@GLOBAL.replicate_ignore_db="db2";

connection slave;
source include/stop_slave.inc;
SET @@GLOBAL.replicate_do_db="db1";
SET @@GLOBAL.replicate_ignore_db="db2";
source include/start_slave.inc;
connection master;

CREATE DATABASE db1;
CREATE DATABASE db2;
CREATE DATABASE db3;

# db is mentioned in do-db rules
USE db1;
CREATE TABLE t1 (a INT);

# db is mentioned in ignore-db rules
USE db2;
CREATE TABLE t2 (a INT);

# db is not mentioned in do-db or ignore-db rules
USE db3;
CREATE TABLE t3 (a INT);

USE db1;
INSERT INTO t1 VALUES (1);

USE db2;
INSERT INTO t2 VALUES (2);

USE db3;
INSERT INTO t3 VALUES (3);

# Only db1 should be replicated to slave
sync_slave_with_master;
echo [on slave];
SHOW DATABASES LIKE 'db%';
SHOW TABLES IN db1 LIKE 't%';

connection master;

# Clean up
connection master;
DROP DATABASE IF EXISTS db1;
DROP DATABASE IF EXISTS db2;
DROP DATABASE IF EXISTS db3;
--source include/rpl_end.inc

connection slave;
SET @@GLOBAL.replicate_do_db="";
SET @@GLOBAL.replicate_ignore_db="";
