Any reason why EZSQLConnectionLost is being changed to EZDatabaseError?

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
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 765
Joined: 18.11.2018, 17:37
Location: Hungary

Any reason why EZSQLConnectionLost is being changed to EZDatabaseError?

Post by aehimself »

My users love to leave my application running without doing anything, which will eventually make the active connection to drop. For this I have a simple logic in the code:

Code: Select all

Try
 If Not ZConnection.PingServer Then Reconnect;
Except
 On E:Exception Do
   If E Is EZNotSupportedException Then
     PingTimer.Enabled := False
   Else
   If E Is EZConnectionLost Then
     Reconnect
   Else
     HandleException(E); // Log and show error message
End;
When I left the application to run as a test I was greeted with the following:
EZDatabaseError was raised while pinging server with the message SQL Error: ORA-03113: end-of-file on communication channel

Code: 3113 Message: PingServer

00e88501 MyApplicat.exe ZAbstractConnection 1017 TZAbstractConnection.ConnectionLost
009706ea MyApplicat.exe ZDbcConnection 1193 TZAbstractDbcConnection.ReleaseImmediat
009744bb MyApplicat.exe ZDbcConnection 2234 TZAbstractSingleTxnConnection.ReleaseImmediat
00ce4785 MyApplicat.exe ZDbcOracle 874 TZOracleConnection.ReleaseImmediat
00ce6774 MyApplicat.exe ZDbcOracle 1427 TZOracleConnection.HandleErrorOrWarning
00ce4a88 MyApplicat.exe ZDbcOracle 925 TZOracleConnection.PingServer
00e88e90 MyApplicat.exe ZAbstractConnection 1253 TZAbstractConnection.PingServer
0116b52c MyApplicat.exe uBaseSQLMyApplicatFrame 217 TBaseSQLMyApplicatFrame.PingTimerTimer
007a3ee0 MyApplicat.exe Vcl.ExtCtrls TTimer.Timer
Now, as EZDatabaseError was raised the application still thought the connection is active and did not reconnect, which is not good.
TZOracleConnection.HandleErrorOrWarning already knows and translates 3113 as loss-of-connection, but when we walk the callstack we find this:

Code: Select all

procedure TZAbstractConnection.ConnectionLost(var AError: EZSQLConnectionLost);
var Err: EZSQLConnectionLost;
    EventErrorRaised: Boolean;
    ADatBaseError: EZDataBaseError;
begin
  Err := AError;
  AError := nil;
  try
    CloseAllLinkedComponents;
  except end;
  EventErrorRaised := True;
  try
    if Assigned(FOnLost) then
      FOnLost(Self);
    EventErrorRaised := False;
  finally
    if EventErrorRaised then begin
      if (Err <> nil) then
        FreeAndNil(Err);
    end else begin
      if Err = nil //should not happen
      then ADatBaseError := EZDataBaseError.Create('Connection lost.')
      else begin
        ADatBaseError := EZDataBaseError.CreateFromException(Err);
        FreeAndNil(Err);
      end;
      raise ADatBaseError;
    end;
  end;
end;
Any particular reason for "suppressing" EZConnectionLost and raising an EZDatabaseError instead?
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
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 765
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Any reason why EZSQLConnectionLost is being changed to EZDatabaseError?

Post by aehimself »

@ Michel,

I saw r7534. Does it have to do anything with this topic?
This only raises one question... why are we going to have two connection loss exceptions? Instead of

Code: Select all

If E Is EZConnectionLost Then
the check will have to be

Code: Select all

If (E Is EZConnectionLost) Or (E Is EZDatabaseConnectionLostError) Then
Maybe I'm missing something vital information here, but this seems to be redundant to me.
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
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Re: Any reason why EZSQLConnectionLost is being changed to EZDatabaseError?

Post by EgonHugeist »

The component and dbc layer are not related. That's why the dbc layer raises EZSQLException descendants and the component layer uses EDatabaseError descendants. It's an alltime design i love to keep. Inbetween loads of people are using ZDBC only because of the advertising from the mORMot project or because of the known TDataSet performance bottleneck.

I'm sorry for the inconsistence which did trigger this thread. But you are right there should be an explicit type of an exception users can test against.
Does it answer your question? Do you disagree?

btw. i can't find a EZConnectionLost class.
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 765
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Any reason why EZSQLConnectionLost is being changed to EZDatabaseError?

Post by aehimself »

Yes, absolutely - this is a logical and acceptable explanation; thank you.

And yes, I made a typo, it's EZSQLConnectionLost, defined in ZDbcIntFs : 153

Code: Select all

  /// <summary>Generic connection lost exception.</summary>
  EZSQLConnectionLost = class(EZSQLException);
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
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Any reason why EZSQLConnectionLost is being changed to EZDatabaseError?

Post by marsupilami »

EgonHugeist wrote: 07.05.2021, 04:52 The component and dbc layer are not related. That's why the dbc layer raises EZSQLException descendants and the component layer uses EDatabaseError descendants. It's an alltime design i love to keep. Inbetween loads of people are using ZDBC only because of the advertising from the mORMot project or because of the known TDataSet performance bottleneck.
When did we decide to change back to this behaviou? I thought that the decision was to have all Zeos exceptiopns be derived from EDatabaseError but make this configurable via the Zeos.inc for poeple who dislike this?

Also here the decisions do get inconsistent. When I raised #507 I was told that it isn't necessary to check indices because the DBC layer mostly gets used by the component layer. So - we already do design decisions in the DBC layer because of the component layer. So they are interrelated.

Also I go with aehimselfs first statement. There shouldn't be two exceptions that can be raised in the event of an connection loss. It just doesn't make sense.
EgonHugeist wrote: 07.05.2021, 04:52 The component and dbc layer are not related. That's why the dbc layer raises EZSQLException descendants and the component layer uses EDatabaseError descendants.
I am sorry, but I can't find the thread. This desicion - having the DBC layer throw exceptions tha are not derived from EDatabaseError - most probably had to do with money because in the old times not all editions of Delphi were delivered with the DB unit. But nowadays it just doesn't make sense anymore. Every edition of Delphi is delivered with the DB unit. And anybody who still uses Delphi 7, most probably uses the Enterprise edition.
Post Reply