SET storage_engine = Falcon;
#
# Mantis bug #148: ROLLBACK fails with two interleaving transactions
#
--echo *** Bug #148 ***
--disable_warnings
DROP DATABASE IF EXISTS test2;
--enable_warnings

--echo # Establish connection conn1 (user = root)
connect (conn1,localhost,root,,);
SET storage_engine = Falcon;

--echo # Switch to connection default
connection default;
SET @@autocommit=0;
CREATE DATABASE test2;
USE test2;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a int primary key, b int);
COMMIT;
INSERT INTO t1 VALUES (0,0),(1,1);
COMMIT;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a int primary key, b int);
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
START TRANSACTION;
SELECT * FROM t1;
INSERT INTO t1 VALUES (0,0);

--echo # Switch to connection conn1
connection conn1;
SET @@autocommit=1;
USE test2;
# Following statements waits for connection default
--send INSERT INTO t1 VALUES (1,1);

--echo # Switch to connection default
connection default;
INSERT INTO t1 VALUES (1,2);
ROLLBACK;

--echo # Switch to connection conn1
connection conn1;
reap;
INSERT INTO t1 VALUES (0,6);
--error 1062
INSERT INTO t1 VALUES (0,6);
COMMIT;

--echo # Switch to connection default
connection default;
SELECT * FROM t1 ORDER BY a;
COMMIT;

# Final cleanup
disconnect conn1;
DROP DATABASE test2;
USE test;
