Hello!

Hello!

I have a small problem, I don't know which of these is right:
- I am using Zeos 7.3 components wrong(possible)
- I am using Firebird 2.5 wrong(possible)
- There is a problem with the ZEOS components(not so very possible, but still)
- There is a problem with Firebird 2.5(uh... not very likely is it?)

This is my stored procedure:

CREATE OR ALTER PROCEDURE GET_PRIMARY_KEY (
    office_id integer not null,
    tablename varchar(100) not null)
returns (
    newprimarykey bigint)
as
declare variable tableid integer;
declare variable newmax integer;
begin
  SELECT ID
  FROM DATA_KEYS
  WHERE TABLE_NAME = :TABLENAME AND OFFICE_ID = :OFFICE_ID
  INTO :TableId;
  NewPrimaryKey = Power(2,32);
  NewMax = gen_id( GEN_KEY_SEQUENCE,1 );
  UPDATE DATA_KEYS SET MAXVALUE = :NewMax
  WHERE ID = :tableid;
  NewPrimaryKey = ( NewPrimaryKey + NewMax ) * Office_ID;
  suspend;
end

And I am using the ZStoredProc component in this way(yes it needs refactoring and am on it, just not right now):

function TServerDataModule.GetPrimaryKeyValue(OfficeID: Integer;
  TableName: String): Int64;
begin
  PrimaryKeyProc.Connection := FBConn;
  PrimaryKeyProc.StoredProcName := 'GET_PRIMARY_KEY';
  PrimaryKeyProc.Prepare;
  PrimaryKeyProc.ParamByName( 'Office_Id' ).Value := OfficeID;
  PrimaryKeyProc.ParamByName( 'TableName' ).Value := TableName;
  PrimaryKeyProc.Open;
  Result := PrimaryKeyProc.ParamByName( 'NewPrimaryKey' ).Value;
  PrimaryKeyProc.Close;
end;

However, Result is always zero.
When I run the stored in IBExpert personal edition, I get the "right"
result(i.e. a very big non zero number).
Result is zero because, as it happens, the output param has an "unassigned" value when looked at in debug.

Hence, somewhere it's going wrong and I have no idea where :)

Suggestions?

Regards,

A

Comments

  1. Do you have a SQL monitor in the client library? I'd check the monitor output first thing.

    I do not know about zeos components, sorry. But...

    Some dataaccess components needs the First call in order to position the record on the first row (perhaps this could be it since the procedure is a suspended procedure). Ususally with suspend a result set is returned so maybe you have to access FieldByName for the output? Maybe the component can not handle a suspend and you need to write a select statement?

    I think IBExpert figures all this out for you. If you look at the output from a procedure ending with suspend and one without suspend you'll see the difference (the first will produce a result set with one row, the other a "message" type result).

    Just some thoughts. HTH.

    ReplyDelete
  2. Mmmmh,... I'll try this one :)

    You might definitely be right.

    A

    ReplyDelete

Post a Comment