MYSQL - Code error 1644

Asked

Viewed 342 times

1

I have two database, when a Trigger is fired it generates an Insert in another database is a trick to generate log :

The scheme is this: local name database has a table called tab_manifesto and an Insert is made on it and Trigger fires an Insert in the local_log.log_tab_manifesto database.

Below is the construction and an example of the error when making the Insert.

USE local_log;

delimiter $$
DROP TABLE IF EXISTS `local_log`.`log_tab_manifesto`$$ 
CREATE TABLE `log_tab_manifesto` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_nome` varchar(30) NOT NULL,
  `data_hora` datetime NOT NULL,
  `host` varchar(45) NOT NULL,
  `operacao` varchar(2) NOT NULL COMMENT 'I-Insert, D-Delete, U-Update',
  `manifesto_id` int(11) DEFAULT NULL,
  `man_id` int(11) DEFAULT NULL,
  `uni_id` int(11) DEFAULT NULL,
  `filial_id` int(11) DEFAULT NULL COMMENT 'numero da carta frete de cada filial, exemplo foz_id',
  `mot_mot_id` int(11) DEFAULT NULL,
  `mot_est_id` int(11) DEFAULT NULL,
  `veic_id` int(11) DEFAULT NULL,
  `man_data` date DEFAULT NULL,
  `man_origem` varchar(45) DEFAULT NULL,
  `man_destino` varchar(45) DEFAULT NULL,
  `man_status` varchar(1) DEFAULT '0' COMMENT 'null  ou 0 = Viajando / 1 = chada / 2 = descarregando / 3 = finalizado',
  `man_ordem_chegada` datetime DEFAULT NULL COMMENT 'Ordena a Chegada dos Manifestos',
  `man_cancelado` varchar(1) DEFAULT NULL,
  `man_descarga` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8$$

    -- CRIANDO trigger PARA A TABELA - triggers SÃO CRIADAS NA DATABASE DE ***PRODUÇÃO***
DELIMITER $$

USE `local`$$

DROP TRIGGER IF EXISTS `local`.`tg_tab_manifesto_after_i`$$
CREATE
DEFINER=`root`@`127.0.0.1`
TRIGGER `local`.`tg_tab_manifesto_after_i`
AFTER INSERT ON `local`.`tab_manifesto`
FOR EACH ROW
BEGIN
    DECLARE EXIT HANDLER FOR SQLEXCEPTION /*DECLARAR EXECEÇÃO*/ 
    RESIGNAL SQLSTATE '21S01' SET MESSAGE_TEXT = 'TRIGGER tg_tab_manifesto_after_i';/*RETORNA O NOME DA TRIGGER EM CASO DE ERRO*/
    /*LOG - INSERIR NOVO REGISTRO DE LOG */
    set @id = (select ifnull(max(id)+1,1) from local_log.log_tab_manifesto);    
    insert into local_log.log_tab_manifesto
        values(         
            @id,
            substring_index(session_user(),'@',1),
            now(),
            substring_index(session_user(),'@',-1),
            'I',
            NEW.`log_tab_manifesto`.`manifesto_id`,
            NEW.`log_tab_manifesto`.`man_id`,
            NEW.`log_tab_manifesto`.`uni_id`,
            NEW.`log_tab_manifesto`.`filial_id`,
            NEW.`log_tab_manifesto`.`mot_mot_id`,
            NEW.`log_tab_manifesto`.`mot_est_id`,
            NEW.`log_tab_manifesto`.`veic_id`,
            NEW.`log_tab_manifesto`.`man_data`,
            NEW.`log_tab_manifesto`.`man_origem`,
            NEW.`log_tab_manifesto`.`man_destino`,
            NEW.`log_tab_manifesto`.`man_status`,
            NEW.`log_tab_manifesto`.`man_ordem_chegada`,
            NEW.`log_tab_manifesto`.`man_cancelado`,
            NEW.`log_tab_manifesto`.`man_descarga`
        );  
end$$

The error happens here at this link below:

INSERT INTO 
tab_manifesto(
    uni_id,
    filial_id,
    mot_mot_id,
    mot_est_id,
    veic_id,
    man_origem,
    man_destino
) values (
    1,
    NULL,
    30,
    NULL,
    327,
    'FOZ',
    ' SAO PAULO'
);

Error Code: 1644. TRIGGER tg_tab_manifesto_after_i

Could someone help me fix this mistake ?

  • The mistake is not in that line ? TRIGGER local.tg_tab_manifesto_after_i``

  • What version of Mysql?

1 answer

1


I found this website who says that this error is defined by the user... so I took a look again at the code to see where I wrote it and found the lines are these

DECLARE EXIT HANDLER FOR SQLEXCEPTION /*DECLARAR EXECEÇÃO*/ 
RESIGNAL SQLSTATE '21S01' SET MESSAGE_TEXT = 'TRIGGER tg_tab_manifesto_after_i';/*RETORNA O NOME DA TRIGGER EM CASO DE ERRO*/

I commented these lines and ran the script again, yes I got a more detailed error message:

08:34:09 INSERT INTO tab_manifesto( uni_id, filial_id, mot_mot_id, mot_est_id, veic_id, man_origem, man_destino ) values ( 1, NULL, 30, NULL, 327, 'FOZ', ' SAO PAULO' ) Error Code: 1054. Unknown column 'NEW.log_tab_manifesto.manifesto_id' in 'field list' 0.031 sec

There is no NEW.log_tab_manifesto.manifesto_id the correct is NEW.tab_manifesto.manifesto_id

Thank you all for your attention, lesson learned!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.