#1 2013-01-02 16:44:43

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Having trouble with TSQLAuthUser TSQLAuthGroup and creating a TSQLRest

I am creating a restclientdb instance like this:

procedure TMormotDBBaseCommonTest.SetUp;
VAR lModel:TSQLModel;
begin
  inherited;
  InitDBProps(FProps);
  FConn := Props.NewConnection;
  FQuery := Conn.NewStatement;

  lModel := TSQLModel.Create([]);
  PrepModel(lModel);
  VirtualTableExternalRegisterAll(lModel, Props);
  FClient := TSQLRestClientDB.Create(lModel, nil, cSQLiteDBInMemory, TSQLRestServerDB,True); // FAILS HERE with COde 21 "Not an Error
  Client.Model.Owner := Client;
  Client.Server.CreateMissingTables;
  Check(Client.SetUser('Admin', 'synopse'),'Unable to set Admin user'); // Need full acccess rights to add users

  // just to ensure the table is empty prior to our tests
  Client.DB.Execute('DELETE FROM '+lModel.Tables[0].SQLTableName+';');
  Client.DB.Execute('SELECT COUNT (*) FROM '+lModel.Tables[0].SQLTableName+';');
end;

When I add TSQLAuthUser and TSQLAuthGroup to the model (in the PrepModel call), then the line creating thre FCLient failes, with a fine error message 'Not an error' (described in earlier topic how I got there)
On the other hand, If I leave them out, my FCLient gets initialized allright, but unit test code fails because I cannot add any users to my table for some reason. Check code below:

procedure TMormotDBaseAuthTest.SetUp;
var
  lUser: TSQLAuthUser;
  lGroupID: PtrInt;
begin
  inherited Setup;
  Check(Client.Server.DB.ExecuteNoException('DELETE FROM AuthUser WHERE LogonName<>''Admin'';'),'Clear AuthUser table failed'); // drop all records except Admin
  // Add a readonly user and a normal user
  lUser := TSQLAuthUser.Create;
  try
    lUser.LogonName := cGuestUser;
    lUser.PasswordPlain := cGuestPw;
    lGroupID := Client.MainFieldID(TSQLAuthGroup, 'Guest');
    lUser.GroupRights := TSQLAuthGroup(lGroupID);
    Client.Add(lUser, true); // FAILS HERE "Class Missing in Model"

    lUser.LogonName := cNormalUser;
    lUser.PasswordPlain := cGuestPw;
    lGroupID := Client.MainFieldID(TSQLAuthGroup, 'User');
    lUser.GroupRights := TSQLAuthGroup(lGroupID);
    Client.Add(lUser, true);
  finally
    lUser.Free;
  end;

end;

(TMormotDBaseAuthTest is derived from TMormotDBBaseCommonTest)

DId I get the order of inititialization wrong? Hints? Tips?

Regards - Hans

Offline

#2 2013-01-02 16:48:32

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Having trouble with TSQLAuthUser TSQLAuthGroup and creating a TSQLRest

mmmh when providing the model as server model, everything appears to work as expected. WHy are there actually 2 parameters for server and client model? SHould onbe default to the other maybe?

Regards - Hans

Offline

#3 2013-01-02 19:14:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,269
Website

Re: Having trouble with TSQLAuthUser TSQLAuthGroup and creating a TSQLRest

One is copied to the other at constructor level.

Each layer has its own model, so you should better create the model once, including both TSQLAuth* tables, and it will be cloned to both "sides".
Even if you use it stand-alone, in fact both layers are handled separately, with one model on each side.

By the way, executing such SQL statements directly in the database will by pass the whole ORM layer, and could make the cache inconsistent.

Offline

#4 2013-01-03 07:21:11

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Having trouble with TSQLAuthUser TSQLAuthGroup and creating a TSQLRest

ab wrote:

One is copied to the other at constructor level.

Each layer has its own model, so you should better create the model once, including both TSQLAuth* tables, and it will be cloned to both "sides".

I see.

ab wrote:

By the way, executing such SQL statements directly in the database will by pass the whole ORM layer, and could make the cache inconsistent.

Yes we know, here it is intentionally in order to have a Test fixture. (meaning circumstances are the same each time the test is executed). Production code will presumably not look like this.

Thx.

Offline

Board footer

Powered by FluxBB