Got it almost working. I create a temp table to stick the id in before I call the stored procedure then fetch the id from the temp table afterwards.
Code:
create procedure GetNextOrderID(IN :user CHAR(8))
AS
START TRANSACTION
DECLARE :nxtid INTEGER;
DECLARE :curid INTEGER;
SELECT TOP 1 Nextsysdocid into :curid FROM Oenextsy ORDER BY Nextsysdocid ASC FOR UPDATE;
SET :nxtid = :curid + 1;
INSERT INTO Oenextsy ( Nextsysdocid, Recuserid, Recdate, Rectime ) VALUES( :nxtid, :user, curdate(), CURRENT_TIME() );
INSERT INTO ##tmpidtable (ID) VALUES(:nxtid);
DELETE FROM Oenextsy WHERE Nextsysdocid=:curid;
COMMIT WORK;
With the above code I get the following error when creating the procedure:
Code:
'FOR': Syntax error
If I remove "FOR UPDATE" then it works fine. However, as I understand it, another user could fetch the same id before the Nextsysdocid table is updated. Any idea why Pervasive does not like the FOR UPDATE?