Dupdate(C-3) changes information in the current record. Only the fields
specified by the drlist or dblist call are changed. Any fields
in the actual file record not in the user record are not changed. Before making
the call to dupdate, your program must have established a current record
as described previously. The program changes the fields to be modified and calls
dupdate. Changing the primary key field(s) of a record is not permitted.
If a primary key field needs to be changed, the record must be deleted and re-inserted
with the correct key.
Dupdate returns -1 if the changes cannot be made. There are basically 4 reasons for dupdate to fail:
1. A current record is not defined.
2. An error was detected while RMS was moving data from the user record to the actual file record.
3. The user program has tried to change the primary key.
4. Some general I/O error has occurred.
If an error is returned, the RMSfile record is not changed. When dupdate fails, the current record is no longer current and must be re-read somehow to make it current again. Upon successful completion of dupdate, the RMSfile record is changed, and the current record is still current. This allows the same record to be changed several times with multiple calls to dupdate. A sample call to dupdate might be:
recno = dupdate (&magbuf, mag);
This statement would change the current magazine record to the contents of magbuf at the time of the call. The entire sequence to update a record might use the following code:
#include <sio.tdio.h>
#include <cbase/dir>
#include <cbase/dtypes.h>
#include "mag.h"
chg_mag (magazine, title)
char *magazine;
char *title;
{
/* move key into data buffer */
strncpy (magbuf.magazine,
magazine, sizeof (magbuf.magazine));
if (dfindk (&magbuf, mag) <= 0L) {
printf ("no magazine record exists for %s\n",
magazine);
}
else {
/* change data in buffer */
strncpy (magbuf.title, title,
sizeof (magbuf.title));
/* ... */
if (dupdate (&magbuf, mag) < 0L) {
printf ("%s\ncan't change magazine record for %s\n",
derrmsg(), magazine);
}
else
printf ("magazine changed: %s = %s\n",
magbuf.magazine, magbuf.title);
}
}