1. EDS db_replace_key()

There isn't a db_replace_key() routine, is there? ,sad

Rgds,

Salix

new topic     » topic index » view message » categorize

2. Re: EDS db_replace_key()

> There isn't a db_replace_key() routine, is there? ,sad

Sure! I used this routine in an app I wrote a while ago. (although
this is from memory, so there may be typos)

~Greg

global procedure db_replace_key( object key1, object key2 )
-- this method is volitle, it will overwrite key2 if it exists

    integer rec
    object data

    -- find the old key
    rec = db_find_key( key1 )
    if rec< 0 then
        -- invalid key
        return
    end if

    -- store the data
    data = db_record_data( rec )

    -- remove the record
    db_delete_record( rec )

    -- find the new key
    rec = db_find_key( key2 )
    if rec < 0 then
        -- record does not exist, create it
        rec = db_insert( key2, data )
    else
        -- record does exist, replace data
        db_replace_data( rec, data )
    end if

end procedure


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

3. Re: EDS db_replace_key()

I tried to create something similar but it screwed 
up the record numbers somehow. It actually does not 
replaces the 'record key' but deletes the 'old record' 
and inserts a 'new record'.

...and I'm too lazy to write a routine as solid as 
db_replace_data(). blink))

Cheers,

Salix

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

4. Re: EDS db_replace_key()

Salix wrote:
> 
> I tried to create something similar but it screwed 
> up the record numbers somehow. It actually does not 
> replaces the 'record key' but deletes the 'old record' 
> and inserts a 'new record'.
> 

In EDS, record numbers are only temporary (subject to change every time you
insert or delete a record).  Records are sorted by key, which is how they are
numbered, so if you "change a key" for a record, the record number will also
change unless it happens to maintain the exact same position in the sorted order.
 For this reason, a db_replace_key() confuses the issue -- you really should just
delete the record and then re-insert it with the new key, keeping in mind that
the record number will most likely change...

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

Search



Quick Links

User menu

Not signed in.

Misc Menu