开发者

Stored Procedure (mysql) fails with "can't return a result set in the given context"

开发者 https://www.devze.com 2023-02-20 05:52 出处:网络
I\'m trying to get this SP to return (leave) if some conditions fails and so forth. This code validates and it saves the procedure, but when I call the procedure with:

I'm trying to get this SP to return (leave) if some conditions fails and so forth.

This code validates and it saves the procedure, but when I call the procedure with:

CALL ACH_Deposit(30027616,3300012003,200.00,"USD", "127.0.0.1")

It fails with error: "Procedure can't return a result set in the given context"

Does anyone have any idea on what the error is?

Procedure code:

CREATE DEFINER=`redpass_web_urs`@`%` PROCEDURE `ACH_Deposit`(
IN __Account_ID BIGINT,
IN __To_Bank_Account BIGINT,
IN __Amount DECIMAL(10,2),
IN __Currency CHAR(3),
IN __IP_Address VARCHAR(50)
)
COMMENT 'Makes a ACH deposit'
BEGIN

-- Declare Account Parameters
DECLARE _Account_Status INT;
DECLARE __Transaction_ID INT;
DECLARE _Account_Type INT DEFAULT 0;
DECLARE _Fee INT;

SELECT              
    Account_Status AS _Account_Status,
    Account_Type AS _Account_Type
FROM Account_Users 
WHERE Account_ID = __Account_ID;

main: BEGIN

    -- Step 1, is account active ?
    IF _Account_Status <> 1 THEN
        -- Account must be active (not restricted, closed etc)
        SELECT Response_Code, Description FROM ResponseCodes WHERE Response_Code = 106;
        LEAVE main; -- Here we die..
    END IF;

    -- Step 2, Calculate the FEE (Loading Funds with ACH)
    IF _Account_Type = 1 THEN
        -- Personal Account
        SET _Fee = (SELECT Fee_Template_Personal_1 FROM Fees WHERE Fee_Type_ID = __Fee_Type_ID);

    ELSE
        -- Business Account
        SET _Fee = (SELECT Fee_Template_Business_1 FROM Fees WHERE Fee_Type_ID = __Fee_Type_ID);

    END IF;

    -- Step 3, Check that Fee is not bigger then the actual amount
    IF _Fee > __Amount THEN

        SELECT Response_Code, Description FROM ResponseCodes WHERE Response_Code = 108;
        LEAVE main; -- Here we die..

    END IF;

    -- If we come here, we can make the transactions
    INSERT INTO Bank_Transaction
       (Bank_Account_ID
       ,Transaction_Type
       ,Amount
       ,IP_Address
       ,Pending)
     VALUES
       (__To_Bank_Account
       ,11
       ,__Amount
       ,__IP_Address
       ,1); -- Reserverade pengar

    -- Transaction ID开发者_开发知识库
    SET __Transaction_ID = (SELECT LAST_INSERT_ID());

    -- Deduct the Fee
    INSERT INTO Bank_Transaction
           (Bank_Account_ID
           ,Transaction_Type
           ,Amount
           ,Fee_Type_ID
           ,Fee_Transaction_ID)
        VALUES
           (__To_Bank_Account
           ,4
           ,-__Fee
           ,21
           ,__Transaction_ID);



END main;

SELECT Response_Code, Description, __Transaction_ID AS Transaction_ID
FROM ResponseCodes 
WHERE Response_Code = 1;

END


To retrieve multiple resultsets from the stored procs, you should use a client which supports multiple queries.

If you use PHP, use MySQLi extension and call the procedure using mysqli_multi_query.

MySQL extension is only able to retrieve the first recordset returned by the proc. To be able to use ti, you should set CLIENT_MULTI_RESULTS (decimal 131072) in the parameter $client_flags to mysql_connect

0

精彩评论

暂无评论...
验证码 换一张
取 消