Re: Need a way to know SessionID -SUMMARY
Posted in 1997
Hi All
My original question was how to find out current
database, or alternatively current sessionid. Both
requirements are elegantly answered in the
following stored procedure provided by Jonathan
Leffler.
Thanks to Johnl and anyone else whose mail I may
not yet have received. (My mail server has been
[sigh] down again)
rgds
Peter Tash
------------------ SP follows ----------------------
Note the installation instructions...
# "@(#)$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;