Re: Getting database name in SPL
Posted in 1997
On Wed, 29 Oct 1997, Jeff Larsen wrote:
> I'm sure I read this somewhere but I can't seem to find it
> now that I need it.
>
> How do you get the name of the current
> database for use in a stored procedure?
From an article in June 1997...
Yours,
Jonathan Leffler (johnl@informix.com) #include <witticism.h>
# "@(#)$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;