Subject Re: Multitable view update
Author ricolebo1
Hi,

I have create a little base to show the bug or the anomaly of
firebird to resolve the update.
Just change the value of v_external in the viewtest and see the result ...

Thank you
Eric



/* Script to create de base test */

SET SQL DIALECT 3;

SET NAMES NONE;

CREATE DATABASE 'c:\base\test.fdb'
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 2048
DEFAULT CHARACTER SET NONE;



/******************************************************************************/
/**** Tables
****/
/******************************************************************************/



CREATE TABLE T1 (
ID INTEGER,
FIRSTNAME VARCHAR(40),
LASTNAME VARCHAR(40)
);

CREATE TABLE T2 (
ID INTEGER,
EXTERNALFIELD INTEGER
);



/******************************************************************************/
/**** Views
****/
/******************************************************************************/


/* View: VIEWTEST */
CREATE VIEW VIEWTEST(
V_FIRSTNAME,
V_LASTNAME,
V_EXTERNAL)
AS
select firstname,lastname,(select externalfield from t2) from t1
;


INSERT INTO T1 (ID, FIRSTNAME, LASTNAME) VALUES (1, 'FIRSTNAME',
'LASTNAME');

COMMIT WORK;

INSERT INTO T2 (ID, EXTERNALFIELD) VALUES (1, 0);

COMMIT WORK;



/******************************************************************************/
/**** Triggers
****/
/******************************************************************************/


SET TERM ^ ;


/******************************************************************************/
/**** Triggers for updatable views
****/
/******************************************************************************/



/* Trigger: VIEWTEST_BU */
CREATE TRIGGER VIEWTEST_BU FOR VIEWTEST
ACTIVE BEFORE UPDATE POSITION 0
AS
BEGIN
POST_EVENT 'DUMMY_EVENT';
END
^

ALTER TRIGGER VIEWTEST_BU
as
begin
if (new.v_external <> old.v_external) then
update t2 set externalfield = new.v_external;
end
^

SET TERM ; ^