With this peace of code I save a record by inserting / updating:
procedure TDBWorld.SaveToDatabase(const aNewRecord: boolean);
var Country : TCountry;
obJID : integer;
MyQuery : TStrings;
begin
Myquery := TStringlist.create;
try
if aNewRecord then
begin
MyQuery.AddText('INSERT INTO countries (name, capital, population, continent_id)');
MyQuery.AddText('VALUES (:name, :capital, :population, :continent_id)');
if fWorld.Countrylist.Count = 0 then
objID := 0
else
objID := fWorld.Countrylist.Count - 1;
end else
begin
MyQuery.AddText('UPDATE countries SET');
MyQuery.AddText('name = :name, capital = :capital,');
MyQuery.AddText('population = :population, continent_id = :continent_id');
MyQuery.AddText('WHERE id = :id');
objID := fWorld.fID;
end;
Country := fWorld.Countrylist[objID];
fSQLQuery.SQL.Text := MyQuery.Text;
fSQLQuery.Params[0].AsString := Country.name;
fSQLQuery.Params[1].AsString := Country.capital;
fSQLQuery.Params[2].AsString := Country.population;
fSQLQuery.Params[3].AsInteger := Country.continent_id;
if not aNewRecord then
fSQLQuery.Params[4].AsInteger := Country.id;
fSQLQuery.ExecSQL;
if DMConnection.SQLConnector1.ConnectorType <> 'SQLite3' then
fSQLTransaction.Commit
else
dmConnection.SQLTransaction1.Commit;
showmessage(inttostr(fSQLQuery.RowsAffected));
if aNewRecord then
Country.id := GetLastID;
finally
MyQuery.free;
end;
end;
fSQLQuery.RowsAffected gives -1 when updating the record. I can see in the database (sqlite) the record is updated.
How can I check in Lazarus if this is true.
I'm using Lazarus 2.04 64b /FPC 3.04 on Windows 10