1. EDS Autonumber

Has anyone got a way of generating an autonumber under the native eds system?

Thanks,
 Alex

new topic     » topic index » view message » categorize

2. Re: EDS Autonumber

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/

new topic     » goto parent     » topic index » view message » categorize

3. Re: EDS Autonumber

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

new topic     » goto parent     » topic index » view message » categorize

4. Re: EDS Autonumber

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/

new topic     » goto parent     » topic index » view message » categorize

5. Re: EDS Autonumber

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

new topic     » goto parent     » topic index » view message » categorize

6. Re: EDS Autonumber

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

new topic     » goto parent     » topic index » view message » categorize

7. Re: EDS Autonumber

> 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

new topic     » goto parent     » topic index » view message » categorize

8. Re: EDS Autonumber

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".
--

new topic     » goto parent     » topic index » view message » categorize

9. Re: EDS Autonumber

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/

new topic     » goto parent     » topic index » view message » categorize

10. Re: EDS Autonumber

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

new topic     » goto parent     » topic index » view message » categorize

11. Re: EDS Autonumber

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/

new topic     » goto parent     » topic index » view message » categorize

12. Re: EDS Autonumber

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

new topic     » goto parent     » topic index » view message » categorize

13. Re: EDS Autonumber

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

new topic     » goto parent     » topic index » view message » categorize

14. Re: EDS Autonumber

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

new topic     » goto parent     » topic index » view message » categorize

15. Re: EDS Autonumber

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...]

new topic     » goto parent     » topic index » view message » categorize

16. Re: EDS Autonumber

> 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

new topic     » goto parent     » topic index » view message » categorize

17. Re: EDS Autonumber

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

new topic     » goto parent     » topic index » view message » categorize

18. Re: EDS Autonumber

> 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

new topic     » goto parent     » topic index » view message » categorize

19. Re: EDS Autonumber

Surely, 4,503,599,627,370,495 atoms is too big for an EDS???

new topic     » goto parent     » topic index » view message » categorize

20. Re: EDS Autonumber

> 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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu