I haven't used it yet, but it looks to me that the RDB$SET_CONTEXT()
and RDB$GET_CONTEXT()
introduced in Firebird 2 are what you need. Using these functions, you can set (and get) additional information specific to the user session (namespace USER_SESSION
) or the current transaction (namespace USER_TRANSACTION
). You can also retrieve additional system information for the current session (namespace SYSTEM
), but that is probably not relevant for your case.
What you would need to do is call the RDB$SET_CONTEXT()
method in that OnUserAuthorize event, eg using (as a query):
SELECT RDB$SET_CONTEXT('USER_SESSION', 'actualuser', '<name of user')
FROM RDB$DATABASE
Here 'actualuser'
is the context variable we use. In your triggers you can then retrieve the name (assuming PSQL, with a declared variable actualuser
)
actualuser = RDB$GET_CONTEXT('USER_SESSION', 'actualuser');
You can then use actualuser
in the rest of your trigger. Just make sure you also account for the case where the context variable is not set (eg an administrator making direct changes to the database or something like that).