summaryrefslogtreecommitdiffstats
path: root/mysql-test/main/sp-package.test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--mysql-test/main/sp-package.test140
1 files changed, 140 insertions, 0 deletions
diff --git a/mysql-test/main/sp-package.test b/mysql-test/main/sp-package.test
new file mode 100644
index 00000000..31524e3e
--- /dev/null
+++ b/mysql-test/main/sp-package.test
@@ -0,0 +1,140 @@
+--echo #
+--echo # Start of 11.4 tests
+--echo #
+
+#
+# CREATE PACKAGE for sql_mode='';
+# Resebmles SQL Standard 'CREATE MODULE'.
+#
+
+SET sql_mode='';
+
+DELIMITER $$;
+CREATE OR REPLACE PACKAGE pkg
+ PROCEDURE p1();
+ FUNCTION f1() RETURNS INT;
+END;
+$$
+DELIMITER ;$$
+
+
+DELIMITER $$;
+CREATE OR REPLACE PACKAGE BODY pkg
+ -- variable declarations
+ DECLARE a INT DEFAULT 11;
+ DECLARE b INT DEFAULT 10;
+
+ -- routine declarations
+ PROCEDURE p1()
+ BEGIN
+ SELECT CURRENT_USER;
+ END;
+ FUNCTION f1() RETURNS INT
+ BEGIN
+ RETURN a;
+ END;
+
+ -- initialization section
+ SET a=a-b;
+END;
+$$
+DELIMITER ;$$
+
+
+SHOW CREATE PACKAGE pkg;
+SHOW CREATE PACKAGE BODY pkg;
+
+CALL pkg.p1();
+SELECT pkg.f1();
+
+DROP PACKAGE pkg;
+
+
+--echo #
+--echo # MDEV-33428 Error messages ER_PACKAGE_ROUTINE_* are not good enough
+--echo #
+
+--echo #
+--echo # Routines declared in CREATE PACKAGE missing in CREATE PACKAGE BODY
+--echo #
+
+DELIMITER $$;
+CREATE PACKAGE test2
+ PROCEDURE p1();
+END;
+$$
+--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
+CREATE PACKAGE BODY test2
+ PROCEDURE p2() BEGIN SELECT 0; END;
+END;
+$$
+DELIMITER ;$$
+DROP PACKAGE test2;
+
+DELIMITER $$;
+CREATE PACKAGE test2
+ FUNCTION f1() RETURNS INT;
+END;
+$$
+--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
+CREATE PACKAGE BODY test2
+ FUNCTION f2() RETURNS INT BEGIN RETURN 10; END;
+END;
+$$
+DELIMITER ;$$
+DROP PACKAGE test2;
+
+DELIMITER $$;
+CREATE PACKAGE test2
+ PROCEDURE p1();
+END;
+$$
+--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
+CREATE PACKAGE BODY test2
+ FUNCTION p1() RETURNS INT BEGIN RETURN 10; END;
+END;
+$$
+DELIMITER ;$$
+DROP PACKAGE test2;
+
+DELIMITER $$;
+CREATE PACKAGE test2
+ PROCEDURE p1();
+END;
+$$
+--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY
+CREATE PACKAGE BODY test2
+ PROCEDURE p1(a INT) BEGIN SELECT 0; END; -- Notice different prototype
+END;
+$$
+DELIMITER ;$$
+DROP PACKAGE test2;
+
+--echo #
+--echo # Forward declarations in CREATE PACKAGE BODY with missing implementations
+--echo #
+
+DELIMITER $$;
+CREATE PACKAGE test2
+ PROCEDURE p1();
+END;
+$$
+--error ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED
+CREATE PACKAGE BODY test2
+ PROCEDURE p1() BEGIN SELECT 0; END;
+ PROCEDURE p2();
+END;
+$$
+--error ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED
+CREATE PACKAGE BODY test2
+ FUNCTION f1() RETURNS INT;
+ PROCEDURE p1() BEGIN SELECT 0; END;
+END;
+$$
+DELIMITER ;$$
+DROP PACKAGE test2;
+
+
+--echo #
+--echo # End of 11.4 tests
+--echo #