Subject | Re: [IBO] Generator not incrementing |
---|---|
Author | Ed Dressel |
Post date | 2011-08-13T17:24:15Z |
> I have the same exact thing going on. My customersHere is a code snippets for checking generators:
> occasionally call and report order numbers (a generator)
> being reissued. A couple have called in the last couple
> of weeks - this is a pretty serious problem that I need to
> figure out.
procedure TdmMaster.CheckGeneratorValue(const aGenName, aTableName, aTableID: string);
var
lCur: TIB_Cursor;
lGenValue: integer;
begin
lCur := CreateCursor(Format('Select Max(%s) from %s', [aTableID, aTableName]));
try
lCur.First;
lGenValue := lCur.Fields[0].AsInteger;
finally
lCur.Free;
end;
if FIBConn.Gen_ID(aGenName, 0) <lGenValue then
ExecSQL('SET GENERATOR %s TO %d', [aGenName, lGenValue]);
end;
And I've started using the following where the problem has occurred:
function TdmMaster.GetNewKeyID(const aTableName, aFieldName, aGenName: string): integer;
var
lMaxID: integer;
begin
lMaxID := GetMaxKeyID(aTableName, aFieldName);
repeat
result := dmMaster.IBConn.Gen_ID(aGenName, 1);
until result > lMaxID;
end;
HTH,
Ed Dressel