gpt4 book ai didi

mysql存储过程异常: One line gets executed,又跳过了?

转载 作者:行者123 更新时间:2023-11-30 23:18:58 25 4
gpt4 key购买 nike

我有一个存储过程,它检查是否有用户具有与输入相同的电子邮件地址,如果没有,则注册一个。

这是表格:

CREATE  TABLE IF NOT EXISTS `overkill`.`accounts` (
`accountID` INT NOT NULL AUTO_INCREMENT ,
`email` VARCHAR(64) NOT NULL ,
`firstName` VARCHAR(32) NOT NULL ,
`lastName` VARCHAR(32) NOT NULL ,
`passSaltedSHA` BINARY(20) NOT NULL ,
`salt` BINARY(20) NOT NULL ,
`gender` ENUM('m','f') NOT NULL ,
`birthDate` DATE NOT NULL ,
`regTime` TIMESTAMP NOT NULL ,
PRIMARY KEY (`accountID`) )
ENGINE = InnoDB;

存储过程如下:

DELIMITER $$

CREATE PROCEDURE `overkill`.`registerUser` (
IN emailIN VARCHAR(64),
IN passwordIN VARCHAR(16),
IN firstNameIN VARCHAR(32),
IN lastNameIn VARCHAR(32),
IN birthIN DATE,
IN genderIN ENUM('f','m'))

BEGIN
DECLARE existingMailAccLOG INT DEFAULT NULL;
DECLARE saltLOC CHAR(40);
DECLARE regSuccessLOC BOOLEAN DEFAULT FALSE;

SELECT COUNT(*) INTO existingMailAccLOG FROM `overkill`.`accounts` WHERE `accounts`.`email` = emailIN;

IF existingMailAccLOG = 0 THEN
SET saltLOC = SHA1(rand());
SET regSuccessLOC = TRUE;
INSERT INTO `overkill`.`accounts` (`email`, `firstName`, `lastName`, `passSaltedSHA`, `salt`, `gender`, `birthDate`) VALUES(emailIN, firstNameIN, lastNameIn, UNHEX(SHA1(CONCAT(passwordIN, saltLOC))), UNHEX(saltLOC), genderIN, birthIN);
END IF;

SELECT regSuccessLOC AS `registered`, saltLOC AS `salt`;
END

如果我调用:

CALL registerUser("abc@def.com", "pass", "firstn", "lastn", "2012-01-01", "f");

它在 accounts 表中插入一行,但忘记返回我在 IF 中设置的正确值

SET saltLOC = SHA1(rand());
SET regSuccessLOC = TRUE;

这怎么可能?为什么跳过这些行并且 INSERT 仍然无误地执行?

最佳答案

尝试在 DECLARE 关键字后的变量名前添加“@”。它可能会引起一些困惑,如下所述:MySQL: @variable vs. variable. Whats the difference? (Part2)在这里:MySQL: @variable vs. variable. Whats the difference?

关于mysql存储过程异常: One line gets executed,又跳过了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com