1 (edited by majklas 2016-02-29 14:56:55)

Topic: trigeris su nauju duomenu tikrinimu

man kažkodėl meta klaidą, kai bandau įrašyti duomenis į tėvinę lentą.
#1442 - Can't update table 'vocabulary' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

Trigeris:

DROP TRIGGER IF EXISTS `vertimai_INSERT` ;

CREATE DEFINER = `root`@`localhost` TRIGGER `vertimai_INSERT` BEFORE INSERT ON `vocabulary`
FOR EACH ROW 
BEGIN 
IF( NEW.oxtype <>3 )
THEN
INSERT INTO `vertimai` (id,lt,lv,ee,ru,en,se,fi,no,dk)
VALUES (
NEW.OXID, NEW.oxtrans_LT, NEW.oxtrans_LV, NEW.oxtrans_EE, NEW.oxtrans_RU, NEW.oxtrans_EN, NEW.oxtrans_SE, NEW.oxtrans_FI, NEW.oxtrans_NO, NEW.oxtrans_DK
);

END IF ;

END

insertas:

 INSERT INTO `vocabulary` (`OXID`, `OXTYPE`, `OXTRANS_LT`, `OXTRANS_LV`, `OXTRANS_SE`, `OXTRANS_FI`, `OXTRANS_EN`, `OXTRANS_EE`, `OXTRANS_RU`, `OXTRANS_PL`, `OXTRANS_NO`, `OXTRANS_DK`) VALUES ('12345678901234567890123456789011', '2', 'rgthyer', 'wrhtwhtw', '', '', '', '', '', '', '', '')

problema kaip suprantu yra "IF( NEW.oxtype <>3 )", ka siššaukia trigerio cikliškumą. Kaip apeiti šią vietą? Noriu tik tam tikrus įrašus perkelti į kitą lentutę (konkrečiai jeigu oxtype nelygu 3).

Re: trigeris su nauju duomenu tikrinimu

O nėra pas tave kitų trigger'ių?

Toks jausmas, kad čia dėl kažkurio kito, UPDATE trigger'io lentelei `vocabulary`.

Re: trigeris su nauju duomenu tikrinimu

jo, velnias, pamiršau yra :) Taip, iš kitos lentos yra insertinama kai atsiranda naujas įrašas (db irgi skiriasi). Problema, kad galima įvesti naują vertimą tiek per viena tiek per kitą vietą, o lentelių struktūra skiriasi.

vertimų lentos trigeris:

BEGIN
    INSERT INTO `vocabulary` (OXID,oxtrans_LT,oxtrans_LV,oxtrans_EE,oxtrans_RU,oxtrans_EN,oxtrans_SE,oxtrans_FI,oxtrans_NO,oxtrans_DK) 
        VALUES (NEW.id,NEW.lt,NEW.lv,NEW.ee,NEW.ru,NEW.en,NEW.se,NEW.fi,NEW.no,NEW.dk);
   END

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 756

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 811

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 811

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 811

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 811

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 811

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 811

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 811

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 811

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 811

Deprecated: Function create_function() is deprecated in /home/pasokime/domains/mysql.lt/public_html/forumas/include/parser.php on line 816

Re: trigeris su nauju duomenu tikrinimu

Nuo MySQL 5.7.2 versijos galima trėt daugiau negu vieną trigger'į tai pačiai lentai tam pačiam event'ui:

As of MySQL 5.7.2, it is possible to define multiple triggers for a given table that have the same trigger event and action time. For example, you can have two BEFORE UPDATE triggers for a table. By default, triggers that have the same trigger event and action time activate in the order they were created. To affect trigger order, specify a clause after FOR EACH ROW that indicates FOLLOWS or PRECEDES and the name of an existing trigger that also has the same trigger event and action time. With FOLLOWS, the new trigger activates after the existing trigger. With PRECEDES, the new trigger activates before the existing trigger.

Plačiau: http://dev.mysql.com/doc/refman/5.7/en/ … yntax.html