2uzhan.com
Advertisement
Now Place:2uzhan.com » C API to get Output value

C API to get Output value

MySQL @ December 4, 2005   Views:0

MySQL 5.0 does support Stored procedure INOUT and OUT parameters. However, I could not find an easy way to get the output values for INOUT and OUT parameters. Here is my problem:

Let us say we have a stored procedure declare like this as

CREATE PROCEDURE MyProc(param1 blob, INOUT param2 INT, OUT param2)
BEGIN
...
END;

Ideally, we shall have an C/C++ API like mysql_stmt_bind_param, after those parameters are bound and query statement is executed, the binding buffer shall have the output values for param2 and param3.

If you have any good workaround, please let me know. Many thanks in advance.

SXD

--------------Solutions-------------

Here's one way I found via debugging the mysql.net connector code.

Say I have the following stored procedure:

CREATE PROCEDURE `get_user_count`(OUT user_count INT)
BEGIN
SELECT COUNT(*) INTO `user_count` FROM `user`;
END

//initialize a stmt
mysql_stmt_init()

//execute the stored proc
mysql_real_query("call mysql.get_user_count(@71bb8831c92e487b9078b40837a36558)")

//create a new stmt using the same mysql_handle
mysql_stmt_init()

//get the out parameter of the stored proc
mysql_real_query("select @71bb8831c92e487b9078b40837a36558")
mysql_use_result()

//go to 1st row of results which will an array with 2 elements..The parameter name, and the value. The parameter name in this case is @71bb8831c92e487b9078b40837a36558")
mysql_fetch_row()

I chose a guid as a parameter name because I believe reusing parameter names within the same session can cause conflicts. Also, make sure CLIENT_MULTI_STATEMENTS CLIENT_MULTI_RESULTS is included in the client_flag argument on the call to mysql_real_connect.

Tags:
© 2018 2uzhan.com Contact