Subject | Re: [Firebird-Architect] On connect/disconnect trigger |
---|---|
Author | Alexandre Benson Smith |
Post date | 2006-06-02T20:27:42Z |
Ann W. Harrison wrote:
Maybe I could not express myself as I wish...
Let's suppose we have an after connect/disconnect trigger.
create trigger LogUser active after connect as
begin
insert into
Usage (LoginTime, LogUser, LogConnection)
values
(Current_TimeStamp, Current_User, Current_Connection);
end
create trigger LogUser active after disconnect as
begin
update
Usage
set
LogoutTime = Current_TimeStamp
where
LogConnection = Current_Connection;
end
To get a list of current logged users I would do:
select
LogUser, LoginTime
from
Usage
where
LogoutTime is null;
to get the amount of time an individual use the system I would do:
select
sum(LogoutTime - LoginTime)
from
Usage
where
LogUser = 'ALEXANDRE' and
LogoutTime is not null and
LoginTime between '2006-05-01' and '2006-05-31'
In the same line one could implement a simplistic license count like this
Count := ExecuteQuery('select count(*) from Usage where LogoutTime is
null');
if Count > 5 then
ShowMessage('Hey ! You run out of licenses ! Please purchase more
licenses from us !');
HaltApplication(1);
Or if the semantics of the before trigger accept and exception raised as
a valid way to close the connection, one could implement a trigger like
this:
Create exception e_ManyUsers 'Too many concurrent users !';
create trigger BC_LogUser active before connect as
declare variable wLoggedUsers integer;
begin
select count(*) from Usage where LogoutTime is null into :wLoggedUsers;
if (wLoggedUsers > 5) then
exception e_ManyUsers;
end
create trigger AC_LogUser active after connect as
begin
insert into
Usage (LoginTime, LogUser, LogConnection)
values
(Current_TimeStamp, Current_User, Current_Connection);
end
I am sure there are a bunch of limitations in my so simplistic examples
(like lost connections that seems as active from the server point of
view for a long time and so on), but this is just to try to explain what
I think before/after connect/disconnect triggers could be used for.
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br
> Alexandre Benson Smith wrote:Ann,
>
>> I think this kind of triggers could be used to monitor active users,
>> implement some kind of concurrent users limit, average use time, etc.
>>
>> It's how I see this.
>>
>>
>
> OK, what would it use to identify active users - under classic,
> for example - and their use time?
>
>
> Regards,
>
>
> Ann
>
>
Maybe I could not express myself as I wish...
Let's suppose we have an after connect/disconnect trigger.
create trigger LogUser active after connect as
begin
insert into
Usage (LoginTime, LogUser, LogConnection)
values
(Current_TimeStamp, Current_User, Current_Connection);
end
create trigger LogUser active after disconnect as
begin
update
Usage
set
LogoutTime = Current_TimeStamp
where
LogConnection = Current_Connection;
end
To get a list of current logged users I would do:
select
LogUser, LoginTime
from
Usage
where
LogoutTime is null;
to get the amount of time an individual use the system I would do:
select
sum(LogoutTime - LoginTime)
from
Usage
where
LogUser = 'ALEXANDRE' and
LogoutTime is not null and
LoginTime between '2006-05-01' and '2006-05-31'
In the same line one could implement a simplistic license count like this
Count := ExecuteQuery('select count(*) from Usage where LogoutTime is
null');
if Count > 5 then
ShowMessage('Hey ! You run out of licenses ! Please purchase more
licenses from us !');
HaltApplication(1);
Or if the semantics of the before trigger accept and exception raised as
a valid way to close the connection, one could implement a trigger like
this:
Create exception e_ManyUsers 'Too many concurrent users !';
create trigger BC_LogUser active before connect as
declare variable wLoggedUsers integer;
begin
select count(*) from Usage where LogoutTime is null into :wLoggedUsers;
if (wLoggedUsers > 5) then
exception e_ManyUsers;
end
create trigger AC_LogUser active after connect as
begin
insert into
Usage (LoginTime, LogUser, LogConnection)
values
(Current_TimeStamp, Current_User, Current_Connection);
end
I am sure there are a bunch of limitations in my so simplistic examples
(like lost connections that seems as active from the server point of
view for a long time and so on), but this is just to try to explain what
I think before/after connect/disconnect triggers could be used for.
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br