##########################################################################
# Author: Hema
# Date: 2009-02-05
# Purpose: This test is to verify the objects dependency and consistency for 
# mysql backup and restore feature.
###############################################################################

# Mysql Backup currently supports following objects:
# Databases, tables, views, stored procedures / functions, triggers
# and events.
# We will include all these objects and check their dependency between 
# each other. To check the consistency, we need to ensure that all data, 
# and objects are properly restored and are intact.
# To get more details of tests, please refer to WL#4225

# Suppress warning about expected backup/restore errors
disable_query_log;
call mtr.add_suppression("Backup: Failed to add view");
call mtr.add_suppression("Backup: Failed to obtain meta-data for view");
call mtr.add_suppression("Restore: Could not restore view");
call mtr.add_suppression("Backup: Operation aborted");
enable_query_log;

--source include/not_embedded.inc

let $bdir=`SELECT @@backupdir`;
--error 0,1
--remove_file $bdir/ob.bak

--echo **START TEST**
--echo **** TEST1 ****

# Create database

CREATE DATABASE IF NOT EXISTS ob1;
CREATE DATABASE IF NOT EXISTS ob2;
CREATE DATABASE IF NOT EXISTS ob3;
CREATE USER 'tom'@'%';

# Grant privileges to user tom

GRANT ALL ON *.* TO tom@'%';

# Create tables

--echo ** create tables in 'ob1' database **
--echo

CREATE TABLE ob1.t11(
 id INT, 
 name CHAR(20), 
 pay FLOAT(7,3)
);
INSERT INTO ob1.t11 VALUES
(10, 'ab1', 2200.23),(12, 'ab2',2190.34),(14,'ab3',3123.45),
(15,'ab4',1236.89),(18,'ab5',3890.78),(20,'ab6',1300);
SELECT * FROM ob1.t11;

CREATE TABLE ob1.t12(
 scode TINYINT, 
 empcode CHAR(10), 
 join_date DATE
);
INSERT INTO ob1.t12 VALUES
(10, 'E120','1997-10-09'),(12,'E145','1999-01-20'),(14,'C134','2001-09-08'),
(15, 'C156','2005-09-11'),(18,'E250','2007-08-06');
SELECT * FROM ob1.t12;

CREATE TABLE ob1.t13(details VARCHAR(40));
CREATE TABLE ob1.t14(payment_type VARCHAR(30), salary MEDIUMINT);
INSERT INTO ob1.t14 VALUES('cash',4000),('cheque',5000);
SELECT * FROM ob1.t14;

--echo ** Create tables in 'ob2' database **
--echo 

CREATE TABLE ob2.t21(
  ecode CHAR(20),
  company VARCHAR(20), 
  identity CHAR(20), 
  designation ENUM('Engineer','support','sales','lead')
 );
INSERT INTO ob2.t21 VALUES
('E250','Mysql','ab2','Engineer'),('E120','SUN','ab3','Sales'),
('E145','Nokia','ab4','Support'),('C134','Veritas','ab5','sales');
SELECT * FROM ob2.t21;

CREATE TABLE ob2.t22(
 empcode CHAR(10), 
 bonus DECIMAL(5,2), 
 rating CHAR(20)
);
INSERT INTO ob2.t22 VALUES
('E250','10.12','good'),('E120','7.23','average'),('E145','12','outstanding');
SELECT * FROM ob2.t22;

CREATE TABLE ob2.t23 AS SELECT 1 A UNION SELECT 2 UNION SELECT 3;
CREATE TABLE ob2.t24 AS SELECT * FROM ob2.t23;
SELECT * FROM ob2.t23 ORDER BY A;
SELECT * FROM ob2.t24;

--echo ** Create tables in 'ob3' database
--echo

CREATE TABLE ob3.t31(
 ccode TINYINT,
 gcode INT,
 company_name CHAR(20),
 company_stocks SMALLINT
);
INSERT INTO ob3.t31 VALUES
(10, 102,'Nokia',2000),(12, 122,'Veritas',1500),(15,152,'Mysql',3000);

CREATE TABLE ob3.t32(id INT);
--echo # Table log will contain entries added by firing event.
CREATE TABLE ob3.log(pos INT UNIQUE AUTO_INCREMENT, msg CHAR(32));
--echo # Table msg contains a message to be inserted into log by the event.
CREATE TABLE ob3.msg(m CHAR(32)) AS SELECT (NULL);

--echo
--echo ------------------------------------------------------------
--echo    CREATE VIEWS, TRIGGERS, EVENTS, PROCEDURES AND FUNCTIONS
--echo ------------------------------------------------------------
--echo

--echo ** creating views in 'ob1' database **
--echo

--echo ### Create views from 2 tables(same DB) ###
CREATE DEFINER=tom@'%' VIEW ob1.v11 AS SELECT id, name, empcode, join_date 
 FROM ob1.t11, ob1.t12 WHERE id=scode;
SELECT * FROM ob1.v11; 

--echo
--echo ### Create views from 2 tables (same/different DB) ###
CREATE VIEW ob1.v12 AS SELECT ecode, name, company, designation 
 FROM ob1.t11, ob2.t21 WHERE name=identity;
SELECT * FROM ob1.v12;

--echo
--echo ### Create views from 2 tables (diff DB) ###
CREATE VIEW ob1.v13 AS SELECT identity, bonus, rating 
 FROM ob2.t21, ob2.t22 WHERE ecode=empcode;
SELECT * FROM ob1.v13;

--echo
--echo ### Create view based on view(same DB) ###
CREATE VIEW ob1.v17 AS SELECT * FROM ob1.v12;
SELECT * FROM ob1.v17;

--echo
--echo ### Create view from view, table (same DB) ###
CREATE VIEW ob1.v18 AS SELECT name, empcode, join_date 
 FROM ob1.v12, ob1.t12 WHERE empcode=ecode;
SELECT * FROM ob1.v18;

--echo 
--echo ### Create view from 2 tables (diff DB) ###
CREATE VIEW ob1.v14 AS SELECT ecode,ccode,gcode 
 FROM ob2.t21, ob3.t31 WHERE company=company_name;

--echo
--echo ### Create view from table (same DB) ###
CREATE VIEW ob1.v15 AS SELECT SUM(pay), AVG(pay),MAX(pay),MIN(pay)
 FROM ob1.t11;
SELECT * FROM ob1.v15;

--echo
--echo ### Create view on tables (diff DB)###
CREATE VIEW ob1.v16 AS SELECT CONCAT(name," ",empcode) AS emp_details
 FROM ob1.t11, ob1.t12 WHERE id=scode;
SELECT * FROM ob1.v16;

--echo
--echo ** creating views in 'ob2' database **

--echo
--echo ### Create view from views (diff DB) ###
CREATE VIEW ob2.v21 AS SELECT designation, bonus 
 FROM ob1.v12, ob1.v13 WHERE name=identity;
SELECT * FROM ob2.v21;

--echo
--echo ### Create view from view (same DB) ###
CREATE VIEW ob2.v22 AS SELECT * FROM ob2.v21;
SELECT * FROM ob2.v22;

--echo ### Create view from tables (diff DB) ###
CREATE VIEW ob2.v23 AS SELECT id, designation FROM ob1.t11 
 JOIN ob2.t21 ON name=identity WHERE id>15;
SELECT * FROM ob2.v23;

--echo ### Create view from table (diff DB) ###
CREATE VIEW ob2.v24 AS SELECT empcode FROM ob2.t22 WHERE EXISTS 
(SELECT empcode FROM ob1.t12);
SELECT * FROM ob2.v24;

--echo
--echo ### Create a simple procedure ###
DELIMITER ||;
CREATE DEFINER=tom@'%' PROCEDURE ob2.p21(x INT, OUT y INT)
BEGIN
 DECLARE z INT;
 SET z=x+1, y=z;
END|| 

--echo 
--echo ### Trigger calls procedure  ###
CREATE TRIGGER ob2.trg23a AFTER INSERT ON ob2.t23 FOR EACH ROW
BEGIN
 INSERT INTO ob1.t13 VALUES('TRIGGER FIRED FROM trg11');
 INSERT INTO ob1.t14 VALUES('dd',2000);
 CALL ob2.p21(10, @ob2.p21);
END;||

--echo
--echo ### Trigger will in turn trigger trg23b ###
CREATE TRIGGER ob1.trg11 BEFORE INSERT ON ob1.t11 FOR EACH ROW
BEGIN
  DELETE FROM ob2.t23 WHERE a < 2;
END;||

--echo
--echo ### Trigger on function  and trigger ###
CREATE TRIGGER ob2.trg23b AFTER DELETE ON ob2.t23 FOR EACH ROW
BEGIN
 INSERT INTO ob1.t13 VALUES('TRIGGER FIRED FROM trg12');
 INSERT INTO ob3.t32 SELECT ob2.f21();
END;||

--echo
--echo ### Trigger trg12 will inturn trigger trg11 ###
CREATE TRIGGER ob1.trg12 AFTER UPDATE ON ob1.t12 FOR EACH ROW
BEGIN
  INSERT INTO ob1.t11 VALUES(22,'ab7','4123.23');
END;
||

--echo 
--echo ### Trigger trg32 depends on user ###
CREATE DEFINER=tom@'%' TRIGGER ob3.trg32 AFTER INSERT ON ob3.t32 FOR EACH ROW
BEGIN
  UPDATE ob1.t14 SET salary=1000 WHERE payment_type='cash';
END;
||

--echo
--echo ### Procedure will trigger trg12 ###
CREATE PROCEDURE ob2.p22()
BEGIN
 UPDATE ob1.t12 SET join_date='2008-08-08' WHERE empcode='E250';
 SELECT * FROM ob1.v15;
END;
||

--echo ### Procedure depends on function ###
CREATE PROCEDURE ob1.p11()
BEGIN
 INSERT INTO ob2.t21 VALUES('E450', 'SUN','ab6','support');
 CREATE VIEW ob1.vp1 AS SELECT 100 AS NUMBER;
 SELECT ob1.f11();
END;||

--echo ### Function on table ###
CREATE FUNCTION ob1.f11() RETURNS INT
  RETURN (SELECT SUM(salary) FROM ob1.t14)||

--echo ### Create function with definer ###
CREATE DEFINER=tom@'%' FUNCTION ob2.f21() RETURNS INTEGER
BEGIN
  DECLARE retn INTEGER;
  SELECT NUMBER FROM ob1.vp1 INTO retn;
  RETURN retn;
END;||

--echo
--echo ## Procedure calling procedure p11 and p22, trigger and function(f21) ##   
CREATE PROCEDURE ob2.p23(srno INT)
IF srno < 0 THEN
     DELETE FROM ob1.t11 WHERE name='ab6';
    CALL ob1.p11();
ELSEIF srno=0 THEN
   INSERT INTO ob2.t23 VALUES(1),(20),(30);
ELSE
   SELECT ob2.f21();
   CALL ob2.p22();
END IF||

--echo 
--echo ### Create procedure that alters tables ###
CREATE PROCEDURE ob1.p12()
BEGIN
 ALTER TABLE ob2.t23 CONVERT TO CHARACTER SET latin7;
 ALTER TABLE ob3.tp CHANGE id a VARCHAR(4);
END;||

--echo ### Procedure that creates table and calls ob1.p12 ###
CREATE PROCEDURE ob3.p31(a CHAR(20))
BEGIN
  CREATE TABLE IF NOT EXISTS ob3.tp(id INT);
  CALL ob1.p12();
END;||

--echo
--echo ### Create procedure that drops table ###
CREATE PROCEDURE ob3.p32()
BEGIN
  DROP TABLE IF EXISTS ob3.tp;
  DROP VIEW ob1.vp1;
END;||

DELIMITER ;||
SET GLOBAL EVENT_SCHEDULER=ON;
CREATE DEFINER=tom@'%' EVENT ob3.e31 ON SCHEDULE AT NOW()
 ON COMPLETION PRESERVE
 DO INSERT INTO ob1.t14 VALUES('cash',0);

--echo
--echo ### Create an event that will fire trigger trg12 ###
CREATE EVENT ob2.e21 ON SCHEDULE AT NOW() ON COMPLETION PRESERVE
DO DELETE FROM ob2.t23 WHERE A=3;

--echo
--echo ### Create an event using definer clause ###
CREATE DEFINER=tom@'%' EVENT ob3.ev ON SCHEDULE AT CURRENT_TIMESTAMP
  ON COMPLETION PRESERVE DISABLE
  DO INSERT INTO ob3.log(msg) SELECT m FROM msg LIMIT 1; 
sleep 1;

DELIMITER ||;
--echo ### Create procedure to check objects in all databases ###

CREATE PROCEDURE test.show_objects(db CHAR(10))
BEGIN
SELECT TABLE_NAME, TABLE_TYPE FROM information_schema.tables
    WHERE TABLE_SCHEMA = db;
(SELECT routine_name , routine_type FROM information_schema.routines
    WHERE routine_schema = db)
UNION (SELECT event_name, 'EVENT' FROM information_schema.events
    WHERE event_schema = db)
UNION (SELECT trigger_name, 'TRIGGER' FROM information_schema.triggers
    WHERE trigger_schema = db) ORDER BY routine_name, routine_type;
END;||

--echo ### Procedure that will fire an event by enabling it ###

CREATE PROCEDURE ob3.fire(msg char(32)) 
BEGIN 
 UPDATE ob3.msg SET m=msg;
 ALTER DEFINER=tom@'%' EVENT ob3.ev ENABLE;
END;||
DELIMITER ;||
CALL ob3.fire('user1 created');

# Excercise all objects

# Verify event is fired
SELECT * FROM ob2.t23; # A=3 will be deleted
SELECT * FROM ob1.t13;
SELECT * FROM ob3.t32;
 
# Excercise procedure p23
# p23(srno<0) will call procedure p11 -->create vp1 and calls f11()
# Function f11 will show sum(salary) from t14
#
CALL ob2.p23(-2);
SELECT * FROM ob1.t14;
SELECT * FROM ob1.vp1;
SELECT * FROM ob1.t11; # ab6 value will be deleted.
SELECT * FROM ob2.t21; # New value will be added 'ab6'

#
# p23(srno=0) will trigger trg23a(by inserting values in t23) which
# inturn will call another procedure p21
CALL ob2.p23(0);

# t23 table will be added with 3 new values of 1, 20 and 30.
SELECT * FROM ob2.t23 ORDER BY A;
SELECT * FROM ob2.t24;

# Trigger trg23a will insert values in t13 and t14
# t13 and t14 will have 3 new values
SELECT * FROM ob1.t13;
SELECT * FROM ob1.t14;
# Function f11 will show sum(salary) from ob1.t14
SELECT ob1.f11();

# select ob1.p21 should show 11
SELECT @ob2.p21;

# p23(srno > 0) will call function f21 and p22
# Procedure p22 will call trigger trg12 (by updating table t12)
# Trigger trg12 will also trigger trg11 by inserting values in t11
# Trigger trg11 in turn will trigger trg23b by deleting values from t23
CALL ob2.p23(10);

# p22 will update table t12. The join_date column is updated for id=18
# we will check all the dependencies of table t12
SELECT * FROM ob1.t12;
SELECT * FROM ob1.v11;
SELECT * FROM ob1.v18;
SELECT * FROM ob1.v16;
SELECT * FROM ob2.v24;

# Update of table t12 will trigger trg12
# Table t11 will include additional row with id=22
SELECT * FROM ob1.t11;
SELECT * FROM ob1.v11;
SELECT * FROM ob1.v12;
SELECT * FROM ob1.v18;
SELECT * FROM ob1.v17;
SELECT * FROM ob2.v23;

# Inserting values in t11 will trigger trg11
# Values < 2 will be deleted from table t23
SELECT * FROM ob2.t23 ORDER BY A;
SELECT * FROM ob2.t24;

# Deletion of data t23 will trigger trg23b
SELECT * FROM ob1.t13;
SELECT * FROM ob1.v16;
SELECT * FROM ob3.t32;
SELECT * FROM ob3.t31;

# Verify that insertion in t32 triggers trg32
SELECT * FROM ob1.t14 WHERE payment_type='cash';

# p31 will create table tp and calls procedure p12 which inturn
# alters tables tp and t23
CALL ob3.p31('TEST');
SHOW CREATE TABLE ob3.tp;
SHOW CREATE TABLE ob2.t23;
SHOW CREATE TABLE ob3.tp;

#
# BUG#43549 This portion disabled because the firing of the event is
#           non-deterministic.
#
# Verify event ob3.ev is fired
#SELECT * FROM ob3.log;

# Checking tables and other objects in databases.
CALL show_objects('ob1');
CALL show_objects('ob2');
CALL show_objects('ob3');

# Perform backup database of all databases and individual database

--replace_column 1 #
BACKUP DATABASE ob1, ob2, ob3 TO 'ob.bak';
--replace_column 1 # 
BACKUP DATABASE ob1 TO 'ob1.bak';
--replace_column 1 #
BACKUP DATABASE ob2 TO 'ob2.bak';
# Drop database.
DROP DATABASE ob2;
--echo restore ob2 database and check all objects are included 
--replace_column 1 # 
RESTORE FROM 'ob2.bak';

# Checking tables and other objects in databases are intact
SHOW DATABASES LIKE 'ob%';
CALL test.show_objects('ob1');
CALL test.show_objects('ob2');
CALL test.show_objects('ob3');

# Excercise objects

# Verify event ob3.ev is fired
CALL ob3.fire('user2 created');

# p32 will drop view vp1 and table tp
CALL ob3.p32();

# Excercise procedure p23 that calls p11 and inturn selects from f11
CALL ob2.p23(-4);
SELECT * FROM ob1.vp1; #vp1 will be created by ob1.p11
SELECT * FROM ob2.t21; #New value ab6 will be inserted

CALL ob2.p23(0);

# t23 table will be added with 3 new values of 1, 20 and 30.
SELECT * FROM ob2.t23 ORDER BY A;
SELECT * FROM ob2.t24;

# trg23a will be triggered by insertion of values in t23
SELECT * FROM ob1.t13;
SELECT * FROM ob1.t14;
SELECT ob1.f11();
# select ob1.p21 should show 11
SELECT @ob2.p21;

# p23(srno > 0) will call function f21 and p22
# Procedure p22 will call trigger trg12
# Trigger trg12 will also trigger trg11 which in turn will trigger trg23b
CALL ob2.p23(10);

# p22 will update table t12. The join_date column is updated for id=18
# we will check all the dependencies of table t12.
SELECT * FROM ob1.t12;
SELECT * FROM ob1.v11;
SELECT * FROM ob1.v18;
SELECT * FROM ob1.v16;

# When trigger trg12 is fired, t11 will include additional row with id=22
SELECT * FROM ob1.t11;
SELECT * FROM ob1.v11;
SELECT * FROM ob1.v12;
SELECT * FROM ob1.v18;
SELECT * FROM ob1.v17;
SELECT * FROM ob2.v23;

# Inserting values in t11 will trigger trg11
# Values < 2 will be deleted from table t23.
SELECT * FROM ob2.t23 ORDER BY A;

# Deletion of data t23 will trigger trg23b
SELECT * FROM ob1.t13;
SELECT * FROM ob3.t32;
SELECT * FROM ob1.v16;
SELECT * FROM ob3.t31;
SELECT * FROM ob1.v14;

# p31 will create table tp and calls procedure p12 which inturn alters tables.

CALL ob3.p31('TEST');
SHOW CREATE TABLE ob3.tp;
SHOW CREATE TABLE ob2.t23;
SHOW CREATE TABLE ob3.tp;

#
# BUG#43549 This portion disabled because the firing of the event is
#           non-deterministic.
#
#SELECT * FROM ob3.log;

--echo
--echo CREATE DEPENDENT TESTS
--echo ======================
#
# Check the response of backup database operation, if create-dependent 
# objects are missing.
#

# The following test scenarios is already covered in backup_views.test.
# 1. Drop the base table(ob1.t11) in which a view(ob1.v11) depends
# 2. Drop base table(of different DB) in which view depends 
# Therefore we will not cover this scenario in this test.

--echo
--echo # Drop view(ob1.v12), table(ob1.t12) in which a view(v18) depends.

DROP TABLE ob1.t12;
DROP VIEW ob1.v12;
--error ER_BACKUP_CATALOG_ADD_VIEW
BACKUP DATABASE ob1 TO 'ob1_missing.bak'; 
--replace_column 1 #
RESTORE FROM 'ob.bak' OVERWRITE;
SELECT * FROM ob1.v12;
SELECT * FROM ob1.t12;
SELECT * FROM ob1.v18;

--error 0,1
--remove_file $bdir/ob1_missing.bak

--echo
--echo # Drop view(ob1.v12) in which a view(v21) depends.

DROP VIEW ob1.v12;
--error ER_BACKUP_CATALOG_ADD_VIEW
BACKUP DATABASE ob2 TO 'ob2_missing.bak'; 
--replace_column 1 #
RESTORE FROM 'ob.bak' OVERWRITE;
SELECT * FROM ob1.v12;
SELECT * FROM ob2.v21;

--error 0,1
--remove_file $bdir/ob2_missing.bak

--echo
--echo USE DEPENDENT TESTS
--echo ===================
#
# Use dependency tests. Check the response of backup database operation,
# if use-dependent objects are missing.
#

--echo
--echo # Drop user(tom) in which view(ob1.v11) depends.
# Because of bug#43168, BACKUP will fail with ER_BACKUP_CATALOG_ADD_VIEW when
# trying to save ob1.v11. Once this is fixed, BACKUP and RESTORE will succeed
# and this scenario can be tested like all the others, using the following
# commands. 

#Let $db=ob1;
#Let $drop_object= USER tom@'%';
#--source suite/backup/include/objects_dependency_use.inc 
#--error ER_NO_SUCH_USER
#SELECT * FROM ob1.v11;
#CREATE USER tom@'%';
#GRANT ALL ON *.* TO tom@'%';
#SELECT * FROM ob1.v11;
# 
# The above commands should be enabled when bug#43168 fixed and the lines
# until '======' mark, should be removed. 
DROP USER tom@'%';
--error ER_BACKUP_CATALOG_ADD_VIEW
BACKUP DATABASE ob1 TO 'ob1_missing.bak';
CREATE USER tom@'%';
GRANT ALL ON *.* TO tom@'%';
# ======

--echo
--echo # Drop user in which procedure(ob2.p21) and function(ob2.f21)depends.

Let $db=ob2;
Let $drop_object= USER tom@'%';
--source suite/backup/include/objects_dependency_use.inc
SHOW CREATE PROCEDURE ob2.p21;
SHOW CREATE FUNCTION ob2.f21;
--error ER_NO_SUCH_USER
SELECT ob2.f21();
--error ER_NO_SUCH_USER
CALL ob2.p21(20, @ob2.p13);
CREATE USER tom@'%';
GRANT ALL ON *.* TO tom@'%';

--echo
--echo # Drop user in which trigger(trg32) and event(ev) depends on.

Let $db=ob3;
Let $drop_object= USER tom@'%';
--source suite/backup/include/objects_dependency_use.inc
SHOW CREATE TRIGGER ob3.trg32;
--echo Fire trigger trgu
--error ER_NO_SUCH_USER
INSERT INTO ob3.t32 VALUES(98);
SELECT * FROM ob1.t14;
SELECT * FROM ob1.t11;
--replace_regex /[0000-9999]+/#/
CALL ob3.fire('no user');
sleep 1;
CREATE USER tom@'%';
GRANT ALL ON *.* TO tom@'%';
INSERT INTO ob3.t32 VALUES(97);
SELECT * FROM ob3.t32;
SELECT * FROM ob1.t14;

#
# BUG#43549 This portion disabled because the firing of the event is
#           non-deterministic.
#
#SELECT * FROM ob3.log;

# Note that we will see both values 97 and 98. trg32 will not update value
# in t14 if user is not present.
# Note that if user is not present, event will not be fired

--echo
--echo # Drop the procedure(ob1.p11) in which procedure(ob2.p23) depends
Let $drop_object= PROCEDURE ob1.p11;
Let $db=ob2;
--source suite/backup/include/objects_dependency_use.inc
--error ER_SP_DOES_NOT_EXIST
CALL ob1.p11(-1); 

--echo
--echo # Drop the table(ob2.t23) in which a procedure(ob2.p23) depends
--echo NOTE: This is also test of procedure firing trigger.
Let $drop_object= TABLE ob2.t23;
Let $db=ob2;
--source suite/backup/include/objects_dependency_use.inc
--error ER_NO_SUCH_TABLE
CALL ob2.p23(0);

--echo
--echo # Procedure that alters table(ob1.p12 alter ob2.t23).

Let $drop_object= TABLE ob2.t23;
Let $db=ob1;
--source suite/backup/include/objects_dependency_use.inc
--error ER_NO_SUCH_TABLE
CALL ob1.p12();

--echo
--echo # Procedure that drops table(ob3.p32 drops ob3.tp).

Let $drop_object= TABLE ob3.tp;
Let $db=ob3;
--source suite/backup/include/objects_dependency_use.inc
CALL ob3.p32();
--replace_column 2 #
SHOW WARNINGS;

--echo
--echo # Function that selects from table(ob1.f11 on ob1.t14)

Let $drop_object= TABLE ob1.t14;
Let $db=ob1;
--source suite/backup/include/objects_dependency_use.inc
--error ER_NO_SUCH_TABLE
SELECT ob1.f11();

--echo
--echo # Trigger that depends on table.(ob3.trg32 on ob1.t14)

Let $drop_object= TABLE ob1.t14;
Let $db=ob3;
--source suite/backup/include/objects_dependency_use.inc
--error ER_NO_SUCH_TABLE
INSERT INTO ob3.t32 VALUES(200);

--echo
--echo # Trigger that calls procedure(ob2.trg23a on ob2.p21)

Let $drop_object= PROCEDURE ob2.p21;
Let $db=ob2;
--source suite/backup/include/objects_dependency_use.inc
--error ER_SP_DOES_NOT_EXIST
INSERT INTO ob2.t23 VALUES(200);

--echo
--echo # Procedure that selects values from stored function(ob1.p11 on ob1.f11)
Let $drop_object= FUNCTION ob1.f11;
Let $db=ob1;
--source suite/backup/include/objects_dependency_use.inc
DROP VIEW ob1.vp1;
--error ER_SP_DOES_NOT_EXIST
eval CALL ob1.p11();

--echo # Event(ob3.ev) that depends on table(ob3.msg)

Let $drop_object= TABLE ob3.msg;
Let $db=ob3;
--source suite/backup/include/objects_dependency_use.inc
--replace_column 4 # 5 # 6 #
--query_vertical SHOW CREATE EVENT ob3.ev;
# Try to fire event
--error ER_NO_SUCH_TABLE
CALL ob3.fire('user3 created');

#
# BUG#43549 This portion disabled because the firing of the event is
#           non-deterministic.
#
#SELECT * FROM ob3.log;

--echo # Test cleanup section

REVOKE ALL ON *.* FROM tom@'%';
DROP USER tom@'%';
FLUSH PRIVILEGES;
DROP DATABASE ob1;
DROP DATABASE ob2;
DROP DATABASE ob3;
DROP PROCEDURE test.show_objects;
SET GLOBAL EVENT_SCHEDULER=OFF;
--remove_file $bdir/ob.bak
--remove_file $bdir/ob1.bak
--remove_file $bdir/ob2.bak
