mariadb/mysql-test/suite/compat/oracle/r/sp-package-code.result
Alexander Barkov 5f7c764fe7 MDEV-11952 Oracle-style packages: stage#5
Backporting from bb-10.2-compatibility to bb-10.2-ext

Version: 2018-01-26

- CREATE PACKAGE [BODY] statements are now
  entirely written to mysql.proc with type='PACKAGE' and type='PACKAGE BODY'.
- CREATE PACKAGE BODY now supports IF NOT EXISTS
- DROP PACKAGE BODY now supports IF EXISTS
- CREATE OR REPLACE PACKAGE [BODY] is now supported
- CREATE PACKAGE [BODY] now support the DEFINER clause:

    CREATE DEFINER user@host PACKAGE pkg ... END;
    CREATE DEFINER user@host PACKAGE BODY pkg ... END;

- CREATE PACKAGE [BODY] now supports SQL SECURITY and COMMENT clauses, e.g.:

    CREATE PACKAGE p1 SQL SECURITY INVOKER COMMENT "comment" AS ... END;

- Package routines are now created from the package CREATE PACKAGE BODY
  statement and don't produce individual records in mysql.proc.

- CREATE PACKAGE BODY now supports package-wide variables.
  Package variables can be read and set inside package routines.
  Package variables are stored in a separate sp_rcontext,
  which is cached in THD on the first packate routine call.

- CREATE PACKAGE BODY now supports the initialization section.

- All public routines (i.e. declared in CREATE PACKAGE)
  must have implementations in CREATE PACKAGE BODY

- Only public package routines are available outside of the package

- {CREATE|DROP} PACKAGE [BODY] now respects CREATE ROUTINE and ALTER ROUTINE
  privileges

- "GRANT EXECUTE ON PACKAGE BODY pkg" is now supported

- SHOW CREATE PACKAGE [BODY] is now supported

- SHOW PACKAGE [BODY] STATUS is now supported

- CREATE and DROP for PACKAGE [BODY] now works for non-current databases

- mysqldump now supports packages

- "SHOW {PROCEDURE|FUNCTION) CODE pkg.routine" now works for package routines

- "SHOW PACKAGE BODY CODE pkg" now works (the package initialization section)

- A new package body level MDL was added

- Recursive calls for package procedures are now possible

- Routine forward declarations in CREATE PACKATE BODY are now supported.

- Package body variables now work as SP OUT parameters

- Package body variables now work as SELECT INTO targets

- Package body variables now support ROW, %ROWTYPE, %TYPE
2018-02-27 15:26:51 +04:00

245 lines
4.2 KiB
Text

SET sql_mode=ORACLE;
CREATE PACKAGE pkg1 AS
PROCEDURE p1;
FUNCTION f1 RETURN INT;
PROCEDURE p2show;
PROCEDURE p2public;
FUNCTION f2public RETURN TEXT;
END;
$$
CREATE PACKAGE BODY pkg1 AS
a INT:=10;
PROCEDURE p1 AS
b INT:=20;
BEGIN
b:=a;
b:=a+1;
a:=b;
a:=b+1;
a:=a+1;
SET @a:=@a+2;
SELECT f1() FROM DUAL;
END;
FUNCTION f1 RETURN INT AS
BEGIN
RETURN a;
END;
PROCEDURE p2private AS
BEGIN
SELECT 'This is p2private';
END;
PROCEDURE p2public AS
BEGIN
SELECT 'This is p2public';
END;
FUNCTION f2private RETURN TEXT AS
BEGIN
RETURN 'This is f2private';
END;
FUNCTION f2public RETURN TEXT AS
BEGIN
RETURN 'This is f2public';
END;
PROCEDURE p2show AS
BEGIN
SHOW FUNCTION CODE f2public;
SHOW FUNCTION CODE f2private;
SHOW PROCEDURE CODE p2public;
SHOW PROCEDURE CODE p2private;
SHOW PROCEDURE CODE p2show;
END;
BEGIN
a:=a+1;
DECLARE
b INT;
BEGIN
b:=a;
b:=a+1;
a:=b;
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
7 jump 11
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 AS
PROCEDURE p1;
END;
$$
CREATE PACKAGE BODY pkg1 AS
a t1.a%TYPE:=10;
PROCEDURE p1 AS
b t1.a%TYPE:=20;
BEGIN
b:=a;
b:=a+1;
b:=b+1;
a:=b;
a:=b+1;
a:=a+1;
END;
BEGIN
a:=a+1;
DECLARE
b t1.a%TYPE;
BEGIN
b:=a;
b:=a+1;
a:=b;
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
7 jump 11
DROP PACKAGE pkg1;
DROP TABLE t1;
CREATE PACKAGE pkg1 AS
PROCEDURE p1;
END;
$$
CREATE PACKAGE BODY pkg1 AS
a ROW(a INT,b TEXT):=ROW(10,'x10');
PROCEDURE p1 AS
b ROW(a INT,b TEXT):=ROW(20,'x20');
BEGIN
b:=a;
a:=b;
b.a:=a.a+1;
a.a:=b.a+1;
a.a:=a.a+1;
END;
BEGIN
a.a:=a.a+1;
DECLARE
b ROW(a INT,b TEXT):=ROW(30,'x30');
BEGIN
b:=a;
b.a:=a.a+1;
a:=b;
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
7 jump 11
DROP PACKAGE pkg1;
CREATE TABLE t1 (a INT, b TEXT);
CREATE PACKAGE pkg1 AS
PROCEDURE p1;
END;
$$
CREATE PACKAGE BODY pkg1 AS
a t1%ROWTYPE:=ROW(10,'x10');
PROCEDURE p1 AS
b t1%ROWTYPE:=ROW(20,'x20');
BEGIN
b:=a;
a:=b;
b.a:=a.a+1;
a.a:=b.a+1;
a.a:=a.a+1;
END;
BEGIN
a.a:=a.a+1;
DECLARE
b t1%ROWTYPE:=ROW(30,'x30');
BEGIN
b:=a;
b.a:=a.a+1;
a:=b;
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
7 jump 11
DROP PACKAGE pkg1;
DROP TABLE t1;