Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Kal
    Kal is offline
    Regular Coder
    Join Date
    Dec 2005
    Posts
    309
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stored Procedure send back value

    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

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts
    sample
    Code:
    CREATE DEFINER=`root`@`localhost` PROCEDURE `galery_add`(OUT `i_result` INT,....
    i_result is the thing that you can read when s.p. returns.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #3
    Kal
    Kal is offline
    Regular Coder
    Join Date
    Dec 2005
    Posts
    309
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that. I have managed to get a status code back now.

    I have the following declared:

    Code:
    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

  • #4
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts
    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:

    Code:
    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
    Last edited by BubikolRamios; 09-30-2011 at 09:27 PM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •