Semaphore Locking Operation IN INFORMIX OnLine 7.1 Stored Procedure
Posted in 1997
I am involved in the migrations of an Oracle 7.x application
to an Informix Online 7.1 Database. One of the requirements is
for implementing something that acts like an Oracle sequence.
(for those of you who haven't dealt with these objects
they behave something like this
Once created:
SELECT <sequence_name>.Nextval
FROM DUAL; Will return the next value of
the sequence an update the next value by an increment
value defined when the sequence is created.)
I have figured out a way on paper to do these using a table and
stored procedures Something like this:
CREATE TABLE ORA_SEQUENCES ( SEQUENCE_NAME varchar(20),
NEXTVAL INT; INCREMENT_BY SMALLINT);
CREATE PROCEDURE getnextseq( sequence varchar(20))
RETURNING INT; DEFINE CURRENTVALUE INT;
DEFINE NEXTVALUE INT;
DEFINE INCR INT;
SELECT NEXTVAL, INCREMENT_BY
INTO CURRENTVALUE, INCR
FROM ORA_SEQUENCES
WHERE SEQUENCE_NAME = SEQUENCE
FOR UPDATE; -- Select current sequence and Lock row
LET NEXTVALUE = CURRENTVALUE + INCR;
-- increment sequence to generate nextvalue
UPDATE ORA_SEQUENCES SET NEXTVAL = NEXTVALUE
WHERE SEQUENCE_NAME = SEQUENCE; -- update sequence
COMMIT WORK; -- conclude transaction
RETURN CURRENTVALUE; -- send back sequence value
END PROCEDURE
problem I'm having is Whenever I include the FOR UPDATE clause
I get a syntax error Documentation is vague on this point but
seams to indicate the for update clause can only be used with a
cursor. The problem is the documentation seams to suggest that
a stored procedure cannot have an explicit cursor.
So really I have three questions.
1) How can I implement this kind of Semaphore operation in an
Informix Stored Procedure?
2) Is this the best way to approach this particular problem
(implementing sequences)?
3) Is my admittedly limited understanding of Informix SPL
correct (i.e. no cursors allowed)?
AT this point I'm willing to take any constructive comments;
- Sean U.M. McGrath
urielmcg@worldnet.att.net