--source include/have_falcon.inc
#
# Bug #22165: ALTER crash if two interleaving transactions
#
--echo *** Bug #22165 ***

# ----------------------------------------------------- #
# --- Initialisation                                --- #
# ----------------------------------------------------- #
let $engine = 'Falcon';
eval SET @@storage_engine = $engine;

--disable_warnings
DROP TABLE IF EXISTS t1;
DROP PROCEDURE IF EXISTS p1;
--enable_warnings
CREATE TABLE t1 (a bigint, b varchar(1000), c timestamp);

delimiter //;
CREATE PROCEDURE p1 ()
begin
  declare v int default 0;
  declare continue handler for sqlexception
  begin
    declare continue handler for sqlexception begin end;
    ALTER TABLE t1 MODIFY COLUMN c timestamp;
  end;
  SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
  while v < 10 do
    START TRANSACTION;
    INSERT INTO t1 (a, b) VALUES (v, 'a');
    UPDATE t1 SET c = current_timestamp WHERE a = v;
	IF (v < 5)  
	  	THEN COMMIT;
	  	ELSE ROLLBACK; 
 	END IF;
    SET v = v + 1;
  end while;
end//
delimiter ;//

connect (conn1,localhost,root,,);
connect (conn2,localhost,root,,);



# ----------------------------------------------------- #
# --- Test                                          --- #
# ----------------------------------------------------- #
--disable_query_log
let $i=150;
while ($i)
{
  connection conn1;
  --send call p1();
  connection conn2;
  --send call p1();
  
  connection conn1;
  --reap
  connection conn2;
  --reap

  dec $i;
}
--enable_query_log
# ----------------------------------------------------- #
# --- Check                                         --- #
# ----------------------------------------------------- #
# Checking row count is not applicable here.
#SELECT count(*) FROM t1;

# ----------------------------------------------------- #
# --- Final cleanup                                 --- #
# ----------------------------------------------------- #
connection default;
disconnect conn1;
disconnect conn2;
DROP PROCEDURE p1;
DROP TABLE t1;

