MySQL Forums
Forum List  »  Triggers

Re: How to Raise Error ?
Posted by: Andy West
Date: February 25, 2006 11:48PM

Here's a workaround I came up with that's along the lines of the "unique constraint violation" and "non-existent procedure" techniques. However, it allows you to pass an error message that most clients will display.

Here is the stored procedure which "raises the error."



delimiter //

--
-- Raise an error.
--
CREATE PROCEDURE raise_error (
p_msg VARCHAR(128))
BEGIN
DECLARE _msg TINYINT;

-- Force an error to be raised by assigning a string to an
-- integer variable. The string will appear on the client.
SET _msg = p_msg;
END//

delimiter ;



Then, in another file, I have a trigger that calls it:
CALL raise_error ('Something bad just happened.');

When the procedure is called, I get the message "#22007Truncated incorrect INTEGER value: 'Something bad just happened.'"

These workarounds are kind of nasty, but I guess you have to make do with what you've got. By the way, I have app and SP logic that tries to prevent these errors from happening in the first place. It's really just there to prevent stupid mistakes.

Options: ReplyQuote


Subject
Views
Written By
Posted
25006
November 17, 2005 04:00AM
16709
November 17, 2005 06:58AM
23666
November 19, 2005 08:53AM
14485
February 23, 2006 02:28AM
10777
February 23, 2006 04:42AM
15434
February 24, 2006 08:28AM
8473
February 24, 2006 10:15AM
6250
February 24, 2006 12:42PM
7880
February 27, 2006 08:56AM
6679
February 27, 2006 11:27AM
18863
February 28, 2006 05:22AM
6525
December 20, 2006 03:34AM
4089
November 18, 2008 08:28AM
4733
November 18, 2008 12:45PM
6142
December 19, 2006 11:00AM
4945
December 19, 2006 02:35PM
6202
December 19, 2006 07:53PM
4394
December 20, 2006 03:37AM
4604
December 19, 2006 11:01AM
5479
November 24, 2006 05:32AM
4455
November 24, 2006 07:02AM
3602
December 23, 2008 06:08AM
Re: How to Raise Error ?
11137
February 25, 2006 11:48PM
4935
December 19, 2007 04:24AM
3907
December 24, 2008 01:02PM
4752
December 19, 2007 03:59AM
4613
December 19, 2007 05:09AM
3511
November 18, 2008 08:25AM
3892
November 18, 2008 12:49PM
5991
December 19, 2007 04:46AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.