UNIQID |
uniqid is used to generate a sequence of unique long integers for each Adonix table.
uniqid ( class )
|
Element |
Description |
Restrictions |
|
class |
Description of a table. |
The table must be opened. |
# I wish to number in a unique manner the written recording
[F:FIC1]NUMERO = uniqid([FIC1])
Write [FIC1]
uniqid is used to have a unique number for a given table opened previously; these numbers are assigned sequentially and therefore they can be used as an acces key to the file.
These numbers are kept by copy, extraction, restoration and revalidation of the table.
Warning ! This number sequence does not need to be consecutive. For instance, there is no number retrieval further to a Rollback.
The result type is Integer.
For a newly created table, numbers are assigned from number 1 and then sequentially by steps of 1. Should the structure be modified, the current number is kept, if a table is reset to 0, the numbers are reassigned starting from 1.There is no other way to decrement this sequence of numbers.
The numbers assigned sequentially cannot be reassigned if a transaction is aborted by Rollback. To implement this kind of function, if all the numbers should be assigned, it is recommended to resort to counters (for instance, a main counter and a grid containing the aborted numbers to be reassigned in priority).
The uniqid instruction is executed even if the table is locked.
The uniqid instruction does not update the [S]fstat variable.
This unique number delivered by the uniqid instruction is sometimes used in a key field without homonym. (Example of the AREPORTM table)
There is a problem if the sequence no longer exists. X3 sends an error message linked to the database. Then the database log file needs to be referred to for further details.
Since sequences are used to build unique keys, if the uniqid function returns a value lower than the last one to be recorded, X3 will display an error message of the type"Key does not exist in the table". In that case, the sequence needs to be updated.
Example of the GACCDENTRYD table of a "DEMO" folder
Under X3
Local file GACCENTRYD [DAE]
Local integer MAX
MAX = uniqid([DAE])
Read [DAE]DAE2 last
If MAX < =[F:DAE]ACCNUM
Errbox "The sequence of the GACCENTRYD table must be rebuilt"
Errbox "It should be" +num$([F :DAE]ACCNUM)+ "but it is" +num$(MAX)
Endif
Under Oracle
# the correct environment, etc. variables need to be positioned in order to be able to launch the next SQL queries.
Select last_number from user_sequences where sequence_name =’SEQ_GACCENTRYD’;
Under SQL Server
select value from SS_SEQUENCE where usr='DEMO' and name='GACCENTRYD'
Under X3
# By proceeding with the process started above.
# The most simple solution is to ensure that there is only one user on this particular file
If nbruser > 1: Errbox ‘You are not the only user of this folder!’ : End: Endif
While uniqid([DAE]) <MAX: Wend
Under Oracle
#aftar having made sure that there is only one user of folder
#, the safest way is to recreate the sequences before assigning them the correct value.
Drop sequence SEQ_GACCENTRYD ; (destroys the register)
Create sequence SEQ_GACCENTRYD increment by 1 start with <MAX+1> ;
grant select on SEQ_GACCENTRYD to ADMIN_ADONIX
Under SQL Server
# the sequences only need to be updated without destroying them beforehand
update SS_SEQUENCE set value=<MAX> where name='GACCENTRYD' and usr='DEMO'
|
Error |
Description |
|
ERCLAS (7) |
The file is not open. |
READ - WRITE - READLOCK - ROLLBACK
|
Copyright © Sage 1999 - 2007 |