--source include/have_innodb.inc

# Don't test this under valgrind, memory leaks will occur due restart
--source include/not_valgrind.inc

# Embedded has issues with restarting
--source include/not_embedded.inc

CREATE DATABASE WL6445;

CREATE TABLE WL6445.t1(c1 INT, c2 INT, INDEX sec_idx(c2)) ENGINE=InnoDB;
INSERT INTO WL6445.t1 VALUES(0,0),(1,1),(2,2);

SHOW CREATE TABLE WL6445.t1;

# Write file to make mysql-test-run.pl wait for the server to stop
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

--echo # Request clean shutdown
--send_shutdown

--echo # Wait for disconect
--source include/wait_until_disconnected.inc

--echo # Restart server.
--exec echo "restart:--innodb-read-only" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

--enable_reconnect
--source include/wait_until_connected_again.inc
--disable_reconnect

--echo # Restarted

## DDL

SELECT COUNT(*) FROM WL6445.t1;

--error ER_CANT_LOCK
INSERT INTO WL6445.t1 VALUES(3,3);

--ERROR ER_OPEN_AS_READONLY
INSERT INTO WL6445.t1 SELECT * FROM WL6445.t1;

--error ER_CANT_LOCK
REPLACE INTO WL6445.t1 VALUES(1,1);

--error ER_CANT_LOCK
UPDATE WL6445.t1 SET c1 = c1 + 100;

--error ER_CANT_LOCK
DELETE FROM WL6445.t1;

# DDL
--error ER_DUP_FIELDNAME
ALTER TABLE WL6445.t1 ADD COLUMN c2 INT;

--error ER_CANT_LOCK
ALTER TABLE WL6445.t1 ADD UNIQUE INDEX(c1);

--error ER_CANT_LOCK
ALTER TABLE WL6445.t1 DROP INDEX sec_idx;

# FIXME: Should bne
#--error ER_OPEN_AS_READONLY
--replace_regex /wl6445/WL6445/i
--error ER_BAD_TABLE_ERROR
DROP TABLE WL6445.t1;

--error ER_OPEN_AS_READONLY
TRUNCATE TABLE WL6445.t1;

--replace_regex /'\..*t1'/'t1'/  /'\..*t2'/'t2'/
--error ER_ERROR_ON_RENAME
RENAME TABLE WL6445.t1 TO WL6444.t2;

--replace_regex /wl6445/WL6445/i
--error ER_BAD_TABLE_ERROR
DROP DATABASE WL6445;

SHOW CREATE TABLE WL6445.t1;

# Restart in RW mode so that we can drop the test data
# Write file to make mysql-test-run.pl wait for the server to stop
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

--echo # Request clean shutdown
--send_shutdown

--echo # Wait for disconect
--source include/wait_until_disconnected.inc

--echo # Restart server.
--exec echo "restart:" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

--enable_reconnect
--source include/wait_until_connected_again.inc
--disable_reconnect

--echo # Restarted

DROP TABLE WL6445.t1;

DROP DATABASE WL6445;
