Firebird存储过程始终返回零

时间:2012-09-25 11:42:45

标签: stored-procedures firebird c++builder-xe2

这是我的存储过程:

SET TERM ^ ;
CREATE PROCEDURE INSERT_ETYPE (
    E_ID Integer,
    E_NAME Varchar(20) CHARACTER SET NONE )
RETURNS (
    NEW_ID Integer)
AS
declare variable addr varchar(20);
declare variable type smallint;
declare variable ord smallint;
declare variable cmd varchar(255);
declare variable answr varchar(255);
begin
  insert into ETYPE
  select * from ETYPE where ID=:e_id;
  select max(ID) from ETYPE into :new_id;

  update ETYPE set NAME = :e_name where ID = :new_id;
  for 
    select ADDR,REGTYPE,ORD from ETYPEREGS 
      where ETYPE_ID=:e_id
      into :addr,:type,:ord
    do
      begin
        insert into ETYPEREGS
          (ETYPE_ID,ADDR,REGTYPE,ORD)
         values
          (:new_id,:addr,:type,:ord);
      end 
  for 
    select CMD,ANSWR,ORD,REGTYPE from ETYPESPECIAL 
      where ETYPE_ID=:e_id
      into :cmd,:answr,:ord,:type
    do
      begin
        insert into ETYPESPECIAL
          (ETYPE_ID,CMD,ANSWR,ORD,REGTYPE)
         values
          (:new_id,:cmd,:answr,:ord,:type);
      end
end^
SET TERM ; ^

这是我在C ++中的代码:

StoredProc_InsertEType->ParamByName("E_ID")->AsInteger = src_id;
StoredProc_InsertEType->ParamByName("E_NAME")->AsString = _name;
try
{
 StoredProc_InsertEType->ExecProc();
 new_id = StoredProc_InsertEType->ParamByName(L"NEW_ID")->AsInteger;
}
catch(EDBEngineError & e)
{
 errors->Add(e.Message);
 return false;
}

无论表ETYPE是否为空,变量new_id始终为零。当我从管理工具FlameRobin运行命令SELECT MAX(ID) FROM ETYPE时,它返回正确的数字(~180)。我该怎么做才能获得正确的NEW_ID参数值?

0 个答案:

没有答案