Subject RE: [firebird-support] Re: FB2.1 frequently Index corruption in DB
Author Alan McDonald
>
> /* Trigger: ACC$PREDOC_BU0 */
> CREATE OR ALTER TRIGGER ACC$PREDOC_BU0 FOR ACC$PREDOC
> ACTIVE BEFORE UPDATE POSITION 0
> AS
> DECLARE VARIABLE A DM_ID;
> DECLARE VARIABLE C DM_ID;
> DECLARE VARIABLE DOC_STATE DM_ID;
> DECLARE VARIABLE Z_UPDATE_BY INTEGER;
> BEGIN
>
> EXECUTE PROCEDURE FUN_GET_CUR_USERID
> RETURNING_VALUES(:Z_UPDATE_BY);
> NEW.INSERT_BY = OLD.INSERT_BY;
> NEW.INSERT_TIME = OLD.INSERT_TIME;
> NEW.UPDATE_BY = Z_UPDATE_BY;
> NEW.LAST_UPDATE_TIME = CURRENT_TIMESTAMP;
> NEW.UPDATE_COUNT = OLD.UPDATE_COUNT + 1;
>
> -- NO CHANGE.
> SELECT D.SSTATE FROM ACC$DOC D WHERE (OLD.DOC_LINK = D.NID) INTO
> :DOC_STATE;
> IF (DOC_STATE <> 1) THEN
> EXCEPTION EXP_DEFAULT 'تنها در
> صورتي امكان
> تغير در
> اقلام سند
> وجود دارد
> كه سند در
> حالت ناقص
> باشد';
> --CHK.
> IF ((ABS(NEW.BED) > 0) AND (ABS(NEW.BES) > 0)) THEN
> EXCEPTION EXP_ACC_BED_BES ;
> -- NULL.
> IF (NEW.NAME IS NULL) THEN
> EXCEPTION EXP_ACC_DOC_NAME ;
> A = 0;
>
> SELECT COUNT(*) FROM ACC$TREE$BASE$R3 T WHERE (NEW.TREE_BASE_R3 =
> T.NID) INTO A;
> IF ((NEW.TREE_BASE_R3 IS NULL) OR (A < 1)) THEN
> EXCEPTION EXP_ACC_DOC_TREE ;
> C = 0;
> SELECT COUNT(*) FROM ACC$PREDOC T1
> WHERE (NEW.ROW = T1.ROW) AND (NEW.DOC_LINK = T1.DOC_LINK) INTO C;
> IF (C > 0) THEN
> EXCEPTION EXP_ACC_DOC_ROW ;
> END
>

this trigger raises an exception when you don't like the update, but what
happens with an insert?
Alan