Subject Absolute unique value/generator/SP problem
Author Kevin Stanton
Greetings,
I have an order entry system that requires an absolutely unique order number
to be issued when sales people enter an order.

In remembering all the posts over the years, using a generator is the way to
go as it's my understanding it "operates" outside of the transaction thus
assuring a unique value.

I am getting reports of duplicate order numbers being issued (a very bad
thing).

Here's how I get the next generator value via a function in a data module:

function TdmSalesInq.GetPermOrderNo: String;
begin
{
qryGetID is a TIB_Cursor with the SQL of : select * from
sp_get_nextid(:idtype)
this cursor is hooked up to a TIB_Transaction set to autocommit = true
which should not matter (I think)
}

with qryGetID do
begin
If Active then Close;
If NOT Prepared then Prepare;
ParamByName('IDType').AsString := 'ORDERNO';
Open;
Result := FieldByName('NextID').AsString;
Close;
end;

If NOT (qryOH.State in [dssEdit, dssInsert]) then
qryOH.Edit;
qryOH.FieldByName('OrderNo').AsString := Result;
PostChanges(qryOH);
Global.RefreshQry(qryOD, False);
Global.RefreshQry(qryODC, False);
end;

//~~~~~~~~~~~~~~~~~~~~~~
sp_get_nextid looks like this:
CREATE PROCEDURE SP_GET_NEXTID(
IDTYPE VARCHAR(15))
RETURNS (
NEXTID INTEGER)
AS
BEGIN
if (IDType = 'QUOTE') then
NextID = GEN_ID(GEN_QUOTES, 1);

if (IDType = 'ORDERNO') then
NextID = GEN_ID(GEN_ORDERNO, 1);

/* many more of these */
Suspend;
end
//~~~~~~~~~~~~~~~~~~~~~~

Any ideas of my problem would be GREATLY appreciated.

Kevin