-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Leigh wrote:
> Gleb Paharenko wrote:
> 
>> Hello.
>>
>> There was a question about exceptions recently. The answer might be
>> helpful:
>>   http://lists.mysql.com/mysql/188048
>>
>>
>>
>> Leigh <[EMAIL PROTECTED]> wrote:
>>
>>> Hi All,
>>>
>>> I'm currently working on porting a database form Informix 9.2 to MySQL 5
>>> in order to determine the suitability of MySQL for our application.  At
>>> the moment, I'm stuck with one of our stored procs that contains the
>>> following lines:
>>>
>>> -- If duplicates are detected, raise an error
>>> IF count > 1 THEN
>>>    RAISE EXCEPTION -746, 0, 'Duplicate mapping: code "' || p_code ||
>>> '", cust "' || p_cust_code || '"';
>>> END IF;
>>>
>>> Under Informix, this IF statement raises a user defined JDBC Exception
>>> (the code "-746" is for user defined errors).  Is there any way of doing
>>> a similar thing in MySQL?
>>>
>>> If you need any more information, I'm happy to provide it. Thanks in
>>> advance!
>>> Regards,
>>> Leigh
>>>
>>
> 
> Hi,
> 
> Thanks for that bit of info.  This may be a stupid question, but how
> exactly does setting the variable @err help me with my current
> situation?  Will this allow me to generate a JDBC Exception or is it
> something I'll need to change in the code to check if an error code has
> been set?  Thanks again!
> 
> Leigh
> 

Leigh,

It looks like the other poster's example just ends up setting the error
variable, _not_ creating a custom error.

MySQL does not yet have a RAISERROR implementation, so to create an
exception, you usually have to do something that is erroneous, but that
has no side effects and then parsing the error message from the
resultant SQLException (like dropping a non-existent table):

DROP TABLE error.`error #nnnn`

(note, this example is from
http://dev.mysql.com/tech-resources/articles/mysql-storedprocedures.pdf
which is worth a read if you're starting out with MySQL stored procedures).

        -Mark



- --
Mark Matthews
MySQL AB, Software Development Manager - Connectivity
www.mysql.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDDcKltvXNTca6JD8RArB+AJoDQSYUlF5yCyz+1sc4X1YVudXQxACgi7Et
6bEs9HNLBRPzj8MgJu4dpfE=
=HSwc
-----END PGP SIGNATURE-----

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to