#1 2023-05-26 07:11:00

larand54
Member
Registered: 2018-12-25
Posts: 96

IRestOrm.add don't report duplicate error

I would like to inform the client when trying to add an already existing record.
But the exception from sqlite3 is not forwarded. The call IRestOrm.add just return zero and the exception can only be seen in the server log.

How could I solve this?


Delphi-11, WIN10

Offline

#2 2023-05-26 13:46:07

tbo
Member
Registered: 2015-04-20
Posts: 335

Re: IRestOrm.add don't report duplicate error

larand54 wrote:

How could I solve this?

As described in the documentation:

// - on success, returns the new RowID value; on error, returns 0
// - on success, Value.ID is updated with the new RowID

In service you can write the following:

type
  TOrmArticle = class(TOrm);

function TArticleService.Add(const pmcItem: TOrmArticle): TID;
var
  restServer: TRestServerDB;
begin
  Result := -1;
  if pmcItem <> Nil then
  begin
    restServer := GetDBRestServer;
    if restServer <> Nil then
      Result := restServer.Server.Add(pmcItem, True, False);
  end;
end;

In client then the following:

var
  data: TOrmArticle;
begin
  ...
  data.IDValue := service.Add(data);
  if data.IDValue > 0 then

Or have a look into function AddOrUpdate.

With best regards
Thomas

Offline

#3 2023-05-26 14:11:58

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: IRestOrm.add don't report duplicate error

I think Trestserverdb.StatementLastException can provide you the sql error that you should return to the client

Offline

Board footer

Powered by FluxBB