#1 2015-09-01 13:27:14

hnb
Member
Registered: 2015-06-15
Posts: 291

OnEngineLockedNextID and EngineIgnoreID patch

Patch contains:

-OnEngineLockedNextID callback event (for example SQL select with some sequence function, or some other stuff depending on the DB back-end)
-EngineIgnoreID for speed up "insert into" for external databases (safer method in many cases than default "select max(id)") Without EngineIgnoreID, I have a lot of errors (duplicated id) in my n-tier system with many non-mormot-clients.

Fell free to modify TOnEngineLockedNextID event parameters (this is only proposition).

Example:

type
  TCustomVirtualTableExternal = class(TSQLVirtualTableExternal)
  public
    constructor Create(aModule: TSQLVirtualTableModule; const aTableName: RawUTF8;
      FieldCount: integer; Fields: PPUTF8CharArray); override;
  end;

var
  aRestServer: TSQLMyServer;

constructor TCustomVirtualTableExternal.Create(aModule: TSQLVirtualTableModule;
  const aTableName: RawUTF8; FieldCount: integer; Fields: PPUTF8CharArray);
begin
  inherited;

  if fStatic.InheritsFrom(TSQLRestStorageExternal) then
  begin
    // ID generated for example by trigger
    //TSQLRestStorageExternal(fStatic).OnEngineLockedNextID := aRestServer.OnEngineLockedNextID;
    // or auto generated ID by DB (for speed up batch and normal record add)
    TSQLRestStorageExternal(fStatic).EngineIgnoreID := true;
  end;
end;


{...}

begin

{...}

VirtualTableExternalRegisterAll(aModel, aProps, TCustomVirtualTableExternal);

{...}

end.

Patch available at:
https://drive.google.com/file/d/0B4PZhd … sp=sharing

This is patch for:
http://synopse.info/fossil/tktview/2013 … 22418760d5

best regards,
Maciej Izak

Last edited by hnb (2015-09-02 07:05:38)


best regards,
Maciej Izak

Offline

#2 2015-09-02 15:07:46

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

Re: OnEngineLockedNextID and EngineIgnoreID patch

I've committed http://synopse.info/fossil/info/334a9933e8

The properties have a diverse names, but implement the same idea.

I did not include the TSQLVirtualTableExternal sub-classing part of the patch.
IMHO this is not how you should do it.
Just use TSQLRestStorageExternal.Instance() method to retrieve directly the TSQLRestStorageExternal instance, and set the properties as expected, after VirtualTableExternalRegister*() call.

Offline

#3 2015-09-04 03:58:47

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: OnEngineLockedNextID and EngineIgnoreID patch

I Arnaud,

I haven't been updated my mORMot source for a while, I see the newly added OnEngineAddComputeID event for TSQLRestStorageExternal - looks like it's for **external** DB only. Is there already a similar event for customizing the record ID value for new records on the server side?


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#4 2015-09-04 06:00:03

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

Re: OnEngineLockedNextID and EngineIgnoreID patch

It is not needed IMHO.

Just set the ID field before adding with your expected value.

Offline

#5 2015-09-07 06:30:15

hnb
Member
Registered: 2015-06-15
Posts: 291

Re: OnEngineLockedNextID and EngineIgnoreID patch

ab wrote:

I've committed http://synopse.info/fossil/info/334a9933e8

The properties have a diverse names, but implement the same idea.

Thanks for that! "select max" was very buggy solution for many clients. You are right about TSQLVirtualTableExternal smile thanks!


best regards,
Maciej Izak

Offline

#6 2015-09-07 06:37:02

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

Re: OnEngineLockedNextID and EngineIgnoreID patch

Yes, but "select max" was a fast and safe solution if the mORMot server is the single one accessing the DB.

Offline

Board footer

Powered by FluxBB