以下存储过程按预期工作但是如果我强制发生错误(请参阅INSERT语句中的故意类型-o)我没有得到任何错误信息。
我创建了一个名为error_check的表,并尝试在其中插入错误信息以查看是否可以获取更多信息,但是当出现错误时,表中没有添加任何行。 (当我取出类型-o时,我得到一个新的行,其中包含空值,如预期的那样。)
这曾经有用,所以我确定这是我错误添加的内容。
CREATE DEFINER=`root`@`localhost` PROCEDURE `addClassToMasterList`( IN begin_date VARCHAR(10), IN day_num INT,
IN startTime VARCHAR(10), IN endTime VARCHAR (20), IN loc_id INT, IN studio VARCHAR(20),
IN class_name VARCHAR(45), IN owner_id INT,
IN club_id INT, OUT return_id VARCHAR(250))
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION, NOT FOUND, SQLWARNING
BEGIN
ROLLBACK;
GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
@errno = MYSQL_ERRNO,
@text = MESSAGE_TEXT;
SET @display_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
END; /*end of exception handing*/
SET @formatted_date = STR_TO_DATE(begin_date, '%m/%d/%Y');
/* Save all data as a new row in the Master Schedule */
INSERT INTO master_class_list_typeo_here
VALUES (null,
day_num,
@formatted_date,
null,
startTime,
endTime,
loc_id,
studio,
class_name,
owner_id,
club_id);
SELECT LAST_INSERT_ID() INTO @new_id;
/* Put bits of error into a table so I can see what is going on. */
INSERT INTO error_check
VALUES (null, @display_error, @text, @errno);
/* If an error message was generated, return the error.
Otherwise, return the new id that was automatically created. */
SELECT IF (@display_error, @display_error, @new_id) INTO return_id;
/* Also tried: SELECT @display_error INTO return_id; */
END
答案 0 :(得分:0)
尝试:
...
GET STACKED DIAGNOSTICS CONDITION 1
...
13.6.7.3 GET DIAGNOSTICS Syntax
...
关键字STACKED表示从第二个检索信息 诊断区域,仅在当前上下文为a时可用 条件处理程序。
...
请参阅db-fiddle。