A single function is used for both inserting and updateing records. The most common form of the function is rec_post() which may be called as follows:
rec_post(&customer.l);
The only parameter is a C structure that corresponds to the table containing the record that is to be posted to the queue. In this case, the CUSTOMER table is to be updated.
The function rec_post() does not specify any checking on the database. To specify checking, use the function rec_post_with_flags().
rec_post_with_flags(&customer.l, CHECK_PARENT);
Again the first parameter is the C structure that corresponds to the table containing the record that is to be posted to the queue. The CUSTOMER table is to be updated.
The second parameter is a set of flags detailing the checks to be performed at commit time, in this case the CHECK_PARENT flag. is specifed This means that the database is not updated unless a parent record exists for foreign keys marked for parent checking. In this case the only such parent table is the REGION table, and so the user cannot enter a new or modified CUSTOMER record unless it includes a valid region code.
If you use the CHECK_PARENT flag with rec_post_with_flags, the new record is still posted to the queue even if it does not have a parent. This is because the checking is not done until db_update is called to write the transaction to the database. You can find out more about the possible checks in the documentation for the rec_post_with_flags(),dp4_rec_post() function.
These functions may be called several times to create a single transaction that contains several updates. When db_update() is called, the complete. This is discussed further in Committing, Flushing and Checkpointing.
The function db_update returns a non zero (and negative) value if it detects a fail condition, the return value corresponds to the error. For example if a contention error is detected the return value is -COMMIT_FAILURE. In the C library version of the function the fail_code variable is used to store the asame information, but this time with a positive value.
If a transaction is rejected because a check specified in a preceding call to rec_post_with_flags() fails, fail_code is set to the same value as the flag, for example if a parent check fails db_update() returns -PARENT_CHECK and fail_code is set to PARENT_CHECK.