0
I’m trying to make an error in trying to record, or for some serious reason in one and not serious in another, is performed the rollback in both tables, I found similar things, but I did not locate anything that needed.
This is the creation of my proc
CREATE DEFINER=`root`@`%` PROCEDURE `SP_IncluirCadastro`( in nome VARCHAR(45), in sobrenome VARCHAR(100), in email VARCHAR(100), in rg VARCHAR(45), in cpf VARCHAR(45), in pai VARCHAR(45), in mae VARCHAR(45), in celular01 VARCHAR(30), in celular02 VARCHAR(30), in telefone VARCHAR(30), in telefonerecado VARCHAR(30), IN rua VARCHAR(100), IN numero VARCHAR(30), IN bairro VARCHAR(100), IN estado VARCHAR(45), IN cidade VARCHAR(45))
BEGIN
DECLARE exit handler for SQLEXCEPTION
BEGIN
GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
@errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
SELECT @full_error;
END;
SET autocommit = 0;
START transaction;
INSERT INTO `Teste`.`CadastroPF`(Nome,
Sobrenome,
Email,
RG,
CPF,
Pai,
Mae,
Celular01,
Celular02,
Telefone,
TelefoneRecado)
VALUES
(nome, sobrenome, email, rg, cpf, pai, mae, celular01, celular02, telefone, telefonerecado);
INSERT INTO `Teste`.`Endereco`(Rua,
Numero,
Bairro,
Estado,
Cidade)
VALUES
(rua, numero, bairro, estado, cidade);
END
How I record:
CALL SP_IncluirCadastro('Ezequiel', 'Delavega Martins', '[email protected]', '461514344', '38094345830', 'Afonso Ramos', 'Mamãe querida', '11942026774', '11998333777', '1155303117', '1191232111', 'dos aniquis', '2142142144', 'jd. santa terezinha', 'são paulo', 'SP')
You must treat "Exception" I believe, not with mysql but ... https://stackoverflow.com/questions/19905900/mysql-transaction-roll-back-on-any-exception
– Motta
I’ll try something similar around here, our is so bad on mysql, but thank you Motta!!!!!!!
– MegaMente
I found even simple , in Oracle is even more complicated.
– Motta