summaryrefslogtreecommitdiffstats
path: root/mysql-test/main/sp-package.test
blob: 31524e3e09169f95b22707474779a0af5321d63a (plain)
1
2
3
4
5
6
7
8
9
10
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
39
40
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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 #