25.4. Modifying the Database
There are two operations that modify qdbm databases: adding records and removing records. Updating records is done using the same function as adding records.
25.4.1. Adding Records
New and updated records are recorded in the database through the dpput() function.
int dpput(DEPOT * depot, const char * key, int keySize, const char * data, int dataSize, int dmode);
The key is the index value that can later be used to retrieve the information referenced by data. Both keySize and dataSize may be -1, which tells dpput() to use strlen() to get the size of that field. It looks at the dmode parameter only if there is already a data item associated with key in the database. dmode can have one of the following values:
The new data is appended to the end of the data already in the database.
The database is not modified; dpput() returns failure and dpecode is set to DP_EKEEP.
The data in the database is overwritten with the new value.
dpput() returns zero if an error occurred (or if the key already existed and DP_DKEEP was specified), and nonzero if the data for the key was updated successfully.
25.4.2. Removing Records
Remove records from the database by passing the key whose data should be removed to dpout().
int dpout(DEPOT * depot, const char * key, int keySize);
The specified key and the data associated with it are removed from the database, and a nonzero value is returned. If there is no data for that key, zero is returned. As for all of the other functions that take a key, if the keySize is -1, dpout uses strlen() to find the length of the key.