rpl_row_sp005.test 3.21 KB
Newer Older
1 2 3 4 5 6 7 8
#############################################################################
# Original Author: JBM                                                      #
# Original Date: Aug/15/2005                                                #
# Updated: Aug/29/2005: Removed sleeps                                      #     
#############################################################################
# Test: Tests SPs with cursors, flow logic, and alter sp. In addition the   #
#       tests SPs with insert and update operations.                        #
#############################################################################
9 10
# 2006-02-08 By JBM added ORDER BY for use with NDB engine
#############################################################################
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

# Includes
-- source include/have_binlog_format_row.inc
-- source include/master-slave.inc


# Begin clean up test section
connection master;
--disable_warnings
DROP PROCEDURE IF EXISTS test.p1;
DROP PROCEDURE IF EXISTS test.p2;
DROP TABLE IF EXISTS test.t2;
DROP TABLE IF EXISTS test.t1;
DROP TABLE IF EXISTS test.t3;
--enable_warnings
# End of cleanup

# Begin test section 1
CREATE TABLE IF NOT EXISTS test.t1(id INT, data CHAR(16),PRIMARY KEY(id));
CREATE TABLE IF NOT EXISTS test.t2(id2 INT,PRIMARY KEY(id2));
CREATE TABLE IF NOT EXISTS test.t3(id3 INT,PRIMARY KEY(id3), c CHAR(16));

delimiter |;
CREATE PROCEDURE test.p1()
BEGIN
DECLARE done INT DEFAULT 0;
  DECLARE spa CHAR(16);
  DECLARE spb,spc INT;
39 40
  DECLARE cur1 CURSOR FOR SELECT id,data FROM test.t1 ORDER BY id;
  DECLARE cur2 CURSOR FOR SELECT id2 FROM test.t2 ORDER BY id2;
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

  OPEN cur1;
  OPEN cur2;

  REPEAT
    FETCH cur1 INTO spb, spa;
    FETCH cur2 INTO spc;
    IF NOT done THEN
       IF spb < spc THEN
          INSERT INTO test.t3 VALUES (spb,spa);
       ELSE
          INSERT INTO test.t3 VALUES (spc,spa);
       END IF;
    END IF;
  UNTIL done END REPEAT;

  CLOSE cur1;
  CLOSE cur2;
END|
CREATE PROCEDURE test.p2()
BEGIN
  INSERT INTO test.t1 VALUES (4,'MySQL'),(20,'ROCKS'),(11,'Texas'),(10,'kyle');
  INSERT INTO test.t2 VALUES (4),(2),(1),(3);
  UPDATE test.t1 SET id=id+4 WHERE id=4;
END|
delimiter ;|

let $message=< ---- Master selects-- >;
--source include/show_msg.inc
CALL test.p2();
72 73
SELECT * FROM test.t1 ORDER BY id;
SELECT * FROM test.t2 ORDER BY id2;
74 75 76 77 78 79

let $message=< ---- Slave selects-- >;
--source include/show_msg.inc
save_master_pos;
connection slave;
sync_with_master;
80 81
SELECT * FROM test.t1 ORDER BY id;
SELECT * FROM test.t2 ORDER BY id2;
82 83 84 85 86

let $message=< ---- Master selects-- >;
--source include/show_msg.inc
connection master;
CALL test.p1();
87 88
let $wait_condition= SELECT COUNT(*) = 4 FROM t3;
--source include/wait_condition.inc
89
save_master_pos;
90
SELECT * FROM test.t3 ORDER BY id3;
91 92 93 94

let $message=< ---- Slave selects-- >;
--source include/show_msg.inc
connection slave;
95
sync_with_master;
96
SELECT * FROM test.t3 ORDER BY id3;
97 98 99 100 101 102

connection master;

ALTER PROCEDURE test.p1 MODIFIES SQL DATA;
#show binlog events;

103 104 105
# Cleanup

connection master;
106 107 108 109 110
DROP PROCEDURE IF EXISTS test.p1;
DROP PROCEDURE IF EXISTS test.p2;
DROP TABLE IF EXISTS test.t1;
DROP TABLE IF EXISTS test.t2;
DROP TABLE IF EXISTS test.t3;
111
sync_slave_with_master;
112 113

# End of 5.0 test case