Subject | Strange VIEW behavior - BUG or what? |
---|---|
Author | fabianobonin@yahoo.com |
Post date | 2001-06-23T15:01:54Z |
I'm having troubles with updatable views that have before update
triggers.
When i update just one record (using the PK), it returns 3 rows
affected.
When i update this view using IBO it gives the error: 'MULTIPLE ROWS
AFFECTED', because the number of rows affected is giving 3 rows!
PS: I can't put the before update in the table, because i have
several view
on one table and i expect that each view have an specific behavior.
Try this:
/* CREATE A TABLE */
create table test (
test_id integer not null primary key,
name varchar(30),
address varchar(30) );
/* CREATE A VIEW */
create view v_test as
select test_id, name, address from test;
/* INSERT A RECORD */
insert into v_test values (1, 'name1', 'address1');
/* ROWS AFFECTED: 1 */
/* UPDATE THIS RECORD */
update v_test set name = 'name1' where test_id = 1;
/* ROWS AFFECTED: 1 */
/* CREATE A TRIGGER FOR THE VIEW */
set term !! ;
create trigger trg_v_test for v_test
before update
as
begin
new.name = 'name1';
end !!
set term ; !!
/* UPDATE THE RECORD AGAIN - SAME AS ABOVE*/
update v_test set name = 'name1' where test_id = 1;
/* ROWS AFFECTED: 3 !!!!!!!!!!!!!!!!!!!!!!! */
triggers.
When i update just one record (using the PK), it returns 3 rows
affected.
When i update this view using IBO it gives the error: 'MULTIPLE ROWS
AFFECTED', because the number of rows affected is giving 3 rows!
PS: I can't put the before update in the table, because i have
several view
on one table and i expect that each view have an specific behavior.
Try this:
/* CREATE A TABLE */
create table test (
test_id integer not null primary key,
name varchar(30),
address varchar(30) );
/* CREATE A VIEW */
create view v_test as
select test_id, name, address from test;
/* INSERT A RECORD */
insert into v_test values (1, 'name1', 'address1');
/* ROWS AFFECTED: 1 */
/* UPDATE THIS RECORD */
update v_test set name = 'name1' where test_id = 1;
/* ROWS AFFECTED: 1 */
/* CREATE A TRIGGER FOR THE VIEW */
set term !! ;
create trigger trg_v_test for v_test
before update
as
begin
new.name = 'name1';
end !!
set term ; !!
/* UPDATE THE RECORD AGAIN - SAME AS ABOVE*/
update v_test set name = 'name1' where test_id = 1;
/* ROWS AFFECTED: 3 !!!!!!!!!!!!!!!!!!!!!!! */