Subject Re: [ib-support] Validation error
Author Marco Bommeljé
Hi,

As far as I am aware, a VIEW does not automatically update once you
define triggers for it. That means that you must handle INSERT, UPDATE
or DELETE statements to the basetables in the corresponding BEFORE
triggers.

So try this:

> create trigger ti_testview
> for testview
> before insert
> as
> declare variable v_test integer;
> begin
> v_test=1;
INSERT INTO TestTable (Field1, Field2)
VALUES (new.Field1, new.Field2);
> end^

Cheers,
Marco

semprolbat wrote:
> Hi.
>
> I am experiencing a weird validation error:
>
> I have a table with a field (Field2) that is not nullable, and has
> the default value of 0. My users access the table via a view.
>
> When a user inserts values in the view, omitting Field2, Firebird is
> supposed to set the field's value to 0. This works great, until I add
> an insert trigger to the view. The result of adding the trigger is
> that Firebird no longer sets the field's value to 0, but returns a
> validation error instead.
>
> Check out the following code:
>
> -------- code part 1 - create the database ------------
> create database "TestDB.gdb" user "sysdba" password "masterkey";
>
> create table TestTable (
> Field1 integer,
> Field2 integer default 0 not null
> );
>
> create view TestView as
> select
> Field1,
> Field2
> from
> TestTable;
>
>
> set term ^;
>
> create trigger ti_testview
> for testview
> before insert
> as
> declare variable v_test integer;
> begin
> v_test=1;
> end^
>
> set term ;^
>
>
> grant all on TestView to SomeUser;
>
> -------- code part 2 - provoke the error ------------
> connect "TestDB.gdb" user SomeUser password SomePassword;
>
> /* firstly we include Field2, which works great */
> insert into testview (Field1,Field2)
> values (1,0);
>
> /* secondly we trust FireBird to set Field2's value to 0 */
> insert into testview (Field1)
> values (1);
>
>
>
> -------- end of code -----------
>
> When running the same code, omitting the insert trigger, both inserts
> work great.
>
> FireBird bug, or am I doing something wrong!???
> I am running FireBird 1.0.2.908 win32.
>
>
> Yours,
> Magnus
>
>
>
> *Yahoo! Groups Sponsor*
> <http://rd.yahoo.com/M=245314.3072841.4397732.2848452/D=egroupweb/S=1705115386:HM/A=1495890/R=0/*http://www.netbizideas.com/yheb42
> >
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
> <http://docs.yahoo.com/info/terms/>.

--
-------------------------------------
-- Marco Bommeljé
-- Bommeljé Crompvoets en partners bv
-- W: www.bcp-software.nl
-- E: mbommelj@...
-- T: +31 (0)30 2428369
-------------------------------------