--let $gtid_violation= 1
--let $error_code= ER_GTID_UNSAFE_NON_TRANSACTIONAL_TABLE
--let $error_message= Statement violates GTID consistency: Updates to non-transactional tables
--let $sync_point= end_decide_logging_format
--let $statement_ends_transaction= 0

CREATE TABLE myisam1 (a INT) ENGINE = MyISAM;
CREATE TABLE myisam2 (a INT) ENGINE = MyISAM;
CREATE TABLE innodb (a INT) ENGINE = InnoDB;



# InnoDB and MyISAM on base tables in the same transaction or in the
# same statement is a GTID-violation.

--echo ---- InnoDB followed by MyISAM in one trx ----
if ($binlog_direct_non_transactional_updates == 0)
{
  if ($binlog_format == 'STATEMENT')
  {
    # In this case we get a warning for unsafe statement.
    --let $extra_warning_count= 1
  }
}
--disable_warnings
--let $pre_statement= BEGIN; INSERT INTO innodb VALUES (1)
--let $statement= INSERT INTO myisam1 VALUES (1)
--source extra/binlog_tests/enforce_gtid_consistency_statement.inc
--enable_warnings
--let $extra_warning_count= 0

--echo ---- InnoDB and MyISAM in one autocommit statement ----
CREATE TRIGGER trig BEFORE INSERT ON innodb FOR EACH ROW INSERT INTO myisam1 VALUES (1);
--let $statement= INSERT INTO innodb VALUES (1)
--let $statement_ends_transaction= 1
--source extra/binlog_tests/enforce_gtid_consistency_statement.inc

--echo ---- InnoDB and MyISAM in one statement inside trx ----
# If binlog_format==STATEMENT, there is a warning for unsafe statement.
if ($binlog_format == 'STATEMENT')
{
  --let $extra_warning_count= 1
}
# Disable warnings to make result the same regardles of binlog_format.
--disable_warnings
--let $pre_statement= BEGIN
--let $statement= INSERT INTO innodb VALUES (1)
--let $statement_ends_transaction= 0
--source extra/binlog_tests/enforce_gtid_consistency_statement.inc
DROP TRIGGER trig;
--let $extra_warning_count= 0
--enable_warnings

# If the MyISAM update is temporary and binlog_format=row, it is not a
# GTID-violation since the temporary updates are not logged. But if
# binlog_format=statement or mixed, it is an violation; that is what
# we check here.

--echo ---- InnoDB followed by temp MyISAM in one trx, binlog_format=stm ----
SET SESSION BINLOG_FORMAT = STATEMENT;

CREATE TEMPORARY TABLE tmp_myisam1 (a INT) ENGINE = MyISAM;
CREATE TEMPORARY TABLE tmp_myisam2 (a INT) ENGINE = MyISAM;

--let $pre_statement= BEGIN; INSERT INTO innodb VALUES (1)
--let $statement= INSERT INTO tmp_myisam1 VALUES (1)
--let $statement_ends_transaction= 0
--source extra/binlog_tests/enforce_gtid_consistency_statement.inc

--echo ---- InnoDB and temp MyISAM in one autocommit statement, binlog_format=stm ----
CREATE TRIGGER trig BEFORE INSERT ON innodb FOR EACH ROW INSERT INTO tmp_myisam1 VALUES (1);
--let $statement= INSERT INTO innodb VALUES (1)
--let $statement_ends_transaction= 1
--source extra/binlog_tests/enforce_gtid_consistency_statement.inc

--echo ---- InnoDB and temp MyISAM in one statement inside trx, binlog_format=stm ----
if (`SELECT @@GLOBAL.BINLOG_DIRECT_NON_TRANSACTIONAL_UPDATES`)
{
  # Unsafe warning
  --let $extra_warning_count= 1
}
--disable_warnings
--let $pre_statement= BEGIN
--let $statement= INSERT INTO innodb VALUES (1)
--let $statement_ends_transaction= 0
--source extra/binlog_tests/enforce_gtid_consistency_statement.inc
DROP TRIGGER trig;
--let $extra_warning_count= 0
--enable_warnings

DROP TABLE myisam1, myisam2, tmp_myisam1, tmp_myisam2, innodb;

--replace_regex /'[A-Z]*'/#/
eval SET BINLOG_FORMAT = '$binlog_format';
