NDBM HELP!

NDBM HELP!

Post by Brian Atki » Mon, 03 Dec 1990 00:00:00



My database gets mucked up when I do a dbm_store with mode == DBM_REPLACE.
(under 4.3, ndbm in libc).  Is this a known bug?  Is there a fix?

Also, I can't seem to find any documentation on ndbm, or the algorithm
it uses. Does such exists?  If so, where?

Thanks in advance, this is killing me.


NBI Inc., P.O. Box 9001, Boulder CO 80301       (303) 938-2986

 
 
 

NDBM HELP!

Post by Allyn Fratk » Sun, 02 Dec 1990 08:07:00



> My database gets mucked up when I do a dbm_store with mode == DBM_REPLACE.
> (under 4.3, ndbm in libc).  Is this a known bug?  Is there a fix?

> Also, I can't seem to find any documentation on ndbm, or the algorithm
> it uses. Does such exists?  If so, where?

this is not a bug, really.  but it does violate the principle of least
astonishment (at least it did for me).

the behavior you desribe is an artifact of the way ndbm works.  when it
returns a pointer to the contents corresponding to a key,
the pointer points into static storage in the page block (this is mentioned
at the end of the manual page).

you're probably modifying the data in place (in the page block) and
then trying to update the information.  but the way dbm_store works
with the DBM_REPLACE option is that it first does a delete followed by a
regular store.  so your newly updated information is getting thrown away
(deleted).  you are then inserting whatever data is left in the page
block instead of what you wanted.

i was bitten by this many times before i finally learned the hard way
how all of this worked.

anyway, the fix is to copy your data into another location before updating,
then do the dbm_store with the replace option.

the key (no pun intended) is just to remember that a store with DBM_REPLACE
is exactly the equivalent of a dbm_delete and then a dbm_store with
DBM_INSERT.  this "feature" is not mentioned in the manual.
--

                          EMU Project              {ucbvax, decvax, ihnp4}
                          U.C. San Diego                         !sdcsvax!allyn

 
 
 

1. need help with ndbm(3)

I've got an application that I'm writing on a Tandem computer, UNIX SVR3.1.1,
with the NDBM(3) library and its not working very well.

Basically I format a unique key and use dbm_store() to store the record.  The
man page says that dbm_store() will only INSERT a new record if the key is
not found in the database and that REPLACE will only update an existing record
with the same key.  For some reason I'm finding multiple copies of records
with identical keys.  I can't understand how this is happening.  Do I have
to rewind the file each time that I insert or replace a record?  

When I initialize the key I'm using:

    key.dptr = (char *) somestring;
    key.dsize = KEYSIZE;  where KEYSIZE = 80

Sometimes 'somesting' is far less than 80 bytes and NULLS are padded until
the array is filled up.  Could this be the problem?  The man page says that
you can use arbitrary binary data but, I'm wondering if this is somehow hosing
up the database.

If anyone has run into this before, I`d appreciate any advice or suggestions.

thanks
John R.

2. Connect NT to Linux via modem/PPP

3. Need help using NDBM files

4. CD-ROM not recognized with Jazz-16

5. Help! NDBM info wanted

6. WordPerfect 8 on RH 7 ??????

7. Help! ndbm and holes in file

8. Penguins

9. <ndbm.h> - help please

10. Need help with ndbm subroutines

11. Help me with ndbm

12. Help with either ndbm.h or dbm.h

13. Help! holes in ndbm files