Please see this reply to your other post on the same subject and avoid starting new threads when you already have active threads on the same topic.
I have no idea why you want to make this so hard either. In a prior post, I showed you how to attach a database to an existing SQLITE connection (your requirement was that the archive is in a separate database file) and then perform the archive by simply doing something like:
attach database '/path/to/archive/db.sqlite' as arch;
insert into arch.userlogevent select * from main.userlogevent where dateTime < datetime('now','localtime','-30 days');
delete from main.userlogevent where dateTime < datetime('now','localtime','-30 days');
attach database '/path/to/archive/db.sqlite' as arch;
insert into arch.userlogevent select * from main.userlogevent where dateTime < datetime('now','localtime','-30 days');
delete from main.userlogevent where dateTime < datetime('now','localtime','-30 days');
To copy to clipboard, switch view to plain text mode
Needless to say, you should check success/failure of each SQL statement above before executing the next, i.e. you don't want to delete the records from the primary table if there were not inserted into the archive successfully, etc.
All done in SQL, no loops required, no QDateTime comparisons needed at all.
Bookmarks