#1 2023-08-07 14:26:01

srclark71
Member
Registered: 2023-07-13
Posts: 5

TRestStorageExternal question

I have been looking into updating our existing application to mORMot 2 and have a question about turning off the auto ID on a certain table.

I created a test application which is connecting to my SQL server fine using a TSQLRestServerDB.  My question is about accessing the TRestStorageExternal.Instance.

I came up with this and it doesn't throw any errors but am wondering if this is the correct way of coding this.  In my existing application I would just pass in the TSQLRestServerDB, but now it is needing a TRestOrmServer.

  MyServer := TSQLRestServerDB.Create(Model,':memory:');

  MyServer.CreateMissingTables;
  MyServer.AcquireExecutionMode[execORMGet] := amBackgroundORMSharedThread;
  MyServer.AcquireExecutionMode[execORMWrite] := amBackgroundORMSharedThread;
  MyServer.DB.UseCache := false;

  VStorage := TRestStorageExternal.Instance(TSQLUser, TRestOrmServer(MyServer.Server));

  if Assigned(VStorage) then
  begin
    VStorage.EngineAddForcedID := -1;
  end;

Thanks for any help

Offline

#2 2023-08-07 15:41:04

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

Re: TRestStorageExternal question

Instead of hard-coding the typecast, via  TRestOrmServer(MyServer.Server), it is always safer to make an explicit cast like " (MyServer.Server as TRestOrmServer) ".
If there is a class type mismatch an explicit error will be raised at runtime. And since you do it once at startup, there is no performance penalty.
Better safe than sorry. wink

About your exact question, between mORMot 1 and mORMot 2, the EngineAddForcedID property behavior did not change.
Only its location did change. smile

Offline

#3 2023-08-07 15:43:41

srclark71
Member
Registered: 2023-07-13
Posts: 5

Re: TRestStorageExternal question

Thanks, this resolves my worries and I can move on with my updating.

Offline

Board footer

Powered by FluxBB