Re: EDS Autonumber
- Posted by Ryan W. Johnson <ryanj at fluidae.com> Dec 03, 2005
- 527 views
cklester wrote: > > Greg Haberek wrote: > > > > > Has anyone got a way of generating an autonumber under the native eds sys= > > tem? > > > > I use something similar to this. Keys start at one. When generating a > > new key, it grabs the last (and highest) then returns the next number. > > If the table is empty, it returns 1, the first key. > > > > }}} <eucode> > > global function db_next_key() > > > > integer count > > > > count = db_table_size() > > if count = 0 then > > key = 0 > > else > > key = db_record_key( count ) > > end if > > > > return key+1 > > end function > > </eucode> {{{ > > You'd need something like > > while keyExists( count ) do > count += 1 > end while > > so as to avoid duplicate keys in cases where records get deleted. > > -=ck > "Programming in a state of Euphoria." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> I made a good-sized database application in Visual Basic 6.0, using an ODBC connection to an mdb (Access) file. I always made keys using the maximum key value + 1. That way, it will still work after you delete records. The only problem i could see is once you hit the highest value possible, you wolud have to wrap around back to 0, and check to make sure you only use unused values. ~Ryan W. Johnson [cool signature here, if i ever think of one...]