Bug #45060 Stored Procedure Returning NULL OUT parameters when called from myodbc
Submitted: 25 May 2009 7:34 Modified: 30 Jun 2009 1:34
Reporter: wang zhengying Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:5.1.5 myodbc , 5.1.30 mysql OS:Any (window , solaris)
Assigned to: CPU Architecture:Any
Tags: NULL PARAMETER RETURNS from STORED PROCEDURE

[25 May 2009 7:34] wang zhengying
Description:
When calling a stored procedure from ODBC (mysql) 5.1.5 any out
parameters are set to NULL.

How to repeat:
1. create a test procedure:
CREATE PROCEDURE param_test (IN p_in INT,

                             OUT p_out INT)
BEGIN

  SET p_out = p_in;

END;

2. code was programed in .net framework1.1 as followed:
using System;
using System.Data.Odbc;
namespace DbFactory
{
	/// <summary>
	/// TestMysqlProcedure 的摘要说明。
	/// </summary>
	public class TestMysqlProcedure
	{
		public TestMysqlProcedure()
		{		}
		public static void RunProcedure()
		{
string connectionStr="DSN=mydsn;User Id=dbLoginUser;Password=dbLoginPwd;";
OdbcConnection connection=new System.Data.Odbc.OdbcConnection(connectionStr);
			string cmdText="{call param_test(?,@p_out)}";
			System.Data.Odbc.OdbcCommand proc=new OdbcCommand(cmdText,connection);
			System.Data.Odbc.OdbcParameter param1=new OdbcParameter("@p_in",1);
			System.Data.Odbc.OdbcParameter param2=new OdbcParameter("@p_out",0);
			param2.Direction=ParameterDirection.Output;
			proc.Parameters.Add(param1);
			proc.Parameters.Add(param2);
			proc.ExecuteNonQuery();
			System.Diagnostics.Debug.WriteLine(param2.Value.ToString());
		}
	}
}

3. When called from a WINDOWS machine using 5.1.5 ODBC (mysql)   The procedure 
runs success(it can assert by insert result into a temp table), but returns NULL. This happens for any function using OUT parameters. All OUT parameters for any PROCEDURES are set to NULL.

Suggested fix:
i know this version of mysql support output parameter, please fix this bug of odbc, or tell me the right sytax to call procedure that can get out parameter;
[25 May 2009 8:09] Tonci Grgin
Hi Wang and thanks for your report.

There seems to be some problem in ODBC/NET bridge as C/C++ tests work... Can you please try using pure C/C++ test and see if the problem goes away?
[25 May 2009 9:28] wang zhengying
i havn't test pure c interface, but other guys have test it, the result is same.
but i found an alternate solution, after call the procedure, run ExecuteScale(@outparameterName), i can get the result.
[30 Jun 2009 1:34] Jess Balint
Automatically retrieved stored procedure output params is not automatically supported. ODBC support for this will be implemented in the future on post-5.1 servers only.
[27 Jul 2009 19:05] Pierre Maroun
I am using ODBC 5.1 with MySQL 5.4 and it's not working. This a major issue, are you trying to fix this or should we forget about Mysql??
[29 Jul 2009 7:17] Tonci Grgin
Pierre, what Jess is saying is that all of the connectors depend on fix for Bug#17898 (No straightforward way to deal with output parameters) which is present only from MySQL server 5.4.4.

Naturally, some time will pass until all of connectors teams implement support for OUT parameters as in fix for Bug#17898.

So, if you are seeing this problem using MySQL server 5.4.4, we'll reopen the report even though not all of the teams implemented this functionality..