MySQL Forums
Forum List  »  Connector/ODBC

Driver has bug when calling stored procecure using cursor.
Posted by: young-ku chae
Date: February 27, 2017 10:43PM

When I call following stored procedure, driver returns invalid garbage output parameter value.
If I remove "open v_cursor" line, then it works fine.

Stored Procedure
-----------------------------------------------------------------------------
CREATE PROCEDURE `cursor_test`(out o_int int, out o_string varchar(20))
BEGIN
declare v_cursor cursor for select 2;

open v_cursor;

set o_int = 123;
set o_string = "chaeyk";
END
-----------------------------------------------------------------------------

C# code
-----------------------------------------------------------------------------
using System.Data;
using System.Data.Odbc;

...

string connectionString = "Driver={MySQL ODBC 5.3 UNICODE Driver};Server=xxxx;Port=yyyy;Database=zzzz;User = aaa; Password = bbb; Option = 4194304;";

using (OdbcConnection connection = new OdbcConnection(connectionString))
{
OdbcCommand command = new OdbcCommand("call cursor_test(?, ?)", connection);
command.Parameters.Add("o_int", SqlDbType.Int).Direction = ParameterDirection.Output;
command.Parameters.Add("o_string", SqlDbType.VarChar).Direction = ParameterDirection.Output;

connection.Open();
command.ExecuteNonQuery();
Console.WriteLine("\t{0}\t{1}", command.Parameters["o_int"].Value, command.Parameters["o_string"].Value);
}
-----------------------------------------------------------------------------

C++ code
-----------------------------------------------------------------------------
_ConnectionPtr pConnection;
pConnection.CreateInstance(__uuidof(Connection));

_bstr_t bstrConnection = "Driver={MySQL ODBC 5.3 UNICODE Driver};Server=xxxx;Port=yyyy;Database=zzzz;User = aaa; Password = bbb; Option = 4194304;";
_bstr_t bstrUser = user;
_bstr_t bstrPass = pass;

pConnection->Open(bstrConnection, bstrUser, bstrPass, adModeUnknown);
pConnection->CursorLocation = adUseClient;
pConnection->PutCommandTimeout(300);

_CommandPtr cmd;
cmd.CreateInstance(__uuidof(Command));
cmd->ActiveConnection = pConnection;

cmd->CommandType = adCmdStoredProc;
cmd->CommandText = _bstr_t(L"cursor_test");
cmd->Parameters->Append(cmd->CreateParameter(_bstr_t(L"o_int"), adInteger, adParamOutput, 4, _variant_t(_bstr_t(L"0"))));
cmd->Parameters->Append(cmd->CreateParameter(_bstr_t(L"o_string"), adVarWChar, adParamOutput, 4096, _variant_t(_bstr_t(L""))));

_variant_t vNull;
vNull.vt = VT_ERROR;
vNull.scode = DISP_E_PARAMNOTFOUND;

cmd->Execute(&vNull, &vNull, adCmdStoredProc);

_variant_t v = pCmd->Parameters->Item[_variant_t("o_int")]->Value;
_bstr_t bstr = (_bstr_t) v;
const char* str = (const char*) bstr;
printf_s("o_int=%s\n", name, str);

-----------------------------------------------------------------------------

Options: ReplyQuote


Subject
Written By
Posted
Driver has bug when calling stored procecure using cursor.
February 27, 2017 10:43PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.