When a user (client) connects to the server, the client ID or customer ID is stored within the session.
When a user wants to access the table of articles (e.g.), only records belonging to this user should be ‘transferred’ to the client. So, I need to filter the articles-table serverside.
How can I achieve this?
Tried to do this in the OnWriteDataSet event of the DataStreamer, but no luck so far…
Many thanks!
Schema Modeler knows nothing about SESSION_XXX macro because such macros are provided by DataService based on your session:
function TBaseDataAbstractService.DoOnUnknownIdentifier(Sender: TObject;
const Name, OrgName: string; var Value: string): Boolean;
..
// Is this a session value request?
if Length(OrgName) > 8 then begin
s := Copy(OrgName, 1, 8);
if AnsiSameText(s, 'SESSION_') then begin
lSessionValueName := Copy(OrgName, 9, Length(OrgName) - 8);
lSessionValue := Self.Session[lSessionValueName];
Result := not (VarIsNull(lSessionValue) or VarIsEmpty(lSessionValue));
if Result then Value := VarToStr(lSessionValue);
Exit;
end;
end;
..
You also can provide SESSION_CUSTOMERNAME macro via DynamicWhere expression.
I managed to figure it out…
When a connection is assigned in the OnCreate of the DA Service, the fConnection is evaluated as assigned, so Exit is called and MacroProcessorEvent will not be called.
In my service this was declared as
procedure TArticleService.DataAbstractServiceCreate(Sender: TObject);
begin
schArticle.ConnectionManager := dmServer.cmConnections; // ConnectionManager
Connection := dmServer.GetDefaultConnection; // method to get the right connection
end;
you can assign event manually in DataAbstractServiceCreate like we do:
// lmacro: IDAHasMacroProcessor;
if Connection.UseMacroProcessor then
if Supports(Connection, IDAHasMacroProcessor, lmacro) then begin
if Assigned(lmacro.GetMacroProcessor) and not Assigned(lmacro.GetMacroProcessor.OnDAServiceUnknownIdentifier) then begin
lmacro.GetMacroProcessor.OnDAServiceUnknownIdentifier := self.DoOnUnknownIdentifier;
end;
lmacro := nil;
end;
Wouldn’t it be better in TBaseDataAbstractService to have the AssignMacroProcesserEvent method public? Or not exiting the GetConnection method when fConnection is assigned?
I’d suggest to use OnBeforeAcquireConnection event and return required connection name instead of calling dmServer.GetDefaultConnection that return IDAConnection.
in this case AssignMacroProcesserEvent method will be called as expected.