# Current test checks Last_errno for administrative command "Quit"
# See Launchpad Bug #716210

--source include/log_prepare.inc

--source include/count_sessions.inc

SET @saved_log_slow_admin_statements=@@GLOBAL.log_slow_admin_statements;
SET GLOBAL log_slow_admin_statements=ON;
SET @saved_long_query_time=@@GLOBAL.long_query_time;
SET GLOBAL long_query_time=0;
SET @saved_min_examined_row_limit=@@GLOBAL.min_examined_row_limit;
SET GLOBAL min_examined_row_limit=0;

CREATE TABLE t(a INT);

--connect(additional,localhost,root,,)
--connection additional

#
# 1st command in the log that sets Last_errno
#
--let log_file=percona.slow_extended.error_on_quit_1
--source include/log_start.inc

--error ER_TABLE_EXISTS_ERROR
CREATE TABLE t(a INT);
--source include/log_stop.inc

--let grep_pattern=Last_errno: [1-9]\d*\s
--source include/log_grep.inc

#
# Subsequent Quit should not have Last_errno set
#
--let log_file=percona.slow_extended.error_on_quit_2
--source include/log_start.inc
--echo # Disconnecting (passing to Slow Query Log "# administrative command: Quit")
--disconnect additional
--connection default
--source include/wait_until_count_sessions.inc
--source include/log_stop.inc

--let grep_pattern=Last_errno: 0\s
--let log_expected_matches= 2
--source include/log_grep.inc

--connect(additional,localhost,root,,)
--connection additional

#
# Negative case: both regular command and Quit with errno = 0
#
--let log_file=percona.slow_extended.error_on_quit_3
--source include/log_start.inc

SELECT * FROM t;

--echo # Disconnecting (passing to Slow Query Log "# administrative command: Quit")
--disconnect additional
--connection default
--source include/wait_until_count_sessions.inc
--source include/log_stop.inc

--let grep_pattern= Last_errno: 0\s
--let log_expected_matches= 3
--source include/log_grep.inc

DROP TABLE t;
SET GLOBAL log_slow_admin_statements=@saved_log_slow_admin_statements;
SET GLOBAL long_query_time=@saved_long_query_time;
SET GLOBAL min_examined_row_limit=@saved_min_examined_row_limit;
--source include/log_cleanup.inc
