#1 2025-10-10 14:45:53

larand54
Member
Registered: 2018-12-25
Posts: 109

TRestServerFullMemory.SetOrmInstance twice

Try to work with MSSQL but fails using this code:

constructor TTest.create(const aConnection: TStrings);
var
  model: TOrmModel;
  connection: TsqlDBConnectionPropertiesClass;
  serverName, DBName, UserID, Passw: RawUTF8;
  rest: TRestServerFullMemory;
begin
  fModel := TOrmModel.Create([TOrmUsers], '');
  connection := GetODBCDriverSpec;
  serverName := aConnection.Values['Server'];
  DBName := aConnection.Values['Database'];
  UserId := aConnection.Values['User_Name'];
  Passw := aConnection.Values['Password'];
  fProps := connection.Create(serverName, DBName, UserID, Passw);
  VirtualTableExternalRegister(fModel, TOrmUsers, fProps, 'dbo.Users');
  fModel.Props[TOrmUsers].ExternalDB.MapField('ID', 'UserID');
  fModel.Props[TOrmUsers].ExternalDB.MapField('UserEmail', 'Description');
  rest := TRestServerFullMemory.create(fModel);
  fDBServer := TRestOrmServerDB.Create(rest); // <<--- occurs here!
  try
    fDBServer.CreateMissingTables;
  finally
  end;
end;

Delphi-11, WIN10

Offline

#2 2025-10-10 15:23:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,240
Website

Re: TRestServerFullMemory.SetOrmInstance twice

  /// a REST server using only in-memory tables
...
  // - so it will not handle all SQL requests, just basic CRUD commands and
  // most simple SELECT with a single where clause, on a single table

TRestServerFullMemory does not support SQL, so you can't include it in a TRestOrmServerDB instance.

What do you want to achieve?
It is very confusing.

Offline

#3 2025-10-10 15:38:13

larand54
Member
Registered: 2018-12-25
Posts: 109

Re: TRestServerFullMemory.SetOrmInstance twice

I just want a handle that I can use to read and write data from a MSSQL database as I can in the old mormot.
I thought I could use the same code as I used in mormot1 but it doesnt look like that.
I've tried a lot of different ways but this is the closest I got. That's why it looks confusing.
I've tried to find any example about external databases but everything is about sqlite3 and I have no problems with that using sqlitebased mormot.

An example of code where I query the database in the old mssql/mormot-version can look like this:

 
    user := TOrmUsers.Create;
    user.FillPrepare(fDBServer, 'ID=?', [aUserID]);
    if user.FillOne then begin
      clientNo := user.companyNo;
      result := user.fFirstName + ' ' +user.LastName;
    end;

Last edited by larand54 (2025-10-10 15:39:58)


Delphi-11, WIN10

Offline

#4 2025-10-10 16:41:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,240
Website

Re: TRestServerFullMemory.SetOrmInstance twice

Do not mess with TRestOrmServerDB instances.
Those are internal classes.

Just define a TRestServerDB instance, then use the IRestOrmServer interface as published by its Server propery.

Offline

#5 2025-10-10 20:40:18

larand54
Member
Registered: 2018-12-25
Posts: 109

Re: TRestServerFullMemory.SetOrmInstance twice

Super that worked! I easily get confused when there are so many options.

Now I have:

  Server := TRestServerDB.Create(fModel);
  fDBserver := Server.server;

and thats it!

Last edited by larand54 (2025-10-10 20:40:43)


Delphi-11, WIN10

Offline

Board footer

Powered by FluxBB