You are not logged in.
Hi,
I would like to understand how to deal with the following type of scenario using mormot:
Offline client can create new records. Also, server can create new records.
At some point client and server will be synced.
Ordinarily, one would use a GUID as ID field for each record. (i.e. client and server need to be creating globally unique ids)
Also, when sending a record from client to server, one includes the ID in the record (i.e. not created at server.)
TSQLRecord.ID is int64, which is pretty large, so perhaps this could be used an an equivalent to GUID. (i.e a GUID is 16 bytes but only uses a restricted range for each byte (0-F). int64 is 8 bytes but could use a larger range..). However, more of a "problem" is that TSQLRecord.ID is read only, so one cannot achieve above requirement (of sending Record.ID to server).
So is the way to deal with such a situation to basically ignore the TSQLRecord.ID, and supply our own GUID field?
Thank you
Rael
Offline
For mORMot's built-in support for your case, check TSQLModel.SetIDGenerator and SynCommons.TSynUniqueIdentifierGenerator.
or check https://github.com/suiyunonghen/DelphiSnowflake.
or check my little function if your data volume is low: https://synopse.info/forum/viewtopic.php?id=2522
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Thanks for the info, that is interesting.
However, it does not answer the second issue: How do I supply a rec.ID to the server when syncing records from the client, since rec.ID is readonly?
Offline
Use rec.IDValue instead of rec.ID
Esteban
Offline
Hi,
That does not seem to work. I tried the following (using Project 02 with new database)
procedure TForm1.AddButtonClick(Sender: TObject);
var
Rec: TSQLSampleRecord;
begin
Rec := TSQLSampleRecord.Create;
try
// we use explicit StringToUTF8() for conversion below
// a real application should use TLanguageFile.StringToUTF8() in mORMoti18n
Rec.Name := StringToUTF8(NameEdit.Text);
Rec.Question := StringToUTF8(QuestionMemo.Text);
Rec.IDValue := 30; // <----
if Database.Add(Rec, true) = 0 then
ShowMessage('Error adding the data')
else
begin
NameEdit.Text := '';
QuestionMemo.Text := '';
NameEdit.SetFocus;
lblID.Caption := 'ID: ' + IntToStr(Rec.ID);
end;
finally
Rec.Free;
end;
end;
The added Rec.ID is 1, not 30 as I had set it.
Offline