###########################################################################
# Purpose: To test backup using default driver
###############################################################################
--source include/have_falcon.inc
--source include/have_partition.inc
--source include/not_embedded.inc

let MYSQLD_BACKUPDIR= `select @@backupdir`;

--echo
--echo Server should not crash for backup using default driver - CSV
--echo Test for bug#35117
--echo

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

CREATE DATABASE db1;
USE db1;

# csv uses default driver
CREATE TABLE csv_table(
   id int NOT NULL,
   name char(20) NOT NULL,
   city varchar(20) NOT NULL) 
ENGINE=csv;

INSERT INTO csv_table VALUES(1,'aa1','bb1'),(2,'aa2','bb2'),(3,'aa3','bb3');

--echo backup on csv only
--replace_column 1 #
BACKUP DATABASE db1 to 'bup_csv.bak';

DROP DATABASE db1;

--echo restore on csv only
--replace_column 1 #
RESTORE FROM 'bup_csv.bak';

--echo testing content in restored tables
SELECT * FROM csv_table ORDER BY id;

DROP DATABASE db1;

--echo
--echo Server should not crash for backup using default driver 
--echo Mix of tables
--echo 

CREATE DATABASE db1;
USE db1;

# create partitioned MyISAM table - will use default driver
CREATE TABLE partition_table (
  int_column int(11), 
  char_column char(5))
PARTITION BY HASH (int_column);

INSERT INTO partition_table VALUES (0,'pVtIa');
INSERT INTO partition_table VALUES (5,'jTfSg');
INSERT INTO partition_table VALUES (20,'UezFi');
INSERT INTO partition_table VALUES (25,'cxmeH');
INSERT INTO partition_table VALUES (65,'lIuNS');

# create CSV table - will use default driver
CREATE TABLE csv_table(
   id int NOT NULL,
   name char(20) NOT NULL,
   city varchar(20) NOT NULL) 
ENGINE=csv;

INSERT INTO csv_table VALUES(1,'aa1','bb1'),(2,'aa2','bb2'),(3,'aa3','bb3');

# create a myisam table (not default driver)
CREATE TABLE myisam_table(
   i int,
   v varchar(20))
;

INSERT INTO myisam_table VALUES(1,'v1'),(2,'v2'),(3,'v3');

--echo backup on mixed table database
--replace_column 1 #
BACKUP DATABASE db1 to 'bup_mixed.bak';

DROP DATABASE db1;

--echo restore on mixed table database
--replace_column 1 #
RESTORE FROM 'bup_mixed.bak';

--echo testing content in restored tables
SELECT * FROM partition_table ORDER BY int_column;
SELECT * FROM csv_table ORDER BY id;
SELECT * FROM myisam_table ORDER BY i;


# Test cleanup section

--echo
--echo ***  CLEANUP  ****
--echo


DROP DATABASE db1;

--remove_file $MYSQLD_BACKUPDIR/bup_csv.bak
#--remove_file $MYSQLD_BACKUPDIR/bup_falcon.bak
#--remove_file $MYSQLD_BACKUPDIR/bup_mixed.bak

