AbortOperation issue

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
stoffman
Senior Boarder
Senior Boarder
Posts: 50
Joined: 03.12.2020, 06:55

AbortOperation issue

Post by stoffman »

There is a mismatch between the return values from AbortOperation (I refer to the last version I'm using but that seems to be going on for some time https://github.com/frones/ZeosLib/tree/ ... ffe888/src)

TZSQLiteConnection.AbortOperation always returns 1

TZPostgreSQLConnection.AbortOperation set the default to 1 but on success returns 0

TZOracleConnection.AbortOperation only returns 0 (raises exception on fail)

TZFirebirdConnection.AbortOperation while I cannot test it, seems to return 1 on success and 0 and failure

What should be the correct behavior in that case, with regard to the other parts of zeos?
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: AbortOperation issue

Post by marsupilami »

Hello stoffman,

even though I didn't look at the code, I would expect that the return value of AbortOperation is irrelevant and that an Exception is raised if AbortOperation doesn't work.

A note on the branch of Zeos that you refer to: Please use https://github.com/marsupilami79/zeoslib. It is more or less our official copy and is kept up to date automatically.

Best regards,

Jan
stoffman
Senior Boarder
Senior Boarder
Posts: 50
Joined: 03.12.2020, 06:55

Re: AbortOperation issue

Post by stoffman »

It feels like this was copied form JDBC design where you have checked exceptions, so the user knows to try and catch AbortOperation. But in pascal it makes less sense

At least in that regard the sqlite driver behave differently has it doesn't raise any exception.

Also in TZAbstractConnection:

Code: Select all

function TZAbstractConnection.AbortOperation: Boolean;
begin
 Result := FConnection.AbortOperation = 0;
end; 
which means that it will always return false for sqlite.
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 796
Joined: 18.11.2018, 17:37
Location: Hungary

Re: AbortOperation issue

Post by aehimself »

Was a long time ago but I think I copied the behavior from Ping... which SHOULD mean 0 on success, 1 on error. Later on we introduced EZNotSupportedException, we also could implement that; makes sense if the driver doesn't (yet) support aborting.

I'll take a closer look tomorrow.
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
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 796
Joined: 18.11.2018, 17:37
Location: Hungary

Re: AbortOperation issue

Post by aehimself »

As it turns out yes, return values were not used correctly in every driver. I issued a pull request on GitHub which attempts to fix this.

However, as I analyzed the code Firebird is completely wrong. I put some notes there explaining why it needs to be reworked... Unfortunately I don't have Firebird available to be able to check and test it.
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
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: AbortOperation issue

Post by marsupilami »

I applied the changes to Zeos trunk and Zeos 8.0-patches
stoffman
Senior Boarder
Senior Boarder
Posts: 50
Joined: 03.12.2020, 06:55

Re: AbortOperation issue

Post by stoffman »

I would also like to recommend a change of code in TZDbcPooledConnection.AbortOperation , The way it works now is that if it doesn't have a connection it obtain one only to abort it immediately. This is a waste. It should first check whatever the connection IsClosed and if not try to abort it. if it is close it should return success.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: AbortOperation issue

Post by marsupilami »

aehimself wrote: 04.09.2024, 18:16 However, as I analyzed the code Firebird is completely wrong. I put some notes there explaining why it needs to be reworked... Unfortunately I don't have Firebird available to be able to check and test it.
I use Firebird on a daily basis. What tests should I do? Should we try to integrate tests into the test suite?
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 796
Joined: 18.11.2018, 17:37
Location: Hungary

Re: AbortOperation issue

Post by aehimself »

marsupilami wrote: 11.09.2024, 13:26I use Firebird on a daily basis. What tests should I do?
Jan,

This is the comment I put in .AbortOperation for Firebird:

Code: Select all

    // This is a mess and probably doesn't work as intended. cIStatus_RESULT_OK is 0, which means it doesn't matter what
    // getState returns, anything AND 0 will be 0. Therefore, 0 <> 0 will always return FALSE and Ord(False) is always 0.
    // Result is always 0, so FStatus.init will never be called...
    Result := Ord((Fstatus.getState and cIStatus_RESULT_OK) <> 0);
    if Result <> 0 then
      FStatus.init;
Delphi 12's LSP went nuts at this point so I could not really identify what FStatus is and what methods it has.
What I'd do is to try to call .AbortOperation on Firebird and check what this GetStatus returns. Maybe we can start from there to try to untangle the correct way...
marsupilami wrote: 11.09.2024, 13:26Should we try to integrate tests into the test suite?
Shortly after implementing .AbortOperation I remember writing some SLEEP queries for MSSQL, MySQL and maybe for Oracle so we can check if aborting is actually successful. Those could be turned into tests for the suite.
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
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 796
Joined: 18.11.2018, 17:37
Location: Hungary

Re: AbortOperation issue

Post by aehimself »

stoffman wrote: 11.09.2024, 08:31I would also like to recommend a change of code in TZDbcPooledConnection.AbortOperation , The way it works now is that if it doesn't have a connection it obtain one only to abort it immediately. This is a waste. It should first check whatever the connection IsClosed and if not try to abort it. if it is close it should return success.
Good catch! Ripe pull request is ready for picking!
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
Post Reply