Subject | Re: [firebird-support] CURRENT_DATABASE? |
---|---|
Author | Gianfranco Rossi |
Post date | 2004-08-03T17:39:15Z |
Thanks for your help, and I don't know where to post this but that would
be a great feature to be added for futre use.
Just so its clear, the reason I need this is because I follow Jim's
example for a logging service
(http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_jim_triggers)
except I used UDFs instead of java. However I have severall small
databases (~25M) which I do repeated gbaks to generate 'debug'
databases, that's why I need some form of system variable to identify
who am I.
Thanks again.
Gianni
Helen Borrie wrote:
be a great feature to be added for futre use.
Just so its clear, the reason I need this is because I follow Jim's
example for a logging service
(http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_jim_triggers)
except I used UDFs instead of java. However I have severall small
databases (~25M) which I do repeated gbaks to generate 'debug'
databases, that's why I need some form of system variable to identify
who am I.
Thanks again.
Gianni
Helen Borrie wrote:
>At 10:04 AM 3/08/2004 -0300, you wrote:
>
>
>>Hi,
>>
>>I am using several triggers across several databases that create log
>>files of any changes in my databases. However, things are getting a bit
>>messy since I can't distinguish in my triggers which database it is
>>being run on. Is the any way to figure out the alias name or database
>>file name just as in the CURRENT_USER var?
>>
>>
>
>Not intrinsically. To a database, itself is just, well "me". The filenames
>and aliases are there for use by the server and clients: databases don't
>know about them at all. You can rename a database file and it doesn't
>change anything inside the database at all. In Squeak (SQL-speak) they
>would say "Firebird doesn't support database namespaces" or something similar.
>
>You can fix this for yourself quite simply. Create a table where you store
>the database file name and, if you like, a short callsign. You can make it
>a single-row table (like RDB$DATABASE) or you can use it like a history or
>configuration table, where the newest row represents the "here and now" of
>the file name and callsign.
>
>e.g.
>CREATE GENERATOR GEN_ME_ID;
>
>CREATE TABLE ME (
> ID SMALLINT NOT NULL,
> FILENAME VARCHAR(80) NOT NULL,
> CALLSIGN VARCHAR(10) NOT NULL,
> CHANGEDATE TIMESTAMP NOT NULL,
> CONSTRAINT PK_ME PRIMARY KEY(ID));
>
>CREATE PROCEDURE GET_MY_CALLSIGN
>(RETURNS CALLSIGN VARCHAR(10))
>AS
>BEGIN
> SELECT M1.CALLSIGN FROM ME M1
> WHERE M1.CHANGEDATE =
> (SELECT MAX(M2.CHANGEDATE) FROM ME M2)
> INTO :CALLSIGN;
>END
>
>In your triggers, just declare a variable for the current database and add
>a column for it to your log tables.
>
>...
>DECLARE CURRENT_DATABASE VARCHAR(10);
>...
>
>EXECUTE PROCEDURE GET_MY_CALLSIGN
>RETURNING_VALUES(:CURRENT_DATABASE);
>
>As an afterthought, it might be wise to avoid using CURRENT_DATABASE for
>the variable name, against the possibility that Firebird does later support
>db namespaces and CURRENT_DATABASE becomes a reserved word.
>
>/heLen
>
>
>
>
>
>Yahoo! Groups Links
>
>
>
>
>
>