#1 2015-12-22 20:22:15

juvencioleite
Member
Registered: 2015-12-22
Posts: 2

AddOrUpdate returning inconsistent value error

Hello, Use the version of FPC 3.1.1 trunk on Linux CentOS 32-bit. And there was the following situation:
I had to use the AddOrUpdate function (mORMot.pas - line 31850) and that the Result default or on exceptions, would need to be 0 or -1 for negative, the value I received was a 12-digit value in the variable type TID. I identified that the Result is not initialized. It was for some reason in specific? If I do not let my contribution. Thank you all.
Ticket UUID:    e0c280430a494aea07dc4cd7727f37adfe0e61a6

Offline

#2 2015-12-23 07:49:28

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

Re: AddOrUpdate returning inconsistent value error

Could you be more specific?
Do you have some code to reproduce?

Result is always set, as shown by the code:

function TSQLRest.AddOrUpdate(Value: TSQLRecord): TID;
begin
  if (self=nil) or (Value=nil) then
    result := 0 else
  if Value.fID=0 then
    result := Add(Value,true) else
    if Update(Value) then
      result := Value.fID else
      result := 0;
end;

Please do not create a ticket before an issue is clearly identified.

Offline

#3 2015-12-23 13:40:12

juvencioleite
Member
Registered: 2015-12-22
Posts: 2

Re: AddOrUpdate returning inconsistent value error

The test I did was send a SQL update to a record that does not exist (it was intentional) and as well as in Delphi, I expected that the result of error was 0, but the value I got was a full 12 digits as a value pattern.
In Delphi returns the result 0 because the Delphi IDE already sets the standard zero for this situation, but the Lazarus do not. What would solve parameterizing the result to zero.

//now
function TSQLRest.AddOrUpdate(Value: TSQLRecord): TID;
begin
  if (self=nil) or (Value=nil) then
    result := 0 else
  if Value.fID=0 then
    result := Add(Value,true) else
    if Update(Value) then
      result := Value.fID else
      result := 0;
end;
//After
function TSQLRest.AddOrUpdate(Value: TSQLRecord): TID;
begin
  Result := 0; //for compatibility with Lazarus
  if (self=nil) or (Value=nil) then
    result := 0 else
  if Value.fID=0 then
    result := Add(Value,true) else
    if Update(Value) then //here and where the error occurs
      result := Value.fID else
      result := 0;
end;

Offline

#4 2015-12-23 17:54:16

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

Re: AddOrUpdate returning inconsistent value error

It does not make any sense at AddOrUpdate level.
In the code, result is ALWAYS set to a value.

If you send a SQL update to a record that does not exist, Update should return false then set result to 0.

Offline

Board footer

Powered by FluxBB