FireDAC.Comp.DataSet.TFDDataSet.RefreshRecord
Delphi
function RefreshRecord(AClearRow: Boolean = True): Boolean;
C++
bool __fastcall RefreshRecord(bool AClearRow = true);
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | FireDAC.Comp.DataSet.pas FireDAC.Comp.DataSet.hpp |
FireDAC.Comp.DataSet | TFDDataSet |
Description
Rereads the field values of the current record from a data source.
Use RefreshRecord to discard all the changes of the current record and reread it from a data source. A similar method, TDataSet.Refresh, replaces the entire contents of the dataset by re-executing the SQL command.
To reread the record, FireDAC performs the following sequence of steps:
- If the OnUpdateRecord event handler is assigned, then it is called with
ARequest
having the value ofarFetchRow
. - If the event handler is not assigned or it returns
AAction
with theeaDefault
value, then:- If TFDAdaptedDataSet.UpdateObject is assigned and TFDUpdateSQL.FetchRowSQL is not empty, then this SQL command is executed.
- Otherwise FireDAC generates a
SELECT
command that rereads a single row from the database and executes the command.- Note: The generated command is
SELECT A
.* FROM
(<insert original SQL command>)A WHERE
(<key fields comparison>). So, the original SQL command must be compatible with the generated command. For example, with SQL Server theSELECT
list items must have a unique name, otherwise the "The column 'Xxx' was specified multiple times for 'A'" error is returned.
If the query to a data source returns no rows (for example, when a record is deleted), then when UpdateOptions.RefreshDelete is True, a record is removed from a dataset, otherwise an exception is raised. When the AClearRow
parameter is set to True (default value), then the record is initially erased. Otherwise the read values override the corresponding column values.
The method returns True if a record is refreshed. Otherwise, it returns False if it is deleted from a dataset.
Example
FDQuery1.UpdateObject := ADUpdateSQL;
// PL/SQL block calling packaged procedure returning customer data by its ID
FDUpdateSQL.FetchRowSQL.Text := 'begin cust_pack.read_cust_data(:new_name, :new_company, :new_state, :old_id); end;';
// Is always required to set up output parameters
with FDUpdateSQL.Commands[arFetchRow] do begin
Params[0].ParamType := ptOutput;
Params[0].DataType := ftString;
Params[1].ParamType := ptOutput;
Params[1].DataType := ftString;
Params[2].ParamType := ptOutput;
Params[2].DataType := ftString;
end;
...
FDQuery1.RefreshRecord;