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!
ZQuery.Delete and ZQuery.Eof
ZQuery.Delete and ZQuery.Eof
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47