ado访问MySQL的带OUT参数的存储过程时出错!

dongdong034 2008-09-22 03:29:23
出错提示信息为:OUT or INOUT argument 1 for routine test.ProcTest2 is not a variable or NEW pseudo-variable in BEFORE trigger
查了资料,貌似是MySQL的bug,是这样的吗?

////////////////////////////////////
// 相关代码如下
try
{
HRESULT hResult;
hResult = m_pDBConn.CreateInstance(__uuidof(Connection));
m_pDBConn->CursorLocation = adUseClient;
TCHAR szOut[MAX_PATH];
sprintf( szOut, "DSN=%s;UID=root;PWD=123;", "zdMySQL" );
hResult = m_pDBConn->Open( _bstr_t(szOut), _bstr_t(""), _bstr_t(""), adModeUnknown );

_CommandPtr pCmd;
hResult = pCmd.CreateInstance( __uuidof( Command ) );
_ParameterPtr pOutParamUserID = pCmd->CreateParameter( "nOutDataUserID", adInteger, adParamOutput, 4, 0 );
pCmd->Parameters->Append( pOutParamUserID );
pCmd->CommandText = "ProcTest2";
pCmd->CommandType = adCmdStoredProc;
pCmd->Prepared = VARIANT_TRUE;
pCmd->ActiveConnection = m_pDBConn;
_RecordsetPtr pRecordSet;

pRecordSet = pCmd->Execute( NULL, NULL, adOptionUnspecified );
if( pRecordSet )
{
while( !pRecordSet->EndOfFile )
{
char szUserName[32];
_snprintf( (char*)szUserName, 32 , _bstr_t( pRecordSet->Fields->Item["UserName"]->Value.bstrVal ) );
int n = 0;
}
}
}
catch(_com_error e)
{
TCHAR szOut[MAX_PATH];
sprintf( szOut, "[ERROR][COM]: \n[0x%08X][%d][%s]\n[%s]\n%s\n",
e.Error(), e.Error(), e.ErrorMessage(), (TCHAR*)e.Source(), (TCHAR*)e.Description());
}

///////////////////////////////////////////////////////////
// ProcTest2是这样创建的
create procdure ProcTest2(OUT nOutDataUserID INT)
BEGIN
select UserName from users where UserID=1;
set nOutDataUserID = 1;
END
...全文
167 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dongdong034 2008-09-25
  • 打赏
  • 举报
回复
终于找到官方解释:c和odbc、PHP不支持OUT和INOUT参数,所以只好改由带结果返回了
Stored procedures in MySQL 5 and 6 accept IN, OUT and INOUT parameters. The parameters work
as documented in the mysql client. Do they work when called via MySQL language APIs?
MySQL Connector/NET supports OUT parameters, and the manual describes how to use them. That's
so also for Connector/J. But the C API, Connector/ODBC 3.51, Connector/ODBC 5.1, and Connector/
PHP have no syntax for fetching the value of an OUT or INOUT parameter. Mark Matthews threw
some light on the issue in a 3 March 2006 bug note:
"Since there's no support in the protocol for an RPC call or binding directionality of parameters
using server-side prepared statements for stored procedures, clients run into the issue that there is no
standard or straightforward way to deal with OUTPUT or INOUT parameters, especially when a user
wants to use a literal as the IN value of an INOUT parameter.
cslxj 2008-09-22
  • 打赏
  • 举报
回复
我看不懂,正学SQL
内存泄漏 2008-09-22
  • 打赏
  • 举报
回复
看异常提示是说存储过程参数的问题..你把存储过程的代码帖出来看看...

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧