我有这个 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
,因为它找不到这样的字段。