ZQuery.Delete and ZQuery.Eof

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 766
Joined: 18.11.2018, 17:37
Location: Hungary

ZQuery.Delete and ZQuery.Eof

Post by aehimself »

Hi all,

I did my research and I know that this is not a bug in Zeos, but it Delphi's way of handling datasets but it's quite annoying and easy to fix.
You are scrolling through a dataset, deleting some records on the way:

While Not ZQuery.Eof Do
If somecondition then ZQuery.Delete
Else ZQuery.Next;

All is fine until you are trying to delete the last record, as it is not setting the Eof and somecondition might return a false positive (e.g. checking for duplicates) and start deleting records you don't want to.

The following workaround works:

Procedure TMyOwnSQLTable.Delete;
Var
islast: Boolean;
Begin
SQLTable.Next;
islast := SQLTable.Eof;
If Not islast Then SQLTable.Prior;
SQLTable.Delete;
If islast Then SQLTable.Next;
End;

So my question is if this is a well-known issue in Delphi, how come it is not fixed yet? Or am I missing something and deleting the last record should not set Eof? If this is the case, can anyone explain why?

Cheers!
Delphi 12.1, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmariadb.dll 3.3.8
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.13
- MSSQL 2012, 2019; sybdb.dll FreeTDS_2435
- SQLite 3.45.2
Post Reply