...

View Full Version : Stored Procedure send back value



Kal
09-28-2011, 11:00 AM
Hi,

I am currently working on writing a Stored Procedure that is all working fine. however I would like to add a bit of validation within it.

I am using cursors, loops and doing calculations.

What I want to do is return a statuscode value of '1' which I have declared if calculation1 is a negative number or less than zero.

Can anyone please help me on how I go about returning this value?

Thanks

BubikolRamios
09-28-2011, 02:20 PM
sample


CREATE DEFINER=`root`@`localhost` PROCEDURE `galery_add`(OUT `i_result` INT,....


i_result is the thing that you can read when s.p. returns.

Kal
09-30-2011, 10:54 AM
Thanks for that. I have managed to get a status code back now.

I have the following declared:



DECLARE EXIT HANDLER FOR SQLWARNING BEGIN ROLLBACK; END;
DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; END;


I also have an INSERT statement which works fine the first time it's ran but not the second, however works everytime directly on MySQL.

Is there anyway to show MySQL Warnings?

Thanks

BubikolRamios
09-30-2011, 10:24 PM
There is , dumb way but only way that it works in order to show you the problem which you have no idea what it is:



DECLARE EXIT HANDLER FOR 1000 return 1000;
...
DECLARE EXIT HANDLER FOR 1711 return 1711;


instead of return you would do set i_result = 1000 or something like that

look on net for 'mysql errorcodes' to see what specific number means



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum