#1 2025-01-10 11:43:29

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

Cannot see a nullableinteger as null

in my database my records are with RackId field filled with null
my class TAmostra has property RackID: TNullableInteger read FRackID write FRackID; 

var
  vListaAmostras: IDocList;
  vAmostra: IDocObject;
  vTempAmostra: TAmostra;
begin
  vTempAmostra := TAmostra.Create;
  try
    vListaAmostras := DocListFrom(FRestOrm.Orm.RetrieveDocVariantArray(TAmostra, '', '(SolicitacaoID=?)', [pSolicitacaoExistenteId], '*'));
    for vAmostra in vListaAmostras do
    begin
      vTempAmostra.FillFrom(Variant(vAmostra.Value^));
      if (Pos(vTempAmostra.Numero, pAmostras) <> 0)
        or not NullableIntegerIsEmptyOrNull(vTempAmostra.RackID) then
        Continue;
    ...

NullableIntegerIsEmptyOrNull(vTempAmostra.RackID) return false when shoul be return true.

debugging i see that vListaAmostras[0] return
'{"ID":26,"datacriacao":"2025-01-07T11:32:17","ultimaalteracao":"2025-01-07T11:42:47","empresaid":1,"numero":"0101","solicitacaoid":12,"exames":"PC, FOS","dataetiqueta":"2022-09-03T10:12:34","rackid":0,"linha":0,"coluna":0,"coletado":false,"cancelada":true,"postoatualid":1}'

should be "rackid": null????? because in database is null

Offline

#2 2025-01-10 15:54:33

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

Re: Cannot see a nullableinteger as null

What is returned by the database itself before converting to the TDocVariantData?

Online

#3 2025-01-17 13:23:59

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

Re: Cannot see a nullableinteger as null

TSqlDBStatement.FetchAllToJson return "rackid":null

'{"id":32,"datacriacao":"2025-01-13T09:58:46","ultimaalteracao":"2025-01-13T09:58:46","empresaid":1,"numero":"0101","solicitacaoid":12,"exames":"PC, FOS","dataetiqueta":"2022-09-03T10:12:34","rackid":null,"linha":0,"coluna":0,"coletado":0,"cancelada":0,"postoatualid":1}'

function TRestOrm.RetrieveDocVariantArray(Table: TOrmClass;
  const ObjectName: RawUtf8; const FormatSqlWhere: RawUtf8;
  const BoundsSqlWhere: array of const; const FieldsCsv: RawUtf8;
  FirstRecordID, LastRecordID: PID): variant;
...
    T := MultiFieldValues(Table, FieldsCsv, FormatSqlWhere, BoundsSqlWhere);
    if T <> nil then
    try
      T.ToDocVariant(v, {readonly=}false); <<<<<<<<<<<< this part change "rackid":null of database to "rackid":0 (ZERO)

      v = > '[{"ID":32,...,"rackid":0,...},...}]'

      if FirstRecordID <> nil then
        FirstRecordID^ := T.GetID(1);
...

Last edited by mrbar2000 (2025-01-17 13:32:44)

Offline

#4 2025-01-17 18:38:25

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

Re: Cannot see a nullableinteger as null

Should be better with
https://github.com/synopse/mORMot2/commit/4028967a5

Note that I made a huge code refactoring of the ORM core about those null values.
Some other commits to consider.

Online

Board footer

Powered by FluxBB