procedure Tdm.ClearToLatest;
var
AllDone : Boolean;
begin
tblData.DisableControls;
try
AllDone:=False;
tblData.First;
repeat
tblData.Delete;
AllDone:=tblData.RecordCount <= 1000;
until AllDone;
finally
tblData.EnableControls;
end;
end;
tStr:='DELETE FROM tblData WHERE inDate <= date(''now'',''-2 day'')';
... but I got a bit more creative with searching and found this for a Query...Yep, that will work too.Code: [Select]tStr:='DELETE FROM tblData WHERE inDate <= date(''now'',''-2 day'')';
Running the program for a few hours will result in about 10,000 records being gathered.If you have 10.000 records in a few hours, you're still left with a lot of records if you only delete everything older than 2 days. You could also use "-4 hours" or something in which case you come closer to those 1000 records you wanted.
It would be nice to include the 1000-limit with the Date, but I can't find anything that relates to "Remaining Record Count" within SQLite3. So, no way I can tell it to stop at 1000, 5000 or whatever.You can (kinda). There is no way to tell which records are the last 1000 (maybe there is but I'm on mobile now so can't check) but you can limit it to the date of the previous 1000 records (which might be more but never less).
https://www.sqlite.org/lang_createtable.html#rowid (https://www.sqlite.org/lang_createtable.html#rowid)
Except for WITHOUT ROWID tables, all rows within SQLite tables have a 64-bit signed integer key that uniquely identifies the row within its table. This integer is usually called the "rowid". The rowid value can be accessed using one of the special case-independent names "rowid", "oid", or "_rowid_" in place of a column name. If a table contains a user defined column named "rowid", "oid" or "_rowid_", then that name always refers the explicitly declared column and cannot be used to retrieve the integer rowid value.
as far as i understood right, you can use rvk's sql script without problem (with little mod)Yes, I kinda suspected there was something internal but couldn't check at the time.