Question

Quel est le mécanisme pour forcer MySQL à lancer une erreur dans le procédure stockée?

J'ai une procédure qui appel est une autre fonction:

PREPARE my_cmd FROM @jobcommand;
EXECUTE my_cmd;
DEALLOCATE PREPARE my_cmd;

la commande de travail est la suivante:

jobq.exec("Select 1;wfdlk# to simulatte an error");

alors:

CREATE PROCEDURE jobq.`exec`(jobID VARCHAR(128),cmd TEXT)
BEGIN
DECLARE result INT DEFAULT 0;  
SELECT sys_exec( CONCAT('echo ',cmd,' |  base64 -d > ', '/tmp/jobq.',jobID,'.sh ; bash /tmp/jobq.',jobID,'.sh &> /tmp/jobq.',jobID)) INTO result; 
IF result>0 THEN 
# call raise_mysql_error(result); 
END IF;
END;

Mon jobq.exec est toujours réussir. Y at-il moyen d'augmenter une erreur? Comment mettre en œuvre la fonction raise_mysql_error ??

BTW J'utilise MySQL 5.5.8

merci Arman.

Était-ce utile?

La solution

Yes, there is: use the SIGNAL keyword.

Autres conseils

You may use following stored procedure to emulate error-throwing:

CREATE PROCEDURE `raise`(`errno` BIGINT UNSIGNED, `message` VARCHAR(256))
BEGIN
SIGNAL SQLSTATE
    'ERR0R'
SET
    MESSAGE_TEXT = `message`,
    MYSQL_ERRNO = `errno`;
END

Example:

CALL `raise`(1356, 'My Error Message');
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top