How to get the ID of the last record inserted in SQLite with Delphi 10?

  

Delphi 10 with Firemonkey and SQLite: After running the code below I want to get the ID of the last record inserted into an SQLite table. How do I get the last ID?

NOTE: The ID field of Table 1 is autoincrement.

var myQr: TFDQuery;
begin

myQr := TFDQuery.Create(Self);

with myQr do begin
SQL.Add(‘Insert into table1 values (:_id, :_name, :_dthr)’);
Params.ParamByName(‘_id’).ParamType := TParamType.ptInput;
Params.ParamByName(‘_id’).DataType := TFieldType.ftInteger;
Params.ParamByName(‘_id’).Value := null;

ParamByName(‘_name’).AsString := ‘name test’;
ParamByName(‘_dthr’).AsDateTime := Now;
ExecSQL;
end;

// How to get last ID? <<<<<<<<<<<<<=================

myQr.DisposeOf;

Comments are closed.