1. EDS Autonumber
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Dec 01, 2005
- 555 views
Has anyone got a way of generating an autonumber under the native eds system? Thanks, Alex
2. Re: EDS Autonumber
- Posted by cklester <cklester at yahoo.com> Dec 01, 2005
- 534 views
Alex Chamberlain wrote: > > Has anyone got a way of generating an autonumber under the native eds system? Look at how EuSQL does it for some ideas. -=ck "Programming in a state of Euphoria." http://www.cklester.com/euphoria/
3. Re: EDS Autonumber
- Posted by Robert Craig <rds at RapidEuphoria.com> Dec 01, 2005
- 504 views
Alex Chamberlain wrote: > Has anyone got a way of generating an autonumber under the native eds system? If there is no natural value to use for the key, I just use the current db_table_size(). Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
4. Re: EDS Autonumber
- Posted by cklester <cklester at yahoo.com> Dec 01, 2005
- 536 views
- Last edited Dec 02, 2005
Robert Craig wrote: > Alex Chamberlain wrote: > > Has anyone got a way of generating an autonumber under the native eds > > system? > If there is no natural value to use for the key, > I just use the current db_table_size(). Couldn't deleting records could mess that system up? -=ck "Programming in a state of Euphoria." http://www.cklester.com/euphoria/
5. Re: EDS Autonumber
- Posted by Robert Craig <rds at RapidEuphoria.com> Dec 01, 2005
- 508 views
- Last edited Dec 02, 2005
cklester wrote: > Robert Craig wrote: > > Alex Chamberlain wrote: > > > Has anyone got a way of generating an autonumber under the native eds > > > system? > > If there is no natural value to use for the key, > > I just use the current db_table_size(). > > Couldn't deleting records could mess that system up? Yes. Come to think of it, I used it in a case where I wasn't planning to delete records. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
6. Re: EDS Autonumber
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Dec 01, 2005
- 530 views
- Last edited Dec 02, 2005
Chers guys! I've set about using EuSQL, and I'll let you know how I get on. Are there any good exmple of using the insert routines rather than SQL? Thanks, Alex
7. Re: EDS Autonumber
- Posted by Greg Haberek <ghaberek at gmail.com> Dec 02, 2005
- 525 views
> 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.
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
HTH, ~Greg
8. Re: EDS Autonumber
- Posted by Michael Raley <thinkways at yahoo.com> Dec 02, 2005
- 541 views
Greg Haberek wrote: > > > Has anyone got a way of generating an autonumber under the native eds sys= > tem? > you could make a serial from date{} elements, or sprintf or add them together into one string {year}{Julian Day}{hh}{mm}{ss}{table_size} --"ask about our layaway plan". --
9. Re: EDS Autonumber
- Posted by cklester <cklester at yahoo.com> Dec 02, 2005
- 535 views
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." http://www.cklester.com/euphoria/
10. Re: EDS Autonumber
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Dec 02, 2005
- 514 views
cklester wrote: > > Greg Haberek wrote: > > > > }}} <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. No, his method would work fine, because EDS always keeps the records sorted by key, so the last record is guaranteed to be the highest number currently in the table. Note that count is the record number of the last record, and key is the acutal key value. Of course, you'd need to define 'atom key' to make this routine work... Matt Lewis
11. Re: EDS Autonumber
- Posted by cklester <cklester at yahoo.com> Dec 02, 2005
- 510 views
Matt Lewis wrote: > cklester wrote: > > Greg Haberek wrote: > > > 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 > > 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. > > No, his method would work fine, because EDS always keeps the records sorted > by key, so the last record is guaranteed to be the highest number currently > in the table. Note that count is the record number of the last record, and > key is the acutal key value. Of course, you'd need to define 'atom key' > to make this routine work... Oh, I see. I misread and thought he was just using the size, like Rob said. -=ck "Programming in a state of Euphoria." http://www.cklester.com/euphoria/
12. Re: EDS Autonumber
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Dec 02, 2005
- 527 views
cklester wrote: > > Matt Lewis wrote: > > cklester wrote: > > > Greg Haberek wrote: > > > > 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 > > > 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. > > > > No, his method would work fine, because EDS always keeps the records sorted > > by key, so the last record is guaranteed to be the highest number currently > > in the table. Note that count is the record number of the last record, and > > key is the acutal key value. Of course, you'd need to define 'atom key' > > to make this routine work... > > Oh, I see. I misread and thought he was just using the size, like Rob said. > > -=ck > "Programming in a state of Euphoria." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> But, I thought that EDS refills deleted records, thus them not being sorted? Thanks, Alex
13. Re: EDS Autonumber
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Dec 02, 2005
- 531 views
Alex Chamberlain wrote: > > But, I thought that EDS refills deleted records, thus them not being sorted? > It reuses the space in the file (if it can), but the keys are always maintained in a sorted list, which is why it's important to find records based on their keys (which don't change) and not on their record number (which can change). Matt Lewis
14. Re: EDS Autonumber
- Posted by petelomax at fastmail.fm Dec 02, 2005
- 536 views
On Thu, 01 Dec 2005 15:09:11 -0800, "Alex Chamberlain" <guest at RapidEuphoria.com> said: > Has anyone got a way of generating an autonumber under the native eds > system? In Edita, I just use db_table_size(), never delete any records in the main program, and have a separate standalone utility which runs in single-user=20 mode and looks for items which ought to be deleted (in this case source files and directories which no longer exist and have no backups). If it finds any it=20 loops through the whole db replacing <high> with <first unused slot>. A simpler (but slower) way is just to have a separate record which contains a counter and is rewritten every time you add a record. You could reduce the overhead by adding say 10 to the counter, and then the next 9 record adds do not need to rewrite the counter record, and possibly release any unused slots on successful program shutdown. Regards, Pete -- =20=20 petelomax at fastmail.fm -- http://www.fastmail.fm - Same, same, but different=85
15. Re: EDS Autonumber
- Posted by Ryan W. Johnson <ryanj at fluidae.com> Dec 03, 2005
- 527 views
- Last edited Dec 04, 2005
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...]
16. Re: EDS Autonumber
- Posted by Greg Haberek <ghaberek at gmail.com> Dec 04, 2005
- 527 views
> 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. Euphoria integers are 31 bits. That's 2,147,483,647 records. Is that enough? Atoms are stored as 32-bit long integers. That's 4,294,967,296 records. Is that enough? Also, keep in mind that's per table. I supposed you could always keep track of the free record numbers somewhere and re-use them. But then your records would be out of order. ~Greg
17. Re: EDS Autonumber
- Posted by Robert Craig <rds at RapidEuphoria.com> Dec 04, 2005
- 527 views
- Last edited Dec 05, 2005
Greg Haberek wrote: > > 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. > > Euphoria integers are 31 bits. That's 2,147,483,647 records. Is that > enough? Atoms are stored as 32-bit long integers. That's 4,294,967,296 > records. Atoms are *not* stored as 32-bit long integers. Someone else said the same thing recently, so I'd better clarify. Atoms are stored (when necessary) as 64-bit floating-point values. If you are only interested in storing integer values in an atom, you can have integers up to about 15 decimal digits (52-bits) without losing any precision. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
18. Re: EDS Autonumber
- Posted by Greg Haberek <ghaberek at gmail.com> Dec 05, 2005
- 543 views
> Atoms are *not* stored as 32-bit long integers. > Someone else said the same thing recently, > so I'd better clarify. Atoms are stored (when necessary) as 64-bit > floating-point values. If you are only interested in storing > integer values in an atom, you can have integers up to > about 15 decimal digits (52-bits) without losing any precision. Ok, so 52-bits would be approximately 4,503,599,627,370,495 records. There are 31,536,000,000 milliseconds in a year. In order to use all the available record numbers, you'd have to be inserting a new record every millisecond for 142,808.2 years! I don't think we have to worry about using up all our available record numbers. Also, keep in mind these numbers are per table. ~Greg
19. Re: EDS Autonumber
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Dec 05, 2005
- 551 views
Surely, 4,503,599,627,370,495 atoms is too big for an EDS???
20. Re: EDS Autonumber
- Posted by Greg Haberek <ghaberek at gmail.com> Dec 05, 2005
- 547 views
- Last edited Dec 06, 2005
> Surely, 4,503,599,627,370,495 atoms is too big for an EDS??? Well of course, that's well over the 4 GB limit of EDS. But if you were constantly deleting a record and inserting a new one, you'd continue to update the auto number count, and the highest record number could easily be well over a billion. ~Greg