How should I correctly code, in Delphi, the situation where the execute might fail, eg if MyStoredProc was unable to do an insert (and so the last ID is invalid)?
Is there a MyStoredProc event I can use or do I just have to put it in a try - except block and let it fail?
(I realise I could put the insert and the select inside a transaction so the select doesn't run if the insert fails but I still need to know that the returned ID isn't valid.)
In essence the stored proc is below (real code has more parameters)
Code: Select all
DELIMITER $$
CREATE PROCEDURE InsertNewArea(new_area VARCHAR(45), area_code VARCHAR(5),
OUT area_id INTEGER)
DETERMINISTIC
BEGIN
INSERT INTO Areas (AreaName, AreaCode)
VALUES (new_area, area_code) ;
SET area_id = (SELECT LAST_INSERT_ID() FROM Areas);
END$$
DELIMITER ;