Subject | Get duplicate generator value? Am I doing wrong? |
---|---|
Author | bigredinf |
Post date | 2005-04-01T08:31:37Z |
Hi,Groups!
I use Ibobject and firebird 1.03.972 on win2k server.
I have a application write by delphi,
when a record before post,I need a lotno,so I write :
procedure QDtlBeforePost(DataSet: TDataSet);
begin
if (qdtllotno.AsString = '') then
qdtlLOTNO.Value :=
afgetNewNo_str(qMainINDT.Value, 4);
end;
function afgetNewNo_str(pddate: tdate):
string;
var
lignid: integer;
begin
QGnid.sql.Clear; //QGnid is a Tiboquery
QGnid.sql.add('select gen_id(gn_lotno,1) from
rdb$database');
QGnid.ExecSQL;
lignid := QGnid.Fields[0].AsInteger;
Result := FormatDateTime('yymm', PDDATE)
+ inttostr((lignid + 10000000) mod 10000);
//so if the Gnid get the value 25418
// then the lotno will become "05035418"
end;
I though this way the lotno won't be duplicate.
and this application run just fine about 6 month.
but last week, my client report they found 2 diffent records with same
lotno.
The time between 2 record insert is about 2hours,
and I am sure they won't insert 10000 record within 2hours.
Do I do something Wrong?
Please forget my poor English.
I use Ibobject and firebird 1.03.972 on win2k server.
I have a application write by delphi,
when a record before post,I need a lotno,so I write :
procedure QDtlBeforePost(DataSet: TDataSet);
begin
if (qdtllotno.AsString = '') then
qdtlLOTNO.Value :=
afgetNewNo_str(qMainINDT.Value, 4);
end;
function afgetNewNo_str(pddate: tdate):
string;
var
lignid: integer;
begin
QGnid.sql.Clear; //QGnid is a Tiboquery
QGnid.sql.add('select gen_id(gn_lotno,1) from
rdb$database');
QGnid.ExecSQL;
lignid := QGnid.Fields[0].AsInteger;
Result := FormatDateTime('yymm', PDDATE)
+ inttostr((lignid + 10000000) mod 10000);
//so if the Gnid get the value 25418
// then the lotno will become "05035418"
end;
I though this way the lotno won't be duplicate.
and this application run just fine about 6 month.
but last week, my client report they found 2 diffent records with same
lotno.
The time between 2 record insert is about 2hours,
and I am sure they won't insert 10000 record within 2hours.
Do I do something Wrong?
Please forget my poor English.