Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Где ошибка в триггере?


}|{yk ©   (2004-12-23 14:35:00) 

---------------------------
Debugger Exception Notification
---------------------------
Project FinUchetMEM.exe raised exception class EFIBInterBaseError with message 'DataModuleMain.Table_Plateg.InsertQuery:
Too many concurrent executions of the same request\n.
Too many concurrent executions of the same request.
'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------
AS
declare variable l_day integer;
declare variable l_month integer;
declare variable l_year integer;
declare variable l_rs varchar(14);
declare variable l_str varchar(82);
declare variable l_exist integer;
declare variable l_rule integer;
declare variable l_summa double precision;
declare variable l_kontragent integer;
declare variable l_rs_id_to integer;
declare variable l_set_to integer;
declare variable l_line_to integer;
declare variable l_cust1 integer;
declare variable l_cust2 integer;
declare variable l_cust3 integer;
declare variable l_unit integer;
begin
 l_kontragent = 483; /*ID контрагента*/
 l_cust1 = 0;                                      --iдентифiкатор CUST1
 l_cust2 = 80000096;                               --iдентифiкатор CUST2
 l_cust3 = 80000076;                               --iдентифiкатор CUST3

 select count(1) from app_pdv_move_rules a where a.reg_from = new.deb_kred
 and a.rs_id_from=new.rs_id into l_rule;
 if (l_rule=1) then
  begin
 /*вибираємо ID статті та ID рахунку, на який іде ПДВ*/
  select a.rs_id_to, a.set_to, a.line_to from app_pdv_move_rules a
  where a.reg_from = new.deb_kred and a.rs_id_from=new.rs_id into
  l_rs_id_to, l_set_to, l_line_to;
 /*-----------------------------------------------------------------*/
 select extract(DAY from new.plat_date) from rdb$database into l_day;
 select extract(MONTH from new.plat_date) from rdb$database into l_month;
 select extract(YEAR from new.plat_date) from rdb$database into l_year;
 select a.rs_name from app_rs a where a.rs_id=new.rs_id into l_rs;
 l_str = 'Коригувальний платіж: ПДВ за '||l_day||'.'||l_month||'.'||l_year||' по рахунку '||l_rs;
 select count(1) from app_plateg a where a.koment = :l_str into l_exist;
    select sum(a.nds_sum) from app_plateg a
     where a.rs_id = new.rs_id and
           a.deb_kred = new.deb_kred and
           extract(day from a.plat_date) = extract(day from new.plat_date) and
           extract(month from a.plat_date) = extract(month from new.plat_date) and
           extract(year from a.plat_date) = extract(year from new.plat_date) into l_summa;
 if (l_exist>0) then
  begin
    update app_plateg a set a.plat_sum=coalesce(:l_summa,0) where koment = :l_str;
    update app_bank a set a.summa=coalesce(:l_summa,0) where a.plat_id = (select plat_id from app_plateg where koment = :l_str);
  end
   else
    begin
     /*дізнаємося ID підрозділу з таблиці рахунків*/
     select a.unit_id from app_rs a where a.rs_id = new.rs_id into l_unit;
     /*-------------------------------------------*/
     insert into app_plateg
       (plat_id,rs_id,kontr_id,plat_nom,plat_date,plat_sum,deb_kred,koment,read_only) values
       (gen_id(gen_app_plateg_id,1),:l_rs_id_to,:l_kontragent,'0000',new.plat_date, coalesce(:l_summa,0), new.deb_kred, :l_str,'Y');
       insert into app_bank (bank_id, plat_id, set_id, line_id, cust1_id,
                             cust2_id, cust3_id, unit_id, plat_date, rs_id,
                             avans_pogash, summa) values
                            (gen_id(gen_app_bank_id,1),gen_id(gen_app_plateg_id,0), :l_set_to, :l_line_to, :l_cust1,
                             :l_cust2, :l_cust3, :l_unit, new.plat_date, :l_rs_id_to,
                             'звичайний', coalesce(:l_summa,0));
    end
 end
end


Zacho   (2004-12-25 11:06:00) [1]

Zacho ©   (25.12.04 11:05) [9]

Ой, ошибочка :)

if (new.koment like 'Коригувальний платіж:%') then l_recurse=1;


Zacho   (2004-12-25 11:05:00) [2]

2 }|{yk © :

А зачем тебе постоянно такие странные извращения с SELECT'ом из RDB$DATABASE ? Причём, нерабочие.

Проще надо быть..

if (new.koment like 'Коригувальний платіж:%') then l_recurse=0;


}|{yk   (2004-12-24 12:23:00) [3]

То есть? Я же в начале триггера проверяю - автоматически ли это созданное поле, или нет. Если автоматически, то новая вставка должне происходить. А она происходит...


Johnmen   (2004-12-24 12:17:00) [4]

Остановить рекурсию можно единственным способом - не делать новых вставок из триггера...


}|{yk   (2004-12-24 12:05:00) [5]

Может кто подскажет?
Ошибка возникает из-за возникновения рекурсии.
То есть я заношу на 206 счет, и перенос тоже на 206 счет. И получаем бесконечный цикл.
Но.
Я добавил в начало такой код
 select count(1) from rdb$database where new.koment like 'Коригувальний платіж:%' into l_recurse;
 
 if (:l_recurse=0) then

, который вроде как должен останавливать рекурсию, так как в автоматически формируемом платеже комментарий начинается из 'Коригувальний платіж:%'. Однако бесконечный цикл все равно есть :(


Zacho   (2004-12-23 15:51:00) [6]

Я тебе уже как-то писал - скорее всего достигнута предельная глубина рекурсии. Точно рекурсии нигде нет ?

И ещё:
1. Вместо SELECT COUNT лучше использовать EXSIST - работает быстрее.
2. Вместо select extract(DAY from new.plat_date) from rdb$database into l_day; лучше l_day=extract(DAY from new.plat_date; и т.п.


}|{yk   (2004-12-23 15:45:00) [7]

Уже разобрался... Рекурсия может возникать...


Johnmen   (2004-12-23 15:27:00) [8]

Триггер на какую таблицу ?


Sergey13   (2004-12-23 15:20:00) [9]

Тригер на что и на когда?


}|{yk   (2004-12-23 14:54:00) [10]

Ошибка в
insert into app_plateg
(plat_id,rs_id,kontr_id,plat_nom,plat_date,plat_sum,deb_kred,koment,read_only) values
      (gen_id(gen_app_plateg_id,1),:l_rs_id_to,:l_kontragent,'0000',new.plat_date, coalesce(:l_summa,0), new.deb_kred, :l_str,'Y');

Но почему она возникает?


Наверх

Титульная страница Поиск, карта сайта Написать письмо