| Utility functions / Database utility functions (IMPORT FGL fgldbutl) | |
Generates a new sequence for a given identifier.
db_get_sequence( id STRING ) RETURNING result BIGINT
This function generates a new sequence from a register table created in the current database.
CREATE TABLE seqreg ( sr_name VARCHAR(30) NOT NULL, sr_last BIGINT NOT NULL, PRIMARY KEY (sr_name) )
Each time you call this function, the sequence is incremented in the database table and returned by the function.
It is mandatory to use this function inside a transaction block, in order to generate unique sequences.
IMPORT FGL fgldbutl
MAIN
DEFINE ns BIGINT, s INTEGER
DATABASE mydb
BEGIN WORK
LET ns = db_get_sequence("mytable")
INSERT INTO mytable VALUES ( ns, 'a new sequence' )
COMMIT WORK
END MAIN