Adding, updating, and deleting records

<< Click to Display Table of Contents >>

Navigation:  Application development > Accessing and updating tables >

Adding, updating, and deleting records

Previous pageReturn to chapter overviewNext page

In order to add, modify or delete a record, the cursor must have write access to the table. The table or record must not be locked by another user. If the application intends to update a record, it can lock the record through the BDE function that fetches the record. The record remains locked until the application explicitly releases it, or the session is closed. For more information about locks, see Locking

Alternatively, you can use the cached updates cursor layer to allow users to retrieve and modify temporarily cached data without immediately writing to the actual underlying database. This minimizes the amount of resource locking.

Adding a record

To add a new record to a table, the application follows these steps:

1.Initializes the client-allocated record buffer with a call to DbiInitRecord.

2.Constructs the record one field at a time, using DbiPutField. For information about BLOB fields, see Working With BLOBs.

3.Calls DbiAppendRecord or DbiInsertRecord to write the record buffer contents to the table. The application specifies whether or not to keep a record lock on the inserted record (DbiInsertRecord).

Updating a record

To modify an existing record in the table, the application follows these steps:

1.Fetches the record to be modified into the client-allocated record buffer (obtaining a lock, if necessary).

2.Writes the updated fields to the record buffer with DbiPutField. For information about BLOB fields, see Working with BLOBs.

3.Calls DbiModifyRecord to write the record buffer to the table. The application specifies whether or not to release the record lock on the updated record when DbiModifyRecord completes.

Deleting a record

To delete a record, the application follows these steps:

1.Positions the cursor on the record to be deleted.

2.Calls DbiDeleteRecord. If a record buffer is supplied, the deleted record is copied there.

3.The cursor is left positioned on the crack where the deleted record was.

dBASE and FoxPro

For dBASE and FoxPro tables, a deleted record is not removed from the table until a call to DbiPackTable is made.

Paradox

The record cannot be recalled once it is deleted. The record is not deleted if the deletion would cause violation of referential integrity. For example, if the cursor is validly positioned on a record within the master table, and that record has linked values in a detail table, then the call to DbiDeleteRecord fails, and the position of the cursor remains unchanged.

Deleting a record does not reduce table size. The only way to gain disk space for records that have been deleted is to restructure the table with a call to DbiDoRestructure. Deleted space may be reused by later inserts.

Multiple Record Updating, Adding, And Deleting

BDE provides two functions that enable your application to update, add, or delete multiple records from a table: DbiBatchMove and DbiWriteBlock.

DbiBatchMove

DbiBatchMove can be used in different modes to append, update, append and update, or subtract records from a source table to a destination table. Source and destination tables can be of different driver types. This function supports filters and field maps. It can also copy a table of one driver type to a new table of a different driver type.

This function can be used with the Text driver to import and export data to or from any supported driver type.

This function can optionally create a key violations tables, a changed table, and a problems table to store records that fail to meet the specified criteria for record transfer. A callback can be registered that alerts the application to data transfer between source and destination fields that could result in data loss.

DbiWriteBlock

To write multiple records to a table, the application creates a record buffer containing the records to be written, and calls DbiWriteBlock, passing the cursor handle of the table to be updated. The entire block of records in the record buffer is written to the specified table. This function is similar to calling DbiAppendRecord for multiple records.