Product Documentation

FairCom DB API for C

Previous Topic

Next Topic

ctdbWriteRecord

Add a new record or update an existing record to a table.

Declaration

CTDBRET ctdbWriteRecord(CTHANDLE Handle)

Description

ctdbWriteRecord() adds a new record to a table or updates an existing record in the table. If you want the former to happen (add a new record to the table), then call the ctdbClearRecord() function to clear the record buffer before using the ctdbSetRecordBuffer() function or the ctdbSetFieldAs() functions to fill the record buffer with the contents of the new record. If you wish, instead, to update the record that the record handle currently points at, do not call ctdbClearRecord(). Just use the ctdbSetRecordBuffer() function or the ctdbSetFieldAs() functions to set the buffer before writing the record by calling this function.

If you are using this function to update an existing record, it is recommended that a WRITE_LOCK be acquired on the record as it is read from the table file, using session-wide record locking. First call ctdbLock() to turn on session-wide record locking in WRITE mode, then read the existing record for the table, which will automatically aquire a WRITE lock for the record. Then, the desired modifications to the record can be made, then this function can be called to write the changes to the table file, and then the record can be unlocked by turning off session-wide record locking (ctdbUnlock()), or by manually unlocking the record (ctdbUnlockRecord()). If this operation is done inside a transaction, the record will be automatically unlocked when the transaction is ended (by calling ctdbCommit() or ctdbAbort()).

If you are using this function to add a new record to a table, session-wide record locking can be used in a similar way. First call ctdbLock() to turn on session-wide record locking, then this function can be called to auto-lock the record and write the changes to the table file, and then the record can be unlocked as described in the previous paragraph.

  • Handle [in] the record handle.

Returns

ctdbWriteRecord() returns CTDBRET_OK if successful, or the c-tree error code on failure.

See also

ctdbAllocRecord(), ctdbReadRecord(), ctdbDeleteRecord(), ctdbSetRecordBuffer(), ctdbGetErrorIndex()

TOCIndex