#1 2022-03-21 13:21:48

manoirx
Member
Registered: 2022-03-21
Posts: 2

Bug in TSQLRecordMany.ManyAdd

function TSQLRecordMany.ManyAdd(aClient: TSQLRest; aSourceID, aDestID: TID;
  NoDuplicates: boolean; aUseBatch: TSQLRestBatch): boolean;

begin
  result := false;
  if (self=nil) or (aClient=nil) or (aSourceID=0) or (aDestID=0) or
     (fSourceID=nil) or (fDestID=nil) then
    exit; // invalid parameters
  if NoDuplicates and
     (InternalIDFromSourceDest(aClient,aSourceID,aDestID)<>0) then
      exit; // this TRecordReference pair already exists
  fSourceID^ := aSourceID; <--- assigned int64 to integer
  fDestID^ := aDestID; <--- assigned int64 to integer
  if aUseBatch<>nil then
    result := aUseBatch.Add(self,true)>=0 else
    result := aClient.Add(self,true)<>0;
end;





TSQLRecordMany = class(TSQLRecord)
  protected
   
    fSourceID: PPtrInt;  <-- integer
    fDestID: PPtrInt; <-- integer


model class that use IDGenerator -> ID generate int64 number value > 2147516417 will rounded to 2147516417

for example
model.SetIDGenerator(Txxxx,1);

the ID will rounded from 3538742966002679809 to 2147516417 for data that stored in DB from class inherited from TSQLRecordMany  (Tested with MongoDB)

Offline

#2 2022-03-21 13:29:17

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

Re: Bug in TSQLRecordMany.ManyAdd

This is not a bug.
This is a limitation due to the pointer size on 32-bit systems.
The source and dest fields are of type TSQLRecord, i.e. pointers, so are limited to 32-bit on 32-bit systems.

64-bit IDs were never supported for TSQLRecordMany on 32-bit systems, because they can't.
If you want to use huge ids, don't use TSQLRecordMany but regular TSQLRecord, with TID explicit fields (which are 64-bit), and make the SQL join by hand. Or even better, don't make joins, but define your ORM class as an aggregate (see the doc) with all needed fields in the single class.

Offline

#3 2022-03-21 13:32:49

manoirx
Member
Registered: 2022-03-21
Posts: 2

Re: Bug in TSQLRecordMany.ManyAdd

Thank you for clarifying

Offline

Board footer

Powered by FluxBB