You are not logged in.
Pages: 1
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
/// 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
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
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
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
Pages: 1