#1 2012-10-11 10:49:11

corchi72
Member
Registered: 2010-12-10
Posts: 232

"missing class in Model" (TSQLAuthUser)

with the latest versions occurs the error "missing class in Model" when I try to add a user in the table TSQLAuthUser. If, however, point to the name of the two tables in my Model works.
But I have seen this piece of code in the file SQLite3Commons and in theory it should not be necessary to inform it if I put the parameter "HandleAuthentication = True".
I ask this because I use the same model to create a local connection (without authentication) and if I point out the tables and TSQLAuthUser TSQLAuthGroup the program I change the parameter "HandleAuthentication from False to True" with all the consequences.

constructor TSQLRestServer.Create(aModel: TSQLModel; aHandleUserAuthentication: boolean);
var i,n: integer;
    C: PtrInt;
    M: PMethodInfo;
//    RI: PReturnInfo; // such RTTI info not available at least in Delphi 7
begin
  // specific server initialization
  fVirtualTableDirect := true; // faster direct Static call by default
  fAuthUserIndex := aModel.GetTableIndex(TSQLAuthUser);
  fAuthGroupIndex := aModel.GetTableIndex(TSQLAuthGroup);
  fHandleAuthentication := (fAuthUserIndex>=0) and (fAuthGroupIndex>=0);
  if aHandleUserAuthentication and (not fHandleAuthentication) then begin
    // we need both AuthUser+AuthGroup tables for authentication -> create now
    if fAuthUserIndex<0 then
      aModel.AddTable(TSQLAuthUser,@fAuthUserIndex);
    if fAuthGroupIndex<0 then
      aModel.AddTable(TSQLAuthGroup,@fAuthGroupIndex);
    fHandleAuthentication := true;
  end;
...

thanks corchi

Offline

#2 2012-10-11 11:48:30

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

Re: "missing class in Model" (TSQLAuthUser)

The model should not be shared, but each TSQLRestServer instance should have its own TSQLModel instance.

This is not the only modification made to the TSQLModel of the server (e.g. if tables are external DB tables and other features implemented by TSQLModelRecordProperties in current trunk version), so it is mandatory not to share the model.

You can use constructor TSQLModel.Create(CloneFrom: TSQLModel) to make a safe copy of an existing model, or - even better IMHO - create a shared function returning a generic TSQLModel instance.

Offline

#3 2012-10-11 12:22:49

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: "missing class in Model" (TSQLAuthUser)

I'm sorry but I did not understand I always declare or not? because before in older versions did not serve its reporting the two tables "TSQLAuthUser, TSQLAuthGroup" in the model, because they were created and added to the model if you indicated the parameter "aHandleUserAuthentication" (as shown in the code above), but now in addition to indicating the parameter "aHandleUserAuthentication "is required to manually add the two tables" TSQLAuthUser, TSQLAuthGroup "otherwise the error occurs in the subject. you is?

  FileTabs: array[0..10] of TFileRibbonTabParameters = (
    (
//    (Table: TSQLAuthUser;              Select: REL_SELECT; Group: GROUP_MAIN; FieldWidth: 'IddId'; Actions: DEF_ACTIONS),
//    (Table: TSQLAuthGroup;             Select: REL_SELECT; Group: GROUP_MAIN; FieldWidth: 'IddId'; Actions: DEF_ACTIONS),
    (Table: TSQLOption;                Select: REL_SELECT; Group: GROUP_MAIN; FieldWidth: 'IddId'; Actions: DEF_ACTIONS),
    (Table: TSQLConnection;            Select: REL_SELECT; Group: GROUP_MAIN; FieldWidth: 'IddId'; Actions: DEF_ACTIONS),
  ....
)

Offline

#4 2012-10-11 15:22:18

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

Re: "missing class in Model" (TSQLAuthUser)

You need the two TSQLAuthUser and TSQLAuthGroup only if authentication is required.
No need to add those to the UI.

Just do not re-use a TSQLModel instance, but use a dedicated one per server.

Offline

#5 2012-10-12 11:02:09

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: "missing class in Model" (TSQLAuthUser)

the error is in the fact that is assigned the value of a variable regardless of the parameter "aHandleUserAuthentication "

fHandleAuthentication := (fAuthUserIndex>=0) and (fAuthGroupIndex>=0);

I would write:

  if aHandleUserAuthentication and (not (fAuthUserIndex>=0) and (fAuthGroupIndex>=0)) then begin
    // we need both AuthUser+AuthGroup tables for authentication -> create now
    if fAuthUserIndex<0 then
      aModel.AddTable(TSQLAuthUser,@fAuthUserIndex);
    if fAuthGroupIndex<0 then
      aModel.AddTable(TSQLAuthGroup,@fAuthGroupIndex);
    fHandleAuthentication := true;
  end;

Offline

#6 2012-10-12 14:16:48

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

Re: "missing class in Model" (TSQLAuthUser)

You are right: there was an  issue in TSQLRestServer.Create() about authentication enabling.

The fix included in  http://synopse.info/fossil/info/073074697e is a bit diverse than yours, which will fail if the tables already exists.

Offline

#7 2012-10-17 07:40:59

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: "missing class in Model" (TSQLAuthUser)

ok thanks!

Offline

Board footer

Powered by FluxBB