Subject Re: [ib-support] Default Values
Author Helen Borrie
At 12:10 PM 16-08-02 +0200, you wrote:
>Hi
>
>I have created a domain with the following values
>
>CREATE DOMAIN DOM_CURRENT_USER
> AS VARCHAR(15)
> DEFAULT CURRENT_USER
> NOT NULL
>
>My question is, is the "Current_User" and the user I logged in with the
>connection the same thing. Put differently, is the current_user variable
>linked or dependant on the current connection to the database.
>
>I ask because I use a sp to insert a record and I dont want to send the
>current user as a sp parameter.
>
>I would assume Current_user is transaction or connection based otherwise it
>would not really be functional. However I just want to make sure, I dont
>like assumptions.

CURRENT_USER is what's known as a context variable: it's value is the user
name of the user who made the request. So user JOEBABY at workstation A
will store or test 'JOEBABY' while 'HOLYMOLLY' at workstation B will store
or test 'HOLYMOLLY'.

Be aware that defaults will only "fire" on inserts and ONLY if the insert
statement does not include the column which requires the default. IMO, to
do what you want, you would be much better to have BEFORE INSERT and BEFORE
UPDATE triggers to write this value explicitly, viz.
...
IF (NEW.CURRENTUSER IS NULL) THEN
NEW.CURRENTUSER = CURRENT_USER;
...

If you want to store the current_user, unconditionally, regardless of what
comes through in the insert or update statement, then take out the IS NULL
test.

heLen

All for Open and Open for All
Firebird Open SQL Database · http://firebirdsql.org ·
http://users.tpg.com.au/helebor/
______________________________________________________________________