The Query property of an update component provides access to the query components that implement its DeleteSQL, InsertSQL, and ModifySQL statements. In most applications, there is no need to access these query components directly: you can use the DeleteSQL, InsertSQL, and ModifySQL properties to specify the statements these queries execute, and execute them by calling the update object's Apply or ExecSQL method. There are times, however, when you may need to directly manipulate the query component. In particular, the Query property is useful when you want to supply your own values for parameters in the SQL statements rather than relying on the update object's automatic parameter binding to old and new field values.
procedure TForm1.BDEClientDataSet1BeforeUpdateRecord(Sender: TObject; SourceDS: TDataSet; DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind; var Applied: Boolean); begin UpdateSQL1.DataSet := DeltaDS; { required for the automatic parameter substitution } with UpdateSQL1.Query[UpdateKind] do begin { Make sure the query has the correct DatabaseName and SessionName } DatabaseName := (SourceDS as TDBDataSet).DatabaseName; SessionName := (SourceDS as TDBDataSet).SessionName; ParamByName('TimeOfUpdate').Value = Now; end; UpdateSQL1.Apply(UpdateKind); { now perform automatic substitutions and execute } Applied := True; end;
void __fastcall TForm1::BDEClientDataSet1BeforeUpdateRecord(TObject *Sender, TDataSet *SourceDS, TCustomClientDataSet *DeltaDS, TUpdateKind UpdateKind, bool &Applied) { UpdateSQL1->DataSet = DeltaDS; // required for the automatic parameter substitution TQuery *pQuery = UpdateSQL1->Query[UpdateKind]; // access the query // make sure the query has the correct DatabaseName and SessionName TDBDataSet *pSrcDS = dynamic_cast<TDBDataSet *>(SourceDS); pQuery->DatabaseName = pSrcDS->DatabaseName; pQuery->SessionName = pSrcDS->SessionName; // now substitute values for custom parameters pQuery->ParamByName("TimeOfLastUpdate")->Value = Now(); UpdateSQL1->Apply(UpdateKind); // now do automatic substitution and execute Applied = true; }
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|