Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is signal keyword not working in mySQL 5.1.48?

I'm using mysql v5.1.48 and red http://dev.mysql.com/doc/refman/5.5/en/signal.html. But the code

DELIMITER $$
CREATE PROCEDURE `CoreRaiseError`()
BEGIN
  SIGNAL SQLSTATE '45000'
      SET MESSAGE_TEXT = 'An error occurred', MYSQL_ERRNO = 1001;
END$$

raise an

SQL Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SQLSTATE '45000'

From which version SIGNAL start to be a keyword? How can I raise an exception with prior version of mysql?

Thank you.

like image 639
MUY Belgium Avatar asked May 16 '12 10:05

MUY Belgium


1 Answers

As stated in the manual for MySQL version 5.1:

Other statements related to conditions are SIGNAL, RESIGNAL, and GET DIAGNOSTICS. The SIGNAL and RESIGNAL statements are not supported until MySQL 5.5. The GET DIAGNOSTICS statement is not supported until MySQL 5.6.

To raise an error in older versions of MySQL, just deliberately issue an erroneous command. I often CALL a non-existent procedure, for example:

CALL raise_error;
like image 98
eggyal Avatar answered Sep 19 '22 15:09

eggyal