firebird icon indicating copy to clipboard operation
firebird copied to clipboard

Stored Procedure don't execute two o more INSERT.

Open Jhironsel opened this issue 3 years ago • 1 comments

CREATE TABLE A
(
  ID D_ID NOT NULL,
  FName D_Name NOT NULL,
  MName D_Name NOT NULL,
  LName D_LastN NOT NULL,
  CONSTRAINT INTEG_1 PRIMARY KEY (ID)
);


CREATE TABLE B
(
  ID_A D_ID NOT NULL,
  CarID D_CardID NOT NULL,
  CONSTRAINT PK_B_0 PRIMARY KEY (ID_A)
);
ALTER TABLE B ADD CONSTRAINT FK_B_0
  FOREIGN KEY (ID_A) REFERENCES A (ID) ON UPDATE NO ACTION ON DELETE NO ACTION;


CREATE TABLE C
(
  ID_A D_ID NOT NULL,
  CONSTRAINT PK_C_0 PRIMARY KEY (ID_A)
);
ALTER TABLE C ADD CONSTRAINT FK_C_0
  FOREIGN KEY (ID_A) REFERENCES A(ID) ON UPDATE NO ACTION ON DELETE NO ACTION;


SET TERM ^ ;
CREATE PROCEDURE SP_INSERT_C_SB (
    CarID D_CardID,
    FName D_Name,
    MName D_Name,
    LName D_LastN )
RETURNS (V_ID D_ID )
SQL SECURITY INVOKER
AS
BEGIN
     INSERT INTO V_A (ID, FName, MName, LName)
     VALUES (
       0,
       :FName,
       :MName,
       :LName) 
     RETURNING ID
     INTO :V_ID ;
     
     INSERT INTO V_B(ID_A, CarID) 
     VALUES(
          :V_ID,
          :CarID); 

     INSERT INTO V_C(ID) VALUES(:V_ID);
     SUSPEND;
END^
SET TERM ; ^

When inside the stored procedure, Insert record in Table A, It must return the ID, which must be used for Tables B and C, which we receive but is not stored in table A.

We received this message.:

Captura de pantalla de 2022-09-22 23-14-03

I don't want to remove the foreign key from table B, because at first that was working.

Jhironsel avatar Sep 23 '22 03:09 Jhironsel

Two things.

  1. This is not the support forum. Go to Firebird support forum and ask there.
  2. Have you tested the above script if it can be run at all? Have you tested if it is able to reproduce your issue? I see that no.

livius2 avatar Sep 23 '22 06:09 livius2