home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.databases
- Path: sparky!uunet!wupost!psuvax1!news.cc.swarthmore.edu!ralph.cs.haverford.edu!eoliver
- From: eoliver@ralph.cs.haverford.edu (Erik Oliver)
- Subject: Re: 4D Field Incrementing
- Message-ID: <NB0WBWA2@cc.swarthmore.edu>
- Sender: news@cc.swarthmore.edu (USENET News System)
- Nntp-Posting-Host: ralph.cs.haverford.edu
- Organization: Haverford College Computer Science Department
- References: <1993Jan24.020602.20467@freenet.carleton.ca>
- Date: Sun, 24 Jan 1993 13:59:55 GMT
- Lines: 32
-
- In article <1993Jan24.020602.20467@freenet.carleton.ca> aa192@Freenet.carleton.ca (Graydon Patterson) writes:
- >
- >Here is the standard procedure I use to create unique ID's..
- >` NextID
- >$0:=[NextID]ID
- >[NextID]ID:=[NextID]ID+1
- >SAVE RECORD([NextID])
- >` end script
- >
- >To obtain a unique ID in any file use the following...
- >[Clients]Client Number:=NextID ` NEXTID being a function
- >
- >The NextIF file has only one field called ID and only one
- >record, the next ID to be called.
- >(pardon my typos)
- >--
- >
-
- NO NO NO NO NO. What if this was a multi-user database, what if lots of
- people all over the world tried to get a new ID simultaneously, two
- people might both assing $0 := [NextID]ID, and both might get the exact
- same value before raising the value of [NextID]ID, in Comp. Sci. terms,
- you have a _race condition_.
-
- If you feel the need to use this solution, turn this procedure into a
- TRANSACTION, or use the SEMAPHORE features of 4D to protect against this
- happening.
-
- But, if you really need Unique IDs, NEVER NEVER NEVER use the above
- procedure in a multi-user database, or even in a single user databse
-
- -Erik
-