我有这个Firebird存储过程:
SET TERM ^ ;
CREATE PROCEDURE MYSP ( FIRSTPARAM Varchar(3) )
RETURNS ( ERROR Varchar(128) )
AS BEGIN
/* a lot of things, including setting a value to ERROR */
suspend;
END^
SET TERM ; ^
我需要在C ++ Builder XE2中执行此过程,最后读取它的返回值(ERROR
)以查看它是否成功。过程只返回一行。
我试过这种方式:
TIBQuery* q = DMH->ordQuery;
q->Close( );
q->SQL->Clear( );
q->SQL->Text = "EXECUTE PROCEDURE MYSP(:P1)";
if ( !DMH->ordTrans->InTransaction )
{
MakeCommit = true;
DMH->ordTrans->StartTransaction( );
}
if ( !q->Prepared )
q->Prepare( );
q->Params->ParamByName( "P1" )->Value = "abc";
q->Open();
//success if error field contains NULL
TField* errorField = q->FieldByName( "ERROR" );
bool success = errorField->IsNull;
if ( MakeCommit )
DMH->ordTrans->Commit( );
它在errorField
上给了我访问权限,因为它找不到这样的字段。
答案 0 :(得分:0)
我不得不改变声明:
SELECT ERROR
FROM MYSP(:P1)