以下是在SQLServer7中,PARADOX把(UPDLOCK) 去掉试试,用事务好像要设
Database.TransIsolation=tiDirtyRead;
function GetMaxXH(xhbs: String) :Integer;
var
XHQuery: TQuery;
Maxxh: Integer;
begin
try
DataModule2.Database1.StartTransaction;
try
XHQuery:=TQuery.Create(nil);
XHQuery.DatabaseName:=DataModule2.Database1.DatabaseName;
XHQuery.SQL.Clear;
XHQuery.SQL.Add('select xhmax from maxxh (UPDLOCK) where xhid='+
#39+xhbs+#39); // 取出Max序号并置更新锁
OpenQuery(XHQuery);
Maxxh:=XHQuery.FieldByName('xhmax').AsInteger;
if Maxxh>0 then begin // 序号从1开始
XHQuery.SQL.Clear;
XHQuery.SQL.Add('update maxxh set xhmax=xhmax+1 where xhid='+
#39+xhbs+#39); // 序号加1
RunQuery(XHQuery);
Result:=Maxxh;
end else
Result:=-1;
finally
XHQuery.Close;
XHQuery.Free;
end;
DataModule2.Database1.Commit;
except
DataModule2.Database1.Rollback;
Raise;
end;
end;