###############################################################################
# Bug#21205695 DROP TABLE MAY CAUSE SLAVES TO BREAK
#
# Problem:
# ========
# 1) Drop table queries are re-generated by server
#    before writing the events(queries) into binlog
#    for various reasons. If table name/db name contains
#    a non regular characters (like latin characters),
#    the generated query is wrong. Hence it breaks the
#    replication.
# 2) In the edge case, when table name contains
#    64 latin characters (latin takes 2 bytes), server is
#    throwing an assert (M_TBLLEN < 128)
#
# 3) In the edge case, when db name contains 64 latin
#    characters, binlog contents are interpreted wrongly
#    which is leading to replication issues.
#
###############################################################################

--source include/not_windows.inc
--source include/master-slave.inc

--let iter=1
# Change iteration to 4 after fixing Bug #22280214
while ($iter <= 2)
{
  --connection master
  if ($iter == 1)
  {
    --echo Test case 1:- table name with one character latin name.
    --let $tblname= REPEAT(CHAR(131),1)
  }
  if ($iter == 2)
  {
    --echo Test case 2:- table name and database names with one character latin name.
    --let $tblname= REPEAT(CHAR(131),1),"`.`",REPEAT(CHAR(131),1)
    --eval SET @s:=CONCAT("CREATE DATABASE `",REPEAT(CHAR(131),1),"`")
    PREPARE STMT FROM @s; EXECUTE stmt;
  }
  # After fixing Bug #22280214 DATADIR LOCATION IS LIMITING
  # IDENTIFIER MAX LENGTH,  the following two tests (iter 3 and 4) can be
  # uncommented.
  #if ($iter == 3)
  #{
    # --echo Test case 3:- table name and database names with 64 latin characters name.
    # --let $tblname= REPEAT(CHAR(131),64),"`.`", REPEAT(CHAR(131),64)
    # --eval SET @s:=CONCAT("CREATE DATABASE `",REPEAT(CHAR(131),64),"`")
    # PREPARE STMT FROM @s; EXECUTE stmt;
  #}
  #if ($iter == 4)
  #{
    # --echo Test case 4:- table name and database names with 64 Euro(€) characters.
    # --let $tblname= REPEAT(CHAR(226,130,172),64),"`.`", REPEAT(CHAR(226,130,172),64)
    # --eval SET @s:=CONCAT("CREATE DATABASE `",REPEAT(CHAR(226,130,172),64),"`")
    # PREPARE STMT FROM @s; EXECUTE stmt;
  #}
  --eval SET @s:=CONCAT("CREATE TABLE `",$tblname,"` (a INT)")
  PREPARE STMT FROM @s; EXECUTE stmt;
  --eval SET @s:=CONCAT("INSERT INTO `",$tblname,"` VALUES (1)")
  PREPARE STMT FROM @s; EXECUTE stmt;
  --eval SET @s:=CONCAT("DROP TABLE `",$tblname, "`")
  PREPARE STMT FROM @s; EXECUTE stmt;
  if ($iter == 2)
  {
    --eval SET @s:=CONCAT("DROP DATABASE `",REPEAT(CHAR(131),1),"`")
    PREPARE STMT FROM @s; EXECUTE stmt;
  }
  # After fixing Bug #22280214 DATADIR LOCATION IS LIMITING
  # IDENTIFIER MAX LENGTH, the following two tests (iter 3 and 4) can be
  # uncommented.
  #if ($iter == 3)
  #{
     # --eval SET @s:=CONCAT("DROP DATABASE `",REPEAT(CHAR(131),64),"`")
     # PREPARE STMT FROM @s; EXECUTE stmt;
  #}
  #if ($iter == 4)
  #{
     # --eval SET @s:=CONCAT("DROP DATABASE `",REPEAT(CHAR(226,130,172),64),"`")
     # PREPARE STMT FROM @s; EXECUTE stmt;
  #}
  --sync_slave_with_master
  --inc $iter
}

--source include/rpl_end.inc
