Navigation Menu

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

The trigger together with the operator MERGE if in a condition of connection ON contains new isn't compiled [CORE3753] #4097

Closed
firebird-automations opened this issue Feb 5, 2012 · 12 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @sim1984

Is related to QA572

The trigger together with the operator MERGE if in a condition of connection ON contains new isn't compiled

CREATE TABLE HORSE (
CODE_HORSE INTEGER NOT NULL,
CODE_FATHER INTEGER DEFAULT -2 NOT NULL,
CODE_MOTHER INTEGER DEFAULT -3 NOT NULL,
NAME VARCHAR(50)
);

ALTER TABLE HORSE ADD CONSTRAINT PK_HORSE PRIMARY KEY (CODE_HORSE);

CREATE TABLE COVER (
CODE_COVER INTEGER NOT NULL,
CODE_FATHER INTEGER NOT NULL,
CODE_MOTHER INTEGER NOT NULL,
CODE_HORSE INTEGER NOT NULL
);

ALTER TABLE COVER ADD CONSTRAINT PK_COVER PRIMARY KEY (CODE_COVER);
ALTER TABLE COVER ADD CONSTRAINT FK_COVER_REF_FATHER FOREIGN KEY (CODE_FATHER) REFERENCES HORSE (CODE_HORSE);
ALTER TABLE COVER ADD CONSTRAINT FK_COVER_REF_HORSE FOREIGN KEY (CODE_HORSE) REFERENCES HORSE (CODE_HORSE) ;
ALTER TABLE COVER ADD CONSTRAINT FK_COVER_REF_MOTHER FOREIGN KEY (CODE_MOTHER) REFERENCES HORSE (CODE_HORSE);

CREATE OR ALTER TRIGGER HORSE_AI FOR HORSE
ACTIVE AFTER INSERT POSITION 0
AS
BEGIN
MERGE INTO COVER
USING RDB$DATABASE AS TBL
ON COVER.CODE_FATHER = NEW.CODE_FATHER AND
COVER.CODE_MOTHER = NEW.CODE_MOTHER
WHEN MATCHED THEN
UPDATE SET
CODE_HORSE = NEW.CODE_HORSE
WHEN NOT MATCHED THEN
INSERT (CODE_HORSE,
CODE_FATHER,
CODE_MOTHER)
VALUES (NEW.CODE_HORSE,
NEW.CODE_FATHER,
NEW.CODE_MOTHER);
END
END^

Error:

Statement failed, SQLSTATE = 42S22
unsuccefussful metadata update
-CREATE OR ALTER TRIGGER HORSE_AI failed
-Dynamic SQL Error
-SQL error code = -206
-Column unknown
-NEW.CODE_MOTHER

On Firebird 2.5 it worked

Commits: bcd483d

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Version: 3.0 Initial [ 10301 ]

Version: 3.0 Alpha 1 [ 10331 ] =>

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

This was a support issue, which should have been posted to the support mailing list.

The problem is that variables in DML/SQL statements need to be prefixed with ":". So, your statement should have read:

MERGE INTO COVER 
USING RDB$DATABASE AS TBL 
ON COVER\.CODE\_FATHER = :NEW\.CODE\_FATHER AND 
   COVER\.CODE\_MOTHER = :NEW\.CODE\_MOTHER 
WHEN MATCHED THEN 
  UPDATE SET 
  CODE\_HORSE = :NEW\.CODE\_HORSE 
WHEN NOT MATCHED THEN 
  INSERT \(CODE\_HORSE, 
          CODE\_FATHER, 
          CODE\_MOTHER\) 
  VALUES \(:NEW\.CODE\_HORSE, 
          :NEW\.CODE\_FATHER, 
          :NEW\.CODE\_MOTHER\); 

@firebird-automations
Copy link
Collaborator Author

Commented by: @sim1984

Hasn't helped.
In section VALUE NEW.CODE_FATHER works and without ':'
Firebird 2.5 allowed to write the trigger as I have written.

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

assignee: Adriano dos Santos Fernandes [ asfernandes ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Dmitry, I saw this is not a MERGE problem. This SELECT causes the problem too:

CREATE OR ALTER TRIGGER HORSE_AI FOR HORSE
ACTIVE AFTER INSERT OR UPDATE OR DELETE POSITION 0
AS
declare x integer;
BEGIN
select 1
from COVER
join RDB$DATABASE AS TBL
ON COVER.CODE_FATHER = NEW.CODE_FATHER
into x;
END!

The problem was caused by commit done in 2010-01-19, then backported to 2.5 in 2010-11-13 and reworked (in 2.5 only) in 2010-11-19.

Later in 2011-01-22 I refactored it, so it's now in RecordSourceNodes.cpp (comment - Set up an empty context to process the joins).

BTW, CORE2812 is marked as fixed in 3.0 only, which I'm not sure since you committed the changes in 2.5 too.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

assignee: Adriano dos Santos Fernandes [ asfernandes ] => Dmitry Yemanov [ dimitr ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 3.0 Alpha 1 [ 10331 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

The fix will be available in the tomorrow's snapshot build. v2.5 is not affected, as CORE2812 was rolled back from that branch.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Link: This issue is related to QA572 [ QA572 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Resolved [ 5 ]

QA Status: Done successfully

@firebird-automations
Copy link
Collaborator Author

Commented by: @pcisar

Test created.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

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

2 participants