Subject Update/Insert view - no current record for fetch operation
Author Dragos Hilbert
I have an view (simplified version - true version: left join 5 tables) :

CREATE VIEW MASTER_VIEW(
id,
town,
den_master)
AS
SELECT master.id,town,master.den den_master

with Trigger for Update and for insert.

If in view I use:
1. SELECT master.id,town,master.den --- update/insert works fine.
2. SELECT master.id,town,master.den den_master -- update/insert fail with err:

The cursor identified in the update or delete statement is not positioned
on a row.
no current record for fetch operation.
attempted update of read-only column.

I remember somthing with "left join rdb$database..." so I change:

CREATE VIEW MASTER_VIEW(
id,
town,
den_master)
AS
SELECT master.id,town, master.den den_master
FROM master LEFT JOIN rdb$database on 1=2;


Insert/Update works fine.

It is a normal? Because if I update "town" works fine. ( update
MASTER_view set TOWN='TOWN1' - works)


WinXP / W2k
WI-T6.3.0.3744 Firebird 1.5 Release Candidate 4

Scripts:

/* View: MASTER_VIEW */
CREATE VIEW MASTER_VIEW(
ID,
TOWN,
DEN_MASTER)
AS
SELECT MASTER.ID,TOWN,MASTER.DEN DEN_MASTER
FROM MASTER
/* left join rdb$database on 1=2; */

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

CREATE TRIGGER MASTER_VIEW_BI0 FOR MASTER_VIEW
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
POST_EVENT 'DUMMY_EVENT';
END


CREATE TRIGGER MASTER_VIEW_BU0 FOR MASTER_VIEW
ACTIVE BEFORE UPDATE POSITION 0
AS
BEGIN
POST_EVENT 'DUMMY_EVENT';
END



ALTER TRIGGER MASTER_VIEW_BI0
AS
begin
new.id=0;
insert into master(den,TOWN) values(new.den_master,NEW.TOWN);
end

ALTER TRIGGER MASTER_VIEW_BU0
AS
begin
update master set DEN=new.den_master,TOWN=NEW.TOWN where id=new.id;
end


CREATE TABLE MASTER (
ID INTEGER NOT NULL,
DEN VARCHAR(10),
TOWN VARCHAR(50)
);