DROP PROCEDURE IF EXISTS `confirm_account`;
DELIMITER ;;
CREATE PROCEDURE `confirm_account`(
    IN p_confirmation_token CHAR(64)
)
proc:BEGIN
    IF (SELECT COUNT(confirmation_token) FROM users WHERE confirmation_token = LOWER(p_confirmation_token)) = 0 OR p_confirmation_token IS NULL THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'confirm_account: Invalid token';
        LEAVE proc;
    END IF;
    UPDATE users SET confirmation_token = NULL WHERE confirmation_token = LOWER(p_confirmation_token);
    SELECT 0 AS 'status', 'confirm_account' AS 'proc';
END ;;
DELIMITER ;
