2
votes

I just switched from using the BDE to ADO by replacing the Tables and Queries to its equivalent in ADO components.

I'm always execute the query inside try...catch like this:

//Fdm is Data Module
//TEndOfDay is TTable
//QEndOfDay is TQuery

Screen->Cursor = crSQLWait;
Fdm->QEndOfDay->SQL->Add("SELECT * FROM TEndOfDay");
try{
  Fdm->QEndOfDay->ExecSQL();
  Fdm->QEndOfDay->Open();
  Screen->Cursor = crDefault;
}
catch (EDBEngineError &DBEngineError){
  strError = DBEngineError.Message;
  Screen->Cursor = crDefault;
}
catch (EDatabaseError &DatabaseError){
  strError = DatabaseError.Message;
  Screen->Cursor = crDefault;
}
catch(...){
  strError = "Error";
  Screen->Cursor = crDefault;
}          

Since I switched to ADO, does those exceptions (DBEngineError, DatabaseError) are applicable?

I have been edited my post to include Delphi folks, they are responds quickly. No matter if the answer in Delphi code.

1

1 Answers

3
votes

You should first check for EADOError, which are specific ADO-related exceptions, and then EDatabaseError, which are more general database exceptions. EDBEngineError is an old BDE exception class, and is not applicable any longer if you're not using the BDE.

Screen.Cursor := crSQLWait;
Fdm.QEndOfDay.SQL.Text := 'SELECT * FROM TEndOfDay';
try
  try
    Fdm.QEndOfDay.Open;
  except
    on E: EAdoError do
    begin
      // ADO specific error handling
    end;
    on E: EDatabaseError do
    begin
      // Generic database error handling
    end;
    on E: Exception do
    begin
      // Other exceptions (non-DB related)
    end;
  end;
finally
  // Revert cursor to default always.
  Screen.Cursor := crDefault;
end;