0
以下存儲過程按預期工作,但如果我強制執行錯誤(請參閱INSERT語句中的故意type-o)我沒有收到任何錯誤信息。mySQL存儲過程不給我錯誤消息
我創建了一個名爲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
我相信你可能擁有它,但mySQL工作區給我一個關於單詞「STACKED」的語法錯誤。將繼續調查並回復。 –
@ B.Krafft:你使用的是什麼版本的MySQL? – wchiquito
我正在使用MySQL 5.6和Workbench 6.3 –