[MDEV-32101] CREATE PACKAGE [BODY] for sql_mode=DEFAULT Created: 2023-09-05  Updated: 2024-02-08  Resolved: 2023-12-22

Status: Closed
Project: MariaDB Server
Component/s: Stored routines
Fix Version/s: 11.4.1

Type: New Feature Priority: Critical
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: Preview_11.4

Issue Links:
Blocks
is blocked by MDEV-32219 Shift/reduce grammar conflict: GRANT ... Closed
is blocked by MDEV-32220 sql_yacc.yy: unify the drop_routine rule Closed
PartOf
Relates
relates to MDEV-10591 Oracle-style packages Closed
relates to MDEV-33384 ALTER PACKAGE [ BODY ] statement Open
relates to MDEV-33385 Support package routines in metadata ... Open
relates to MDEV-33386 Wrong error message on `GRANT .. ON P... Closed
relates to MDEV-33395 I_S views to list stored packages Open
relates to MDEV-33382 Documentation fixes for CREATE PACKAG... Open
relates to MDEV-33399 Package variables return a wrong resu... Open
relates to MDEV-33402 Calling a private package routine by ... Open
relates to MDEV-33403 Document stored packages overview Open

 Description   

Let's allow the CREATE PACKAGE [BODY] statement in sql_mode=DEFAULT.

It will work almost like the same statement for sql_mode=ORACLE, but will use SQL/PSM dialect instead of PL/SQL dialect in all parts of the statement, including:

  • routine declarations
  • variable declatations
  • initialization section
  • etc

For example:

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;
 
  -- package initialization section
  SET a=a-b;
END;
$$
DELIMITER ;

Invocation examples:

MariaDB [test]> SELECT pkg.f1();
+----------+
| pkg.f1() |
+----------+
|        1 |
+----------+

MariaDB [test]> CALL pkg.p1();
+---------------+
| CURRENT_USER  |
+---------------+
| bar@localhost |
+---------------+

In the future we can add CREATE MODULE on top of this work, for sql_mode=DB2, for IBM DB2 compatibility.



 Comments   
Comment by Alexander Barkov [ 2023-09-05 ]

serg, can you please review this patch:
https://github.com/MariaDB/server/commit/025ca90e5df89ffa28a948cbf7e037f17821cc7b
?
Thanks.

Comment by Alexander Barkov [ 2023-09-22 ]

Hello serg,

Here's a new patch version:

https://github.com/MariaDB/server/commit/28deba0a6119c64020970e48b0994804d88688a1

Please have a look.

Comment by Ramesh Sivaraman [ 2023-12-11 ]

bar Test looks good.

Generated at Thu Feb 08 10:28:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.