Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Altering non existing trigger with OLD. variable cause "Column unknown" instead "Trigger not found" [CORE5941] #6197

Open
firebird-automations opened this issue Oct 15, 2018 · 4 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @livius2

try altering not existing trigger

SET TERM ^ ;
ALTER TRIGGER XYZXX
ACTIVE AFTER DELETE POSITION 1000
AS
DECLARE VARIABLE VAR_OLD_UMOWA_ID CHAR(7);
begin

END^
SET TERM ; ^

as expected:

Engine Code : 335544351
Engine Message :
unsuccessful metadata update
ALTER TRIGGER XYZXX failed
Trigger XYZXX not found

--------------------------------------------------------------------------------

add reference to OLD variable in the not existing trigger

SET TERM ^ ;
ALTER TRIGGER XYZXX
ACTIVE AFTER DELETE POSITION 1000
AS
DECLARE VARIABLE VAR_OLD_UMOWA_ID CHAR(7);
begin
VAR_OLD_UMOWA_ID = OLD.UMOWA_ID;
END^
SET TERM ; ^

Engine Code : 335544351
Engine Message :
unsuccessful metadata update
ALTER TRIGGER XYZXX failed
Dynamic SQL Error
SQL error code = -206
Column unknown
OLD.UMOWA_ID

----------------------------------------------------------------

but the main reason is that this trigger does not exists at all
the body does not matter here

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

Karol,

Although the ALTER is the "operation", the fact that the body of the trigger is evaluated/verified before the existence of the trigger is (IMO) not significant. In fact, it can be thought of as logical, since the command syntax must be valid before executed.

The first example is syntactically valid/correct, so the command is attempted, which is why the "not found" is reported.

@firebird-automations
Copy link
Collaborator Author

Commented by: @livius2

Sean,

i understand your point. Yes, whole script must be valid.
But how it can be validated if there is no context? You know, alter trigger does not have name of the table.
Then to validate something, you must refer to table first to see if OLD.FIELD exists in that table.

Trigger existence must be first step here.

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

Karol,

I also take your point, but trigger existence does not need to be the first step.

The fact that the error refers to "column unknown" can be considered as pointer to the user that their base syntax is missing the "... FOR {relation name}". But that fails to consider the DB triggers syntax for which there is no "... FOR {relation name}".

@firebird-automations
Copy link
Collaborator Author

Commented by: @livius2

Sean,
another good point, but i this particular example,
error message refer exactly that FB know that it work with trigger. It know exactly with which one

unsuccessful metadata update
ALTER TRIGGER XYZXX failed
Dynamic SQL Error

FB know also that this is "ALTER" operation. For alter operation first should be check existence of the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant