#1 2019-04-22 12:04:58

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

Authorization tables not created with "CreateMissingTables

Setting up the server with authorization doesn't work as expected.
I expected the two tables would be created automatically when I set the parameter of "TSQLRestServerDB.Create" to true.
The table "Ticket" is created

constructor TTicketServer.create;
begin
  TDDDRepositoryRestFactory.ComputeSQLRecord([TTicket]);
  DBConnect(rseZeosMySQL, 'zdbc:mysql://localhost:3306', 'test_mormot', 'root', '');
  Model := CreateTicketModel;
  VirtualTableExternalRegister(Model, [TTicket], Props);
  DBServer := TSQLRestServerDB.Create(Model, true);  // Require authorization
  try
    DBServer.CreateMissingTables(0);
    DBServer.ServiceContainer.InjectResolver([TInfraRepoTicketFactory.create(DBServer)], true);
    DBServer.ServiceDefine(TInfraRepoTicket, [IDomTicketCommand], sicClientDriven);
    httpServer := TSQLHttpServer.Create(PORT_NAME, [DBServer], '+', HTTP_DEFAULT_MODE);

function createTicketModel: TSQLModel;
begin
  result := TSQLModel.Create([TTicket],'root');
end;

procedure TTicketServer.DBConnect(aEngine: TRemoteSQLEngine; const aServerName,
  aDatabaseName, aUserID, aPassWord: RawUTF8);
const
  TYPES: array[TRemoteSQLEngine] of TSQLDBConnectionPropertiesClass = (TSQLDBZEOSConnectionProperties,TOleDBConnectionProperties, TODBCConnectionProperties, TSQLDBOracleConnectionProperties, TSQLDBSQLite3ConnectionProperties, nil, TOleDBMSSQL2008ConnectionProperties);
begin
  if Props <> nil then
    raise Exception.Create('Connect called more than once');
  if TYPES[aEngine] = nil then
    raise Exception.CreateFmt('aEngine=%s is not supported', [GetEnumName(TypeInfo(TRemoteSQLEngine), ord(aEngine))^]);
  Props := TYPES[aEngine].Create(aServerName, aDatabaseName, aUserID, aPassWord);
end;

What am I missing?

Last edited by larand54 (2019-04-22 14:41:29)


Delphi-11, WIN10

Offline

#2 2019-04-22 15:14:54

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

Re: Authorization tables not created with "CreateMissingTables

Include TSQLAuthUser and TSQLAuthGroup in your database model, something like:

TSQLModel.Create([TTicket, TSQLAuthUser, TSQLAuthGroup],'root');


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

Offline

#3 2019-04-22 18:28:50

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

Re: Authorization tables not created with "CreateMissingTables

I have already tested that and I did it again but only the ticket.table is created.

I'm using fpc, zeos and lazarus and I have had a lot of problems making it work can it be something with this configuration? I've tested with delphi in another project and that was easier but then I also used MSSQL.

Last edited by larand54 (2019-04-22 21:04:57)


Delphi-11, WIN10

Offline

#4 2019-04-23 08:11:00

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

Re: Authorization tables not created with "CreateMissingTables

I actually declaring a classes inheriting from TSQLAuthUser/Group and add it to the model, but what you did should also work.

I'm using Delphi only, with sqlite db. maybe you can debug into the CreateMissingTables method.


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

Offline

#5 2019-04-23 10:16:47

ianxevcd
Member
Registered: 2016-07-04
Posts: 11

Re: Authorization tables not created with "CreateMissingTables

As I understand your call CreateMissingTables(0) means database schema is not modified. Try to use just DBServer.CreateMissingTables;


Alexander

Offline

#6 2019-04-23 14:02:43

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

Re: Authorization tables not created with "CreateMissingTables

ianxevcd, I tried that before and I tried again - it didn't change anything. The parameter I used is, as what I understand, just a version number. Don't know where it is used but as my ticket table is created with or without this parameter, I can't see that it have something with db modification to do. But what do I know?

I will try to debug that function a bit more later on if no other solution comes up.


Delphi-11, WIN10

Offline

#7 2019-04-25 07:36:32

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

Re: Authorization tables not created with "CreateMissingTables

I found the missing part myself. I had to put all tables in the "VirtualTableExternalRegister" procedure.
I was fooled by the fact that you didn't need to put these tables (TSQLAuthUser, TSQLAuthGroup) into the model as do that automatically in the background, so I never thought about putting these tables into the VirtualTableExternalRegister procedure.

  VirtualTableExternalRegister(Model, [TTicket, TSQLAuthUser, TSQLAuthGroup], Props);

Delphi-11, WIN10

Offline

#8 2019-04-25 10:08:08

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

Re: Authorization tables not created with "CreateMissingTables

The safer option is to use VirtualTableExternalRegisterAll() in such cases.

Offline

Board footer

Powered by FluxBB