I have this Firebird stored procedure:
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 ; ^
I need to execute this procedure in C++ Builder XE2 and finally read its return value (ERROR) to see if it succeded. Procedure returns only one row.
I tried this way:
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( );
It gives me an access violation on errorField, because it can’t find such field.
I had to change the statement: