3.8.3. Configuring the Customer Module for Editing

In this section, we will configure some properties in the qryCustomer and FDUpdateCustomer objects to make the Customer dataset editable.

The TFDUpdateSQL Settings

To make the dataset editable, the InsertSQL, ModifySQL, DeleteSQL and FetchRowSQL properties should be specified in the FDUpdateSQL object that is linked to the dataset. The wizard can generate these statements but it may be necessary to correct some things afterwards. For example, you can add a RETURNING clause, remove some columns from the update list or cancel an automatically generated stored procedure call entirely.

InsertSQL

  1. INSERT INTO customer (
  2. customer_id,
  3. name,
  4. address,
  5. zipcode,
  6. phone)
  7. VALUES (:new_customer_id,
  8. :new_name,
  9. :new_address,
  10. :new_zipcode,
  11. :new_phone)

ModifySQL

  1. UPDATE customer
  2. SET name = :new_name,
  3. address = :new_address,
  4. zipcode = :new_zipcode,
  5. phone = :new_phone
  6. WHERE (customer_id = :old_customer_id)

DeleteSQL

  1. DELETE FROM customer
  2. WHERE (customer_id = :old_customer_id)

FetchRowSQL

  1. SELECT
  2. customer_id,
  3. name,
  4. address,
  5. zipcode,
  6. phone
  7. FROM
  8. customer
  9. WHERE customer_id = :old_customer_id

Getting a Generator Value

In this project, we will get the value from the generator before making an insert into the table. To enable that, specify the following values for the properties of the TFDQuery component:

  1. UpdateOptions.GeneratorName = GEN_CUSTOMER_ID

and

  1. UpdateOptions.AutoIncFields = CUSTOMER_ID

This method works only for autoinc fields that are populated by explicit generators (sequences). It is not applicable to the IDENTITY type of autoinc key introduced in Firebird 3.0.

Another way to get the value from the generator is to return it after the INSERT is executed by means of a RETURNING clause. This method, which works for IDENTITY fields as well, will be shown later, in the topic Using a RETURNING Clause to Acquire an Autoinc Value.