--source include/have_falcon.inc
#
# Bug #22143: Crash creating temporary table
#
--echo *** Bug #22143 ***

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

--disable_warnings
DROP DATABASE IF EXISTS test2;
--enable_warnings

CREATE DATABASE test2;
USE test2;

--echo # Establish connection conn1 (user = root)
connect (conn1,localhost,root,,);
eval SET @@storage_engine = $engine;
USE test2;

# ----------------------------------------------------- #
# --- Test                                          --- #
# ----------------------------------------------------- #
--echo # Switch to connection default
connection default;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (3), (0), (3);
SELECT count(*) FROM t1;

CREATE TEMPORARY TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (2, 3);
SELECT count(*) FROM t1;

--echo # Switch to connection conn1
connection conn1;
CREATE TEMPORARY TABLE t1 (a int, b int, c int);
INSERT INTO t1 VALUES (2, 3, 5), (5, 3, 2);
SELECT count(*) FROM t1;

--echo # Switch to connection default
connection default;
DROP TEMPORARY TABLE t1;
SELECT count(*) FROM t1;

--echo # Switch to connection conn1
connection conn1;
DROP TEMPORARY TABLE t1;
SELECT count(*) FROM t1;

# ----------------------------------------------------- #
# --- Check                                         --- #
# ----------------------------------------------------- #
--echo # Switch to connection default
connection default;
SELECT count(*) FROM t1;

# ----------------------------------------------------- #
# --- Final cleanup                                 --- #
# ----------------------------------------------------- #
--echo # Switch to connection default
connection default;
disconnect conn1;
DROP DATABASE test2;
