Re: Determining what database your connected to in a SP
Posted in 1998
On Mon, 19 Oct 1998 Sujit.Pal@alltel.com wrote:
> To find the instance name, you could use the following SQL:
>
> SELECT cf_effective INTO currinstname
> FROM sysmaster:sysconfig
> WHERE cf_name = "DBSERVERNAME";
>
> To find the database name, I could think of only this. Maybe somebody
> could come up with something simpler?
>
> [...]
How about:
# "@(#)$Id: currentdb.spl,v 1.5 1997/06/03 16:19:58 johnl Exp $"
#
# Stored procedure CURRENT_DATABASE written by Jonatha Leffler
# (johnl@informix.com), based on a tip from John Lysell
# (jlysell@informix.com), with corrigenda from Raj Muralidharan
# (rmurali@informix.com) and Tue Hejlskov Larsen (tue@informix.com).
#
# If this stored procedure is created (by user informix to get
# the necessary permissions) in the SysMaster database, then any
# user in any database can run it (or call it in a SELECT
# statement) and get the name of the current database. You can
# drop the owner part if you are not using a MODE ANSI database:
#
# EXECUTE PROCEDURE sysmaster:'informix'.current_database()
# EXECUTE PROCEDURE sysmaster:current_database()
#
# The size of the return parameter probably only needs to be 18.
CREATE PROCEDURE current_database() RETURNING VARCHAR(64);
DEFINE s VARCHAR(64);
SELECT ODB_DBName
INTO s
FROM SysMaster:'informix'.SysOpenDB
WHERE ODB_SessionID = (SELECT DBINFO("sessionid")
FROM 'informix'.SysTables
WHERE TabID = 1)
AND ODB_IsCurrent = "Y";
RETURN s;
END PROCEDURE;
This has been posted to c.d.i before, I'm virtually certain.
David, if it isn't already on your FAQ list, could you put it there...
Yours,
Jonathan Leffler (jleffler@informix.com) #include <witticism.h>
Guardian of DBD::Informix v0.60 -- http://www.perl.com/CPAN
Informix IDN for D4GL & Linux -- http://www.informix.com/idn