mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
aed9c656a9
This patch adds PACKAGE support with SQL/PSM dialect for sql_mode=DEFAULT: - CREATE PACKAGE - DROP PACKAGE - CREATE PACKAGE BODY - DROP PACKAGE BODY - Package function and procedure invocation from outside of the package: -- using two step identifiers SELECT pkg.f1(); CALL pkg.p1() -- using three step identifiers SELECT db.pkg.f1(); CALL db.pkg.p1(); This is a non-standard MariaDB extension. However, later this code can be used to implement the SQL Standard and DB2 dialects of CREATE MODULE.
260 lines
4.9 KiB
Text
260 lines
4.9 KiB
Text
#
|
|
# MDEV-32101 CREATE PACKAGE [BODY] for sql_mode=DEFAULT
|
|
#
|
|
CREATE PACKAGE pkg1
|
|
PROCEDURE p1();
|
|
FUNCTION f1() RETURNS INT;
|
|
END;
|
|
$$
|
|
CREATE PACKAGE BODY pkg1
|
|
PROCEDURE p1()
|
|
BEGIN SELECT 1;
|
|
END;
|
|
FUNCTION f1() RETURNS INT RETURN 1;
|
|
END;
|
|
$$
|
|
SHOW PROCEDURE CODE pkg1.p1;
|
|
Pos Instruction
|
|
0 stmt 0 "SELECT 1"
|
|
SHOW FUNCTION CODE pkg1.f1;
|
|
Pos Instruction
|
|
0 freturn int 1
|
|
SHOW PACKAGE BODY CODE pkg1;
|
|
Pos Instruction
|
|
DROP PACKAGE pkg1;
|
|
CREATE PACKAGE pkg1
|
|
PROCEDURE p1();
|
|
FUNCTION f1() RETURNS INT;
|
|
PROCEDURE p2show();
|
|
PROCEDURE p2public();
|
|
FUNCTION f2public() RETURNS TEXT;
|
|
END;
|
|
$$
|
|
CREATE PACKAGE BODY pkg1
|
|
DECLARE a INT DEFAULT 10;
|
|
PROCEDURE p1()
|
|
BEGIN
|
|
DECLARE b INT DEFAULT 20;
|
|
SET b=a;
|
|
SET b=a+1;
|
|
SET a=b;
|
|
SET a=b+1;
|
|
SET a=a+1;
|
|
SET @a=@a+2;
|
|
SELECT f1() FROM DUAL;
|
|
END;
|
|
FUNCTION f1() RETURNS INT
|
|
BEGIN
|
|
RETURN a;
|
|
END;
|
|
PROCEDURE p2private()
|
|
BEGIN
|
|
SELECT 'This is p2private';
|
|
END;
|
|
PROCEDURE p2public()
|
|
BEGIN
|
|
SELECT 'This is p2public';
|
|
END;
|
|
FUNCTION f2private() RETURNS TEXT
|
|
BEGIN
|
|
RETURN 'This is f2private';
|
|
END;
|
|
FUNCTION f2public() RETURNS TEXT
|
|
BEGIN
|
|
RETURN 'This is f2public';
|
|
END;
|
|
PROCEDURE p2show()
|
|
BEGIN
|
|
SHOW FUNCTION CODE f2public;
|
|
SHOW FUNCTION CODE f2private;
|
|
SHOW PROCEDURE CODE p2public;
|
|
SHOW PROCEDURE CODE p2private;
|
|
SHOW PROCEDURE CODE p2show;
|
|
END;
|
|
-- Initialization section
|
|
SET a=a+1;
|
|
BEGIN
|
|
DECLARE b INT;
|
|
SET b=a;
|
|
SET b=a+1;
|
|
SET a=b;
|
|
SET a=b+1;
|
|
END;
|
|
END;
|
|
$$
|
|
SHOW PROCEDURE CODE pkg1.p1;
|
|
Pos Instruction
|
|
0 set b@0 20
|
|
1 set b@0 PACKAGE_BODY.a@0
|
|
2 set b@0 PACKAGE_BODY.a@0 + 1
|
|
3 set PACKAGE_BODY.a@0 b@0
|
|
4 set PACKAGE_BODY.a@0 b@0 + 1
|
|
5 set PACKAGE_BODY.a@0 PACKAGE_BODY.a@0 + 1
|
|
6 stmt 31 "SET @a=@a+2"
|
|
7 stmt 0 "SELECT f1() FROM DUAL"
|
|
SHOW FUNCTION CODE pkg1.f1;
|
|
Pos Instruction
|
|
0 freturn int PACKAGE_BODY.a@0
|
|
SHOW PACKAGE BODY CODE pkg1;
|
|
Pos Instruction
|
|
0 set a@0 10
|
|
1 set a@0 a@0 + 1
|
|
2 set b@1 NULL
|
|
3 set b@1 a@0
|
|
4 set b@1 a@0 + 1
|
|
5 set a@0 b@1
|
|
6 set a@0 b@1 + 1
|
|
CALL pkg1.p2show;
|
|
Pos Instruction
|
|
0 freturn blob 'This is f2public'
|
|
Pos Instruction
|
|
0 freturn blob 'This is f2private'
|
|
Pos Instruction
|
|
0 stmt 0 "SELECT 'This is p2public'"
|
|
Pos Instruction
|
|
0 stmt 0 "SELECT 'This is p2private'"
|
|
Pos Instruction
|
|
0 stmt 110 "SHOW FUNCTION CODE f2public"
|
|
1 stmt 110 "SHOW FUNCTION CODE f2private"
|
|
2 stmt 109 "SHOW PROCEDURE CODE p2public"
|
|
3 stmt 109 "SHOW PROCEDURE CODE p2private"
|
|
4 stmt 109 "SHOW PROCEDURE CODE p2show"
|
|
DROP PACKAGE pkg1;
|
|
CREATE TABLE t1 (a INT);
|
|
CREATE PACKAGE pkg1
|
|
PROCEDURE p1();
|
|
END;
|
|
$$
|
|
CREATE PACKAGE BODY pkg1
|
|
DECLARE a TYPE OF t1.a DEFAULT 10;
|
|
PROCEDURE p1()
|
|
BEGIN
|
|
DECLARE b TYPE OF t1.a DEFAULT 20;
|
|
SET b=a;
|
|
SET b=a+1;
|
|
SET b=b+1;
|
|
SET a=b;
|
|
SET a=b+1;
|
|
SET a=a+1;
|
|
END;
|
|
-- Initialization section
|
|
SET a=a+1;
|
|
BEGIN
|
|
DECLARE b TYPE OF t1.a;
|
|
SET b=a;
|
|
SET b=a+1;
|
|
SET a=b;
|
|
SET a=b+1;
|
|
END;
|
|
END;
|
|
$$
|
|
SHOW PROCEDURE CODE pkg1.p1;
|
|
Pos Instruction
|
|
0 set b@0 20
|
|
1 set b@0 PACKAGE_BODY.a@0
|
|
2 set b@0 PACKAGE_BODY.a@0 + 1
|
|
3 set b@0 b@0 + 1
|
|
4 set PACKAGE_BODY.a@0 b@0
|
|
5 set PACKAGE_BODY.a@0 b@0 + 1
|
|
6 set PACKAGE_BODY.a@0 PACKAGE_BODY.a@0 + 1
|
|
SHOW PACKAGE BODY CODE pkg1;
|
|
Pos Instruction
|
|
0 set a@0 10
|
|
1 set a@0 a@0 + 1
|
|
2 set b@1 NULL
|
|
3 set b@1 a@0
|
|
4 set b@1 a@0 + 1
|
|
5 set a@0 b@1
|
|
6 set a@0 b@1 + 1
|
|
DROP PACKAGE pkg1;
|
|
DROP TABLE t1;
|
|
CREATE PACKAGE pkg1
|
|
PROCEDURE p1();
|
|
END;
|
|
$$
|
|
CREATE PACKAGE BODY pkg1
|
|
DECLARE a ROW(a INT,b TEXT) DEFAULT ROW(10,'x10');
|
|
PROCEDURE p1()
|
|
BEGIN
|
|
DECLARE b ROW(a INT,b TEXT) DEFAULT ROW(20,'x20');
|
|
SET b=a;
|
|
SET a=b;
|
|
SET b.a=a.a+1;
|
|
SET a.a=b.a+1;
|
|
SET a.a=a.a+1;
|
|
END;
|
|
-- Initialization section
|
|
SET a.a:=a.a+1;
|
|
BEGIN
|
|
DECLARE b ROW(a INT,b TEXT) DEFAULT ROW(30,'x30');
|
|
SET b=a;
|
|
SET b.a=a.a+1;
|
|
SET a=b;
|
|
SET a.a=b.a+1;
|
|
END;
|
|
END;
|
|
$$
|
|
SHOW PROCEDURE CODE pkg1.p1;
|
|
Pos Instruction
|
|
0 set b@0 (20,'x20')
|
|
1 set b@0 PACKAGE_BODY.a@0
|
|
2 set PACKAGE_BODY.a@0 b@0
|
|
3 set b.a@0[0] PACKAGE_BODY.a.a@0[0] + 1
|
|
4 set PACKAGE_BODY.a.a@0[0] b.a@0[0] + 1
|
|
5 set PACKAGE_BODY.a.a@0[0] PACKAGE_BODY.a.a@0[0] + 1
|
|
SHOW PACKAGE BODY CODE pkg1;
|
|
Pos Instruction
|
|
0 set a@0 (10,'x10')
|
|
1 set a.a@0[0] a.a@0[0] + 1
|
|
2 set b@1 (30,'x30')
|
|
3 set b@1 a@0
|
|
4 set b.a@1[0] a.a@0[0] + 1
|
|
5 set a@0 b@1
|
|
6 set a.a@0[0] b.a@1[0] + 1
|
|
DROP PACKAGE pkg1;
|
|
CREATE TABLE t1 (a INT, b TEXT);
|
|
CREATE PACKAGE pkg1
|
|
PROCEDURE p1();
|
|
END;
|
|
$$
|
|
CREATE PACKAGE BODY pkg1
|
|
DECLARE a ROW TYPE OF t1 DEFAULT ROW(10,'x10');
|
|
PROCEDURE p1()
|
|
BEGIN
|
|
DECLARE b ROW TYPE OF t1 DEFAULT ROW(20,'x20');
|
|
SET b=a;
|
|
SET a=b;
|
|
SET b.a=a.a+1;
|
|
SET a.a=b.a+1;
|
|
SET a.a=a.a+1;
|
|
END;
|
|
-- Initialization section
|
|
SET a.a=a.a+1;
|
|
BEGIN
|
|
DECLARE b ROW TYPE OF t1 DEFAULT ROW(30,'x30');
|
|
SET b=a;
|
|
SET b.a=a.a+1;
|
|
SET a=b;
|
|
SET a.a=b.a+1;
|
|
END;
|
|
END;
|
|
$$
|
|
SHOW PROCEDURE CODE pkg1.p1;
|
|
Pos Instruction
|
|
0 set b@0 (20,'x20')
|
|
1 set b@0 PACKAGE_BODY.a@0
|
|
2 set PACKAGE_BODY.a@0 b@0
|
|
3 set b.a@0["a"] PACKAGE_BODY.a.a@0["a"] + 1
|
|
4 set PACKAGE_BODY.a.a@0["a"] b.a@0["a"] + 1
|
|
5 set PACKAGE_BODY.a.a@0["a"] PACKAGE_BODY.a.a@0["a"] + 1
|
|
SHOW PACKAGE BODY CODE pkg1;
|
|
Pos Instruction
|
|
0 set a@0 (10,'x10')
|
|
1 set a.a@0["a"] a.a@0["a"] + 1
|
|
2 set b@1 (30,'x30')
|
|
3 set b@1 a@0
|
|
4 set b.a@1["a"] a.a@0["a"] + 1
|
|
5 set a@0 b@1
|
|
6 set a.a@0["a"] b.a@1["a"] + 1
|
|
DROP PACKAGE pkg1;
|
|
DROP TABLE t1;
|