#1 2023-03-30 16:16:28

mrbar2000
Member
From: Brazil
Registered: 2016-10-26
Posts: 56

How treat error in SQL Statement

I see that all code framework, if the statement is wrong the exception do not explode to user.

In the framework I see this piece of code in several parts:

      try
        ...
        GetAndPrepareStatementRelease(...);
        ...
      except
        on E: Exception do
          GetAndPrepareStatementRelease(E);
      end;

So if I assemble an invalid sql statement by mistake when doing the orm.RetrieveDocVariant does not generate an exception bringing up the null record. example:

function TProjetoService.Busca(pId: Int64): TServiceCustomAnswer;
var
  vProjeto, vPaineis: Variant;
begin
  TDocVariant.New(vProjeto);
  vProjeto := GlobalRepository.Orm.RetrieveDocVariant(TProjeto, '(ID=?)', [pId], '');
  if VarIsEmptyOrNull(vProjeto) then
    Result := ReturnRecordNotFound
  else
  begin
    vPaineis := GlobalRepository.Orm.RetrieveDocVariantArray(TPainel, '',
      '(IdProjeto=?)',
      [pId],
      'ID , Nome2');   <<<<<<<< Nome2 not exists, just Nome field  (in runtime this do not generate exception)
    vProjeto.Paineis := vPaineis;   <<<<< this part run normally bring um Json "Paineis" : null
    Result := ReturnOk(vProjeto);
  end;
end;

Offline

#2 2023-03-31 06:50:31

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: How treat error in SQL Statement

This is as expected.

You can access the exception error test from TRestOrmServerDB.StatementLastException proeprty.

Offline

#3 2023-03-31 12:14:00

Chaa
Member
Registered: 2011-03-26
Posts: 245

Re: How treat error in SQL Statement

Also, in TRestStorageExternal methods like EngineList or EngineRetrieve and so on, exceptions are supressed in try..except block, without being stored anywhere.

Offline

#4 2023-03-31 14:52:59

mrbar2000
Member
From: Brazil
Registered: 2016-10-26
Posts: 56

Re: How treat error in SQL Statement

Chaa wrote:

Also, in TRestStorageExternal methods like EngineList or EngineRetrieve and so on, exceptions are supressed in try..except block, without being stored anywhere.

do not store in StatementLastException ????????
This is a problem no?

Offline

Board footer

Powered by FluxBB