I think Ed's solution is the best more or less bulletproof one. I implement something similar in my apps. I have a table called SETUP with the names of every table, and the next id to be issued in it....In the default value of each primary key, I have:
getid('employees')
(where employees is the name of the table and in the stored procedures):
PROCEDURE GETID
PARAMETERS gettable
** Gets the next id for each table
LOCAL lcoldalias, lnreturn
lnreturn=0 && to hold the new id
lcoldalias=alias() && so we can return to the originally selected table
USE setup ORDER tablename in 0 SHARED && open the setup table
SELECT setup
SEEK gettable && Look for the name of the table to be added to
IF FOUND()
LOCK() && Lock the record - set reprocess should allow others to get it &&after this is done
lnreturn=nextid && Grab the id
replace nextid with nextid+1 && Increment the id by one
UNLOCK && Unlock the record
ENDIF
select setup
use
select (lcoldalias)
RETURN lnreturn && Return the id from the setup table
It seems to me that anyone tryibng to get unique values has to have some variation of this scheme. To me it seems pretty simple - all table share this same method for key generation. The main thing it does it prevent two people from ever getting the same number. And that of course is the goal, whowever your variation of this idea gets you there.
Jerry
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement