FirebirdSQL / firebird

Firebird server, client and tools
https://firebirdsql.org
1.26k stars 217 forks source link

Add `ALTER PACKAGE BODY` and `CRETE OR ALTER PACKAGE BODY` parse rules #8309

Closed Noremos closed 1 week ago

Noremos commented 2 weeks ago

Hello. Currently, it is possible to CREATE, ALTER, or RECREATE a PACKAGE

set autoterm;
CREATE PACKAGE TEST_PACKAGE
AS
BEGIN
    FUNCTION DUMMY() RETURNS INT;
END;

CREATE OR ALTER PACKAGE TEST_PACKAGE
AS
BEGIN
    FUNCTION DUMMY() RETURNS INT;
END;

ALTER PACKAGE TEST_PACKAGE
AS
BEGIN
    FUNCTION DUMMY() RETURNS INT;
END;

RECREATE PACKAGE TEST_PACKAGE
AS
BEGIN
    FUNCTION DUMMY() RETURNS INT;
END;

However, when it comes to a package body, some operations may fail:

set term ^;
ALTER PACKAGE BODY TEST_PACKAGE
AS
BEGIN
    FUNCTION DUMMY() RETURNS INT
    AS
    BEGIN
        RETURN 1;
    END
END^

This results in the following error message:

Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 1, column 20
-TEST_PACKAGE

This is a really confusing error message. The problem is that the PACKAGE BODY does not support the ALTER or CREATE OR ALTER statements, yet the message references the package name, which can be misleading.

I think it is worth adding this parse rules to not confuse the users. From my perspective, ALTER PACKAGE BODY is essentially equivalent to RECREATE statement, so I used the RECREATE node without changing the package code.

asfernandes commented 2 weeks ago

Please update doc/sql.extensions/README.packages.txt