#1 2014-09-22 11:49:12

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

cache related

Hi AB

function TSQLRest.Add(Value: TSQLRecord; SendData: boolean;
  ForceID: boolean=false): integer;
var JSONValues: RawUTF8;
    TableIndex: integer;
begin
  if Value=nil then begin
    result := 0;
    exit;
  end;
  TableIndex := Model.GetTableIndexExisting(PSQLRecordClass(Value)^);
  if SendData then begin
    Value.ComputeFieldsBeforeWrite(self,seAdd); // update TModTime/TCreateTime fields
    if Model.TableProps[TableIndex].Kind in INSERT_WITH_ID then
      ForceID := true;
    JSONValues := Value.GetJSONValues(true, // true=expanded
      (Value.fID<>0) and ForceID,soInsert);
  end else
    JSONValues := '';
  // on success, returns the new ROWID value; ************************ on error, returns 0 **************************
  result := EngineAdd(TableIndex,JSONValues); // will call static
  // on success, Value.ID is updated with the new ROWID

  Value.fID := result; 
  if SendData then ********************* result not checked maybe better: if SendData and (result<>0) then ?
    fCache.Notify(PSQLRecordClass(Value)^,result,JSONValues,soInsert);
end;

Not a bug, but

EngineAdd on error, returns 0
but not checked

Offline

#2 2014-09-23 09:21:30

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

Re: cache related

Yes, this is by design.
It is to the client to check that ID is not 0.

You are right: it should be checked for the cache update.
Should be fixed by http://synopse.info/fossil/info/143a5a8209

Thanks for the feedback

Offline

Board footer

Powered by FluxBB