Subject | Re: [firebird-support] CURRENT_DATABASE? |
---|---|
Author | Helen Borrie |
Post date | 2004-08-03T15:53:47Z |
At 10:04 AM 3/08/2004 -0300, you wrote:
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
>Hi,Not intrinsically. To a database, itself is just, well "me". The filenames
>
>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?
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