Using an Update Component’s Query Property

From InterBase

Go Up to Creating SQL Statements for Update Components


Use the Query property of an update component to access one of the update SQL properties DeleteSQL, InsertSQL, RefreshSQL, or ModifySQL, such as to set or alter the SQL statement. Use UpdateKind constant values as an index into the array of query components. The Query property is only accessible at runtime.

The statement below uses the UpdateKind constant ukDelete with the Query property to access the DeleteSQL property.

with IBUpdateSQL1.Query[ukDelete] do begin
  Clear;
  Add(DELETE FROM Inventory I);
  Add(WHERE (I.ItemNo = :OLD_ItemNo));
end;

Normally, the properties indexed by the Query property are set at design time using the Update SQL editor. You might, however, need to access these values at runtime if you are generating a unique update SQL statement for each record and not using parameter binding. The following example generates a unique Query property value for each row updated:

procedure TForm1.EmpAuditUpdateRecord(DataSet: TDataSet;
  UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
begin
  with IBUpdateSQL1 do begin
    case UpdateKind of
      ukModified:
        begin
          Query[UpdateKind].Text := Format('update emptab set Salary = %d where EmpNo = %d',
            [EmpAuditSalary.NewValue, EmpAuditEmpNo.OldValue]);
          ExecSQL(UpdateKind);
        end;
      ukInserted:
        {...}
      ukDeleted:
        {...}
    end;
  end;
  UpdateAction := uaApplied;
end;
Note:
Query returns a value of type TIBDataSetUpdateObject. To treat this return value as a TIBUpdateSQL component, to use properties and methods specific to TIBUpdateSQL, typecast the UpdateObject property. For example:
with (DataSet.UpdateObject as IBUpdateSQL).Query[UpdateKind] do begin
  { perform operations on the statement in DeleteSQL }
end;

For an example of using this property, see Calling the SetParams Method.

Advance To: